forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p.zzz.upnp' (head 8719ae9a1473d748947733043f465a4589cc23d5)
to branch 'i2p.i2p' (head 5ae9785903c4b9452f4241758e8ddc1338e94574)
This commit is contained in:
@@ -1,165 +1,165 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberHTTP for Java
|
* CyberHTTP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File : Date.java
|
* File : Date.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/05/03
|
* 01/05/03
|
||||||
* - first revision
|
* - first revision
|
||||||
* 10/20/04
|
* 10/20/04
|
||||||
* - Theo Beisch <theo.beisch@gmx.de>
|
* - Theo Beisch <theo.beisch@gmx.de>
|
||||||
* - Fixed the following methods to use HOUR_OF_DAY instead of HOUR.
|
* - Fixed the following methods to use HOUR_OF_DAY instead of HOUR.
|
||||||
* getHour(), getDateString() getTimeString()
|
* getHour(), getDateString() getTimeString()
|
||||||
* - Fixed getInstance() to return GMT instance.
|
* - Fixed getInstance() to return GMT instance.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public class Date
|
public class Date
|
||||||
{
|
{
|
||||||
private Calendar cal;
|
private Calendar cal;
|
||||||
|
|
||||||
public Date(Calendar cal)
|
public Date(Calendar cal)
|
||||||
{
|
{
|
||||||
this.cal = cal;
|
this.cal = cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Calendar getCalendar()
|
public Calendar getCalendar()
|
||||||
{
|
{
|
||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Time
|
// Time
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public int getHour()
|
public int getHour()
|
||||||
{
|
{
|
||||||
// Thanks for Theo Beisch (10/20/04)
|
// Thanks for Theo Beisch (10/20/04)
|
||||||
return getCalendar().get(Calendar.HOUR_OF_DAY);
|
return getCalendar().get(Calendar.HOUR_OF_DAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinute()
|
public int getMinute()
|
||||||
{
|
{
|
||||||
return getCalendar().get(Calendar.MINUTE);
|
return getCalendar().get(Calendar.MINUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSecond()
|
public int getSecond()
|
||||||
{
|
{
|
||||||
return getCalendar().get(Calendar.SECOND);
|
return getCalendar().get(Calendar.SECOND);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// paint
|
// paint
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public final static Date getLocalInstance()
|
public final static Date getLocalInstance()
|
||||||
{
|
{
|
||||||
return new Date(Calendar.getInstance());
|
return new Date(Calendar.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static Date getInstance()
|
public final static Date getInstance()
|
||||||
{
|
{
|
||||||
// Thanks for Theo Beisch (10/20/04)
|
// Thanks for Theo Beisch (10/20/04)
|
||||||
return new Date(Calendar.getInstance(TimeZone.getTimeZone("GMT")));
|
return new Date(Calendar.getInstance(TimeZone.getTimeZone("GMT")));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// getDateString
|
// getDateString
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public final static String toDateString(int value)
|
public final static String toDateString(int value)
|
||||||
{
|
{
|
||||||
if (value < 10)
|
if (value < 10)
|
||||||
return "0" + Integer.toString(value);
|
return "0" + Integer.toString(value);
|
||||||
return Integer.toString(value);
|
return Integer.toString(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String MONTH_STRING[] = {
|
private final static String MONTH_STRING[] = {
|
||||||
"Jan",
|
"Jan",
|
||||||
"Feb",
|
"Feb",
|
||||||
"Mar",
|
"Mar",
|
||||||
"Apr",
|
"Apr",
|
||||||
"May",
|
"May",
|
||||||
"Jun",
|
"Jun",
|
||||||
"Jul",
|
"Jul",
|
||||||
"Aug",
|
"Aug",
|
||||||
"Sep",
|
"Sep",
|
||||||
"Oct",
|
"Oct",
|
||||||
"Nov",
|
"Nov",
|
||||||
"Dec",
|
"Dec",
|
||||||
};
|
};
|
||||||
|
|
||||||
public final static String toMonthString(int value)
|
public final static String toMonthString(int value)
|
||||||
{
|
{
|
||||||
value -= Calendar.JANUARY;
|
value -= Calendar.JANUARY;
|
||||||
if (0 <= value && value < 12)
|
if (0 <= value && value < 12)
|
||||||
return MONTH_STRING[value];
|
return MONTH_STRING[value];
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String WEEK_STRING[] = {
|
private final static String WEEK_STRING[] = {
|
||||||
"Sun",
|
"Sun",
|
||||||
"Mon",
|
"Mon",
|
||||||
"Tue",
|
"Tue",
|
||||||
"Wed",
|
"Wed",
|
||||||
"Thu",
|
"Thu",
|
||||||
"Fri",
|
"Fri",
|
||||||
"Sat",
|
"Sat",
|
||||||
};
|
};
|
||||||
|
|
||||||
public final static String toWeekString(int value)
|
public final static String toWeekString(int value)
|
||||||
{
|
{
|
||||||
value -= Calendar.SUNDAY;
|
value -= Calendar.SUNDAY;
|
||||||
if (0 <= value && value < 7)
|
if (0 <= value && value < 7)
|
||||||
return WEEK_STRING[value];
|
return WEEK_STRING[value];
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String toTimeString(int value)
|
public final static String toTimeString(int value)
|
||||||
{
|
{
|
||||||
String str = "";
|
String str = "";
|
||||||
if (value < 10)
|
if (value < 10)
|
||||||
str += "0";
|
str += "0";
|
||||||
str += Integer.toString(value);
|
str += Integer.toString(value);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDateString()
|
public String getDateString()
|
||||||
{
|
{
|
||||||
// Thanks for Theo Beisch (10/20/04)
|
// Thanks for Theo Beisch (10/20/04)
|
||||||
Calendar cal = getCalendar();
|
Calendar cal = getCalendar();
|
||||||
return
|
return
|
||||||
toWeekString(cal.get(Calendar.DAY_OF_WEEK)) +", " +
|
toWeekString(cal.get(Calendar.DAY_OF_WEEK)) +", " +
|
||||||
toTimeString(cal.get(Calendar.DATE)) + " " +
|
toTimeString(cal.get(Calendar.DATE)) + " " +
|
||||||
toMonthString(cal.get(Calendar.MONTH)) + " " +
|
toMonthString(cal.get(Calendar.MONTH)) + " " +
|
||||||
Integer.toString(cal.get(Calendar.YEAR)) + " " +
|
Integer.toString(cal.get(Calendar.YEAR)) + " " +
|
||||||
toTimeString(cal.get(Calendar.HOUR_OF_DAY)) + ":" +
|
toTimeString(cal.get(Calendar.HOUR_OF_DAY)) + ":" +
|
||||||
toTimeString(cal.get(Calendar.MINUTE)) + ":" +
|
toTimeString(cal.get(Calendar.MINUTE)) + ":" +
|
||||||
toTimeString(cal.get(Calendar.SECOND)) + " GMT";
|
toTimeString(cal.get(Calendar.SECOND)) + " GMT";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// getTimeString
|
// getTimeString
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public String getTimeString()
|
public String getTimeString()
|
||||||
{
|
{
|
||||||
// Thanks for Theo Beisch (10/20/04)
|
// Thanks for Theo Beisch (10/20/04)
|
||||||
Calendar cal = getCalendar();
|
Calendar cal = getCalendar();
|
||||||
return
|
return
|
||||||
toDateString(cal.get(Calendar.HOUR_OF_DAY)) +
|
toDateString(cal.get(Calendar.HOUR_OF_DAY)) +
|
||||||
(((cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") +
|
(((cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") +
|
||||||
toDateString(cal.get(Calendar.MINUTE));
|
toDateString(cal.get(Calendar.MINUTE));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,22 +1,22 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberHTTP for Java
|
* CyberHTTP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: HTML.java
|
* File: HTML.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/05/03
|
* 01/05/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
public class HTML
|
public class HTML
|
||||||
{
|
{
|
||||||
public static final String CONTENT_TYPE = "text/html; charset=\"utf-8\"";
|
public static final String CONTENT_TYPE = "text/html; charset=\"utf-8\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: HTTP.java
|
* File: HTTP.java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Revision:
|
||||||
*
|
*
|
||||||
* 11/18/02
|
* 11/18/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 08/30/03
|
* 08/30/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Problem : the method getPort should return the default http port 80 when a port is not specified
|
* - 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;
|
* - Added Range and MYNAME;
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
public class HTTP
|
public class HTTP
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constants
|
// Constants
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public static final String HOST = "HOST";
|
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_10 = "1.0";
|
||||||
public static final String VERSION_11 = "1.1";
|
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 CR = '\r';
|
||||||
public static final byte LF = '\n';
|
public static final byte LF = '\n';
|
||||||
public static final String TAB = "\t";
|
public static final String TAB = "\t";
|
||||||
|
|
||||||
public static final String SOAP_ACTION = "SOAPACTION";
|
public static final String SOAP_ACTION = "SOAPACTION";
|
||||||
|
|
||||||
public static final String M_SEARCH = "M-SEARCH";
|
public static final String M_SEARCH = "M-SEARCH";
|
||||||
public static final String NOTIFY = "NOTIFY";
|
public static final String NOTIFY = "NOTIFY";
|
||||||
public static final String POST = "POST";
|
public static final String POST = "POST";
|
||||||
public static final String GET = "GET";
|
public static final String GET = "GET";
|
||||||
public static final String HEAD = "HEAD";
|
public static final String HEAD = "HEAD";
|
||||||
public static final String SUBSCRIBE = "SUBSCRIBE";
|
public static final String SUBSCRIBE = "SUBSCRIBE";
|
||||||
public static final String UNSUBSCRIBE = "UNSUBSCRIBE";
|
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 CACHE_CONTROL = "Cache-Control";
|
||||||
public static final String NO_CACHE = "no-cache";
|
public static final String NO_CACHE = "no-cache";
|
||||||
public static final String MAX_AGE = "max-age";
|
public static final String MAX_AGE = "max-age";
|
||||||
public static final String CONNECTION = "Connection";
|
public static final String CONNECTION = "Connection";
|
||||||
public static final String CLOSE = "close";
|
public static final String CLOSE = "close";
|
||||||
public static final String KEEP_ALIVE = "Keep-Alive";
|
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 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 = "Content-Range";
|
||||||
public static final String CONTENT_RANGE_BYTES = "bytes";
|
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 RANGE = "Range";
|
||||||
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
|
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
|
||||||
public static final String CHUNKED = "Chunked";
|
public static final String CHUNKED = "Chunked";
|
||||||
public static final String LOCATION = "Location";
|
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 ST = "ST";
|
||||||
public static final String MX = "MX";
|
public static final String MX = "MX";
|
||||||
public static final String MAN = "MAN";
|
public static final String MAN = "MAN";
|
||||||
@@ -90,13 +89,16 @@ public class HTTP
|
|||||||
public static final String SEQ = "SEQ";
|
public static final String SEQ = "SEQ";
|
||||||
public final static String CALLBACK = "CALLBACK";
|
public final static String CALLBACK = "CALLBACK";
|
||||||
public final static String TIMEOUT = "TIMEOUT";
|
public final static String TIMEOUT = "TIMEOUT";
|
||||||
|
|
||||||
|
public final static String BOOTID_UPNP_ORG = "BOOTID.UPNP.ORG";
|
||||||
|
|
||||||
// Thanks for Brent Hills (10/20/04)
|
// Thanks for Brent Hills (10/20/04)
|
||||||
public final static String MYNAME = "MYNAME";
|
public final static String MYNAME = "MYNAME";
|
||||||
|
|
||||||
public static final String REQEST_LINE_DELIM = " ";
|
public static final String REQEST_LINE_DELIM = " ";
|
||||||
public static final String HEADER_LINE_DELIM = " :";
|
public static final String HEADER_LINE_DELIM = " :";
|
||||||
public static final String STATUS_LINE_DELIM = " ";
|
public static final String STATUS_LINE_DELIM = " ";
|
||||||
|
|
||||||
public static final int DEFAULT_PORT = 80;
|
public static final int DEFAULT_PORT = 80;
|
||||||
public static final int DEFAULT_CHUNK_SIZE = 512 * 1024;
|
public static final int DEFAULT_CHUNK_SIZE = 512 * 1024;
|
||||||
public static final int DEFAULT_TIMEOUT = 30;
|
public static final int DEFAULT_TIMEOUT = 30;
|
||||||
@@ -105,53 +107,53 @@ public class HTTP
|
|||||||
// URL
|
// URL
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public static final boolean isAbsoluteURL(String urlStr)
|
public static final boolean isAbsoluteURL(String urlStr)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
new URL(urlStr);
|
new URL(urlStr);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String getHost(String urlStr)
|
public static final String getHost(String urlStr)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
URL url = new URL(urlStr);
|
URL url = new URL(urlStr);
|
||||||
return url.getHost();
|
return url.getHost();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int getPort(String urlStr)
|
public static final int getPort(String urlStr)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
URL url = new URL(urlStr);
|
URL url = new URL(urlStr);
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (08/30/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (08/30/03)
|
||||||
int port = url.getPort();
|
int port = url.getPort();
|
||||||
if (port <= 0)
|
if (port <= 0)
|
||||||
port = DEFAULT_PORT;
|
port = DEFAULT_PORT;
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
return DEFAULT_PORT;
|
return DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String getRequestHostURL(String host, int port)
|
public static final String getRequestHostURL(String host, int port)
|
||||||
{
|
{
|
||||||
String reqHost = "http://" + host + ":" + port;
|
String reqHost = "http://" + host + ":" + port;
|
||||||
return reqHost;
|
return reqHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String toRelativeURL(String urlStr, boolean withParam)
|
public static final String toRelativeURL(String urlStr, boolean withParam)
|
||||||
{
|
{
|
||||||
String uri = urlStr;
|
String uri = urlStr;
|
||||||
if (isAbsoluteURL(urlStr) == false) {
|
if (isAbsoluteURL(urlStr) == false) {
|
||||||
if (0 < urlStr.length() && urlStr.charAt(0) != '/')
|
if (0 < urlStr.length() && urlStr.charAt(0) != '/')
|
||||||
uri = "/" + urlStr;
|
uri = "/" + urlStr;
|
||||||
}
|
}
|
||||||
@@ -171,28 +173,28 @@ public class HTTP
|
|||||||
}
|
}
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String toRelativeURL(String urlStr)
|
public static final String toRelativeURL(String urlStr)
|
||||||
{
|
{
|
||||||
return toRelativeURL(urlStr, true);
|
return toRelativeURL(urlStr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String getAbsoluteURL(String baseURLStr, String relURlStr)
|
public static final String getAbsoluteURL(String baseURLStr, String relURlStr)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
URL baseURL = new URL(baseURLStr);
|
URL baseURL = new URL(baseURLStr);
|
||||||
String url =
|
String url =
|
||||||
baseURL.getProtocol() + "://" +
|
baseURL.getProtocol() + "://" +
|
||||||
baseURL.getHost() + ":" +
|
baseURL.getHost() + ":" +
|
||||||
baseURL.getPort() +
|
baseURL.getPort() +
|
||||||
toRelativeURL(relURlStr);
|
toRelativeURL(relURlStr);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Chunk Size
|
// Chunk Size
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -209,5 +211,5 @@ public class HTTP
|
|||||||
return chunkSize;
|
return chunkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,37 +5,37 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: HTTPHeader.java
|
* File: HTTPHeader.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/19/02
|
* 11/19/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/26/04
|
* 05/26/04
|
||||||
* - Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (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().
|
* - Fixed getValue() to compare using String::equals() instead of String::startWidth().
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.LineNumberReader;
|
import java.io.LineNumberReader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.cybergarage.util.Debug;
|
import org.cybergarage.util.Debug;
|
||||||
|
|
||||||
public class HTTPHeader
|
public class HTTPHeader
|
||||||
{
|
{
|
||||||
private static int MAX_LENGTH = 1024;
|
private static int MAX_LENGTH = 1024;
|
||||||
private String name;
|
private String name;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public HTTPHeader(String name, String value)
|
public HTTPHeader(String name, String value)
|
||||||
{
|
{
|
||||||
setName(name);
|
setName(name);
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPHeader(String lineStr)
|
public HTTPHeader(String lineStr)
|
||||||
{
|
{
|
||||||
@@ -51,30 +51,30 @@ public class HTTPHeader
|
|||||||
setName(name.trim());
|
setName(name.trim());
|
||||||
setValue(value.trim());
|
setValue(value.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setName(String name)
|
public void setName(String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(String value)
|
public void setValue(String value)
|
||||||
{
|
{
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue()
|
public String getValue()
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasName()
|
public boolean hasName()
|
||||||
{
|
{
|
||||||
@@ -82,68 +82,68 @@ public class HTTPHeader
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// static methods
|
// static methods
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public final static String getValue(LineNumberReader reader, String name)
|
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)
|
|
||||||
{
|
{
|
||||||
/* 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);
|
StringReader strReader = new StringReader(data);
|
||||||
LineNumberReader lineReader = new LineNumberReader(strReader, Math.min(data.length(), MAX_LENGTH));
|
LineNumberReader lineReader = new LineNumberReader(strReader, Math.min(data.length(), MAX_LENGTH));
|
||||||
return getValue(lineReader, name);
|
return getValue(lineReader, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String getValue(byte[] data, String name)
|
public final static String getValue(byte[] data, String name)
|
||||||
{
|
{
|
||||||
return getValue(new String(data), name);
|
return getValue(new String(data), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static int getIntegerValue(String data, String name)
|
public final static int getIntegerValue(String data, String name)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(getValue(data, name));
|
return Integer.parseInt(getValue(data, name));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static int getIntegerValue(byte[] data, String name)
|
public final static int getIntegerValue(byte[] data, String name)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(getValue(data, name));
|
return Integer.parseInt(getValue(data, name));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -610,6 +610,20 @@ public class HTTPPacket
|
|||||||
return getHeaderValue(HTTP.CONTENT_TYPE);
|
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
|
// Charset
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002-2004
|
* Copyright (C) Satoshi Konno 2002-2004
|
||||||
*
|
*
|
||||||
* File: HTTPRequest.java
|
* File: HTTPRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/18/02
|
* 11/18/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/23/03
|
* 05/23/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Add a relative URL check to setURI().
|
* - Add a relative URL check to setURI().
|
||||||
@@ -51,9 +51,9 @@
|
|||||||
* - Fixed post() to output the chunk size as a hex string.
|
* - Fixed post() to output the chunk size as a hex string.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -73,17 +73,17 @@ import org.cybergarage.util.Debug;
|
|||||||
* @author Stefano "Kismet" Lenzi
|
* @author Stefano "Kismet" Lenzi
|
||||||
* @version 1.8
|
* @version 1.8
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class HTTPRequest extends HTTPPacket
|
public class HTTPRequest extends HTTPPacket
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public HTTPRequest()
|
public HTTPRequest()
|
||||||
{
|
{
|
||||||
setVersion(HTTP.VERSION_10);
|
setVersion(HTTP.VERSION_10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPRequest(InputStream in)
|
public HTTPRequest(InputStream in)
|
||||||
{
|
{
|
||||||
@@ -96,23 +96,23 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
setSocket(httpSock);
|
setSocket(httpSock);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Method
|
// Method
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String method = null;
|
private String method = null;
|
||||||
|
|
||||||
public void setMethod(String value)
|
public void setMethod(String value)
|
||||||
{
|
|
||||||
method = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMethod()
|
|
||||||
{
|
{
|
||||||
if (method != null)
|
method = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod()
|
||||||
|
{
|
||||||
|
if (method != null)
|
||||||
return method;
|
return method;
|
||||||
return getFirstLineToken(0);
|
return getFirstLineToken(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMethod(String method)
|
public boolean isMethod(String method)
|
||||||
{
|
{
|
||||||
@@ -121,16 +121,16 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
return false;
|
return false;
|
||||||
return headerMethod.equalsIgnoreCase(method);
|
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);
|
return isMethod(HTTP.POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHeadRequest()
|
public boolean isHeadRequest()
|
||||||
{
|
{
|
||||||
@@ -152,33 +152,33 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
return isMethod(HTTP.NOTIFY);
|
return isMethod(HTTP.NOTIFY);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// URI
|
// URI
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String uri = null;
|
private String uri = null;
|
||||||
|
|
||||||
public void setURI(String value, boolean isCheckRelativeURL)
|
public void setURI(String value, boolean isCheckRelativeURL)
|
||||||
{
|
{
|
||||||
uri = value;
|
uri = value;
|
||||||
if (isCheckRelativeURL == false)
|
if (isCheckRelativeURL == false)
|
||||||
return;
|
return;
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03)
|
||||||
uri = HTTP.toRelativeURL(uri);
|
uri = HTTP.toRelativeURL(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setURI(String value)
|
public void setURI(String value)
|
||||||
{
|
{
|
||||||
setURI(value, false);
|
setURI(value, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getURI()
|
public String getURI()
|
||||||
{
|
{
|
||||||
if (uri != null)
|
if (uri != null)
|
||||||
return uri;
|
return uri;
|
||||||
return getFirstLineToken(1);
|
return getFirstLineToken(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// URI Parameter
|
// URI Parameter
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -247,21 +247,21 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
return requestPort;
|
return requestPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Socket
|
// Socket
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private HTTPSocket httpSocket = null;
|
private HTTPSocket httpSocket = null;
|
||||||
|
|
||||||
public void setSocket(HTTPSocket value)
|
public void setSocket(HTTPSocket value)
|
||||||
{
|
{
|
||||||
httpSocket = value;
|
httpSocket = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPSocket getSocket()
|
public HTTPSocket getSocket()
|
||||||
{
|
{
|
||||||
return httpSocket;
|
return httpSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////// /////////////////////
|
/////////////////////////// /////////////////////
|
||||||
// local address/port
|
// local address/port
|
||||||
@@ -276,25 +276,25 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
{
|
{
|
||||||
return getSocket().getLocalPort();
|
return getSocket().getLocalPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// parseRequest
|
// parseRequest
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public boolean parseRequestLine(String lineStr)
|
public boolean parseRequestLine(String lineStr)
|
||||||
{
|
{
|
||||||
StringTokenizer st = new StringTokenizer(lineStr, HTTP.REQEST_LINE_DELIM);
|
StringTokenizer st = new StringTokenizer(lineStr, HTTP.REQEST_LINE_DELIM);
|
||||||
if (st.hasMoreTokens() == false)
|
if (st.hasMoreTokens() == false)
|
||||||
return false;
|
return false;
|
||||||
setMethod(st.nextToken());
|
setMethod(st.nextToken());
|
||||||
if (st.hasMoreTokens() == false)
|
if (st.hasMoreTokens() == false)
|
||||||
return false;
|
return false;
|
||||||
setURI(st.nextToken());
|
setURI(st.nextToken());
|
||||||
if (st.hasMoreTokens() == false)
|
if (st.hasMoreTokens() == false)
|
||||||
return false;
|
return false;
|
||||||
setVersion(st.nextToken());
|
setVersion(st.nextToken());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// First Line
|
// First Line
|
||||||
@@ -312,22 +312,22 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
return getMethod() + " " + getURI() + " " + getHTTPVersion() + HTTP.CRLF;
|
return getMethod() + " " + getURI() + " " + getHTTPVersion() + HTTP.CRLF;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// getHeader
|
// getHeader
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public String getHeader()
|
public String getHeader()
|
||||||
{
|
{
|
||||||
StringBuffer str = new StringBuffer();
|
StringBuffer str = new StringBuffer();
|
||||||
|
|
||||||
str.append(getFirstLineString());
|
str.append(getFirstLineString());
|
||||||
|
|
||||||
String headerString = getHeaderString();
|
String headerString = getHeaderString();
|
||||||
str.append(headerString);
|
str.append(headerString);
|
||||||
|
|
||||||
return str.toString();
|
return str.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// isKeepAlive
|
// isKeepAlive
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -354,9 +354,9 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
return super.read(getSocket());
|
return super.read(getSocket());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// POST (Response)
|
// POST (Response)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public boolean post(HTTPResponse httpRes)
|
public boolean post(HTTPResponse httpRes)
|
||||||
{
|
{
|
||||||
@@ -381,15 +381,15 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
return httpSock.post(httpRes, offset, length, isHeadRequest());
|
return httpSock.post(httpRes, offset, length, isHeadRequest());
|
||||||
//httpSock.close();
|
//httpSock.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// POST (Request)
|
// POST (Request)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Socket postSocket = null;
|
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();
|
HTTPResponse httpRes = new HTTPResponse();
|
||||||
|
|
||||||
setHost(host);
|
setHost(host);
|
||||||
@@ -418,9 +418,9 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
postSocket.connect(sa, 3000);
|
postSocket.connect(sa, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
out = postSocket.getOutputStream();
|
out = postSocket.getOutputStream();
|
||||||
PrintStream pout = new PrintStream(out);
|
PrintStream pout = new PrintStream(out);
|
||||||
pout.print(getHeader());
|
pout.print(getHeader());
|
||||||
pout.print(HTTP.CRLF);
|
pout.print(HTTP.CRLF);
|
||||||
|
|
||||||
boolean isChunkedRequest = isChunked();
|
boolean isChunkedRequest = isChunked();
|
||||||
@@ -429,7 +429,7 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
int contentLength = 0;
|
int contentLength = 0;
|
||||||
if (content != null)
|
if (content != null)
|
||||||
contentLength = content.length();
|
contentLength = content.length();
|
||||||
|
|
||||||
if (0 < contentLength) {
|
if (0 < contentLength) {
|
||||||
if (isChunkedRequest == true) {
|
if (isChunkedRequest == true) {
|
||||||
// Thanks for Lee Peik Feng <pflee@users.sourceforge.net> (07/07/05)
|
// 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.print(HTTP.CRLF);
|
||||||
}
|
}
|
||||||
|
|
||||||
pout.flush();
|
pout.flush();
|
||||||
|
|
||||||
in = postSocket.getInputStream();
|
in = postSocket.getInputStream();
|
||||||
httpRes.set(in, isHeaderRequest);
|
httpRes.set(in, isHeaderRequest);
|
||||||
@@ -477,7 +477,7 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
}
|
}
|
||||||
|
|
||||||
return httpRes;
|
return httpRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPResponse post(String host, int port)
|
public HTTPResponse post(String host, int port)
|
||||||
{
|
{
|
||||||
@@ -516,20 +516,20 @@ public class HTTPRequest extends HTTPPacket
|
|||||||
return returnResponse(HTTPStatus.BAD_REQUEST);
|
return returnResponse(HTTPStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// toString
|
// toString
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuffer str = new StringBuffer();
|
StringBuffer str = new StringBuffer();
|
||||||
|
|
||||||
str.append(getHeader());
|
str.append(getHeader());
|
||||||
str.append(HTTP.CRLF);
|
str.append(HTTP.CRLF);
|
||||||
str.append(getContentString());
|
str.append(getContentString());
|
||||||
|
|
||||||
return str.toString();
|
return str.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print()
|
public void print()
|
||||||
{
|
{
|
||||||
|
@@ -5,17 +5,17 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: HTTPRequestListener.java
|
* File: HTTPRequestListener.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 12/13/02
|
* 12/13/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
public interface HTTPRequestListener
|
public interface HTTPRequestListener
|
||||||
{
|
{
|
||||||
public void httpRequestRecieved(HTTPRequest httpReq);
|
public void httpRequestRecieved(HTTPRequest httpReq);
|
||||||
}
|
}
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: HTTPResponse.java
|
* File: HTTPResponse.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/18/02
|
* 11/18/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 10/22/03
|
* 10/22/03
|
||||||
* - Changed to initialize a content length header.
|
* - Changed to initialize a content length header.
|
||||||
* 10/22/04
|
* 10/22/04
|
||||||
@@ -17,24 +17,24 @@
|
|||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import org.cybergarage.util.Debug;
|
import org.cybergarage.util.Debug;
|
||||||
|
|
||||||
public class HTTPResponse extends HTTPPacket
|
public class HTTPResponse extends HTTPPacket
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public HTTPResponse()
|
public HTTPResponse()
|
||||||
{
|
{
|
||||||
setVersion(HTTP.VERSION_11);
|
setVersion(HTTP.VERSION_11);
|
||||||
setContentType(HTML.CONTENT_TYPE);
|
setContentType(HTML.CONTENT_TYPE);
|
||||||
setServer(HTTPServer.getName());
|
setServer(HTTPServer.getName());
|
||||||
setContent("");
|
setContent("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPResponse(HTTPResponse httpRes)
|
public HTTPResponse(HTTPResponse httpRes)
|
||||||
{
|
{
|
||||||
@@ -50,25 +50,25 @@ public class HTTPResponse extends HTTPPacket
|
|||||||
{
|
{
|
||||||
this(httpSock.getInputStream());
|
this(httpSock.getInputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Status Line
|
// Status Line
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private int statusCode = 0;
|
private int statusCode = 0;
|
||||||
|
|
||||||
public void setStatusCode(int code)
|
public void setStatusCode(int code)
|
||||||
{
|
{
|
||||||
statusCode = code;
|
statusCode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStatusCode()
|
public int getStatusCode()
|
||||||
{
|
{
|
||||||
if (statusCode != 0)
|
if (statusCode != 0)
|
||||||
return statusCode;
|
return statusCode;
|
||||||
HTTPStatus httpStatus = new HTTPStatus(getFirstLine());
|
HTTPStatus httpStatus = new HTTPStatus(getFirstLine());
|
||||||
return httpStatus.getStatusCode();
|
return httpStatus.getStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuccessful()
|
public boolean isSuccessful()
|
||||||
{
|
{
|
||||||
@@ -79,20 +79,20 @@ public class HTTPResponse extends HTTPPacket
|
|||||||
{
|
{
|
||||||
return "HTTP/" + getVersion() + " " + getStatusCode() + " " + HTTPStatus.code2String(statusCode) + HTTP.CRLF;
|
return "HTTP/" + getVersion() + " " + getStatusCode() + " " + HTTPStatus.code2String(statusCode) + HTTP.CRLF;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// getHeader
|
// getHeader
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public String getHeader()
|
public String getHeader()
|
||||||
{
|
{
|
||||||
StringBuffer str = new StringBuffer();
|
StringBuffer str = new StringBuffer();
|
||||||
|
|
||||||
str.append(getStatusLineString());
|
str.append(getStatusLineString());
|
||||||
str.append(getHeaderString());
|
str.append(getHeaderString());
|
||||||
|
|
||||||
return str.toString();
|
return str.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// toString
|
// toString
|
||||||
|
@@ -1,54 +1,54 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberHTTP for Java
|
* CyberHTTP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: HTTPServerThread.java
|
* File: HTTPServerThread.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 10/10/03
|
* 10/10/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
public class HTTPServerThread extends Thread
|
public class HTTPServerThread extends Thread
|
||||||
{
|
{
|
||||||
private HTTPServer httpServer;
|
private HTTPServer httpServer;
|
||||||
private Socket sock;
|
private Socket sock;
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public HTTPServerThread(HTTPServer httpServer, Socket sock)
|
public HTTPServerThread(HTTPServer httpServer, Socket sock)
|
||||||
{
|
{
|
||||||
super("Cyber.HTTPServerThread");
|
super("Cyber.HTTPServerThread");
|
||||||
this.httpServer = httpServer;
|
this.httpServer = httpServer;
|
||||||
this.sock = sock;
|
this.sock = sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// run
|
// run
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
HTTPSocket httpSock = new HTTPSocket(sock);
|
HTTPSocket httpSock = new HTTPSocket(sock);
|
||||||
if (httpSock.open() == false)
|
if (httpSock.open() == false)
|
||||||
return;
|
return;
|
||||||
HTTPRequest httpReq = new HTTPRequest();
|
HTTPRequest httpReq = new HTTPRequest();
|
||||||
httpReq.setSocket(httpSock);
|
httpReq.setSocket(httpSock);
|
||||||
while (httpReq.read() == true) {
|
while (httpReq.read() == true) {
|
||||||
httpServer.performRequestListener(httpReq);
|
httpServer.performRequestListener(httpReq);
|
||||||
if (httpReq.isKeepAlive() == false)
|
if (httpReq.isKeepAlive() == false)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
httpSock.close();
|
httpSock.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: HTTPStatus.java
|
* File: HTTPStatus.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 12/17/02
|
* 12/17/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 09/03/03
|
* 09/03/03
|
||||||
* - Added CONTINUE_STATUS.
|
* - Added CONTINUE_STATUS.
|
||||||
* 10/20/04
|
* 10/20/04
|
||||||
@@ -22,105 +22,105 @@
|
|||||||
* - Fixed set() to read multi words of the response sring such as Not Found.
|
* - Fixed set() to read multi words of the response sring such as Not Found.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import org.cybergarage.util.Debug;
|
import org.cybergarage.util.Debug;
|
||||||
|
|
||||||
public class HTTPStatus
|
public class HTTPStatus
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Code
|
// Code
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public static final int CONTINUE = 100;
|
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)
|
// Thanks for Brent Hills (10/20/04)
|
||||||
public static final int PARTIAL_CONTENT = 206;
|
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 NOT_FOUND = 404;
|
||||||
public static final int PRECONDITION_FAILED = 412;
|
public static final int PRECONDITION_FAILED = 412;
|
||||||
// Thanks for Brent Hills (10/20/04)
|
// Thanks for Brent Hills (10/20/04)
|
||||||
public static final int INVALID_RANGE = 416;
|
public static final int INVALID_RANGE = 416;
|
||||||
public static final int INTERNAL_SERVER_ERROR = 500;
|
public static final int INTERNAL_SERVER_ERROR = 500;
|
||||||
|
|
||||||
public static final String code2String(int code)
|
public static final String code2String(int code)
|
||||||
{
|
{
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case CONTINUE: return "Continue";
|
case CONTINUE: return "Continue";
|
||||||
case OK: return "OK";
|
case OK: return "OK";
|
||||||
case PARTIAL_CONTENT: return "Partial Content";
|
case PARTIAL_CONTENT: return "Partial Content";
|
||||||
case BAD_REQUEST: return "Bad Request";
|
case BAD_REQUEST: return "Bad Request";
|
||||||
case NOT_FOUND: return "Not Found";
|
case NOT_FOUND: return "Not Found";
|
||||||
case PRECONDITION_FAILED: return "Precondition Failed";
|
case PRECONDITION_FAILED: return "Precondition Failed";
|
||||||
case INVALID_RANGE: return "Invalid Range";
|
case INVALID_RANGE: return "Invalid Range";
|
||||||
case INTERNAL_SERVER_ERROR: return "Internal Server Error";
|
case INTERNAL_SERVER_ERROR: return "Internal Server Error";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public HTTPStatus()
|
public HTTPStatus()
|
||||||
{
|
{
|
||||||
setVersion("");
|
setVersion("");
|
||||||
setStatusCode(0);
|
setStatusCode(0);
|
||||||
setReasonPhrase("");
|
setReasonPhrase("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPStatus(String ver, int code, String reason)
|
public HTTPStatus(String ver, int code, String reason)
|
||||||
{
|
{
|
||||||
setVersion(ver);
|
setVersion(ver);
|
||||||
setStatusCode(code);
|
setStatusCode(code);
|
||||||
setReasonPhrase(reason);
|
setReasonPhrase(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPStatus(String lineStr)
|
public HTTPStatus(String lineStr)
|
||||||
{
|
{
|
||||||
set(lineStr);
|
set(lineStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String version = "";
|
private String version = "";
|
||||||
private int statusCode = 0;
|
private int statusCode = 0;
|
||||||
private String reasonPhrase = "";
|
private String reasonPhrase = "";
|
||||||
|
|
||||||
public void setVersion(String value)
|
public void setVersion(String value)
|
||||||
{
|
{
|
||||||
version = value;
|
version = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatusCode(int value)
|
public void setStatusCode(int value)
|
||||||
{
|
{
|
||||||
statusCode = value;
|
statusCode = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReasonPhrase(String value)
|
public void setReasonPhrase(String value)
|
||||||
{
|
{
|
||||||
reasonPhrase = value;
|
reasonPhrase = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion()
|
public String getVersion()
|
||||||
{
|
{
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStatusCode()
|
public int getStatusCode()
|
||||||
{
|
{
|
||||||
return statusCode;
|
return statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReasonPhrase()
|
public String getReasonPhrase()
|
||||||
{
|
{
|
||||||
return reasonPhrase;
|
return reasonPhrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Status
|
// Status
|
||||||
|
@@ -1,61 +1,61 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberHTTP for Java
|
* CyberHTTP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2004
|
* Copyright (C) Satoshi Konno 2002-2004
|
||||||
*
|
*
|
||||||
* File: Parameter.java
|
* File: Parameter.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 02/01/04
|
* 02/01/04
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
public class Parameter
|
public class Parameter
|
||||||
{
|
{
|
||||||
private String name = new String();
|
private String name = new String();
|
||||||
private String value = new String();
|
private String value = new String();
|
||||||
|
|
||||||
public Parameter()
|
public Parameter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Parameter(String name, String value)
|
public Parameter(String name, String value)
|
||||||
{
|
{
|
||||||
setName(name);
|
setName(name);
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// name
|
// name
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setName(String name)
|
public void setName(String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// value
|
// value
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setValue(String value)
|
public void setValue(String value)
|
||||||
{
|
{
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue()
|
public String getValue()
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,58 +1,58 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberHTTP for Java
|
* CyberHTTP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2004
|
* Copyright (C) Satoshi Konno 2002-2004
|
||||||
*
|
*
|
||||||
* File: ParameterList.java
|
* File: ParameterList.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 02/01/04
|
* 02/01/04
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.http;
|
package org.cybergarage.http;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
public class ParameterList extends Vector<Parameter>
|
public class ParameterList extends Vector<Parameter>
|
||||||
{
|
{
|
||||||
public ParameterList()
|
public ParameterList()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Parameter at(int n)
|
public Parameter at(int n)
|
||||||
{
|
{
|
||||||
return (Parameter)get(n);
|
return (Parameter)get(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Parameter getParameter(int n)
|
public Parameter getParameter(int n)
|
||||||
{
|
{
|
||||||
return (Parameter)get(n);
|
return (Parameter)get(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Parameter getParameter(String name)
|
public Parameter getParameter(String name)
|
||||||
{
|
{
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int nLists = size();
|
int nLists = size();
|
||||||
for (int n=0; n<nLists; n++) {
|
for (int n=0; n<nLists; n++) {
|
||||||
Parameter param = at(n);
|
Parameter param = at(n);
|
||||||
if (name.compareTo(param.getName()) == 0)
|
if (name.compareTo(param.getName()) == 0)
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue(String name)
|
public String getValue(String name)
|
||||||
{
|
{
|
||||||
Parameter param = getParameter(name);
|
Parameter param = getParameter(name);
|
||||||
if (param == null)
|
if (param == null)
|
||||||
return "";
|
return "";
|
||||||
return param.getValue();
|
return param.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: HostInterface.java
|
* File: HostInterface.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 05/12/03
|
* 05/12/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/13/03
|
* 05/13/03
|
||||||
* - Added support for IPv6 and loopback address.
|
* - Added support for IPv6 and loopback address.
|
||||||
* 02/15/04
|
* 02/15/04
|
||||||
@@ -22,9 +22,9 @@
|
|||||||
* - Changed isUseAddress() to isUsableAddress().
|
* - Changed isUseAddress() to isUsableAddress().
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.net;
|
package org.cybergarage.net;
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@@ -35,9 +35,9 @@ import java.util.Enumeration;
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.cybergarage.util.Debug;
|
import org.cybergarage.util.Debug;
|
||||||
|
|
||||||
public class HostInterface
|
public class HostInterface
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constants
|
// Constants
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
@@ -5,45 +5,45 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SOAP.java
|
* File: SOAP.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 12/11/02
|
* 12/11/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.soap;
|
package org.cybergarage.soap;
|
||||||
|
|
||||||
import org.cybergarage.xml.Node;
|
import org.cybergarage.xml.Node;
|
||||||
import org.cybergarage.xml.Parser;
|
import org.cybergarage.xml.Parser;
|
||||||
|
|
||||||
public class SOAP
|
public class SOAP
|
||||||
{
|
{
|
||||||
public static final String ENVELOPE = "Envelope";
|
public static final String ENVELOPE = "Envelope";
|
||||||
public static final String BODY = "Body";
|
public static final String BODY = "Body";
|
||||||
public static final String RESPONSE = "Response";
|
public static final String RESPONSE = "Response";
|
||||||
public static final String FAULT = "Fault";
|
public static final String FAULT = "Fault";
|
||||||
public static final String FAULT_CODE = "faultcode";
|
public static final String FAULT_CODE = "faultcode";
|
||||||
public static final String FAULT_STRING = "faultstring";
|
public static final String FAULT_STRING = "faultstring";
|
||||||
public static final String FAULTACTOR = "faultactor";
|
public static final String FAULTACTOR = "faultactor";
|
||||||
public static final String DETAIL = "detail";
|
public static final String DETAIL = "detail";
|
||||||
|
|
||||||
public static final String RESULTSTATUS = "ResultStatus";
|
public static final String RESULTSTATUS = "ResultStatus";
|
||||||
public static final String UPNP_ERROR = "UPnPError";
|
public static final String UPNP_ERROR = "UPnPError";
|
||||||
public static final String ERROR_CODE = "errorCode";
|
public static final String ERROR_CODE = "errorCode";
|
||||||
public static final String ERROR_DESCRIPTION = "errorDescription";
|
public static final String ERROR_DESCRIPTION = "errorDescription";
|
||||||
|
|
||||||
//public static final String XMLNS = "SOAP-ENV";
|
//public static final String XMLNS = "SOAP-ENV";
|
||||||
public static final String XMLNS = "s";
|
public static final String XMLNS = "s";
|
||||||
public static final String METHODNS = "u";
|
public static final String METHODNS = "u";
|
||||||
public static final String DELIM = ":";
|
public static final String DELIM = ":";
|
||||||
|
|
||||||
public static final String XMLNS_URL = "http://schemas.xmlsoap.org/soap/envelope/";
|
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 ENCSTYLE_URL = "http://schemas.xmlsoap.org/soap/encoding/";
|
||||||
|
|
||||||
public static final String CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
|
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 VERSION_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// createEnvelopeBodyNode
|
// createEnvelopeBodyNode
|
||||||
@@ -78,5 +78,5 @@ public class SOAP
|
|||||||
{
|
{
|
||||||
return xmlParser;
|
return xmlParser;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SOAPRequest.java
|
* File: SOAPRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 12/11/02
|
* 12/11/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 02/13/04
|
* 02/13/04
|
||||||
* - Ralf G. R. Bergs <Ralf@Ber.gs>, Inma Marin Lopez <inma@dif.um.es>.
|
* - Ralf G. R. Bergs <Ralf@Ber.gs>, Inma Marin Lopez <inma@dif.um.es>.
|
||||||
* - Added XML header, <?xml version=\"1.0\"?> to setContent().
|
* - 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().
|
* - 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 java.io.ByteArrayInputStream;
|
||||||
|
|
||||||
import org.cybergarage.http.HTTP;
|
import org.cybergarage.http.HTTP;
|
||||||
@@ -29,20 +29,20 @@ import org.cybergarage.util.Debug;
|
|||||||
import org.cybergarage.xml.Node;
|
import org.cybergarage.xml.Node;
|
||||||
import org.cybergarage.xml.Parser;
|
import org.cybergarage.xml.Parser;
|
||||||
import org.cybergarage.xml.ParserException;
|
import org.cybergarage.xml.ParserException;
|
||||||
|
|
||||||
public class SOAPRequest extends HTTPRequest
|
public class SOAPRequest extends HTTPRequest
|
||||||
{
|
{
|
||||||
private final static String SOAPACTION = "SOAPACTION";
|
private final static String SOAPACTION = "SOAPACTION";
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SOAPRequest()
|
public SOAPRequest()
|
||||||
{
|
{
|
||||||
setContentType(SOAP.CONTENT_TYPE);
|
setContentType(SOAP.CONTENT_TYPE);
|
||||||
setMethod(HTTP.POST);
|
setMethod(HTTP.POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SOAPRequest(HTTPRequest httpReq)
|
public SOAPRequest(HTTPRequest httpReq)
|
||||||
{
|
{
|
||||||
@@ -75,33 +75,33 @@ public class SOAPRequest extends HTTPRequest
|
|||||||
return false;
|
return false;
|
||||||
return soapAction.equals(value);
|
return soapAction.equals(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// post
|
// post
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SOAPResponse postMessage(String host, int port)
|
public SOAPResponse postMessage(String host, int port)
|
||||||
{
|
{
|
||||||
HTTPResponse httpRes = post(host, port);
|
HTTPResponse httpRes = post(host, port);
|
||||||
|
|
||||||
SOAPResponse soapRes = new SOAPResponse(httpRes);
|
SOAPResponse soapRes = new SOAPResponse(httpRes);
|
||||||
|
|
||||||
byte content[] = soapRes.getContent();
|
byte content[] = soapRes.getContent();
|
||||||
if (content.length <= 0)
|
if (content.length <= 0)
|
||||||
return soapRes;
|
return soapRes;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ByteArrayInputStream byteIn = new ByteArrayInputStream(content);
|
ByteArrayInputStream byteIn = new ByteArrayInputStream(content);
|
||||||
Parser xmlParser = SOAP.getXMLParser();
|
Parser xmlParser = SOAP.getXMLParser();
|
||||||
Node rootNode = xmlParser.parse(byteIn);
|
Node rootNode = xmlParser.parse(byteIn);
|
||||||
soapRes.setEnvelopeNode(rootNode);
|
soapRes.setEnvelopeNode(rootNode);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Debug.warning(e);
|
Debug.warning(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return soapRes;
|
return soapRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Node
|
// Node
|
||||||
|
@@ -34,21 +34,21 @@ public class SOAPResponse extends HTTPResponse
|
|||||||
public SOAPResponse()
|
public SOAPResponse()
|
||||||
{
|
{
|
||||||
setRootNode(SOAP.createEnvelopeBodyNode());
|
setRootNode(SOAP.createEnvelopeBodyNode());
|
||||||
setContentType(XML.CONTENT_TYPE);
|
setContentType(XML.DEFAULT_CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SOAPResponse(HTTPResponse httpRes)
|
public SOAPResponse(HTTPResponse httpRes)
|
||||||
{
|
{
|
||||||
super(httpRes);
|
super(httpRes);
|
||||||
setRootNode(SOAP.createEnvelopeBodyNode());
|
setRootNode(SOAP.createEnvelopeBodyNode());
|
||||||
setContentType(XML.CONTENT_TYPE);
|
setContentType(XML.DEFAULT_CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SOAPResponse(SOAPResponse soapRes)
|
public SOAPResponse(SOAPResponse soapRes)
|
||||||
{
|
{
|
||||||
super(soapRes);
|
super(soapRes);
|
||||||
setEnvelopeNode(soapRes.getEnvelopeNode());
|
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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/05/02
|
* File: ActionList.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: Icon.java
|
* File: Icon.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/28/02
|
* 11/28/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 04/12/06
|
* 04/12/06
|
||||||
* - Added setUserData() and getUserData() to set a user original data object.
|
* - Added setUserData() and getUserData() to set a user original data object.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp;
|
package org.cybergarage.upnp;
|
||||||
|
|
||||||
import org.cybergarage.xml.Node;
|
import org.cybergarage.xml.Node;
|
||||||
|
|
||||||
public class Icon
|
public class Icon
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constants
|
// Constants
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public final static String ELEM_NAME = "icon";
|
public final static String ELEM_NAME = "icon";
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node iconNode;
|
private Node iconNode;
|
||||||
|
|
||||||
public Node getIconNode()
|
public Node getIconNode()
|
||||||
{
|
{
|
||||||
return iconNode;
|
return iconNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public Icon(Node node)
|
public Icon(Node node)
|
||||||
{
|
{
|
||||||
iconNode = node;
|
iconNode = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
public Icon() {
|
||||||
// isIconNode
|
this(new Node(ELEM_NAME));
|
||||||
////////////////////////////////////////////////
|
}
|
||||||
|
|
||||||
public static boolean isIconNode(Node node)
|
////////////////////////////////////////////////
|
||||||
{
|
// isIconNode
|
||||||
return Icon.ELEM_NAME.equals(node.getName());
|
////////////////////////////////////////////////
|
||||||
}
|
|
||||||
|
public static boolean isIconNode(Node node)
|
||||||
////////////////////////////////////////////////
|
{
|
||||||
// mimeType
|
return Icon.ELEM_NAME.equals(node.getName());
|
||||||
////////////////////////////////////////////////
|
}
|
||||||
|
|
||||||
private final static String MIME_TYPE = "mimeType";
|
////////////////////////////////////////////////
|
||||||
|
// mimeType
|
||||||
public void setMimeType(String value)
|
////////////////////////////////////////////////
|
||||||
{
|
|
||||||
getIconNode().setNode(MIME_TYPE, value);
|
private final static String MIME_TYPE = "mimeType";
|
||||||
}
|
|
||||||
|
public void setMimeType(String value)
|
||||||
public String getMimeType()
|
{
|
||||||
{
|
getIconNode().setNode(MIME_TYPE, value);
|
||||||
return getIconNode().getNodeValue(MIME_TYPE);
|
}
|
||||||
}
|
|
||||||
|
public String getMimeType()
|
||||||
////////////////////////////////////////////////
|
{
|
||||||
// width
|
return getIconNode().getNodeValue(MIME_TYPE);
|
||||||
////////////////////////////////////////////////
|
}
|
||||||
|
|
||||||
private final static String WIDTH = "width";
|
public boolean hasMimeType()
|
||||||
|
{
|
||||||
public void setWidth(String value)
|
String iconMimeType = getMimeType();
|
||||||
{
|
if (iconMimeType == null)
|
||||||
getIconNode().setNode(WIDTH, value);
|
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)
|
public void setWidth(int value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -91,26 +103,26 @@ public class Icon
|
|||||||
catch (Exception e) {};
|
catch (Exception e) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth()
|
public int getWidth()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(getIconNode().getNodeValue(WIDTH));
|
return Integer.parseInt(getIconNode().getNodeValue(WIDTH));
|
||||||
}
|
}
|
||||||
catch (Exception e) {};
|
catch (Exception e) {};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// height
|
// height
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private final static String HEIGHT = "height";
|
private final static String HEIGHT = "height";
|
||||||
|
|
||||||
public void setHeight(String value)
|
public void setHeight(String value)
|
||||||
{
|
{
|
||||||
getIconNode().setNode(HEIGHT, value);
|
getIconNode().setNode(HEIGHT, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHeight(int value)
|
public void setHeight(int value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -119,47 +131,77 @@ public class Icon
|
|||||||
catch (Exception e) {};
|
catch (Exception e) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight()
|
public int getHeight()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(getIconNode().getNodeValue(HEIGHT));
|
return Integer.parseInt(getIconNode().getNodeValue(HEIGHT));
|
||||||
}
|
}
|
||||||
catch (Exception e) {};
|
catch (Exception e) {};
|
||||||
return 0;
|
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
|
// userData
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -175,4 +217,25 @@ public class Icon
|
|||||||
{
|
{
|
||||||
return userData;
|
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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/04/02
|
* File: IconList.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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;
|
package org.cybergarage.upnp;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stefano "Kismet" Lenzi - kismet-sl@users.sourceforge.net <br>
|
* @author Stefano "Kismet" Lenzi - kismet-sl@users.sourceforge.net <br>
|
||||||
* Copyright (c) 2005
|
* Copyright (c) 2005
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface RootDescription {
|
public interface RootDescription {
|
||||||
|
|
||||||
public final String ROOT_ELEMENT = "root";
|
public final String ROOT_ELEMENT = "root";
|
||||||
public final String ROOT_ELEMENT_NAMESPACE = "urn:schemas-upnp-org:device-1-0";
|
public final String ROOT_ELEMENT_NAMESPACE = "urn:schemas-upnp-org:device-1-0";
|
||||||
|
|
||||||
|
|
||||||
public final String SPECVERSION_ELEMENT = "specVersion";
|
public final String SPECVERSION_ELEMENT = "specVersion";
|
||||||
public final String MAJOR_ELEMENT = "major";
|
public final String MAJOR_ELEMENT = "major";
|
||||||
public final String MINOR_ELEMENT = "minor";
|
public final String MINOR_ELEMENT = "minor";
|
||||||
public final String SERVICE_LIST_ELEMENT = "serviceList";
|
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="scpd";
|
||||||
public static final String SCPD_ROOTNODE_NS="urn:schemas-upnp-org:service-1-0";
|
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 SPEC_VERSION="specVersion";
|
||||||
public static final String MAJOR="major";
|
public static final String MAJOR="major";
|
||||||
public static final String MAJOR_VALUE="1";
|
public static final String MAJOR_VALUE="1";
|
||||||
@@ -142,8 +142,8 @@ public class Service
|
|||||||
sp.addNode(m);
|
sp.addNode(m);
|
||||||
|
|
||||||
//Node scpd = new Node(SCPD_ROOTNODE,SCPD_ROOTNODE_NS); wrong!
|
//Node scpd = new Node(SCPD_ROOTNODE,SCPD_ROOTNODE_NS); wrong!
|
||||||
Node scpd = new Node(SCPD_ROOTNODE); // better (twa)
|
Node scpd = new Node(SCPD_ROOTNODE);
|
||||||
scpd.addAttribute("xmlns",SCPD_ROOTNODE_NS); // better (twa)
|
scpd.addAttribute("xmlns",SCPD_ROOTNODE_NS);
|
||||||
scpd.addNode(sp);
|
scpd.addNode(sp);
|
||||||
getServiceData().setSCPDNode(scpd);
|
getServiceData().setSCPDNode(scpd);
|
||||||
}
|
}
|
||||||
@@ -241,6 +241,31 @@ public class Service
|
|||||||
return getServiceNode().getNodeValue(SERVICE_ID);
|
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
|
// isURL
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -340,6 +365,7 @@ public class Service
|
|||||||
catch (ParserException e) {
|
catch (ParserException e) {
|
||||||
throw new InvalidDescriptionException(e);
|
throw new InvalidDescriptionException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,8 +375,10 @@ public class Service
|
|||||||
Node scpdNode = parser.parse(file);
|
Node scpdNode = parser.parse(file);
|
||||||
if (scpdNode == null)
|
if (scpdNode == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ServiceData data = getServiceData();
|
ServiceData data = getServiceData();
|
||||||
data.setSCPDNode(scpdNode);
|
data.setSCPDNode(scpdNode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,20 +391,22 @@ public class Service
|
|||||||
Node scpdNode = parser.parse(input);
|
Node scpdNode = parser.parse(input);
|
||||||
if (scpdNode == null)
|
if (scpdNode == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ServiceData data = getServiceData();
|
ServiceData data = getServiceData();
|
||||||
data.setSCPDNode(scpdNode);
|
data.setSCPDNode(scpdNode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setDescriptionURL(String value)
|
public void setDescriptionURL(String value)
|
||||||
{
|
{
|
||||||
getServiceData().setDescriptionURL(value);
|
getServiceData().setDescriptionURL(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescriptionURL()
|
public String getDescriptionURL()
|
||||||
{
|
{
|
||||||
return getServiceData().getDescriptionURL();
|
return getServiceData().getDescriptionURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -406,6 +436,9 @@ public class Service
|
|||||||
|
|
||||||
String scpdURLStr = getSCPDURL();
|
String scpdURLStr = getSCPDURL();
|
||||||
|
|
||||||
|
/****
|
||||||
|
* I2P - no, dont attempt to load local file
|
||||||
|
*
|
||||||
// Thanks for Robin V. (Sep 18, 2010)
|
// Thanks for Robin V. (Sep 18, 2010)
|
||||||
String rootDevPath = rootDev.getDescriptionFilePath();
|
String rootDevPath = rootDev.getDescriptionFilePath();
|
||||||
if(rootDevPath!=null) {
|
if(rootDevPath!=null) {
|
||||||
@@ -425,6 +458,7 @@ public class Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL scpdUrl = new URL(rootDev.getAbsoluteURL(scpdURLStr));
|
URL scpdUrl = new URL(rootDev.getAbsoluteURL(scpdURLStr));
|
||||||
@@ -434,8 +468,14 @@ public class Service
|
|||||||
return scpdNode;
|
return scpdNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
catch (Exception e) {
|
||||||
|
// I2P
|
||||||
|
Debug.warning(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****
|
||||||
|
* I2P - no, dont attempt to load local file
|
||||||
|
*
|
||||||
String newScpdURLStr = rootDev.getDescriptionFilePath() + HTTP.toRelativeURL(scpdURLStr);
|
String newScpdURLStr = rootDev.getDescriptionFilePath() + HTTP.toRelativeURL(scpdURLStr);
|
||||||
try {
|
try {
|
||||||
scpdNode = getSCPDNode(new File(newScpdURLStr));
|
scpdNode = getSCPDNode(new File(newScpdURLStr));
|
||||||
@@ -444,6 +484,7 @@ public class Service
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Debug.warning(e);
|
Debug.warning(e);
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -1,52 +1,52 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberUPnP for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: ServiceList.java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/04/02
|
* File: ServiceList.java
|
||||||
* - first revision.
|
*
|
||||||
* 06/18/03
|
* Revision;
|
||||||
* - Added caching a ArrayIndexOfBound exception.
|
*
|
||||||
*
|
* 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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/06/02
|
* File: ServiceStateTable.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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 XML_CLASS_PROPERTTY="cyberlink.upnp.xml.parser";
|
||||||
|
|
||||||
public final static String NAME = "CyberLinkJava";
|
public final static String NAME = "CyberLinkJava";
|
||||||
public final static String VERSION = "1.8";
|
public final static String VERSION = "3.0";
|
||||||
|
|
||||||
// I2P was 100
|
// I2P was 100
|
||||||
public final static int SERVER_RETRY_COUNT = 4;
|
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 String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
||||||
|
|
||||||
|
public final static int CONFIGID_UPNP_ORG_MAX = 16777215;
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Enable / Disable
|
// Enable / Disable
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -190,6 +192,34 @@ public class UPnP
|
|||||||
toUUID((int)((time2 >> 32) | 0xE000) & 0xFFFF);
|
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
|
// XML Parser
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
@@ -1,82 +1,82 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2004
|
* Copyright (C) Satoshi Konno 2002-2004
|
||||||
*
|
*
|
||||||
* File: UPnPStatus.java
|
* File: UPnPStatus.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/18/02
|
* 11/18/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 01/03/04
|
* 01/03/04
|
||||||
* - Changed the class name from UPnPError to UPnPStatus.
|
* - Changed the class name from UPnPError to UPnPStatus.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp;
|
package org.cybergarage.upnp;
|
||||||
import org.cybergarage.http.HTTPStatus;
|
import org.cybergarage.http.HTTPStatus;
|
||||||
|
|
||||||
public class UPnPStatus
|
public class UPnPStatus
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Code
|
// Code
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public static final int INVALID_ACTION = 401;
|
public static final int INVALID_ACTION = 401;
|
||||||
public static final int INVALID_ARGS = 402;
|
public static final int INVALID_ARGS = 402;
|
||||||
public static final int OUT_OF_SYNC = 403;
|
public static final int OUT_OF_SYNC = 403;
|
||||||
public static final int INVALID_VAR = 404;
|
public static final int INVALID_VAR = 404;
|
||||||
public static final int PRECONDITION_FAILED = 412;
|
public static final int PRECONDITION_FAILED = 412;
|
||||||
public static final int ACTION_FAILED = 501;
|
public static final int ACTION_FAILED = 501;
|
||||||
|
|
||||||
public static final String code2String(int code)
|
public static final String code2String(int code)
|
||||||
{
|
{
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case INVALID_ACTION: return "Invalid Action";
|
case INVALID_ACTION: return "Invalid Action";
|
||||||
case INVALID_ARGS: return "Invalid Args";
|
case INVALID_ARGS: return "Invalid Args";
|
||||||
case OUT_OF_SYNC: return "Out of Sync";
|
case OUT_OF_SYNC: return "Out of Sync";
|
||||||
case INVALID_VAR: return "Invalid Var";
|
case INVALID_VAR: return "Invalid Var";
|
||||||
case PRECONDITION_FAILED: return "Precondition Failed";
|
case PRECONDITION_FAILED: return "Precondition Failed";
|
||||||
case ACTION_FAILED: return "Action Failed";
|
case ACTION_FAILED: return "Action Failed";
|
||||||
default: return HTTPStatus.code2String(code);
|
default: return HTTPStatus.code2String(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private int code;
|
private int code;
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
public UPnPStatus()
|
public UPnPStatus()
|
||||||
{
|
{
|
||||||
setCode(0);
|
setCode(0);
|
||||||
setDescription("");
|
setDescription("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public UPnPStatus(int code, String desc)
|
public UPnPStatus(int code, String desc)
|
||||||
{
|
{
|
||||||
setCode(code);
|
setCode(code);
|
||||||
setDescription(desc);
|
setDescription(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCode(int code) {
|
public void setCode(int code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,23 +1,23 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: ActionListener.java
|
* File: ActionListener.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/16/03
|
* 01/16/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public interface ActionListener
|
public interface ActionListener
|
||||||
{
|
{
|
||||||
public boolean actionControlReceived(Action action);
|
public boolean actionControlReceived(Action action);
|
||||||
}
|
}
|
||||||
|
@@ -1,145 +1,145 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: ControlRequest.java
|
* File: ControlRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/29/03
|
* 01/29/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/09/05
|
* 05/09/05
|
||||||
* - Changed getActionName() to return when the delimiter is not found.
|
* - Changed getActionName() to return when the delimiter is not found.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
import org.cybergarage.xml.*;
|
import org.cybergarage.xml.*;
|
||||||
import org.cybergarage.soap.*;
|
import org.cybergarage.soap.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public class ActionRequest extends ControlRequest
|
public class ActionRequest extends ControlRequest
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public ActionRequest()
|
public ActionRequest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionRequest(HTTPRequest httpReq)
|
public ActionRequest(HTTPRequest httpReq)
|
||||||
{
|
{
|
||||||
set(httpReq);
|
set(httpReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Action
|
// Action
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public Node getActionNode()
|
public Node getActionNode()
|
||||||
{
|
{
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
if (bodyNode == null)
|
if (bodyNode == null)
|
||||||
return null;
|
return null;
|
||||||
if (bodyNode.hasNodes() == false)
|
if (bodyNode.hasNodes() == false)
|
||||||
return null;
|
return null;
|
||||||
return bodyNode.getNode(0);
|
return bodyNode.getNode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActionName()
|
public String getActionName()
|
||||||
{
|
{
|
||||||
Node node = getActionNode();
|
Node node = getActionNode();
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return "";
|
return "";
|
||||||
String name = node.getName();
|
String name = node.getName();
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return "";
|
return "";
|
||||||
int idx = name.indexOf(SOAP.DELIM)+1;
|
int idx = name.indexOf(SOAP.DELIM)+1;
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return "";
|
return "";
|
||||||
return name.substring(idx, name.length());
|
return name.substring(idx, name.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArgumentList getArgumentList()
|
public ArgumentList getArgumentList()
|
||||||
{
|
{
|
||||||
Node actNode = getActionNode();
|
Node actNode = getActionNode();
|
||||||
int nArgNodes = actNode.getNNodes();
|
int nArgNodes = actNode.getNNodes();
|
||||||
ArgumentList argList = new ArgumentList();
|
ArgumentList argList = new ArgumentList();
|
||||||
for (int n=0; n<nArgNodes; n++) {
|
for (int n=0; n<nArgNodes; n++) {
|
||||||
Argument arg = new Argument();
|
Argument arg = new Argument();
|
||||||
Node argNode = actNode.getNode(n);
|
Node argNode = actNode.getNode(n);
|
||||||
arg.setName(argNode.getName());
|
arg.setName(argNode.getName());
|
||||||
arg.setValue(argNode.getValue());
|
arg.setValue(argNode.getValue());
|
||||||
argList.add(arg);
|
argList.add(arg);
|
||||||
}
|
}
|
||||||
return argList;
|
return argList;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// setRequest
|
// setRequest
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setRequest(Action action, ArgumentList argList)
|
public void setRequest(Action action, ArgumentList argList)
|
||||||
{
|
{
|
||||||
Service service = action.getService();
|
Service service = action.getService();
|
||||||
|
|
||||||
setRequestHost(service);
|
setRequestHost(service);
|
||||||
|
|
||||||
setEnvelopeNode(SOAP.createEnvelopeBodyNode());
|
setEnvelopeNode(SOAP.createEnvelopeBodyNode());
|
||||||
Node envNode = getEnvelopeNode();
|
Node envNode = getEnvelopeNode();
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
Node argNode = createContentNode(service, action, argList);
|
Node argNode = createContentNode(service, action, argList);
|
||||||
bodyNode.addNode(argNode);
|
bodyNode.addNode(argNode);
|
||||||
setContent(envNode);
|
setContent(envNode);
|
||||||
|
|
||||||
String serviceType = service.getServiceType();
|
String serviceType = service.getServiceType();
|
||||||
String actionName = action.getName();
|
String actionName = action.getName();
|
||||||
String soapAction = "\"" +
|
String soapAction = "\"" +
|
||||||
serviceType +
|
serviceType +
|
||||||
"#" + actionName +
|
"#" + actionName +
|
||||||
"\"";
|
"\"";
|
||||||
setSOAPAction(soapAction);
|
setSOAPAction(soapAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Contents
|
// Contents
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node createContentNode(Service service, Action action, ArgumentList argList)
|
private Node createContentNode(Service service, Action action, ArgumentList argList)
|
||||||
{
|
{
|
||||||
String actionName = action.getName();
|
String actionName = action.getName();
|
||||||
String serviceType = service.getServiceType();
|
String serviceType = service.getServiceType();
|
||||||
|
|
||||||
Node actionNode = new Node();
|
Node actionNode = new Node();
|
||||||
actionNode.setName(Control.NS, actionName);
|
actionNode.setName(Control.NS, actionName);
|
||||||
actionNode.setNameSpace(Control.NS, serviceType);
|
actionNode.setNameSpace(Control.NS, serviceType);
|
||||||
|
|
||||||
int argListCnt = argList.size();
|
int argListCnt = argList.size();
|
||||||
for (int n=0; n<argListCnt; n++) {
|
for (int n=0; n<argListCnt; n++) {
|
||||||
Argument arg = argList.getArgument(n);
|
Argument arg = argList.getArgument(n);
|
||||||
Node argNode = new Node();
|
Node argNode = new Node();
|
||||||
argNode.setName(arg.getName());
|
argNode.setName(arg.getName());
|
||||||
argNode.setValue(arg.getValue());
|
argNode.setValue(arg.getValue());
|
||||||
actionNode.addNode(argNode);
|
actionNode.addNode(argNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionNode;
|
return actionNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// post
|
// post
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public ActionResponse post()
|
public ActionResponse post()
|
||||||
{
|
{
|
||||||
SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort());
|
SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort());
|
||||||
return new ActionResponse(soapRes);
|
return new ActionResponse(soapRes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,120 +1,120 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: ActionResponse.java
|
* File: ActionResponse.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/29/03
|
* 01/29/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 09/02/03
|
* 09/02/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Problem : Action Responses do not contain the mandatory header field EXT
|
* - Problem : Action Responses do not contain the mandatory header field EXT
|
||||||
* - Error : ActionResponse class does not set the EXT header
|
* - Error : ActionResponse class does not set the EXT header
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
import org.cybergarage.soap.*;
|
import org.cybergarage.soap.*;
|
||||||
import org.cybergarage.xml.*;
|
import org.cybergarage.xml.*;
|
||||||
|
|
||||||
public class ActionResponse extends ControlResponse
|
public class ActionResponse extends ControlResponse
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public ActionResponse()
|
public ActionResponse()
|
||||||
{
|
{
|
||||||
setHeader(HTTP.EXT, "");
|
setHeader(HTTP.EXT, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResponse(SOAPResponse soapRes)
|
public ActionResponse(SOAPResponse soapRes)
|
||||||
{
|
{
|
||||||
super(soapRes);
|
super(soapRes);
|
||||||
setHeader(HTTP.EXT, "");
|
setHeader(HTTP.EXT, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Response
|
// Response
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setResponse(Action action)
|
public void setResponse(Action action)
|
||||||
{
|
{
|
||||||
setStatusCode(HTTPStatus.OK);
|
setStatusCode(HTTPStatus.OK);
|
||||||
|
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
Node resNode = createResponseNode(action);
|
Node resNode = createResponseNode(action);
|
||||||
bodyNode.addNode(resNode);
|
bodyNode.addNode(resNode);
|
||||||
|
|
||||||
Node envNode = getEnvelopeNode();
|
Node envNode = getEnvelopeNode();
|
||||||
setContent(envNode);
|
setContent(envNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node createResponseNode(Action action)
|
private Node createResponseNode(Action action)
|
||||||
{
|
{
|
||||||
String actionName = action.getName();
|
String actionName = action.getName();
|
||||||
Node actionNameResNode = new Node(SOAP.METHODNS + SOAP.DELIM + actionName + SOAP.RESPONSE);
|
Node actionNameResNode = new Node(SOAP.METHODNS + SOAP.DELIM + actionName + SOAP.RESPONSE);
|
||||||
|
|
||||||
Service service = action.getService();
|
Service service = action.getService();
|
||||||
if (service != null) {
|
if (service != null) {
|
||||||
actionNameResNode.setAttribute(
|
actionNameResNode.setAttribute(
|
||||||
"xmlns:" + SOAP.METHODNS,
|
"xmlns:" + SOAP.METHODNS,
|
||||||
service.getServiceType());
|
service.getServiceType());
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgumentList argList = action.getArgumentList();
|
ArgumentList argList = action.getArgumentList();
|
||||||
int nArgs = argList.size();
|
int nArgs = argList.size();
|
||||||
for (int n=0; n<nArgs; n++) {
|
for (int n=0; n<nArgs; n++) {
|
||||||
Argument arg = argList.getArgument(n);
|
Argument arg = argList.getArgument(n);
|
||||||
if (arg.isOutDirection() == false)
|
if (arg.isOutDirection() == false)
|
||||||
continue;
|
continue;
|
||||||
Node argNode = new Node();
|
Node argNode = new Node();
|
||||||
argNode.setName(arg.getName());
|
argNode.setName(arg.getName());
|
||||||
argNode.setValue(arg.getValue());
|
argNode.setValue(arg.getValue());
|
||||||
actionNameResNode.addNode(argNode);
|
actionNameResNode.addNode(argNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionNameResNode;
|
return actionNameResNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// getResponse
|
// getResponse
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node getActionResponseNode()
|
private Node getActionResponseNode()
|
||||||
{
|
{
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
if (bodyNode == null || bodyNode.hasNodes() == false)
|
if (bodyNode == null || bodyNode.hasNodes() == false)
|
||||||
return null;
|
return null;
|
||||||
return bodyNode.getNode(0);
|
return bodyNode.getNode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArgumentList getResponse()
|
public ArgumentList getResponse()
|
||||||
{
|
{
|
||||||
ArgumentList argList = new ArgumentList();
|
ArgumentList argList = new ArgumentList();
|
||||||
|
|
||||||
Node resNode = getActionResponseNode();
|
Node resNode = getActionResponseNode();
|
||||||
if (resNode == null)
|
if (resNode == null)
|
||||||
return argList;
|
return argList;
|
||||||
|
|
||||||
int nArgs = resNode.getNNodes();
|
int nArgs = resNode.getNNodes();
|
||||||
for (int n=0; n<nArgs; n++) {
|
for (int n=0; n<nArgs; n++) {
|
||||||
Node node = resNode.getNode(n);
|
Node node = resNode.getNode(n);
|
||||||
String name = node.getName();
|
String name = node.getName();
|
||||||
String value = node.getValue();
|
String value = node.getValue();
|
||||||
Argument arg = new Argument(name, value);
|
Argument arg = new Argument(name, value);
|
||||||
argList.add(arg);
|
argList.add(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return argList;
|
return argList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,29 +1,29 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: Control.java
|
* File: Control.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/20/03
|
* 01/20/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
public class Control
|
public class Control
|
||||||
{
|
{
|
||||||
public final static String NS = "u";
|
public final static String NS = "u";
|
||||||
public final static String QUERY_SOAPACTION = "urn:schemas-upnp-org:control-1-0#QueryStateVariable";
|
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 XMLNS = "urn:schemas-upnp-org:control-1-0";
|
||||||
public final static String QUERY_STATE_VARIABLE = "QueryStateVariable";
|
public final static String QUERY_STATE_VARIABLE = "QueryStateVariable";
|
||||||
public final static String QUERY_STATE_VARIABLE_RESPONSE = "QueryStateVariableResponse";
|
public final static String QUERY_STATE_VARIABLE_RESPONSE = "QueryStateVariableResponse";
|
||||||
public final static String VAR_NAME = "varName";
|
public final static String VAR_NAME = "varName";
|
||||||
public final static String RETURN = "return";
|
public final static String RETURN = "return";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,128 +1,128 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: ControlRequest.java
|
* File: ControlRequest.java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Revision:
|
||||||
*
|
*
|
||||||
* 01/29/03
|
* 01/29/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/22/03
|
* 05/22/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Description: inserted a check at the beginning of the setRequestHost method
|
* - 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
|
* - 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
|
* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices
|
||||||
* 09/02/03
|
* 09/02/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it> / Suzan Foster
|
* - Giordano Sassaroli <sassarol@cefriel.it> / Suzan Foster
|
||||||
* - Problem : NullpointerException thrown for devices whose description use absolute urls
|
* - 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.
|
* - 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
|
* 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
|
* - Description: The method setRequestHost/setService should be changed as follows
|
||||||
* 02/17/04
|
* 02/17/04
|
||||||
* - Rob van den Boomen <rob.van.den.boomen@philips.com>
|
* - 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.
|
* - Fixed to set a URLBase from the SSDP header when the URLBase of the description is null.
|
||||||
* 02/18/04
|
* 02/18/04
|
||||||
* - Andre <andre@antiheld.net>
|
* - Andre <andre@antiheld.net>
|
||||||
* - The xml nodes controlUrl and eventSubUrl can contain absolut urls, but these absolut urls may have
|
* - 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
|
* 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,
|
* 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
|
* 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
|
* (oddly, there was a response returned even on port 80, but with empty body tags. but the correct response
|
||||||
* finally came from port 5440).
|
* finally came from port 5440).
|
||||||
* - Fixed to get the port from the control url when it is absolute.
|
* - Fixed to get the port from the control url when it is absolute.
|
||||||
* 03/20/04
|
* 03/20/04
|
||||||
* - Thanks for Thomas Schulz <tsroyale at users.sourceforge.net>
|
* - Thanks for Thomas Schulz <tsroyale at users.sourceforge.net>
|
||||||
* - Fixed setRequestHost() for Sony's UPnP stack when the URLBase has the path.
|
* - Fixed setRequestHost() for Sony's UPnP stack when the URLBase has the path.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
import org.cybergarage.soap.*;
|
import org.cybergarage.soap.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public class ControlRequest extends SOAPRequest
|
public class ControlRequest extends SOAPRequest
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public ControlRequest()
|
public ControlRequest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlRequest(HTTPRequest httpReq)
|
public ControlRequest(HTTPRequest httpReq)
|
||||||
{
|
{
|
||||||
set(httpReq);
|
set(httpReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Query
|
// Query
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public boolean isQueryControl()
|
public boolean isQueryControl()
|
||||||
{
|
{
|
||||||
return isSOAPAction(Control.QUERY_SOAPACTION);
|
return isSOAPAction(Control.QUERY_SOAPACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActionControl()
|
public boolean isActionControl()
|
||||||
{
|
{
|
||||||
return !isQueryControl();
|
return !isQueryControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// setRequest
|
// setRequest
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
protected void setRequestHost(Service service)
|
protected void setRequestHost(Service service)
|
||||||
{
|
{
|
||||||
String ctrlURL = service.getControlURL();
|
String ctrlURL = service.getControlURL();
|
||||||
|
|
||||||
// Thanks for Thomas Schulz (2004/03/20)
|
// Thanks for Thomas Schulz (2004/03/20)
|
||||||
String urlBase = service.getRootDevice().getURLBase();
|
String urlBase = service.getRootDevice().getURLBase();
|
||||||
if (urlBase != null && 0 < urlBase.length()){
|
if (urlBase != null && 0 < urlBase.length()){
|
||||||
try {
|
try {
|
||||||
URL url = new URL(urlBase);
|
URL url = new URL(urlBase);
|
||||||
String basePath = url.getPath();
|
String basePath = url.getPath();
|
||||||
int baseLen = basePath.length();
|
int baseLen = basePath.length();
|
||||||
if (0 < baseLen) {
|
if (0 < baseLen) {
|
||||||
if (1 < baseLen || (basePath.charAt(0) != '/'))
|
if (1 < baseLen || (basePath.charAt(0) != '/'))
|
||||||
ctrlURL = basePath + ctrlURL;
|
ctrlURL = basePath + ctrlURL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (MalformedURLException e) {}
|
catch (MalformedURLException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03)
|
||||||
setURI(ctrlURL, true);
|
setURI(ctrlURL, true);
|
||||||
|
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> and Suzan Foster (09/02/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> and Suzan Foster (09/02/03)
|
||||||
// Thanks for Andre <andre@antiheld.net> (02/18/04)
|
// Thanks for Andre <andre@antiheld.net> (02/18/04)
|
||||||
String postURL = "";
|
String postURL = "";
|
||||||
if (HTTP.isAbsoluteURL(ctrlURL) == true)
|
if (HTTP.isAbsoluteURL(ctrlURL) == true)
|
||||||
postURL = ctrlURL;
|
postURL = ctrlURL;
|
||||||
|
|
||||||
if (postURL == null || postURL.length() <= 0)
|
if (postURL == null || postURL.length() <= 0)
|
||||||
postURL = service.getRootDevice().getURLBase();
|
postURL = service.getRootDevice().getURLBase();
|
||||||
|
|
||||||
// Thanks for Rob van den Boomen <rob.van.den.boomen@philips.com> (02/17/04)
|
// 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
|
// BUGFIX, set urlbase from location string if not set in description.xml
|
||||||
if (postURL == null || postURL.length() <= 0)
|
if (postURL == null || postURL.length() <= 0)
|
||||||
postURL = service.getRootDevice().getLocation();
|
postURL = service.getRootDevice().getLocation();
|
||||||
|
|
||||||
String reqHost = HTTP.getHost(postURL);
|
String reqHost = HTTP.getHost(postURL);
|
||||||
int reqPort = HTTP.getPort(postURL);
|
int reqPort = HTTP.getPort(postURL);
|
||||||
|
|
||||||
setHost(reqHost, reqPort);
|
setHost(reqHost, reqPort);
|
||||||
setRequestHost(reqHost);
|
setRequestHost(reqHost);
|
||||||
setRequestPort(reqPort);
|
setRequestPort(reqPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,173 +1,173 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: ControlResponse.java
|
* File: ControlResponse.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/29/03
|
* 01/29/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
import org.cybergarage.xml.*;
|
import org.cybergarage.xml.*;
|
||||||
import org.cybergarage.soap.*;
|
import org.cybergarage.soap.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public class ControlResponse extends SOAPResponse
|
public class ControlResponse extends SOAPResponse
|
||||||
{
|
{
|
||||||
public static final String FAULT_CODE = "Client";
|
public static final String FAULT_CODE = "Client";
|
||||||
public static final String FAULT_STRING = "UPnPError";
|
public static final String FAULT_STRING = "UPnPError";
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public ControlResponse()
|
public ControlResponse()
|
||||||
{
|
{
|
||||||
setServer(UPnP.getServerName());
|
setServer(UPnP.getServerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlResponse(SOAPResponse soapRes)
|
public ControlResponse(SOAPResponse soapRes)
|
||||||
{
|
{
|
||||||
super(soapRes);
|
super(soapRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// FaultResponse
|
// FaultResponse
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setFaultResponse(int errCode, String errDescr)
|
public void setFaultResponse(int errCode, String errDescr)
|
||||||
{
|
{
|
||||||
setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR);
|
setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
Node faultNode = createFaultResponseNode(errCode, errDescr);
|
Node faultNode = createFaultResponseNode(errCode, errDescr);
|
||||||
bodyNode.addNode(faultNode);
|
bodyNode.addNode(faultNode);
|
||||||
|
|
||||||
Node envNode = getEnvelopeNode();
|
Node envNode = getEnvelopeNode();
|
||||||
setContent(envNode);
|
setContent(envNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFaultResponse(int errCode)
|
public void setFaultResponse(int errCode)
|
||||||
{
|
{
|
||||||
setFaultResponse(errCode, UPnPStatus.code2String(errCode));
|
setFaultResponse(errCode, UPnPStatus.code2String(errCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// createFaultResponseNode
|
// createFaultResponseNode
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node createFaultResponseNode(int errCode, String errDescr)
|
private Node createFaultResponseNode(int errCode, String errDescr)
|
||||||
{
|
{
|
||||||
// <s:Fault>
|
// <s:Fault>
|
||||||
Node faultNode = new Node(SOAP.XMLNS + SOAP.DELIM + SOAP.FAULT);
|
Node faultNode = new Node(SOAP.XMLNS + SOAP.DELIM + SOAP.FAULT);
|
||||||
|
|
||||||
// <faultcode>s:Client</faultcode>
|
// <faultcode>s:Client</faultcode>
|
||||||
Node faultCodeNode = new Node(SOAP.FAULT_CODE);
|
Node faultCodeNode = new Node(SOAP.FAULT_CODE);
|
||||||
faultCodeNode.setValue(SOAP.XMLNS + SOAP.DELIM + FAULT_CODE);
|
faultCodeNode.setValue(SOAP.XMLNS + SOAP.DELIM + FAULT_CODE);
|
||||||
faultNode.addNode(faultCodeNode);
|
faultNode.addNode(faultCodeNode);
|
||||||
|
|
||||||
// <faultstring>UPnPError</faultstring>
|
// <faultstring>UPnPError</faultstring>
|
||||||
Node faultStringNode = new Node(SOAP.FAULT_STRING);
|
Node faultStringNode = new Node(SOAP.FAULT_STRING);
|
||||||
faultStringNode.setValue(FAULT_STRING);
|
faultStringNode.setValue(FAULT_STRING);
|
||||||
faultNode.addNode(faultStringNode);
|
faultNode.addNode(faultStringNode);
|
||||||
|
|
||||||
// <detail>
|
// <detail>
|
||||||
Node detailNode = new Node(SOAP.DETAIL);
|
Node detailNode = new Node(SOAP.DETAIL);
|
||||||
faultNode.addNode(detailNode);
|
faultNode.addNode(detailNode);
|
||||||
|
|
||||||
// <UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
|
// <UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
|
||||||
Node upnpErrorNode = new Node(FAULT_STRING);
|
Node upnpErrorNode = new Node(FAULT_STRING);
|
||||||
upnpErrorNode.setAttribute("xmlns", Control.XMLNS);
|
upnpErrorNode.setAttribute("xmlns", Control.XMLNS);
|
||||||
detailNode.addNode(upnpErrorNode);
|
detailNode.addNode(upnpErrorNode);
|
||||||
|
|
||||||
// <errorCode>error code</errorCode>
|
// <errorCode>error code</errorCode>
|
||||||
Node errorCodeNode = new Node(SOAP.ERROR_CODE);
|
Node errorCodeNode = new Node(SOAP.ERROR_CODE);
|
||||||
errorCodeNode.setValue(errCode);
|
errorCodeNode.setValue(errCode);
|
||||||
upnpErrorNode.addNode(errorCodeNode);
|
upnpErrorNode.addNode(errorCodeNode);
|
||||||
|
|
||||||
// <errorDescription>error string</errorDescription>
|
// <errorDescription>error string</errorDescription>
|
||||||
Node errorDesctiprionNode = new Node(SOAP.ERROR_DESCRIPTION);
|
Node errorDesctiprionNode = new Node(SOAP.ERROR_DESCRIPTION);
|
||||||
errorDesctiprionNode.setValue(errDescr);
|
errorDesctiprionNode.setValue(errDescr);
|
||||||
upnpErrorNode.addNode(errorDesctiprionNode);
|
upnpErrorNode.addNode(errorDesctiprionNode);
|
||||||
|
|
||||||
return faultNode;
|
return faultNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node createFaultResponseNode(int errCode)
|
private Node createFaultResponseNode(int errCode)
|
||||||
{
|
{
|
||||||
return createFaultResponseNode(errCode, UPnPStatus.code2String(errCode));
|
return createFaultResponseNode(errCode, UPnPStatus.code2String(errCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// UPnP Error
|
// UPnP Error
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private UPnPStatus upnpErr = new UPnPStatus();
|
private UPnPStatus upnpErr = new UPnPStatus();
|
||||||
|
|
||||||
private Node getUPnPErrorNode()
|
private Node getUPnPErrorNode()
|
||||||
{
|
{
|
||||||
Node detailNode = getFaultDetailNode();
|
Node detailNode = getFaultDetailNode();
|
||||||
if (detailNode == null)
|
if (detailNode == null)
|
||||||
return null;
|
return null;
|
||||||
return detailNode.getNodeEndsWith(SOAP.UPNP_ERROR);
|
return detailNode.getNodeEndsWith(SOAP.UPNP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node getUPnPErrorCodeNode()
|
private Node getUPnPErrorCodeNode()
|
||||||
{
|
{
|
||||||
Node errorNode = getUPnPErrorNode();
|
Node errorNode = getUPnPErrorNode();
|
||||||
if (errorNode == null)
|
if (errorNode == null)
|
||||||
return null;
|
return null;
|
||||||
return errorNode.getNodeEndsWith(SOAP.ERROR_CODE);
|
return errorNode.getNodeEndsWith(SOAP.ERROR_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node getUPnPErrorDescriptionNode()
|
private Node getUPnPErrorDescriptionNode()
|
||||||
{
|
{
|
||||||
Node errorNode = getUPnPErrorNode();
|
Node errorNode = getUPnPErrorNode();
|
||||||
if (errorNode == null)
|
if (errorNode == null)
|
||||||
return null;
|
return null;
|
||||||
return errorNode.getNodeEndsWith(SOAP.ERROR_DESCRIPTION);
|
return errorNode.getNodeEndsWith(SOAP.ERROR_DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUPnPErrorCode()
|
public int getUPnPErrorCode()
|
||||||
{
|
{
|
||||||
Node errorCodeNode = getUPnPErrorCodeNode();
|
Node errorCodeNode = getUPnPErrorCodeNode();
|
||||||
if (errorCodeNode == null)
|
if (errorCodeNode == null)
|
||||||
return -1;
|
return -1;
|
||||||
String errorCodeStr = errorCodeNode.getValue();
|
String errorCodeStr = errorCodeNode.getValue();
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(errorCodeStr);
|
return Integer.parseInt(errorCodeStr);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUPnPErrorDescription()
|
public String getUPnPErrorDescription()
|
||||||
{
|
{
|
||||||
Node errorDescNode = getUPnPErrorDescriptionNode();
|
Node errorDescNode = getUPnPErrorDescriptionNode();
|
||||||
if (errorDescNode == null)
|
if (errorDescNode == null)
|
||||||
return "";
|
return "";
|
||||||
return errorDescNode.getValue();
|
return errorDescNode.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UPnPStatus getUPnPError()
|
public UPnPStatus getUPnPError()
|
||||||
{
|
{
|
||||||
int code = 0;
|
int code = 0;
|
||||||
String desc = "";
|
String desc = "";
|
||||||
code = getUPnPErrorCode();
|
code = getUPnPErrorCode();
|
||||||
desc = getUPnPErrorDescription();
|
desc = getUPnPErrorDescription();
|
||||||
upnpErr.setCode(code);
|
upnpErr.setCode(code);
|
||||||
upnpErr.setDescription(desc);
|
upnpErr.setDescription(desc);
|
||||||
return upnpErr;
|
return upnpErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,25 +1,25 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: QueryListener.java
|
* File: QueryListener.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/30/03
|
* 01/30/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 01/04/04
|
* 01/04/04
|
||||||
* - Changed the interface.
|
* - Changed the interface.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public interface QueryListener
|
public interface QueryListener
|
||||||
{
|
{
|
||||||
public boolean queryControlReceived(StateVariable stateVar);
|
public boolean queryControlReceived(StateVariable stateVar);
|
||||||
}
|
}
|
||||||
|
@@ -1,119 +1,119 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: QueryRequest.java
|
* File: QueryRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/29/03
|
* 01/29/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 09/02/03
|
* 09/02/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - 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
|
* - 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;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
import org.cybergarage.xml.*;
|
import org.cybergarage.xml.*;
|
||||||
import org.cybergarage.soap.*;
|
import org.cybergarage.soap.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public class QueryRequest extends ControlRequest
|
public class QueryRequest extends ControlRequest
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public QueryRequest()
|
public QueryRequest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryRequest(HTTPRequest httpReq)
|
public QueryRequest(HTTPRequest httpReq)
|
||||||
{
|
{
|
||||||
set(httpReq);
|
set(httpReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Qyery
|
// Qyery
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node getVarNameNode()
|
private Node getVarNameNode()
|
||||||
{
|
{
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
if (bodyNode == null)
|
if (bodyNode == null)
|
||||||
return null;
|
return null;
|
||||||
if (bodyNode.hasNodes() == false)
|
if (bodyNode.hasNodes() == false)
|
||||||
return null;
|
return null;
|
||||||
Node queryStateVarNode = bodyNode.getNode(0);
|
Node queryStateVarNode = bodyNode.getNode(0);
|
||||||
if (queryStateVarNode == null)
|
if (queryStateVarNode == null)
|
||||||
return null;
|
return null;
|
||||||
if (queryStateVarNode.hasNodes() == false)
|
if (queryStateVarNode.hasNodes() == false)
|
||||||
return null;
|
return null;
|
||||||
return queryStateVarNode.getNode(0);
|
return queryStateVarNode.getNode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVarName()
|
public String getVarName()
|
||||||
{
|
{
|
||||||
Node node = getVarNameNode();
|
Node node = getVarNameNode();
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return "";
|
return "";
|
||||||
return node.getValue();
|
return node.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// setRequest
|
// setRequest
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setRequest(StateVariable stateVar)
|
public void setRequest(StateVariable stateVar)
|
||||||
{
|
{
|
||||||
Service service = stateVar.getService();
|
Service service = stateVar.getService();
|
||||||
|
|
||||||
String ctrlURL = service.getControlURL();
|
String ctrlURL = service.getControlURL();
|
||||||
|
|
||||||
setRequestHost(service);
|
setRequestHost(service);
|
||||||
|
|
||||||
setEnvelopeNode(SOAP.createEnvelopeBodyNode());
|
setEnvelopeNode(SOAP.createEnvelopeBodyNode());
|
||||||
Node envNode = getEnvelopeNode();
|
Node envNode = getEnvelopeNode();
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
Node qeuryNode = createContentNode(stateVar);
|
Node qeuryNode = createContentNode(stateVar);
|
||||||
bodyNode.addNode(qeuryNode);
|
bodyNode.addNode(qeuryNode);
|
||||||
setContent(envNode);
|
setContent(envNode);
|
||||||
|
|
||||||
setSOAPAction(Control.QUERY_SOAPACTION);
|
setSOAPAction(Control.QUERY_SOAPACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Contents
|
// Contents
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node createContentNode(StateVariable stateVar)
|
private Node createContentNode(StateVariable stateVar)
|
||||||
{
|
{
|
||||||
Node queryVarNode = new Node();
|
Node queryVarNode = new Node();
|
||||||
queryVarNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE);
|
queryVarNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE);
|
||||||
queryVarNode.setNameSpace(Control.NS, Control.XMLNS);
|
queryVarNode.setNameSpace(Control.NS, Control.XMLNS);
|
||||||
|
|
||||||
Node varNode = new Node();
|
Node varNode = new Node();
|
||||||
varNode.setName(Control.NS, Control.VAR_NAME);
|
varNode.setName(Control.NS, Control.VAR_NAME);
|
||||||
varNode.setValue(stateVar.getName());
|
varNode.setValue(stateVar.getName());
|
||||||
queryVarNode.addNode(varNode);
|
queryVarNode.addNode(varNode);
|
||||||
|
|
||||||
return queryVarNode;
|
return queryVarNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// post
|
// post
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public QueryResponse post()
|
public QueryResponse post()
|
||||||
{
|
{
|
||||||
SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort());
|
SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort());
|
||||||
return new QueryResponse(soapRes);
|
return new QueryResponse(soapRes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,97 +1,97 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: QueryResponse.java
|
* File: QueryResponse.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/30/03
|
* 01/30/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
import org.cybergarage.soap.*;
|
import org.cybergarage.soap.*;
|
||||||
import org.cybergarage.xml.*;
|
import org.cybergarage.xml.*;
|
||||||
|
|
||||||
public class QueryResponse extends ControlResponse
|
public class QueryResponse extends ControlResponse
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public QueryResponse()
|
public QueryResponse()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryResponse(SOAPResponse soapRes)
|
public QueryResponse(SOAPResponse soapRes)
|
||||||
{
|
{
|
||||||
super(soapRes);
|
super(soapRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Qyery
|
// Qyery
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node getReturnNode()
|
private Node getReturnNode()
|
||||||
{
|
{
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
if (bodyNode == null)
|
if (bodyNode == null)
|
||||||
return null;
|
return null;
|
||||||
if (bodyNode.hasNodes() == false)
|
if (bodyNode.hasNodes() == false)
|
||||||
return null;
|
return null;
|
||||||
Node queryResNode = bodyNode.getNode(0);
|
Node queryResNode = bodyNode.getNode(0);
|
||||||
if (queryResNode == null)
|
if (queryResNode == null)
|
||||||
return null;
|
return null;
|
||||||
if (queryResNode.hasNodes() == false)
|
if (queryResNode.hasNodes() == false)
|
||||||
return null;
|
return null;
|
||||||
return queryResNode.getNode(0);
|
return queryResNode.getNode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReturnValue()
|
public String getReturnValue()
|
||||||
{
|
{
|
||||||
Node node = getReturnNode();
|
Node node = getReturnNode();
|
||||||
if (node == null)
|
if (node == null)
|
||||||
return "";
|
return "";
|
||||||
return node.getValue();
|
return node.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Response
|
// Response
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setResponse(StateVariable stateVar)
|
public void setResponse(StateVariable stateVar)
|
||||||
{
|
{
|
||||||
String var = stateVar.getValue();
|
String var = stateVar.getValue();
|
||||||
|
|
||||||
setStatusCode(HTTPStatus.OK);
|
setStatusCode(HTTPStatus.OK);
|
||||||
|
|
||||||
Node bodyNode = getBodyNode();
|
Node bodyNode = getBodyNode();
|
||||||
Node resNode = createResponseNode(var);
|
Node resNode = createResponseNode(var);
|
||||||
bodyNode.addNode(resNode);
|
bodyNode.addNode(resNode);
|
||||||
|
|
||||||
Node envNodee = getEnvelopeNode();
|
Node envNodee = getEnvelopeNode();
|
||||||
setContent(envNodee);
|
setContent(envNodee);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node createResponseNode(String var)
|
private Node createResponseNode(String var)
|
||||||
{
|
{
|
||||||
Node queryResNode = new Node();
|
Node queryResNode = new Node();
|
||||||
queryResNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE_RESPONSE);
|
queryResNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE_RESPONSE);
|
||||||
queryResNode.setNameSpace(Control.NS, Control.XMLNS);
|
queryResNode.setNameSpace(Control.NS, Control.XMLNS);
|
||||||
|
|
||||||
Node returnNode = new Node();
|
Node returnNode = new Node();
|
||||||
returnNode.setName(Control.RETURN);
|
returnNode.setName(Control.RETURN);
|
||||||
returnNode.setValue(var);
|
returnNode.setValue(var);
|
||||||
queryResNode.addNode(returnNode);
|
queryResNode.addNode(returnNode);
|
||||||
|
|
||||||
return queryResNode;
|
return queryResNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,65 +1,65 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: RenewSubscriber.java
|
* File: RenewSubscriber.java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Revision:
|
||||||
*
|
*
|
||||||
* 07/07/04
|
* 07/07/04
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.control;
|
package org.cybergarage.upnp.control;
|
||||||
|
|
||||||
import org.cybergarage.util.*;
|
import org.cybergarage.util.*;
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public class RenewSubscriber extends ThreadCore
|
public class RenewSubscriber extends ThreadCore
|
||||||
{
|
{
|
||||||
public final static long INTERVAL = 120;
|
public final static long INTERVAL = 120;
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public RenewSubscriber(ControlPoint ctrlp)
|
public RenewSubscriber(ControlPoint ctrlp)
|
||||||
{
|
{
|
||||||
setControlPoint(ctrlp);
|
setControlPoint(ctrlp);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private ControlPoint ctrlPoint;
|
private ControlPoint ctrlPoint;
|
||||||
|
|
||||||
public void setControlPoint(ControlPoint ctrlp)
|
public void setControlPoint(ControlPoint ctrlp)
|
||||||
{
|
{
|
||||||
ctrlPoint = ctrlp;
|
ctrlPoint = ctrlp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlPoint getControlPoint()
|
public ControlPoint getControlPoint()
|
||||||
{
|
{
|
||||||
return ctrlPoint;
|
return ctrlPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Thread
|
// Thread
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
ControlPoint ctrlp = getControlPoint();
|
ControlPoint ctrlp = getControlPoint();
|
||||||
long renewInterval = INTERVAL * 1000;
|
long renewInterval = INTERVAL * 1000;
|
||||||
while (isRunnable() == true) {
|
while (isRunnable() == true) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(renewInterval);
|
Thread.sleep(renewInterval);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
ctrlp.renewSubscriberService();
|
ctrlp.renewSubscriberService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,68 +1,68 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: Advertiser.java
|
* File: Advertiser.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 12/24/03
|
* 12/24/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 06/18/04
|
* 06/18/04
|
||||||
* - Changed to advertise every 25%-50% of the periodic notification cycle for NMPR;
|
* - Changed to advertise every 25%-50% of the periodic notification cycle for NMPR;
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.device;
|
package org.cybergarage.upnp.device;
|
||||||
|
|
||||||
import org.cybergarage.util.*;
|
import org.cybergarage.util.*;
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public class Advertiser extends ThreadCore
|
public class Advertiser extends ThreadCore
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public Advertiser(Device dev)
|
public Advertiser(Device dev)
|
||||||
{
|
{
|
||||||
setDevice(dev);
|
setDevice(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Device device;
|
private Device device;
|
||||||
|
|
||||||
public void setDevice(Device dev)
|
public void setDevice(Device dev)
|
||||||
{
|
{
|
||||||
device = dev;
|
device = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Device getDevice()
|
public Device getDevice()
|
||||||
{
|
{
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Thread
|
// Thread
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Device dev = getDevice();
|
Device dev = getDevice();
|
||||||
long leaseTime = dev.getLeaseTime();
|
long leaseTime = dev.getLeaseTime();
|
||||||
long notifyInterval;
|
long notifyInterval;
|
||||||
while (isRunnable() == true) {
|
while (isRunnable() == true) {
|
||||||
notifyInterval = (leaseTime/4) + (long)((float)leaseTime * (Math.random() * 0.25f));
|
notifyInterval = (leaseTime/4) + (long)((float)leaseTime * (Math.random() * 0.25f));
|
||||||
notifyInterval *= 1000;
|
notifyInterval *= 1000;
|
||||||
try {
|
try {
|
||||||
Thread.sleep(notifyInterval);
|
Thread.sleep(notifyInterval);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
dev.announce();
|
dev.announce();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,24 +1,24 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberUPnP for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: MAN.java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/30/02
|
* File: MAN.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* CyberLink for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2004
|
* Copyright (C) Satoshi Konno 2002-2004
|
||||||
*
|
*
|
||||||
* File: Disposer.java
|
* File: Disposer.java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Revision:
|
||||||
*
|
*
|
||||||
* 01/05/04
|
* 01/05/04
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.device;
|
package org.cybergarage.upnp.device;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
import org.cybergarage.util.*;
|
import org.cybergarage.util.*;
|
||||||
|
|
||||||
public class Disposer extends ThreadCore
|
public class Disposer extends ThreadCore
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public Disposer(ControlPoint ctrlp)
|
public Disposer(ControlPoint ctrlp)
|
||||||
{
|
{
|
||||||
setControlPoint(ctrlp);
|
setControlPoint(ctrlp);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private ControlPoint ctrlPoint;
|
private ControlPoint ctrlPoint;
|
||||||
|
|
||||||
public void setControlPoint(ControlPoint ctrlp)
|
public void setControlPoint(ControlPoint ctrlp)
|
||||||
{
|
{
|
||||||
ctrlPoint = ctrlp;
|
ctrlPoint = ctrlp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlPoint getControlPoint()
|
public ControlPoint getControlPoint()
|
||||||
{
|
{
|
||||||
return ctrlPoint;
|
return ctrlPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Thread
|
// Thread
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Thread.currentThread().setName("UPnP-Disposer");
|
Thread.currentThread().setName("UPnP-Disposer");
|
||||||
ControlPoint ctrlp = getControlPoint();
|
ControlPoint ctrlp = getControlPoint();
|
||||||
long monitorInterval = ctrlp.getExpiredDeviceMonitoringInterval() * 1000;
|
long monitorInterval = ctrlp.getExpiredDeviceMonitoringInterval() * 1000;
|
||||||
|
|
||||||
while (isRunnable() == true) {
|
while (isRunnable() == true) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(monitorInterval);
|
Thread.sleep(monitorInterval);
|
||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
ctrlp.removeExpiredDevices();
|
ctrlp.removeExpiredDevices();
|
||||||
//ctrlp.print();
|
//ctrlp.print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,37 +5,37 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: InvalidDescriptionException.java
|
* File: InvalidDescriptionException.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 12/26/02
|
* 12/26/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.device;
|
package org.cybergarage.upnp.device;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class InvalidDescriptionException extends Exception
|
public class InvalidDescriptionException extends Exception
|
||||||
{
|
{
|
||||||
public InvalidDescriptionException()
|
public InvalidDescriptionException()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvalidDescriptionException(String s)
|
public InvalidDescriptionException(String s)
|
||||||
{
|
{
|
||||||
super(s);
|
super(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvalidDescriptionException(String s, File file)
|
public InvalidDescriptionException(String s, File file)
|
||||||
{
|
{
|
||||||
super(s + " (" + file.toString() + ")");
|
super(s + " (" + file.toString() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvalidDescriptionException(Exception e)
|
public InvalidDescriptionException(Exception e)
|
||||||
{
|
{
|
||||||
super(e.getMessage());
|
super(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,31 +1,31 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberUPnP for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: MAN.java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/30/02
|
* File: MAN.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/09/02
|
* File: NT.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/09/02
|
* File: NTS.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: DeviceNotifyListener.java
|
* File: DeviceNotifyListener.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/18/02
|
* 11/18/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.device;
|
package org.cybergarage.upnp.device;
|
||||||
|
|
||||||
import org.cybergarage.upnp.ssdp.*;
|
import org.cybergarage.upnp.ssdp.*;
|
||||||
|
|
||||||
public interface NotifyListener
|
public interface NotifyListener
|
||||||
{
|
{
|
||||||
public void deviceNotifyReceived(SSDPPacket ssdpPacket);
|
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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* 01/07/03
|
* File: ST.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SearchListener.java
|
* File: SearchListener.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/18/02b
|
* 11/18/02b
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.device;
|
package org.cybergarage.upnp.device;
|
||||||
|
|
||||||
import org.cybergarage.upnp.ssdp.*;
|
import org.cybergarage.upnp.ssdp.*;
|
||||||
|
|
||||||
public interface SearchListener
|
public interface SearchListener
|
||||||
{
|
{
|
||||||
public void deviceSearchReceived(SSDPPacket ssdpPacket);
|
public void deviceSearchReceived(SSDPPacket ssdpPacket);
|
||||||
}
|
}
|
||||||
|
@@ -1,23 +1,23 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SearchResponseListener.java
|
* File: SearchResponseListener.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/18/02
|
* 11/18/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.device;
|
package org.cybergarage.upnp.device;
|
||||||
|
|
||||||
import org.cybergarage.upnp.ssdp.*;
|
import org.cybergarage.upnp.ssdp.*;
|
||||||
|
|
||||||
public interface SearchResponseListener
|
public interface SearchResponseListener
|
||||||
{
|
{
|
||||||
public void deviceSearchResponseReceived(SSDPPacket ssdpPacket);
|
public void deviceSearchResponseReceived(SSDPPacket ssdpPacket);
|
||||||
}
|
}
|
||||||
|
@@ -1,40 +1,40 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberUPnP for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: USN.java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/09/02
|
* File: USN.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: EventListener.java
|
* File: EventListener.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/18/02
|
* 11/18/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.event;
|
package org.cybergarage.upnp.event;
|
||||||
|
|
||||||
public interface EventListener
|
public interface EventListener
|
||||||
{
|
{
|
||||||
public void eventNotifyReceived(String uuid, long seq, String varName, String value);
|
public void eventNotifyReceived(String uuid, long seq, String varName, String value);
|
||||||
}
|
}
|
||||||
|
@@ -1,205 +1,205 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SOAPRequest.java
|
* File: SOAPRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 12/11/02
|
* 12/11/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/22/03
|
* 05/22/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Description: removed the xml namespace
|
* - Description: removed the xml namespace
|
||||||
* - Problem : Notification messages refer to uncorrect variable names
|
* - Problem : Notification messages refer to uncorrect variable names
|
||||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||||
* 05/22/03
|
* 05/22/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Problem : Notification messages refer to uncorrect variable names
|
* - Problem : Notification messages refer to uncorrect variable names
|
||||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||||
* - Description : removed the xml namespace
|
* - Description : removed the xml namespace
|
||||||
* 09/03/03
|
* 09/03/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Problem : Notification messages refer to uncorrect variable names
|
* - Problem : Notification messages refer to uncorrect variable names
|
||||||
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
* - Error : The NotifyRequest class introduces the XML namespace in variable names, too
|
||||||
* - Description: removed the xml namespace
|
* - Description: removed the xml namespace
|
||||||
* 09/08/03
|
* 09/08/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Problem : when an event notification message is received and the message
|
* - Problem : when an event notification message is received and the message
|
||||||
* contains updates on more than one variable, only the first variable update
|
* contains updates on more than one variable, only the first variable update
|
||||||
* is notified.
|
* is notified.
|
||||||
* - Error : the other xml nodes of the message are ignored
|
* - Error : the other xml nodes of the message are ignored
|
||||||
* - Fix : add two methods to the NotifyRequest for extracting the property array
|
* - Fix : add two methods to the NotifyRequest for extracting the property array
|
||||||
* and modify the httpRequestRecieved method in ControlPoint
|
* and modify the httpRequestRecieved method in ControlPoint
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.event;
|
package org.cybergarage.upnp.event;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
import org.cybergarage.xml.*;
|
import org.cybergarage.xml.*;
|
||||||
import org.cybergarage.soap.*;
|
import org.cybergarage.soap.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.device.*;
|
import org.cybergarage.upnp.device.*;
|
||||||
|
|
||||||
public class NotifyRequest extends SOAPRequest
|
public class NotifyRequest extends SOAPRequest
|
||||||
{
|
{
|
||||||
private final static String XMLNS = "e";
|
private final static String XMLNS = "e";
|
||||||
private final static String PROPERTY = "property";
|
private final static String PROPERTY = "property";
|
||||||
private final static String PROPERTYSET = "propertyset";
|
private final static String PROPERTYSET = "propertyset";
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public NotifyRequest()
|
public NotifyRequest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotifyRequest(HTTPRequest httpReq)
|
public NotifyRequest(HTTPRequest httpReq)
|
||||||
{
|
{
|
||||||
set(httpReq);
|
set(httpReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// NT
|
// NT
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setNT(String value)
|
public void setNT(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.NT, value);
|
setHeader(HTTP.NT, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// NTS
|
// NTS
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setNTS(String value)
|
public void setNTS(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.NTS, value);
|
setHeader(HTTP.NTS, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SID
|
// SID
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setSID(String id)
|
public void setSID(String id)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSID()
|
public String getSID()
|
||||||
{
|
{
|
||||||
return Subscription.getSID(getHeaderValue(HTTP.SID));
|
return Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SEQ
|
// SEQ
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setSEQ(long value)
|
public void setSEQ(long value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.SEQ, Long.toString(value));
|
setHeader(HTTP.SEQ, Long.toString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getSEQ()
|
public long getSEQ()
|
||||||
{
|
{
|
||||||
return getLongHeaderValue(HTTP.SEQ);
|
return getLongHeaderValue(HTTP.SEQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public boolean setRequest(Subscriber sub, String varName, String value)
|
public boolean setRequest(Subscriber sub, String varName, String value)
|
||||||
{
|
{
|
||||||
String callback = sub.getDeliveryURL();
|
String callback = sub.getDeliveryURL();
|
||||||
String sid = sub.getSID();
|
String sid = sub.getSID();
|
||||||
long notifyCnt = sub.getNotifyCount();
|
long notifyCnt = sub.getNotifyCount();
|
||||||
String host = sub.getDeliveryHost();
|
String host = sub.getDeliveryHost();
|
||||||
String path = sub.getDeliveryPath();
|
String path = sub.getDeliveryPath();
|
||||||
int port = sub.getDeliveryPort();
|
int port = sub.getDeliveryPort();
|
||||||
|
|
||||||
setMethod(HTTP.NOTIFY);
|
setMethod(HTTP.NOTIFY);
|
||||||
setURI(path);
|
setURI(path);
|
||||||
setHost(host, port);
|
setHost(host, port);
|
||||||
setNT(NT.EVENT);
|
setNT(NT.EVENT);
|
||||||
setNTS(NTS.PROPCHANGE);
|
setNTS(NTS.PROPCHANGE);
|
||||||
setSID(sid);
|
setSID(sid);
|
||||||
setSEQ(notifyCnt);
|
setSEQ(notifyCnt);
|
||||||
|
|
||||||
setContentType(XML.CONTENT_TYPE);
|
setContentType(XML.DEFAULT_CONTENT_TYPE);
|
||||||
Node propSetNode = createPropertySetNode(varName, value);
|
Node propSetNode = createPropertySetNode(varName, value);
|
||||||
setContent(propSetNode);
|
setContent(propSetNode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node createPropertySetNode(String varName, String value)
|
private Node createPropertySetNode(String varName, String value)
|
||||||
{
|
{
|
||||||
Node propSetNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTYSET);
|
Node propSetNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTYSET);
|
||||||
|
|
||||||
propSetNode.setNameSpace(XMLNS, Subscription.XMLNS);
|
propSetNode.setNameSpace(XMLNS, Subscription.XMLNS);
|
||||||
|
|
||||||
Node propNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTY);
|
Node propNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTY);
|
||||||
propSetNode.addNode(propNode);
|
propSetNode.addNode(propNode);
|
||||||
|
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/22/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/22/03)
|
||||||
//Node varNameNode = new Node(XMLNS + SOAP.DELIM + varName);
|
//Node varNameNode = new Node(XMLNS + SOAP.DELIM + varName);
|
||||||
Node varNameNode = new Node(varName);
|
Node varNameNode = new Node(varName);
|
||||||
varNameNode.setValue(value);
|
varNameNode.setValue(value);
|
||||||
propNode.addNode(varNameNode);
|
propNode.addNode(varNameNode);
|
||||||
|
|
||||||
return propSetNode;
|
return propSetNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node getVariableNode()
|
private Node getVariableNode()
|
||||||
{
|
{
|
||||||
Node rootNode = getEnvelopeNode();
|
Node rootNode = getEnvelopeNode();
|
||||||
if (rootNode == null)
|
if (rootNode == null)
|
||||||
return null;
|
return null;
|
||||||
if (rootNode.hasNodes() == false)
|
if (rootNode.hasNodes() == false)
|
||||||
return null;
|
return null;
|
||||||
Node propNode = rootNode.getNode(0);
|
Node propNode = rootNode.getNode(0);
|
||||||
if (propNode.hasNodes() == false)
|
if (propNode.hasNodes() == false)
|
||||||
return null;
|
return null;
|
||||||
return propNode.getNode(0);
|
return propNode.getNode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03)
|
||||||
private Property getProperty(Node varNode)
|
private Property getProperty(Node varNode)
|
||||||
{
|
{
|
||||||
Property prop = new Property();
|
Property prop = new Property();
|
||||||
if (varNode == null)
|
if (varNode == null)
|
||||||
return prop;
|
return prop;
|
||||||
// remove the event namespace
|
// remove the event namespace
|
||||||
String variableName = varNode.getName();
|
String variableName = varNode.getName();
|
||||||
int index = variableName.lastIndexOf(':');
|
int index = variableName.lastIndexOf(':');
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
variableName = variableName.substring(index + 1);
|
variableName = variableName.substring(index + 1);
|
||||||
prop.setName(variableName);
|
prop.setName(variableName);
|
||||||
prop.setValue(varNode.getValue());
|
prop.setValue(varNode.getValue());
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03)
|
||||||
public PropertyList getPropertyList() {
|
public PropertyList getPropertyList() {
|
||||||
PropertyList properties = new PropertyList();
|
PropertyList properties = new PropertyList();
|
||||||
Node varSetNode = getEnvelopeNode();
|
Node varSetNode = getEnvelopeNode();
|
||||||
// I2P change: ParserException caught in getRootNode() causes
|
// I2P change: ParserException caught in getRootNode() causes
|
||||||
// getEnvelopeNode() to return null
|
// getEnvelopeNode() to return null
|
||||||
if (varSetNode == null)
|
if (varSetNode == null)
|
||||||
return properties;
|
return properties;
|
||||||
for (int i = 0; i<varSetNode.getNNodes(); i++){
|
for (int i = 0; i<varSetNode.getNNodes(); i++){
|
||||||
Node propNode = varSetNode.getNode(i);
|
Node propNode = varSetNode.getNode(i);
|
||||||
if (propNode == null)
|
if (propNode == null)
|
||||||
continue;
|
continue;
|
||||||
Property prop = getProperty(propNode.getNode(0));
|
Property prop = getProperty(propNode.getNode(0));
|
||||||
properties.add(prop);
|
properties.add(prop);
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,65 +1,65 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: Subscriber.java
|
* File: Subscriber.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/29/03
|
* 01/29/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/22/03
|
* 05/22/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Problem : the setName method does not set the name of the property
|
* - Problem : the setName method does not set the name of the property
|
||||||
* - Error : the method contains a bug:
|
* - Error : the method contains a bug:
|
||||||
* 06/18/03
|
* 06/18/03
|
||||||
* - Fixed a bug when a null value is received to the name and the value of property.
|
* - Fixed a bug when a null value is received to the name and the value of property.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.event;
|
package org.cybergarage.upnp.event;
|
||||||
|
|
||||||
public class Property
|
public class Property
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public Property()
|
public Property()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// name
|
// name
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String name = "";
|
private String name = "";
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String val) {
|
public void setName(String val) {
|
||||||
if (val == null)
|
if (val == null)
|
||||||
val = "";
|
val = "";
|
||||||
name = val;
|
name = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// value
|
// value
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String value = "";
|
private String value = "";
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(String val) {
|
public void setValue(String val) {
|
||||||
if (val == null)
|
if (val == null)
|
||||||
val = "";
|
val = "";
|
||||||
value = val;
|
value = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,45 +1,45 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberUPnP for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: PropertyList.java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 09/08/03
|
* File: PropertyList.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: Subscriber.java
|
* File: Subscriber.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/29/03
|
* 01/29/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 07/31/04
|
* 07/31/04
|
||||||
* - Added isExpired().
|
* - Added isExpired().
|
||||||
* 10/26/04
|
* 10/26/04
|
||||||
* - Oliver Newell <newell@media-rush.com>
|
* - Oliver Newell <newell@media-rush.com>
|
||||||
* - Added support the intinite time and fixed a bug in isExpired().
|
* - Added support the intinite time and fixed a bug in isExpired().
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.event;
|
package org.cybergarage.upnp.event;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
|
||||||
public class Subscriber
|
public class Subscriber
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public Subscriber()
|
public Subscriber()
|
||||||
{
|
{
|
||||||
renew();
|
renew();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SID
|
// SID
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String SID = null;
|
private String SID = null;
|
||||||
|
|
||||||
public String getSID() {
|
public String getSID() {
|
||||||
return SID;
|
return SID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSID(String sid) {
|
public void setSID(String sid) {
|
||||||
SID = sid;
|
SID = sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// deliveryURL
|
// deliveryURL
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String ifAddr = "";
|
private String ifAddr = "";
|
||||||
|
|
||||||
public void setInterfaceAddress(String addr)
|
public void setInterfaceAddress(String addr)
|
||||||
{
|
{
|
||||||
ifAddr = addr;
|
ifAddr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInterfaceAddress()
|
public String getInterfaceAddress()
|
||||||
{
|
{
|
||||||
return ifAddr;
|
return ifAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// deliveryURL
|
// deliveryURL
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String deliveryURL = "";
|
private String deliveryURL = "";
|
||||||
|
|
||||||
public String getDeliveryURL() {
|
public String getDeliveryURL() {
|
||||||
return deliveryURL;
|
return deliveryURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeliveryURL(String deliveryURL) {
|
public void setDeliveryURL(String deliveryURL) {
|
||||||
this.deliveryURL = deliveryURL;
|
this.deliveryURL = deliveryURL;
|
||||||
try {
|
try {
|
||||||
URL url = new URL(deliveryURL);
|
URL url = new URL(deliveryURL);
|
||||||
deliveryHost = url.getHost();
|
deliveryHost = url.getHost();
|
||||||
deliveryPath = url.getPath();
|
deliveryPath = url.getPath();
|
||||||
deliveryPort = url.getPort();
|
deliveryPort = url.getPort();
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
catch (Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String deliveryHost = "";
|
private String deliveryHost = "";
|
||||||
private String deliveryPath = "";
|
private String deliveryPath = "";
|
||||||
private int deliveryPort = 0;
|
private int deliveryPort = 0;
|
||||||
|
|
||||||
public String getDeliveryHost() {
|
public String getDeliveryHost() {
|
||||||
return deliveryHost;
|
return deliveryHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeliveryPath() {
|
public String getDeliveryPath() {
|
||||||
return deliveryPath;
|
return deliveryPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDeliveryPort() {
|
public int getDeliveryPort() {
|
||||||
return deliveryPort;
|
return deliveryPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Timeout
|
// Timeout
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private long timeOut = 0;
|
private long timeOut = 0;
|
||||||
|
|
||||||
public long getTimeOut() {
|
public long getTimeOut() {
|
||||||
return timeOut;
|
return timeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeOut(long value) {
|
public void setTimeOut(long value) {
|
||||||
timeOut = value;
|
timeOut = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpired()
|
public boolean isExpired()
|
||||||
{
|
{
|
||||||
long currTime = System.currentTimeMillis();
|
long currTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// Thanks for Oliver Newell (10/26/04)
|
// Thanks for Oliver Newell (10/26/04)
|
||||||
if(timeOut == Subscription.INFINITE_VALUE )
|
if(timeOut == Subscription.INFINITE_VALUE )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Thanks for Oliver Newell (10/26/04)
|
// Thanks for Oliver Newell (10/26/04)
|
||||||
long expiredTime = getSubscriptionTime() + getTimeOut()*1000;
|
long expiredTime = getSubscriptionTime() + getTimeOut()*1000;
|
||||||
if (expiredTime < currTime)
|
if (expiredTime < currTime)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SubscriptionTIme
|
// SubscriptionTIme
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private long subscriptionTime = 0;
|
private long subscriptionTime = 0;
|
||||||
|
|
||||||
public long getSubscriptionTime() {
|
public long getSubscriptionTime() {
|
||||||
return subscriptionTime;
|
return subscriptionTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubscriptionTime(long time) {
|
public void setSubscriptionTime(long time) {
|
||||||
subscriptionTime = time;
|
subscriptionTime = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SEQ
|
// SEQ
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private long notifyCount = 0;
|
private long notifyCount = 0;
|
||||||
|
|
||||||
public long getNotifyCount() {
|
public long getNotifyCount() {
|
||||||
return notifyCount;
|
return notifyCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotifyCount(int cnt) {
|
public void setNotifyCount(int cnt) {
|
||||||
notifyCount = cnt;
|
notifyCount = cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incrementNotifyCount() {
|
public void incrementNotifyCount() {
|
||||||
if (notifyCount == Long.MAX_VALUE) {
|
if (notifyCount == Long.MAX_VALUE) {
|
||||||
notifyCount = 1;
|
notifyCount = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
notifyCount++;
|
notifyCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// renew
|
// renew
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void renew()
|
public void renew()
|
||||||
{
|
{
|
||||||
setSubscriptionTime(System.currentTimeMillis());
|
setSubscriptionTime(System.currentTimeMillis());
|
||||||
setNotifyCount(0);
|
setNotifyCount(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,46 +1,46 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SubscriberList.java
|
* File: SubscriberList.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/31/03
|
* 01/31/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 06/18/03
|
* 06/18/03
|
||||||
* - Fixed to catch ArrayIndexOutOfBounds.
|
* - Fixed to catch ArrayIndexOutOfBounds.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.event;
|
package org.cybergarage.upnp.event;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class SubscriberList extends Vector<Subscriber>
|
public class SubscriberList extends Vector<Subscriber>
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SubscriberList()
|
public SubscriberList()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Methods
|
// Methods
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public Subscriber getSubscriber(int n)
|
public Subscriber getSubscriber(int n)
|
||||||
{
|
{
|
||||||
Object obj = null;
|
Object obj = null;
|
||||||
try {
|
try {
|
||||||
obj = get(n);
|
obj = get(n);
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
catch (Exception e) {}
|
||||||
return (Subscriber)obj;
|
return (Subscriber)obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,77 +1,77 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: ST.java
|
* File: ST.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/31/03
|
* 01/31/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.event;
|
package org.cybergarage.upnp.event;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public class Subscription
|
public class Subscription
|
||||||
{
|
{
|
||||||
public final static String XMLNS = "urn:schemas-upnp-org:event-1-0";
|
public final static String XMLNS = "urn:schemas-upnp-org:event-1-0";
|
||||||
public final static String TIMEOUT_HEADER = "Second-";
|
public final static String TIMEOUT_HEADER = "Second-";
|
||||||
public final static String INFINITE_STRING = "infinite";
|
public final static String INFINITE_STRING = "infinite";
|
||||||
public final static int INFINITE_VALUE = -1;
|
public final static int INFINITE_VALUE = -1;
|
||||||
public final static String UUID = "uuid:";
|
public final static String UUID = "uuid:";
|
||||||
public final static String SUBSCRIBE_METHOD = "SUBSCRIBE";
|
public final static String SUBSCRIBE_METHOD = "SUBSCRIBE";
|
||||||
public final static String UNSUBSCRIBE_METHOD = "UNSUBSCRIBE";
|
public final static String UNSUBSCRIBE_METHOD = "UNSUBSCRIBE";
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Timeout
|
// Timeout
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public final static String toTimeoutHeaderString(long time)
|
public final static String toTimeoutHeaderString(long time)
|
||||||
{
|
{
|
||||||
if (time == Subscription.INFINITE_VALUE)
|
if (time == Subscription.INFINITE_VALUE)
|
||||||
return Subscription.INFINITE_STRING;
|
return Subscription.INFINITE_STRING;
|
||||||
return Subscription.TIMEOUT_HEADER + Long.toString(time);
|
return Subscription.TIMEOUT_HEADER + Long.toString(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static long getTimeout(String headerValue)
|
public final static long getTimeout(String headerValue)
|
||||||
{
|
{
|
||||||
int minusIdx = headerValue.indexOf('-');
|
int minusIdx = headerValue.indexOf('-');
|
||||||
long timeout = Subscription.INFINITE_VALUE;
|
long timeout = Subscription.INFINITE_VALUE;
|
||||||
try {
|
try {
|
||||||
String timeoutStr = headerValue.substring(minusIdx+1, headerValue.length());
|
String timeoutStr = headerValue.substring(minusIdx+1, headerValue.length());
|
||||||
timeout = Long.parseLong(timeoutStr);
|
timeout = Long.parseLong(timeoutStr);
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
catch (Exception e) {}
|
||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SID
|
// SID
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public static final String createSID()
|
public static final String createSID()
|
||||||
{
|
{
|
||||||
return UPnP.createUUID();
|
return UPnP.createUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String toSIDHeaderString(String id)
|
public final static String toSIDHeaderString(String id)
|
||||||
{
|
{
|
||||||
return Subscription.UUID + id;
|
return Subscription.UUID + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String getSID(String headerValue)
|
public final static String getSID(String headerValue)
|
||||||
{
|
{
|
||||||
if (headerValue == null)
|
if (headerValue == null)
|
||||||
return "";
|
return "";
|
||||||
if (headerValue.startsWith(Subscription.UUID) == false)
|
if (headerValue.startsWith(Subscription.UUID) == false)
|
||||||
return headerValue;
|
return headerValue;
|
||||||
return headerValue.substring(Subscription.UUID.length(), headerValue.length());
|
return headerValue.substring(Subscription.UUID.length(), headerValue.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,221 +1,221 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SubscriptionRequest.java
|
* File: SubscriptionRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/31/03
|
* 01/31/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/21/03
|
* 05/21/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Description: inserted a check at the beginning of the setService method
|
* - 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
|
* - 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
|
* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices
|
||||||
* 09/02/03
|
* 09/02/03
|
||||||
* - Giordano Sassaroli <sassarol@cefriel.it>
|
* - Giordano Sassaroli <sassarol@cefriel.it>
|
||||||
* - Problem : NullpointerException thrown for devices whose description use absolute urls
|
* - 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
|
* - 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
|
* - Description: The method setRequestHost/setService should be changed as follows
|
||||||
* 06/11/04
|
* 06/11/04
|
||||||
* - Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004)
|
* - 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.
|
* - Changed setServie() to get the host address from the SSDP Location field when the URLBase is null.
|
||||||
* 12/06/04
|
* 12/06/04
|
||||||
* - Grzegorz Lehmann <grzegorz.lehmann@dai-labor.de>
|
* - Grzegorz Lehmann <grzegorz.lehmann@dai-labor.de>
|
||||||
* - Stefano Lenzi <kismet-sl@users.sourceforge.net>
|
* - Stefano Lenzi <kismet-sl@users.sourceforge.net>
|
||||||
* - Fixed getSID() to loop between getSID() and hasSID();
|
* - Fixed getSID() to loop between getSID() and hasSID();
|
||||||
*
|
*
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.event;
|
package org.cybergarage.upnp.event;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
import org.cybergarage.upnp.device.*;
|
import org.cybergarage.upnp.device.*;
|
||||||
|
|
||||||
public class SubscriptionRequest extends HTTPRequest
|
public class SubscriptionRequest extends HTTPRequest
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SubscriptionRequest(){
|
public SubscriptionRequest(){
|
||||||
setContentLength(0);
|
setContentLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubscriptionRequest(HTTPRequest httpReq){
|
public SubscriptionRequest(HTTPRequest httpReq){
|
||||||
this();
|
this();
|
||||||
set(httpReq);
|
set(httpReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// setRequest
|
// setRequest
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private void setService(Service service)
|
private void setService(Service service)
|
||||||
{
|
{
|
||||||
String eventSubURL = service.getEventSubURL();
|
String eventSubURL = service.getEventSubURL();
|
||||||
|
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03)
|
||||||
setURI(eventSubURL, true);
|
setURI(eventSubURL, true);
|
||||||
|
|
||||||
String urlBaseStr = "";
|
String urlBaseStr = "";
|
||||||
Device dev = service.getDevice();
|
Device dev = service.getDevice();
|
||||||
if (dev != null)
|
if (dev != null)
|
||||||
urlBaseStr = dev.getURLBase();
|
urlBaseStr = dev.getURLBase();
|
||||||
|
|
||||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||||
Device rootDev = service.getRootDevice();
|
Device rootDev = service.getRootDevice();
|
||||||
if (rootDev != null)
|
if (rootDev != null)
|
||||||
urlBaseStr = rootDev.getURLBase();
|
urlBaseStr = rootDev.getURLBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thansk for Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004)
|
// Thansk for Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004)
|
||||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||||
Device rootDev = service.getRootDevice();
|
Device rootDev = service.getRootDevice();
|
||||||
if (rootDev != null)
|
if (rootDev != null)
|
||||||
urlBaseStr = rootDev.getLocation();
|
urlBaseStr = rootDev.getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03)
|
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03)
|
||||||
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
|
||||||
if (HTTP.isAbsoluteURL(eventSubURL))
|
if (HTTP.isAbsoluteURL(eventSubURL))
|
||||||
urlBaseStr = eventSubURL;
|
urlBaseStr = eventSubURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
String reqHost = HTTP.getHost(urlBaseStr);
|
String reqHost = HTTP.getHost(urlBaseStr);
|
||||||
int reqPort = HTTP.getPort(urlBaseStr);
|
int reqPort = HTTP.getPort(urlBaseStr);
|
||||||
|
|
||||||
setHost(reqHost, reqPort);
|
setHost(reqHost, reqPort);
|
||||||
setRequestHost(reqHost);
|
setRequestHost(reqHost);
|
||||||
setRequestPort(reqPort);
|
setRequestPort(reqPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubscribeRequest(Service service, String callback, long timeout)
|
public void setSubscribeRequest(Service service, String callback, long timeout)
|
||||||
{
|
{
|
||||||
setMethod(Subscription.SUBSCRIBE_METHOD);
|
setMethod(Subscription.SUBSCRIBE_METHOD);
|
||||||
setService(service);
|
setService(service);
|
||||||
setCallback(callback);
|
setCallback(callback);
|
||||||
setNT(NT.EVENT);
|
setNT(NT.EVENT);
|
||||||
setTimeout(timeout);
|
setTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRenewRequest(Service service, String uuid, long timeout)
|
public void setRenewRequest(Service service, String uuid, long timeout)
|
||||||
{
|
{
|
||||||
setMethod(Subscription.SUBSCRIBE_METHOD);
|
setMethod(Subscription.SUBSCRIBE_METHOD);
|
||||||
setService(service);
|
setService(service);
|
||||||
setSID(uuid);
|
setSID(uuid);
|
||||||
setTimeout(timeout);
|
setTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUnsubscribeRequest(Service service)
|
public void setUnsubscribeRequest(Service service)
|
||||||
{
|
{
|
||||||
setMethod(Subscription.UNSUBSCRIBE_METHOD);
|
setMethod(Subscription.UNSUBSCRIBE_METHOD);
|
||||||
setService(service);
|
setService(service);
|
||||||
setSID(service.getSID());
|
setSID(service.getSID());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// NT
|
// NT
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setNT(String value)
|
public void setNT(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.NT, value);
|
setHeader(HTTP.NT, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNT()
|
public String getNT()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.NT);
|
return getHeaderValue(HTTP.NT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNT()
|
public boolean hasNT()
|
||||||
{
|
{
|
||||||
String nt = getNT();
|
String nt = getNT();
|
||||||
return (nt != null && 0 < nt.length()) ? true : false;
|
return (nt != null && 0 < nt.length()) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// CALLBACK
|
// CALLBACK
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private final static String CALLBACK_START_WITH = "<";
|
private final static String CALLBACK_START_WITH = "<";
|
||||||
private final static String CALLBACK_END_WITH = ">";
|
private final static String CALLBACK_END_WITH = ">";
|
||||||
|
|
||||||
public void setCallback(String value)
|
public void setCallback(String value)
|
||||||
{
|
{
|
||||||
setStringHeader(HTTP.CALLBACK, value, CALLBACK_START_WITH, CALLBACK_END_WITH);
|
setStringHeader(HTTP.CALLBACK, value, CALLBACK_START_WITH, CALLBACK_END_WITH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCallback()
|
public String getCallback()
|
||||||
{
|
{
|
||||||
return getStringHeaderValue(HTTP.CALLBACK, CALLBACK_START_WITH, CALLBACK_END_WITH);
|
return getStringHeaderValue(HTTP.CALLBACK, CALLBACK_START_WITH, CALLBACK_END_WITH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCallback()
|
public boolean hasCallback()
|
||||||
{
|
{
|
||||||
String callback = getCallback();
|
String callback = getCallback();
|
||||||
return (callback != null && 0 < callback.length()) ? true : false;
|
return (callback != null && 0 < callback.length()) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SID
|
// SID
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setSID(String id)
|
public void setSID(String id)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSID()
|
public String getSID()
|
||||||
{
|
{
|
||||||
// Thanks for Grzegorz Lehmann and Stefano Lenzi(12/06/04)
|
// Thanks for Grzegorz Lehmann and Stefano Lenzi(12/06/04)
|
||||||
String sid = Subscription.getSID(getHeaderValue(HTTP.SID));
|
String sid = Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||||
if (sid == null)
|
if (sid == null)
|
||||||
return "";
|
return "";
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSID()
|
public boolean hasSID()
|
||||||
{
|
{
|
||||||
String sid = getSID();
|
String sid = getSID();
|
||||||
return (sid != null && 0 < sid.length()) ? true : false;
|
return (sid != null && 0 < sid.length()) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Timeout
|
// Timeout
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public final void setTimeout(long value)
|
public final void setTimeout(long value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value));
|
setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimeout()
|
public long getTimeout()
|
||||||
{
|
{
|
||||||
return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT));
|
return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// post (Response)
|
// post (Response)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void post(SubscriptionResponse subRes)
|
public void post(SubscriptionResponse subRes)
|
||||||
{
|
{
|
||||||
super.post(subRes);
|
super.post(subRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// post
|
// post
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SubscriptionResponse post()
|
public SubscriptionResponse post()
|
||||||
{
|
{
|
||||||
HTTPResponse httpRes = post(getRequestHost(), getRequestPort());
|
HTTPResponse httpRes = post(getRequestHost(), getRequestPort());
|
||||||
return new SubscriptionResponse(httpRes);
|
return new SubscriptionResponse(httpRes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,84 +1,84 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SubscriptionResponse.java
|
* File: SubscriptionResponse.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/29/03
|
* 01/29/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.event;
|
package org.cybergarage.upnp.event;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
|
|
||||||
public class SubscriptionResponse extends HTTPResponse
|
public class SubscriptionResponse extends HTTPResponse
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SubscriptionResponse()
|
public SubscriptionResponse()
|
||||||
{
|
{
|
||||||
setServer(UPnP.getServerName());
|
setServer(UPnP.getServerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubscriptionResponse(HTTPResponse httpRes)
|
public SubscriptionResponse(HTTPResponse httpRes)
|
||||||
{
|
{
|
||||||
super(httpRes);
|
super(httpRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Error
|
// Error
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setResponse(int code)
|
public void setResponse(int code)
|
||||||
{
|
{
|
||||||
setStatusCode(code);
|
setStatusCode(code);
|
||||||
setContentLength(0);
|
setContentLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Error
|
// Error
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setErrorResponse(int code)
|
public void setErrorResponse(int code)
|
||||||
{
|
{
|
||||||
setStatusCode(code);
|
setStatusCode(code);
|
||||||
setContentLength(0);
|
setContentLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SID
|
// SID
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setSID(String id)
|
public void setSID(String id)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
setHeader(HTTP.SID, Subscription.toSIDHeaderString(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSID()
|
public String getSID()
|
||||||
{
|
{
|
||||||
return Subscription.getSID(getHeaderValue(HTTP.SID));
|
return Subscription.getSID(getHeaderValue(HTTP.SID));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Timeout
|
// Timeout
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setTimeout(long value)
|
public void setTimeout(long value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value));
|
setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimeout()
|
public long getTimeout()
|
||||||
{
|
{
|
||||||
return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT));
|
return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
* 08/23/07
|
* 08/23/07
|
||||||
* - Thanks for Kazuyuki Shudo
|
* - Thanks for Kazuyuki Shudo
|
||||||
* - Changed receive() to throw IOException.
|
* - 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.
|
* - 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
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: HTTPMU.java
|
* File: HTTPMU.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/20/02
|
* 11/20/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 12/12/03
|
* 12/12/03
|
||||||
* - Inma Mar?n <inma@DIF.UM.ES>
|
* - Inma Mar?n <inma@DIF.UM.ES>
|
||||||
* - Changed open(addr, port) to send IPv6 SSDP packets.
|
* - Changed open(addr, port) to send IPv6 SSDP packets.
|
||||||
@@ -20,49 +20,49 @@
|
|||||||
* - Added to set a current timestamp when the packet are received.
|
* - 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.DatagramPacket;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
import org.cybergarage.util.Debug;
|
import org.cybergarage.util.Debug;
|
||||||
|
|
||||||
public class HTTPUSocket
|
public class HTTPUSocket
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Member
|
// Member
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private DatagramSocket ssdpUniSock = null;
|
private DatagramSocket ssdpUniSock = null;
|
||||||
//private MulticastSocket ssdpUniSock = null;
|
//private MulticastSocket ssdpUniSock = null;
|
||||||
|
|
||||||
public DatagramSocket getDatagramSocket()
|
public DatagramSocket getDatagramSocket()
|
||||||
{
|
{
|
||||||
return ssdpUniSock;
|
return ssdpUniSock;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public HTTPUSocket()
|
public HTTPUSocket()
|
||||||
{
|
{
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPUSocket(String bindAddr, int bindPort)
|
public HTTPUSocket(String bindAddr, int bindPort)
|
||||||
{
|
{
|
||||||
open(bindAddr, bindPort);
|
open(bindAddr, bindPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPUSocket(int bindPort)
|
public HTTPUSocket(int bindPort)
|
||||||
{
|
{
|
||||||
open(bindPort);
|
open(bindPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void finalize()
|
protected void finalize()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
@@ -166,67 +166,67 @@ public class HTTPUSocket
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// close
|
// close
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public boolean close()
|
|
||||||
{
|
|
||||||
if (ssdpUniSock == null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
ssdpUniSock.close();
|
|
||||||
ssdpUniSock = null;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Debug.warning(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
public boolean close()
|
||||||
// send
|
{
|
||||||
////////////////////////////////////////////////
|
if (ssdpUniSock == null)
|
||||||
|
return true;
|
||||||
public boolean post(String addr, int port, String msg)
|
|
||||||
{
|
try {
|
||||||
try {
|
ssdpUniSock.close();
|
||||||
InetAddress inetAddr = InetAddress.getByName(addr);
|
ssdpUniSock = null;
|
||||||
DatagramPacket dgmPacket = new DatagramPacket(msg.getBytes(), msg.length(), inetAddr, port);
|
}
|
||||||
ssdpUniSock.send(dgmPacket);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
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("port = " + ssdpUniSock.getLocalPort());
|
||||||
Debug.warning(e);
|
Debug.warning(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// reveive
|
// reveive
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SSDPPacket receive()
|
public SSDPPacket receive()
|
||||||
{
|
{
|
||||||
byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE];
|
byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE];
|
||||||
SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length);
|
SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length);
|
||||||
recvPacket.setLocalAddress(getLocalAddress());
|
recvPacket.setLocalAddress(getLocalAddress());
|
||||||
try {
|
try {
|
||||||
ssdpUniSock.receive(recvPacket.getDatagramPacket());
|
ssdpUniSock.receive(recvPacket.getDatagramPacket());
|
||||||
recvPacket.setTimeStamp(System.currentTimeMillis());
|
recvPacket.setTimeStamp(System.currentTimeMillis());
|
||||||
Debug.message("Received SSDP unicast packet on " + getLocalAddress() + " from " + recvPacket.getRemoteAddress());
|
Debug.message("Received SSDP unicast packet on " + getLocalAddress() + " from " + recvPacket.getRemoteAddress());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
//Debug.warning(e);
|
//Debug.warning(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return recvPacket;
|
return recvPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// join/leave
|
// join/leave
|
||||||
@@ -261,5 +261,5 @@ public class HTTPUSocket
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,31 +1,31 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SSDPMSearchRequest.java
|
* File: SSDPMSearchRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/14/03
|
* 01/14/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.ssdp;
|
package org.cybergarage.upnp.ssdp;
|
||||||
|
|
||||||
import org.cybergarage.http.HTTP;
|
import org.cybergarage.http.HTTP;
|
||||||
|
|
||||||
public class SSDPNotifyRequest extends SSDPRequest
|
public class SSDPNotifyRequest extends SSDPRequest
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SSDPNotifyRequest()
|
public SSDPNotifyRequest()
|
||||||
{
|
{
|
||||||
setMethod(HTTP.NOTIFY);
|
setMethod(HTTP.NOTIFY);
|
||||||
setURI("*");
|
setURI("*");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: SSDPPacket.java
|
* File: SSDPPacket.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/18/02
|
* 11/18/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 05/13/03
|
* 05/13/03
|
||||||
* - Added getLocalAddress().
|
* - Added getLocalAddress().
|
||||||
* 11/01/04
|
* 11/01/04
|
||||||
@@ -20,25 +20,25 @@
|
|||||||
* - Changed getRemoteAddress() to return the adresss instead of the host name.
|
* - Changed getRemoteAddress() to return the adresss instead of the host name.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.ssdp;
|
package org.cybergarage.upnp.ssdp;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.device.*;
|
import org.cybergarage.upnp.device.*;
|
||||||
|
|
||||||
public class SSDPPacket
|
public class SSDPPacket
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SSDPPacket(byte[] buf, int length)
|
public SSDPPacket(byte[] buf, int length)
|
||||||
{
|
{
|
||||||
dgmPacket = new DatagramPacket(buf, length);
|
dgmPacket = new DatagramPacket(buf, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// DatagramPacket
|
// DatagramPacket
|
||||||
@@ -68,115 +68,115 @@ public class SSDPPacket
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Time
|
// Time
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private long timeStamp;
|
private long timeStamp;
|
||||||
|
|
||||||
public void setTimeStamp(long value)
|
public void setTimeStamp(long value)
|
||||||
{
|
{
|
||||||
timeStamp = value;
|
timeStamp = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimeStamp()
|
public long getTimeStamp()
|
||||||
{
|
{
|
||||||
return timeStamp;
|
return timeStamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Remote host
|
// Remote host
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public InetAddress getRemoteInetAddress()
|
public InetAddress getRemoteInetAddress()
|
||||||
{
|
{
|
||||||
return getDatagramPacket().getAddress();
|
return getDatagramPacket().getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRemoteAddress()
|
public String getRemoteAddress()
|
||||||
{
|
{
|
||||||
// Thanks for Theo Beisch (11/09/04)
|
// Thanks for Theo Beisch (11/09/04)
|
||||||
return getDatagramPacket().getAddress().getHostAddress();
|
return getDatagramPacket().getAddress().getHostAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRemotePort()
|
public int getRemotePort()
|
||||||
{
|
{
|
||||||
return getDatagramPacket().getPort();
|
return getDatagramPacket().getPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Access Methods
|
// Access Methods
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public byte[] packetBytes = null;
|
public byte[] packetBytes = null;
|
||||||
|
|
||||||
public byte[] getData()
|
public byte[] getData()
|
||||||
{
|
{
|
||||||
if (packetBytes != null)
|
if (packetBytes != null)
|
||||||
return packetBytes;
|
return packetBytes;
|
||||||
|
|
||||||
DatagramPacket packet = getDatagramPacket();
|
DatagramPacket packet = getDatagramPacket();
|
||||||
int packetLen = packet.getLength();
|
int packetLen = packet.getLength();
|
||||||
String packetData = new String(packet.getData(), 0, packetLen);
|
String packetData = new String(packet.getData(), 0, packetLen);
|
||||||
packetBytes = packetData.getBytes();
|
packetBytes = packetData.getBytes();
|
||||||
|
|
||||||
return packetBytes;
|
return packetBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Access Methods
|
// Access Methods
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public String getHost()
|
public String getHost()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.HOST);
|
return HTTPHeader.getValue(getData(), HTTP.HOST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCacheControl()
|
public String getCacheControl()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.CACHE_CONTROL);
|
return HTTPHeader.getValue(getData(), HTTP.CACHE_CONTROL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocation()
|
public String getLocation()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.LOCATION);
|
return HTTPHeader.getValue(getData(), HTTP.LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMAN()
|
public String getMAN()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.MAN);
|
return HTTPHeader.getValue(getData(), HTTP.MAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getST()
|
public String getST()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.ST);
|
return HTTPHeader.getValue(getData(), HTTP.ST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNT()
|
public String getNT()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.NT);
|
return HTTPHeader.getValue(getData(), HTTP.NT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNTS()
|
public String getNTS()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.NTS);
|
return HTTPHeader.getValue(getData(), HTTP.NTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServer()
|
public String getServer()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.SERVER);
|
return HTTPHeader.getValue(getData(), HTTP.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUSN()
|
public String getUSN()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getValue(getData(), HTTP.USN);
|
return HTTPHeader.getValue(getData(), HTTP.USN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMX()
|
public int getMX()
|
||||||
{
|
{
|
||||||
return HTTPHeader.getIntegerValue(getData(), HTTP.MX);
|
return HTTPHeader.getIntegerValue(getData(), HTTP.MX);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Access Methods
|
// Access Methods
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -197,39 +197,39 @@ public class SSDPPacket
|
|||||||
return isockaddr.getAddress();
|
return isockaddr.getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Access Methods (Extension)
|
// Access Methods (Extension)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public boolean isRootDevice()
|
public boolean isRootDevice()
|
||||||
{
|
{
|
||||||
if (NT.isRootDevice(getNT()) == true)
|
if (NT.isRootDevice(getNT()) == true)
|
||||||
return true;
|
return true;
|
||||||
// Thanks for Theo Beisch (11/01/04)
|
// Thanks for Theo Beisch (11/01/04)
|
||||||
if (ST.isRootDevice(getST()) == true)
|
if (ST.isRootDevice(getST()) == true)
|
||||||
return true;
|
return true;
|
||||||
return USN.isRootDevice(getUSN());
|
return USN.isRootDevice(getUSN());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDiscover()
|
public boolean isDiscover()
|
||||||
{
|
{
|
||||||
return MAN.isDiscover(getMAN());
|
return MAN.isDiscover(getMAN());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlive()
|
public boolean isAlive()
|
||||||
{
|
{
|
||||||
return NTS.isAlive(getNTS());
|
return NTS.isAlive(getNTS());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isByeBye()
|
public boolean isByeBye()
|
||||||
{
|
{
|
||||||
return NTS.isByeBye(getNTS());
|
return NTS.isByeBye(getNTS());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeaseTime()
|
public int getLeaseTime()
|
||||||
{
|
{
|
||||||
return SSDP.getLeaseTime(getCacheControl());
|
return SSDP.getLeaseTime(getCacheControl());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// toString
|
// toString
|
||||||
@@ -240,4 +240,4 @@ public class SSDPPacket
|
|||||||
return new String(getData());
|
return new String(getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,111 +1,125 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SSDPRequest.java
|
* File: SSDPRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/14/03
|
* 01/14/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 03/16/04
|
* 03/16/04
|
||||||
* - Thanks for Darrell Young
|
* - Thanks for Darrell Young
|
||||||
* - Fixed to set v1.1 to the HTTP version.;
|
* - Fixed to set v1.1 to the HTTP version.;
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.ssdp;
|
package org.cybergarage.upnp.ssdp;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
|
|
||||||
public class SSDPRequest extends HTTPRequest
|
public class SSDPRequest extends HTTPRequest
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SSDPRequest()
|
public SSDPRequest()
|
||||||
{
|
{
|
||||||
setVersion(HTTP.VERSION_11);
|
setVersion(HTTP.VERSION_11);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSDPRequest(InputStream in)
|
public SSDPRequest(InputStream in)
|
||||||
{
|
{
|
||||||
super(in);
|
super(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// NT
|
// NT
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setNT(String value)
|
public void setNT(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.NT, value);
|
setHeader(HTTP.NT, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNT()
|
public String getNT()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.NT);
|
return getHeaderValue(HTTP.NT);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// NTS
|
// NTS
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setNTS(String value)
|
public void setNTS(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.NTS, value);
|
setHeader(HTTP.NTS, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNTS()
|
public String getNTS()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.NTS);
|
return getHeaderValue(HTTP.NTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Location
|
// Location
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setLocation(String value)
|
public void setLocation(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.LOCATION, value);
|
setHeader(HTTP.LOCATION, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocation()
|
public String getLocation()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.LOCATION);
|
return getHeaderValue(HTTP.LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// USN
|
// USN
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setUSN(String value)
|
public void setUSN(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.USN, value);
|
setHeader(HTTP.USN, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUSN()
|
public String getUSN()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.USN);
|
return getHeaderValue(HTTP.USN);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// CacheControl
|
// CacheControl
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setLeaseTime(int len)
|
public void setLeaseTime(int len)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len));
|
setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeaseTime()
|
public int getLeaseTime()
|
||||||
{
|
{
|
||||||
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
|
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
|
||||||
return SSDP.getLeaseTime(cacheCtrl);
|
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
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SSDPResponse.java
|
* File: SSDPResponse.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/14/03
|
* 01/14/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 01/23/04
|
* 01/23/04
|
||||||
* - Oliver Newell
|
* - Oliver Newell
|
||||||
* - Overided HTTPResponse::getHeader() for Intel UPnP control points.
|
* - Overided HTTPResponse::getHeader() for Intel UPnP control points.
|
||||||
* 03/16/04
|
* 03/16/04
|
||||||
* - Thanks for Darrell Young
|
* - Thanks for Darrell Young
|
||||||
* - Fixed to set v1.1 to the HTTP version.
|
* - Fixed to set v1.1 to the HTTP version.
|
||||||
* 10/20/04
|
* 10/20/04
|
||||||
* - Brent Hills <bhills@openshores.com>
|
* - Brent Hills <bhills@openshores.com>
|
||||||
* - Added setMYNAME() and getMYNAME().
|
* - Added setMYNAME() and getMYNAME().
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.ssdp;
|
package org.cybergarage.upnp.ssdp;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
|
|
||||||
public class SSDPResponse extends HTTPResponse
|
public class SSDPResponse extends HTTPResponse
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SSDPResponse()
|
public SSDPResponse()
|
||||||
{
|
{
|
||||||
setVersion(HTTP.VERSION_11);
|
setVersion(HTTP.VERSION_11);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSDPResponse(InputStream in)
|
public SSDPResponse(InputStream in)
|
||||||
{
|
{
|
||||||
super(in);
|
super(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// ST (SearchTarget)
|
// ST (SearchTarget)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setST(String value)
|
public void setST(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.ST, value);
|
setHeader(HTTP.ST, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getST()
|
public String getST()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.ST);
|
return getHeaderValue(HTTP.ST);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Location
|
// Location
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setLocation(String value)
|
public void setLocation(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.LOCATION, value);
|
setHeader(HTTP.LOCATION, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocation()
|
public String getLocation()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.LOCATION);
|
return getHeaderValue(HTTP.LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// USN
|
// USN
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setUSN(String value)
|
public void setUSN(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.USN, value);
|
setHeader(HTTP.USN, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUSN()
|
public String getUSN()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.USN);
|
return getHeaderValue(HTTP.USN);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// MYNAME
|
// MYNAME
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setMYNAME(String value)
|
public void setMYNAME(String value)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.MYNAME, value);
|
setHeader(HTTP.MYNAME, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMYNAME()
|
public String getMYNAME()
|
||||||
{
|
{
|
||||||
return getHeaderValue(HTTP.MYNAME);
|
return getHeaderValue(HTTP.MYNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// CacheControl
|
// CacheControl
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setLeaseTime(int len)
|
public void setLeaseTime(int len)
|
||||||
{
|
{
|
||||||
setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len));
|
setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeaseTime()
|
public int getLeaseTime()
|
||||||
{
|
{
|
||||||
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
|
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
|
||||||
return SSDP.getLeaseTime(cacheCtrl);
|
return SSDP.getLeaseTime(cacheCtrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// getHeader (Override)
|
// BootId
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public String getHeader()
|
public void setBootId(int bootId)
|
||||||
{
|
{
|
||||||
StringBuffer str = new StringBuffer();
|
setHeader(HTTP.BOOTID_UPNP_ORG, bootId);
|
||||||
|
}
|
||||||
str.append(getStatusLineString());
|
|
||||||
str.append(getHeaderString());
|
public int getBootId()
|
||||||
str.append(HTTP.CRLF); // for Intel UPnP control points.
|
{
|
||||||
|
return getIntegerHeaderValue(HTTP.BOOTID_UPNP_ORG);
|
||||||
return str.toString();
|
}
|
||||||
}
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
}
|
// 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
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SSDPMSearchRequest.java
|
* File: SSDPMSearchRequest.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 11/19/02
|
* 11/19/02
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.ssdp;
|
package org.cybergarage.upnp.ssdp;
|
||||||
|
|
||||||
import org.cybergarage.net.*;
|
import org.cybergarage.net.*;
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.device.*;
|
import org.cybergarage.upnp.device.*;
|
||||||
|
|
||||||
public class SSDPSearchRequest extends SSDPRequest
|
public class SSDPSearchRequest extends SSDPRequest
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SSDPSearchRequest(String serachTarget, int mx)
|
public SSDPSearchRequest(String serachTarget, int mx)
|
||||||
{
|
{
|
||||||
@@ -35,16 +35,16 @@ public class SSDPSearchRequest extends SSDPRequest
|
|||||||
setHeader(HTTP.MX, Integer.toString(mx));
|
setHeader(HTTP.MX, Integer.toString(mx));
|
||||||
setHeader(HTTP.MAN, "\"" + MAN.DISCOVER + "\"");
|
setHeader(HTTP.MAN, "\"" + MAN.DISCOVER + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSDPSearchRequest(String serachTarget)
|
public SSDPSearchRequest(String serachTarget)
|
||||||
{
|
{
|
||||||
this(serachTarget, SSDP.DEFAULT_MSEARCH_MX);
|
this(serachTarget, SSDP.DEFAULT_MSEARCH_MX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SSDPSearchRequest()
|
public SSDPSearchRequest()
|
||||||
{
|
{
|
||||||
this(ST.ROOT_DEVICE);
|
this(ST.ROOT_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// HOST
|
// HOST
|
||||||
|
@@ -5,31 +5,31 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* File: SSDPSearchResponse.java
|
* File: SSDPSearchResponse.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/14/03
|
* 01/14/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.ssdp;
|
package org.cybergarage.upnp.ssdp;
|
||||||
|
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
|
|
||||||
public class SSDPSearchResponse extends SSDPResponse
|
public class SSDPSearchResponse extends SSDPResponse
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public SSDPSearchResponse()
|
public SSDPSearchResponse()
|
||||||
{
|
{
|
||||||
setStatusCode(HTTPStatus.OK);
|
setStatusCode(HTTPStatus.OK);
|
||||||
setCacheControl(Device.DEFAULT_LEASE_TIME);
|
setCacheControl(Device.DEFAULT_LEASE_TIME);
|
||||||
setHeader(HTTP.SERVER, UPnP.getServerName());
|
setHeader(HTTP.SERVER, UPnP.getServerName());
|
||||||
setHeader(HTTP.EXT, "");
|
setHeader(HTTP.EXT, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
* 08/23/07
|
* 08/23/07
|
||||||
* - Thanks for Kazuyuki Shudo
|
* - Thanks for Kazuyuki Shudo
|
||||||
* - Changed run() to catch IOException of HTTPMUSocket::receive().
|
* - 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.
|
* - 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;
|
this.multicastIPv6 = multicastIPv6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Methods
|
// Methods
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
@@ -1,57 +1,57 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: ActionData.java
|
* File: ActionData.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 03/28/03
|
* 03/28/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.xml;
|
package org.cybergarage.upnp.xml;
|
||||||
|
|
||||||
import org.cybergarage.upnp.control.*;
|
import org.cybergarage.upnp.control.*;
|
||||||
|
|
||||||
public class ActionData extends NodeData
|
public class ActionData extends NodeData
|
||||||
{
|
{
|
||||||
public ActionData()
|
public ActionData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// ActionListener
|
// ActionListener
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private ActionListener actionListener = null;
|
private ActionListener actionListener = null;
|
||||||
|
|
||||||
public ActionListener getActionListener() {
|
public ActionListener getActionListener() {
|
||||||
return actionListener;
|
return actionListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActionListener(ActionListener actionListener) {
|
public void setActionListener(ActionListener actionListener) {
|
||||||
this.actionListener = actionListener;
|
this.actionListener = actionListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// ControlResponse
|
// ControlResponse
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private ControlResponse ctrlRes = null;
|
private ControlResponse ctrlRes = null;
|
||||||
|
|
||||||
public ControlResponse getControlResponse()
|
public ControlResponse getControlResponse()
|
||||||
{
|
{
|
||||||
return ctrlRes;
|
return ctrlRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setControlResponse(ControlResponse res)
|
public void setControlResponse(ControlResponse res)
|
||||||
{
|
{
|
||||||
ctrlRes = res;
|
ctrlRes = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,271 +1,271 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: DeviceData.java
|
* File: DeviceData.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 03/28/03
|
* 03/28/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 12/25/03
|
* 12/25/03
|
||||||
* - Added Advertiser functions.
|
* - Added Advertiser functions.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.xml;
|
package org.cybergarage.upnp.xml;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
|
||||||
import org.cybergarage.util.*;
|
import org.cybergarage.util.*;
|
||||||
import org.cybergarage.http.*;
|
import org.cybergarage.http.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.*;
|
import org.cybergarage.upnp.*;
|
||||||
import org.cybergarage.upnp.ssdp.*;
|
import org.cybergarage.upnp.ssdp.*;
|
||||||
import org.cybergarage.upnp.device.*;
|
import org.cybergarage.upnp.device.*;
|
||||||
|
|
||||||
public class DeviceData extends NodeData
|
public class DeviceData extends NodeData
|
||||||
{
|
{
|
||||||
public DeviceData()
|
public DeviceData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// description
|
// description
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String descriptionURI = null;
|
private String descriptionURI = null;
|
||||||
private File descriptionFile = null;
|
private File descriptionFile = null;
|
||||||
|
|
||||||
public File getDescriptionFile() {
|
public File getDescriptionFile() {
|
||||||
return descriptionFile;
|
return descriptionFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescriptionURI() {
|
public String getDescriptionURI() {
|
||||||
return descriptionURI;
|
return descriptionURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescriptionFile(File descriptionFile) {
|
public void setDescriptionFile(File descriptionFile) {
|
||||||
this.descriptionFile = descriptionFile;
|
this.descriptionFile = descriptionFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescriptionURI(String descriptionURI) {
|
public void setDescriptionURI(String descriptionURI) {
|
||||||
this.descriptionURI = descriptionURI;
|
this.descriptionURI = descriptionURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// description
|
// description
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String location = "";
|
private String location = "";
|
||||||
|
|
||||||
public String getLocation() {
|
public String getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(String location) {
|
public void setLocation(String location) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// LeaseTime
|
// LeaseTime
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private int leaseTime = Device.DEFAULT_LEASE_TIME;
|
private int leaseTime = Device.DEFAULT_LEASE_TIME;
|
||||||
|
|
||||||
public int getLeaseTime()
|
public int getLeaseTime()
|
||||||
{
|
{
|
||||||
return leaseTime;
|
return leaseTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLeaseTime(int val)
|
public void setLeaseTime(int val)
|
||||||
{
|
{
|
||||||
leaseTime = val;
|
leaseTime = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// HTTPServer
|
// HTTPServer
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private HTTPServerList httpServerList = null;
|
private HTTPServerList httpServerList = null;
|
||||||
|
|
||||||
public HTTPServerList getHTTPServerList() {
|
public HTTPServerList getHTTPServerList() {
|
||||||
if(this.httpServerList==null){
|
if(this.httpServerList==null){
|
||||||
this.httpServerList = new HTTPServerList(this.httpBinds,this.httpPort);
|
this.httpServerList = new HTTPServerList(this.httpBinds,this.httpPort);
|
||||||
}
|
}
|
||||||
return this.httpServerList;
|
return this.httpServerList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InetAddress[] httpBinds = null;
|
private InetAddress[] httpBinds = null;
|
||||||
|
|
||||||
public void setHTTPBindAddress(InetAddress[] inets){
|
public void setHTTPBindAddress(InetAddress[] inets){
|
||||||
this.httpBinds=inets;
|
this.httpBinds=inets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetAddress[] getHTTPBindAddress(){
|
public InetAddress[] getHTTPBindAddress(){
|
||||||
return this.httpBinds;
|
return this.httpBinds;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// httpPort
|
// httpPort
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private int httpPort = Device.HTTP_DEFAULT_PORT;
|
private int httpPort = Device.HTTP_DEFAULT_PORT;
|
||||||
|
|
||||||
public int getHTTPPort() {
|
public int getHTTPPort() {
|
||||||
return httpPort;
|
return httpPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHTTPPort(int port) {
|
public void setHTTPPort(int port) {
|
||||||
httpPort = port;
|
httpPort = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// controlActionListenerList
|
// controlActionListenerList
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private ListenerList controlActionListenerList = new ListenerList();
|
private ListenerList controlActionListenerList = new ListenerList();
|
||||||
|
|
||||||
public ListenerList getControlActionListenerList() {
|
public ListenerList getControlActionListenerList() {
|
||||||
return controlActionListenerList;
|
return controlActionListenerList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public void setControlActionListenerList(ListenerList controlActionListenerList) {
|
public void setControlActionListenerList(ListenerList controlActionListenerList) {
|
||||||
this.controlActionListenerList = controlActionListenerList;
|
this.controlActionListenerList = controlActionListenerList;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SSDPSearchSocket
|
// SSDPSearchSocket
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private SSDPSearchSocketList ssdpSearchSocketList = null;
|
private SSDPSearchSocketList ssdpSearchSocketList = null;
|
||||||
private String ssdpMulticastIPv4 = SSDP.ADDRESS;
|
private String ssdpMulticastIPv4 = SSDP.ADDRESS;
|
||||||
private String ssdpMulticastIPv6 = SSDP.getIPv6Address();
|
private String ssdpMulticastIPv6 = SSDP.getIPv6Address();
|
||||||
private int ssdpPort = SSDP.PORT;
|
private int ssdpPort = SSDP.PORT;
|
||||||
private InetAddress[] ssdpBinds = null;
|
private InetAddress[] ssdpBinds = null;
|
||||||
|
|
||||||
public SSDPSearchSocketList getSSDPSearchSocketList() {
|
public SSDPSearchSocketList getSSDPSearchSocketList() {
|
||||||
if(this.ssdpSearchSocketList==null){
|
if(this.ssdpSearchSocketList==null){
|
||||||
this.ssdpSearchSocketList = new SSDPSearchSocketList(this.ssdpBinds,ssdpPort,ssdpMulticastIPv4,ssdpMulticastIPv6);
|
this.ssdpSearchSocketList = new SSDPSearchSocketList(this.ssdpBinds,ssdpPort,ssdpMulticastIPv4,ssdpMulticastIPv6);
|
||||||
}
|
}
|
||||||
return ssdpSearchSocketList;
|
return ssdpSearchSocketList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param port The port to use for binding the SSDP service.
|
* @param port The port to use for binding the SSDP service.
|
||||||
* The port will be used as source port for all SSDP messages
|
* The port will be used as source port for all SSDP messages
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public void setSSDPPort(int port){
|
public void setSSDPPort(int port){
|
||||||
this.ssdpPort=port;
|
this.ssdpPort=port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return The port used for binding the SSDP service.
|
* @return The port used for binding the SSDP service.
|
||||||
* The port will be used as source port for all SSDP messages
|
* The port will be used as source port for all SSDP messages
|
||||||
*/
|
*/
|
||||||
public int getSSDPPort(){
|
public int getSSDPPort(){
|
||||||
return this.ssdpPort;
|
return this.ssdpPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param inets The <tt>InetAddress</tt> that will be binded for listing this service.
|
* @param inets The <tt>InetAddress</tt> that will be binded for listing this service.
|
||||||
* Use <code>null</code> for the default behaviur.
|
* Use <code>null</code> for the default behaviur.
|
||||||
* @see org.cybergarage.upnp.ssdp
|
* @see org.cybergarage.upnp.ssdp
|
||||||
* @see org.cybergarage.upnp
|
* @see org.cybergarage.upnp
|
||||||
* @see org.cybergarage.net.HostInterface
|
* @see org.cybergarage.net.HostInterface
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public void setSSDPBindAddress(InetAddress[] inets){
|
public void setSSDPBindAddress(InetAddress[] inets){
|
||||||
this.ssdpBinds=inets;
|
this.ssdpBinds=inets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return inets The <tt>InetAddress</tt> that will be binded for this service
|
* @return inets The <tt>InetAddress</tt> that will be binded for this service
|
||||||
* <code>null</code> means that defulat behaviur will be used
|
* <code>null</code> means that defulat behaviur will be used
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public InetAddress[] getSSDPBindAddress(){
|
public InetAddress[] getSSDPBindAddress(){
|
||||||
return this.ssdpBinds;
|
return this.ssdpBinds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param ip The IPv4 address used as destination address for Multicast comunication
|
* @param ip The IPv4 address used as destination address for Multicast comunication
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public void setMulticastIPv4Address(String ip){
|
public void setMulticastIPv4Address(String ip){
|
||||||
this.ssdpMulticastIPv4=ip;
|
this.ssdpMulticastIPv4=ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return The IPv4 address used for Multicast comunication
|
* @return The IPv4 address used for Multicast comunication
|
||||||
*/
|
*/
|
||||||
public String getMulticastIPv4Address(){
|
public String getMulticastIPv4Address(){
|
||||||
return this.ssdpMulticastIPv4;
|
return this.ssdpMulticastIPv4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param ip The IPv6 address used as destination address for Multicast comunication
|
* @param ip The IPv6 address used as destination address for Multicast comunication
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public void setMulticastIPv6Address(String ip){
|
public void setMulticastIPv6Address(String ip){
|
||||||
this.ssdpMulticastIPv6=ip;
|
this.ssdpMulticastIPv6=ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return The IPv6 address used as destination address for Multicast comunication
|
* @return The IPv6 address used as destination address for Multicast comunication
|
||||||
* @since 1.8
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public String getMulticastIPv6Address(){
|
public String getMulticastIPv6Address(){
|
||||||
return this.ssdpMulticastIPv6;
|
return this.ssdpMulticastIPv6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SSDPPacket
|
// SSDPPacket
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private SSDPPacket ssdpPacket = null;
|
private SSDPPacket ssdpPacket = null;
|
||||||
|
|
||||||
public SSDPPacket getSSDPPacket() {
|
public SSDPPacket getSSDPPacket() {
|
||||||
return ssdpPacket;
|
return ssdpPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSSDPPacket(SSDPPacket packet) {
|
public void setSSDPPacket(SSDPPacket packet) {
|
||||||
ssdpPacket = packet;
|
ssdpPacket = packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Advertiser
|
// Advertiser
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Advertiser advertiser = null;
|
private Advertiser advertiser = null;
|
||||||
|
|
||||||
public void setAdvertiser(Advertiser adv)
|
public void setAdvertiser(Advertiser adv)
|
||||||
{
|
{
|
||||||
advertiser = adv;
|
advertiser = adv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Advertiser getAdvertiser()
|
public Advertiser getAdvertiser()
|
||||||
{
|
{
|
||||||
return advertiser;
|
return advertiser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,43 +1,43 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: ActionData.java
|
* File: ActionData.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 03/28/03
|
* 03/28/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.xml;
|
package org.cybergarage.upnp.xml;
|
||||||
|
|
||||||
import org.cybergarage.xml.*;
|
import org.cybergarage.xml.*;
|
||||||
|
|
||||||
public class NodeData
|
public class NodeData
|
||||||
{
|
{
|
||||||
public NodeData()
|
public NodeData()
|
||||||
{
|
{
|
||||||
setNode(null);
|
setNode(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Node
|
// Node
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node node;
|
private Node node;
|
||||||
|
|
||||||
public void setNode(Node node)
|
public void setNode(Node node)
|
||||||
{
|
{
|
||||||
this.node = node;
|
this.node = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node getNode()
|
public Node getNode()
|
||||||
{
|
{
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,112 +1,112 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: ServiceData.java
|
* File: ServiceData.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 03/28/03
|
* 03/28/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 01/06/04
|
* 01/06/04
|
||||||
* - Moved setQueryListener() and getQueryListener() to StateVariableData class.
|
* - Moved setQueryListener() and getQueryListener() to StateVariableData class.
|
||||||
* 03/30/05
|
* 03/30/05
|
||||||
* - Removed setDescriptionURL() and getDescriptionURL().
|
* - Removed setDescriptionURL() and getDescriptionURL().
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.xml;
|
package org.cybergarage.upnp.xml;
|
||||||
|
|
||||||
import org.cybergarage.util.*;
|
import org.cybergarage.util.*;
|
||||||
import org.cybergarage.xml.*;
|
import org.cybergarage.xml.*;
|
||||||
|
|
||||||
import org.cybergarage.upnp.event.*;
|
import org.cybergarage.upnp.event.*;
|
||||||
|
|
||||||
public class ServiceData extends NodeData
|
public class ServiceData extends NodeData
|
||||||
{
|
{
|
||||||
public ServiceData()
|
public ServiceData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// controlActionListenerList
|
// controlActionListenerList
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private ListenerList controlActionListenerList = new ListenerList();
|
private ListenerList controlActionListenerList = new ListenerList();
|
||||||
|
|
||||||
public ListenerList getControlActionListenerList() {
|
public ListenerList getControlActionListenerList() {
|
||||||
return controlActionListenerList;
|
return controlActionListenerList;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// scpdNode
|
// scpdNode
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private Node scpdNode = null;
|
private Node scpdNode = null;
|
||||||
|
|
||||||
public Node getSCPDNode() {
|
public Node getSCPDNode() {
|
||||||
return scpdNode;
|
return scpdNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSCPDNode(Node node) {
|
public void setSCPDNode(Node node) {
|
||||||
scpdNode = node;
|
scpdNode = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SubscriberList
|
// SubscriberList
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private SubscriberList subscriberList = new SubscriberList();
|
private SubscriberList subscriberList = new SubscriberList();
|
||||||
|
|
||||||
public SubscriberList getSubscriberList() {
|
public SubscriberList getSubscriberList() {
|
||||||
return subscriberList;
|
return subscriberList;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SID
|
// SID
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String descriptionURL = "";
|
private String descriptionURL = "";
|
||||||
|
|
||||||
public String getDescriptionURL() {
|
public String getDescriptionURL() {
|
||||||
return descriptionURL;
|
return descriptionURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescriptionURL(String descriptionURL) {
|
public void setDescriptionURL(String descriptionURL) {
|
||||||
this.descriptionURL = descriptionURL;
|
this.descriptionURL = descriptionURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// SID
|
// SID
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String sid = "";
|
private String sid = "";
|
||||||
|
|
||||||
public String getSID() {
|
public String getSID() {
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSID(String id) {
|
public void setSID(String id) {
|
||||||
sid = id;
|
sid = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Timeout
|
// Timeout
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private long timeout = 0;
|
private long timeout = 0;
|
||||||
|
|
||||||
public long getTimeout()
|
public long getTimeout()
|
||||||
{
|
{
|
||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeout(long value)
|
public void setTimeout(long value)
|
||||||
{
|
{
|
||||||
timeout = value;
|
timeout = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,73 +1,73 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUPnP for Java
|
* CyberUPnP for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File:StateVariableData.java
|
* File:StateVariableData.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 02/05/03
|
* 02/05/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 01/06/04
|
* 01/06/04
|
||||||
* - Added setQueryListener() and getQueryListener().
|
* - Added setQueryListener() and getQueryListener().
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.upnp.xml;
|
package org.cybergarage.upnp.xml;
|
||||||
|
|
||||||
import org.cybergarage.upnp.control.*;
|
import org.cybergarage.upnp.control.*;
|
||||||
|
|
||||||
public class StateVariableData extends NodeData
|
public class StateVariableData extends NodeData
|
||||||
{
|
{
|
||||||
public StateVariableData()
|
public StateVariableData()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// value
|
// value
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private String value = "";
|
private String value = "";
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// QueryListener
|
// QueryListener
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private QueryListener queryListener = null;
|
private QueryListener queryListener = null;
|
||||||
|
|
||||||
public QueryListener getQueryListener() {
|
public QueryListener getQueryListener() {
|
||||||
return queryListener;
|
return queryListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQueryListener(QueryListener queryListener) {
|
public void setQueryListener(QueryListener queryListener) {
|
||||||
this.queryListener = queryListener;
|
this.queryListener = queryListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// QueryResponse
|
// QueryResponse
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private QueryResponse queryRes = null;
|
private QueryResponse queryRes = null;
|
||||||
|
|
||||||
public QueryResponse getQueryResponse()
|
public QueryResponse getQueryResponse()
|
||||||
{
|
{
|
||||||
return queryRes;
|
return queryRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQueryResponse(QueryResponse res)
|
public void setQueryResponse(QueryResponse res)
|
||||||
{
|
{
|
||||||
queryRes = res;
|
queryRes = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,80 +1,79 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUtil for Java
|
* CyberUtil for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: FileUtil.java
|
* File: FileUtil.java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Revision:
|
||||||
*
|
*
|
||||||
* 01/03/03
|
* 01/03/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.util;
|
package org.cybergarage.util;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.util.Locale;
|
|
||||||
|
public final class FileUtil
|
||||||
public final class FileUtil
|
{
|
||||||
{
|
public final static byte[] load(String fileName)
|
||||||
public final static byte[] load(String fileName)
|
{
|
||||||
{
|
try {
|
||||||
try {
|
FileInputStream fin=new FileInputStream(fileName);
|
||||||
FileInputStream fin=new FileInputStream(fileName);
|
return load(fin);
|
||||||
return load(fin);
|
}
|
||||||
}
|
catch (Exception e) {
|
||||||
catch (Exception e) {
|
Debug.warning(e);
|
||||||
Debug.warning(e);
|
return new byte[0];
|
||||||
return new byte[0];
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public final static byte[] load(File file)
|
||||||
public final static byte[] load(File file)
|
{
|
||||||
{
|
try {
|
||||||
try {
|
FileInputStream fin=new FileInputStream(file);
|
||||||
FileInputStream fin=new FileInputStream(file);
|
return load(fin);
|
||||||
return load(fin);
|
}
|
||||||
}
|
catch (Exception e) {
|
||||||
catch (Exception e) {
|
Debug.warning(e);
|
||||||
Debug.warning(e);
|
return new byte[0];
|
||||||
return new byte[0];
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public final static byte[] load(FileInputStream fin)
|
||||||
public final static byte[] load(FileInputStream fin)
|
{
|
||||||
{
|
byte readBuf[] = new byte[512*1024];
|
||||||
byte readBuf[] = new byte[512*1024];
|
|
||||||
|
try {
|
||||||
try {
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
|
||||||
|
int readCnt = fin.read(readBuf);
|
||||||
int readCnt = fin.read(readBuf);
|
while (0 < readCnt) {
|
||||||
while (0 < readCnt) {
|
bout.write(readBuf, 0, readCnt);
|
||||||
bout.write(readBuf, 0, readCnt);
|
readCnt = fin.read(readBuf);
|
||||||
readCnt = fin.read(readBuf);
|
}
|
||||||
}
|
|
||||||
|
fin.close();
|
||||||
fin.close();
|
|
||||||
|
return bout.toByteArray();
|
||||||
return bout.toByteArray();
|
}
|
||||||
}
|
catch (Exception e) {
|
||||||
catch (Exception e) {
|
Debug.warning(e);
|
||||||
Debug.warning(e);
|
return new byte[0];
|
||||||
return new byte[0];
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public final static boolean isXMLFileName(String name)
|
||||||
public final static boolean isXMLFileName(String name)
|
{
|
||||||
{
|
if (StringUtil.hasData(name) == false)
|
||||||
if (StringUtil.hasData(name) == false)
|
return false;
|
||||||
return false;
|
String lowerName = name.toLowerCase();
|
||||||
String lowerName = name.toLowerCase(Locale.US);
|
return lowerName.endsWith("xml");
|
||||||
return lowerName.endsWith("xml");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -1,29 +1,29 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberUtil for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: ListenerList.java
|
* CyberUtil for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 12/30/02
|
* File: ListenerList.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* Revision;
|
||||||
******************************************************************/
|
*
|
||||||
|
* 12/30/02
|
||||||
|
* - first revision.
|
||||||
|
*
|
||||||
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.util;
|
package org.cybergarage.util;
|
||||||
|
|
||||||
import java.util.Vector;
|
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
|
* CyberUtil for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2004
|
* Copyright (C) Satoshi Konno 2002-2004
|
||||||
*
|
*
|
||||||
* File: Mutex.java
|
* File: Mutex.java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Revision:
|
||||||
*
|
*
|
||||||
* 06/19/04
|
* 06/19/04
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.util;
|
package org.cybergarage.util;
|
||||||
|
|
||||||
public class Mutex
|
public class Mutex
|
||||||
{
|
{
|
||||||
private boolean syncLock;
|
private boolean syncLock;
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public Mutex()
|
public Mutex()
|
||||||
{
|
{
|
||||||
syncLock = false;
|
syncLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// lock
|
// lock
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public synchronized void lock()
|
public synchronized void lock()
|
||||||
{
|
{
|
||||||
while(syncLock == true) {
|
while(syncLock == true) {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Debug.warning(e);
|
Debug.warning(e);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
syncLock = true;
|
syncLock = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void unlock()
|
public synchronized void unlock()
|
||||||
{
|
{
|
||||||
syncLock = false;
|
syncLock = false;
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -1,123 +1,123 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberUtil for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
|
||||||
*
|
*
|
||||||
* File: FileUtil.java
|
* CyberUtil for Java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* 01/12/03
|
* File: FileUtil.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* 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
|
* CyberUtil for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2004
|
* Copyright (C) Satoshi Konno 2002-2004
|
||||||
*
|
*
|
||||||
* File: Thread.java
|
* File: Thread.java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Revision:
|
||||||
*
|
*
|
||||||
* 01/05/04
|
* 01/05/04
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 08/23/07
|
* 08/23/07
|
||||||
* - Thanks for Kazuyuki Shudo
|
* - Thanks for Kazuyuki Shudo
|
||||||
* - Changed stop() to stop more safety using Thread::interrupt().
|
* - Changed stop() to stop more safety using Thread::interrupt().
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.util;
|
package org.cybergarage.util;
|
||||||
|
|
||||||
public class ThreadCore implements Runnable
|
public class ThreadCore implements Runnable
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public ThreadCore()
|
public ThreadCore()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Thread
|
// Thread
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
private java.lang.Thread mThreadObject = null;
|
private java.lang.Thread mThreadObject = null;
|
||||||
|
|
||||||
public void setThreadObject(java.lang.Thread obj) {
|
public void setThreadObject(java.lang.Thread obj) {
|
||||||
mThreadObject = obj;
|
mThreadObject = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public java.lang.Thread getThreadObject() {
|
public java.lang.Thread getThreadObject() {
|
||||||
return mThreadObject;
|
return mThreadObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start()
|
public void start()
|
||||||
{
|
{
|
||||||
java.lang.Thread threadObject = getThreadObject();
|
java.lang.Thread threadObject = getThreadObject();
|
||||||
if (threadObject == null) {
|
if (threadObject == null) {
|
||||||
threadObject = new java.lang.Thread(this,"Cyber.ThreadCore");
|
threadObject = new java.lang.Thread(this,"Cyber.ThreadCore");
|
||||||
setThreadObject(threadObject);
|
setThreadObject(threadObject);
|
||||||
threadObject.start();
|
threadObject.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRunnable()
|
public boolean isRunnable()
|
||||||
{
|
{
|
||||||
return (Thread.currentThread() == getThreadObject()) ? true : false;
|
return (Thread.currentThread() == getThreadObject()) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
java.lang.Thread threadObject = getThreadObject();
|
java.lang.Thread threadObject = getThreadObject();
|
||||||
if (threadObject != null) {
|
if (threadObject != null) {
|
||||||
//threadObject.destroy();
|
//threadObject.destroy();
|
||||||
//threadObject.stop();
|
//threadObject.stop();
|
||||||
|
|
||||||
// Thanks for Kazuyuki Shudo (08/23/07)
|
// Thanks for Kazuyuki Shudo (08/23/07)
|
||||||
threadObject.interrupt();
|
threadObject.interrupt();
|
||||||
|
|
||||||
setThreadObject(null);
|
setThreadObject(null);
|
||||||
// I2P break Disposer out of sleep()
|
// I2P break Disposer out of sleep()
|
||||||
threadObject.interrupt();
|
threadObject.interrupt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restart()
|
public void restart()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,37 +1,37 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberUtil for Java
|
* CyberUtil for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: TimerUtil.java
|
* File: TimerUtil.java
|
||||||
*
|
*
|
||||||
* Revision:
|
* Revision:
|
||||||
*
|
*
|
||||||
* 01/15/03
|
* 01/15/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.util;
|
package org.cybergarage.util;
|
||||||
|
|
||||||
public final class TimerUtil
|
public final class TimerUtil
|
||||||
{
|
{
|
||||||
public final static void wait(int waitTime)
|
public final static void wait(int waitTime)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Thread.sleep(waitTime);
|
Thread.sleep(waitTime);
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
catch (Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static void waitRandom(int time)
|
public final static void waitRandom(int time)
|
||||||
{
|
{
|
||||||
int waitTime = (int)(Math.random() * (double)time);
|
int waitTime = (int)(Math.random() * (double)time);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(waitTime);
|
Thread.sleep(waitTime);
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
catch (Exception e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,61 +1,78 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberXML for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: Attribute.java
|
* CyberXML for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 11/27/02
|
* File: Attribute.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* Revision;
|
||||||
******************************************************************/
|
*
|
||||||
|
* 11/27/02
|
||||||
|
* - first revision.
|
||||||
|
*
|
||||||
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.xml;
|
package org.cybergarage.xml;
|
||||||
|
|
||||||
public class Attribute
|
public class Attribute
|
||||||
{
|
{
|
||||||
private String name = new String();
|
private String name = new String();
|
||||||
private String value = new String();
|
private String value = new String();
|
||||||
|
|
||||||
public Attribute()
|
public Attribute()
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Attribute(String name, String value)
|
|
||||||
{
|
|
||||||
setName(name);
|
|
||||||
setValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
|
||||||
// name
|
|
||||||
////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public void setName(String name)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName()
|
|
||||||
{
|
{
|
||||||
return name;
|
}
|
||||||
}
|
|
||||||
|
public Attribute(String name, String value)
|
||||||
////////////////////////////////////////////////
|
|
||||||
// value
|
|
||||||
////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public void setValue(String value)
|
|
||||||
{
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue()
|
|
||||||
{
|
{
|
||||||
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
|
* CyberXML for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 11/27/02
|
* File: AttributeList.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* Revision;
|
||||||
******************************************************************/
|
*
|
||||||
|
* 11/27/02
|
||||||
|
* - first revision.
|
||||||
|
*
|
||||||
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.xml;
|
package org.cybergarage.xml;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
public class AttributeList extends Vector<Attribute>
|
public class AttributeList extends Vector<Attribute>
|
||||||
{
|
{
|
||||||
public AttributeList()
|
public AttributeList()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Attribute getAttribute(int n)
|
public Attribute getAttribute(int n)
|
||||||
{
|
{
|
||||||
return (Attribute)get(n);
|
return (Attribute)get(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Attribute getAttribute(String name)
|
public Attribute getAttribute(String name)
|
||||||
{
|
{
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int nLists = size();
|
int nLists = size();
|
||||||
for (int n=0; n<nLists; n++) {
|
for (int n=0; n<nLists; n++) {
|
||||||
Attribute elem = getAttribute(n);
|
Attribute elem = getAttribute(n);
|
||||||
if (name.compareTo(elem.getName()) == 0)
|
if (name.compareTo(elem.getName()) == 0)
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,6 +61,12 @@ public class Node
|
|||||||
setName(ns, name);
|
setName(ns, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Node(Node otherNode)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
set(otherNode);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// parent node
|
// parent node
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -189,6 +195,11 @@ public class Node
|
|||||||
return removeAttribute(getAttribute(name));
|
return removeAttribute(getAttribute(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeAllAttributes()
|
||||||
|
{
|
||||||
|
attrList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasAttributes()
|
public boolean hasAttributes()
|
||||||
{
|
{
|
||||||
if (0 < getNAttributes())
|
if (0 < getNAttributes())
|
||||||
@@ -239,6 +250,51 @@ public class Node
|
|||||||
setAttribute("xmlns:" + ns, value);
|
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
|
// Child node
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -309,16 +365,30 @@ public class Node
|
|||||||
// Element (Child Node)
|
// Element (Child Node)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setNode(String name, String value) {
|
public boolean hasNode(String name) {
|
||||||
Node node = getNode(name);
|
Node node = getNode(name);
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node.setValue(value);
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNode(String name) {
|
||||||
|
if (hasNode(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node = new Node(name);
|
Node node = new Node(name);
|
||||||
node.setValue(value);
|
|
||||||
addNode(node);
|
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) {
|
public String getNodeValue(String name) {
|
||||||
Node node = getNode(name);
|
Node node = getNode(name);
|
||||||
|
@@ -1,63 +1,63 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberXML for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: NodeList.java
|
* CyberXML for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 11/27/02
|
* File: NodeList.java
|
||||||
* - first revision.
|
*
|
||||||
*
|
* Revision;
|
||||||
******************************************************************/
|
*
|
||||||
|
* 11/27/02
|
||||||
|
* - first revision.
|
||||||
|
*
|
||||||
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.xml;
|
package org.cybergarage.xml;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
public class NodeList extends Vector<Node>
|
public class NodeList extends Vector<Node>
|
||||||
{
|
{
|
||||||
public NodeList()
|
public NodeList()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node getNode(int n)
|
public Node getNode(int n)
|
||||||
{
|
{
|
||||||
return (Node)get(n);
|
return (Node)get(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node getNode(String name)
|
public Node getNode(String name)
|
||||||
{
|
{
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int nLists = size();
|
int nLists = size();
|
||||||
for (int n=0; n<nLists; n++) {
|
for (int n=0; n<nLists; n++) {
|
||||||
Node node = getNode(n);
|
Node node = getNode(n);
|
||||||
String nodeName = node.getName();
|
String nodeName = node.getName();
|
||||||
if (name.compareTo(nodeName) == 0)
|
if (name.compareTo(nodeName) == 0)
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node getEndsWith(String name)
|
public Node getEndsWith(String name)
|
||||||
{
|
{
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
int nLists = size();
|
int nLists = size();
|
||||||
for (int n=0; n<nLists; n++) {
|
for (int n=0; n<nLists; n++) {
|
||||||
Node node = getNode(n);
|
Node node = getNode(n);
|
||||||
String nodeName = node.getName();
|
String nodeName = node.getName();
|
||||||
if (nodeName == null)
|
if (nodeName == null)
|
||||||
continue;
|
continue;
|
||||||
if (nodeName.endsWith(name) == true)
|
if (nodeName.endsWith(name) == true)
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,30 +1,30 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
|
||||||
* CyberXML for Java
|
|
||||||
*
|
|
||||||
* Copyright (C) Satoshi Konno 2002
|
|
||||||
*
|
*
|
||||||
* File: ParserException.java
|
* CyberXML for Java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Copyright (C) Satoshi Konno 2002
|
||||||
*
|
*
|
||||||
* 11/27/02
|
* File: ParserException.java
|
||||||
* - first revision.
|
*
|
||||||
* 12/26/03
|
* Revision;
|
||||||
* - Changed to a sub class of Exception instead of SAXException.
|
*
|
||||||
*
|
* 11/27/02
|
||||||
******************************************************************/
|
* - first revision.
|
||||||
|
* 12/26/03
|
||||||
package org.cybergarage.xml;
|
* - Changed to a sub class of Exception instead of SAXException.
|
||||||
|
*
|
||||||
public class ParserException extends Exception
|
******************************************************************/
|
||||||
|
|
||||||
|
package org.cybergarage.xml;
|
||||||
|
|
||||||
|
public class ParserException extends Exception
|
||||||
{
|
{
|
||||||
public ParserException(Exception e)
|
public ParserException(Exception e)
|
||||||
{
|
{
|
||||||
super(e);
|
super(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParserException(String s)
|
public ParserException(String s)
|
||||||
{
|
{
|
||||||
super(s);
|
super(s);
|
||||||
}
|
}
|
||||||
|
@@ -5,22 +5,23 @@
|
|||||||
* Copyright (C) Satoshi Konno 2002-2003
|
* Copyright (C) Satoshi Konno 2002-2003
|
||||||
*
|
*
|
||||||
* File: XML.java
|
* File: XML.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 01/05/03
|
* 01/05/03
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 12/15/03
|
* 12/15/03
|
||||||
* - Terje Bakken
|
* - Terje Bakken
|
||||||
* - Added escapeXMLChars()
|
* - Added escapeXMLChars()
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.xml;
|
package org.cybergarage.xml;
|
||||||
|
|
||||||
public class XML
|
public class XML
|
||||||
{
|
{
|
||||||
public final static String CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
|
public final static String DEFAULT_CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
|
||||||
|
public final static String DEFAULT_CONTENT_LANGUAGE = "en";
|
||||||
public final static String CHARSET_UTF8 = "utf-8";
|
public final static String CHARSET_UTF8 = "utf-8";
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -82,5 +83,5 @@ public class XML
|
|||||||
|
|
||||||
return outStr;
|
return outStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,200 +1,200 @@
|
|||||||
/******************************************************************
|
/******************************************************************
|
||||||
*
|
*
|
||||||
* CyberXML for Java
|
* CyberXML for Java
|
||||||
*
|
*
|
||||||
* Copyright (C) Satoshi Konno 2004
|
* Copyright (C) Satoshi Konno 2004
|
||||||
*
|
*
|
||||||
* Author: Markus Thurner (http://thoean.com)
|
* Author: Markus Thurner (http://thoean.com)
|
||||||
*
|
*
|
||||||
* File: JaxpParser.java
|
* File: JaxpParser.java
|
||||||
*
|
*
|
||||||
* Revision;
|
* Revision;
|
||||||
*
|
*
|
||||||
* 06/15/04
|
* 06/15/04
|
||||||
* - first revision.
|
* - first revision.
|
||||||
* 01/08/08
|
* 01/08/08
|
||||||
* - Fixed parse() not to occur null exception when the NamedNodeMap is null on Android.
|
* - Fixed parse() not to occur null exception when the NamedNodeMap is null on Android.
|
||||||
* 02/08/08
|
* 02/08/08
|
||||||
* - Change parse() to use Node::addValue() instead of the setValue().
|
* - Change parse() to use Node::addValue() instead of the setValue().
|
||||||
*
|
*
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
package org.cybergarage.xml.parser;
|
package org.cybergarage.xml.parser;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.FilterInputStream;
|
import java.io.FilterInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
import org.cybergarage.xml.Node;
|
import org.cybergarage.xml.Node;
|
||||||
import org.cybergarage.xml.Parser;
|
import org.cybergarage.xml.Parser;
|
||||||
import org.cybergarage.xml.ParserException;
|
import org.cybergarage.xml.ParserException;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
import org.xml.sax.EntityResolver;
|
import org.xml.sax.EntityResolver;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
|
||||||
public class JaxpParser extends Parser
|
public class JaxpParser extends Parser
|
||||||
{
|
{
|
||||||
|
|
||||||
public JaxpParser()
|
public JaxpParser()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// parse (Node)
|
// parse (Node)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode, int rank)
|
public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode, int rank)
|
||||||
{
|
{
|
||||||
int domNodeType = domNode.getNodeType();
|
int domNodeType = domNode.getNodeType();
|
||||||
// if (domNodeType != Node.ELEMENT_NODE)
|
// if (domNodeType != Node.ELEMENT_NODE)
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
String domNodeName = domNode.getNodeName();
|
String domNodeName = domNode.getNodeName();
|
||||||
String domNodeValue = domNode.getNodeValue();
|
String domNodeValue = domNode.getNodeValue();
|
||||||
NamedNodeMap attrs = domNode.getAttributes();
|
NamedNodeMap attrs = domNode.getAttributes();
|
||||||
int arrrsLen = (attrs != null) ? attrs.getLength() : 0;
|
int arrrsLen = (attrs != null) ? attrs.getLength() : 0;
|
||||||
|
|
||||||
// Debug.message("[" + rank + "] ELEM : " + domNodeName + ", " + domNodeValue + ", type = " + domNodeType + ", attrs = " + arrrsLen);
|
// Debug.message("[" + rank + "] ELEM : " + domNodeName + ", " + domNodeValue + ", type = " + domNodeType + ", attrs = " + arrrsLen);
|
||||||
|
|
||||||
if (domNodeType == org.w3c.dom.Node.TEXT_NODE) {
|
if (domNodeType == org.w3c.dom.Node.TEXT_NODE) {
|
||||||
// Change to use Node::addValue() instead of the setValue(). (2008/02/07)
|
// Change to use Node::addValue() instead of the setValue(). (2008/02/07)
|
||||||
//parentNode.setValue(domNodeValue);
|
//parentNode.setValue(domNodeValue);
|
||||||
parentNode.addValue(domNodeValue);
|
parentNode.addValue(domNodeValue);
|
||||||
return parentNode;
|
return parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (domNodeType != org.w3c.dom.Node.ELEMENT_NODE)
|
if (domNodeType != org.w3c.dom.Node.ELEMENT_NODE)
|
||||||
return parentNode;
|
return parentNode;
|
||||||
|
|
||||||
org.cybergarage.xml.Node node = new org.cybergarage.xml.Node();
|
org.cybergarage.xml.Node node = new org.cybergarage.xml.Node();
|
||||||
node.setName(domNodeName);
|
node.setName(domNodeName);
|
||||||
node.setValue(domNodeValue);
|
node.setValue(domNodeValue);
|
||||||
|
|
||||||
if (parentNode != null)
|
if (parentNode != null)
|
||||||
parentNode.addNode(node);
|
parentNode.addNode(node);
|
||||||
|
|
||||||
NamedNodeMap attrMap = domNode.getAttributes();
|
NamedNodeMap attrMap = domNode.getAttributes();
|
||||||
if (attrMap != null) {
|
if (attrMap != null) {
|
||||||
int attrLen = attrMap.getLength();
|
int attrLen = attrMap.getLength();
|
||||||
//Debug.message("attrLen = " + attrLen);
|
//Debug.message("attrLen = " + attrLen);
|
||||||
for (int n = 0; n<attrLen; n++) {
|
for (int n = 0; n<attrLen; n++) {
|
||||||
org.w3c.dom.Node attr = attrMap.item(n);
|
org.w3c.dom.Node attr = attrMap.item(n);
|
||||||
String attrName = attr.getNodeName();
|
String attrName = attr.getNodeName();
|
||||||
String attrValue = attr.getNodeValue();
|
String attrValue = attr.getNodeValue();
|
||||||
node.setAttribute(attrName, attrValue);
|
node.setAttribute(attrName, attrValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
org.w3c.dom.Node child = domNode.getFirstChild();
|
org.w3c.dom.Node child = domNode.getFirstChild();
|
||||||
if(child==null){
|
if(child==null){
|
||||||
node.setValue("");
|
node.setValue("");
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
do{
|
do{
|
||||||
parse(node, child, rank+1);
|
parse(node, child, rank+1);
|
||||||
child = child.getNextSibling();
|
child = child.getNextSibling();
|
||||||
}while (child != null);
|
}while (child != null);
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode)
|
public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode)
|
||||||
{
|
{
|
||||||
return parse(parentNode, domNode, 0);
|
return parse(parentNode, domNode, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.cybergarage.xml.Parser#parse(java.io.InputStream)
|
* @see org.cybergarage.xml.Parser#parse(java.io.InputStream)
|
||||||
*/
|
*/
|
||||||
public Node parse(InputStream inStream) throws ParserException
|
public Node parse(InputStream inStream) throws ParserException
|
||||||
{
|
{
|
||||||
org.cybergarage.xml.Node root = null;
|
org.cybergarage.xml.Node root = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing
|
// https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
factory.setValidating(false);
|
factory.setValidating(false);
|
||||||
factory.setNamespaceAware(true);
|
factory.setNamespaceAware(true);
|
||||||
factory.setExpandEntityReferences(false);
|
factory.setExpandEntityReferences(false);
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||||
} catch (ParserConfigurationException pce) {}
|
} catch (ParserConfigurationException pce) {}
|
||||||
try {
|
try {
|
||||||
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||||
} catch (ParserConfigurationException pce) {}
|
} catch (ParserConfigurationException pce) {}
|
||||||
try {
|
try {
|
||||||
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||||
} catch (ParserConfigurationException pce) {}
|
} catch (ParserConfigurationException pce) {}
|
||||||
try {
|
try {
|
||||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||||
} catch (ParserConfigurationException pce) {}
|
} catch (ParserConfigurationException pce) {}
|
||||||
} catch (AbstractMethodError ame) {} // FreeBSD
|
} catch (AbstractMethodError ame) {} // FreeBSD
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
builder.setEntityResolver(new BlankingResolver());
|
builder.setEntityResolver(new BlankingResolver());
|
||||||
InputSource inSrc = new InputSource(new NullFilterInputStream(inStream));
|
InputSource inSrc = new InputSource(new NullFilterInputStream(inStream));
|
||||||
Document doc = builder.parse(inSrc);
|
Document doc = builder.parse(inSrc);
|
||||||
|
|
||||||
org.w3c.dom.Element docElem = doc.getDocumentElement();
|
org.w3c.dom.Element docElem = doc.getDocumentElement();
|
||||||
|
|
||||||
if (docElem != null)
|
if (docElem != null)
|
||||||
root = parse(root, docElem);
|
root = parse(root, docElem);
|
||||||
/*
|
/*
|
||||||
NodeList rootList = doc.getElementsByTagName("root");
|
NodeList rootList = doc.getElementsByTagName("root");
|
||||||
Debug.message("rootList = " + rootList.getLength());
|
Debug.message("rootList = " + rootList.getLength());
|
||||||
|
|
||||||
if (0 < rootList.getLength())
|
if (0 < rootList.getLength())
|
||||||
root = parse(root, rootList.item(0));
|
root = parse(root, rootList.item(0));
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new ParserException(e);
|
throw new ParserException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I2P -
|
* I2P -
|
||||||
* Filter out nulls, hopefully to avoid
|
* Filter out nulls, hopefully to avoid
|
||||||
* SAXParserException "Content not allowed in trailing section",
|
* SAXParserException "Content not allowed in trailing section",
|
||||||
* which is apparently caused by nulls.
|
* which is apparently caused by nulls.
|
||||||
* Alternative is to remove all stuff between '>' and '<',
|
* Alternative is to remove all stuff between '>' and '<',
|
||||||
* which isn't so hard if we assume no CDATA.
|
* which isn't so hard if we assume no CDATA.
|
||||||
*/
|
*/
|
||||||
private static class NullFilterInputStream extends FilterInputStream {
|
private static class NullFilterInputStream extends FilterInputStream {
|
||||||
|
|
||||||
public NullFilterInputStream(InputStream is) {
|
public NullFilterInputStream(InputStream is) {
|
||||||
super(is);
|
super(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
int rv;
|
int rv;
|
||||||
while ((rv = super.read()) == 0) {
|
while ((rv = super.read()) == 0) {
|
||||||
// try again
|
// try again
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I2P -
|
* I2P -
|
||||||
* http://stackoverflow.com/questions/5883542/disable-xml-validation-based-on-external-dtd-xsd
|
* http://stackoverflow.com/questions/5883542/disable-xml-validation-based-on-external-dtd-xsd
|
||||||
*/
|
*/
|
||||||
private static class BlankingResolver implements EntityResolver {
|
private static class BlankingResolver implements EntityResolver {
|
||||||
private static final byte[] DUMMY = new byte[0];
|
private static final byte[] DUMMY = new byte[0];
|
||||||
|
|
||||||
public InputSource resolveEntity(String arg0, String arg1) {
|
public InputSource resolveEntity(String arg0, String arg1) {
|
||||||
return new InputSource(new ByteArrayInputStream(DUMMY));
|
return new InputSource(new ByteArrayInputStream(DUMMY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user