public boolean verifyParameter(String parameter, String value) {
    List verifiers = ConfigurationDefaults.getInstance().getVerifiers(parameter);

    if (verifiers != null) {
      try {
        for (int i = 0; i < verifiers.size(); i++) {

          ParameterVerifier verifier = (ParameterVerifier) verifiers.get(i);

          if (verifier != null) {

            try {
              if (!verifier.verify(parameter, value)) {

                return (false);
              }
            } catch (Throwable e) {

              Debug.printStackTrace(e);
            }
          }
        }
      } catch (Throwable e) {

        // we're not synchronized so possible but unlikely error here

        Debug.printStackTrace(e);
      }
    }

    return (true);
  }
  /**
   * Perform the actual version check by connecting to the version server.
   *
   * @param data_to_send version message
   * @return version reply
   * @throws Exception if the server check connection fails
   */
  private Map performVersionCheck(
      Map data_to_send, boolean use_az_message, boolean use_http, boolean v6) throws Exception {
    Exception error = null;
    Map reply = null;

    if (use_http) {

      try {
        reply = executeHTTP(data_to_send, v6);

        reply.put("protocol_used", "HTTP");

        error = null;
      } catch (IOException e) {
        error = e;
      } catch (Exception e) {
        Debug.printStackTrace(e);
        error = e;
      }
    }

    if (reply == null && use_az_message) {

      try {
        reply = executeAZMessage(data_to_send, v6);

        reply.put("protocol_used", "AZMSG");
      } catch (IOException e) {
        error = e;
      } catch (Exception e) {
        Debug.printStackTrace(e);
        error = e;
      }
    }
    if (error != null) {

      throw (error);
    }

    if (Logger.isEnabled())
      Logger.log(
          new LogEvent(
              LOGID,
              "VersionCheckClient server "
                  + "version check successful. Received "
                  + reply.size()
                  + " reply keys."));

    if (v6) {

      last_check_time_v6 = SystemTime.getCurrentTime();

    } else {

      last_check_time_v4 = SystemTime.getCurrentTime();
    }

    return reply;
  }
Пример #3
0
  protected void openSupport(String reason) throws FMFileManagerException {

    if (raf != null) {

      throw (new FMFileManagerException("file already open"));
    }

    reserveAccess(reason);

    try {
      file_access.aboutToOpen();

      raf =
          new RandomAccessFile(
              linked_file, access_mode == FM_READ ? READ_ACCESS_MODE : WRITE_ACCESS_MODE);

    } catch (FileNotFoundException e) {

      int st = file_access.getStorageType();

      boolean ok = false;

      // edge case here when switching one file from dnd -> download and the compact files at edge
      // boundaries not
      // yet allocated - attempt to create the file on demand

      try {
        linked_file.getParentFile().mkdirs();

        linked_file.createNewFile();

        raf =
            new RandomAccessFile(
                linked_file, access_mode == FM_READ ? READ_ACCESS_MODE : WRITE_ACCESS_MODE);

        ok = true;

      } catch (Throwable f) {
      }

      if (!ok) {

        Debug.printStackTrace(e);

        throw (new FMFileManagerException("open fails", e));
      }
    } catch (Throwable e) {

      Debug.printStackTrace(e);

      throw (new FMFileManagerException("open fails", e));
    }
  }
