propagate from branch 'i2p.i2p.zzz.upnp' (head 8719ae9a1473d748947733043f465a4589cc23d5)

to branch 'i2p.i2p' (head 5ae9785903c4b9452f4241758e8ddc1338e94574)
This commit is contained in:
zzz
2015-03-18 12:13:41 +00:00
86 changed files with 6801 additions and 6380 deletions

View File

@@ -69,16 +69,15 @@ public class HTTP
public static final String CONTENT_TYPE = "Content-Type";
public static final String CHARSET = "charset";
public static final String CONTENT_LENGTH = "Content-Length";
public static final String CONTENT_LANGUAGE = "Content-Language";
public static final String CONTENT_RANGE = "Content-Range";
public static final String CONTENT_RANGE_BYTES = "bytes";
// Thanks for Brent Hills (10/20/04)
public static final String RANGE = "Range";
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
public static final String CHUNKED = "Chunked";
public static final String LOCATION = "Location";
public static final String SERVER = "Server";
public static final String ST = "ST";
public static final String MX = "MX";
public static final String MAN = "MAN";
@@ -90,6 +89,9 @@ public class HTTP
public static final String SEQ = "SEQ";
public final static String CALLBACK = "CALLBACK";
public final static String TIMEOUT = "TIMEOUT";
public final static String BOOTID_UPNP_ORG = "BOOTID.UPNP.ORG";
// Thanks for Brent Hills (10/20/04)
public final static String MYNAME = "MYNAME";

View File

@@ -610,6 +610,20 @@ public class HTTPPacket
return getHeaderValue(HTTP.CONTENT_TYPE);
}
////////////////////////////////////////////////
// ContentLanguage
////////////////////////////////////////////////
public void setContentLanguage(String code)
{
setHeader(HTTP.CONTENT_LANGUAGE, code);
}
public String getContentLanguage()
{
return getHeaderValue(HTTP.CONTENT_LANGUAGE);
}
////////////////////////////////////////////////
// Charset
////////////////////////////////////////////////

View File

@@ -34,21 +34,21 @@ public class SOAPResponse extends HTTPResponse
public SOAPResponse()
{
setRootNode(SOAP.createEnvelopeBodyNode());
setContentType(XML.CONTENT_TYPE);
setContentType(XML.DEFAULT_CONTENT_TYPE);
}
public SOAPResponse(HTTPResponse httpRes)
{
super(httpRes);
setRootNode(SOAP.createEnvelopeBodyNode());
setContentType(XML.CONTENT_TYPE);
setContentType(XML.DEFAULT_CONTENT_TYPE);
}
public SOAPResponse(SOAPResponse soapRes)
{
super(soapRes);
setEnvelopeNode(soapRes.getEnvelopeNode());
setContentType(XML.CONTENT_TYPE);
setContentType(XML.DEFAULT_CONTENT_TYPE);
}
////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@@ -47,6 +47,10 @@ public class Icon
iconNode = node;
}
public Icon() {
this(new Node(ELEM_NAME));
}
////////////////////////////////////////////////
// isIconNode
////////////////////////////////////////////////
@@ -72,6 +76,14 @@ public class Icon
return getIconNode().getNodeValue(MIME_TYPE);
}
public boolean hasMimeType()
{
String iconMimeType = getMimeType();
if (iconMimeType == null)
return false;
return (0 < iconMimeType.length()) ? true : false;
}
////////////////////////////////////////////////
// width
////////////////////////////////////////////////
@@ -139,9 +151,21 @@ public class Icon
getIconNode().setNode(DEPTH, value);
}
public String getDepth()
public void setDepth(int value)
{
return getIconNode().getNodeValue(DEPTH);
try {
setDepth(Integer.toString(value));
}
catch (Exception e) {};
}
public int getDepth()
{
try {
return Integer.parseInt(getIconNode().getNodeValue(DEPTH));
}
catch (Exception e) {};
return 0;
}
////////////////////////////////////////////////
@@ -160,6 +184,24 @@ public class Icon
return getIconNode().getNodeValue(URL);
}
public boolean hasURL()
{
String iconURL = getURL();
if (iconURL == null)
return false;
return (0 < iconURL.length()) ? true : false;
}
public boolean isURL(String url)
{
if (url == null)
return false;
String iconURL = getURL();
if (iconURL == null)
return false;
return iconURL.equals(url);
}
////////////////////////////////////////////////
// userData
////////////////////////////////////////////////
@@ -175,4 +217,25 @@ public class Icon
{
return userData;
}
////////////////////////////////////////////////
// Bytes
////////////////////////////////////////////////
private byte bytes[] = null;
public void setBytes(byte data[])
{
bytes = data;
}
public boolean hasBytes()
{
return (bytes != null) ? true : false;
}
public byte[]getBytes()
{
return bytes;
}
}

View File

