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);
  }
  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();
    }
  }
  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;
  }
示例#4
0
  public static URL[][] getAnnounceURLs() {
    String tracker_host = COConfigurationManager.getStringParameter("Tracker IP", "");

    List urls = new ArrayList();

    if (tracker_host.length() > 0) {

      if (COConfigurationManager.getBooleanParameter("Tracker Port Enable")) {

        int port = COConfigurationManager.getIntParameter("Tracker Port", TRHost.DEFAULT_PORT);

        try {
          List l = new ArrayList();

          l.add(
              new URL(
                  "http://" + UrlUtils.convertIPV6Host(tracker_host) + ":" + port + "/announce"));

          List ports =
              stringToPorts(COConfigurationManager.getStringParameter("Tracker Port Backups"));

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

            l.add(
                new URL(
                    "http://"
                        + UrlUtils.convertIPV6Host(tracker_host)
                        + ":"
                        + ((Integer) ports.get(i)).intValue()
                        + "/announce"));
          }

          urls.add(l);

        } catch (MalformedURLException e) {

          Debug.printStackTrace(e);
        }
      }

      if (COConfigurationManager.getBooleanParameter("Tracker Port SSL Enable")) {

        int port =
            COConfigurationManager.getIntParameter("Tracker Port SSL", TRHost.DEFAULT_PORT_SSL);

        try {
          List l = new ArrayList();

          l.add(
              new URL(
                  "https://" + UrlUtils.convertIPV6Host(tracker_host) + ":" + port + "/announce"));

          List ports =
              stringToPorts(COConfigurationManager.getStringParameter("Tracker Port SSL Backups"));

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

            l.add(
                new URL(
                    "https://"
                        + UrlUtils.convertIPV6Host(tracker_host)
                        + ":"
                        + ((Integer) ports.get(i)).intValue()
                        + "/announce"));
          }

          urls.add(l);

        } catch (MalformedURLException e) {

          Debug.printStackTrace(e);
        }
      }

      if (COConfigurationManager.getBooleanParameter("Tracker Port UDP Enable")) {

        int port = COConfigurationManager.getIntParameter("Tracker Port", TRHost.DEFAULT_PORT);

        boolean auth =
            COConfigurationManager.getBooleanParameter("Tracker Password Enable Torrent");

        try {
          List l = new ArrayList();

          l.add(
              new URL(
                  "udp://"
                      + UrlUtils.convertIPV6Host(tracker_host)
                      + ":"
                      + port
                      + "/announce"
                      + (auth ? "?auth" : "")));

          urls.add(l);

        } catch (MalformedURLException e) {

          Debug.printStackTrace(e);
        }
      }
    }

    URL[][] res = new URL[urls.size()][];

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

      List l = (List) urls.get(i);

      URL[] u = new URL[l.size()];

      l.toArray(u);

      res[i] = u;
    }

    return (res);
  }