Пример #4
0
  public <T> void setPersistentMapProperty(String prop, Map<String, T> value) {
    boolean dirty = false;

    synchronized (persistent_properties) {
      Map<String, T> existing = getPersistentMapProperty(prop, null);

      if (!BEncoder.mapsAreIdentical(value, existing)) {

        try {
          if (value == null) {

            persistent_properties.remove(prop);

          } else {

            persistent_properties.put(prop, value);
          }

          dirty = true;

        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      }
    }

    if (dirty) {

      setDirty();
    }
  }
  private void notifyParameterListeners(String parameter) {
    ParameterListener[] listeners;

    synchronized (parameterListenerz) {
      listeners = parameterListenerz.get(parameter);
    }

    if (listeners == null) {
      return;
    }

    for (ParameterListener listener : listeners) {

      if (listener != null) {

        try {
          listener.parameterChanged(parameter);

        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      }
    }
  }
Пример #6
0
  public String[] getPersistentStringListProperty(String prop) {
    synchronized (persistent_properties) {
      try {
        List<byte[]> values = (List<byte[]>) persistent_properties.get(prop);

        if (values == null) {

          return (new String[0]);
        }

        String[] res = new String[values.size()];

        int pos = 0;

        for (byte[] value : values) {

          res[pos++] = new String(value, "UTF-8");
        }

        return (res);

      } catch (Throwable e) {

        Debug.printStackTrace(e);

        return (new String[0]);
      }
    }
  }
Пример #7
0
  public void removePersistentProperty(String prop) {
    boolean dirty = false;

    synchronized (persistent_properties) {
      String existing = getPersistentStringProperty(prop);

      if (existing != null) {

        try {
          persistent_properties.remove(prop);

          dirty = true;

        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      }
    }

    if (dirty) {

      setDirty();
    }
  }
  public AuthenticatorWindow() {
    SESecurityManager.addPasswordListener(this);

    // System.out.println( "AuthenticatorWindow");

    Map cache = COConfigurationManager.getMapParameter(CONFIG_PARAM, new HashMap());

    try {
      Iterator it = cache.entrySet().iterator();

      while (it.hasNext()) {

        Map.Entry entry = (Map.Entry) it.next();

        String key = (String) entry.getKey();
        Map value = (Map) entry.getValue();

        String user = new String((byte[]) value.get("user"), "UTF-8");
        char[] pw = new String((byte[]) value.get("pw"), "UTF-8").toCharArray();

        auth_cache.put(key, new authCache(key, new PasswordAuthentication(user, pw), true));
      }

    } catch (Throwable e) {

      COConfigurationManager.setParameter(CONFIG_PARAM, new HashMap());

      Debug.printStackTrace(e);
    }
  }
Пример #9
0
  public void setPersistentStringListProperty(String prop, String[] values) {
    boolean dirty = false;

    synchronized (persistent_properties) {
      try {
        List<byte[]> values_list = new ArrayList<byte[]>();

        for (String value : values) {

          values_list.add(value.getBytes("UTF-8"));
        }

        persistent_properties.put(prop, values_list);

        dirty = true;

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }

    if (dirty) {

      setDirty();
    }
  }
Пример #10
0
  public void setPersistentStringProperty(String prop, String value) {
    boolean dirty = false;

    synchronized (persistent_properties) {
      String existing = getPersistentStringProperty(prop);

      if (!existing.equals(value)) {

        try {
          if (value == null) {

            persistent_properties.remove(prop);

          } else {

            persistent_properties.put(prop, value.getBytes("UTF-8"));
          }

          dirty = true;

        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      }
    }

    if (dirty) {

      setDirty();
    }
  }
Пример #11
0
 public void positionChanged(Download download, int old_position, int new_position) {
   Iterator itr = this.listeners.iterator();
   while (itr.hasNext()) {
     try {
       ((DownloadListener) itr.next()).positionChanged(download, old_position, new_position);
     } catch (Throwable t) {
       Debug.printStackTrace(t);
     }
   }
 }
Пример #12
0
 public void onCompletion(Download download) {
   Iterator itr = this.listeners.iterator();
   while (itr.hasNext()) {
     try {
       ((DownloadCompletionListener) itr.next()).onCompletion(download);
     } catch (Throwable t) {
       Debug.printStackTrace(t);
     }
   }
 }
 public boolean setParameter(String parameter, Map value) {
   try {
     propertiesMap.put(parameter, value);
     notifyParameterListeners(parameter);
   } catch (Exception e) {
     Debug.printStackTrace(e);
     return false;
   }
   return true;
 }
Пример #14
0
 public void peerManagerRemoved(Download download, PeerManager peer_manager) {
   Iterator itr = this.listeners.iterator();
   while (itr.hasNext()) {
     try {
       ((DownloadPeerListener) itr.next()).peerManagerRemoved(download, peer_manager);
     } catch (Throwable t) {
       Debug.printStackTrace(t);
     }
   }
 }
Пример #15
0
 public void propertyChanged(Download download, DownloadPropertyEvent event) {
   Iterator itr = this.listeners.iterator();
   while (itr.hasNext()) {
     try {
       ((DownloadPropertyListener) itr.next()).propertyChanged(download, event);
     } catch (Throwable t) {
       Debug.printStackTrace(t);
     }
   }
 }
Пример #16
0
 public void announceResult(DownloadAnnounceResult result) {
   Iterator itr = this.listeners.iterator();
   while (itr.hasNext()) {
     try {
       ((DownloadTrackerListener) itr.next()).announceResult(result);
     } catch (Throwable t) {
       Debug.printStackTrace(t);
     }
   }
 }
Пример #17
0
 public void attributeEventOccurred(Download d, TorrentAttribute ta, int event_type) {
   Iterator itr = this.listeners.iterator();
   while (itr.hasNext()) {
     try {
       ((DownloadAttributeListener) itr.next()).attributeEventOccurred(d, ta, event_type);
     } catch (Throwable t) {
       Debug.printStackTrace(t);
     }
   }
 }
Пример #18
0
  public static boolean isPlatformTracker(TOTorrent torrent) {
    try {
      if (torrent == null) {

        return false;
      }

      Object oCache = mapPlatformTrackerTorrents.get(torrent);
      if (oCache instanceof Boolean) {
        return ((Boolean) oCache).booleanValue();
      }

      // check them all incase someone includes one of our trackers in a multi-tracker
      // torrent

      URL announceURL = torrent.getAnnounceURL();

      if (announceURL != null) {

        if (!isPlatformHost(announceURL.getHost())) {

          mapPlatformTrackerTorrents.put(torrent, new Boolean(false));
          return (false);
        }
      }

      TOTorrentAnnounceURLSet[] sets = torrent.getAnnounceURLGroup().getAnnounceURLSets();

      for (int i = 0; i < sets.length; i++) {

        URL[] urls = sets[i].getAnnounceURLs();

        for (int j = 0; j < urls.length; j++) {

          if (!isPlatformHost(urls[j].getHost())) {

            mapPlatformTrackerTorrents.put(torrent, new Boolean(false));
            return (false);
          }
        }
      }

      boolean b = announceURL != null;
      mapPlatformTrackerTorrents.put(torrent, new Boolean(b));
      return b;

    } catch (Throwable e) {

      Debug.printStackTrace(e);

      mapPlatformTrackerTorrents.put(torrent, new Boolean(false));
      return (false);
    }
  }
Пример #19
0
 public void downloadWillBeRemoved(Download download) throws DownloadRemovalVetoException {
   Iterator itr = this.listeners.iterator();
   while (itr.hasNext()) {
     try {
       ((DownloadWillBeRemovedListener) itr.next()).downloadWillBeRemoved(download);
     } catch (DownloadRemovalVetoException e) {
       throw e;
     } catch (Throwable t) {
       Debug.printStackTrace(t);
     }
   }
 }
  public void save(String filename) {
    if (propertiesMap == null) {

      // nothing to save, initialisation not complete

      return;
    }

    /**
     * Note - propertiesMap isn't synchronised! We'll clone the map now, because we need to modify
     * it. The BEncoding code will create a new map object (TreeMap) because it needs to be sorted,
     * so we might as well do it here too.
     */
    TreeMap<String, Object> properties_clone = propertiesMap.toTreeMap();

    // Remove any transient parameters.
    if (!this.transient_properties.isEmpty()) {
      properties_clone.keySet().removeAll(this.transient_properties);
    }

    FileUtil.writeResilientConfigFile(filename, properties_clone);

    List<COConfigurationListener> listeners_copy;

    synchronized (listenerz) {
      listeners_copy = new ArrayList<COConfigurationListener>(listenerz);
    }

    for (int i = 0; i < listeners_copy.size(); i++) {

      COConfigurationListener l = (COConfigurationListener) listeners_copy.get(i);

      if (l != null) {

        try {
          l.configurationSaved();

        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      } else {

        Debug.out("COConfigurationListener is null");
      }
    }

    if (exported_parameters_dirty) {

      exportParameters();
    }
  }
Пример #21
0
 public boolean activationRequested(DownloadActivationEvent event) {
   Iterator itr = this.listeners.iterator();
   while (itr.hasNext()) {
     try {
       if (((DownloadActivationListener) itr.next()).activationRequested(event)) {
         return true;
       }
     } catch (Throwable t) {
       Debug.printStackTrace(t);
     }
   }
   return false;
 }
  public void addAndFireListener(COConfigurationListener listener) {
    synchronized (listenerz) {
      listenerz.add(listener);
    }

    try {
      listener.configurationSaved();

    } catch (Throwable e) {

      Debug.printStackTrace(e);
    }
  }
Пример #23
0
  protected String[] getAuthenticationDialog(final String realm, final String tracker) {
    final Display display = SWTThread.getInstance().getDisplay();

    if (display.isDisposed()) {

      return (null);
    }

    final AESemaphore sem = new AESemaphore("SWTAuth");

    final authDialog[] dialog = new authDialog[1];

    TOTorrent torrent = TorrentUtils.getTLSTorrent();

    final String torrent_name;

    if (torrent == null) {

      torrent_name = null;

    } else {

      torrent_name = TorrentUtils.getLocalisedName(torrent);
    }

    try {
      display.asyncExec(
          new AERunnable() {
            public void runSupport() {
              dialog[0] = new authDialog(sem, display, realm, tracker, torrent_name);
            }
          });
    } catch (Throwable e) {

      Debug.printStackTrace(e);

      return (null);
    }
    sem.reserve();

    String user = dialog[0].getUsername();
    String pw = dialog[0].getPassword();
    String persist = dialog[0].savePassword() ? "true" : "false";

    if (user == null) {

      return (null);
    }

    return (new String[] {user, pw == null ? "" : pw, persist});
  }
  public boolean setParameter(String parameter, StringList value) {
    try {
      List encoded = new ArrayList();

      List l = ((StringListImpl) value).getList();

      for (int i = 0; i < l.size(); i++) {

        encoded.add(stringToBytes((String) l.get(i)));
      }
      propertiesMap.put(parameter, encoded);
      notifyParameterListeners(parameter);
    } catch (Exception e) {
      Debug.printStackTrace(e);
      return false;
    }
    return true;
  }
  protected void closedownComplete() {
    Iterator it = listeners.iterator();

    while (it.hasNext()) {

      try {
        ((PluginListener) it.next()).closedownComplete();

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }

    for (int i = 0; i < children.size(); i++) {

      ((PluginInterfaceImpl) children.get(i)).closedownComplete();
    }
  }
  protected void initialisationComplete() {
    Iterator<PluginListener> it = listeners.iterator();

    while (it.hasNext()) {

      try {
        fireInitComplete(it.next());

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }

    for (int i = 0; i < children.size(); i++) {

      ((PluginInterfaceImpl) children.get(i)).initialisationComplete();
    }
  }
Пример #27
0
  public String getPersistentStringProperty(String prop, String def) {
    synchronized (persistent_properties) {
      try {
        byte[] value = (byte[]) persistent_properties.get(prop);

        if (value == null) {

          return (def);
        }

        return (new String(value, "UTF-8"));

      } catch (Throwable e) {

        Debug.printStackTrace(e);

        return (def);
      }
    }
  }
Пример #28
0
  public <T> Map<String, T> getPersistentMapProperty(String prop, Map<String, T> def) {
    synchronized (persistent_properties) {
      try {
        Map<String, T> value = (Map<String, T>) persistent_properties.get(prop);

        if (value == null) {

          return (def);
        }

        return (value);

      } catch (Throwable e) {

        Debug.printStackTrace(e);

        return (def);
      }
    }
  }
  protected void firePluginEventSupport(PluginEvent event) {
    Iterator<PluginEventListener> it = event_listeners.iterator();

    while (it.hasNext()) {

      try {
        PluginEventListener listener = it.next();

        listener.handleEvent(event);

      } catch (Throwable e) {

        Debug.printStackTrace(e);
      }
    }

    for (int i = 0; i < children.size(); i++) {

      ((PluginInterfaceImpl) children.get(i)).firePluginEvent(event);
    }
  }
Пример #30
0
  protected void setLengthSupport(long length) throws FMFileManagerException {

    try {
      file_access.setLength(raf, length);

    } catch (FMFileManagerException e) {

      if (OUTPUT_REOPEN_RELATED_ERRORS) {
        Debug.printStackTrace(e);
      }

      try {
        reopen(e);

        file_access.setLength(raf, length);

      } catch (Throwable e2) {

        throw (e);
      }
    }
  }