@@ -142,8 +142,8 @@ public class Service
sp.addNode(m);
//Node scpd = new Node(SCPD_ROOTNODE,SCPD_ROOTNODE_NS); wrong!
Node scpd = new Node(SCPD_ROOTNODE); // better (twa)
scpd.addAttribute("xmlns",SCPD_ROOTNODE_NS); // better (twa)
Node scpd = new Node(SCPD_ROOTNODE);
scpd.addAttribute("xmlns",SCPD_ROOTNODE_NS);
scpd.addNode(sp);
getServiceData().setSCPDNode(scpd);
}
@@ -241,6 +241,31 @@ public class Service
return getServiceNode().getNodeValue(SERVICE_ID);
}
////////////////////////////////////////////////
// configID
////////////////////////////////////////////////
private final static String CONFIG_ID = "configId";
public void updateConfigId()
{
Node scpdNode = getSCPDNode();
if (scpdNode == null)
return;
String scpdXml = scpdNode.toString();
int configId = UPnP.caluculateConfigId(scpdXml);
scpdNode.setAttribute(CONFIG_ID, configId);
}
public int getConfigId()
{
Node scpdNode = getSCPDNode();
if (scpdNode == null)
return 0;
return scpdNode.getAttributeIntegerValue(CONFIG_ID);
}
////////////////////////////////////////////////
// isURL
////////////////////////////////////////////////
@@ -340,6 +365,7 @@ public class Service
catch (ParserException e) {
throw new InvalidDescriptionException(e);
}
return true;
}
@@ -349,8 +375,10 @@ public class Service
Node scpdNode = parser.parse(file);
if (scpdNode == null)
return false;
ServiceData data = getServiceData();
data.setSCPDNode(scpdNode);
return true;
}
@@ -363,20 +391,22 @@ public class Service
Node scpdNode = parser.parse(input);
if (scpdNode == null)
return false;
ServiceData data = getServiceData();
data.setSCPDNode(scpdNode);
return true;
}
public void setDescriptionURL(String value)
{
getServiceData().setDescriptionURL(value);
getServiceData().setDescriptionURL(value);
}
public String getDescriptionURL()
{
return getServiceData().getDescriptionURL();
return getServiceData().getDescriptionURL();
}
@@ -406,6 +436,9 @@ public class Service
String scpdURLStr = getSCPDURL();
/****
* I2P - no, dont attempt to load local file
*
// Thanks for Robin V. (Sep 18, 2010)
String rootDevPath = rootDev.getDescriptionFilePath();
if(rootDevPath!=null) {
@@ -425,6 +458,7 @@ public class Service
}
}
}
****/
try {
URL scpdUrl = new URL(rootDev.getAbsoluteURL(scpdURLStr));
@@ -434,8 +468,14 @@ public class Service
return scpdNode;
}
}
catch (Exception e) {}
catch (Exception e) {
// I2P
Debug.warning(e);
}
/****
* I2P - no, dont attempt to load local file
*
String newScpdURLStr = rootDev.getDescriptionFilePath() + HTTP.toRelativeURL(scpdURLStr);
try {
scpdNode = getSCPDNode(new File(newScpdURLStr));
@@ -444,6 +484,7 @@ public class Service
catch (Exception e) {
Debug.warning(e);
}
****/
return null;
}

View File

@@ -45,7 +45,7 @@ public class UPnP
public final static String XML_CLASS_PROPERTTY="cyberlink.upnp.xml.parser";
public final static String NAME = "CyberLinkJava";
public final static String VERSION = "1.8";
public final static String VERSION = "3.0";
// I2P was 100
public final static int SERVER_RETRY_COUNT = 4;
@@ -64,6 +64,8 @@ public class UPnP
public final static String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
public final static int CONFIGID_UPNP_ORG_MAX = 16777215;
////////////////////////////////////////////////
// Enable / Disable
////////////////////////////////////////////////
@@ -190,6 +192,34 @@ public class UPnP
toUUID((int)((time2 >> 32) | 0xE000) & 0xFFFF);
}
////////////////////////////////////////////////
// BootId
////////////////////////////////////////////////
public static final int createBootId()
{
return (int)(System.currentTimeMillis() / 1000L);
}
////////////////////////////////////////////////
// ConfigId
////////////////////////////////////////////////
public static final int caluculateConfigId(String configXml)
{
if (configXml == null)
return 0;
int configId = 0;
int configLen = configXml.length();
for (int n=0; n<configLen; n++) {
configId += configXml.codePointAt(n);
if (configId < CONFIGID_UPNP_ORG_MAX)
continue;
configId = configId % CONFIGID_UPNP_ORG_MAX;
}
return configId;
}
////////////////////////////////////////////////
// XML Parser
////////////////////////////////////////////////

View File

@@ -0,0 +1,23 @@
/******************************************************************
*
* CyberUPnP for Java
*
* Copyright (C) Satoshi Konno 2002
*
* File: DeviceNotifyListener.java
*
* Revision;
*
* 11/18/02
* - first revision.
*
******************************************************************/
package org.cybergarage.upnp.device;
import org.cybergarage.http.HTTPRequest;
public interface PresentationListener
{
public void httpRequestRecieved(HTTPRequest httpReq);
}

View File

@@ -130,7 +130,7 @@ public class NotifyRequest extends SOAPRequest
setSID(sid);
setSEQ(notifyCnt);
setContentType(XML.CONTENT_TYPE);
setContentType(XML.DEFAULT_CONTENT_TYPE);
Node propSetNode = createPropertySetNode(varName, value);
setContent(propSetNode);

