Beispiel #1
0
  public UPnPPluginService[] getServices(UPnPDevice device) {
    String target_usn = device.getRootDevice().getUSN();

    List<UPnPPluginService> res = new ArrayList<UPnPPluginService>();

    try {
      this_mon.enter();

      for (UPnPPluginService service : services) {

        String this_usn =
            service.getService().getGenericService().getDevice().getRootDevice().getUSN();

        if (this_usn.equals(target_usn)) {

          res.add(service);
        }
      }
    } finally {

      this_mon.exit();
    }

    return (res.toArray(new UPnPPluginService[res.size()]));
  }
Beispiel #2
0
  public UPnPPluginService[] getServices() {
    try {
      this_mon.enter();

      return ((UPnPPluginService[]) services.toArray(new UPnPPluginService[services.size()]));

    } finally {

      this_mon.exit();
    }
  }
Beispiel #3
0
  public void rootDeviceFound(UPnPRootDevice device) {
    incrementDeviceStats(device.getUSN(), "found");

    checkDeviceStats(device);

    try {
      int interesting = processDevice(device.getDevice());

      if (interesting > 0) {

        try {
          this_mon.enter();

          root_info_map.put(device.getLocation(), device.getInfo());

          Iterator<String> it = root_info_map.values().iterator();

          String all_info = "";

          List reported_info = new ArrayList();

          while (it.hasNext()) {

            String info = (String) it.next();

            if (info != null && !reported_info.contains(info)) {

              reported_info.add(info);

              all_info += (all_info.length() == 0 ? "" : ",") + info;
            }
          }

          if (all_info.length() > 0) {

            plugin_interface.getPluginconfig().setPluginParameter("plugin.info", all_info);
          }

        } finally {

          this_mon.exit();
        }
      }
    } catch (Throwable e) {

      log.log("Root device processing fails", e);
    }
  }
  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();
    }
  }
Beispiel #6
0
  protected String[] getSelectedAddresses() {
    String si = selected_addresses_param.getValue().trim();

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

    List res = new ArrayList();

    while (tok.hasMoreTokens()) {

      String s = tok.nextToken().trim();

      if (s.length() > 0) {

        res.add(s);
      }
    }

    return ((String[]) res.toArray(new String[res.size()]));
  }
Beispiel #7
0
  public void mappingDestroyed(UPnPMapping mapping) {
    try {
      this_mon.enter();

      mappings.remove(mapping);

      log.log("Mapping request removed: " + mapping.getString());

      for (int j = 0; j < services.size(); j++) {

        UPnPPluginService service = (UPnPPluginService) services.get(j);

        service.removeMapping(log, mapping, false);
      }
    } finally {

      this_mon.exit();
    }
  }
Beispiel #8
0
  protected void checkState() {
    try {
      this_mon.enter();

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

        UPnPMapping mapping = (UPnPMapping) mappings.get(i);

        for (int j = 0; j < services.size(); j++) {

          UPnPPluginService service = (UPnPPluginService) services.get(j);

          service.checkMapping(log, mapping);
        }
      }
    } finally {

      this_mon.exit();
    }
  }
  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);
    }
  }
Beispiel #10
0
  public String[] getExternalIPAddresses() {
    List res = new ArrayList();

    try {
      this_mon.enter();

      for (int j = 0; j < services.size(); j++) {

        UPnPPluginService service = (UPnPPluginService) services.get(j);

        try {
          String address = service.getService().getExternalIPAddress();

          if (address != null) {

            res.add(address);
          }
        } catch (Throwable e) {

          Debug.printStackTrace(e);
        }
      }
    } finally {

      this_mon.exit();
    }

    return ((String[]) res.toArray(new String[res.size()]));
  }
