@Override
 public boolean canSwallow(ConnectionBan ban) {
   if (ban instanceof EndPointConnectExceptionBan) {
     final EndPointConnectExceptionBan other = (EndPointConnectExceptionBan) ban;
     if (proxyEquals(getProxy(), other.getProxy())
         && getPort() == other.getPort()
         && StringUtils.equals(getHost(), other.getHost())
         && StringUtils.equals(getProtocol(), other.getProtocol())) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 2
0
 public boolean stringEquals(String a, String b) {
   if (a == null) {
     a = "";
   }
   if (b == null) {
     b = "";
   }
   return StringUtils.equals(a, b);
 }
Exemplo n.º 3
0
 public void setCurrentActiveItem(Item item) {
   if (currentActiveItem == item) {
     return;
   }
   if (currentActiveItem != null
       && item != null
       && StringUtils.equals(currentActiveItem.getPath(), item.getPath())) {
     return;
   }
   this.currentActiveItem = item;
   fireEvent(ExtractionEvent.Type.ACTIVE_ITEM);
 }
  public void validate(Login login, String url) {

    if (StringUtils.isEmpty(url)) {
      return;
    }
    AuthenticationInfo.Type type = null;
    if (url.startsWith("ftp")) {
      type = Type.FTP;
    } else if (url.startsWith("http")) {
      type = Type.HTTP;
    } else {
      Log.L.info("Unknown Protocoll: " + url);
      return;
    }

    String urlHost = Browser.getHost(url, true);
    for (AuthenticationInfo info : list) {
      if (!info.isEnabled()) {
        continue;
      }
      String authHost = info.getHostmask();
      if (info.getType().equals(type) && !StringUtils.isEmpty(authHost)) {
        boolean contains = false;
        if (authHost.length() > urlHost.length()) {
          /* hostMask of AuthenticationInfo is longer */
          contains = authHost.contains(urlHost);
        } else {
          /* hostMask of urlHost is longer */
          contains = urlHost.contains(authHost);
        }
        if (contains) {
          if (StringUtils.equals(info.getUsername(), login.getUsername())
              && StringUtils.equals(info.getPassword(), login.getPassword())) {
            info.setLastValidated(System.currentTimeMillis());
          }
        }
      }
    }
  }
 @Override
 public boolean isProxyBannedByUrlOrPlugin(
     final HTTPProxy proxy,
     final URL url,
     final Plugin pluginFromThread,
     boolean ignoreConnectBans) {
   if (!ignoreConnectBans && proxyEquals(getProxy(), proxy)) {
     final boolean ret =
         getPort() == getPort(url)
             && StringUtils.containsIgnoreCase(getHost(), Browser.getHost(url))
             && StringUtils.equals(getProtocol(), url.getProtocol());
     return ret;
   }
   return false;
 }
Exemplo n.º 6
0
 @SuppressWarnings("deprecation")
 public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress)
     throws Exception {
   br = new Browser();
   decryptedLinks = new ArrayList<DownloadLink>();
   this.param = param;
   if (param.toString().matches(TYPE_INVALID)) {
     decryptedLinks.add(createOfflinelink(parameter));
     return decryptedLinks;
   }
   parameter = param.toString().replace("www.", "");
   passCode = new Regex(parameter, "\\?password=(.+)").getMatch(0);
   if (passCode != null) {
     /* Remove this from our url as it is only needed for this decrypter internally. */
     parameter = parameter.replace("?password="******"");
   }
   useOriginalFilename =
       PluginJsonConfig.get(TumblrComConfig.class).isUseOriginalFilenameEnabled();
   final Account aa =
       AccountController.getInstance()
           .getValidAccount(JDUtilities.getPluginForHost(this.getHost()));
   if (aa != null) {
     /* Login whenever possible to be able to download account-only-stuff */
     try {
       jd.plugins.hoster.TumblrCom.login(this.br, aa, false);
     } catch (final Throwable e) {
     }
   }
   try {
     if (parameter.matches(TYPE_FILE)) {
       decryptFile();
     } else if (parameter.matches(TYPE_POST)) {
       decryptPost();
     } else if (parameter.matches(TYPE_IMAGE)) {
       decryptedLinks.addAll(processImage(parameter, null, null));
     } else {
       /*
        * 2016-08-26: Seems like when logged in, users now get the same view they have when not logged in. Using the "old"
        * logged-in method, the crawler will not find all entries which is why we now use the normal method (again).
        */
       // if (loggedin) {
       // decryptUserLoggedIn();
       // } else {
       // parameter = convertUserUrlToLoggedOutUser();
       // decryptUser();
       // }
       parameter = convertUserUrlToLoggedOutUser();
       decryptUser();
     }
   } catch (final BrowserException e) {
     logger.info("Server error, couldn't decrypt link: " + parameter);
     return decryptedLinks;
   } catch (final UnknownHostException eu) {
     logger.info("UnknownHostException, couldn't decrypt link: " + parameter);
     return decryptedLinks;
   } catch (final DecrypterException d) {
     if (StringUtils.equals(d.getMessage(), PLUGIN_DEFECT)) {
       logger.warning("Decrypter broken for link: " + parameter);
       return null;
     } else if (StringUtils.equals(d.getMessage(), OFFLINE)) {
       decryptedLinks.add(createOfflinelink(parameter));
       return decryptedLinks;
     }
     throw d;
   }
   return decryptedLinks;
 }
Exemplo n.º 7
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public Object jsonToObject(final JSonNode json, Type type) throws MapperException {
    final ClassCache cc;
    try {

      Class<?> clazz = null;
      if (type instanceof ParameterizedType) {
        Type typ = ((ParameterizedType) type).getRawType();
        if (typ instanceof Class) {
          clazz = (Class<?>) typ;
        }
      } else if (type instanceof Class) {
        clazz = (Class) type;
      } else if (type instanceof GenericArrayType) {
        // this is for 1.6
        // for 1.7 we do not get GenericArrayTypeImpl here but the
        // actual array class
        type =
            clazz =
                Array.newInstance((Class<?>) ((GenericArrayType) type).getGenericComponentType(), 0)
                    .getClass();
      }

      if (clazz == null || clazz == Object.class) {

        if (json instanceof JSonArray) {
          type = clazz = LinkedList.class;
        } else if (json instanceof JSonObject) {
          type = clazz = HashMap.class;
        } else if (json instanceof JSonValue) {
          switch (((JSonValue) json).getType()) {
            case BOOLEAN:
              type = clazz = boolean.class;
              break;
            case DOUBLE:
              type = clazz = double.class;
              break;
            case LONG:
              type = clazz = long.class;
              break;
            case NULL:
            case STRING:
              type = clazz = String.class;
          }
        }
      }
      final TypeMapper<?> tm = typeMapper.get(clazz);
      if (tm != null) {

        return tm.reverseMap(json);
      }
      if (json instanceof JSonValue) {
        if (!Clazz.isPrimitive(type)
            && !Clazz.isString(type)
            && type != Object.class
            && ((JSonValue) json).getValue() != null
            && !Clazz.isEnum(type)) {
          //
          throw new MapperException(json + " cannot be mapped to " + type);
        }
        switch (((JSonValue) json).getType()) {
          case BOOLEAN:
          case DOUBLE:
          case LONG:
            if (type instanceof Class) {
              return JSonMapper.cast(((JSonValue) json).getValue(), (Class) type);
            } else {
              return ((JSonValue) json).getValue();
            }

          case STRING:
            if (type instanceof Class && ((Class<?>) type).isEnum()) {
              try {
                return Enum.valueOf((Class<Enum>) type, ((JSonValue) json).getValue() + "");
              } catch (final IllegalArgumentException e) {
                if (isIgnoreIllegalArgumentMappings() || isIgnoreIllegalEnumMappings()) {
                  return null;
                }
                throw e;
              }
            } else {
              return ((JSonValue) json).getValue();
            }

          case NULL:
            return null;
        }
      }
      if (type instanceof ParameterizedType) {
        final ParameterizedType pType = (ParameterizedType) type;
        Type raw = pType.getRawType();
        if (raw instanceof Class && Collection.class.isAssignableFrom((Class) raw)) {
          final Collection<Object> inst =
              (Collection<Object>) mapClasses((Class) raw).newInstance();
          final JSonArray obj = (JSonArray) json;
          for (final JSonNode n : obj) {
            inst.add(this.jsonToObject(n, pType.getActualTypeArguments()[0]));
          }
          return inst;
        } else if (raw instanceof Class && Map.class.isAssignableFrom((Class) raw)) {
          final Map<String, Object> inst =
              (Map<String, Object>) mapClasses((Class) raw).newInstance();
          final JSonObject obj = (JSonObject) json;
          Entry<String, JSonNode> next;
          for (final Iterator<Entry<String, JSonNode>> it = obj.entrySet().iterator();
              it.hasNext(); ) {
            next = it.next();
            inst.put(
                next.getKey(),
                this.jsonToObject(next.getValue(), pType.getActualTypeArguments()[1]));
          }
          return inst;
        }
      }
      if (clazz != null) {
        if (clazz == Object.class) {
          // guess type
          if (json instanceof JSonArray) {
            type = LinkedList.class;
          } else if (json instanceof JSonObject) {
            type = HashMap.class;
          }
        }

        if (Collection.class.isAssignableFrom(clazz)) {
          final Collection<Object> inst = (Collection<Object>) mapClasses(clazz).newInstance();
          final JSonArray obj = (JSonArray) json;
          final Type gs = clazz.getGenericSuperclass();
          final Type gType;
          if (gs instanceof ParameterizedType) {
            gType = ((ParameterizedType) gs).getActualTypeArguments()[0];
          } else {
            gType = void.class;
          }
          for (final JSonNode n : obj) {
            inst.add(this.jsonToObject(n, gType));
          }
          return inst;
        } else if (Map.class.isAssignableFrom(clazz)) {
          final Map<String, Object> inst = (Map<String, Object>) mapClasses(clazz).newInstance();
          final JSonObject obj = (JSonObject) json;
          final Type gs = clazz.getGenericSuperclass();
          final Type gType;
          if (gs instanceof ParameterizedType) {
            gType = ((ParameterizedType) gs).getActualTypeArguments()[1];
          } else {
            gType = void.class;
          }

          Entry<String, JSonNode> next;
          for (final Iterator<Entry<String, JSonNode>> it = obj.entrySet().iterator();
              it.hasNext(); ) {
            next = it.next();
            inst.put(next.getKey(), this.jsonToObject(next.getValue(), gType));
          }

          return inst;

        } else if (clazz.isArray()) {
          final JSonArray obj = (JSonArray) json;
          final Object arr = Array.newInstance(mapClasses(clazz.getComponentType()), obj.size());
          for (int i = 0; i < obj.size(); i++) {
            final Object v = this.jsonToObject(obj.get(i), clazz.getComponentType());

            Array.set(arr, i, v);
          }
          return arr;
        } else {

          if (json instanceof JSonArray) {

            final java.util.List<Object> inst = new ArrayList<Object>();
            final JSonArray obj = (JSonArray) json;
            final Type gs = clazz.getGenericSuperclass();
            final Type gType;
            if (gs instanceof ParameterizedType) {
              gType = ((ParameterizedType) gs).getActualTypeArguments()[0];
            } else {
              gType = Object.class;
            }
            for (final JSonNode n : obj) {
              inst.add(this.jsonToObject(n, gType));
            }
            return inst;

          } else {
            final JSonObject obj = (JSonObject) json;
            if (Clazz.isPrimitive(clazz)) {
              //
              if (isIgnoreIllegalArgumentMappings()) {
                return null;
              } else {
                throw new IllegalArgumentException("Cannot Map " + obj + " to " + clazz);
              }
            }

            cc = ClassCache.getClassCache(clazz);

            final Object inst = cc.getInstance();
            JSonNode value;
            Object v;
            for (final Setter s : cc.getSetter()) {

              value = obj.get(s.getKey());
              if (value == null) {
                continue;
              }
              //
              Type fieldType = s.getType();
              // special handling for generic fields
              if (fieldType instanceof TypeVariable) {
                final Type[] actualTypes = ((ParameterizedType) type).getActualTypeArguments();
                final TypeVariable<?>[] genericTypes = clazz.getTypeParameters();
                for (int i = 0; i < genericTypes.length; i++) {
                  if (StringUtils.equals(
                      ((TypeVariable) fieldType).getName(), genericTypes[i].getName())) {

                    fieldType = actualTypes[i];
                    break;
                  }
                }
              }
              v = this.jsonToObject(value, fieldType);
              try {
                s.setValue(inst, v);
              } catch (final IllegalArgumentException e) {
                if (isIgnoreIllegalArgumentMappings()) {
                  continue;
                } else if (v == null && isIgnorePrimitiveNullMapping()) {
                  continue;
                }
                throw e;
              }
            }

            return inst;
          }
        }
      } else {
        System.err.println("TYPE?!");
      }
    } catch (final SecurityException e) {
      e.printStackTrace();
    } catch (final NoSuchMethodException e) {
      e.printStackTrace();
    } catch (final IllegalArgumentException e) {
      e.printStackTrace();
    } catch (final InstantiationException e) {
      e.printStackTrace();
    } catch (final IllegalAccessException e) {
      e.printStackTrace();
    } catch (final InvocationTargetException e) {
      e.printStackTrace();
    }
    return null;
  }