Skip to content
Browse files

Protecting access to soapaction, which can be null.

  • Loading branch information...
1 parent 9022443 commit a0b18940376058be913ba17e1e571204b58de3c1 @Raptor399 Raptor399 committed
Showing with 54 additions and 45 deletions.
  1. +14 −11 src/main/java/net/pms/network/Request.java
  2. +40 −34 src/main/java/net/pms/network/RequestV2.java
View
25 src/main/java/net/pms/network/Request.java
@@ -393,7 +393,7 @@ public void answer(OutputStream output, StartStopListenerDelegate startStopListe
response.append(CRLF);
} else if (method.equals("POST") && argument.endsWith("upnp/control/connection_manager")) {
output(output, CONTENT_TYPE_UTF8);
- if (soapaction.indexOf("ConnectionManager:1#GetProtocolInfo") > -1) {
+ if (soapaction != null && soapaction.indexOf("ConnectionManager:1#GetProtocolInfo") > -1) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -404,8 +404,11 @@ public void answer(OutputStream output, StartStopListenerDelegate startStopListe
response.append(CRLF);
}
} else if (method.equals("SUBSCRIBE")) {
- if(soapaction==null) //ignore this
+ if (soapaction == null) {
+ // ignore this
return;
+ }
+
output(output, CONTENT_TYPE_UTF8);
output(output,"Content-Length: 0");
output(output,"Connection: close");
@@ -452,7 +455,7 @@ else if(argument.contains("content_directory")) {
}
} else if (method.equals("POST") && argument.endsWith("upnp/control/content_directory")) {
output(output, CONTENT_TYPE_UTF8);
- if (soapaction.indexOf("ContentDirectory:1#GetSystemUpdateID") > -1) {
+ if (soapaction != null && soapaction.indexOf("ContentDirectory:1#GetSystemUpdateID") > -1) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -465,7 +468,7 @@ else if(argument.contains("content_directory")) {
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
- } else if (soapaction.indexOf("ContentDirectory:1#GetSortCapabilities") > -1) {
+ } else if (soapaction != null && soapaction.indexOf("ContentDirectory:1#GetSortCapabilities") > -1) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -474,7 +477,7 @@ else if(argument.contains("content_directory")) {
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
- } else if (soapaction.indexOf("ContentDirectory:1#X_GetFeatureList") > -1) { // Added for Samsung 2012 TVs
+ } else if (soapaction != null && soapaction.indexOf("ContentDirectory:1#X_GetFeatureList") > -1) { // Added for Samsung 2012 TVs
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -483,7 +486,7 @@ else if(argument.contains("content_directory")) {
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
- } else if (soapaction.indexOf("ContentDirectory:1#GetSearchCapabilities") > -1) {
+ } else if (soapaction != null && soapaction.indexOf("ContentDirectory:1#GetSearchCapabilities") > -1) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -492,8 +495,8 @@ else if(argument.contains("content_directory")) {
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
- } else if (soapaction.contains("ContentDirectory:1#Browse") || soapaction.contains("ContentDirectory:1#Search")) {
- //LOGGER.trace(content);
+ } else if (soapaction != null && (soapaction.contains("ContentDirectory:1#Browse")
+ || soapaction.contains("ContentDirectory:1#Search"))) {
objectID = getEnclosingValue(content, "<ObjectID>", "</ObjectID>");
String containerID = null;
if ((objectID == null || objectID.length() == 0) && xbox) {
@@ -519,7 +522,7 @@ else if(argument.contains("content_directory")) {
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
- if (soapaction.contains("ContentDirectory:1#Search")) {
+ if (soapaction != null && soapaction.contains("ContentDirectory:1#Search")) {
response.append(HTTPXMLHelper.SEARCHRESPONSE_HEADER);
} else {
response.append(HTTPXMLHelper.BROWSERESPONSE_HEADER);
@@ -529,7 +532,7 @@ else if(argument.contains("content_directory")) {
response.append(HTTPXMLHelper.DIDL_HEADER);
- if (soapaction.contains("ContentDirectory:1#Search")) {
+ if (soapaction != null && soapaction.contains("ContentDirectory:1#Search")) {
browseFlag = "BrowseDirectChildren";
}
@@ -622,7 +625,7 @@ else if(browseFlag!=null && browseFlag.equals("BrowseDirectChildren"))
}
response.append("</UpdateID>");
response.append(CRLF);
- if (soapaction.contains("ContentDirectory:1#Search")) {
+ if (soapaction != null && soapaction.contains("ContentDirectory:1#Search")) {
response.append(HTTPXMLHelper.SEARCHRESPONSE_FOOTER);
} else {
response.append(HTTPXMLHelper.BROWSERESPONSE_FOOTER);
View
74 src/main/java/net/pms/network/RequestV2.java
@@ -508,7 +508,7 @@ public ChannelFuture answer(
response.append(CRLF);
} else if (method.equals("POST") && argument.endsWith("upnp/control/connection_manager")) {
output.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/xml; charset=\"utf-8\"");
- if (soapaction.indexOf("ConnectionManager:1#GetProtocolInfo") > -1) {
+ if (soapaction != null && soapaction.indexOf("ConnectionManager:1#GetProtocolInfo") > -1) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -520,7 +520,7 @@ public ChannelFuture answer(
}
} else if (method.equals("POST") && argument.endsWith("upnp/control/content_directory")) {
output.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/xml; charset=\"utf-8\"");
- if (soapaction.indexOf("ContentDirectory:1#GetSystemUpdateID") > -1) {
+ if (soapaction != null && soapaction.indexOf("ContentDirectory:1#GetSystemUpdateID") > -1) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -533,7 +533,7 @@ public ChannelFuture answer(
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
- } else if (soapaction.indexOf("ContentDirectory:1#X_GetFeatureList") > -1) { // Added for Samsung 2012 TVs
+ } else if (soapaction != null && soapaction.indexOf("ContentDirectory:1#X_GetFeatureList") > -1) { // Added for Samsung 2012 TVs
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -542,7 +542,7 @@ public ChannelFuture answer(
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
- } else if (soapaction.indexOf("ContentDirectory:1#GetSortCapabilities") > -1) {
+ } else if (soapaction != null && soapaction.indexOf("ContentDirectory:1#GetSortCapabilities") > -1) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -551,7 +551,7 @@ public ChannelFuture answer(
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
- } else if (soapaction.indexOf("ContentDirectory:1#GetSearchCapabilities") > -1) {
+ } else if (soapaction != null && soapaction.indexOf("ContentDirectory:1#GetSearchCapabilities") > -1) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
@@ -560,7 +560,8 @@ public ChannelFuture answer(
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
- } else if (soapaction.contains("ContentDirectory:1#Browse") || soapaction.contains("ContentDirectory:1#Search")) {
+ } else if (soapaction != null && (soapaction.contains("ContentDirectory:1#Browse")
+ || soapaction.contains("ContentDirectory:1#Search"))) {
objectID = getEnclosingValue(content, "<ObjectID>", "</ObjectID>");
String containerID = null;
if ((objectID == null || objectID.length() == 0) && xbox) {
@@ -589,7 +590,7 @@ public ChannelFuture answer(
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
- if (soapaction.contains("ContentDirectory:1#Search")) {
+ if (soapaction != null && soapaction.contains("ContentDirectory:1#Search")) {
response.append(HTTPXMLHelper.SEARCHRESPONSE_HEADER);
} else {
response.append(HTTPXMLHelper.BROWSERESPONSE_HEADER);
@@ -599,7 +600,7 @@ public ChannelFuture answer(
response.append(HTTPXMLHelper.RESULT_HEADER);
response.append(HTTPXMLHelper.DIDL_HEADER);
- if (soapaction.contains("ContentDirectory:1#Search")) {
+ if (soapaction != null && soapaction.contains("ContentDirectory:1#Search")) {
browseFlag = "BrowseDirectChildren";
}
@@ -691,7 +692,7 @@ public ChannelFuture answer(
}
response.append("</UpdateID>");
response.append(CRLF);
- if (soapaction.contains("ContentDirectory:1#Search")) {
+ if (soapaction != null && soapaction.contains("ContentDirectory:1#Search")) {
response.append(HTTPXMLHelper.SEARCHRESPONSE_FOOTER);
} else {
response.append(HTTPXMLHelper.BROWSERESPONSE_FOOTER);
@@ -704,31 +705,36 @@ public ChannelFuture answer(
} else if (method.equals("SUBSCRIBE")) {
output.setHeader("SID", PMS.get().usn());
output.setHeader("TIMEOUT", "Second-1800");
- String cb = soapaction.replace("<", "").replace(">", "");
-
- try {
- URL soapActionUrl = new URL(cb);
- String addr = soapActionUrl.getHost();
- int port = soapActionUrl.getPort();
- Socket sock = new Socket(addr,port);
- OutputStream out = sock.getOutputStream();
-
- out.write(("NOTIFY /" + argument + " HTTP/1.1").getBytes());
- out.write(CRLF.getBytes());
- out.write(("SID: " + PMS.get().usn()).getBytes());
- out.write(CRLF.getBytes());
- out.write(("SEQ: " + 0).getBytes());
- out.write(CRLF.getBytes());
- out.write(("NT: upnp:event").getBytes());
- out.write(CRLF.getBytes());
- out.write(("NTS: upnp:propchange").getBytes());
- out.write(CRLF.getBytes());
- out.write(("HOST: " + addr + ":" + port).getBytes());
- out.write(CRLF.getBytes());
- out.flush();
- out.close();
- } catch (MalformedURLException ex) {
- LOGGER.debug("Cannot parse address and port from soap action \"" + soapaction + "\"", ex);
+
+ if (soapaction != null) {
+ String cb = soapaction.replace("<", "").replace(">", "");
+
+ try {
+ URL soapActionUrl = new URL(cb);
+ String addr = soapActionUrl.getHost();
+ int port = soapActionUrl.getPort();
+ Socket sock = new Socket(addr,port);
+ OutputStream out = sock.getOutputStream();
+
+ out.write(("NOTIFY /" + argument + " HTTP/1.1").getBytes());
+ out.write(CRLF.getBytes());
+ out.write(("SID: " + PMS.get().usn()).getBytes());
+ out.write(CRLF.getBytes());
+ out.write(("SEQ: " + 0).getBytes());
+ out.write(CRLF.getBytes());
+ out.write(("NT: upnp:event").getBytes());
+ out.write(CRLF.getBytes());
+ out.write(("NTS: upnp:propchange").getBytes());
+ out.write(CRLF.getBytes());
+ out.write(("HOST: " + addr + ":" + port).getBytes());
+ out.write(CRLF.getBytes());
+ out.flush();
+ out.close();
+ } catch (MalformedURLException ex) {
+ LOGGER.debug("Cannot parse address and port from soap action \"" + soapaction + "\"", ex);
+ }
+ } else {
+ LOGGER.debug("Expected soap action in request");
}
if (argument.contains("connection_manager")) {

0 comments on commit a0b1894

Please sign in to comment.
Something went wrong with that request. Please try again.