Beispiel #11
0
  protected void removeService(UPnPWANConnection wan_service, boolean replaced) {
    try {
      this_mon.enter();

      String name =
          wan_service.getGenericService().getServiceType().indexOf("PPP") == -1
              ? "WANIPConnection"
              : "WANPPPConnection";

      String text =
          MessageText.getString(
              "upnp.alert.lostdevice",
              new String[] {
                name,
                wan_service.getGenericService().getDevice().getRootDevice().getLocation().getHost()
              });

      log.log(text);

      if ((!replaced) && alert_device_probs_param.getValue()) {

        log.logAlertRepeatable(LoggerChannel.LT_WARNING, text);
      }

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

        UPnPPluginService ps = (UPnPPluginService) services.get(i);

        if (ps.getService() == wan_service) {

          services.remove(i);

          break;
        }
      }
    } finally {

      this_mon.exit();
    }
  }
  public PluginInterface getLocalPluginInterface(Class plugin_class, String id)
      throws PluginException {
    try {
      Plugin p = (Plugin) plugin_class.newInstance();

      // Discard plugin.id from the properties, we want the
      // plugin ID we create to take priority - not a value
      // from the original plugin ID properties file.
      Properties local_props = new Properties(props);
      local_props.remove("plugin.id");

      if (id.endsWith("_v")) {

        throw (new Exception("Verified plugins must be loaded from a jar"));
      }

      PluginInterfaceImpl pi =
          new PluginInterfaceImpl(
              p,
              initialiser,
              initialiser_key,
              class_loader,
              null,
              key + "." + id,
              local_props,
              pluginDir,
              getPluginID() + "." + id,
              plugin_version);

      initialiser.fireCreated(pi);

      p.initialize(pi);

      children.add(pi);

      return (pi);

    } catch (Throwable e) {

      if (e instanceof PluginException) {

        throw ((PluginException) e);
      }

      throw (new PluginException("Local initialisation fails", e));
    }
  }
Beispiel #13
0
  protected void addMapping(UPnPMapping mapping) {
    try {
      this_mon.enter();

      mappings.add(mapping);

      log.log("Mapping request: " + mapping.getString() + ", enabled = " + mapping.isEnabled());

      mapping.addListener(this);

      checkState();

    } finally {

      this_mon.exit();
    }
  }
Beispiel #14
0
  protected void addService(UPnPWANConnection wan_service) throws UPnPException {

    wan_service.addListener(this);

    mapping_manager.serviceFound(wan_service);

    try {
      this_mon.enter();

      log.log(
          "    Found "
              + (wan_service.getGenericService().getServiceType().indexOf("PPP") == -1
                  ? "WANIPConnection"
                  : "WANPPPConnection"));

      UPnPWANConnectionPortMapping[] ports;

      String usn = wan_service.getGenericService().getDevice().getRootDevice().getUSN();

      if (getDeviceStats(usn, STATS_READ_OK) == 0 && getDeviceStats(usn, STATS_READ_BAD) > 2) {

        ports = new UPnPWANConnectionPortMapping[0];

        wan_service.periodicallyRecheckMappings(false);

        log.log("    Not reading port mappings from device due to previous failures");

      } else {

        ports = wan_service.getPortMappings();
      }

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

        log.log(
            "      mapping ["
                + j
                + "] "
                + ports[j].getExternalPort()
                + "/"
                + (ports[j].isTCP() ? "TCP" : "UDP")
                + " ["
                + ports[j].getDescription()
                + "] -> "
                + ports[j].getInternalHost());
      }

      services.add(
          new UPnPPluginService(
              wan_service,
              ports,
              alert_success_param,
              grab_ports_param,
              alert_other_port_param,
              release_mappings_param));

      if (services.size() > 1) {

        // check this isn't a single device with multiple services

        String new_usn = wan_service.getGenericService().getDevice().getRootDevice().getUSN();

        boolean multiple_found = false;

        for (int i = 0; i < services.size() - 1; i++) {

          UPnPPluginService service = (UPnPPluginService) services.get(i);

          String existing_usn =
              service.getService().getGenericService().getDevice().getRootDevice().getUSN();

          if (!new_usn.equals(existing_usn)) {

            multiple_found = true;

            break;
          }
        }

        if (multiple_found) {

          PluginConfig pc = plugin_interface.getPluginconfig();

          if (!pc.getPluginBooleanParameter("upnp.device.multipledevices.warned", false)) {

            pc.setPluginParameter("upnp.device.multipledevices.warned", true);

            String text = MessageText.getString("upnp.alert.multipledevice.warning");

            log.logAlertRepeatable(LoggerChannel.LT_WARNING, text);
          }
        }
      }

      checkState();

    } finally {

      this_mon.exit();
    }
  }