View File

@@ -108,4 +108,18 @@ public class SSDPRequest extends HTTPRequest
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
return SSDP.getLeaseTime(cacheCtrl);
}
////////////////////////////////////////////////
// BootId
////////////////////////////////////////////////
public void setBootId(int bootId)
{
setHeader(HTTP.BOOTID_UPNP_ORG, bootId);
}
public int getBootId()
{
return getIntegerHeaderValue(HTTP.BOOTID_UPNP_ORG);
}
}

View File

@@ -115,6 +115,20 @@ public class SSDPResponse extends HTTPResponse
return SSDP.getLeaseTime(cacheCtrl);
}
////////////////////////////////////////////////
// BootId
////////////////////////////////////////////////
public void setBootId(int bootId)
{
setHeader(HTTP.BOOTID_UPNP_ORG, bootId);
}
public int getBootId()
{
return getIntegerHeaderValue(HTTP.BOOTID_UPNP_ORG);
}
////////////////////////////////////////////////
// getHeader (Override)
////////////////////////////////////////////////

View File

@@ -61,9 +61,6 @@ public class SSDPSearchSocketList extends Vector<SSDPSearchSocket>
this.multicastIPv6 = multicastIPv6;
}
////////////////////////////////////////////////
// Methods
////////////////////////////////////////////////

View File

@@ -18,7 +18,6 @@ package org.cybergarage.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Locale;
public final class FileUtil
{
@@ -73,7 +72,7 @@ public final class FileUtil
{
if (StringUtil.hasData(name) == false)
return false;
String lowerName = name.toLowerCase(Locale.US);
String lowerName = name.toLowerCase();
return lowerName.endsWith("xml");
}
}

View File

@@ -26,10 +26,17 @@ public class Attribute
public Attribute(String name, String value)
{
this();
setName(name);
setValue(value);
}
public Attribute(Attribute otherAttr)
{
this();
set(otherAttr);
}
////////////////////////////////////////////////
// name
////////////////////////////////////////////////
@@ -57,5 +64,15 @@ public class Attribute
{
return value;
}
////////////////////////////////////////////////
// set
////////////////////////////////////////////////
public void set(Attribute otherAttr)
{
setName(otherAttr.getName());
setValue(otherAttr.getValue());
}
}

View File

@@ -61,6 +61,12 @@ public class Node
setName(ns, name);
}
public Node(Node otherNode)
{
this();
set(otherNode);
}
////////////////////////////////////////////////
// parent node
////////////////////////////////////////////////
@@ -189,6 +195,11 @@ public class Node
return removeAttribute(getAttribute(name));
}
public void removeAllAttributes()
{
attrList.clear();
}
public boolean hasAttributes()
{
if (0 < getNAttributes())
@@ -239,6 +250,51 @@ public class Node
setAttribute("xmlns:" + ns, value);
}
////////////////////////////////////////////////
// set
////////////////////////////////////////////////
public boolean set(Node otherNode) {
if (otherNode == null)
return false;
setName(otherNode.getName());
setValue(otherNode.getValue());
removeAllAttributes();
int nOtherAttributes = otherNode.getNAttributes();
for (int n=0; n<nOtherAttributes; n++) {
Attribute otherAttr = otherNode.getAttribute(n);
Attribute thisAttr = new Attribute(otherAttr);
addAttribute(thisAttr);
}
removeAllNodes();
int nOtherChildNodes = otherNode.getNNodes();
for (int n=0; n<nOtherChildNodes; n++) {
Node otherChildNode = otherNode.getNode(n);
Node thisChildNode = new Node();
thisChildNode.set(otherChildNode);
addNode(thisChildNode);
}
return true;
}
////////////////////////////////////////////////
// equals
////////////////////////////////////////////////
public boolean equals(Node otherNode) {
if (otherNode == null)
return false;
String thisNodeString = toString();
String otherNodeString = otherNode.toString();
return thisNodeString.equals(otherNodeString);
}
////////////////////////////////////////////////
// Child node
////////////////////////////////////////////////
@@ -309,17 +365,31 @@ public class Node
// Element (Child Node)
////////////////////////////////////////////////
public void setNode(String name, String value) {
public boolean hasNode(String name) {
Node node = getNode(name);
if (node != null) {
node.setValue(value);
return true;
}
return false;
}
public void setNode(String name) {
if (hasNode(name)) {
return;
}
node = new Node(name);
node.setValue(value);
Node node = new Node(name);
addNode(node);
}
public void setNode(String name, String value) {
Node node = getNode(name);
if (node == null) {
node = new Node(name);
addNode(node);
}
node.setValue(value);
}
public String getNodeValue(String name) {
Node node = getNode(name);
if (node != null)

View File

@@ -20,7 +20,8 @@ package org.cybergarage.xml;
public class XML
{
public final static String CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
public final static String DEFAULT_CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
public final static String DEFAULT_CONTENT_LANGUAGE = "en";
public final static String CHARSET_UTF8 = "utf-8";
////////////////////////////////////////////////