mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-21 17:18:49 +00:00
Added settings for strict upnp mode of checking ig it is a request for a
hue or not before responding. Updated Readme
This commit is contained in:
@@ -6,6 +6,7 @@ public class BridgeSettings {
|
||||
private String upnpresponseport;
|
||||
private String upnpdevicedb;
|
||||
private String veraaddress;
|
||||
private boolean upnpStrict;
|
||||
|
||||
public String getUpnpConfigAddress() {
|
||||
return upnpconfigaddress;
|
||||
@@ -37,6 +38,11 @@ public class BridgeSettings {
|
||||
public void setVeraAddress(String veraAddress) {
|
||||
this.veraaddress = veraAddress;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isUpnpStrict() {
|
||||
return upnpStrict;
|
||||
}
|
||||
public void setUpnpStrict(boolean upnpStrict) {
|
||||
this.upnpStrict = upnpStrict;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.bwssystems.HABridge.devicemanagmeent.*;
|
||||
import com.bwssystems.HABridge.hue.HueMulator;
|
||||
import com.bwssystems.HABridge.upnp.UpnpListener;
|
||||
import com.bwssystems.HABridge.upnp.UpnpSettingsResource;
|
||||
import com.bwssystems.vera.VeraInfo;
|
||||
|
||||
public class HABridge {
|
||||
|
||||
@@ -55,6 +54,7 @@ public class HABridge {
|
||||
bridgeSettings.setUpnpDeviceDb(System.getProperty("upnp.device.db", "data/device.db"));
|
||||
bridgeSettings.setUpnpResponsePort(System.getProperty("upnp.response.port", "50000"));
|
||||
bridgeSettings.setVeraAddress(System.getProperty("vera.address", "192.168.1.100"));
|
||||
bridgeSettings.setUpnpStrict(Boolean.parseBoolean(System.getProperty("upnp.strict", "true")));
|
||||
|
||||
// sparkjava config directive to set ip address for the web server to listen on
|
||||
// ipAddress("0.0.0.0"); // not used
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
package com.bwssystems.HABridge.api;
|
||||
|
||||
/**
|
||||
* Created by arm on 4/13/15.
|
||||
*/
|
||||
public class Device {
|
||||
private String name;
|
||||
private String deviceType;
|
||||
private String offUrl;
|
||||
private String onUrl;
|
||||
private String httpVerb;
|
||||
private String contentType;
|
||||
private String contentBody;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public String getOffUrl() {
|
||||
return offUrl;
|
||||
}
|
||||
|
||||
public void setOffUrl(String offUrl) {
|
||||
this.offUrl = offUrl;
|
||||
}
|
||||
|
||||
public String getOnUrl() {
|
||||
return onUrl;
|
||||
}
|
||||
|
||||
public void setOnUrl(String onUrl) {
|
||||
this.onUrl = onUrl;
|
||||
}
|
||||
|
||||
public String getHttpVerb() {
|
||||
return httpVerb;
|
||||
}
|
||||
|
||||
public void setHttpVerb(String httpVerb) {
|
||||
this.httpVerb = httpVerb;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getContentBody() {
|
||||
return contentBody;
|
||||
}
|
||||
|
||||
public void setContentBody(String contentBody) {
|
||||
this.contentBody = contentBody;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,12 +22,15 @@ public class UpnpListener {
|
||||
private int httpServerPort;
|
||||
|
||||
private String responseAddress;
|
||||
|
||||
private boolean strict;
|
||||
|
||||
public UpnpListener(BridgeSettings theSettings) {
|
||||
super();
|
||||
upnpResponsePort = Integer.valueOf(theSettings.getUpnpResponsePort());
|
||||
httpServerPort = Integer.valueOf(theSettings.getServerPort());
|
||||
responseAddress = theSettings.getUpnpConfigAddress();
|
||||
strict = theSettings.isUpnpStrict();
|
||||
}
|
||||
|
||||
public void startListening(){
|
||||
@@ -63,7 +66,8 @@ public class UpnpListener {
|
||||
DatagramPacket packet = new DatagramPacket(buf, buf.length);
|
||||
upnpMulticastSocket.receive(packet);
|
||||
String packetString = new String(packet.getData());
|
||||
log.debug("Got SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + " body : " + packetString);
|
||||
if(packetString != null && packetString.startsWith("M-SEARCH * HTTP/1.1"))
|
||||
log.debug("Got SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + " body : " + packetString);
|
||||
if(isSSDPDiscovery(packetString)){
|
||||
sendUpnpResponse(responseSocket, packet.getAddress(), packet.getPort());
|
||||
}
|
||||
@@ -85,9 +89,11 @@ public class UpnpListener {
|
||||
protected boolean isSSDPDiscovery(String body){
|
||||
// log.debug("Check if this is a MAN ssdp-discover packet for a upnp basic device: " + body);
|
||||
//Only respond to discover request for upnp basic device from echo, the others are for the wemo
|
||||
// other check: && body.contains("ST: urn:schemas-upnp-org:device:basic:1")
|
||||
if(body != null && body.startsWith("M-SEARCH * HTTP/1.1") && body.contains("MAN: \"ssdp:discover\"")){
|
||||
return true;
|
||||
if(strict && body.contains("ST: urn:schemas-upnp-org:device:basic:1"))
|
||||
return true;
|
||||
else if (!strict)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user