forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 97716ce246bcbee153cf1a28253bac2385ddf7be)
to branch 'i2p.i2p.zzz.upnp' (head e508f71db90f382080b98d11efbdb4d88c1bc406)
This commit is contained in:
@ -1,165 +1,165 @@
|
||||
/******************************************************************
|
||||
*
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File : Date.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/05/03
|
||||
* - first revision
|
||||
* 10/20/04
|
||||
* - Theo Beisch <theo.beisch@gmx.de>
|
||||
* - Fixed the following methods to use HOUR_OF_DAY instead of HOUR.
|
||||
* getHour(), getDateString() getTimeString()
|
||||
* - Fixed getInstance() to return GMT instance.
|
||||
*
|
||||
*
|
||||
* File : Date.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/05/03
|
||||
* - first revision
|
||||
* 10/20/04
|
||||
* - Theo Beisch <theo.beisch@gmx.de>
|
||||
* - Fixed the following methods to use HOUR_OF_DAY instead of HOUR.
|
||||
* getHour(), getDateString() getTimeString()
|
||||
* - Fixed getInstance() to return GMT instance.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class Date
|
||||
{
|
||||
private Calendar cal;
|
||||
|
||||
public Date(Calendar cal)
|
||||
{
|
||||
this.cal = cal;
|
||||
}
|
||||
|
||||
public Calendar getCalendar()
|
||||
{
|
||||
return cal;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Time
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public int getHour()
|
||||
{
|
||||
// Thanks for Theo Beisch (10/20/04)
|
||||
return getCalendar().get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
public int getMinute()
|
||||
{
|
||||
return getCalendar().get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
public int getSecond()
|
||||
{
|
||||
return getCalendar().get(Calendar.SECOND);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// paint
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static Date getLocalInstance()
|
||||
{
|
||||
return new Date(Calendar.getInstance());
|
||||
}
|
||||
|
||||
public final static Date getInstance()
|
||||
{
|
||||
// Thanks for Theo Beisch (10/20/04)
|
||||
return new Date(Calendar.getInstance(TimeZone.getTimeZone("GMT")));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getDateString
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String toDateString(int value)
|
||||
{
|
||||
if (value < 10)
|
||||
return "0" + Integer.toString(value);
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
private final static String MONTH_STRING[] = {
|
||||
"Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec",
|
||||
};
|
||||
|
||||
public final static String toMonthString(int value)
|
||||
{
|
||||
value -= Calendar.JANUARY;
|
||||
if (0 <= value && value < 12)
|
||||
return MONTH_STRING[value];
|
||||
return "";
|
||||
}
|
||||
|
||||
private final static String WEEK_STRING[] = {
|
||||
"Sun",
|
||||
"Mon",
|
||||
"Tue",
|
||||
"Wed",
|
||||
"Thu",
|
||||
"Fri",
|
||||
"Sat",
|
||||
};
|
||||
|
||||
public final static String toWeekString(int value)
|
||||
{
|
||||
value -= Calendar.SUNDAY;
|
||||
if (0 <= value && value < 7)
|
||||
return WEEK_STRING[value];
|
||||
return "";
|
||||
}
|
||||
|
||||
public final static String toTimeString(int value)
|
||||
{
|
||||
String str = "";
|
||||
if (value < 10)
|
||||
str += "0";
|
||||
str += Integer.toString(value);
|
||||
return str;
|
||||
}
|
||||
|
||||
public String getDateString()
|
||||
{
|
||||
// Thanks for Theo Beisch (10/20/04)
|
||||
Calendar cal = getCalendar();
|
||||
return
|
||||
toWeekString(cal.get(Calendar.DAY_OF_WEEK)) +", " +
|
||||
toTimeString(cal.get(Calendar.DATE)) + " " +
|
||||
toMonthString(cal.get(Calendar.MONTH)) + " " +
|
||||
Integer.toString(cal.get(Calendar.YEAR)) + " " +
|
||||
toTimeString(cal.get(Calendar.HOUR_OF_DAY)) + ":" +
|
||||
toTimeString(cal.get(Calendar.MINUTE)) + ":" +
|
||||
toTimeString(cal.get(Calendar.SECOND)) + " GMT";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getTimeString
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getTimeString()
|
||||
{
|
||||
// Thanks for Theo Beisch (10/20/04)
|
||||
Calendar cal = getCalendar();
|
||||
return
|
||||
toDateString(cal.get(Calendar.HOUR_OF_DAY)) +
|
||||
(((cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") +
|
||||
toDateString(cal.get(Calendar.MINUTE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class Date
|
||||
{
|
||||
private Calendar cal;
|
||||
|
||||
public Date(Calendar cal)
|
||||
{
|
||||
this.cal = cal;
|
||||
}
|
||||
|
||||
public Calendar getCalendar()
|
||||
{
|
||||
return cal;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Time
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public int getHour()
|
||||
{
|
||||
// Thanks for Theo Beisch (10/20/04)
|
||||
return getCalendar().get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
public int getMinute()
|
||||
{
|
||||
return getCalendar().get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
public int getSecond()
|
||||
{
|
||||
return getCalendar().get(Calendar.SECOND);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// paint
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static Date getLocalInstance()
|
||||
{
|
||||
return new Date(Calendar.getInstance());
|
||||
}
|
||||
|
||||
public final static Date getInstance()
|
||||
{
|
||||
// Thanks for Theo Beisch (10/20/04)
|
||||
return new Date(Calendar.getInstance(TimeZone.getTimeZone("GMT")));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getDateString
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String toDateString(int value)
|
||||
{
|
||||
if (value < 10)
|
||||
return "0" + Integer.toString(value);
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
private final static String MONTH_STRING[] = {
|
||||
"Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec",
|
||||
};
|
||||
|
||||
public final static String toMonthString(int value)
|
||||
{
|
||||
value -= Calendar.JANUARY;
|
||||
if (0 <= value && value < 12)
|
||||
return MONTH_STRING[value];
|
||||
return "";
|
||||
}
|
||||
|
||||
private final static String WEEK_STRING[] = {
|
||||
"Sun",
|
||||
"Mon",
|
||||
"Tue",
|
||||
"Wed",
|
||||
"Thu",
|
||||
"Fri",
|
||||
"Sat",
|
||||
};
|
||||
|
||||
public final static String toWeekString(int value)
|
||||
{
|
||||
value -= Calendar.SUNDAY;
|
||||
if (0 <= value && value < 7)
|
||||
return WEEK_STRING[value];
|
||||
return "";
|
||||
}
|
||||
|
||||
public final static String toTimeString(int value)
|
||||
{
|
||||
String str = "";
|
||||
if (value < 10)
|
||||
str += "0";
|
||||
str += Integer.toString(value);
|
||||
return str;
|
||||
}
|
||||
|
||||
public String getDateString()
|
||||
{
|
||||
// Thanks for Theo Beisch (10/20/04)
|
||||
Calendar cal = getCalendar();
|
||||
return
|
||||
toWeekString(cal.get(Calendar.DAY_OF_WEEK)) +", " +
|
||||
toTimeString(cal.get(Calendar.DATE)) + " " +
|
||||
toMonthString(cal.get(Calendar.MONTH)) + " " +
|
||||
Integer.toString(cal.get(Calendar.YEAR)) + " " +
|
||||
toTimeString(cal.get(Calendar.HOUR_OF_DAY)) + ":" +
|
||||
toTimeString(cal.get(Calendar.MINUTE)) + ":" +
|
||||
toTimeString(cal.get(Calendar.SECOND)) + " GMT";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getTimeString
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getTimeString()
|
||||
{
|
||||
// Thanks for Theo Beisch (10/20/04)
|
||||
Calendar cal = getCalendar();
|
||||
return
|
||||
toDateString(cal.get(Calendar.HOUR_OF_DAY)) +
|
||||
(((cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") +
|
||||
toDateString(cal.get(Calendar.MINUTE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,22 +1,22 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: HTML.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/05/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
public class HTML
|
||||
{
|
||||
public static final String CONTENT_TYPE = "text/html; charset=\"utf-8\"";
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: HTML.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/05/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
public class HTML
|
||||
{
|
||||
public static final String CONTENT_TYPE = "text/html; charset=\"utf-8\"";
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,11 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: HTTP.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
* 08/30/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : the method getPort should return the default http port 80 when a port is not specified
|
||||
@ -27,58 +27,57 @@
|
||||
* - Added Range and MYNAME;
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
public class HTTP
|
||||
{
|
||||
|
||||
public class HTTP
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static final String HOST = "HOST";
|
||||
|
||||
public static final String VERSION = "1.1";
|
||||
public static final String VERSION = "1.1";
|
||||
public static final String VERSION_10 = "1.0";
|
||||
public static final String VERSION_11 = "1.1";
|
||||
|
||||
public static final String CRLF = "\r\n";
|
||||
public static final String CRLF = "\r\n";
|
||||
public static final byte CR = '\r';
|
||||
public static final byte LF = '\n';
|
||||
public static final String TAB = "\t";
|
||||
|
||||
|
||||
public static final String SOAP_ACTION = "SOAPACTION";
|
||||
|
||||
public static final String M_SEARCH = "M-SEARCH";
|
||||
public static final String NOTIFY = "NOTIFY";
|
||||
public static final String POST = "POST";
|
||||
public static final String GET = "GET";
|
||||
public static final String POST = "POST";
|
||||
public static final String GET = "GET";
|
||||
public static final String HEAD = "HEAD";
|
||||
public static final String SUBSCRIBE = "SUBSCRIBE";
|
||||
public static final String UNSUBSCRIBE = "UNSUBSCRIBE";
|
||||
|
||||
public static final String DATE = "Date";
|
||||
|
||||
public static final String DATE = "Date";
|
||||
public static final String CACHE_CONTROL = "Cache-Control";
|
||||
public static final String NO_CACHE = "no-cache";
|
||||
public static final String MAX_AGE = "max-age";
|
||||
public static final String CONNECTION = "Connection";
|
||||
public static final String CLOSE = "close";
|
||||
public static final String KEEP_ALIVE = "Keep-Alive";
|
||||
public static final String CONTENT_TYPE = "Content-Type";
|
||||
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_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 SERVER = "Server";
|
||||
|
||||
public static final String ST = "ST";
|
||||
public static final String MX = "MX";
|
||||
public static final String MAN = "MAN";
|
||||
@ -90,13 +89,16 @@ 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";
|
||||
|
||||
public static final String REQEST_LINE_DELIM = " ";
|
||||
public static final String HEADER_LINE_DELIM = " :";
|
||||
public static final String STATUS_LINE_DELIM = " ";
|
||||
|
||||
|
||||
public static final String REQEST_LINE_DELIM = " ";
|
||||
public static final String HEADER_LINE_DELIM = " :";
|
||||
public static final String STATUS_LINE_DELIM = " ";
|
||||
|
||||
public static final int DEFAULT_PORT = 80;
|
||||
public static final int DEFAULT_CHUNK_SIZE = 512 * 1024;
|
||||
public static final int DEFAULT_TIMEOUT = 30;
|
||||
@ -105,53 +107,53 @@ public class HTTP
|
||||
// URL
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static final boolean isAbsoluteURL(String urlStr)
|
||||
{
|
||||
try {
|
||||
new URL(urlStr);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String getHost(String urlStr)
|
||||
{
|
||||
try {
|
||||
URL url = new URL(urlStr);
|
||||
return url.getHost();
|
||||
}
|
||||
catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static final int getPort(String urlStr)
|
||||
{
|
||||
try {
|
||||
URL url = new URL(urlStr);
|
||||
public static final boolean isAbsoluteURL(String urlStr)
|
||||
{
|
||||
try {
|
||||
new URL(urlStr);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String getHost(String urlStr)
|
||||
{
|
||||
try {
|
||||
URL url = new URL(urlStr);
|
||||
return url.getHost();
|
||||
}
|
||||
catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static final int getPort(String urlStr)
|
||||
{
|
||||
try {
|
||||
URL url = new URL(urlStr);
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (08/30/03)
|
||||
int port = url.getPort();
|
||||
int port = url.getPort();
|
||||
if (port <= 0)
|
||||
port = DEFAULT_PORT;
|
||||
return port;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return DEFAULT_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
return DEFAULT_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String getRequestHostURL(String host, int port)
|
||||
{
|
||||
String reqHost = "http://" + host + ":" + port;
|
||||
return reqHost;
|
||||
}
|
||||
|
||||
public static final String toRelativeURL(String urlStr, boolean withParam)
|
||||
public static final String toRelativeURL(String urlStr, boolean withParam)
|
||||
{
|
||||
String uri = urlStr;
|
||||
if (isAbsoluteURL(urlStr) == false) {
|
||||
if (isAbsoluteURL(urlStr) == false) {
|
||||
if (0 < urlStr.length() && urlStr.charAt(0) != '/')
|
||||
uri = "/" + urlStr;
|
||||
}
|
||||
@ -171,28 +173,28 @@ public class HTTP
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
public static final String toRelativeURL(String urlStr)
|
||||
{
|
||||
return toRelativeURL(urlStr, true);
|
||||
}
|
||||
|
||||
public static final String getAbsoluteURL(String baseURLStr, String relURlStr)
|
||||
{
|
||||
try {
|
||||
URL baseURL = new URL(baseURLStr);
|
||||
String url =
|
||||
baseURL.getProtocol() + "://" +
|
||||
baseURL.getHost() + ":" +
|
||||
baseURL.getPort() +
|
||||
toRelativeURL(relURlStr);
|
||||
return url;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
|
||||
public static final String getAbsoluteURL(String baseURLStr, String relURlStr)
|
||||
{
|
||||
try {
|
||||
URL baseURL = new URL(baseURLStr);
|
||||
String url =
|
||||
baseURL.getProtocol() + "://" +
|
||||
baseURL.getHost() + ":" +
|
||||
baseURL.getPort() +
|
||||
toRelativeURL(relURlStr);
|
||||
return url;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Chunk Size
|
||||
////////////////////////////////////////////////
|
||||
@ -209,5 +211,5 @@ public class HTTP
|
||||
return chunkSize;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,37 +5,37 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: HTTPHeader.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/19/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/19/02
|
||||
* - first revision.
|
||||
* 05/26/04
|
||||
* - Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (05/26/04)
|
||||
* - Fixed getValue() to compare using String::equals() instead of String::startWidth().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.cybergarage.util.Debug;
|
||||
|
||||
public class HTTPHeader
|
||||
|
||||
public class HTTPHeader
|
||||
{
|
||||
private static int MAX_LENGTH = 1024;
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public HTTPHeader(String name, String value)
|
||||
{
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
private static int MAX_LENGTH = 1024;
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public HTTPHeader(String name, String value)
|
||||
{
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
public HTTPHeader(String lineStr)
|
||||
{
|
||||
@ -51,30 +51,30 @@ public class HTTPHeader
|
||||
setName(name.trim());
|
||||
setValue(value.trim());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean hasName()
|
||||
{
|
||||
@ -82,68 +82,68 @@ public class HTTPHeader
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// static methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String getValue(LineNumberReader reader, String name)
|
||||
{
|
||||
String bigName = name.toUpperCase(Locale.US);
|
||||
try {
|
||||
String lineStr = reader.readLine();
|
||||
while (lineStr != null && 0 < lineStr.length()) {
|
||||
HTTPHeader header = new HTTPHeader(lineStr);
|
||||
if (header.hasName() == false) {
|
||||
lineStr = reader.readLine();
|
||||
continue;
|
||||
}
|
||||
String bigLineHeaderName = header.getName().toUpperCase(Locale.US);
|
||||
// Thanks for Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (05/26/04)
|
||||
if (bigLineHeaderName.equals(bigName) == false) {
|
||||
lineStr = reader.readLine();
|
||||
continue;
|
||||
}
|
||||
return header.getValue();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
Debug.warning(e);
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public final static String getValue(String data, String name)
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// static methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String getValue(LineNumberReader reader, String name)
|
||||
{
|
||||
/* Thanks for Stephan Mehlhase (2010-10-26) */
|
||||
String bigName = name.toUpperCase(Locale.US);
|
||||
try {
|
||||
String lineStr = reader.readLine();
|
||||
while (lineStr != null && 0 < lineStr.length()) {
|
||||
HTTPHeader header = new HTTPHeader(lineStr);
|
||||
if (header.hasName() == false) {
|
||||
lineStr = reader.readLine();
|
||||
continue;
|
||||
}
|
||||
String bigLineHeaderName = header.getName().toUpperCase(Locale.US);
|
||||
// Thanks for Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (05/26/04)
|
||||
if (bigLineHeaderName.equals(bigName) == false) {
|
||||
lineStr = reader.readLine();
|
||||
continue;
|
||||
}
|
||||
return header.getValue();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
Debug.warning(e);
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public final static String getValue(String data, String name)
|
||||
{
|
||||
/* Thanks for Stephan Mehlhase (2010-10-26) */
|
||||
StringReader strReader = new StringReader(data);
|
||||
LineNumberReader lineReader = new LineNumberReader(strReader, Math.min(data.length(), MAX_LENGTH));
|
||||
return getValue(lineReader, name);
|
||||
}
|
||||
|
||||
public final static String getValue(byte[] data, String name)
|
||||
{
|
||||
return getValue(new String(data), name);
|
||||
}
|
||||
|
||||
public final static int getIntegerValue(String data, String name)
|
||||
return getValue(lineReader, name);
|
||||
}
|
||||
|
||||
public final static String getValue(byte[] data, String name)
|
||||
{
|
||||
return getValue(new String(data), name);
|
||||
}
|
||||
|
||||
public final static int getIntegerValue(String data, String name)
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(getValue(data, name));
|
||||
}
|
||||
catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public final static int getIntegerValue(byte[] data, String name)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public final static int getIntegerValue(byte[] data, String name)
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(getValue(data, name));
|
||||
}
|
||||
catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
////////////////////////////////////////////////
|
||||
|
@ -5,11 +5,11 @@
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: HTTPRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
* 05/23/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Add a relative URL check to setURI().
|
||||
@ -51,9 +51,9 @@
|
||||
* - Fixed post() to output the chunk size as a hex string.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -73,17 +73,17 @@ import org.cybergarage.util.Debug;
|
||||
* @author Stefano "Kismet" Lenzi
|
||||
* @version 1.8
|
||||
*
|
||||
*/
|
||||
public class HTTPRequest extends HTTPPacket
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPRequest()
|
||||
{
|
||||
*/
|
||||
public class HTTPRequest extends HTTPPacket
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPRequest()
|
||||
{
|
||||
setVersion(HTTP.VERSION_10);
|
||||
}
|
||||
}
|
||||
|
||||
public HTTPRequest(InputStream in)
|
||||
{
|
||||
@ -96,23 +96,23 @@ public class HTTPRequest extends HTTPPacket
|
||||
setSocket(httpSock);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Method
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String method = null;
|
||||
|
||||
public void setMethod(String value)
|
||||
{
|
||||
method = value;
|
||||
}
|
||||
|
||||
public String getMethod()
|
||||
////////////////////////////////////////////////
|
||||
// Method
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String method = null;
|
||||
|
||||
public void setMethod(String value)
|
||||
{
|
||||
if (method != null)
|
||||
method = value;
|
||||
}
|
||||
|
||||
public String getMethod()
|
||||
{
|
||||
if (method != null)
|
||||
return method;
|
||||
return getFirstLineToken(0);
|
||||
}
|
||||
return getFirstLineToken(0);
|
||||
}
|
||||
|
||||
public boolean isMethod(String method)
|
||||
{
|
||||
@ -121,16 +121,16 @@ public class HTTPRequest extends HTTPPacket
|
||||
return false;
|
||||
return headerMethod.equalsIgnoreCase(method);
|
||||
}
|
||||
|
||||
public boolean isGetRequest()
|
||||
|
||||
public boolean isGetRequest()
|
||||
{
|
||||
return isMethod(HTTP.GET);
|
||||
}
|
||||
|
||||
public boolean isPostRequest()
|
||||
{
|
||||
return isMethod(HTTP.GET);
|
||||
}
|
||||
|
||||
public boolean isPostRequest()
|
||||
{
|
||||
return isMethod(HTTP.POST);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isHeadRequest()
|
||||
{
|
||||
@ -152,33 +152,33 @@ public class HTTPRequest extends HTTPPacket
|
||||
return isMethod(HTTP.NOTIFY);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// URI
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String uri = null;
|
||||
|
||||
public void setURI(String value, boolean isCheckRelativeURL)
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// URI
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String uri = null;
|
||||
|
||||
public void setURI(String value, boolean isCheckRelativeURL)
|
||||
{
|
||||
uri = value;
|
||||
if (isCheckRelativeURL == false)
|
||||
return;
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03)
|
||||
uri = HTTP.toRelativeURL(uri);
|
||||
}
|
||||
}
|
||||
|
||||
public void setURI(String value)
|
||||
{
|
||||
setURI(value, false);
|
||||
}
|
||||
|
||||
public String getURI()
|
||||
public String getURI()
|
||||
{
|
||||
if (uri != null)
|
||||
return uri;
|
||||
if (uri != null)
|
||||
return uri;
|
||||
return getFirstLineToken(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// URI Parameter
|
||||
////////////////////////////////////////////////
|
||||
@ -247,21 +247,21 @@ public class HTTPRequest extends HTTPPacket
|
||||
return requestPort;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Socket
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private HTTPSocket httpSocket = null;
|
||||
|
||||
public void setSocket(HTTPSocket value)
|
||||
{
|
||||
httpSocket = value;
|
||||
}
|
||||
|
||||
public HTTPSocket getSocket()
|
||||
{
|
||||
return httpSocket;
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
// Socket
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private HTTPSocket httpSocket = null;
|
||||
|
||||
public void setSocket(HTTPSocket value)
|
||||
{
|
||||
httpSocket = value;
|
||||
}
|
||||
|
||||
public HTTPSocket getSocket()
|
||||
{
|
||||
return httpSocket;
|
||||
}
|
||||
|
||||
/////////////////////////// /////////////////////
|
||||
// local address/port
|
||||
@ -276,25 +276,25 @@ public class HTTPRequest extends HTTPPacket
|
||||
{
|
||||
return getSocket().getLocalPort();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// parseRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean parseRequestLine(String lineStr)
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(lineStr, HTTP.REQEST_LINE_DELIM);
|
||||
if (st.hasMoreTokens() == false)
|
||||
return false;
|
||||
setMethod(st.nextToken());
|
||||
if (st.hasMoreTokens() == false)
|
||||
return false;
|
||||
setURI(st.nextToken());
|
||||
if (st.hasMoreTokens() == false)
|
||||
return false;
|
||||
setVersion(st.nextToken());
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// parseRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean parseRequestLine(String lineStr)
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(lineStr, HTTP.REQEST_LINE_DELIM);
|
||||
if (st.hasMoreTokens() == false)
|
||||
return false;
|
||||
setMethod(st.nextToken());
|
||||
if (st.hasMoreTokens() == false)
|
||||
return false;
|
||||
setURI(st.nextToken());
|
||||
if (st.hasMoreTokens() == false)
|
||||
return false;
|
||||
setVersion(st.nextToken());
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// First Line
|
||||
@ -312,22 +312,22 @@ public class HTTPRequest extends HTTPPacket
|
||||
return getMethod() + " " + getURI() + " " + getHTTPVersion() + HTTP.CRLF;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getHeader
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getHeader()
|
||||
{
|
||||
StringBuffer str = new StringBuffer();
|
||||
|
||||
str.append(getFirstLineString());
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getHeader
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getHeader()
|
||||
{
|
||||
StringBuffer str = new StringBuffer();
|
||||
|
||||
str.append(getFirstLineString());
|
||||
|
||||
String headerString = getHeaderString();
|
||||
str.append(headerString);
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// isKeepAlive
|
||||
////////////////////////////////////////////////
|
||||
@ -354,9 +354,9 @@ public class HTTPRequest extends HTTPPacket
|
||||
return super.read(getSocket());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// POST (Response)
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
// POST (Response)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean post(HTTPResponse httpRes)
|
||||
{
|
||||
@ -381,15 +381,15 @@ public class HTTPRequest extends HTTPPacket
|
||||
return httpSock.post(httpRes, offset, length, isHeadRequest());
|
||||
//httpSock.close();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// POST (Request)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Socket postSocket = null;
|
||||
|
||||
public HTTPResponse post(String host, int port, boolean isKeepAlive)
|
||||
{
|
||||
public HTTPResponse post(String host, int port, boolean isKeepAlive)
|
||||
{
|
||||
HTTPResponse httpRes = new HTTPResponse();
|
||||
|
||||
setHost(host);
|
||||
@ -418,9 +418,9 @@ public class HTTPRequest extends HTTPPacket
|
||||
postSocket.connect(sa, 3000);
|
||||
}
|
||||
|
||||
out = postSocket.getOutputStream();
|
||||
PrintStream pout = new PrintStream(out);
|
||||
pout.print(getHeader());
|
||||
out = postSocket.getOutputStream();
|
||||
PrintStream pout = new PrintStream(out);
|
||||
pout.print(getHeader());
|
||||
pout.print(HTTP.CRLF);
|
||||
|
||||
boolean isChunkedRequest = isChunked();
|
||||
@ -429,7 +429,7 @@ public class HTTPRequest extends HTTPPacket
|
||||
int contentLength = 0;
|
||||
if (content != null)
|
||||
contentLength = content.length();
|
||||
|
||||
|
||||
if (0 < contentLength) {
|
||||
if (isChunkedRequest == true) {
|
||||
// Thanks for Lee Peik Feng <pflee@users.sourceforge.net> (07/07/05)
|
||||
@ -447,7 +447,7 @@ public class HTTPRequest extends HTTPPacket
|
||||
pout.print(HTTP.CRLF);
|
||||
}
|
||||
|
||||
pout.flush();
|
||||
pout.flush();
|
||||
|
||||
in = postSocket.getInputStream();
|
||||
httpRes.set(in, isHeaderRequest);
|
||||
@ -477,7 +477,7 @@ public class HTTPRequest extends HTTPPacket
|
||||
}
|
||||
|
||||
return httpRes;
|
||||
}
|
||||
}
|
||||
|
||||
public HTTPResponse post(String host, int port)
|
||||
{
|
||||
@ -516,20 +516,20 @@ public class HTTPRequest extends HTTPPacket
|
||||
return returnResponse(HTTPStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// toString
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer str = new StringBuffer();
|
||||
|
||||
str.append(getHeader());
|
||||
str.append(HTTP.CRLF);
|
||||
str.append(getContentString());
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
// toString
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer str = new StringBuffer();
|
||||
|
||||
str.append(getHeader());
|
||||
str.append(HTTP.CRLF);
|
||||
str.append(getContentString());
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
public void print()
|
||||
{
|
||||
|
@ -5,17 +5,17 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: HTTPRequestListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/13/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/13/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
public interface HTTPRequestListener
|
||||
{
|
||||
public void httpRequestRecieved(HTTPRequest httpReq);
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
public interface HTTPRequestListener
|
||||
{
|
||||
public void httpRequestRecieved(HTTPRequest httpReq);
|
||||
}
|
||||
|
@ -5,11 +5,11 @@
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: HTTPResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
* 10/22/03
|
||||
* - Changed to initialize a content length header.
|
||||
* 10/22/04
|
||||
@ -17,24 +17,24 @@
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
package org.cybergarage.http;
|
||||
|
||||
import java.io.InputStream;
|
||||
import org.cybergarage.util.Debug;
|
||||
|
||||
public class HTTPResponse extends HTTPPacket
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPResponse()
|
||||
{
|
||||
|
||||
public class HTTPResponse extends HTTPPacket
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPResponse()
|
||||
{
|
||||
setVersion(HTTP.VERSION_11);
|
||||
setContentType(HTML.CONTENT_TYPE);
|
||||
setServer(HTTPServer.getName());
|
||||
setContent("");
|
||||
}
|
||||
}
|
||||
|
||||
public HTTPResponse(HTTPResponse httpRes)
|
||||
{
|
||||
@ -50,25 +50,25 @@ public class HTTPResponse extends HTTPPacket
|
||||
{
|
||||
this(httpSock.getInputStream());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Status Line
|
||||
////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Status Line
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private int statusCode = 0;
|
||||
|
||||
public void setStatusCode(int code)
|
||||
|
||||
public void setStatusCode(int code)
|
||||
{
|
||||
statusCode = code;
|
||||
}
|
||||
|
||||
public int getStatusCode()
|
||||
statusCode = code;
|
||||
}
|
||||
|
||||
public int getStatusCode()
|
||||
{
|
||||
if (statusCode != 0)
|
||||
return statusCode;
|
||||
return statusCode;
|
||||
HTTPStatus httpStatus = new HTTPStatus(getFirstLine());
|
||||
return httpStatus.getStatusCode();
|
||||
}
|
||||
return httpStatus.getStatusCode();
|
||||
}
|
||||
|
||||
public boolean isSuccessful()
|
||||
{
|
||||
@ -79,20 +79,20 @@ public class HTTPResponse extends HTTPPacket
|
||||
{
|
||||
return "HTTP/" + getVersion() + " " + getStatusCode() + " " + HTTPStatus.code2String(statusCode) + HTTP.CRLF;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getHeader
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getHeader()
|
||||
{
|
||||
StringBuffer str = new StringBuffer();
|
||||
|
||||
str.append(getStatusLineString());
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getHeader
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getHeader()
|
||||
{
|
||||
StringBuffer str = new StringBuffer();
|
||||
|
||||
str.append(getStatusLineString());
|
||||
str.append(getHeaderString());
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// toString
|
||||
|
@ -1,54 +1,54 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: HTTPServerThread.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 10/10/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
public class HTTPServerThread extends Thread
|
||||
{
|
||||
private HTTPServer httpServer;
|
||||
private Socket sock;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPServerThread(HTTPServer httpServer, Socket sock)
|
||||
{
|
||||
super("Cyber.HTTPServerThread");
|
||||
this.httpServer = httpServer;
|
||||
this.sock = sock;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// run
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void run()
|
||||
{
|
||||
HTTPSocket httpSock = new HTTPSocket(sock);
|
||||
if (httpSock.open() == false)
|
||||
return;
|
||||
HTTPRequest httpReq = new HTTPRequest();
|
||||
httpReq.setSocket(httpSock);
|
||||
while (httpReq.read() == true) {
|
||||
httpServer.performRequestListener(httpReq);
|
||||
if (httpReq.isKeepAlive() == false)
|
||||
break;
|
||||
}
|
||||
httpSock.close();
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: HTTPServerThread.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 10/10/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
public class HTTPServerThread extends Thread
|
||||
{
|
||||
private HTTPServer httpServer;
|
||||
private Socket sock;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPServerThread(HTTPServer httpServer, Socket sock)
|
||||
{
|
||||
super("Cyber.HTTPServerThread");
|
||||
this.httpServer = httpServer;
|
||||
this.sock = sock;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// run
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void run()
|
||||
{
|
||||
HTTPSocket httpSock = new HTTPSocket(sock);
|
||||
if (httpSock.open() == false)
|
||||
return;
|
||||
HTTPRequest httpReq = new HTTPRequest();
|
||||
httpReq.setSocket(httpSock);
|
||||
while (httpReq.read() == true) {
|
||||
httpServer.performRequestListener(httpReq);
|
||||
if (httpReq.isKeepAlive() == false)
|
||||
break;
|
||||
}
|
||||
httpSock.close();
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,11 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: HTTPStatus.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/17/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/17/02
|
||||
* - first revision.
|
||||
* 09/03/03
|
||||
* - Added CONTINUE_STATUS.
|
||||
* 10/20/04
|
||||
@ -22,105 +22,105 @@
|
||||
* - Fixed set() to read multi words of the response sring such as Not Found.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.cybergarage.util.Debug;
|
||||
|
||||
public class HTTPStatus
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////
|
||||
|
||||
|
||||
public class HTTPStatus
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static final int CONTINUE = 100;
|
||||
public static final int OK = 200;
|
||||
public static final int OK = 200;
|
||||
// Thanks for Brent Hills (10/20/04)
|
||||
public static final int PARTIAL_CONTENT = 206;
|
||||
public static final int BAD_REQUEST = 400;
|
||||
public static final int BAD_REQUEST = 400;
|
||||
public static final int NOT_FOUND = 404;
|
||||
public static final int PRECONDITION_FAILED = 412;
|
||||
// Thanks for Brent Hills (10/20/04)
|
||||
public static final int INVALID_RANGE = 416;
|
||||
public static final int INTERNAL_SERVER_ERROR = 500;
|
||||
|
||||
public static final String code2String(int code)
|
||||
{
|
||||
switch (code) {
|
||||
public static final String code2String(int code)
|
||||
{
|
||||
switch (code) {
|
||||
case CONTINUE: return "Continue";
|
||||
case OK: return "OK";
|
||||
case OK: return "OK";
|
||||
case PARTIAL_CONTENT: return "Partial Content";
|
||||
case BAD_REQUEST: return "Bad Request";
|
||||
case NOT_FOUND: return "Not Found";
|
||||
case PRECONDITION_FAILED: return "Precondition Failed";
|
||||
case INVALID_RANGE: return "Invalid Range";
|
||||
case INTERNAL_SERVER_ERROR: return "Internal Server Error";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPStatus()
|
||||
{
|
||||
setVersion("");
|
||||
setStatusCode(0);
|
||||
setReasonPhrase("");
|
||||
}
|
||||
|
||||
public HTTPStatus(String ver, int code, String reason)
|
||||
{
|
||||
setVersion(ver);
|
||||
setStatusCode(code);
|
||||
setReasonPhrase(reason);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPStatus()
|
||||
{
|
||||
setVersion("");
|
||||
setStatusCode(0);
|
||||
setReasonPhrase("");
|
||||
}
|
||||
|
||||
public HTTPStatus(String ver, int code, String reason)
|
||||
{
|
||||
setVersion(ver);
|
||||
setStatusCode(code);
|
||||
setReasonPhrase(reason);
|
||||
}
|
||||
|
||||
public HTTPStatus(String lineStr)
|
||||
{
|
||||
set(lineStr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String version = "";
|
||||
private int statusCode = 0;
|
||||
private String reasonPhrase = "";
|
||||
|
||||
public void setVersion(String value)
|
||||
{
|
||||
version = value;
|
||||
}
|
||||
|
||||
public void setStatusCode(int value)
|
||||
{
|
||||
statusCode = value;
|
||||
}
|
||||
|
||||
public void setReasonPhrase(String value)
|
||||
{
|
||||
reasonPhrase = value;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public int getStatusCode()
|
||||
{
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public String getReasonPhrase()
|
||||
{
|
||||
return reasonPhrase;
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String version = "";
|
||||
private int statusCode = 0;
|
||||
private String reasonPhrase = "";
|
||||
|
||||
public void setVersion(String value)
|
||||
{
|
||||
version = value;
|
||||
}
|
||||
|
||||
public void setStatusCode(int value)
|
||||
{
|
||||
statusCode = value;
|
||||
}
|
||||
|
||||
public void setReasonPhrase(String value)
|
||||
{
|
||||
reasonPhrase = value;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public int getStatusCode()
|
||||
{
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public String getReasonPhrase()
|
||||
{
|
||||
return reasonPhrase;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Status
|
||||
|
@ -1,61 +1,61 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: Parameter.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 02/01/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
public class Parameter
|
||||
{
|
||||
private String name = new String();
|
||||
private String value = new String();
|
||||
|
||||
public Parameter()
|
||||
{
|
||||
}
|
||||
|
||||
public Parameter(String name, String value)
|
||||
{
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// name
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// value
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: Parameter.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 02/01/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
public class Parameter
|
||||
{
|
||||
private String name = new String();
|
||||
private String value = new String();
|
||||
|
||||
public Parameter()
|
||||
{
|
||||
}
|
||||
|
||||
public Parameter(String name, String value)
|
||||
{
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// name
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// value
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,58 +1,58 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: ParameterList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 02/01/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ParameterList extends Vector<Parameter>
|
||||
{
|
||||
public ParameterList()
|
||||
{
|
||||
}
|
||||
|
||||
public Parameter at(int n)
|
||||
{
|
||||
return (Parameter)get(n);
|
||||
}
|
||||
|
||||
public Parameter getParameter(int n)
|
||||
{
|
||||
return (Parameter)get(n);
|
||||
}
|
||||
|
||||
public Parameter getParameter(String name)
|
||||
{
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
int nLists = size();
|
||||
for (int n=0; n<nLists; n++) {
|
||||
Parameter param = at(n);
|
||||
if (name.compareTo(param.getName()) == 0)
|
||||
return param;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getValue(String name)
|
||||
{
|
||||
Parameter param = getParameter(name);
|
||||
if (param == null)
|
||||
return "";
|
||||
return param.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberHTTP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: ParameterList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 02/01/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.http;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ParameterList extends Vector<Parameter>
|
||||
{
|
||||
public ParameterList()
|
||||
{
|
||||
}
|
||||
|
||||
public Parameter at(int n)
|
||||
{
|
||||
return (Parameter)get(n);
|
||||
}
|
||||
|
||||
public Parameter getParameter(int n)
|
||||
{
|
||||
return (Parameter)get(n);
|
||||
}
|
||||
|
||||
public Parameter getParameter(String name)
|
||||
{
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
int nLists = size();
|
||||
for (int n=0; n<nLists; n++) {
|
||||
Parameter param = at(n);
|
||||
if (name.compareTo(param.getName()) == 0)
|
||||
return param;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getValue(String name)
|
||||
{
|
||||
Parameter param = getParameter(name);
|
||||
if (param == null)
|
||||
return "";
|
||||
return param.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,11 @@
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: HostInterface.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 05/12/03
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 05/12/03
|
||||
* - first revision.
|
||||
* 05/13/03
|
||||
* - Added support for IPv6 and loopback address.
|
||||
* 02/15/04
|
||||
@ -22,9 +22,9 @@
|
||||
* - Changed isUseAddress() to isUsableAddress().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.net;
|
||||
|
||||
|
||||
package org.cybergarage.net;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
@ -35,9 +35,9 @@ import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.cybergarage.util.Debug;
|
||||
|
||||
public class HostInterface
|
||||
{
|
||||
|
||||
public class HostInterface
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
@ -5,45 +5,45 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SOAP.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/11/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/11/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.soap;
|
||||
|
||||
package org.cybergarage.soap;
|
||||
|
||||
import org.cybergarage.xml.Node;
|
||||
import org.cybergarage.xml.Parser;
|
||||
|
||||
public class SOAP
|
||||
{
|
||||
public static final String ENVELOPE = "Envelope";
|
||||
public static final String BODY = "Body";
|
||||
public static final String RESPONSE = "Response";
|
||||
public static final String FAULT = "Fault";
|
||||
public static final String FAULT_CODE = "faultcode";
|
||||
public static final String FAULT_STRING = "faultstring";
|
||||
public static final String FAULTACTOR = "faultactor";
|
||||
public static final String DETAIL = "detail";
|
||||
|
||||
public static final String RESULTSTATUS = "ResultStatus";
|
||||
public static final String UPNP_ERROR = "UPnPError";
|
||||
public static final String ERROR_CODE = "errorCode";
|
||||
public static final String ERROR_DESCRIPTION = "errorDescription";
|
||||
|
||||
//public static final String XMLNS = "SOAP-ENV";
|
||||
public static final String XMLNS = "s";
|
||||
public static final String METHODNS = "u";
|
||||
|
||||
public class SOAP
|
||||
{
|
||||
public static final String ENVELOPE = "Envelope";
|
||||
public static final String BODY = "Body";
|
||||
public static final String RESPONSE = "Response";
|
||||
public static final String FAULT = "Fault";
|
||||
public static final String FAULT_CODE = "faultcode";
|
||||
public static final String FAULT_STRING = "faultstring";
|
||||
public static final String FAULTACTOR = "faultactor";
|
||||
public static final String DETAIL = "detail";
|
||||
|
||||
public static final String RESULTSTATUS = "ResultStatus";
|
||||
public static final String UPNP_ERROR = "UPnPError";
|
||||
public static final String ERROR_CODE = "errorCode";
|
||||
public static final String ERROR_DESCRIPTION = "errorDescription";
|
||||
|
||||
//public static final String XMLNS = "SOAP-ENV";
|
||||
public static final String XMLNS = "s";
|
||||
public static final String METHODNS = "u";
|
||||
public static final String DELIM = ":";
|
||||
|
||||
public static final String XMLNS_URL = "http://schemas.xmlsoap.org/soap/envelope/";
|
||||
public static final String ENCSTYLE_URL = "http://schemas.xmlsoap.org/soap/encoding/";
|
||||
|
||||
public static final String CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
|
||||
public static final String VERSION_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
||||
|
||||
public static final String XMLNS_URL = "http://schemas.xmlsoap.org/soap/envelope/";
|
||||
public static final String ENCSTYLE_URL = "http://schemas.xmlsoap.org/soap/encoding/";
|
||||
|
||||
public static final String CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
|
||||
public static final String VERSION_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// createEnvelopeBodyNode
|
||||
@ -78,5 +78,5 @@ public class SOAP
|
||||
{
|
||||
return xmlParser;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,11 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SOAPRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/11/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/11/02
|
||||
* - first revision.
|
||||
* 02/13/04
|
||||
* - Ralf G. R. Bergs <Ralf@Ber.gs>, Inma Marin Lopez <inma@dif.um.es>.
|
||||
* - Added XML header, <?xml version=\"1.0\"?> to setContent().
|
||||
@ -17,9 +17,9 @@
|
||||
* - Changed the XML header to <?xml version="1.0" encoding="utf-8"?> in setContent().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.soap;
|
||||
|
||||
|
||||
package org.cybergarage.soap;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.cybergarage.http.HTTP;
|
||||
@ -29,20 +29,20 @@ import org.cybergarage.util.Debug;
|
||||
import org.cybergarage.xml.Node;
|
||||
import org.cybergarage.xml.Parser;
|
||||
import org.cybergarage.xml.ParserException;
|
||||
|
||||
public class SOAPRequest extends HTTPRequest
|
||||
|
||||
public class SOAPRequest extends HTTPRequest
|
||||
{
|
||||
private final static String SOAPACTION = "SOAPACTION";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SOAPRequest()
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SOAPRequest()
|
||||
{
|
||||
setContentType(SOAP.CONTENT_TYPE);
|
||||
setMethod(HTTP.POST);
|
||||
}
|
||||
setContentType(SOAP.CONTENT_TYPE);
|
||||
setMethod(HTTP.POST);
|
||||
}
|
||||
|
||||
public SOAPRequest(HTTPRequest httpReq)
|
||||
{
|
||||
@ -75,33 +75,33 @@ public class SOAPRequest extends HTTPRequest
|
||||
return false;
|
||||
return soapAction.equals(value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SOAPResponse postMessage(String host, int port)
|
||||
{
|
||||
HTTPResponse httpRes = post(host, port);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SOAPResponse postMessage(String host, int port)
|
||||
{
|
||||
HTTPResponse httpRes = post(host, port);
|
||||
|
||||
SOAPResponse soapRes = new SOAPResponse(httpRes);
|
||||
|
||||
byte content[] = soapRes.getContent();
|
||||
if (content.length <= 0)
|
||||
return soapRes;
|
||||
|
||||
try {
|
||||
ByteArrayInputStream byteIn = new ByteArrayInputStream(content);
|
||||
Parser xmlParser = SOAP.getXMLParser();
|
||||
Node rootNode = xmlParser.parse(byteIn);
|
||||
soapRes.setEnvelopeNode(rootNode);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
}
|
||||
|
||||
return soapRes;
|
||||
}
|
||||
SOAPResponse soapRes = new SOAPResponse(httpRes);
|
||||
|
||||
byte content[] = soapRes.getContent();
|
||||
if (content.length <= 0)
|
||||
return soapRes;
|
||||
|
||||
try {
|
||||
ByteArrayInputStream byteIn = new ByteArrayInputStream(content);
|
||||
Parser xmlParser = SOAP.getXMLParser();
|
||||
Node rootNode = xmlParser.parse(byteIn);
|
||||
soapRes.setEnvelopeNode(rootNode);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
}
|
||||
|
||||
return soapRes;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Node
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
@ -1,45 +1,45 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: ActionList.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 12/05/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ActionList.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 12/05/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ActionList extends Vector<Action>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "actionList";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ActionList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Action getAction(int n)
|
||||
{
|
||||
return (Action)get(n);
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ActionList extends Vector<Action>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "actionList";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ActionList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Action getAction(int n)
|
||||
{
|
||||
return (Action)get(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,84 +5,96 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: Icon.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/28/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/28/02
|
||||
* - first revision.
|
||||
* 04/12/06
|
||||
* - Added setUserData() and getUserData() to set a user original data object.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import org.cybergarage.xml.Node;
|
||||
|
||||
public class Icon
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "icon";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node iconNode;
|
||||
|
||||
public Node getIconNode()
|
||||
{
|
||||
return iconNode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Icon(Node node)
|
||||
{
|
||||
iconNode = node;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// isIconNode
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static boolean isIconNode(Node node)
|
||||
{
|
||||
return Icon.ELEM_NAME.equals(node.getName());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// mimeType
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String MIME_TYPE = "mimeType";
|
||||
|
||||
public void setMimeType(String value)
|
||||
{
|
||||
getIconNode().setNode(MIME_TYPE, value);
|
||||
}
|
||||
|
||||
public String getMimeType()
|
||||
{
|
||||
return getIconNode().getNodeValue(MIME_TYPE);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// width
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String WIDTH = "width";
|
||||
|
||||
public void setWidth(String value)
|
||||
{
|
||||
getIconNode().setNode(WIDTH, value);
|
||||
}
|
||||
|
||||
|
||||
public class Icon
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "icon";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node iconNode;
|
||||
|
||||
public Node getIconNode()
|
||||
{
|
||||
return iconNode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Icon(Node node)
|
||||
{
|
||||
iconNode = node;
|
||||
}
|
||||
|
||||
public Icon() {
|
||||
this(new Node(ELEM_NAME));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// isIconNode
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static boolean isIconNode(Node node)
|
||||
{
|
||||
return Icon.ELEM_NAME.equals(node.getName());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// mimeType
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String MIME_TYPE = "mimeType";
|
||||
|
||||
public void setMimeType(String value)
|
||||
{
|
||||
getIconNode().setNode(MIME_TYPE, value);
|
||||
}
|
||||
|
||||
public String getMimeType()
|
||||
{
|
||||
return getIconNode().getNodeValue(MIME_TYPE);
|
||||
}
|
||||
|
||||
public boolean hasMimeType()
|
||||
{
|
||||
String iconMimeType = getMimeType();
|
||||
if (iconMimeType == null)
|
||||
return false;
|
||||
return (0 < iconMimeType.length()) ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// width
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String WIDTH = "width";
|
||||
|
||||
public void setWidth(String value)
|
||||
{
|
||||
getIconNode().setNode(WIDTH, value);
|
||||
}
|
||||
|
||||
public void setWidth(int value)
|
||||
{
|
||||
try {
|
||||
@ -91,26 +103,26 @@ public class Icon
|
||||
catch (Exception e) {};
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
public int getWidth()
|
||||
{
|
||||
try {
|
||||
try {
|
||||
return Integer.parseInt(getIconNode().getNodeValue(WIDTH));
|
||||
}
|
||||
catch (Exception e) {};
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// height
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String HEIGHT = "height";
|
||||
|
||||
public void setHeight(String value)
|
||||
{
|
||||
getIconNode().setNode(HEIGHT, value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// height
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String HEIGHT = "height";
|
||||
|
||||
public void setHeight(String value)
|
||||
{
|
||||
getIconNode().setNode(HEIGHT, value);
|
||||
}
|
||||
|
||||
public void setHeight(int value)
|
||||
{
|
||||
try {
|
||||
@ -119,47 +131,77 @@ public class Icon
|
||||
catch (Exception e) {};
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
public int getHeight()
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(getIconNode().getNodeValue(HEIGHT));
|
||||
}
|
||||
catch (Exception e) {};
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// depth
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String DEPTH = "depth";
|
||||
|
||||
public void setDepth(String value)
|
||||
{
|
||||
getIconNode().setNode(DEPTH, value);
|
||||
}
|
||||
|
||||
public String getDepth()
|
||||
{
|
||||
return getIconNode().getNodeValue(DEPTH);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// URL
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String URL = "url";
|
||||
|
||||
public void setURL(String value)
|
||||
{
|
||||
getIconNode().setNode(URL, value);
|
||||
}
|
||||
|
||||
public String getURL()
|
||||
{
|
||||
return getIconNode().getNodeValue(URL);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// depth
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String DEPTH = "depth";
|
||||
|
||||
public void setDepth(String value)
|
||||
{
|
||||
getIconNode().setNode(DEPTH, value);
|
||||
}
|
||||
|
||||
public void setDepth(int value)
|
||||
{
|
||||
try {
|
||||
setDepth(Integer.toString(value));
|
||||
}
|
||||
catch (Exception e) {};
|
||||
}
|
||||
|
||||
public int getDepth()
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(getIconNode().getNodeValue(DEPTH));
|
||||
}
|
||||
catch (Exception e) {};
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// URL
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String URL = "url";
|
||||
|
||||
public void setURL(String value)
|
||||
{
|
||||
getIconNode().setNode(URL, value);
|
||||
}
|
||||
|
||||
public String getURL()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +1,45 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: IconList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/04/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: IconList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/04/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class IconList extends Vector<Icon>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "iconList";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public IconList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Icon getIcon(int n)
|
||||
{
|
||||
return (Icon)get(n);
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class IconList extends Vector<Icon>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "iconList";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public IconList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Icon getIcon(int n)
|
||||
{
|
||||
return (Icon)get(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
|
||||
/**
|
||||
* @author Stefano "Kismet" Lenzi - kismet-sl@users.sourceforge.net <br>
|
||||
* Copyright (c) 2005
|
||||
*
|
||||
*/
|
||||
public interface RootDescription {
|
||||
|
||||
public final String ROOT_ELEMENT = "root";
|
||||
public final String ROOT_ELEMENT_NAMESPACE = "urn:schemas-upnp-org:device-1-0";
|
||||
|
||||
|
||||
public final String SPECVERSION_ELEMENT = "specVersion";
|
||||
public final String MAJOR_ELEMENT = "major";
|
||||
public final String MINOR_ELEMENT = "minor";
|
||||
public final String SERVICE_LIST_ELEMENT = "serviceList";
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Stefano "Kismet" Lenzi - kismet-sl@users.sourceforge.net <br>
|
||||
* Copyright (c) 2005
|
||||
*
|
||||
*/
|
||||
public interface RootDescription {
|
||||
|
||||
public final String ROOT_ELEMENT = "root";
|
||||
public final String ROOT_ELEMENT_NAMESPACE = "urn:schemas-upnp-org:device-1-0";
|
||||
|
||||
|
||||
public final String SPECVERSION_ELEMENT = "specVersion";
|
||||
public final String MAJOR_ELEMENT = "major";
|
||||
public final String MINOR_ELEMENT = "minor";
|
||||
public final String SERVICE_LIST_ELEMENT = "serviceList";
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class Service
|
||||
////////////////////////////////////////////////
|
||||
public static final String SCPD_ROOTNODE="scpd";
|
||||
public static final String SCPD_ROOTNODE_NS="urn:schemas-upnp-org:service-1-0";
|
||||
|
||||
|
||||
public static final String SPEC_VERSION="specVersion";
|
||||
public static final String MAJOR="major";
|
||||
public static final String MAJOR_VALUE="1";
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,52 +1,52 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: ServiceList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/04/02
|
||||
* - first revision.
|
||||
* 06/18/03
|
||||
* - Added caching a ArrayIndexOfBound exception.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ServiceList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/04/02
|
||||
* - first revision.
|
||||
* 06/18/03
|
||||
* - Added caching a ArrayIndexOfBound exception.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ServiceList extends Vector<Service>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "serviceList";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ServiceList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Service getService(int n)
|
||||
{
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = get(n);
|
||||
}
|
||||
catch (Exception e) {};
|
||||
return (Service)obj;
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ServiceList extends Vector<Service>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "serviceList";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ServiceList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Service getService(int n)
|
||||
{
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = get(n);
|
||||
}
|
||||
catch (Exception e) {};
|
||||
return (Service)obj;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,45 +1,45 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: ServiceStateTable.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 12/06/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ServiceStateTable.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 12/06/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ServiceStateTable extends Vector<StateVariable>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "serviceStateTable";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ServiceStateTable()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public StateVariable getStateVariable(int n)
|
||||
{
|
||||
return (StateVariable)get(n);
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ServiceStateTable extends Vector<StateVariable>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "serviceStateTable";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ServiceStateTable()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public StateVariable getStateVariable(int n)
|
||||
{
|
||||
return (StateVariable)get(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
////////////////////////////////////////////////
|
||||
|
@ -1,82 +1,82 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: UPnPStatus.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
* 01/03/04
|
||||
* - Changed the class name from UPnPError to UPnPStatus.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
import org.cybergarage.http.HTTPStatus;
|
||||
|
||||
public class UPnPStatus
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static final int INVALID_ACTION = 401;
|
||||
public static final int INVALID_ARGS = 402;
|
||||
public static final int OUT_OF_SYNC = 403;
|
||||
public static final int INVALID_VAR = 404;
|
||||
public static final int PRECONDITION_FAILED = 412;
|
||||
public static final int ACTION_FAILED = 501;
|
||||
|
||||
public static final String code2String(int code)
|
||||
{
|
||||
switch (code) {
|
||||
case INVALID_ACTION: return "Invalid Action";
|
||||
case INVALID_ARGS: return "Invalid Args";
|
||||
case OUT_OF_SYNC: return "Out of Sync";
|
||||
case INVALID_VAR: return "Invalid Var";
|
||||
case PRECONDITION_FAILED: return "Precondition Failed";
|
||||
case ACTION_FAILED: return "Action Failed";
|
||||
default: return HTTPStatus.code2String(code);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private int code;
|
||||
private String description;
|
||||
|
||||
public UPnPStatus()
|
||||
{
|
||||
setCode(0);
|
||||
setDescription("");
|
||||
}
|
||||
|
||||
public UPnPStatus(int code, String desc)
|
||||
{
|
||||
setCode(code);
|
||||
setDescription(desc);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: UPnPStatus.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
* 01/03/04
|
||||
* - Changed the class name from UPnPError to UPnPStatus.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp;
|
||||
import org.cybergarage.http.HTTPStatus;
|
||||
|
||||
public class UPnPStatus
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static final int INVALID_ACTION = 401;
|
||||
public static final int INVALID_ARGS = 402;
|
||||
public static final int OUT_OF_SYNC = 403;
|
||||
public static final int INVALID_VAR = 404;
|
||||
public static final int PRECONDITION_FAILED = 412;
|
||||
public static final int ACTION_FAILED = 501;
|
||||
|
||||
public static final String code2String(int code)
|
||||
{
|
||||
switch (code) {
|
||||
case INVALID_ACTION: return "Invalid Action";
|
||||
case INVALID_ARGS: return "Invalid Args";
|
||||
case OUT_OF_SYNC: return "Out of Sync";
|
||||
case INVALID_VAR: return "Invalid Var";
|
||||
case PRECONDITION_FAILED: return "Precondition Failed";
|
||||
case ACTION_FAILED: return "Action Failed";
|
||||
default: return HTTPStatus.code2String(code);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private int code;
|
||||
private String description;
|
||||
|
||||
public UPnPStatus()
|
||||
{
|
||||
setCode(0);
|
||||
setDescription("");
|
||||
}
|
||||
|
||||
public UPnPStatus(int code, String desc)
|
||||
{
|
||||
setCode(code);
|
||||
setDescription(desc);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ActionListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/16/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public interface ActionListener
|
||||
{
|
||||
public boolean actionControlReceived(Action action);
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ActionListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/16/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public interface ActionListener
|
||||
{
|
||||
public boolean actionControlReceived(Action action);
|
||||
}
|
||||
|
@ -1,145 +1,145 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ControlRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 05/09/05
|
||||
* - Changed getActionName() to return when the delimiter is not found.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.xml.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class ActionRequest extends ControlRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ActionRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public ActionRequest(HTTPRequest httpReq)
|
||||
{
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Action
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Node getActionNode()
|
||||
{
|
||||
Node bodyNode = getBodyNode();
|
||||
if (bodyNode == null)
|
||||
return null;
|
||||
if (bodyNode.hasNodes() == false)
|
||||
return null;
|
||||
return bodyNode.getNode(0);
|
||||
}
|
||||
|
||||
public String getActionName()
|
||||
{
|
||||
Node node = getActionNode();
|
||||
if (node == null)
|
||||
return "";
|
||||
String name = node.getName();
|
||||
if (name == null)
|
||||
return "";
|
||||
int idx = name.indexOf(SOAP.DELIM)+1;
|
||||
if (idx < 0)
|
||||
return "";
|
||||
return name.substring(idx, name.length());
|
||||
}
|
||||
|
||||
public ArgumentList getArgumentList()
|
||||
{
|
||||
Node actNode = getActionNode();
|
||||
int nArgNodes = actNode.getNNodes();
|
||||
ArgumentList argList = new ArgumentList();
|
||||
for (int n=0; n<nArgNodes; n++) {
|
||||
Argument arg = new Argument();
|
||||
Node argNode = actNode.getNode(n);
|
||||
arg.setName(argNode.getName());
|
||||
arg.setValue(argNode.getValue());
|
||||
argList.add(arg);
|
||||
}
|
||||
return argList;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// setRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setRequest(Action action, ArgumentList argList)
|
||||
{
|
||||
Service service = action.getService();
|
||||
|
||||
setRequestHost(service);
|
||||
|
||||
setEnvelopeNode(SOAP.createEnvelopeBodyNode());
|
||||
Node envNode = getEnvelopeNode();
|
||||
Node bodyNode = getBodyNode();
|
||||
Node argNode = createContentNode(service, action, argList);
|
||||
bodyNode.addNode(argNode);
|
||||
setContent(envNode);
|
||||
|
||||
String serviceType = service.getServiceType();
|
||||
String actionName = action.getName();
|
||||
String soapAction = "\"" +
|
||||
serviceType +
|
||||
"#" + actionName +
|
||||
"\"";
|
||||
setSOAPAction(soapAction);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Contents
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node createContentNode(Service service, Action action, ArgumentList argList)
|
||||
{
|
||||
String actionName = action.getName();
|
||||
String serviceType = service.getServiceType();
|
||||
|
||||
Node actionNode = new Node();
|
||||
actionNode.setName(Control.NS, actionName);
|
||||
actionNode.setNameSpace(Control.NS, serviceType);
|
||||
|
||||
int argListCnt = argList.size();
|
||||
for (int n=0; n<argListCnt; n++) {
|
||||
Argument arg = argList.getArgument(n);
|
||||
Node argNode = new Node();
|
||||
argNode.setName(arg.getName());
|
||||
argNode.setValue(arg.getValue());
|
||||
actionNode.addNode(argNode);
|
||||
}
|
||||
|
||||
return actionNode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ActionResponse post()
|
||||
{
|
||||
SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort());
|
||||
return new ActionResponse(soapRes);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ControlRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 05/09/05
|
||||
* - Changed getActionName() to return when the delimiter is not found.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.xml.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class ActionRequest extends ControlRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ActionRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public ActionRequest(HTTPRequest httpReq)
|
||||
{
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Action
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Node getActionNode()
|
||||
{
|
||||
Node bodyNode = getBodyNode();
|
||||
if (bodyNode == null)
|
||||
return null;
|
||||
if (bodyNode.hasNodes() == false)
|
||||
return null;
|
||||
return bodyNode.getNode(0);
|
||||
}
|
||||
|
||||
public String getActionName()
|
||||
{
|
||||
Node node = getActionNode();
|
||||
if (node == null)
|
||||
return "";
|
||||
String name = node.getName();
|
||||
if (name == null)
|
||||
return "";
|
||||
int idx = name.indexOf(SOAP.DELIM)+1;
|
||||
if (idx < 0)
|
||||
return "";
|
||||
return name.substring(idx, name.length());
|
||||
}
|
||||
|
||||
public ArgumentList getArgumentList()
|
||||
{
|
||||
Node actNode = getActionNode();
|
||||
int nArgNodes = actNode.getNNodes();
|
||||
ArgumentList argList = new ArgumentList();
|
||||
for (int n=0; n<nArgNodes; n++) {
|
||||
Argument arg = new Argument();
|
||||
Node argNode = actNode.getNode(n);
|
||||
arg.setName(argNode.getName());
|
||||
arg.setValue(argNode.getValue());
|
||||
argList.add(arg);
|
||||
}
|
||||
return argList;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// setRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setRequest(Action action, ArgumentList argList)
|
||||
{
|
||||
Service service = action.getService();
|
||||
|
||||
setRequestHost(service);
|
||||
|
||||
setEnvelopeNode(SOAP.createEnvelopeBodyNode());
|
||||
Node envNode = getEnvelopeNode();
|
||||
Node bodyNode = getBodyNode();
|
||||
Node argNode = createContentNode(service, action, argList);
|
||||
bodyNode.addNode(argNode);
|
||||
setContent(envNode);
|
||||
|
||||
String serviceType = service.getServiceType();
|
||||
String actionName = action.getName();
|
||||
String soapAction = "\"" +
|
||||
serviceType +
|
||||
"#" + actionName +
|
||||
"\"";
|
||||
setSOAPAction(soapAction);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Contents
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node createContentNode(Service service, Action action, ArgumentList argList)
|
||||
{
|
||||
String actionName = action.getName();
|
||||
String serviceType = service.getServiceType();
|
||||
|
||||
Node actionNode = new Node();
|
||||
actionNode.setName(Control.NS, actionName);
|
||||
actionNode.setNameSpace(Control.NS, serviceType);
|
||||
|
||||
int argListCnt = argList.size();
|
||||
for (int n=0; n<argListCnt; n++) {
|
||||
Argument arg = argList.getArgument(n);
|
||||
Node argNode = new Node();
|
||||
argNode.setName(arg.getName());
|
||||
argNode.setValue(arg.getValue());
|
||||
actionNode.addNode(argNode);
|
||||
}
|
||||
|
||||
return actionNode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ActionResponse post()
|
||||
{
|
||||
SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort());
|
||||
return new ActionResponse(soapRes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,120 +1,120 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ActionResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 09/02/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : Action Responses do not contain the mandatory header field EXT
|
||||
* - Error : ActionResponse class does not set the EXT header
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.soap.*;
|
||||
import org.cybergarage.xml.*;
|
||||
|
||||
public class ActionResponse extends ControlResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ActionResponse()
|
||||
{
|
||||
setHeader(HTTP.EXT, "");
|
||||
}
|
||||
|
||||
public ActionResponse(SOAPResponse soapRes)
|
||||
{
|
||||
super(soapRes);
|
||||
setHeader(HTTP.EXT, "");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Response
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setResponse(Action action)
|
||||
{
|
||||
setStatusCode(HTTPStatus.OK);
|
||||
|
||||
Node bodyNode = getBodyNode();
|
||||
Node resNode = createResponseNode(action);
|
||||
bodyNode.addNode(resNode);
|
||||
|
||||
Node envNode = getEnvelopeNode();
|
||||
setContent(envNode);
|
||||
}
|
||||
|
||||
private Node createResponseNode(Action action)
|
||||
{
|
||||
String actionName = action.getName();
|
||||
Node actionNameResNode = new Node(SOAP.METHODNS + SOAP.DELIM + actionName + SOAP.RESPONSE);
|
||||
|
||||
Service service = action.getService();
|
||||
if (service != null) {
|
||||
actionNameResNode.setAttribute(
|
||||
"xmlns:" + SOAP.METHODNS,
|
||||
service.getServiceType());
|
||||
}
|
||||
|
||||
ArgumentList argList = action.getArgumentList();
|
||||
int nArgs = argList.size();
|
||||
for (int n=0; n<nArgs; n++) {
|
||||
Argument arg = argList.getArgument(n);
|
||||
if (arg.isOutDirection() == false)
|
||||
continue;
|
||||
Node argNode = new Node();
|
||||
argNode.setName(arg.getName());
|
||||
argNode.setValue(arg.getValue());
|
||||
actionNameResNode.addNode(argNode);
|
||||
}
|
||||
|
||||
return actionNameResNode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getResponse
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node getActionResponseNode()
|
||||
{
|
||||
Node bodyNode = getBodyNode();
|
||||
if (bodyNode == null || bodyNode.hasNodes() == false)
|
||||
return null;
|
||||
return bodyNode.getNode(0);
|
||||
}
|
||||
|
||||
|
||||
public ArgumentList getResponse()
|
||||
{
|
||||
ArgumentList argList = new ArgumentList();
|
||||
|
||||
Node resNode = getActionResponseNode();
|
||||
if (resNode == null)
|
||||
return argList;
|
||||
|
||||
int nArgs = resNode.getNNodes();
|
||||
for (int n=0; n<nArgs; n++) {
|
||||
Node node = resNode.getNode(n);
|
||||
String name = node.getName();
|
||||
String value = node.getValue();
|
||||
Argument arg = new Argument(name, value);
|
||||
argList.add(arg);
|
||||
}
|
||||
|
||||
return argList;
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ActionResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 09/02/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : Action Responses do not contain the mandatory header field EXT
|
||||
* - Error : ActionResponse class does not set the EXT header
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.soap.*;
|
||||
import org.cybergarage.xml.*;
|
||||
|
||||
public class ActionResponse extends ControlResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ActionResponse()
|
||||
{
|
||||
setHeader(HTTP.EXT, "");
|
||||
}
|
||||
|
||||
public ActionResponse(SOAPResponse soapRes)
|
||||
{
|
||||
super(soapRes);
|
||||
setHeader(HTTP.EXT, "");
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Response
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setResponse(Action action)
|
||||
{
|
||||
setStatusCode(HTTPStatus.OK);
|
||||
|
||||
Node bodyNode = getBodyNode();
|
||||
Node resNode = createResponseNode(action);
|
||||
bodyNode.addNode(resNode);
|
||||
|
||||
Node envNode = getEnvelopeNode();
|
||||
setContent(envNode);
|
||||
}
|
||||
|
||||
private Node createResponseNode(Action action)
|
||||
{
|
||||
String actionName = action.getName();
|
||||
Node actionNameResNode = new Node(SOAP.METHODNS + SOAP.DELIM + actionName + SOAP.RESPONSE);
|
||||
|
||||
Service service = action.getService();
|
||||
if (service != null) {
|
||||
actionNameResNode.setAttribute(
|
||||
"xmlns:" + SOAP.METHODNS,
|
||||
service.getServiceType());
|
||||
}
|
||||
|
||||
ArgumentList argList = action.getArgumentList();
|
||||
int nArgs = argList.size();
|
||||
for (int n=0; n<nArgs; n++) {
|
||||
Argument arg = argList.getArgument(n);
|
||||
if (arg.isOutDirection() == false)
|
||||
continue;
|
||||
Node argNode = new Node();
|
||||
argNode.setName(arg.getName());
|
||||
argNode.setValue(arg.getValue());
|
||||
actionNameResNode.addNode(argNode);
|
||||
}
|
||||
|
||||
return actionNameResNode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getResponse
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node getActionResponseNode()
|
||||
{
|
||||
Node bodyNode = getBodyNode();
|
||||
if (bodyNode == null || bodyNode.hasNodes() == false)
|
||||
return null;
|
||||
return bodyNode.getNode(0);
|
||||
}
|
||||
|
||||
|
||||
public ArgumentList getResponse()
|
||||
{
|
||||
ArgumentList argList = new ArgumentList();
|
||||
|
||||
Node resNode = getActionResponseNode();
|
||||
if (resNode == null)
|
||||
return argList;
|
||||
|
||||
int nArgs = resNode.getNNodes();
|
||||
for (int n=0; n<nArgs; n++) {
|
||||
Node node = resNode.getNode(n);
|
||||
String name = node.getName();
|
||||
String value = node.getValue();
|
||||
Argument arg = new Argument(name, value);
|
||||
argList.add(arg);
|
||||
}
|
||||
|
||||
return argList;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,29 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: Control.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/20/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
public class Control
|
||||
{
|
||||
public final static String NS = "u";
|
||||
public final static String QUERY_SOAPACTION = "urn:schemas-upnp-org:control-1-0#QueryStateVariable";
|
||||
public final static String XMLNS = "urn:schemas-upnp-org:control-1-0";
|
||||
public final static String QUERY_STATE_VARIABLE = "QueryStateVariable";
|
||||
public final static String QUERY_STATE_VARIABLE_RESPONSE = "QueryStateVariableResponse";
|
||||
public final static String VAR_NAME = "varName";
|
||||
public final static String RETURN = "return";
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: Control.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/20/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
public class Control
|
||||
{
|
||||
public final static String NS = "u";
|
||||
public final static String QUERY_SOAPACTION = "urn:schemas-upnp-org:control-1-0#QueryStateVariable";
|
||||
public final static String XMLNS = "urn:schemas-upnp-org:control-1-0";
|
||||
public final static String QUERY_STATE_VARIABLE = "QueryStateVariable";
|
||||
public final static String QUERY_STATE_VARIABLE_RESPONSE = "QueryStateVariableResponse";
|
||||
public final static String VAR_NAME = "varName";
|
||||
public final static String RETURN = "return";
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,128 +1,128 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ControlRequest.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 05/22/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Description: inserted a check at the beginning of the setRequestHost method
|
||||
* - Problem : If the host does not start with a '/', the device could refuse the control action
|
||||
* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices
|
||||
* 09/02/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it> / Suzan Foster
|
||||
* - Problem : NullpointerException thrown for devices whose description use absolute urls
|
||||
* - Error : the presence of a base url is not mandatory, the API code makes the assumption that control and event subscription urls are relative.
|
||||
* If the baseUrl is not present, the request host and port should be extracted from the control/subscription url
|
||||
* - Description: The method setRequestHost/setService should be changed as follows
|
||||
* 02/17/04
|
||||
* - Rob van den Boomen <rob.van.den.boomen@philips.com>
|
||||
* - Fixed to set a URLBase from the SSDP header when the URLBase of the description is null.
|
||||
* 02/18/04
|
||||
* - Andre <andre@antiheld.net>
|
||||
* - The xml nodes controlUrl and eventSubUrl can contain absolut urls, but these absolut urls may have
|
||||
* different ports than the base url! (so seen on my SMC 7004ABR Barricade Router, where xml files are
|
||||
* requested from port 80, but soap requests are made on port 5440). Therefore whenever a request is made,
|
||||
* the port specified by the controlUrl or eventSubUrl node should be used, else no response will be returned
|
||||
* (oddly, there was a response returned even on port 80, but with empty body tags. but the correct response
|
||||
* finally came from port 5440).
|
||||
* - Fixed to get the port from the control url when it is absolute.
|
||||
* 03/20/04
|
||||
* - Thanks for Thomas Schulz <tsroyale at users.sourceforge.net>
|
||||
* - Fixed setRequestHost() for Sony's UPnP stack when the URLBase has the path.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class ControlRequest extends SOAPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ControlRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public ControlRequest(HTTPRequest httpReq)
|
||||
{
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Query
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean isQueryControl()
|
||||
{
|
||||
return isSOAPAction(Control.QUERY_SOAPACTION);
|
||||
}
|
||||
|
||||
public boolean isActionControl()
|
||||
{
|
||||
return !isQueryControl();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// setRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
protected void setRequestHost(Service service)
|
||||
{
|
||||
String ctrlURL = service.getControlURL();
|
||||
|
||||
// Thanks for Thomas Schulz (2004/03/20)
|
||||
String urlBase = service.getRootDevice().getURLBase();
|
||||
if (urlBase != null && 0 < urlBase.length()){
|
||||
try {
|
||||
URL url = new URL(urlBase);
|
||||
String basePath = url.getPath();
|
||||
int baseLen = basePath.length();
|
||||
if (0 < baseLen) {
|
||||
if (1 < baseLen || (basePath.charAt(0) != '/'))
|
||||
ctrlURL = basePath + ctrlURL;
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException e) {}
|
||||
}
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03)
|
||||
setURI(ctrlURL, true);
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> and Suzan Foster (09/02/03)
|
||||
// Thanks for Andre <andre@antiheld.net> (02/18/04)
|
||||
String postURL = "";
|
||||
if (HTTP.isAbsoluteURL(ctrlURL) == true)
|
||||
postURL = ctrlURL;
|
||||
|
||||
if (postURL == null || postURL.length() <= 0)
|
||||
postURL = service.getRootDevice().getURLBase();
|
||||
|
||||
// Thanks for Rob van den Boomen <rob.van.den.boomen@philips.com> (02/17/04)
|
||||
// BUGFIX, set urlbase from location string if not set in description.xml
|
||||
if (postURL == null || postURL.length() <= 0)
|
||||
postURL = service.getRootDevice().getLocation();
|
||||
|
||||
String reqHost = HTTP.getHost(postURL);
|
||||
int reqPort = HTTP.getPort(postURL);
|
||||
|
||||
setHost(reqHost, reqPort);
|
||||
setRequestHost(reqHost);
|
||||
setRequestPort(reqPort);
|
||||
}
|
||||
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ControlRequest.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 05/22/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Description: inserted a check at the beginning of the setRequestHost method
|
||||
* - Problem : If the host does not start with a '/', the device could refuse the control action
|
||||
* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices
|
||||
* 09/02/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it> / Suzan Foster
|
||||
* - Problem : NullpointerException thrown for devices whose description use absolute urls
|
||||
* - Error : the presence of a base url is not mandatory, the API code makes the assumption that control and event subscription urls are relative.
|
||||
* If the baseUrl is not present, the request host and port should be extracted from the control/subscription url
|
||||
* - Description: The method setRequestHost/setService should be changed as follows
|
||||
* 02/17/04
|
||||
* - Rob van den Boomen <rob.van.den.boomen@philips.com>
|
||||
* - Fixed to set a URLBase from the SSDP header when the URLBase of the description is null.
|
||||
* 02/18/04
|
||||
* - Andre <andre@antiheld.net>
|
||||
* - The xml nodes controlUrl and eventSubUrl can contain absolut urls, but these absolut urls may have
|
||||
* different ports than the base url! (so seen on my SMC 7004ABR Barricade Router, where xml files are
|
||||
* requested from port 80, but soap requests are made on port 5440). Therefore whenever a request is made,
|
||||
* the port specified by the controlUrl or eventSubUrl node should be used, else no response will be returned
|
||||
* (oddly, there was a response returned even on port 80, but with empty body tags. but the correct response
|
||||
* finally came from port 5440).
|
||||
* - Fixed to get the port from the control url when it is absolute.
|
||||
* 03/20/04
|
||||
* - Thanks for Thomas Schulz <tsroyale at users.sourceforge.net>
|
||||
* - Fixed setRequestHost() for Sony's UPnP stack when the URLBase has the path.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class ControlRequest extends SOAPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ControlRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public ControlRequest(HTTPRequest httpReq)
|
||||
{
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Query
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean isQueryControl()
|
||||
{
|
||||
return isSOAPAction(Control.QUERY_SOAPACTION);
|
||||
}
|
||||
|
||||
public boolean isActionControl()
|
||||
{
|
||||
return !isQueryControl();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// setRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
protected void setRequestHost(Service service)
|
||||
{
|
||||
String ctrlURL = service.getControlURL();
|
||||
|
||||
// Thanks for Thomas Schulz (2004/03/20)
|
||||
String urlBase = service.getRootDevice().getURLBase();
|
||||
if (urlBase != null && 0 < urlBase.length()){
|
||||
try {
|
||||
URL url = new URL(urlBase);
|
||||
String basePath = url.getPath();
|
||||
int baseLen = basePath.length();
|
||||
if (0 < baseLen) {
|
||||
if (1 < baseLen || (basePath.charAt(0) != '/'))
|
||||
ctrlURL = basePath + ctrlURL;
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException e) {}
|
||||
}
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03)
|
||||
setURI(ctrlURL, true);
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> and Suzan Foster (09/02/03)
|
||||
// Thanks for Andre <andre@antiheld.net> (02/18/04)
|
||||
String postURL = "";
|
||||
if (HTTP.isAbsoluteURL(ctrlURL) == true)
|
||||
postURL = ctrlURL;
|
||||
|
||||
if (postURL == null || postURL.length() <= 0)
|
||||
postURL = service.getRootDevice().getURLBase();
|
||||
|
||||
// Thanks for Rob van den Boomen <rob.van.den.boomen@philips.com> (02/17/04)
|
||||
// BUGFIX, set urlbase from location string if not set in description.xml
|
||||
if (postURL == null || postURL.length() <= 0)
|
||||
postURL = service.getRootDevice().getLocation();
|
||||
|
||||
String reqHost = HTTP.getHost(postURL);
|
||||
int reqPort = HTTP.getPort(postURL);
|
||||
|
||||
setHost(reqHost, reqPort);
|
||||
setRequestHost(reqHost);
|
||||
setRequestPort(reqPort);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,173 +1,173 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ControlResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.xml.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class ControlResponse extends SOAPResponse
|
||||
{
|
||||
public static final String FAULT_CODE = "Client";
|
||||
public static final String FAULT_STRING = "UPnPError";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ControlResponse()
|
||||
{
|
||||
setServer(UPnP.getServerName());
|
||||
}
|
||||
|
||||
public ControlResponse(SOAPResponse soapRes)
|
||||
{
|
||||
super(soapRes);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// FaultResponse
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setFaultResponse(int errCode, String errDescr)
|
||||
{
|
||||
setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR);
|
||||
|
||||
Node bodyNode = getBodyNode();
|
||||
Node faultNode = createFaultResponseNode(errCode, errDescr);
|
||||
bodyNode.addNode(faultNode);
|
||||
|
||||
Node envNode = getEnvelopeNode();
|
||||
setContent(envNode);
|
||||
}
|
||||
|
||||
public void setFaultResponse(int errCode)
|
||||
{
|
||||
setFaultResponse(errCode, UPnPStatus.code2String(errCode));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// createFaultResponseNode
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node createFaultResponseNode(int errCode, String errDescr)
|
||||
{
|
||||
// <s:Fault>
|
||||
Node faultNode = new Node(SOAP.XMLNS + SOAP.DELIM + SOAP.FAULT);
|
||||
|
||||
// <faultcode>s:Client</faultcode>
|
||||
Node faultCodeNode = new Node(SOAP.FAULT_CODE);
|
||||
faultCodeNode.setValue(SOAP.XMLNS + SOAP.DELIM + FAULT_CODE);
|
||||
faultNode.addNode(faultCodeNode);
|
||||
|
||||
// <faultstring>UPnPError</faultstring>
|
||||
Node faultStringNode = new Node(SOAP.FAULT_STRING);
|
||||
faultStringNode.setValue(FAULT_STRING);
|
||||
faultNode.addNode(faultStringNode);
|
||||
|
||||
// <detail>
|
||||
Node detailNode = new Node(SOAP.DETAIL);
|
||||
faultNode.addNode(detailNode);
|
||||
|
||||
// <UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
|
||||
Node upnpErrorNode = new Node(FAULT_STRING);
|
||||
upnpErrorNode.setAttribute("xmlns", Control.XMLNS);
|
||||
detailNode.addNode(upnpErrorNode);
|
||||
|
||||
// <errorCode>error code</errorCode>
|
||||
Node errorCodeNode = new Node(SOAP.ERROR_CODE);
|
||||
errorCodeNode.setValue(errCode);
|
||||
upnpErrorNode.addNode(errorCodeNode);
|
||||
|
||||
// <errorDescription>error string</errorDescription>
|
||||
Node errorDesctiprionNode = new Node(SOAP.ERROR_DESCRIPTION);
|
||||
errorDesctiprionNode.setValue(errDescr);
|
||||
upnpErrorNode.addNode(errorDesctiprionNode);
|
||||
|
||||
return faultNode;
|
||||
}
|
||||
|
||||
private Node createFaultResponseNode(int errCode)
|
||||
{
|
||||
return createFaultResponseNode(errCode, UPnPStatus.code2String(errCode));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// UPnP Error
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private UPnPStatus upnpErr = new UPnPStatus();
|
||||
|
||||
private Node getUPnPErrorNode()
|
||||
{
|
||||
Node detailNode = getFaultDetailNode();
|
||||
if (detailNode == null)
|
||||
return null;
|
||||
return detailNode.getNodeEndsWith(SOAP.UPNP_ERROR);
|
||||
}
|
||||
|
||||
private Node getUPnPErrorCodeNode()
|
||||
{
|
||||
Node errorNode = getUPnPErrorNode();
|
||||
if (errorNode == null)
|
||||
return null;
|
||||
return errorNode.getNodeEndsWith(SOAP.ERROR_CODE);
|
||||
}
|
||||
|
||||
private Node getUPnPErrorDescriptionNode()
|
||||
{
|
||||
Node errorNode = getUPnPErrorNode();
|
||||
if (errorNode == null)
|
||||
return null;
|
||||
return errorNode.getNodeEndsWith(SOAP.ERROR_DESCRIPTION);
|
||||
}
|
||||
|
||||
public int getUPnPErrorCode()
|
||||
{
|
||||
Node errorCodeNode = getUPnPErrorCodeNode();
|
||||
if (errorCodeNode == null)
|
||||
return -1;
|
||||
String errorCodeStr = errorCodeNode.getValue();
|
||||
try {
|
||||
return Integer.parseInt(errorCodeStr);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUPnPErrorDescription()
|
||||
{
|
||||
Node errorDescNode = getUPnPErrorDescriptionNode();
|
||||
if (errorDescNode == null)
|
||||
return "";
|
||||
return errorDescNode.getValue();
|
||||
}
|
||||
|
||||
public UPnPStatus getUPnPError()
|
||||
{
|
||||
int code = 0;
|
||||
String desc = "";
|
||||
code = getUPnPErrorCode();
|
||||
desc = getUPnPErrorDescription();
|
||||
upnpErr.setCode(code);
|
||||
upnpErr.setDescription(desc);
|
||||
return upnpErr;
|
||||
}
|
||||
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ControlResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.xml.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class ControlResponse extends SOAPResponse
|
||||
{
|
||||
public static final String FAULT_CODE = "Client";
|
||||
public static final String FAULT_STRING = "UPnPError";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ControlResponse()
|
||||
{
|
||||
setServer(UPnP.getServerName());
|
||||
}
|
||||
|
||||
public ControlResponse(SOAPResponse soapRes)
|
||||
{
|
||||
super(soapRes);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// FaultResponse
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setFaultResponse(int errCode, String errDescr)
|
||||
{
|
||||
setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR);
|
||||
|
||||
Node bodyNode = getBodyNode();
|
||||
Node faultNode = createFaultResponseNode(errCode, errDescr);
|
||||
bodyNode.addNode(faultNode);
|
||||
|
||||
Node envNode = getEnvelopeNode();
|
||||
setContent(envNode);
|
||||
}
|
||||
|
||||
public void setFaultResponse(int errCode)
|
||||
{
|
||||
setFaultResponse(errCode, UPnPStatus.code2String(errCode));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// createFaultResponseNode
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node createFaultResponseNode(int errCode, String errDescr)
|
||||
{
|
||||
// <s:Fault>
|
||||
Node faultNode = new Node(SOAP.XMLNS + SOAP.DELIM + SOAP.FAULT);
|
||||
|
||||
// <faultcode>s:Client</faultcode>
|
||||
Node faultCodeNode = new Node(SOAP.FAULT_CODE);
|
||||
faultCodeNode.setValue(SOAP.XMLNS + SOAP.DELIM + FAULT_CODE);
|
||||
faultNode.addNode(faultCodeNode);
|
||||
|
||||
// <faultstring>UPnPError</faultstring>
|
||||
Node faultStringNode = new Node(SOAP.FAULT_STRING);
|
||||
faultStringNode.setValue(FAULT_STRING);
|
||||
faultNode.addNode(faultStringNode);
|
||||
|
||||
// <detail>
|
||||
Node detailNode = new Node(SOAP.DETAIL);
|
||||
faultNode.addNode(detailNode);
|
||||
|
||||
// <UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
|
||||
Node upnpErrorNode = new Node(FAULT_STRING);
|
||||
upnpErrorNode.setAttribute("xmlns", Control.XMLNS);
|
||||
detailNode.addNode(upnpErrorNode);
|
||||
|
||||
// <errorCode>error code</errorCode>
|
||||
Node errorCodeNode = new Node(SOAP.ERROR_CODE);
|
||||
errorCodeNode.setValue(errCode);
|
||||
upnpErrorNode.addNode(errorCodeNode);
|
||||
|
||||
// <errorDescription>error string</errorDescription>
|
||||
Node errorDesctiprionNode = new Node(SOAP.ERROR_DESCRIPTION);
|
||||
errorDesctiprionNode.setValue(errDescr);
|
||||
upnpErrorNode.addNode(errorDesctiprionNode);
|
||||
|
||||
return faultNode;
|
||||
}
|
||||
|
||||
private Node createFaultResponseNode(int errCode)
|
||||
{
|
||||
return createFaultResponseNode(errCode, UPnPStatus.code2String(errCode));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// UPnP Error
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private UPnPStatus upnpErr = new UPnPStatus();
|
||||
|
||||
private Node getUPnPErrorNode()
|
||||
{
|
||||
Node detailNode = getFaultDetailNode();
|
||||
if (detailNode == null)
|
||||
return null;
|
||||
return detailNode.getNodeEndsWith(SOAP.UPNP_ERROR);
|
||||
}
|
||||
|
||||
private Node getUPnPErrorCodeNode()
|
||||
{
|
||||
Node errorNode = getUPnPErrorNode();
|
||||
if (errorNode == null)
|
||||
return null;
|
||||
return errorNode.getNodeEndsWith(SOAP.ERROR_CODE);
|
||||
}
|
||||
|
||||
private Node getUPnPErrorDescriptionNode()
|
||||
{
|
||||
Node errorNode = getUPnPErrorNode();
|
||||
if (errorNode == null)
|
||||
return null;
|
||||
return errorNode.getNodeEndsWith(SOAP.ERROR_DESCRIPTION);
|
||||
}
|
||||
|
||||
public int getUPnPErrorCode()
|
||||
{
|
||||
Node errorCodeNode = getUPnPErrorCodeNode();
|
||||
if (errorCodeNode == null)
|
||||
return -1;
|
||||
String errorCodeStr = errorCodeNode.getValue();
|
||||
try {
|
||||
return Integer.parseInt(errorCodeStr);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUPnPErrorDescription()
|
||||
{
|
||||
Node errorDescNode = getUPnPErrorDescriptionNode();
|
||||
if (errorDescNode == null)
|
||||
return "";
|
||||
return errorDescNode.getValue();
|
||||
}
|
||||
|
||||
public UPnPStatus getUPnPError()
|
||||
{
|
||||
int code = 0;
|
||||
String desc = "";
|
||||
code = getUPnPErrorCode();
|
||||
desc = getUPnPErrorDescription();
|
||||
upnpErr.setCode(code);
|
||||
upnpErr.setDescription(desc);
|
||||
return upnpErr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: QueryListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/30/03
|
||||
* - first revision.
|
||||
* 01/04/04
|
||||
* - Changed the interface.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public interface QueryListener
|
||||
{
|
||||
public boolean queryControlReceived(StateVariable stateVar);
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: QueryListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/30/03
|
||||
* - first revision.
|
||||
* 01/04/04
|
||||
* - Changed the interface.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public interface QueryListener
|
||||
{
|
||||
public boolean queryControlReceived(StateVariable stateVar);
|
||||
}
|
||||
|
@ -1,119 +1,119 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: QueryRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 09/02/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Error : redundant code, the setRequest method in QueryRequest invokes setURI even if after a couple of rows setRequestHost is invoked
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.xml.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class QueryRequest extends ControlRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public QueryRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public QueryRequest(HTTPRequest httpReq)
|
||||
{
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Qyery
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node getVarNameNode()
|
||||
{
|
||||
Node bodyNode = getBodyNode();
|
||||
if (bodyNode == null)
|
||||
return null;
|
||||
if (bodyNode.hasNodes() == false)
|
||||
return null;
|
||||
Node queryStateVarNode = bodyNode.getNode(0);
|
||||
if (queryStateVarNode == null)
|
||||
return null;
|
||||
if (queryStateVarNode.hasNodes() == false)
|
||||
return null;
|
||||
return queryStateVarNode.getNode(0);
|
||||
}
|
||||
|
||||
public String getVarName()
|
||||
{
|
||||
Node node = getVarNameNode();
|
||||
if (node == null)
|
||||
return "";
|
||||
return node.getValue();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// setRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setRequest(StateVariable stateVar)
|
||||
{
|
||||
Service service = stateVar.getService();
|
||||
|
||||
String ctrlURL = service.getControlURL();
|
||||
|
||||
setRequestHost(service);
|
||||
|
||||
setEnvelopeNode(SOAP.createEnvelopeBodyNode());
|
||||
Node envNode = getEnvelopeNode();
|
||||
Node bodyNode = getBodyNode();
|
||||
Node qeuryNode = createContentNode(stateVar);
|
||||
bodyNode.addNode(qeuryNode);
|
||||
setContent(envNode);
|
||||
|
||||
setSOAPAction(Control.QUERY_SOAPACTION);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Contents
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node createContentNode(StateVariable stateVar)
|
||||
{
|
||||
Node queryVarNode = new Node();
|
||||
queryVarNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE);
|
||||
queryVarNode.setNameSpace(Control.NS, Control.XMLNS);
|
||||
|
||||
Node varNode = new Node();
|
||||
varNode.setName(Control.NS, Control.VAR_NAME);
|
||||
varNode.setValue(stateVar.getName());
|
||||
queryVarNode.addNode(varNode);
|
||||
|
||||
return queryVarNode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public QueryResponse post()
|
||||
{
|
||||
SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort());
|
||||
return new QueryResponse(soapRes);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: QueryRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 09/02/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Error : redundant code, the setRequest method in QueryRequest invokes setURI even if after a couple of rows setRequestHost is invoked
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.xml.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class QueryRequest extends ControlRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public QueryRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public QueryRequest(HTTPRequest httpReq)
|
||||
{
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Qyery
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node getVarNameNode()
|
||||
{
|
||||
Node bodyNode = getBodyNode();
|
||||
if (bodyNode == null)
|
||||
return null;
|
||||
if (bodyNode.hasNodes() == false)
|
||||
return null;
|
||||
Node queryStateVarNode = bodyNode.getNode(0);
|
||||
if (queryStateVarNode == null)
|
||||
return null;
|
||||
if (queryStateVarNode.hasNodes() == false)
|
||||
return null;
|
||||
return queryStateVarNode.getNode(0);
|
||||
}
|
||||
|
||||
public String getVarName()
|
||||
{
|
||||
Node node = getVarNameNode();
|
||||
if (node == null)
|
||||
return "";
|
||||
return node.getValue();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// setRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setRequest(StateVariable stateVar)
|
||||
{
|
||||
Service service = stateVar.getService();
|
||||
|
||||
String ctrlURL = service.getControlURL();
|
||||
|
||||
setRequestHost(service);
|
||||
|
||||
setEnvelopeNode(SOAP.createEnvelopeBodyNode());
|
||||
Node envNode = getEnvelopeNode();
|
||||
Node bodyNode = getBodyNode();
|
||||
Node qeuryNode = createContentNode(stateVar);
|
||||
bodyNode.addNode(qeuryNode);
|
||||
setContent(envNode);
|
||||
|
||||
setSOAPAction(Control.QUERY_SOAPACTION);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Contents
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node createContentNode(StateVariable stateVar)
|
||||
{
|
||||
Node queryVarNode = new Node();
|
||||
queryVarNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE);
|
||||
queryVarNode.setNameSpace(Control.NS, Control.XMLNS);
|
||||
|
||||
Node varNode = new Node();
|
||||
varNode.setName(Control.NS, Control.VAR_NAME);
|
||||
varNode.setValue(stateVar.getName());
|
||||
queryVarNode.addNode(varNode);
|
||||
|
||||
return queryVarNode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public QueryResponse post()
|
||||
{
|
||||
SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort());
|
||||
return new QueryResponse(soapRes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,97 +1,97 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: QueryResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/30/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.soap.*;
|
||||
import org.cybergarage.xml.*;
|
||||
|
||||
public class QueryResponse extends ControlResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public QueryResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public QueryResponse(SOAPResponse soapRes)
|
||||
{
|
||||
super(soapRes);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Qyery
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node getReturnNode()
|
||||
{
|
||||
Node bodyNode = getBodyNode();
|
||||
if (bodyNode == null)
|
||||
return null;
|
||||
if (bodyNode.hasNodes() == false)
|
||||
return null;
|
||||
Node queryResNode = bodyNode.getNode(0);
|
||||
if (queryResNode == null)
|
||||
return null;
|
||||
if (queryResNode.hasNodes() == false)
|
||||
return null;
|
||||
return queryResNode.getNode(0);
|
||||
}
|
||||
|
||||
public String getReturnValue()
|
||||
{
|
||||
Node node = getReturnNode();
|
||||
if (node == null)
|
||||
return "";
|
||||
return node.getValue();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Response
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setResponse(StateVariable stateVar)
|
||||
{
|
||||
String var = stateVar.getValue();
|
||||
|
||||
setStatusCode(HTTPStatus.OK);
|
||||
|
||||
Node bodyNode = getBodyNode();
|
||||
Node resNode = createResponseNode(var);
|
||||
bodyNode.addNode(resNode);
|
||||
|
||||
Node envNodee = getEnvelopeNode();
|
||||
setContent(envNodee);
|
||||
|
||||
}
|
||||
|
||||
private Node createResponseNode(String var)
|
||||
{
|
||||
Node queryResNode = new Node();
|
||||
queryResNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE_RESPONSE);
|
||||
queryResNode.setNameSpace(Control.NS, Control.XMLNS);
|
||||
|
||||
Node returnNode = new Node();
|
||||
returnNode.setName(Control.RETURN);
|
||||
returnNode.setValue(var);
|
||||
queryResNode.addNode(returnNode);
|
||||
|
||||
return queryResNode;
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: QueryResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/30/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.soap.*;
|
||||
import org.cybergarage.xml.*;
|
||||
|
||||
public class QueryResponse extends ControlResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public QueryResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public QueryResponse(SOAPResponse soapRes)
|
||||
{
|
||||
super(soapRes);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Qyery
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node getReturnNode()
|
||||
{
|
||||
Node bodyNode = getBodyNode();
|
||||
if (bodyNode == null)
|
||||
return null;
|
||||
if (bodyNode.hasNodes() == false)
|
||||
return null;
|
||||
Node queryResNode = bodyNode.getNode(0);
|
||||
if (queryResNode == null)
|
||||
return null;
|
||||
if (queryResNode.hasNodes() == false)
|
||||
return null;
|
||||
return queryResNode.getNode(0);
|
||||
}
|
||||
|
||||
public String getReturnValue()
|
||||
{
|
||||
Node node = getReturnNode();
|
||||
if (node == null)
|
||||
return "";
|
||||
return node.getValue();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Response
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setResponse(StateVariable stateVar)
|
||||
{
|
||||
String var = stateVar.getValue();
|
||||
|
||||
setStatusCode(HTTPStatus.OK);
|
||||
|
||||
Node bodyNode = getBodyNode();
|
||||
Node resNode = createResponseNode(var);
|
||||
bodyNode.addNode(resNode);
|
||||
|
||||
Node envNodee = getEnvelopeNode();
|
||||
setContent(envNodee);
|
||||
|
||||
}
|
||||
|
||||
private Node createResponseNode(String var)
|
||||
{
|
||||
Node queryResNode = new Node();
|
||||
queryResNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE_RESPONSE);
|
||||
queryResNode.setNameSpace(Control.NS, Control.XMLNS);
|
||||
|
||||
Node returnNode = new Node();
|
||||
returnNode.setName(Control.RETURN);
|
||||
returnNode.setValue(var);
|
||||
queryResNode.addNode(returnNode);
|
||||
|
||||
return queryResNode;
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +1,65 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: RenewSubscriber.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 07/07/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.util.*;
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class RenewSubscriber extends ThreadCore
|
||||
{
|
||||
public final static long INTERVAL = 120;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public RenewSubscriber(ControlPoint ctrlp)
|
||||
{
|
||||
setControlPoint(ctrlp);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ControlPoint ctrlPoint;
|
||||
|
||||
public void setControlPoint(ControlPoint ctrlp)
|
||||
{
|
||||
ctrlPoint = ctrlp;
|
||||
}
|
||||
|
||||
public ControlPoint getControlPoint()
|
||||
{
|
||||
return ctrlPoint;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Thread
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void run()
|
||||
{
|
||||
ControlPoint ctrlp = getControlPoint();
|
||||
long renewInterval = INTERVAL * 1000;
|
||||
while (isRunnable() == true) {
|
||||
try {
|
||||
Thread.sleep(renewInterval);
|
||||
} catch (InterruptedException e) {}
|
||||
ctrlp.renewSubscriberService();
|
||||
}
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: RenewSubscriber.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 07/07/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.control;
|
||||
|
||||
import org.cybergarage.util.*;
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class RenewSubscriber extends ThreadCore
|
||||
{
|
||||
public final static long INTERVAL = 120;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public RenewSubscriber(ControlPoint ctrlp)
|
||||
{
|
||||
setControlPoint(ctrlp);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ControlPoint ctrlPoint;
|
||||
|
||||
public void setControlPoint(ControlPoint ctrlp)
|
||||
{
|
||||
ctrlPoint = ctrlp;
|
||||
}
|
||||
|
||||
public ControlPoint getControlPoint()
|
||||
{
|
||||
return ctrlPoint;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Thread
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void run()
|
||||
{
|
||||
ControlPoint ctrlp = getControlPoint();
|
||||
long renewInterval = INTERVAL * 1000;
|
||||
while (isRunnable() == true) {
|
||||
try {
|
||||
Thread.sleep(renewInterval);
|
||||
} catch (InterruptedException e) {}
|
||||
ctrlp.renewSubscriberService();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,68 +1,68 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: Advertiser.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/24/03
|
||||
* - first revision.
|
||||
* 06/18/04
|
||||
* - Changed to advertise every 25%-50% of the periodic notification cycle for NMPR;
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.util.*;
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class Advertiser extends ThreadCore
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Advertiser(Device dev)
|
||||
{
|
||||
setDevice(dev);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Device device;
|
||||
|
||||
public void setDevice(Device dev)
|
||||
{
|
||||
device = dev;
|
||||
}
|
||||
|
||||
public Device getDevice()
|
||||
{
|
||||
return device;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Thread
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void run()
|
||||
{
|
||||
Device dev = getDevice();
|
||||
long leaseTime = dev.getLeaseTime();
|
||||
long notifyInterval;
|
||||
while (isRunnable() == true) {
|
||||
notifyInterval = (leaseTime/4) + (long)((float)leaseTime * (Math.random() * 0.25f));
|
||||
notifyInterval *= 1000;
|
||||
try {
|
||||
Thread.sleep(notifyInterval);
|
||||
} catch (InterruptedException e) {}
|
||||
dev.announce();
|
||||
}
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: Advertiser.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/24/03
|
||||
* - first revision.
|
||||
* 06/18/04
|
||||
* - Changed to advertise every 25%-50% of the periodic notification cycle for NMPR;
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.util.*;
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class Advertiser extends ThreadCore
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Advertiser(Device dev)
|
||||
{
|
||||
setDevice(dev);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Device device;
|
||||
|
||||
public void setDevice(Device dev)
|
||||
{
|
||||
device = dev;
|
||||
}
|
||||
|
||||
public Device getDevice()
|
||||
{
|
||||
return device;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Thread
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void run()
|
||||
{
|
||||
Device dev = getDevice();
|
||||
long leaseTime = dev.getLeaseTime();
|
||||
long notifyInterval;
|
||||
while (isRunnable() == true) {
|
||||
notifyInterval = (leaseTime/4) + (long)((float)leaseTime * (Math.random() * 0.25f));
|
||||
notifyInterval *= 1000;
|
||||
try {
|
||||
Thread.sleep(notifyInterval);
|
||||
} catch (InterruptedException e) {}
|
||||
dev.announce();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: MAN.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/30/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: MAN.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/30/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class Description
|
||||
{
|
||||
public final static String LOADING_EXCEPTION = "Couldn't load a specified description file ";
|
||||
public final static String NOROOT_EXCEPTION = "Couldn't find a root node";
|
||||
public final static String NOROOTDEVICE_EXCEPTION = "Couldn't find a root device node";
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class Description
|
||||
{
|
||||
public final static String LOADING_EXCEPTION = "Couldn't load a specified description file ";
|
||||
public final static String NOROOT_EXCEPTION = "Couldn't find a root node";
|
||||
public final static String NOROOTDEVICE_EXCEPTION = "Couldn't find a root device node";
|
||||
}
|
||||
|
||||
|
@ -1,66 +1,66 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberLink for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: Disposer.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/05/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.util.*;
|
||||
|
||||
public class Disposer extends ThreadCore
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Disposer(ControlPoint ctrlp)
|
||||
{
|
||||
setControlPoint(ctrlp);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ControlPoint ctrlPoint;
|
||||
|
||||
public void setControlPoint(ControlPoint ctrlp)
|
||||
{
|
||||
ctrlPoint = ctrlp;
|
||||
}
|
||||
|
||||
public ControlPoint getControlPoint()
|
||||
{
|
||||
return ctrlPoint;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Thread
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void run()
|
||||
{
|
||||
Thread.currentThread().setName("UPnP-Disposer");
|
||||
ControlPoint ctrlp = getControlPoint();
|
||||
long monitorInterval = ctrlp.getExpiredDeviceMonitoringInterval() * 1000;
|
||||
|
||||
while (isRunnable() == true) {
|
||||
try {
|
||||
Thread.sleep(monitorInterval);
|
||||
} catch (InterruptedException e) {}
|
||||
ctrlp.removeExpiredDevices();
|
||||
//ctrlp.print();
|
||||
}
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberLink for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: Disposer.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/05/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.util.*;
|
||||
|
||||
public class Disposer extends ThreadCore
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Disposer(ControlPoint ctrlp)
|
||||
{
|
||||
setControlPoint(ctrlp);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ControlPoint ctrlPoint;
|
||||
|
||||
public void setControlPoint(ControlPoint ctrlp)
|
||||
{
|
||||
ctrlPoint = ctrlp;
|
||||
}
|
||||
|
||||
public ControlPoint getControlPoint()
|
||||
{
|
||||
return ctrlPoint;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Thread
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void run()
|
||||
{
|
||||
Thread.currentThread().setName("UPnP-Disposer");
|
||||
ControlPoint ctrlp = getControlPoint();
|
||||
long monitorInterval = ctrlp.getExpiredDeviceMonitoringInterval() * 1000;
|
||||
|
||||
while (isRunnable() == true) {
|
||||
try {
|
||||
Thread.sleep(monitorInterval);
|
||||
} catch (InterruptedException e) {}
|
||||
ctrlp.removeExpiredDevices();
|
||||
//ctrlp.print();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,37 +5,37 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: InvalidDescriptionException.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/26/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/26/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class InvalidDescriptionException extends Exception
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class InvalidDescriptionException extends Exception
|
||||
{
|
||||
public InvalidDescriptionException()
|
||||
public InvalidDescriptionException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidDescriptionException(String s)
|
||||
public InvalidDescriptionException(String s)
|
||||
{
|
||||
super(s);
|
||||
}
|
||||
|
||||
public InvalidDescriptionException(String s, File file)
|
||||
|
||||
public InvalidDescriptionException(String s, File file)
|
||||
{
|
||||
super(s + " (" + file.toString() + ")");
|
||||
}
|
||||
|
||||
public InvalidDescriptionException(Exception e)
|
||||
|
||||
public InvalidDescriptionException(Exception e)
|
||||
{
|
||||
super(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: MAN.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/30/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: MAN.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/30/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class MAN
|
||||
{
|
||||
public final static String DISCOVER = "ssdp:discover";
|
||||
|
||||
public final static boolean isDiscover(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.equals(MAN.DISCOVER) == true)
|
||||
return true;
|
||||
return value.equals("\"" + MAN.DISCOVER + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class MAN
|
||||
{
|
||||
public final static String DISCOVER = "ssdp:discover";
|
||||
|
||||
public final static boolean isDiscover(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.equals(MAN.DISCOVER) == true)
|
||||
return true;
|
||||
return value.equals("\"" + MAN.DISCOVER + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,30 +1,30 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: NT.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/09/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: NT.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/09/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class NT
|
||||
{
|
||||
public final static String ROOTDEVICE = "upnp:rootdevice";
|
||||
public final static String EVENT = "upnp:event";
|
||||
|
||||
public final static boolean isRootDevice(String ntValue)
|
||||
{
|
||||
if (ntValue == null)
|
||||
return false;
|
||||
return ntValue.startsWith(ROOTDEVICE);
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class NT
|
||||
{
|
||||
public final static String ROOTDEVICE = "upnp:rootdevice";
|
||||
public final static String EVENT = "upnp:event";
|
||||
|
||||
public final static boolean isRootDevice(String ntValue)
|
||||
{
|
||||
if (ntValue == null)
|
||||
return false;
|
||||
return ntValue.startsWith(ROOTDEVICE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,38 +1,38 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: NTS.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/09/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: NTS.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/09/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class NTS
|
||||
{
|
||||
public final static String ALIVE = "ssdp:alive";
|
||||
public final static String BYEBYE = "ssdp:byebye";
|
||||
public final static String PROPCHANGE = "upnp:propchange";
|
||||
|
||||
public final static boolean isAlive(String ntsValue)
|
||||
{
|
||||
if (ntsValue == null)
|
||||
return false;
|
||||
return ntsValue.startsWith(NTS.ALIVE);
|
||||
}
|
||||
|
||||
public final static boolean isByeBye(String ntsValue)
|
||||
{
|
||||
if (ntsValue == null)
|
||||
return false;
|
||||
return ntsValue.startsWith(NTS.BYEBYE);
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class NTS
|
||||
{
|
||||
public final static String ALIVE = "ssdp:alive";
|
||||
public final static String BYEBYE = "ssdp:byebye";
|
||||
public final static String PROPCHANGE = "upnp:propchange";
|
||||
|
||||
public final static boolean isAlive(String ntsValue)
|
||||
{
|
||||
if (ntsValue == null)
|
||||
return false;
|
||||
return ntsValue.startsWith(NTS.ALIVE);
|
||||
}
|
||||
|
||||
public final static boolean isByeBye(String ntsValue)
|
||||
{
|
||||
if (ntsValue == null)
|
||||
return false;
|
||||
return ntsValue.startsWith(NTS.BYEBYE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,19 +5,19 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: DeviceNotifyListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.upnp.ssdp.*;
|
||||
|
||||
public interface NotifyListener
|
||||
{
|
||||
public void deviceNotifyReceived(SSDPPacket ssdpPacket);
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.upnp.ssdp.*;
|
||||
|
||||
public interface NotifyListener
|
||||
{
|
||||
public void deviceNotifyReceived(SSDPPacket ssdpPacket);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -1,71 +1,71 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
/******************************************************************
|
||||
*
|
||||
* File: ST.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/07/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ST.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/07/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class ST
|
||||
{
|
||||
public final static String ALL_DEVICE = "ssdp:all";
|
||||
public final static String ROOT_DEVICE = "upnp:rootdevice";
|
||||
public final static String UUID_DEVICE = "uuid";
|
||||
public final static String URN_DEVICE = "urn:schemas-upnp-org:device:";
|
||||
public final static String URN_SERVICE = "urn:schemas-upnp-org:service:";
|
||||
|
||||
public final static boolean isAllDevice(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.equals(ALL_DEVICE) == true)
|
||||
return true;
|
||||
return value.equals("\"" + ALL_DEVICE + "\"");
|
||||
}
|
||||
|
||||
public final static boolean isRootDevice(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.equals(ROOT_DEVICE) == true)
|
||||
return true;
|
||||
return value.equals("\"" + ROOT_DEVICE + "\"");
|
||||
}
|
||||
|
||||
public final static boolean isUUIDDevice(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.startsWith(UUID_DEVICE) == true)
|
||||
return true;
|
||||
return value.startsWith("\"" + UUID_DEVICE);
|
||||
}
|
||||
|
||||
public final static boolean isURNDevice(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.startsWith(URN_DEVICE) == true)
|
||||
return true;
|
||||
return value.startsWith("\"" + URN_DEVICE);
|
||||
}
|
||||
|
||||
public final static boolean isURNService(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.startsWith(URN_SERVICE) == true)
|
||||
return true;
|
||||
return value.startsWith("\"" + URN_SERVICE);
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class ST
|
||||
{
|
||||
public final static String ALL_DEVICE = "ssdp:all";
|
||||
public final static String ROOT_DEVICE = "upnp:rootdevice";
|
||||
public final static String UUID_DEVICE = "uuid";
|
||||
public final static String URN_DEVICE = "urn:schemas-upnp-org:device:";
|
||||
public final static String URN_SERVICE = "urn:schemas-upnp-org:service:";
|
||||
|
||||
public final static boolean isAllDevice(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.equals(ALL_DEVICE) == true)
|
||||
return true;
|
||||
return value.equals("\"" + ALL_DEVICE + "\"");
|
||||
}
|
||||
|
||||
public final static boolean isRootDevice(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.equals(ROOT_DEVICE) == true)
|
||||
return true;
|
||||
return value.equals("\"" + ROOT_DEVICE + "\"");
|
||||
}
|
||||
|
||||
public final static boolean isUUIDDevice(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.startsWith(UUID_DEVICE) == true)
|
||||
return true;
|
||||
return value.startsWith("\"" + UUID_DEVICE);
|
||||
}
|
||||
|
||||
public final static boolean isURNDevice(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.startsWith(URN_DEVICE) == true)
|
||||
return true;
|
||||
return value.startsWith("\"" + URN_DEVICE);
|
||||
}
|
||||
|
||||
public final static boolean isURNService(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.startsWith(URN_SERVICE) == true)
|
||||
return true;
|
||||
return value.startsWith("\"" + URN_SERVICE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SearchListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02b
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.upnp.ssdp.*;
|
||||
|
||||
public interface SearchListener
|
||||
{
|
||||
public void deviceSearchReceived(SSDPPacket ssdpPacket);
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SearchListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02b
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.upnp.ssdp.*;
|
||||
|
||||
public interface SearchListener
|
||||
{
|
||||
public void deviceSearchReceived(SSDPPacket ssdpPacket);
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SearchResponseListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.upnp.ssdp.*;
|
||||
|
||||
public interface SearchResponseListener
|
||||
{
|
||||
public void deviceSearchResponseReceived(SSDPPacket ssdpPacket);
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SearchResponseListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
import org.cybergarage.upnp.ssdp.*;
|
||||
|
||||
public interface SearchResponseListener
|
||||
{
|
||||
public void deviceSearchResponseReceived(SSDPPacket ssdpPacket);
|
||||
}
|
||||
|
@ -1,40 +1,40 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: USN.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/09/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: USN.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/09/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class USN
|
||||
{
|
||||
public final static String ROOTDEVICE = "upnp:rootdevice";
|
||||
|
||||
public final static boolean isRootDevice(String usnValue)
|
||||
{
|
||||
if (usnValue == null)
|
||||
return false;
|
||||
return usnValue.endsWith(ROOTDEVICE);
|
||||
}
|
||||
|
||||
public final static String getUDN(String usnValue)
|
||||
{
|
||||
if (usnValue == null)
|
||||
return "";
|
||||
int idx = usnValue.indexOf("::");
|
||||
if (idx < 0)
|
||||
return usnValue.trim();
|
||||
String udnValue = new String(usnValue.getBytes(), 0, idx);
|
||||
return udnValue.trim();
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp.device;
|
||||
|
||||
public class USN
|
||||
{
|
||||
public final static String ROOTDEVICE = "upnp:rootdevice";
|
||||
|
||||
public final static boolean isRootDevice(String usnValue)
|
||||
{
|
||||
if (usnValue == null)
|
||||
return false;
|
||||
return usnValue.endsWith(ROOTDEVICE);
|
||||
}
|
||||
|
||||
public final static String getUDN(String usnValue)
|
||||
{
|
||||
if (usnValue == null)
|
||||
return "";
|
||||
int idx = usnValue.indexOf("::");
|
||||
if (idx < 0)
|
||||
return usnValue.trim();
|
||||
String udnValue = new String(usnValue.getBytes(), 0, idx);
|
||||
return udnValue.trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,21 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: EventListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
public interface EventListener
|
||||
{
|
||||
public void eventNotifyReceived(String uuid, long seq, String varName, String value);
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: EventListener.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
public interface EventListener
|
||||
{
|
||||
public void eventNotifyReceived(String uuid, long seq, String varName, String value);
|
||||
}
|
||||
|
@ -1,205 +1,205 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SOAPRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/11/02
|
||||
* - first revision.
|
||||
* 05/22/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Description: removed the xml namespace
|
||||
* - Problem : Notification messages refer to uncorrect variable names
|
||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||
* 05/22/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : Notification messages refer to uncorrect variable names
|
||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||
* - Description : removed the xml namespace
|
||||
* 09/03/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : Notification messages refer to uncorrect variable names
|
||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||
* - Description: removed the xml namespace
|
||||
* 09/08/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : when an event notification message is received and the message
|
||||
* contains updates on more than one variable, only the first variable update
|
||||
* is notified.
|
||||
* - Error : the other xml nodes of the message are ignored
|
||||
* - Fix : add two methods to the NotifyRequest for extracting the property array
|
||||
* and modify the httpRequestRecieved method in ControlPoint
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.xml.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class NotifyRequest extends SOAPRequest
|
||||
{
|
||||
private final static String XMLNS = "e";
|
||||
private final static String PROPERTY = "property";
|
||||
private final static String PROPERTYSET = "propertyset";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public NotifyRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public NotifyRequest(HTTPRequest httpReq)
|
||||
{
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NT
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNT(String value)
|
||||
{
|
||||
setHeader(HTTP.NT, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NTS
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNTS(String value)
|
||||
{
|
||||
setHeader(HTTP.NTS, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setSID(String id)
|
||||
{
|
||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||
}
|
||||
|
||||
public String getSID()
|
||||
{
|
||||
return Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SEQ
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setSEQ(long value)
|
||||
{
|
||||
setHeader(HTTP.SEQ, Long.toString(value));
|
||||
}
|
||||
|
||||
public long getSEQ()
|
||||
{
|
||||
return getLongHeaderValue(HTTP.SEQ);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean setRequest(Subscriber sub, String varName, String value)
|
||||
{
|
||||
String callback = sub.getDeliveryURL();
|
||||
String sid = sub.getSID();
|
||||
long notifyCnt = sub.getNotifyCount();
|
||||
String host = sub.getDeliveryHost();
|
||||
String path = sub.getDeliveryPath();
|
||||
int port = sub.getDeliveryPort();
|
||||
|
||||
setMethod(HTTP.NOTIFY);
|
||||
setURI(path);
|
||||
setHost(host, port);
|
||||
setNT(NT.EVENT);
|
||||
setNTS(NTS.PROPCHANGE);
|
||||
setSID(sid);
|
||||
setSEQ(notifyCnt);
|
||||
|
||||
setContentType(XML.CONTENT_TYPE);
|
||||
Node propSetNode = createPropertySetNode(varName, value);
|
||||
setContent(propSetNode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Node createPropertySetNode(String varName, String value)
|
||||
{
|
||||
Node propSetNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTYSET);
|
||||
|
||||
propSetNode.setNameSpace(XMLNS, Subscription.XMLNS);
|
||||
|
||||
Node propNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTY);
|
||||
propSetNode.addNode(propNode);
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/22/03)
|
||||
//Node varNameNode = new Node(XMLNS + SOAP.DELIM + varName);
|
||||
Node varNameNode = new Node(varName);
|
||||
varNameNode.setValue(value);
|
||||
propNode.addNode(varNameNode);
|
||||
|
||||
return propSetNode;
|
||||
}
|
||||
|
||||
private Node getVariableNode()
|
||||
{
|
||||
Node rootNode = getEnvelopeNode();
|
||||
if (rootNode == null)
|
||||
return null;
|
||||
if (rootNode.hasNodes() == false)
|
||||
return null;
|
||||
Node propNode = rootNode.getNode(0);
|
||||
if (propNode.hasNodes() == false)
|
||||
return null;
|
||||
return propNode.getNode(0);
|
||||
}
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03)
|
||||
private Property getProperty(Node varNode)
|
||||
{
|
||||
Property prop = new Property();
|
||||
if (varNode == null)
|
||||
return prop;
|
||||
// remove the event namespace
|
||||
String variableName = varNode.getName();
|
||||
int index = variableName.lastIndexOf(':');
|
||||
if (index != -1)
|
||||
variableName = variableName.substring(index + 1);
|
||||
prop.setName(variableName);
|
||||
prop.setValue(varNode.getValue());
|
||||
return prop;
|
||||
}
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03)
|
||||
public PropertyList getPropertyList() {
|
||||
PropertyList properties = new PropertyList();
|
||||
Node varSetNode = getEnvelopeNode();
|
||||
// I2P change: ParserException caught in getRootNode() causes
|
||||
// getEnvelopeNode() to return null
|
||||
if (varSetNode == null)
|
||||
return properties;
|
||||
for (int i = 0; i<varSetNode.getNNodes(); i++){
|
||||
Node propNode = varSetNode.getNode(i);
|
||||
if (propNode == null)
|
||||
continue;
|
||||
Property prop = getProperty(propNode.getNode(0));
|
||||
properties.add(prop);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SOAPRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/11/02
|
||||
* - first revision.
|
||||
* 05/22/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Description: removed the xml namespace
|
||||
* - Problem : Notification messages refer to uncorrect variable names
|
||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||
* 05/22/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : Notification messages refer to uncorrect variable names
|
||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||
* - Description : removed the xml namespace
|
||||
* 09/03/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : Notification messages refer to uncorrect variable names
|
||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||
* - Description: removed the xml namespace
|
||||
* 09/08/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : when an event notification message is received and the message
|
||||
* contains updates on more than one variable, only the first variable update
|
||||
* is notified.
|
||||
* - Error : the other xml nodes of the message are ignored
|
||||
* - Fix : add two methods to the NotifyRequest for extracting the property array
|
||||
* and modify the httpRequestRecieved method in ControlPoint
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
import org.cybergarage.xml.*;
|
||||
import org.cybergarage.soap.*;
|
||||
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class NotifyRequest extends SOAPRequest
|
||||
{
|
||||
private final static String XMLNS = "e";
|
||||
private final static String PROPERTY = "property";
|
||||
private final static String PROPERTYSET = "propertyset";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public NotifyRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public NotifyRequest(HTTPRequest httpReq)
|
||||
{
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NT
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNT(String value)
|
||||
{
|
||||
setHeader(HTTP.NT, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NTS
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNTS(String value)
|
||||
{
|
||||
setHeader(HTTP.NTS, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setSID(String id)
|
||||
{
|
||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||
}
|
||||
|
||||
public String getSID()
|
||||
{
|
||||
return Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SEQ
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setSEQ(long value)
|
||||
{
|
||||
setHeader(HTTP.SEQ, Long.toString(value));
|
||||
}
|
||||
|
||||
public long getSEQ()
|
||||
{
|
||||
return getLongHeaderValue(HTTP.SEQ);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean setRequest(Subscriber sub, String varName, String value)
|
||||
{
|
||||
String callback = sub.getDeliveryURL();
|
||||
String sid = sub.getSID();
|
||||
long notifyCnt = sub.getNotifyCount();
|
||||
String host = sub.getDeliveryHost();
|
||||
String path = sub.getDeliveryPath();
|
||||
int port = sub.getDeliveryPort();
|
||||
|
||||
setMethod(HTTP.NOTIFY);
|
||||
setURI(path);
|
||||
setHost(host, port);
|
||||
setNT(NT.EVENT);
|
||||
setNTS(NTS.PROPCHANGE);
|
||||
setSID(sid);
|
||||
setSEQ(notifyCnt);
|
||||
|
||||
setContentType(XML.DEFAULT_CONTENT_TYPE);
|
||||
Node propSetNode = createPropertySetNode(varName, value);
|
||||
setContent(propSetNode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Node createPropertySetNode(String varName, String value)
|
||||
{
|
||||
Node propSetNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTYSET);
|
||||
|
||||
propSetNode.setNameSpace(XMLNS, Subscription.XMLNS);
|
||||
|
||||
Node propNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTY);
|
||||
propSetNode.addNode(propNode);
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/22/03)
|
||||
//Node varNameNode = new Node(XMLNS + SOAP.DELIM + varName);
|
||||
Node varNameNode = new Node(varName);
|
||||
varNameNode.setValue(value);
|
||||
propNode.addNode(varNameNode);
|
||||
|
||||
return propSetNode;
|
||||
}
|
||||
|
||||
private Node getVariableNode()
|
||||
{
|
||||
Node rootNode = getEnvelopeNode();
|
||||
if (rootNode == null)
|
||||
return null;
|
||||
if (rootNode.hasNodes() == false)
|
||||
return null;
|
||||
Node propNode = rootNode.getNode(0);
|
||||
if (propNode.hasNodes() == false)
|
||||
return null;
|
||||
return propNode.getNode(0);
|
||||
}
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03)
|
||||
private Property getProperty(Node varNode)
|
||||
{
|
||||
Property prop = new Property();
|
||||
if (varNode == null)
|
||||
return prop;
|
||||
// remove the event namespace
|
||||
String variableName = varNode.getName();
|
||||
int index = variableName.lastIndexOf(':');
|
||||
if (index != -1)
|
||||
variableName = variableName.substring(index + 1);
|
||||
prop.setName(variableName);
|
||||
prop.setValue(varNode.getValue());
|
||||
return prop;
|
||||
}
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03)
|
||||
public PropertyList getPropertyList() {
|
||||
PropertyList properties = new PropertyList();
|
||||
Node varSetNode = getEnvelopeNode();
|
||||
// I2P change: ParserException caught in getRootNode() causes
|
||||
// getEnvelopeNode() to return null
|
||||
if (varSetNode == null)
|
||||
return properties;
|
||||
for (int i = 0; i<varSetNode.getNNodes(); i++){
|
||||
Node propNode = varSetNode.getNode(i);
|
||||
if (propNode == null)
|
||||
continue;
|
||||
Property prop = getProperty(propNode.getNode(0));
|
||||
properties.add(prop);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,65 +1,65 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: Subscriber.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 05/22/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : the setName method does not set the name of the property
|
||||
* - Error : the method contains a bug:
|
||||
* 06/18/03
|
||||
* - Fixed a bug when a null value is received to the name and the value of property.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
public class Property
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Property()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// name
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String name = "";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String val) {
|
||||
if (val == null)
|
||||
val = "";
|
||||
name = val;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// value
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String value = "";
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String val) {
|
||||
if (val == null)
|
||||
val = "";
|
||||
value = val;
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: Subscriber.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 05/22/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : the setName method does not set the name of the property
|
||||
* - Error : the method contains a bug:
|
||||
* 06/18/03
|
||||
* - Fixed a bug when a null value is received to the name and the value of property.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
public class Property
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Property()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// name
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String name = "";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String val) {
|
||||
if (val == null)
|
||||
val = "";
|
||||
name = val;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// value
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String value = "";
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String val) {
|
||||
if (val == null)
|
||||
val = "";
|
||||
value = val;
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +1,45 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: PropertyList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 09/08/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: PropertyList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 09/08/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PropertyList extends Vector<Property>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "PropertyList";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public PropertyList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Property getProperty(int n)
|
||||
{
|
||||
return (Property)get(n);
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PropertyList extends Vector<Property>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constants
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String ELEM_NAME = "PropertyList";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public PropertyList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Property getProperty(int n)
|
||||
{
|
||||
return (Property)get(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,180 +1,180 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: Subscriber.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 07/31/04
|
||||
* - Added isExpired().
|
||||
* 10/26/04
|
||||
* - Oliver Newell <newell@media-rush.com>
|
||||
* - Added support the intinite time and fixed a bug in isExpired().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
public class Subscriber
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Subscriber()
|
||||
{
|
||||
renew();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String SID = null;
|
||||
|
||||
public String getSID() {
|
||||
return SID;
|
||||
}
|
||||
|
||||
public void setSID(String sid) {
|
||||
SID = sid;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// deliveryURL
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String ifAddr = "";
|
||||
|
||||
public void setInterfaceAddress(String addr)
|
||||
{
|
||||
ifAddr = addr;
|
||||
}
|
||||
|
||||
public String getInterfaceAddress()
|
||||
{
|
||||
return ifAddr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// deliveryURL
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String deliveryURL = "";
|
||||
|
||||
public String getDeliveryURL() {
|
||||
return deliveryURL;
|
||||
}
|
||||
|
||||
public void setDeliveryURL(String deliveryURL) {
|
||||
this.deliveryURL = deliveryURL;
|
||||
try {
|
||||
URL url = new URL(deliveryURL);
|
||||
deliveryHost = url.getHost();
|
||||
deliveryPath = url.getPath();
|
||||
deliveryPort = url.getPort();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
|
||||
private String deliveryHost = "";
|
||||
private String deliveryPath = "";
|
||||
private int deliveryPort = 0;
|
||||
|
||||
public String getDeliveryHost() {
|
||||
return deliveryHost;
|
||||
}
|
||||
|
||||
public String getDeliveryPath() {
|
||||
return deliveryPath;
|
||||
}
|
||||
|
||||
public int getDeliveryPort() {
|
||||
return deliveryPort;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long timeOut = 0;
|
||||
|
||||
public long getTimeOut() {
|
||||
return timeOut;
|
||||
}
|
||||
|
||||
public void setTimeOut(long value) {
|
||||
timeOut = value;
|
||||
}
|
||||
|
||||
public boolean isExpired()
|
||||
{
|
||||
long currTime = System.currentTimeMillis();
|
||||
|
||||
// Thanks for Oliver Newell (10/26/04)
|
||||
if(timeOut == Subscription.INFINITE_VALUE )
|
||||
return false;
|
||||
|
||||
// Thanks for Oliver Newell (10/26/04)
|
||||
long expiredTime = getSubscriptionTime() + getTimeOut()*1000;
|
||||
if (expiredTime < currTime)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SubscriptionTIme
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long subscriptionTime = 0;
|
||||
|
||||
public long getSubscriptionTime() {
|
||||
return subscriptionTime;
|
||||
}
|
||||
|
||||
public void setSubscriptionTime(long time) {
|
||||
subscriptionTime = time;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SEQ
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long notifyCount = 0;
|
||||
|
||||
public long getNotifyCount() {
|
||||
return notifyCount;
|
||||
}
|
||||
|
||||
public void setNotifyCount(int cnt) {
|
||||
notifyCount = cnt;
|
||||
}
|
||||
|
||||
public void incrementNotifyCount() {
|
||||
if (notifyCount == Long.MAX_VALUE) {
|
||||
notifyCount = 1;
|
||||
return;
|
||||
}
|
||||
notifyCount++;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// renew
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void renew()
|
||||
{
|
||||
setSubscriptionTime(System.currentTimeMillis());
|
||||
setNotifyCount(0);
|
||||
}
|
||||
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: Subscriber.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
* 07/31/04
|
||||
* - Added isExpired().
|
||||
* 10/26/04
|
||||
* - Oliver Newell <newell@media-rush.com>
|
||||
* - Added support the intinite time and fixed a bug in isExpired().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
public class Subscriber
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Subscriber()
|
||||
{
|
||||
renew();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String SID = null;
|
||||
|
||||
public String getSID() {
|
||||
return SID;
|
||||
}
|
||||
|
||||
public void setSID(String sid) {
|
||||
SID = sid;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// deliveryURL
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String ifAddr = "";
|
||||
|
||||
public void setInterfaceAddress(String addr)
|
||||
{
|
||||
ifAddr = addr;
|
||||
}
|
||||
|
||||
public String getInterfaceAddress()
|
||||
{
|
||||
return ifAddr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// deliveryURL
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String deliveryURL = "";
|
||||
|
||||
public String getDeliveryURL() {
|
||||
return deliveryURL;
|
||||
}
|
||||
|
||||
public void setDeliveryURL(String deliveryURL) {
|
||||
this.deliveryURL = deliveryURL;
|
||||
try {
|
||||
URL url = new URL(deliveryURL);
|
||||
deliveryHost = url.getHost();
|
||||
deliveryPath = url.getPath();
|
||||
deliveryPort = url.getPort();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
|
||||
private String deliveryHost = "";
|
||||
private String deliveryPath = "";
|
||||
private int deliveryPort = 0;
|
||||
|
||||
public String getDeliveryHost() {
|
||||
return deliveryHost;
|
||||
}
|
||||
|
||||
public String getDeliveryPath() {
|
||||
return deliveryPath;
|
||||
}
|
||||
|
||||
public int getDeliveryPort() {
|
||||
return deliveryPort;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long timeOut = 0;
|
||||
|
||||
public long getTimeOut() {
|
||||
return timeOut;
|
||||
}
|
||||
|
||||
public void setTimeOut(long value) {
|
||||
timeOut = value;
|
||||
}
|
||||
|
||||
public boolean isExpired()
|
||||
{
|
||||
long currTime = System.currentTimeMillis();
|
||||
|
||||
// Thanks for Oliver Newell (10/26/04)
|
||||
if(timeOut == Subscription.INFINITE_VALUE )
|
||||
return false;
|
||||
|
||||
// Thanks for Oliver Newell (10/26/04)
|
||||
long expiredTime = getSubscriptionTime() + getTimeOut()*1000;
|
||||
if (expiredTime < currTime)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SubscriptionTIme
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long subscriptionTime = 0;
|
||||
|
||||
public long getSubscriptionTime() {
|
||||
return subscriptionTime;
|
||||
}
|
||||
|
||||
public void setSubscriptionTime(long time) {
|
||||
subscriptionTime = time;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SEQ
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long notifyCount = 0;
|
||||
|
||||
public long getNotifyCount() {
|
||||
return notifyCount;
|
||||
}
|
||||
|
||||
public void setNotifyCount(int cnt) {
|
||||
notifyCount = cnt;
|
||||
}
|
||||
|
||||
public void incrementNotifyCount() {
|
||||
if (notifyCount == Long.MAX_VALUE) {
|
||||
notifyCount = 1;
|
||||
return;
|
||||
}
|
||||
notifyCount++;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// renew
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void renew()
|
||||
{
|
||||
setSubscriptionTime(System.currentTimeMillis());
|
||||
setNotifyCount(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SubscriberList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/31/03
|
||||
* - first revision.
|
||||
* 06/18/03
|
||||
* - Fixed to catch ArrayIndexOutOfBounds.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SubscriberList extends Vector<Subscriber>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SubscriberList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Subscriber getSubscriber(int n)
|
||||
{
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = get(n);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
return (Subscriber)obj;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SubscriberList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/31/03
|
||||
* - first revision.
|
||||
* 06/18/03
|
||||
* - Fixed to catch ArrayIndexOutOfBounds.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SubscriberList extends Vector<Subscriber>
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SubscriberList()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Subscriber getSubscriber(int n)
|
||||
{
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = get(n);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
return (Subscriber)obj;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,77 +1,77 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ST.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/31/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class Subscription
|
||||
{
|
||||
public final static String XMLNS = "urn:schemas-upnp-org:event-1-0";
|
||||
public final static String TIMEOUT_HEADER = "Second-";
|
||||
public final static String INFINITE_STRING = "infinite";
|
||||
public final static int INFINITE_VALUE = -1;
|
||||
public final static String UUID = "uuid:";
|
||||
public final static String SUBSCRIBE_METHOD = "SUBSCRIBE";
|
||||
public final static String UNSUBSCRIBE_METHOD = "UNSUBSCRIBE";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String toTimeoutHeaderString(long time)
|
||||
{
|
||||
if (time == Subscription.INFINITE_VALUE)
|
||||
return Subscription.INFINITE_STRING;
|
||||
return Subscription.TIMEOUT_HEADER + Long.toString(time);
|
||||
}
|
||||
|
||||
public final static long getTimeout(String headerValue)
|
||||
{
|
||||
int minusIdx = headerValue.indexOf('-');
|
||||
long timeout = Subscription.INFINITE_VALUE;
|
||||
try {
|
||||
String timeoutStr = headerValue.substring(minusIdx+1, headerValue.length());
|
||||
timeout = Long.parseLong(timeoutStr);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
return timeout;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static final String createSID()
|
||||
{
|
||||
return UPnP.createUUID();
|
||||
}
|
||||
|
||||
public final static String toSIDHeaderString(String id)
|
||||
{
|
||||
return Subscription.UUID + id;
|
||||
}
|
||||
|
||||
public final static String getSID(String headerValue)
|
||||
{
|
||||
if (headerValue == null)
|
||||
return "";
|
||||
if (headerValue.startsWith(Subscription.UUID) == false)
|
||||
return headerValue;
|
||||
return headerValue.substring(Subscription.UUID.length(), headerValue.length());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ST.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/31/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class Subscription
|
||||
{
|
||||
public final static String XMLNS = "urn:schemas-upnp-org:event-1-0";
|
||||
public final static String TIMEOUT_HEADER = "Second-";
|
||||
public final static String INFINITE_STRING = "infinite";
|
||||
public final static int INFINITE_VALUE = -1;
|
||||
public final static String UUID = "uuid:";
|
||||
public final static String SUBSCRIBE_METHOD = "SUBSCRIBE";
|
||||
public final static String UNSUBSCRIBE_METHOD = "UNSUBSCRIBE";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final static String toTimeoutHeaderString(long time)
|
||||
{
|
||||
if (time == Subscription.INFINITE_VALUE)
|
||||
return Subscription.INFINITE_STRING;
|
||||
return Subscription.TIMEOUT_HEADER + Long.toString(time);
|
||||
}
|
||||
|
||||
public final static long getTimeout(String headerValue)
|
||||
{
|
||||
int minusIdx = headerValue.indexOf('-');
|
||||
long timeout = Subscription.INFINITE_VALUE;
|
||||
try {
|
||||
String timeoutStr = headerValue.substring(minusIdx+1, headerValue.length());
|
||||
timeout = Long.parseLong(timeoutStr);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
return timeout;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public static final String createSID()
|
||||
{
|
||||
return UPnP.createUUID();
|
||||
}
|
||||
|
||||
public final static String toSIDHeaderString(String id)
|
||||
{
|
||||
return Subscription.UUID + id;
|
||||
}
|
||||
|
||||
public final static String getSID(String headerValue)
|
||||
{
|
||||
if (headerValue == null)
|
||||
return "";
|
||||
if (headerValue.startsWith(Subscription.UUID) == false)
|
||||
return headerValue;
|
||||
return headerValue.substring(Subscription.UUID.length(), headerValue.length());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,221 +1,221 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SubscriptionRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/31/03
|
||||
* - first revision.
|
||||
* 05/21/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Description: inserted a check at the beginning of the setService method
|
||||
* - Problem : If the EventSubURL does not start with a '/', the device could refuse event subscription
|
||||
* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices
|
||||
* 09/02/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : NullpointerException thrown for devices whose description use absolute urls
|
||||
* - Error : the presence of a base url is not mandatory, the API code makes the assumption that control and event subscription urls are relative. If the baseUrl is not present, the request host and port should be extracted from the control/subscription url
|
||||
* - Description: The method setRequestHost/setService should be changed as follows
|
||||
* 06/11/04
|
||||
* - Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004)
|
||||
* - Changed setServie() to get the host address from the SSDP Location field when the URLBase is null.
|
||||
* 12/06/04
|
||||
* - Grzegorz Lehmann <grzegorz.lehmann@dai-labor.de>
|
||||
* - Stefano Lenzi <kismet-sl@users.sourceforge.net>
|
||||
* - Fixed getSID() to loop between getSID() and hasSID();
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class SubscriptionRequest extends HTTPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SubscriptionRequest(){
|
||||
setContentLength(0);
|
||||
}
|
||||
|
||||
public SubscriptionRequest(HTTPRequest httpReq){
|
||||
this();
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// setRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private void setService(Service service)
|
||||
{
|
||||
String eventSubURL = service.getEventSubURL();
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03)
|
||||
setURI(eventSubURL, true);
|
||||
|
||||
String urlBaseStr = "";
|
||||
Device dev = service.getDevice();
|
||||
if (dev != null)
|
||||
urlBaseStr = dev.getURLBase();
|
||||
|
||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||
Device rootDev = service.getRootDevice();
|
||||
if (rootDev != null)
|
||||
urlBaseStr = rootDev.getURLBase();
|
||||
}
|
||||
|
||||
// Thansk for Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004)
|
||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||
Device rootDev = service.getRootDevice();
|
||||
if (rootDev != null)
|
||||
urlBaseStr = rootDev.getLocation();
|
||||
}
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03)
|
||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||
if (HTTP.isAbsoluteURL(eventSubURL))
|
||||
urlBaseStr = eventSubURL;
|
||||
}
|
||||
|
||||
String reqHost = HTTP.getHost(urlBaseStr);
|
||||
int reqPort = HTTP.getPort(urlBaseStr);
|
||||
|
||||
setHost(reqHost, reqPort);
|
||||
setRequestHost(reqHost);
|
||||
setRequestPort(reqPort);
|
||||
}
|
||||
|
||||
public void setSubscribeRequest(Service service, String callback, long timeout)
|
||||
{
|
||||
setMethod(Subscription.SUBSCRIBE_METHOD);
|
||||
setService(service);
|
||||
setCallback(callback);
|
||||
setNT(NT.EVENT);
|
||||
setTimeout(timeout);
|
||||
}
|
||||
|
||||
public void setRenewRequest(Service service, String uuid, long timeout)
|
||||
{
|
||||
setMethod(Subscription.SUBSCRIBE_METHOD);
|
||||
setService(service);
|
||||
setSID(uuid);
|
||||
setTimeout(timeout);
|
||||
}
|
||||
|
||||
public void setUnsubscribeRequest(Service service)
|
||||
{
|
||||
setMethod(Subscription.UNSUBSCRIBE_METHOD);
|
||||
setService(service);
|
||||
setSID(service.getSID());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NT
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNT(String value)
|
||||
{
|
||||
setHeader(HTTP.NT, value);
|
||||
}
|
||||
|
||||
public String getNT()
|
||||
{
|
||||
return getHeaderValue(HTTP.NT);
|
||||
}
|
||||
|
||||
public boolean hasNT()
|
||||
{
|
||||
String nt = getNT();
|
||||
return (nt != null && 0 < nt.length()) ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// CALLBACK
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String CALLBACK_START_WITH = "<";
|
||||
private final static String CALLBACK_END_WITH = ">";
|
||||
|
||||
public void setCallback(String value)
|
||||
{
|
||||
setStringHeader(HTTP.CALLBACK, value, CALLBACK_START_WITH, CALLBACK_END_WITH);
|
||||
}
|
||||
|
||||
public String getCallback()
|
||||
{
|
||||
return getStringHeaderValue(HTTP.CALLBACK, CALLBACK_START_WITH, CALLBACK_END_WITH);
|
||||
}
|
||||
|
||||
public boolean hasCallback()
|
||||
{
|
||||
String callback = getCallback();
|
||||
return (callback != null && 0 < callback.length()) ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setSID(String id)
|
||||
{
|
||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||
}
|
||||
|
||||
public String getSID()
|
||||
{
|
||||
// Thanks for Grzegorz Lehmann and Stefano Lenzi(12/06/04)
|
||||
String sid = Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||
if (sid == null)
|
||||
return "";
|
||||
return sid;
|
||||
}
|
||||
|
||||
public boolean hasSID()
|
||||
{
|
||||
String sid = getSID();
|
||||
return (sid != null && 0 < sid.length()) ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final void setTimeout(long value)
|
||||
{
|
||||
setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value));
|
||||
}
|
||||
|
||||
public long getTimeout()
|
||||
{
|
||||
return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post (Response)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void post(SubscriptionResponse subRes)
|
||||
{
|
||||
super.post(subRes);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SubscriptionResponse post()
|
||||
{
|
||||
HTTPResponse httpRes = post(getRequestHost(), getRequestPort());
|
||||
return new SubscriptionResponse(httpRes);
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SubscriptionRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/31/03
|
||||
* - first revision.
|
||||
* 05/21/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Description: inserted a check at the beginning of the setService method
|
||||
* - Problem : If the EventSubURL does not start with a '/', the device could refuse event subscription
|
||||
* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices
|
||||
* 09/02/03
|
||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||
* - Problem : NullpointerException thrown for devices whose description use absolute urls
|
||||
* - Error : the presence of a base url is not mandatory, the API code makes the assumption that control and event subscription urls are relative. If the baseUrl is not present, the request host and port should be extracted from the control/subscription url
|
||||
* - Description: The method setRequestHost/setService should be changed as follows
|
||||
* 06/11/04
|
||||
* - Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004)
|
||||
* - Changed setServie() to get the host address from the SSDP Location field when the URLBase is null.
|
||||
* 12/06/04
|
||||
* - Grzegorz Lehmann <grzegorz.lehmann@dai-labor.de>
|
||||
* - Stefano Lenzi <kismet-sl@users.sourceforge.net>
|
||||
* - Fixed getSID() to loop between getSID() and hasSID();
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class SubscriptionRequest extends HTTPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SubscriptionRequest(){
|
||||
setContentLength(0);
|
||||
}
|
||||
|
||||
public SubscriptionRequest(HTTPRequest httpReq){
|
||||
this();
|
||||
set(httpReq);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// setRequest
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private void setService(Service service)
|
||||
{
|
||||
String eventSubURL = service.getEventSubURL();
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03)
|
||||
setURI(eventSubURL, true);
|
||||
|
||||
String urlBaseStr = "";
|
||||
Device dev = service.getDevice();
|
||||
if (dev != null)
|
||||
urlBaseStr = dev.getURLBase();
|
||||
|
||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||
Device rootDev = service.getRootDevice();
|
||||
if (rootDev != null)
|
||||
urlBaseStr = rootDev.getURLBase();
|
||||
}
|
||||
|
||||
// Thansk for Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004)
|
||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||
Device rootDev = service.getRootDevice();
|
||||
if (rootDev != null)
|
||||
urlBaseStr = rootDev.getLocation();
|
||||
}
|
||||
|
||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03)
|
||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||
if (HTTP.isAbsoluteURL(eventSubURL))
|
||||
urlBaseStr = eventSubURL;
|
||||
}
|
||||
|
||||
String reqHost = HTTP.getHost(urlBaseStr);
|
||||
int reqPort = HTTP.getPort(urlBaseStr);
|
||||
|
||||
setHost(reqHost, reqPort);
|
||||
setRequestHost(reqHost);
|
||||
setRequestPort(reqPort);
|
||||
}
|
||||
|
||||
public void setSubscribeRequest(Service service, String callback, long timeout)
|
||||
{
|
||||
setMethod(Subscription.SUBSCRIBE_METHOD);
|
||||
setService(service);
|
||||
setCallback(callback);
|
||||
setNT(NT.EVENT);
|
||||
setTimeout(timeout);
|
||||
}
|
||||
|
||||
public void setRenewRequest(Service service, String uuid, long timeout)
|
||||
{
|
||||
setMethod(Subscription.SUBSCRIBE_METHOD);
|
||||
setService(service);
|
||||
setSID(uuid);
|
||||
setTimeout(timeout);
|
||||
}
|
||||
|
||||
public void setUnsubscribeRequest(Service service)
|
||||
{
|
||||
setMethod(Subscription.UNSUBSCRIBE_METHOD);
|
||||
setService(service);
|
||||
setSID(service.getSID());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NT
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNT(String value)
|
||||
{
|
||||
setHeader(HTTP.NT, value);
|
||||
}
|
||||
|
||||
public String getNT()
|
||||
{
|
||||
return getHeaderValue(HTTP.NT);
|
||||
}
|
||||
|
||||
public boolean hasNT()
|
||||
{
|
||||
String nt = getNT();
|
||||
return (nt != null && 0 < nt.length()) ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// CALLBACK
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private final static String CALLBACK_START_WITH = "<";
|
||||
private final static String CALLBACK_END_WITH = ">";
|
||||
|
||||
public void setCallback(String value)
|
||||
{
|
||||
setStringHeader(HTTP.CALLBACK, value, CALLBACK_START_WITH, CALLBACK_END_WITH);
|
||||
}
|
||||
|
||||
public String getCallback()
|
||||
{
|
||||
return getStringHeaderValue(HTTP.CALLBACK, CALLBACK_START_WITH, CALLBACK_END_WITH);
|
||||
}
|
||||
|
||||
public boolean hasCallback()
|
||||
{
|
||||
String callback = getCallback();
|
||||
return (callback != null && 0 < callback.length()) ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setSID(String id)
|
||||
{
|
||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||
}
|
||||
|
||||
public String getSID()
|
||||
{
|
||||
// Thanks for Grzegorz Lehmann and Stefano Lenzi(12/06/04)
|
||||
String sid = Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||
if (sid == null)
|
||||
return "";
|
||||
return sid;
|
||||
}
|
||||
|
||||
public boolean hasSID()
|
||||
{
|
||||
String sid = getSID();
|
||||
return (sid != null && 0 < sid.length()) ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public final void setTimeout(long value)
|
||||
{
|
||||
setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value));
|
||||
}
|
||||
|
||||
public long getTimeout()
|
||||
{
|
||||
return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post (Response)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void post(SubscriptionResponse subRes)
|
||||
{
|
||||
super.post(subRes);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// post
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SubscriptionResponse post()
|
||||
{
|
||||
HTTPResponse httpRes = post(getRequestHost(), getRequestPort());
|
||||
return new SubscriptionResponse(httpRes);
|
||||
}
|
||||
}
|
||||
|
@ -1,84 +1,84 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SubscriptionResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
public class SubscriptionResponse extends HTTPResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SubscriptionResponse()
|
||||
{
|
||||
setServer(UPnP.getServerName());
|
||||
}
|
||||
|
||||
public SubscriptionResponse(HTTPResponse httpRes)
|
||||
{
|
||||
super(httpRes);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Error
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setResponse(int code)
|
||||
{
|
||||
setStatusCode(code);
|
||||
setContentLength(0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Error
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setErrorResponse(int code)
|
||||
{
|
||||
setStatusCode(code);
|
||||
setContentLength(0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setSID(String id)
|
||||
{
|
||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||
}
|
||||
|
||||
public String getSID()
|
||||
{
|
||||
return Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setTimeout(long value)
|
||||
{
|
||||
setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value));
|
||||
}
|
||||
|
||||
public long getTimeout()
|
||||
{
|
||||
return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT));
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SubscriptionResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/29/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.event;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
public class SubscriptionResponse extends HTTPResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SubscriptionResponse()
|
||||
{
|
||||
setServer(UPnP.getServerName());
|
||||
}
|
||||
|
||||
public SubscriptionResponse(HTTPResponse httpRes)
|
||||
{
|
||||
super(httpRes);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Error
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setResponse(int code)
|
||||
{
|
||||
setStatusCode(code);
|
||||
setContentLength(0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Error
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setErrorResponse(int code)
|
||||
{
|
||||
setStatusCode(code);
|
||||
setContentLength(0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setSID(String id)
|
||||
{
|
||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||
}
|
||||
|
||||
public String getSID()
|
||||
{
|
||||
return Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setTimeout(long value)
|
||||
{
|
||||
setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value));
|
||||
}
|
||||
|
||||
public long getTimeout()
|
||||
{
|
||||
return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT));
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
* 08/23/07
|
||||
* - Thanks for Kazuyuki Shudo
|
||||
* - Changed receive() to throw IOException.
|
||||
* 01/10/08
|
||||
* 01/10/08
|
||||
* - Changed getLocalAddress() to return a brank string when the ssdpMultiGroup or ssdpMultiIf is null on Android m3-rc37a.
|
||||
*
|
||||
******************************************************************/
|
||||
|
@ -5,11 +5,11 @@
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: HTTPMU.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/20/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/20/02
|
||||
* - first revision.
|
||||
* 12/12/03
|
||||
* - Inma Mar?n <inma@DIF.UM.ES>
|
||||
* - Changed open(addr, port) to send IPv6 SSDP packets.
|
||||
@ -20,49 +20,49 @@
|
||||
* - Added to set a current timestamp when the packet are received.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.cybergarage.util.Debug;
|
||||
|
||||
public class HTTPUSocket
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private DatagramSocket ssdpUniSock = null;
|
||||
|
||||
public class HTTPUSocket
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Member
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private DatagramSocket ssdpUniSock = null;
|
||||
//private MulticastSocket ssdpUniSock = null;
|
||||
|
||||
public DatagramSocket getDatagramSocket()
|
||||
{
|
||||
return ssdpUniSock;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPUSocket()
|
||||
|
||||
public DatagramSocket getDatagramSocket()
|
||||
{
|
||||
return ssdpUniSock;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public HTTPUSocket()
|
||||
{
|
||||
open();
|
||||
}
|
||||
|
||||
public HTTPUSocket(String bindAddr, int bindPort)
|
||||
}
|
||||
|
||||
public HTTPUSocket(String bindAddr, int bindPort)
|
||||
{
|
||||
open(bindAddr, bindPort);
|
||||
}
|
||||
}
|
||||
|
||||
public HTTPUSocket(int bindPort)
|
||||
{
|
||||
open(bindPort);
|
||||
}
|
||||
|
||||
|
||||
protected void finalize()
|
||||
{
|
||||
close();
|
||||
@ -166,67 +166,67 @@ public class HTTPUSocket
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// close
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean close()
|
||||
{
|
||||
if (ssdpUniSock == null)
|
||||
return true;
|
||||
|
||||
try {
|
||||
ssdpUniSock.close();
|
||||
ssdpUniSock = null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
// close
|
||||
////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// send
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean post(String addr, int port, String msg)
|
||||
{
|
||||
try {
|
||||
InetAddress inetAddr = InetAddress.getByName(addr);
|
||||
DatagramPacket dgmPacket = new DatagramPacket(msg.getBytes(), msg.length(), inetAddr, port);
|
||||
ssdpUniSock.send(dgmPacket);
|
||||
}
|
||||
public boolean close()
|
||||
{
|
||||
if (ssdpUniSock == null)
|
||||
return true;
|
||||
|
||||
try {
|
||||
ssdpUniSock.close();
|
||||
ssdpUniSock = null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning("addr = " +ssdpUniSock.getLocalAddress().getHostName());
|
||||
Debug.warning(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// send
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean post(String addr, int port, String msg)
|
||||
{
|
||||
try {
|
||||
InetAddress inetAddr = InetAddress.getByName(addr);
|
||||
DatagramPacket dgmPacket = new DatagramPacket(msg.getBytes(), msg.length(), inetAddr, port);
|
||||
ssdpUniSock.send(dgmPacket);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning("addr = " +ssdpUniSock.getLocalAddress().getHostName());
|
||||
Debug.warning("port = " + ssdpUniSock.getLocalPort());
|
||||
Debug.warning(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// reveive
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPPacket receive()
|
||||
{
|
||||
byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE];
|
||||
SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length);
|
||||
Debug.warning(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// reveive
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPPacket receive()
|
||||
{
|
||||
byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE];
|
||||
SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length);
|
||||
recvPacket.setLocalAddress(getLocalAddress());
|
||||
try {
|
||||
ssdpUniSock.receive(recvPacket.getDatagramPacket());
|
||||
try {
|
||||
ssdpUniSock.receive(recvPacket.getDatagramPacket());
|
||||
recvPacket.setTimeStamp(System.currentTimeMillis());
|
||||
Debug.message("Received SSDP unicast packet on " + getLocalAddress() + " from " + recvPacket.getRemoteAddress());
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
//Debug.warning(e);
|
||||
return null;
|
||||
}
|
||||
return recvPacket;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return recvPacket;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// join/leave
|
||||
@ -261,5 +261,5 @@ public class HTTPUSocket
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,31 +1,31 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SSDPMSearchRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/14/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import org.cybergarage.http.HTTP;
|
||||
|
||||
public class SSDPNotifyRequest extends SSDPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPNotifyRequest()
|
||||
{
|
||||
setMethod(HTTP.NOTIFY);
|
||||
setURI("*");
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SSDPMSearchRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/14/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import org.cybergarage.http.HTTP;
|
||||
|
||||
public class SSDPNotifyRequest extends SSDPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPNotifyRequest()
|
||||
{
|
||||
setMethod(HTTP.NOTIFY);
|
||||
setURI("*");
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,11 @@
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: SSDPPacket.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/18/02
|
||||
* - first revision.
|
||||
* 05/13/03
|
||||
* - Added getLocalAddress().
|
||||
* 11/01/04
|
||||
@ -20,25 +20,25 @@
|
||||
* - Changed getRemoteAddress() to return the adresss instead of the host name.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import java.net.*;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class SSDPPacket
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPPacket(byte[] buf, int length)
|
||||
{
|
||||
dgmPacket = new DatagramPacket(buf, length);
|
||||
}
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class SSDPPacket
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPPacket(byte[] buf, int length)
|
||||
{
|
||||
dgmPacket = new DatagramPacket(buf, length);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// DatagramPacket
|
||||
@ -68,115 +68,115 @@ public class SSDPPacket
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Time
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long timeStamp;
|
||||
|
||||
public void setTimeStamp(long value)
|
||||
{
|
||||
timeStamp = value;
|
||||
}
|
||||
|
||||
public long getTimeStamp()
|
||||
{
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Remote host
|
||||
////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////
|
||||
// Time
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long timeStamp;
|
||||
|
||||
public void setTimeStamp(long value)
|
||||
{
|
||||
timeStamp = value;
|
||||
}
|
||||
|
||||
public long getTimeStamp()
|
||||
{
|
||||
return timeStamp;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Remote host
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public InetAddress getRemoteInetAddress()
|
||||
{
|
||||
return getDatagramPacket().getAddress();
|
||||
}
|
||||
|
||||
public String getRemoteAddress()
|
||||
{
|
||||
public String getRemoteAddress()
|
||||
{
|
||||
// Thanks for Theo Beisch (11/09/04)
|
||||
return getDatagramPacket().getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
public int getRemotePort()
|
||||
{
|
||||
return getDatagramPacket().getPort();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Access Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public byte[] packetBytes = null;
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
if (packetBytes != null)
|
||||
return packetBytes;
|
||||
|
||||
DatagramPacket packet = getDatagramPacket();
|
||||
int packetLen = packet.getLength();
|
||||
String packetData = new String(packet.getData(), 0, packetLen);
|
||||
packetBytes = packetData.getBytes();
|
||||
|
||||
return packetBytes;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Access Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getHost()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.HOST);
|
||||
}
|
||||
|
||||
public String getCacheControl()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.CACHE_CONTROL);
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.LOCATION);
|
||||
}
|
||||
|
||||
public String getMAN()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.MAN);
|
||||
}
|
||||
return getDatagramPacket().getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
public int getRemotePort()
|
||||
{
|
||||
return getDatagramPacket().getPort();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Access Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public byte[] packetBytes = null;
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
if (packetBytes != null)
|
||||
return packetBytes;
|
||||
|
||||
DatagramPacket packet = getDatagramPacket();
|
||||
int packetLen = packet.getLength();
|
||||
String packetData = new String(packet.getData(), 0, packetLen);
|
||||
packetBytes = packetData.getBytes();
|
||||
|
||||
return packetBytes;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Access Methods
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getHost()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.HOST);
|
||||
}
|
||||
|
||||
public String getCacheControl()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.CACHE_CONTROL);
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.LOCATION);
|
||||
}
|
||||
|
||||
public String getMAN()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.MAN);
|
||||
}
|
||||
|
||||
public String getST()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.ST);
|
||||
}
|
||||
|
||||
public String getNT()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.NT);
|
||||
}
|
||||
|
||||
public String getNTS()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.NTS);
|
||||
}
|
||||
|
||||
public String getServer()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.SERVER);
|
||||
}
|
||||
|
||||
public String getUSN()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.USN);
|
||||
}
|
||||
|
||||
public int getMX()
|
||||
{
|
||||
return HTTPHeader.getIntegerValue(getData(), HTTP.MX);
|
||||
}
|
||||
|
||||
|
||||
public String getNT()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.NT);
|
||||
}
|
||||
|
||||
public String getNTS()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.NTS);
|
||||
}
|
||||
|
||||
public String getServer()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.SERVER);
|
||||
}
|
||||
|
||||
public String getUSN()
|
||||
{
|
||||
return HTTPHeader.getValue(getData(), HTTP.USN);
|
||||
}
|
||||
|
||||
public int getMX()
|
||||
{
|
||||
return HTTPHeader.getIntegerValue(getData(), HTTP.MX);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Access Methods
|
||||
////////////////////////////////////////////////
|
||||
@ -197,39 +197,39 @@ public class SSDPPacket
|
||||
return isockaddr.getAddress();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Access Methods (Extension)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean isRootDevice()
|
||||
{
|
||||
if (NT.isRootDevice(getNT()) == true)
|
||||
////////////////////////////////////////////////
|
||||
// Access Methods (Extension)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public boolean isRootDevice()
|
||||
{
|
||||
if (NT.isRootDevice(getNT()) == true)
|
||||
return true;
|
||||
// Thanks for Theo Beisch (11/01/04)
|
||||
// Thanks for Theo Beisch (11/01/04)
|
||||
if (ST.isRootDevice(getST()) == true)
|
||||
return true;
|
||||
return USN.isRootDevice(getUSN());
|
||||
}
|
||||
|
||||
public boolean isDiscover()
|
||||
{
|
||||
return MAN.isDiscover(getMAN());
|
||||
}
|
||||
|
||||
public boolean isAlive()
|
||||
{
|
||||
return NTS.isAlive(getNTS());
|
||||
}
|
||||
|
||||
public boolean isByeBye()
|
||||
{
|
||||
return NTS.isByeBye(getNTS());
|
||||
}
|
||||
|
||||
public int getLeaseTime()
|
||||
{
|
||||
return SSDP.getLeaseTime(getCacheControl());
|
||||
}
|
||||
return USN.isRootDevice(getUSN());
|
||||
}
|
||||
|
||||
public boolean isDiscover()
|
||||
{
|
||||
return MAN.isDiscover(getMAN());
|
||||
}
|
||||
|
||||
public boolean isAlive()
|
||||
{
|
||||
return NTS.isAlive(getNTS());
|
||||
}
|
||||
|
||||
public boolean isByeBye()
|
||||
{
|
||||
return NTS.isByeBye(getNTS());
|
||||
}
|
||||
|
||||
public int getLeaseTime()
|
||||
{
|
||||
return SSDP.getLeaseTime(getCacheControl());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// toString
|
||||
@ -240,4 +240,4 @@ public class SSDPPacket
|
||||
return new String(getData());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,111 +1,125 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SSDPRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/14/03
|
||||
* - first revision.
|
||||
* 03/16/04
|
||||
* - Thanks for Darrell Young
|
||||
* - Fixed to set v1.1 to the HTTP version.;
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
public class SSDPRequest extends HTTPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPRequest()
|
||||
{
|
||||
setVersion(HTTP.VERSION_11);
|
||||
}
|
||||
|
||||
public SSDPRequest(InputStream in)
|
||||
{
|
||||
super(in);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NT
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNT(String value)
|
||||
{
|
||||
setHeader(HTTP.NT, value);
|
||||
}
|
||||
|
||||
public String getNT()
|
||||
{
|
||||
return getHeaderValue(HTTP.NT);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NTS
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNTS(String value)
|
||||
{
|
||||
setHeader(HTTP.NTS, value);
|
||||
}
|
||||
|
||||
public String getNTS()
|
||||
{
|
||||
return getHeaderValue(HTTP.NTS);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Location
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setLocation(String value)
|
||||
{
|
||||
setHeader(HTTP.LOCATION, value);
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return getHeaderValue(HTTP.LOCATION);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// USN
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setUSN(String value)
|
||||
{
|
||||
setHeader(HTTP.USN, value);
|
||||
}
|
||||
|
||||
public String getUSN()
|
||||
{
|
||||
return getHeaderValue(HTTP.USN);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// CacheControl
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setLeaseTime(int len)
|
||||
{
|
||||
setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len));
|
||||
}
|
||||
|
||||
public int getLeaseTime()
|
||||
{
|
||||
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
|
||||
return SSDP.getLeaseTime(cacheCtrl);
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SSDPRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/14/03
|
||||
* - first revision.
|
||||
* 03/16/04
|
||||
* - Thanks for Darrell Young
|
||||
* - Fixed to set v1.1 to the HTTP version.;
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
public class SSDPRequest extends HTTPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPRequest()
|
||||
{
|
||||
setVersion(HTTP.VERSION_11);
|
||||
}
|
||||
|
||||
public SSDPRequest(InputStream in)
|
||||
{
|
||||
super(in);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NT
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNT(String value)
|
||||
{
|
||||
setHeader(HTTP.NT, value);
|
||||
}
|
||||
|
||||
public String getNT()
|
||||
{
|
||||
return getHeaderValue(HTTP.NT);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// NTS
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setNTS(String value)
|
||||
{
|
||||
setHeader(HTTP.NTS, value);
|
||||
}
|
||||
|
||||
public String getNTS()
|
||||
{
|
||||
return getHeaderValue(HTTP.NTS);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Location
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setLocation(String value)
|
||||
{
|
||||
setHeader(HTTP.LOCATION, value);
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return getHeaderValue(HTTP.LOCATION);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// USN
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setUSN(String value)
|
||||
{
|
||||
setHeader(HTTP.USN, value);
|
||||
}
|
||||
|
||||
public String getUSN()
|
||||
{
|
||||
return getHeaderValue(HTTP.USN);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// CacheControl
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setLeaseTime(int len)
|
||||
{
|
||||
setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len));
|
||||
}
|
||||
|
||||
public int getLeaseTime()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,133 +1,147 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SSDPResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/14/03
|
||||
* - first revision.
|
||||
* 01/23/04
|
||||
* - Oliver Newell
|
||||
* - Overided HTTPResponse::getHeader() for Intel UPnP control points.
|
||||
* 03/16/04
|
||||
* - Thanks for Darrell Young
|
||||
* - Fixed to set v1.1 to the HTTP version.
|
||||
* 10/20/04
|
||||
* - Brent Hills <bhills@openshores.com>
|
||||
* - Added setMYNAME() and getMYNAME().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
public class SSDPResponse extends HTTPResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPResponse()
|
||||
{
|
||||
setVersion(HTTP.VERSION_11);
|
||||
}
|
||||
|
||||
public SSDPResponse(InputStream in)
|
||||
{
|
||||
super(in);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// ST (SearchTarget)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setST(String value)
|
||||
{
|
||||
setHeader(HTTP.ST, value);
|
||||
}
|
||||
|
||||
public String getST()
|
||||
{
|
||||
return getHeaderValue(HTTP.ST);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Location
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setLocation(String value)
|
||||
{
|
||||
setHeader(HTTP.LOCATION, value);
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return getHeaderValue(HTTP.LOCATION);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// USN
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setUSN(String value)
|
||||
{
|
||||
setHeader(HTTP.USN, value);
|
||||
}
|
||||
|
||||
public String getUSN()
|
||||
{
|
||||
return getHeaderValue(HTTP.USN);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// MYNAME
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setMYNAME(String value)
|
||||
{
|
||||
setHeader(HTTP.MYNAME, value);
|
||||
}
|
||||
|
||||
public String getMYNAME()
|
||||
{
|
||||
return getHeaderValue(HTTP.MYNAME);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// CacheControl
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setLeaseTime(int len)
|
||||
{
|
||||
setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len));
|
||||
}
|
||||
|
||||
public int getLeaseTime()
|
||||
{
|
||||
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
|
||||
return SSDP.getLeaseTime(cacheCtrl);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getHeader (Override)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getHeader()
|
||||
{
|
||||
StringBuffer str = new StringBuffer();
|
||||
|
||||
str.append(getStatusLineString());
|
||||
str.append(getHeaderString());
|
||||
str.append(HTTP.CRLF); // for Intel UPnP control points.
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SSDPResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/14/03
|
||||
* - first revision.
|
||||
* 01/23/04
|
||||
* - Oliver Newell
|
||||
* - Overided HTTPResponse::getHeader() for Intel UPnP control points.
|
||||
* 03/16/04
|
||||
* - Thanks for Darrell Young
|
||||
* - Fixed to set v1.1 to the HTTP version.
|
||||
* 10/20/04
|
||||
* - Brent Hills <bhills@openshores.com>
|
||||
* - Added setMYNAME() and getMYNAME().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
public class SSDPResponse extends HTTPResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPResponse()
|
||||
{
|
||||
setVersion(HTTP.VERSION_11);
|
||||
}
|
||||
|
||||
public SSDPResponse(InputStream in)
|
||||
{
|
||||
super(in);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// ST (SearchTarget)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setST(String value)
|
||||
{
|
||||
setHeader(HTTP.ST, value);
|
||||
}
|
||||
|
||||
public String getST()
|
||||
{
|
||||
return getHeaderValue(HTTP.ST);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Location
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setLocation(String value)
|
||||
{
|
||||
setHeader(HTTP.LOCATION, value);
|
||||
}
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return getHeaderValue(HTTP.LOCATION);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// USN
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setUSN(String value)
|
||||
{
|
||||
setHeader(HTTP.USN, value);
|
||||
}
|
||||
|
||||
public String getUSN()
|
||||
{
|
||||
return getHeaderValue(HTTP.USN);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// MYNAME
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setMYNAME(String value)
|
||||
{
|
||||
setHeader(HTTP.MYNAME, value);
|
||||
}
|
||||
|
||||
public String getMYNAME()
|
||||
{
|
||||
return getHeaderValue(HTTP.MYNAME);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// CacheControl
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setLeaseTime(int len)
|
||||
{
|
||||
setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len));
|
||||
}
|
||||
|
||||
public int getLeaseTime()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// getHeader (Override)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public String getHeader()
|
||||
{
|
||||
StringBuffer str = new StringBuffer();
|
||||
|
||||
str.append(getStatusLineString());
|
||||
str.append(getHeaderString());
|
||||
str.append(HTTP.CRLF); // for Intel UPnP control points.
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,26 +5,26 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SSDPMSearchRequest.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/19/02
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/19/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import org.cybergarage.net.*;
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class SSDPSearchRequest extends SSDPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public class SSDPSearchRequest extends SSDPRequest
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPSearchRequest(String serachTarget, int mx)
|
||||
{
|
||||
@ -35,16 +35,16 @@ public class SSDPSearchRequest extends SSDPRequest
|
||||
setHeader(HTTP.MX, Integer.toString(mx));
|
||||
setHeader(HTTP.MAN, "\"" + MAN.DISCOVER + "\"");
|
||||
}
|
||||
|
||||
public SSDPSearchRequest(String serachTarget)
|
||||
|
||||
public SSDPSearchRequest(String serachTarget)
|
||||
{
|
||||
this(serachTarget, SSDP.DEFAULT_MSEARCH_MX);
|
||||
}
|
||||
|
||||
public SSDPSearchRequest()
|
||||
this(serachTarget, SSDP.DEFAULT_MSEARCH_MX);
|
||||
}
|
||||
|
||||
public SSDPSearchRequest()
|
||||
{
|
||||
this(ST.ROOT_DEVICE);
|
||||
}
|
||||
this(ST.ROOT_DEVICE);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// HOST
|
||||
|
@ -5,31 +5,31 @@
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: SSDPSearchResponse.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/14/03
|
||||
* - first revision.
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/14/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
|
||||
package org.cybergarage.upnp.ssdp;
|
||||
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class SSDPSearchResponse extends SSDPResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPSearchResponse()
|
||||
{
|
||||
setStatusCode(HTTPStatus.OK);
|
||||
setCacheControl(Device.DEFAULT_LEASE_TIME);
|
||||
setHeader(HTTP.SERVER, UPnP.getServerName());
|
||||
setHeader(HTTP.EXT, "");
|
||||
}
|
||||
import org.cybergarage.upnp.*;
|
||||
|
||||
public class SSDPSearchResponse extends SSDPResponse
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public SSDPSearchResponse()
|
||||
{
|
||||
setStatusCode(HTTPStatus.OK);
|
||||
setCacheControl(Device.DEFAULT_LEASE_TIME);
|
||||
setHeader(HTTP.SERVER, UPnP.getServerName());
|
||||
setHeader(HTTP.EXT, "");
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
* 08/23/07
|
||||
* - Thanks for Kazuyuki Shudo
|
||||
* - Changed run() to catch IOException of HTTPMUSocket::receive().
|
||||
* 01/10/08
|
||||
* 01/10/08
|
||||
* - Changed start() not to abort when the interface infomation is null on Android m3-rc37a.
|
||||
*
|
||||
******************************************************************/
|
||||
|
@ -61,9 +61,6 @@ public class SSDPSearchSocketList extends Vector<SSDPSearchSocket>
|
||||
this.multicastIPv6 = multicastIPv6;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Methods
|
||||
////////////////////////////////////////////////
|
||||
|
@ -1,57 +1,57 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ActionData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 03/28/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import org.cybergarage.upnp.control.*;
|
||||
|
||||
public class ActionData extends NodeData
|
||||
{
|
||||
public ActionData()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// ActionListener
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ActionListener actionListener = null;
|
||||
|
||||
public ActionListener getActionListener() {
|
||||
return actionListener;
|
||||
}
|
||||
|
||||
public void setActionListener(ActionListener actionListener) {
|
||||
this.actionListener = actionListener;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// ControlResponse
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ControlResponse ctrlRes = null;
|
||||
|
||||
public ControlResponse getControlResponse()
|
||||
{
|
||||
return ctrlRes;
|
||||
}
|
||||
|
||||
public void setControlResponse(ControlResponse res)
|
||||
{
|
||||
ctrlRes = res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ActionData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 03/28/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import org.cybergarage.upnp.control.*;
|
||||
|
||||
public class ActionData extends NodeData
|
||||
{
|
||||
public ActionData()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// ActionListener
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ActionListener actionListener = null;
|
||||
|
||||
public ActionListener getActionListener() {
|
||||
return actionListener;
|
||||
}
|
||||
|
||||
public void setActionListener(ActionListener actionListener) {
|
||||
this.actionListener = actionListener;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// ControlResponse
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ControlResponse ctrlRes = null;
|
||||
|
||||
public ControlResponse getControlResponse()
|
||||
{
|
||||
return ctrlRes;
|
||||
}
|
||||
|
||||
public void setControlResponse(ControlResponse res)
|
||||
{
|
||||
ctrlRes = res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,271 +1,271 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: DeviceData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 03/28/03
|
||||
* - first revision.
|
||||
* 12/25/03
|
||||
* - Added Advertiser functions.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.cybergarage.util.*;
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.upnp.ssdp.*;
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class DeviceData extends NodeData
|
||||
{
|
||||
public DeviceData()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// description
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String descriptionURI = null;
|
||||
private File descriptionFile = null;
|
||||
|
||||
public File getDescriptionFile() {
|
||||
return descriptionFile;
|
||||
}
|
||||
|
||||
public String getDescriptionURI() {
|
||||
return descriptionURI;
|
||||
}
|
||||
|
||||
public void setDescriptionFile(File descriptionFile) {
|
||||
this.descriptionFile = descriptionFile;
|
||||
}
|
||||
|
||||
public void setDescriptionURI(String descriptionURI) {
|
||||
this.descriptionURI = descriptionURI;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// description
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String location = "";
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// LeaseTime
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private int leaseTime = Device.DEFAULT_LEASE_TIME;
|
||||
|
||||
public int getLeaseTime()
|
||||
{
|
||||
return leaseTime;
|
||||
}
|
||||
|
||||
public void setLeaseTime(int val)
|
||||
{
|
||||
leaseTime = val;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// HTTPServer
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private HTTPServerList httpServerList = null;
|
||||
|
||||
public HTTPServerList getHTTPServerList() {
|
||||
if(this.httpServerList==null){
|
||||
this.httpServerList = new HTTPServerList(this.httpBinds,this.httpPort);
|
||||
}
|
||||
return this.httpServerList;
|
||||
}
|
||||
|
||||
private InetAddress[] httpBinds = null;
|
||||
|
||||
public void setHTTPBindAddress(InetAddress[] inets){
|
||||
this.httpBinds=inets;
|
||||
}
|
||||
|
||||
public InetAddress[] getHTTPBindAddress(){
|
||||
return this.httpBinds;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// httpPort
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private int httpPort = Device.HTTP_DEFAULT_PORT;
|
||||
|
||||
public int getHTTPPort() {
|
||||
return httpPort;
|
||||
}
|
||||
|
||||
public void setHTTPPort(int port) {
|
||||
httpPort = port;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// controlActionListenerList
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ListenerList controlActionListenerList = new ListenerList();
|
||||
|
||||
public ListenerList getControlActionListenerList() {
|
||||
return controlActionListenerList;
|
||||
}
|
||||
|
||||
/*
|
||||
public void setControlActionListenerList(ListenerList controlActionListenerList) {
|
||||
this.controlActionListenerList = controlActionListenerList;
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SSDPSearchSocket
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private SSDPSearchSocketList ssdpSearchSocketList = null;
|
||||
private String ssdpMulticastIPv4 = SSDP.ADDRESS;
|
||||
private String ssdpMulticastIPv6 = SSDP.getIPv6Address();
|
||||
private int ssdpPort = SSDP.PORT;
|
||||
private InetAddress[] ssdpBinds = null;
|
||||
|
||||
public SSDPSearchSocketList getSSDPSearchSocketList() {
|
||||
if(this.ssdpSearchSocketList==null){
|
||||
this.ssdpSearchSocketList = new SSDPSearchSocketList(this.ssdpBinds,ssdpPort,ssdpMulticastIPv4,ssdpMulticastIPv6);
|
||||
}
|
||||
return ssdpSearchSocketList;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param port The port to use for binding the SSDP service.
|
||||
* The port will be used as source port for all SSDP messages
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setSSDPPort(int port){
|
||||
this.ssdpPort=port;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The port used for binding the SSDP service.
|
||||
* The port will be used as source port for all SSDP messages
|
||||
*/
|
||||
public int getSSDPPort(){
|
||||
return this.ssdpPort;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param inets The <tt>InetAddress</tt> that will be binded for listing this service.
|
||||
* Use <code>null</code> for the default behaviur.
|
||||
* @see org.cybergarage.upnp.ssdp
|
||||
* @see org.cybergarage.upnp
|
||||
* @see org.cybergarage.net.HostInterface
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setSSDPBindAddress(InetAddress[] inets){
|
||||
this.ssdpBinds=inets;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return inets The <tt>InetAddress</tt> that will be binded for this service
|
||||
* <code>null</code> means that defulat behaviur will be used
|
||||
* @since 1.8
|
||||
*/
|
||||
public InetAddress[] getSSDPBindAddress(){
|
||||
return this.ssdpBinds;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ip The IPv4 address used as destination address for Multicast comunication
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setMulticastIPv4Address(String ip){
|
||||
this.ssdpMulticastIPv4=ip;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The IPv4 address used for Multicast comunication
|
||||
*/
|
||||
public String getMulticastIPv4Address(){
|
||||
return this.ssdpMulticastIPv4;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ip The IPv6 address used as destination address for Multicast comunication
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setMulticastIPv6Address(String ip){
|
||||
this.ssdpMulticastIPv6=ip;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The IPv6 address used as destination address for Multicast comunication
|
||||
* @since 1.8
|
||||
*/
|
||||
public String getMulticastIPv6Address(){
|
||||
return this.ssdpMulticastIPv6;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SSDPPacket
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private SSDPPacket ssdpPacket = null;
|
||||
|
||||
public SSDPPacket getSSDPPacket() {
|
||||
return ssdpPacket;
|
||||
}
|
||||
|
||||
public void setSSDPPacket(SSDPPacket packet) {
|
||||
ssdpPacket = packet;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Advertiser
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Advertiser advertiser = null;
|
||||
|
||||
public void setAdvertiser(Advertiser adv)
|
||||
{
|
||||
advertiser = adv;
|
||||
}
|
||||
|
||||
public Advertiser getAdvertiser()
|
||||
{
|
||||
return advertiser;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: DeviceData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 03/28/03
|
||||
* - first revision.
|
||||
* 12/25/03
|
||||
* - Added Advertiser functions.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.cybergarage.util.*;
|
||||
import org.cybergarage.http.*;
|
||||
|
||||
import org.cybergarage.upnp.*;
|
||||
import org.cybergarage.upnp.ssdp.*;
|
||||
import org.cybergarage.upnp.device.*;
|
||||
|
||||
public class DeviceData extends NodeData
|
||||
{
|
||||
public DeviceData()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// description
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String descriptionURI = null;
|
||||
private File descriptionFile = null;
|
||||
|
||||
public File getDescriptionFile() {
|
||||
return descriptionFile;
|
||||
}
|
||||
|
||||
public String getDescriptionURI() {
|
||||
return descriptionURI;
|
||||
}
|
||||
|
||||
public void setDescriptionFile(File descriptionFile) {
|
||||
this.descriptionFile = descriptionFile;
|
||||
}
|
||||
|
||||
public void setDescriptionURI(String descriptionURI) {
|
||||
this.descriptionURI = descriptionURI;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// description
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String location = "";
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// LeaseTime
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private int leaseTime = Device.DEFAULT_LEASE_TIME;
|
||||
|
||||
public int getLeaseTime()
|
||||
{
|
||||
return leaseTime;
|
||||
}
|
||||
|
||||
public void setLeaseTime(int val)
|
||||
{
|
||||
leaseTime = val;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// HTTPServer
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private HTTPServerList httpServerList = null;
|
||||
|
||||
public HTTPServerList getHTTPServerList() {
|
||||
if(this.httpServerList==null){
|
||||
this.httpServerList = new HTTPServerList(this.httpBinds,this.httpPort);
|
||||
}
|
||||
return this.httpServerList;
|
||||
}
|
||||
|
||||
private InetAddress[] httpBinds = null;
|
||||
|
||||
public void setHTTPBindAddress(InetAddress[] inets){
|
||||
this.httpBinds=inets;
|
||||
}
|
||||
|
||||
public InetAddress[] getHTTPBindAddress(){
|
||||
return this.httpBinds;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// httpPort
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private int httpPort = Device.HTTP_DEFAULT_PORT;
|
||||
|
||||
public int getHTTPPort() {
|
||||
return httpPort;
|
||||
}
|
||||
|
||||
public void setHTTPPort(int port) {
|
||||
httpPort = port;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// controlActionListenerList
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ListenerList controlActionListenerList = new ListenerList();
|
||||
|
||||
public ListenerList getControlActionListenerList() {
|
||||
return controlActionListenerList;
|
||||
}
|
||||
|
||||
/*
|
||||
public void setControlActionListenerList(ListenerList controlActionListenerList) {
|
||||
this.controlActionListenerList = controlActionListenerList;
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SSDPSearchSocket
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private SSDPSearchSocketList ssdpSearchSocketList = null;
|
||||
private String ssdpMulticastIPv4 = SSDP.ADDRESS;
|
||||
private String ssdpMulticastIPv6 = SSDP.getIPv6Address();
|
||||
private int ssdpPort = SSDP.PORT;
|
||||
private InetAddress[] ssdpBinds = null;
|
||||
|
||||
public SSDPSearchSocketList getSSDPSearchSocketList() {
|
||||
if(this.ssdpSearchSocketList==null){
|
||||
this.ssdpSearchSocketList = new SSDPSearchSocketList(this.ssdpBinds,ssdpPort,ssdpMulticastIPv4,ssdpMulticastIPv6);
|
||||
}
|
||||
return ssdpSearchSocketList;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param port The port to use for binding the SSDP service.
|
||||
* The port will be used as source port for all SSDP messages
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setSSDPPort(int port){
|
||||
this.ssdpPort=port;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The port used for binding the SSDP service.
|
||||
* The port will be used as source port for all SSDP messages
|
||||
*/
|
||||
public int getSSDPPort(){
|
||||
return this.ssdpPort;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param inets The <tt>InetAddress</tt> that will be binded for listing this service.
|
||||
* Use <code>null</code> for the default behaviur.
|
||||
* @see {@link UPnP}
|
||||
* @see {@link USSDP}
|
||||
* @see {@link HostInterface}
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setSSDPBindAddress(InetAddress[] inets){
|
||||
this.ssdpBinds=inets;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return inets The <tt>InetAddress</tt> that will be binded for this service
|
||||
* <code>null</code> means that defulat behaviur will be used
|
||||
* @since 1.8
|
||||
*/
|
||||
public InetAddress[] getSSDPBindAddress(){
|
||||
return this.ssdpBinds;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ip The IPv4 address used as destination address for Multicast comunication
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setMulticastIPv4Address(String ip){
|
||||
this.ssdpMulticastIPv4=ip;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The IPv4 address used for Multicast comunication
|
||||
*/
|
||||
public String getMulticastIPv4Address(){
|
||||
return this.ssdpMulticastIPv4;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ip The IPv6 address used as destination address for Multicast comunication
|
||||
* @since 1.8
|
||||
*/
|
||||
public void setMulticastIPv6Address(String ip){
|
||||
this.ssdpMulticastIPv6=ip;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return The IPv6 address used as destination address for Multicast comunication
|
||||
* @since 1.8
|
||||
*/
|
||||
public String getMulticastIPv6Address(){
|
||||
return this.ssdpMulticastIPv6;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SSDPPacket
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private SSDPPacket ssdpPacket = null;
|
||||
|
||||
public SSDPPacket getSSDPPacket() {
|
||||
return ssdpPacket;
|
||||
}
|
||||
|
||||
public void setSSDPPacket(SSDPPacket packet) {
|
||||
ssdpPacket = packet;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Advertiser
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Advertiser advertiser = null;
|
||||
|
||||
public void setAdvertiser(Advertiser adv)
|
||||
{
|
||||
advertiser = adv;
|
||||
}
|
||||
|
||||
public Advertiser getAdvertiser()
|
||||
{
|
||||
return advertiser;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,43 +1,43 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ActionData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 03/28/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import org.cybergarage.xml.*;
|
||||
|
||||
public class NodeData
|
||||
{
|
||||
public NodeData()
|
||||
{
|
||||
setNode(null);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Node
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node node;
|
||||
|
||||
public void setNode(Node node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public Node getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ActionData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 03/28/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import org.cybergarage.xml.*;
|
||||
|
||||
public class NodeData
|
||||
{
|
||||
public NodeData()
|
||||
{
|
||||
setNode(null);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Node
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node node;
|
||||
|
||||
public void setNode(Node node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public Node getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,112 +1,112 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ServiceData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 03/28/03
|
||||
* - first revision.
|
||||
* 01/06/04
|
||||
* - Moved setQueryListener() and getQueryListener() to StateVariableData class.
|
||||
* 03/30/05
|
||||
* - Removed setDescriptionURL() and getDescriptionURL().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import org.cybergarage.util.*;
|
||||
import org.cybergarage.xml.*;
|
||||
|
||||
import org.cybergarage.upnp.event.*;
|
||||
|
||||
public class ServiceData extends NodeData
|
||||
{
|
||||
public ServiceData()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// controlActionListenerList
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ListenerList controlActionListenerList = new ListenerList();
|
||||
|
||||
public ListenerList getControlActionListenerList() {
|
||||
return controlActionListenerList;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// scpdNode
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node scpdNode = null;
|
||||
|
||||
public Node getSCPDNode() {
|
||||
return scpdNode;
|
||||
}
|
||||
|
||||
public void setSCPDNode(Node node) {
|
||||
scpdNode = node;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SubscriberList
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private SubscriberList subscriberList = new SubscriberList();
|
||||
|
||||
public SubscriberList getSubscriberList() {
|
||||
return subscriberList;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String descriptionURL = "";
|
||||
|
||||
public String getDescriptionURL() {
|
||||
return descriptionURL;
|
||||
}
|
||||
|
||||
public void setDescriptionURL(String descriptionURL) {
|
||||
this.descriptionURL = descriptionURL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String sid = "";
|
||||
|
||||
public String getSID() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSID(String id) {
|
||||
sid = id;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long timeout = 0;
|
||||
|
||||
public long getTimeout()
|
||||
{
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(long value)
|
||||
{
|
||||
timeout = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: ServiceData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 03/28/03
|
||||
* - first revision.
|
||||
* 01/06/04
|
||||
* - Moved setQueryListener() and getQueryListener() to StateVariableData class.
|
||||
* 03/30/05
|
||||
* - Removed setDescriptionURL() and getDescriptionURL().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import org.cybergarage.util.*;
|
||||
import org.cybergarage.xml.*;
|
||||
|
||||
import org.cybergarage.upnp.event.*;
|
||||
|
||||
public class ServiceData extends NodeData
|
||||
{
|
||||
public ServiceData()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// controlActionListenerList
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private ListenerList controlActionListenerList = new ListenerList();
|
||||
|
||||
public ListenerList getControlActionListenerList() {
|
||||
return controlActionListenerList;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// scpdNode
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private Node scpdNode = null;
|
||||
|
||||
public Node getSCPDNode() {
|
||||
return scpdNode;
|
||||
}
|
||||
|
||||
public void setSCPDNode(Node node) {
|
||||
scpdNode = node;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SubscriberList
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private SubscriberList subscriberList = new SubscriberList();
|
||||
|
||||
public SubscriberList getSubscriberList() {
|
||||
return subscriberList;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String descriptionURL = "";
|
||||
|
||||
public String getDescriptionURL() {
|
||||
return descriptionURL;
|
||||
}
|
||||
|
||||
public void setDescriptionURL(String descriptionURL) {
|
||||
this.descriptionURL = descriptionURL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// SID
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String sid = "";
|
||||
|
||||
public String getSID() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSID(String id) {
|
||||
sid = id;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Timeout
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private long timeout = 0;
|
||||
|
||||
public long getTimeout()
|
||||
{
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(long value)
|
||||
{
|
||||
timeout = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,73 +1,73 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File:StateVariableData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 02/05/03
|
||||
* - first revision.
|
||||
* 01/06/04
|
||||
* - Added setQueryListener() and getQueryListener().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import org.cybergarage.upnp.control.*;
|
||||
|
||||
public class StateVariableData extends NodeData
|
||||
{
|
||||
public StateVariableData()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// value
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String value = "";
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// QueryListener
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private QueryListener queryListener = null;
|
||||
|
||||
public QueryListener getQueryListener() {
|
||||
return queryListener;
|
||||
}
|
||||
|
||||
public void setQueryListener(QueryListener queryListener) {
|
||||
this.queryListener = queryListener;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// QueryResponse
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private QueryResponse queryRes = null;
|
||||
|
||||
public QueryResponse getQueryResponse()
|
||||
{
|
||||
return queryRes;
|
||||
}
|
||||
|
||||
public void setQueryResponse(QueryResponse res)
|
||||
{
|
||||
queryRes = res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUPnP for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File:StateVariableData.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 02/05/03
|
||||
* - first revision.
|
||||
* 01/06/04
|
||||
* - Added setQueryListener() and getQueryListener().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.upnp.xml;
|
||||
|
||||
import org.cybergarage.upnp.control.*;
|
||||
|
||||
public class StateVariableData extends NodeData
|
||||
{
|
||||
public StateVariableData()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// value
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private String value = "";
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// QueryListener
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private QueryListener queryListener = null;
|
||||
|
||||
public QueryListener getQueryListener() {
|
||||
return queryListener;
|
||||
}
|
||||
|
||||
public void setQueryListener(QueryListener queryListener) {
|
||||
this.queryListener = queryListener;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// QueryResponse
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private QueryResponse queryRes = null;
|
||||
|
||||
public QueryResponse getQueryResponse()
|
||||
{
|
||||
return queryRes;
|
||||
}
|
||||
|
||||
public void setQueryResponse(QueryResponse res)
|
||||
{
|
||||
queryRes = res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,80 +1,79 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: FileUtil.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/03/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class FileUtil
|
||||
{
|
||||
public final static byte[] load(String fileName)
|
||||
{
|
||||
try {
|
||||
FileInputStream fin=new FileInputStream(fileName);
|
||||
return load(fin);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public final static byte[] load(File file)
|
||||
{
|
||||
try {
|
||||
FileInputStream fin=new FileInputStream(file);
|
||||
return load(fin);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public final static byte[] load(FileInputStream fin)
|
||||
{
|
||||
byte readBuf[] = new byte[512*1024];
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
|
||||
int readCnt = fin.read(readBuf);
|
||||
while (0 < readCnt) {
|
||||
bout.write(readBuf, 0, readCnt);
|
||||
readCnt = fin.read(readBuf);
|
||||
}
|
||||
|
||||
fin.close();
|
||||
|
||||
return bout.toByteArray();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public final static boolean isXMLFileName(String name)
|
||||
{
|
||||
if (StringUtil.hasData(name) == false)
|
||||
return false;
|
||||
String lowerName = name.toLowerCase(Locale.US);
|
||||
return lowerName.endsWith("xml");
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: FileUtil.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/03/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
public final class FileUtil
|
||||
{
|
||||
public final static byte[] load(String fileName)
|
||||
{
|
||||
try {
|
||||
FileInputStream fin=new FileInputStream(fileName);
|
||||
return load(fin);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public final static byte[] load(File file)
|
||||
{
|
||||
try {
|
||||
FileInputStream fin=new FileInputStream(file);
|
||||
return load(fin);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public final static byte[] load(FileInputStream fin)
|
||||
{
|
||||
byte readBuf[] = new byte[512*1024];
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
|
||||
int readCnt = fin.read(readBuf);
|
||||
while (0 < readCnt) {
|
||||
bout.write(readBuf, 0, readCnt);
|
||||
readCnt = fin.read(readBuf);
|
||||
}
|
||||
|
||||
fin.close();
|
||||
|
||||
return bout.toByteArray();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public final static boolean isXMLFileName(String name)
|
||||
{
|
||||
if (StringUtil.hasData(name) == false)
|
||||
return false;
|
||||
String lowerName = name.toLowerCase();
|
||||
return lowerName.endsWith("xml");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,29 +1,29 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: ListenerList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/30/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ListenerList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 12/30/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
import java.util.Vector;
|
||||
package org.cybergarage.util;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class ListenerList extends Vector<Object>
|
||||
{
|
||||
public boolean add(Object obj)
|
||||
{
|
||||
if (0 <= indexOf(obj))
|
||||
return false;
|
||||
return super.add(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public class ListenerList extends Vector<Object>
|
||||
{
|
||||
public boolean add(Object obj)
|
||||
{
|
||||
if (0 <= indexOf(obj))
|
||||
return false;
|
||||
return super.add(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,54 +1,54 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: Mutex.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 06/19/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
public class Mutex
|
||||
{
|
||||
private boolean syncLock;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Mutex()
|
||||
{
|
||||
syncLock = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// lock
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public synchronized void lock()
|
||||
{
|
||||
while(syncLock == true) {
|
||||
try {
|
||||
wait();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
};
|
||||
}
|
||||
syncLock = true;
|
||||
}
|
||||
|
||||
public synchronized void unlock()
|
||||
{
|
||||
syncLock = false;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: Mutex.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 06/19/04
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
public class Mutex
|
||||
{
|
||||
private boolean syncLock;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public Mutex()
|
||||
{
|
||||
syncLock = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// lock
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public synchronized void lock()
|
||||
{
|
||||
while(syncLock == true) {
|
||||
try {
|
||||
wait();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
};
|
||||
}
|
||||
syncLock = true;
|
||||
}
|
||||
|
||||
public synchronized void unlock()
|
||||
{
|
||||
syncLock = false;
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
}
|
@ -1,123 +1,123 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
/******************************************************************
|
||||
*
|
||||
* File: FileUtil.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/12/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: FileUtil.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/12/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
public final class StringUtil
|
||||
{
|
||||
public final static boolean hasData(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.length() <= 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public final static int toInteger(String value)
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public final static long toLong(String value)
|
||||
{
|
||||
try {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public final static int findOf(String str, String chars, int startIdx, int endIdx, int offset, boolean isEqual)
|
||||
{
|
||||
if (offset == 0)
|
||||
return -1;
|
||||
int charCnt = chars.length();
|
||||
int idx = startIdx;
|
||||
while (true) {
|
||||
if (0 < offset) {
|
||||
if (endIdx < idx)
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (idx < endIdx)
|
||||
break;
|
||||
}
|
||||
char strc = str.charAt(idx);
|
||||
int noEqualCnt = 0;
|
||||
for (int n=0; n<charCnt; n++) {
|
||||
char charc = chars.charAt(n);
|
||||
if (isEqual == true) {
|
||||
if (strc == charc)
|
||||
return idx;
|
||||
}
|
||||
else {
|
||||
if (strc != charc)
|
||||
noEqualCnt++;
|
||||
if (noEqualCnt == charCnt)
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
idx += offset;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public final static int findFirstOf(String str, String chars)
|
||||
{
|
||||
return findOf(str, chars, 0, (str.length()-1), 1, true);
|
||||
}
|
||||
|
||||
public final static int findFirstNotOf(String str, String chars)
|
||||
{
|
||||
return findOf(str, chars, 0, (str.length()-1), 1, false);
|
||||
}
|
||||
|
||||
public final static int findLastOf(String str, String chars)
|
||||
{
|
||||
return findOf(str, chars, (str.length()-1), 0, -1, true);
|
||||
}
|
||||
|
||||
public final static int findLastNotOf(String str, String chars)
|
||||
{
|
||||
return findOf(str, chars, (str.length()-1), 0, -1, false);
|
||||
}
|
||||
|
||||
public final static String trim(String trimStr, String trimChars)
|
||||
{
|
||||
int spIdx = findFirstNotOf(trimStr, trimChars);
|
||||
if (spIdx < 0) {
|
||||
String buf = trimStr;
|
||||
return buf;
|
||||
}
|
||||
String trimStr2 = trimStr.substring(spIdx, trimStr.length());
|
||||
spIdx = findLastNotOf(trimStr2, trimChars);
|
||||
if (spIdx < 0) {
|
||||
String buf = trimStr2;
|
||||
return buf;
|
||||
}
|
||||
String buf = trimStr2.substring(0, spIdx+1);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
public final class StringUtil
|
||||
{
|
||||
public final static boolean hasData(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return false;
|
||||
if (value.length() <= 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public final static int toInteger(String value)
|
||||
{
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public final static long toLong(String value)
|
||||
{
|
||||
try {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.warning(e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public final static int findOf(String str, String chars, int startIdx, int endIdx, int offset, boolean isEqual)
|
||||
{
|
||||
if (offset == 0)
|
||||
return -1;
|
||||
int charCnt = chars.length();
|
||||
int idx = startIdx;
|
||||
while (true) {
|
||||
if (0 < offset) {
|
||||
if (endIdx < idx)
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (idx < endIdx)
|
||||
break;
|
||||
}
|
||||
char strc = str.charAt(idx);
|
||||
int noEqualCnt = 0;
|
||||
for (int n=0; n<charCnt; n++) {
|
||||
char charc = chars.charAt(n);
|
||||
if (isEqual == true) {
|
||||
if (strc == charc)
|
||||
return idx;
|
||||
}
|
||||
else {
|
||||
if (strc != charc)
|
||||
noEqualCnt++;
|
||||
if (noEqualCnt == charCnt)
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
idx += offset;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public final static int findFirstOf(String str, String chars)
|
||||
{
|
||||
return findOf(str, chars, 0, (str.length()-1), 1, true);
|
||||
}
|
||||
|
||||
public final static int findFirstNotOf(String str, String chars)
|
||||
{
|
||||
return findOf(str, chars, 0, (str.length()-1), 1, false);
|
||||
}
|
||||
|
||||
public final static int findLastOf(String str, String chars)
|
||||
{
|
||||
return findOf(str, chars, (str.length()-1), 0, -1, true);
|
||||
}
|
||||
|
||||
public final static int findLastNotOf(String str, String chars)
|
||||
{
|
||||
return findOf(str, chars, (str.length()-1), 0, -1, false);
|
||||
}
|
||||
|
||||
public final static String trim(String trimStr, String trimChars)
|
||||
{
|
||||
int spIdx = findFirstNotOf(trimStr, trimChars);
|
||||
if (spIdx < 0) {
|
||||
String buf = trimStr;
|
||||
return buf;
|
||||
}
|
||||
String trimStr2 = trimStr.substring(spIdx, trimStr.length());
|
||||
spIdx = findLastNotOf(trimStr2, trimChars);
|
||||
if (spIdx < 0) {
|
||||
String buf = trimStr2;
|
||||
return buf;
|
||||
}
|
||||
String buf = trimStr2.substring(0, spIdx+1);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,85 +1,85 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: Thread.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/05/04
|
||||
* - first revision.
|
||||
* 08/23/07
|
||||
* - Thanks for Kazuyuki Shudo
|
||||
* - Changed stop() to stop more safety using Thread::interrupt().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
public class ThreadCore implements Runnable
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ThreadCore()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Thread
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private java.lang.Thread mThreadObject = null;
|
||||
|
||||
public void setThreadObject(java.lang.Thread obj) {
|
||||
mThreadObject = obj;
|
||||
}
|
||||
|
||||
public java.lang.Thread getThreadObject() {
|
||||
return mThreadObject;
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
java.lang.Thread threadObject = getThreadObject();
|
||||
if (threadObject == null) {
|
||||
threadObject = new java.lang.Thread(this,"Cyber.ThreadCore");
|
||||
setThreadObject(threadObject);
|
||||
threadObject.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isRunnable()
|
||||
{
|
||||
return (Thread.currentThread() == getThreadObject()) ? true : false;
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
java.lang.Thread threadObject = getThreadObject();
|
||||
if (threadObject != null) {
|
||||
//threadObject.destroy();
|
||||
//threadObject.stop();
|
||||
|
||||
// Thanks for Kazuyuki Shudo (08/23/07)
|
||||
threadObject.interrupt();
|
||||
|
||||
setThreadObject(null);
|
||||
// I2P break Disposer out of sleep()
|
||||
threadObject.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public void restart()
|
||||
{
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2004
|
||||
*
|
||||
* File: Thread.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/05/04
|
||||
* - first revision.
|
||||
* 08/23/07
|
||||
* - Thanks for Kazuyuki Shudo
|
||||
* - Changed stop() to stop more safety using Thread::interrupt().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
public class ThreadCore implements Runnable
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// Constructor
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public ThreadCore()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Thread
|
||||
////////////////////////////////////////////////
|
||||
|
||||
private java.lang.Thread mThreadObject = null;
|
||||
|
||||
public void setThreadObject(java.lang.Thread obj) {
|
||||
mThreadObject = obj;
|
||||
}
|
||||
|
||||
public java.lang.Thread getThreadObject() {
|
||||
return mThreadObject;
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
java.lang.Thread threadObject = getThreadObject();
|
||||
if (threadObject == null) {
|
||||
threadObject = new java.lang.Thread(this,"Cyber.ThreadCore");
|
||||
setThreadObject(threadObject);
|
||||
threadObject.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isRunnable()
|
||||
{
|
||||
return (Thread.currentThread() == getThreadObject()) ? true : false;
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
java.lang.Thread threadObject = getThreadObject();
|
||||
if (threadObject != null) {
|
||||
//threadObject.destroy();
|
||||
//threadObject.stop();
|
||||
|
||||
// Thanks for Kazuyuki Shudo (08/23/07)
|
||||
threadObject.interrupt();
|
||||
|
||||
setThreadObject(null);
|
||||
// I2P break Disposer out of sleep()
|
||||
threadObject.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public void restart()
|
||||
{
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,37 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: TimerUtil.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/15/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
public final class TimerUtil
|
||||
{
|
||||
public final static void wait(int waitTime)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(waitTime);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
|
||||
public final static void waitRandom(int time)
|
||||
{
|
||||
int waitTime = (int)(Math.random() * (double)time);
|
||||
try {
|
||||
Thread.sleep(waitTime);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberUtil for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: TimerUtil.java
|
||||
*
|
||||
* Revision:
|
||||
*
|
||||
* 01/15/03
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.util;
|
||||
|
||||
public final class TimerUtil
|
||||
{
|
||||
public final static void wait(int waitTime)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(waitTime);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
|
||||
public final static void waitRandom(int time)
|
||||
{
|
||||
int waitTime = (int)(Math.random() * (double)time);
|
||||
try {
|
||||
Thread.sleep(waitTime);
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,61 +1,78 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: Attribute.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/27/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: Attribute.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/27/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.xml;
|
||||
|
||||
public class Attribute
|
||||
{
|
||||
private String name = new String();
|
||||
private String value = new String();
|
||||
|
||||
public Attribute()
|
||||
{
|
||||
}
|
||||
|
||||
public Attribute(String name, String value)
|
||||
{
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// name
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
package org.cybergarage.xml;
|
||||
|
||||
public class Attribute
|
||||
{
|
||||
private String name = new String();
|
||||
private String value = new String();
|
||||
|
||||
public Attribute()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// value
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
}
|
||||
|
||||
public Attribute(String name, String value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
this();
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
public Attribute(Attribute otherAttr)
|
||||
{
|
||||
this();
|
||||
set(otherAttr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// name
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// value
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// set
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public void set(Attribute otherAttr)
|
||||
{
|
||||
setName(otherAttr.getName());
|
||||
setValue(otherAttr.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,45 +1,45 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: AttributeList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/27/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: AttributeList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/27/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.xml;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class AttributeList extends Vector<Attribute>
|
||||
{
|
||||
public AttributeList()
|
||||
{
|
||||
}
|
||||
|
||||
public Attribute getAttribute(int n)
|
||||
{
|
||||
return (Attribute)get(n);
|
||||
}
|
||||
|
||||
public Attribute getAttribute(String name)
|
||||
{
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
int nLists = size();
|
||||
for (int n=0; n<nLists; n++) {
|
||||
Attribute elem = getAttribute(n);
|
||||
if (name.compareTo(elem.getName()) == 0)
|
||||
return elem;
|
||||
package org.cybergarage.xml;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class AttributeList extends Vector<Attribute>
|
||||
{
|
||||
public AttributeList()
|
||||
{
|
||||
}
|
||||
|
||||
public Attribute getAttribute(int n)
|
||||
{
|
||||
return (Attribute)get(n);
|
||||
}
|
||||
|
||||
public Attribute getAttribute(String name)
|
||||
{
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
int nLists = size();
|
||||
for (int n=0; n<nLists; n++) {
|
||||
Attribute elem = getAttribute(n);
|
||||
if (name.compareTo(elem.getName()) == 0)
|
||||
return elem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,16 +365,30 @@ 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);
|
||||
|
@ -1,63 +1,63 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: NodeList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/27/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: NodeList.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/27/02
|
||||
* - first revision.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.xml;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class NodeList extends Vector<Node>
|
||||
{
|
||||
public NodeList()
|
||||
{
|
||||
}
|
||||
|
||||
public Node getNode(int n)
|
||||
{
|
||||
return (Node)get(n);
|
||||
}
|
||||
|
||||
public Node getNode(String name)
|
||||
{
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
int nLists = size();
|
||||
for (int n=0; n<nLists; n++) {
|
||||
Node node = getNode(n);
|
||||
String nodeName = node.getName();
|
||||
if (name.compareTo(nodeName) == 0)
|
||||
return node;
|
||||
package org.cybergarage.xml;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class NodeList extends Vector<Node>
|
||||
{
|
||||
public NodeList()
|
||||
{
|
||||
}
|
||||
|
||||
public Node getNode(int n)
|
||||
{
|
||||
return (Node)get(n);
|
||||
}
|
||||
|
||||
public Node getNode(String name)
|
||||
{
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
int nLists = size();
|
||||
for (int n=0; n<nLists; n++) {
|
||||
Node node = getNode(n);
|
||||
String nodeName = node.getName();
|
||||
if (name.compareTo(nodeName) == 0)
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Node getEndsWith(String name)
|
||||
{
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
int nLists = size();
|
||||
for (int n=0; n<nLists; n++) {
|
||||
Node node = getNode(n);
|
||||
String nodeName = node.getName();
|
||||
if (nodeName == null)
|
||||
continue;
|
||||
if (nodeName.endsWith(name) == true)
|
||||
return node;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Node getEndsWith(String name)
|
||||
{
|
||||
if (name == null)
|
||||
return null;
|
||||
|
||||
int nLists = size();
|
||||
for (int n=0; n<nLists; n++) {
|
||||
Node node = getNode(n);
|
||||
String nodeName = node.getName();
|
||||
if (nodeName == null)
|
||||
continue;
|
||||
if (nodeName.endsWith(name) == true)
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,30 +1,30 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
/******************************************************************
|
||||
*
|
||||
* File: ParserException.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/27/02
|
||||
* - first revision.
|
||||
* 12/26/03
|
||||
* - Changed to a sub class of Exception instead of SAXException.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.xml;
|
||||
|
||||
public class ParserException extends Exception
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2002
|
||||
*
|
||||
* File: ParserException.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 11/27/02
|
||||
* - first revision.
|
||||
* 12/26/03
|
||||
* - Changed to a sub class of Exception instead of SAXException.
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.xml;
|
||||
|
||||
public class ParserException extends Exception
|
||||
{
|
||||
public ParserException(Exception e)
|
||||
public ParserException(Exception e)
|
||||
{
|
||||
super(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ParserException(String s)
|
||||
public ParserException(String s)
|
||||
{
|
||||
super(s);
|
||||
}
|
||||
|
@ -5,22 +5,23 @@
|
||||
* Copyright (C) Satoshi Konno 2002-2003
|
||||
*
|
||||
* File: XML.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/05/03
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 01/05/03
|
||||
* - first revision.
|
||||
* 12/15/03
|
||||
* - Terje Bakken
|
||||
* - Added escapeXMLChars()
|
||||
* - Added escapeXMLChars()
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
|
||||
package org.cybergarage.xml;
|
||||
|
||||
public class XML
|
||||
{
|
||||
public final static String CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
|
||||
public class XML
|
||||
{
|
||||
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";
|
||||
|
||||
////////////////////////////////////////////////
|
||||
@ -82,5 +83,5 @@ public class XML
|
||||
|
||||
return outStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,200 +1,200 @@
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2004
|
||||
*
|
||||
* Author: Markus Thurner (http://thoean.com)
|
||||
*
|
||||
* File: JaxpParser.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 06/15/04
|
||||
* - first revision.
|
||||
* 01/08/08
|
||||
* - Fixed parse() not to occur null exception when the NamedNodeMap is null on Android.
|
||||
* 02/08/08
|
||||
* - Change parse() to use Node::addValue() instead of the setValue().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.xml.parser;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.cybergarage.xml.Node;
|
||||
import org.cybergarage.xml.Parser;
|
||||
import org.cybergarage.xml.ParserException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
|
||||
public class JaxpParser extends Parser
|
||||
{
|
||||
|
||||
public JaxpParser()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// parse (Node)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode, int rank)
|
||||
{
|
||||
int domNodeType = domNode.getNodeType();
|
||||
// if (domNodeType != Node.ELEMENT_NODE)
|
||||
// return;
|
||||
|
||||
String domNodeName = domNode.getNodeName();
|
||||
String domNodeValue = domNode.getNodeValue();
|
||||
NamedNodeMap attrs = domNode.getAttributes();
|
||||
int arrrsLen = (attrs != null) ? attrs.getLength() : 0;
|
||||
|
||||
// Debug.message("[" + rank + "] ELEM : " + domNodeName + ", " + domNodeValue + ", type = " + domNodeType + ", attrs = " + arrrsLen);
|
||||
|
||||
if (domNodeType == org.w3c.dom.Node.TEXT_NODE) {
|
||||
// Change to use Node::addValue() instead of the setValue(). (2008/02/07)
|
||||
//parentNode.setValue(domNodeValue);
|
||||
parentNode.addValue(domNodeValue);
|
||||
return parentNode;
|
||||
}
|
||||
|
||||
if (domNodeType != org.w3c.dom.Node.ELEMENT_NODE)
|
||||
return parentNode;
|
||||
|
||||
org.cybergarage.xml.Node node = new org.cybergarage.xml.Node();
|
||||
node.setName(domNodeName);
|
||||
node.setValue(domNodeValue);
|
||||
|
||||
if (parentNode != null)
|
||||
parentNode.addNode(node);
|
||||
|
||||
NamedNodeMap attrMap = domNode.getAttributes();
|
||||
if (attrMap != null) {
|
||||
int attrLen = attrMap.getLength();
|
||||
//Debug.message("attrLen = " + attrLen);
|
||||
for (int n = 0; n<attrLen; n++) {
|
||||
org.w3c.dom.Node attr = attrMap.item(n);
|
||||
String attrName = attr.getNodeName();
|
||||
String attrValue = attr.getNodeValue();
|
||||
node.setAttribute(attrName, attrValue);
|
||||
}
|
||||
}
|
||||
|
||||
org.w3c.dom.Node child = domNode.getFirstChild();
|
||||
if(child==null){
|
||||
node.setValue("");
|
||||
return node;
|
||||
}
|
||||
do{
|
||||
parse(node, child, rank+1);
|
||||
child = child.getNextSibling();
|
||||
}while (child != null);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode)
|
||||
{
|
||||
return parse(parentNode, domNode, 0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.cybergarage.xml.Parser#parse(java.io.InputStream)
|
||||
*/
|
||||
public Node parse(InputStream inStream) throws ParserException
|
||||
{
|
||||
org.cybergarage.xml.Node root = null;
|
||||
|
||||
try {
|
||||
// https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setValidating(false);
|
||||
factory.setNamespaceAware(true);
|
||||
factory.setExpandEntityReferences(false);
|
||||
try {
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
} catch (ParserConfigurationException pce) {}
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
} catch (ParserConfigurationException pce) {}
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
} catch (ParserConfigurationException pce) {}
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
} catch (ParserConfigurationException pce) {}
|
||||
} catch (AbstractMethodError ame) {} // FreeBSD
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
builder.setEntityResolver(new BlankingResolver());
|
||||
InputSource inSrc = new InputSource(new NullFilterInputStream(inStream));
|
||||
Document doc = builder.parse(inSrc);
|
||||
|
||||
org.w3c.dom.Element docElem = doc.getDocumentElement();
|
||||
|
||||
if (docElem != null)
|
||||
root = parse(root, docElem);
|
||||
/*
|
||||
NodeList rootList = doc.getElementsByTagName("root");
|
||||
Debug.message("rootList = " + rootList.getLength());
|
||||
|
||||
if (0 < rootList.getLength())
|
||||
root = parse(root, rootList.item(0));
|
||||
*/
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ParserException(e);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* I2P -
|
||||
* Filter out nulls, hopefully to avoid
|
||||
* SAXParserException "Content not allowed in trailing section",
|
||||
* which is apparently caused by nulls.
|
||||
* Alternative is to remove all stuff between '>' and '<',
|
||||
* which isn't so hard if we assume no CDATA.
|
||||
*/
|
||||
private static class NullFilterInputStream extends FilterInputStream {
|
||||
|
||||
public NullFilterInputStream(InputStream is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int rv;
|
||||
while ((rv = super.read()) == 0) {
|
||||
// try again
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* I2P -
|
||||
* http://stackoverflow.com/questions/5883542/disable-xml-validation-based-on-external-dtd-xsd
|
||||
*/
|
||||
private static class BlankingResolver implements EntityResolver {
|
||||
private static final byte[] DUMMY = new byte[0];
|
||||
|
||||
public InputSource resolveEntity(String arg0, String arg1) {
|
||||
return new InputSource(new ByteArrayInputStream(DUMMY));
|
||||
}
|
||||
}
|
||||
}
|
||||
/******************************************************************
|
||||
*
|
||||
* CyberXML for Java
|
||||
*
|
||||
* Copyright (C) Satoshi Konno 2004
|
||||
*
|
||||
* Author: Markus Thurner (http://thoean.com)
|
||||
*
|
||||
* File: JaxpParser.java
|
||||
*
|
||||
* Revision;
|
||||
*
|
||||
* 06/15/04
|
||||
* - first revision.
|
||||
* 01/08/08
|
||||
* - Fixed parse() not to occur null exception when the NamedNodeMap is null on Android.
|
||||
* 02/08/08
|
||||
* - Change parse() to use Node::addValue() instead of the setValue().
|
||||
*
|
||||
******************************************************************/
|
||||
|
||||
package org.cybergarage.xml.parser;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.cybergarage.xml.Node;
|
||||
import org.cybergarage.xml.Parser;
|
||||
import org.cybergarage.xml.ParserException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
|
||||
public class JaxpParser extends Parser
|
||||
{
|
||||
|
||||
public JaxpParser()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// parse (Node)
|
||||
////////////////////////////////////////////////
|
||||
|
||||
public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode, int rank)
|
||||
{
|
||||
int domNodeType = domNode.getNodeType();
|
||||
// if (domNodeType != Node.ELEMENT_NODE)
|
||||
// return;
|
||||
|
||||
String domNodeName = domNode.getNodeName();
|
||||
String domNodeValue = domNode.getNodeValue();
|
||||
NamedNodeMap attrs = domNode.getAttributes();
|
||||
int arrrsLen = (attrs != null) ? attrs.getLength() : 0;
|
||||
|
||||
// Debug.message("[" + rank + "] ELEM : " + domNodeName + ", " + domNodeValue + ", type = " + domNodeType + ", attrs = " + arrrsLen);
|
||||
|
||||
if (domNodeType == org.w3c.dom.Node.TEXT_NODE) {
|
||||
// Change to use Node::addValue() instead of the setValue(). (2008/02/07)
|
||||
//parentNode.setValue(domNodeValue);
|
||||
parentNode.addValue(domNodeValue);
|
||||
return parentNode;
|
||||
}
|
||||
|
||||
if (domNodeType != org.w3c.dom.Node.ELEMENT_NODE)
|
||||
return parentNode;
|
||||
|
||||
org.cybergarage.xml.Node node = new org.cybergarage.xml.Node();
|
||||
node.setName(domNodeName);
|
||||
node.setValue(domNodeValue);
|
||||
|
||||
if (parentNode != null)
|
||||
parentNode.addNode(node);
|
||||
|
||||
NamedNodeMap attrMap = domNode.getAttributes();
|
||||
if (attrMap != null) {
|
||||
int attrLen = attrMap.getLength();
|
||||
//Debug.message("attrLen = " + attrLen);
|
||||
for (int n = 0; n<attrLen; n++) {
|
||||
org.w3c.dom.Node attr = attrMap.item(n);
|
||||
String attrName = attr.getNodeName();
|
||||
String attrValue = attr.getNodeValue();
|
||||
node.setAttribute(attrName, attrValue);
|
||||
}
|
||||
}
|
||||
|
||||
org.w3c.dom.Node child = domNode.getFirstChild();
|
||||
if(child==null){
|
||||
node.setValue("");
|
||||
return node;
|
||||
}
|
||||
do{
|
||||
parse(node, child, rank+1);
|
||||
child = child.getNextSibling();
|
||||
}while (child != null);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode)
|
||||
{
|
||||
return parse(parentNode, domNode, 0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.cybergarage.xml.Parser#parse(java.io.InputStream)
|
||||
*/
|
||||
public Node parse(InputStream inStream) throws ParserException
|
||||
{
|
||||
org.cybergarage.xml.Node root = null;
|
||||
|
||||
try {
|
||||
// https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setValidating(false);
|
||||
factory.setNamespaceAware(true);
|
||||
factory.setExpandEntityReferences(false);
|
||||
try {
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
} catch (ParserConfigurationException pce) {}
|
||||
try {
|
||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
} catch (ParserConfigurationException pce) {}
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
} catch (ParserConfigurationException pce) {}
|
||||
try {
|
||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
} catch (ParserConfigurationException pce) {}
|
||||
} catch (AbstractMethodError ame) {} // FreeBSD
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
builder.setEntityResolver(new BlankingResolver());
|
||||
InputSource inSrc = new InputSource(new NullFilterInputStream(inStream));
|
||||
Document doc = builder.parse(inSrc);
|
||||
|
||||
org.w3c.dom.Element docElem = doc.getDocumentElement();
|
||||
|
||||
if (docElem != null)
|
||||
root = parse(root, docElem);
|
||||
/*
|
||||
NodeList rootList = doc.getElementsByTagName("root");
|
||||
Debug.message("rootList = " + rootList.getLength());
|
||||
|
||||
if (0 < rootList.getLength())
|
||||
root = parse(root, rootList.item(0));
|
||||
*/
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ParserException(e);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* I2P -
|
||||
* Filter out nulls, hopefully to avoid
|
||||
* SAXParserException "Content not allowed in trailing section",
|
||||
* which is apparently caused by nulls.
|
||||
* Alternative is to remove all stuff between '>' and '<',
|
||||
* which isn't so hard if we assume no CDATA.
|
||||
*/
|
||||
private static class NullFilterInputStream extends FilterInputStream {
|
||||
|
||||
public NullFilterInputStream(InputStream is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int rv;
|
||||
while ((rv = super.read()) == 0) {
|
||||
// try again
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* I2P -
|
||||
* http://stackoverflow.com/questions/5883542/disable-xml-validation-based-on-external-dtd-xsd
|
||||
*/
|
||||
private static class BlankingResolver implements EntityResolver {
|
||||
private static final byte[] DUMMY = new byte[0];
|
||||
|
||||
public InputSource resolveEntity(String arg0, String arg1) {
|
||||
return new InputSource(new ByteArrayInputStream(DUMMY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user