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;
  }
Esempio n. 4
0
  protected static List stringToPorts(String str) {
    str = str.replace(',', ';');

    StringTokenizer tok = new StringTokenizer(str, ";");

    List res = new ArrayList();

    while (tok.hasMoreTokens()) {

      try {
        res.add(new Integer(tok.nextToken().trim()));

      } catch (Throwable e) {

        Debug.out("Invalid port entry in '" + str + "'", e);
      }
    }

    return (res);
  }
  public void addAndFireListener(COConfigurationListener listener) {
    synchronized (listenerz) {
      listenerz.add(listener);
    }

    try {
      listener.configurationSaved();

    } catch (Throwable e) {

      Debug.printStackTrace(e);
    }
  }
Esempio n. 6
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);
  }
 public void addResetToDefaultsListener(ResetToDefaultsListener l) {
   synchronized (reset_to_def_listeners) {
     reset_to_def_listeners.add(l);
   }
 }
 public void removeListener(COConfigurationListener listener) {
   synchronized (listenerz) {
     listenerz.remove(listener);
   }
 }
 public void addListener(COConfigurationListener listener) {
   synchronized (listenerz) {
     listenerz.add(listener);
   }
 }