Compare commits

...

3 Commits

Author SHA1 Message Date
BWS Systems
28d84f667a Fixed broke upnp responses and notifies 2019-07-18 13:41:17 -05:00
BWS Systems
755533b30d changed hue-bridgeid to be lower case 2019-07-16 16:10:55 -05:00
BWS Systems
53208ddabc missed use https in the response of the upnp listener 2019-07-15 08:38:07 -05:00
3 changed files with 38 additions and 30 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId> <groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId> <artifactId>ha-bridge</artifactId>
<version>5.3.0RC10</version> <version>5.3.0RC12</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>

View File

@@ -112,7 +112,7 @@ public class HABridge {
// start the upnp ssdp discovery listener // start the upnp ssdp discovery listener
theUpnpListener = null; theUpnpListener = null;
try { try {
theUpnpListener = new UpnpListener(bridgeSettings.getBridgeSettingsDescriptor(), bridgeSettings.getBridgeControl(), udpSender); theUpnpListener = new UpnpListener(bridgeSettings, bridgeSettings.getBridgeControl(), udpSender);
} catch (IOException e) { } catch (IOException e) {
log.error("Could not initialize UpnpListener, exiting....", e); log.error("Could not initialize UpnpListener, exiting....", e);
theUpnpListener = null; theUpnpListener = null;

View File

@@ -4,7 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.bwssystems.HABridge.BridgeControlDescriptor; import com.bwssystems.HABridge.BridgeControlDescriptor;
import com.bwssystems.HABridge.BridgeSettingsDescriptor; import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.HABridge.Configuration; import com.bwssystems.HABridge.Configuration;
import com.bwssystems.HABridge.api.hue.HueConstants; import com.bwssystems.HABridge.api.hue.HueConstants;
import com.bwssystems.HABridge.api.hue.HuePublicConfig; import com.bwssystems.HABridge.api.hue.HuePublicConfig;
@@ -34,82 +34,90 @@ public class UpnpListener {
private BridgeControlDescriptor bridgeControl; private BridgeControlDescriptor bridgeControl;
private String bridgeId; private String bridgeId;
private String bridgeSNUUID; private String bridgeSNUUID;
private String httpType;
private HuePublicConfig aHueConfig; private HuePublicConfig aHueConfig;
private Integer theUpnpSendDelay; private Integer theUpnpSendDelay;
private String responseTemplate1 = "HTTP/1.1 200 OK\r\n" + private String responseTemplate1 = "HTTP/1.1 200 OK\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"EXT:\r\n" + "EXT:\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"HUE-BRIDGEID: %s\r\n" + "hue-bridgeid: %s\r\n" +
"ST: upnp:rootdevice\r\n" + "ST: upnp:rootdevice\r\n" +
"USN: uuid:" + HueConstants.UUID_PREFIX + "%s::upnp:rootdevice\r\n\r\n"; "USN: uuid:" + HueConstants.UUID_PREFIX + "%s::upnp:rootdevice\r\n\r\n";
private String responseTemplate2 = "HTTP/1.1 200 OK\r\n" + private String responseTemplate2 = "HTTP/1.1 200 OK\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"EXT:\r\n" + "EXT:\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"HUE-BRIDGEID: %s\r\n" + "hue-bridgeid: %s\r\n" +
"ST: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n" + "ST: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n" +
"USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n"; "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
private String responseTemplate3 = "HTTP/1.1 200 OK\r\n" + private String responseTemplate3 = "HTTP/1.1 200 OK\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"EXT:\r\n" + "EXT:\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"HUE-BRIDGEID: %s\r\n" + "hue-bridgeid: %s\r\n" +
"ST: urn:schemas-upnp-org:device:basic:1\r\n" + "ST: urn:schemas-upnp-org:device:basic:1\r\n" +
"USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n"; "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
private String notifyTemplate1 = "NOTIFY * HTTP/1.1\r\n" + private String notifyTemplate1 = "NOTIFY * HTTP/1.1\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"NTS: ssdp:alive\r\n" + "NTS: ssdp:alive\r\n" +
"HUE-BRIDGEID: %s\r\n" + "hue-bridgeid: %s\r\n" +
"NT: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n" + "NT: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n" +
"USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n"; "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
private String notifyTemplate2 = "NOTIFY * HTTP/1.1\r\n" + private String notifyTemplate2 = "NOTIFY * HTTP/1.1\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"NTS: ssdp:alive\r\n" + "HUE-BRIDGEID: %s\r\n" + "NTS: ssdp:alive\r\n" +
"hue-bridgeid: %s\r\n" +
"NT: upnp:rootdevice\r\n" + "NT: upnp:rootdevice\r\n" +
"USN: uuid:" + HueConstants.UUID_PREFIX + "%s::upnp:rootdevice\r\n\r\n"; "USN: uuid:" + HueConstants.UUID_PREFIX + "%s::upnp:rootdevice\r\n\r\n";
private String notifyTemplate3 = "NOTIFY * HTTP/1.1\r\n" + private String notifyTemplate3 = "NOTIFY * HTTP/1.1\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"NTS: ssdp:alive\r\n" + "NTS: ssdp:alive\r\n" +
"HUE-BRIDGEID: %s\r\n" + "hue-bridgeid: %s\r\n" +
"NT: urn:schemas-upnp-org:device:basic:1\r\n" + "NT: urn:schemas-upnp-org:device:basic:1\r\n" +
"USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n"; "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
public UpnpListener(BridgeSettingsDescriptor theSettings, BridgeControlDescriptor theControl, public UpnpListener(BridgeSettings theSettings, BridgeControlDescriptor theControl,
UDPDatagramSender aUdpDatagramSender) throws IOException { UDPDatagramSender aUdpDatagramSender) throws IOException {
super(); super();
theUDPDatagramSender = aUdpDatagramSender; theUDPDatagramSender = aUdpDatagramSender;
upnpMulticastSocket = null; upnpMulticastSocket = null;
httpServerPort = Integer.valueOf(theSettings.getServerPort()); httpServerPort = Integer.valueOf(theSettings.getBridgeSettingsDescriptor().getServerPort());
upnpConfigIP = theSettings.getUpnpConfigAddress(); upnpConfigIP = theSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress();
// strict = theSettings.isUpnpStrict(); // strict = theSettings.isUpnpStrict();
upnpOriginal = theSettings.isUpnporiginal(); upnpOriginal = theSettings.getBridgeSettingsDescriptor().isUpnporiginal();
traceupnp = theSettings.isTraceupnp(); traceupnp = theSettings.getBridgeSettingsDescriptor().isTraceupnp();
useUpnpIface = theSettings.isUseupnpiface(); useUpnpIface = theSettings.getBridgeSettingsDescriptor().isUseupnpiface();
theUpnpSendDelay = theSettings.getUpnpsenddelay(); theUpnpSendDelay = theSettings.getBridgeSettingsDescriptor().getUpnpsenddelay();
bridgeControl = theControl; bridgeControl = theControl;
aHueConfig = HuePublicConfig.createConfig("temp", upnpConfigIP, HueConstants.HUB_VERSION, aHueConfig = HuePublicConfig.createConfig("temp", upnpConfigIP, HueConstants.HUB_VERSION,
theSettings.getHubmac()); theSettings.getBridgeSettingsDescriptor().getHubmac());
bridgeId = aHueConfig.getBridgeid(); bridgeId = aHueConfig.getBridgeid();
bridgeSNUUID = aHueConfig.getSNUUIDFromMac(); bridgeSNUUID = aHueConfig.getSNUUIDFromMac();
if(theSettings.getBridgeSecurity().isUseHttps()) {
httpType = "https";
} else {
httpType = "http";
}
try { try {
if (useUpnpIface) if (useUpnpIface)
upnpMulticastSocket = new MulticastSocket( upnpMulticastSocket = new MulticastSocket(
@@ -322,7 +330,7 @@ public class UpnpListener {
} }
discoveryResponse = String.format(responseTemplate1, Configuration.UPNP_MULTICAST_ADDRESS, discoveryResponse = String.format(responseTemplate1, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, httpType, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: send upnp discovery template 1 with response address: " + httpLocationAddress + ":" log.info("Traceupnp: send upnp discovery template 1 with response address: " + httpLocationAddress + ":"
+ httpServerPort + " to address: " + requester + ":" + sourcePort); + httpServerPort + " to address: " + requester + ":" + sourcePort);
@@ -337,7 +345,7 @@ public class UpnpListener {
// noop // noop
} }
discoveryResponse = String.format(responseTemplate2, Configuration.UPNP_MULTICAST_ADDRESS, discoveryResponse = String.format(responseTemplate2, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID, Configuration.UPNP_DISCOVERY_PORT, httpType, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID,
bridgeSNUUID); bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: send upnp discovery template 2 with response address: " + httpLocationAddress + ":" log.info("Traceupnp: send upnp discovery template 2 with response address: " + httpLocationAddress + ":"
@@ -352,8 +360,8 @@ public class UpnpListener {
} catch (InterruptedException e) { } catch (InterruptedException e) {
// noop // noop
} }
discoveryResponse = String.format(responseTemplate3, Configuration.UPNP_MULTICAST_ADDRESS, discoveryResponse = String.format(responseTemplate3,Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, httpType, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: send upnp discovery template 3 with response address: " + httpLocationAddress + ":" log.info("Traceupnp: send upnp discovery template 3 with response address: " + httpLocationAddress + ":"
+ httpServerPort + " to address: " + requester + ":" + sourcePort); + httpServerPort + " to address: " + requester + ":" + sourcePort);
@@ -384,7 +392,7 @@ public class UpnpListener {
} }
notifyData = String.format(notifyTemplate1, Configuration.UPNP_MULTICAST_ADDRESS, notifyData = String.format(notifyTemplate1, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, httpType, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: sendUpnpNotify notifyTemplate1"); log.info("Traceupnp: sendUpnpNotify notifyTemplate1");
} }
@@ -398,7 +406,7 @@ public class UpnpListener {
} }
notifyData = String.format(notifyTemplate2, Configuration.UPNP_MULTICAST_ADDRESS, notifyData = String.format(notifyTemplate2, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, httpType, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: sendUpnpNotify notifyTemplate2"); log.info("Traceupnp: sendUpnpNotify notifyTemplate2");
} }
@@ -412,7 +420,7 @@ public class UpnpListener {
} }
notifyData = String.format(notifyTemplate3, Configuration.UPNP_MULTICAST_ADDRESS, notifyData = String.format(notifyTemplate3, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, httpType, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: sendUpnpNotify notifyTemplate3"); log.info("Traceupnp: sendUpnpNotify notifyTemplate3");
} }