use of org.cybergarage.upnp.Service in project felix by apache.
the class Monitor method updateListener.
public synchronized void updateListener(ListenerModified msg, SubscriptionQueue subqueue, MyCtrlPoint ctrl) /*##renew, SidRenewer sidRenewer*/
{
UPnPEventListener listener = msg.getListener();
Vector newServices = msg.getNewServices();
Vector subscribed = new Vector();
Vector notSubscribed = new Vector();
for (int i = 0; i < newServices.size(); i++) {
Service ser = (Service) newServices.elementAt(i);
if (ser.isSubscribed()) {
subscribed.add(ser);
} else {
notSubscribed.add(ser);
}
}
Vector oldSids = sidListSid.getSidsFromListener(listener);
// check subscribed services
if (oldSids == null)
return;
for (int i = 0; i < notSubscribed.size(); i++) {
Service ser = (Service) notSubscribed.elementAt(i);
subqueue.enqueue(new FirstMessage(ser, listener));
}
for (int i = 0; i < oldSids.size(); i++) {
String oldSid = (String) oldSids.elementAt(i);
if (!subscribed.contains(oldSid)) {
// francesco-renew
// to check -- Listner removal from sid2Listener
unsubscribeListenerForSid(oldSid, listener, ctrl);
}
}
}
use of org.cybergarage.upnp.Service in project felix by apache.
the class SubScriber method run.
public void run() {
while (running) {
Object msg = subQueue.dequeue();
if (running) {
if (msg instanceof FirstMessage) {
FirstMessage firstmsg = (FirstMessage) msg;
Service service = firstmsg.getService();
if (!service.isSubscribed()) {
// is not subscribe
boolean ok = ctrl.subscribe(service, 120000);
String sid = "";
if (ok) {
// subcribe ok
sid = service.getSID();
firstmsg.setSid(sid);
monitor.addListener(sid, firstmsg.getListener());
} else {
// subscribe not ok
Activator.logger.log(LogService.LOG_ERROR, "Sucribe failed");
}
} else {
// already subscribe
monitor.addListener(service.getSID(), firstmsg.getListener());
}
} else if (msg instanceof ListenerModified) {
monitor.updateListener((ListenerModified) msg, subQueue, ctrl);
} else if (msg instanceof ListenerUnRegistration) {
ListenerUnRegistration unreg = (ListenerUnRegistration) msg;
monitor.delListener(unreg.getListener(), ctrl);
} else if (msg instanceof SidExipired) {
Activator.logger.WARNING("[Importer] Please report the bug. Used code - should be checked and removed");
}
}
}
}
use of org.cybergarage.upnp.Service in project i2p.i2p by i2p.
the class UPnP method listSubServices.
// TODO: extend it! RTFM
private void listSubServices(Device dev, StringBuilder sb) {
ServiceList sl = dev.getServiceList();
if (sl.isEmpty())
return;
sb.append("<ul>\n");
for (int i = 0; i < sl.size(); i++) {
Service serv = sl.getService(i);
if (serv == null)
continue;
sb.append("<li>").append(_t("Service")).append(": ");
// NOTE: Group all toString() of common actions together
// to avoid excess fetches, since toString() caches.
String type = serv.getServiceType();
if ("urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1".equals(type)) {
sb.append(_t("WAN Common Interface Configuration"));
sb.append("<ul><li>").append(_t("Status")).append(": ").append(toString("GetCommonLinkProperties", "NewPhysicalLinkStatus", serv));
sb.append("<li>").append(_t("Type")).append(": ").append(toString("GetCommonLinkProperties", "NewWANAccessType", serv));
sb.append("<li>").append(_t("Upstream")).append(": ").append(toLong("GetCommonLinkProperties", "NewLayer1UpstreamMaxBitRate", serv)).append("bps");
sb.append("<li>").append(_t("Downstream")).append(": ").append(toLong("GetCommonLinkProperties", "NewLayer1DownstreamMaxBitRate", serv)).append("bps");
if (_context.getBooleanProperty(PROP_ADVANCED)) {
// don't bother translating
sb.append("<li>").append("Sent: ").append(toLong("GetTotalBytesSent", "NewTotalBytesSent", serv)).append('B');
sb.append("<li>").append("Received: ").append(toLong("GetTotalBytesReceived", "NewTotalBytesReceived", serv)).append('B');
sb.append("<li>").append("Sent packets: ").append(toLong("GetTotalPacketsSent", "NewTotalPacketsSent", serv));
sb.append("<li>").append("Received packets: ").append(toLong("GetTotalPacketsReceived", "NewTotalPacketsReceived", serv));
}
} else if (WAN_PPP_CONNECTION.equals(type)) {
sb.append(_t("WAN PPP Connection"));
sb.append("<ul><li>").append(_t("Status")).append(": ").append(toString("GetStatusInfo", "NewConnectionStatus", serv));
sb.append("<li>").append(_t("Uptime")).append(": ").append(toTime("GetStatusInfo", "NewUptime", serv));
sb.append("<li>").append(_t("Type")).append(": ").append(toString("GetConnectionTypeInfo", "NewConnectionType", serv));
sb.append("<li>").append(_t("Upstream")).append(": ").append(toLong("GetLinkLayerMaxBitRates", "NewUpstreamMaxBitRate", serv)).append("bps");
sb.append("<li>").append(_t("Downstream")).append(": ").append(toLong("GetLinkLayerMaxBitRates", "NewDownstreamMaxBitRate", serv)).append("bps");
sb.append("<li>").append(_t("External IP")).append(": ").append(toString("GetExternalIPAddress", "NewExternalIPAddress", serv));
} else if ("urn:schemas-upnp-org:service:Layer3Forwarding:1".equals(type)) {
sb.append(_t("Layer 3 Forwarding"));
sb.append("<ul><li>").append(_t("Default Connection Service")).append(": ").append(toString("GetDefaultConnectionService", "NewDefaultConnectionService", serv));
} else if (WAN_IP_CONNECTION.equals(type) || WAN_IP_CONNECTION_2.equals(type)) {
sb.append(_t("WAN IP Connection"));
sb.append("<ul><li>").append(_t("Status")).append(": ").append(toString("GetStatusInfo", "NewConnectionStatus", serv));
sb.append("<li>").append(_t("Uptime")).append(": ").append(toTime("GetStatusInfo", "NewUptime", serv));
String error = toString("GetStatusInfo", "NewLastConnectionError", serv);
if (error != null && error.length() > 0 && !error.equals("ERROR_NONE"))
sb.append("<li>").append("Last Error").append(": ").append(error);
sb.append("<li>").append(_t("Type")).append(": ").append(toString("GetConnectionTypeInfo", "NewConnectionType", serv));
sb.append("<li>").append(_t("External IP")).append(": ").append(toString("GetExternalIPAddress", "NewExternalIPAddress", serv));
} else if (WAN_IPV6_CONNECTION.equals(type)) {
sb.append("WAN IPv6 Connection");
sb.append("<ul><li>").append("Firewall Enabled").append(": ").append(toBoolean("GetFirewallStatus", "FirewallEnabled", serv));
sb.append("<li>").append("Pinhole Allowed").append(": ").append(toBoolean("GetFirewallStatus", "InboundPinholeAllowed", serv));
} else if ("urn:schemas-upnp-org:service:WANEthernetLinkConfig:1".equals(type)) {
sb.append(_t("WAN Ethernet Link Configuration"));
sb.append("<ul><li>").append(_t("Status")).append(": ").append(toString("GetEthernetLinkStatus", "NewEthernetLinkStatus", serv));
} else {
sb.append(DataHelper.escapeHTML(type)).append("<ul>");
}
if (_context.getBooleanProperty(PROP_ADVANCED)) {
sb.append("<li>Actions");
listActions(serv, sb);
sb.append("</li><li>States");
listStateTable(serv, sb);
sb.append("</li>");
}
sb.append("</ul>\n");
}
sb.append("</ul>\n");
}
use of org.cybergarage.upnp.Service in project i2p.i2p by i2p.
the class UPnP method removeMapping.
/**
* blocking
*/
private boolean removeMapping(String protocol, int port, ForwardPort fp, boolean noLog) {
Service service;
synchronized (lock) {
if (isDisabled || !isNATPresent()) {
_log.error("Can't removeMapping: " + isDisabled + " " + isNATPresent() + " " + _router);
return false;
}
service = _service;
}
Action remove = service.getAction("DeletePortMapping");
if (remove == null) {
if (_log.shouldLog(Log.WARN))
_log.warn("Couldn't find DeletePortMapping action!");
return false;
}
// remove.setArgumentValue("NewRemoteHost", "");
remove.setArgumentValue("NewExternalPort", port);
remove.setArgumentValue("NewProtocol", protocol);
boolean retval = remove.postControlAction();
synchronized (lock) {
portsForwarded.remove(fp);
}
if (_log.shouldLog(Log.WARN) && !noLog)
_log.warn("UPnP: Removed mapping for " + fp.name + " " + port + " / " + protocol);
return retval;
}
use of org.cybergarage.upnp.Service in project i2p.i2p by i2p.
the class UPnP method addMapping.
/**
* This always requests that the external port == the internal port, for now.
* Blocking!
*/
private boolean addMapping(String protocol, int port, String description, ForwardPort fp) {
Service service;
synchronized (lock) {
if (isDisabled || !isNATPresent() || _router == null) {
_log.error("Can't addMapping: " + isDisabled + " " + isNATPresent() + " " + _router);
return false;
}
service = _service;
}
// Just in case...
// this confuses my linksys? - zzz
// removeMapping(protocol, port, fp, true);
Action add = service.getAction("AddPortMapping");
if (add == null) {
if (_serviceLacksAPM) {
if (_log.shouldLog(Log.WARN))
_log.warn("Couldn't find AddPortMapping action!");
} else {
_serviceLacksAPM = true;
_log.logAlways(Log.WARN, "UPnP device does not support port forwarding");
}
return false;
}
add.setArgumentValue("NewRemoteHost", "");
add.setArgumentValue("NewExternalPort", port);
// bugfix, see below for details
String intf = _router.getInterfaceAddress();
String us = getOurAddress(intf);
if (_log.shouldLog(Log.WARN) && !us.equals(intf))
_log.warn("Requesting port forward to " + us + ':' + port + " when cybergarage wanted " + intf);
add.setArgumentValue("NewInternalClient", us);
add.setArgumentValue("NewInternalPort", port);
add.setArgumentValue("NewProtocol", protocol);
add.setArgumentValue("NewPortMappingDescription", description);
add.setArgumentValue("NewEnabled", "1");
add.setArgumentValue("NewLeaseDuration", 0);
boolean rv = add.postControlAction();
if (rv) {
synchronized (lock) {
portsForwarded.add(fp);
}
}
int level = rv ? Log.INFO : Log.WARN;
if (_log.shouldLog(level)) {
StringBuilder buf = new StringBuilder();
buf.append("AddPortMapping result for ").append(protocol).append(" port ").append(port);
// Not sure which of these has the good info
UPnPStatus status = add.getStatus();
if (status != null)
buf.append(" Status: ").append(status.getCode()).append(' ').append(status.getDescription());
status = add.getControlStatus();
if (status != null)
buf.append(" ControlStatus: ").append(status.getCode()).append(' ').append(status.getDescription());
_log.log(level, buf.toString());
}
return rv;
}
Aggregations