diff --git a/router/java/src/org/cybergarage/http/Date.java b/router/java/src/org/cybergarage/http/Date.java index 117964d34b49b326059d9eeab0ae057cf4c362b9..2b1d8a2f8293d587c7ee4333128e455fe61f2361 100644 --- a/router/java/src/org/cybergarage/http/Date.java +++ b/router/java/src/org/cybergarage/http/Date.java @@ -1,165 +1,165 @@ -/****************************************************************** -* +/****************************************************************** +* * CyberHTTP for Java * * Copyright (C) Satoshi Konno 2002-2003 -* -* File : Date.java -* -* Revision; -* -* 01/05/03 -* - first revision -* 10/20/04 -* - Theo Beisch <theo.beisch@gmx.de> -* - Fixed the following methods to use HOUR_OF_DAY instead of HOUR. -* getHour(), getDateString() getTimeString() -* - Fixed getInstance() to return GMT instance. -* +* +* File : Date.java +* +* Revision; +* +* 01/05/03 +* - first revision +* 10/20/04 +* - Theo Beisch <theo.beisch@gmx.de> +* - Fixed the following methods to use HOUR_OF_DAY instead of HOUR. +* getHour(), getDateString() getTimeString() +* - Fixed getInstance() to return GMT instance. +* ******************************************************************/ - -package org.cybergarage.http; - -import java.util.Calendar; -import java.util.TimeZone; - -public class Date -{ - private Calendar cal; - - public Date(Calendar cal) - { - this.cal = cal; - } - - public Calendar getCalendar() - { - return cal; - } - - //////////////////////////////////////////////// - // Time - //////////////////////////////////////////////// - - public int getHour() - { - // Thanks for Theo Beisch (10/20/04) - return getCalendar().get(Calendar.HOUR_OF_DAY); - } - - public int getMinute() - { - return getCalendar().get(Calendar.MINUTE); - } - - public int getSecond() - { - return getCalendar().get(Calendar.SECOND); - } - - //////////////////////////////////////////////// - // paint - //////////////////////////////////////////////// - - public final static Date getLocalInstance() - { - return new Date(Calendar.getInstance()); - } - - public final static Date getInstance() - { - // Thanks for Theo Beisch (10/20/04) - return new Date(Calendar.getInstance(TimeZone.getTimeZone("GMT"))); - } - - //////////////////////////////////////////////// - // getDateString - //////////////////////////////////////////////// - - public final static String toDateString(int value) - { - if (value < 10) - return "0" + Integer.toString(value); - return Integer.toString(value); - } - - private final static String MONTH_STRING[] = { - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec", - }; - - public final static String toMonthString(int value) - { - value -= Calendar.JANUARY; - if (0 <= value && value < 12) - return MONTH_STRING[value]; - return ""; - } - - private final static String WEEK_STRING[] = { - "Sun", - "Mon", - "Tue", - "Wed", - "Thu", - "Fri", - "Sat", - }; - - public final static String toWeekString(int value) - { - value -= Calendar.SUNDAY; - if (0 <= value && value < 7) - return WEEK_STRING[value]; - return ""; - } - - public final static String toTimeString(int value) - { - String str = ""; - if (value < 10) - str += "0"; - str += Integer.toString(value); - return str; - } - - public String getDateString() - { - // Thanks for Theo Beisch (10/20/04) - Calendar cal = getCalendar(); - return - toWeekString(cal.get(Calendar.DAY_OF_WEEK)) +", " + - toTimeString(cal.get(Calendar.DATE)) + " " + - toMonthString(cal.get(Calendar.MONTH)) + " " + - Integer.toString(cal.get(Calendar.YEAR)) + " " + - toTimeString(cal.get(Calendar.HOUR_OF_DAY)) + ":" + - toTimeString(cal.get(Calendar.MINUTE)) + ":" + - toTimeString(cal.get(Calendar.SECOND)) + " GMT"; - } - - //////////////////////////////////////////////// - // getTimeString - //////////////////////////////////////////////// - - public String getTimeString() - { - // Thanks for Theo Beisch (10/20/04) - Calendar cal = getCalendar(); - return - toDateString(cal.get(Calendar.HOUR_OF_DAY)) + - (((cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") + - toDateString(cal.get(Calendar.MINUTE)); - } - -} - + +package org.cybergarage.http; + +import java.util.Calendar; +import java.util.TimeZone; + +public class Date +{ + private Calendar cal; + + public Date(Calendar cal) + { + this.cal = cal; + } + + public Calendar getCalendar() + { + return cal; + } + + //////////////////////////////////////////////// + // Time + //////////////////////////////////////////////// + + public int getHour() + { + // Thanks for Theo Beisch (10/20/04) + return getCalendar().get(Calendar.HOUR_OF_DAY); + } + + public int getMinute() + { + return getCalendar().get(Calendar.MINUTE); + } + + public int getSecond() + { + return getCalendar().get(Calendar.SECOND); + } + + //////////////////////////////////////////////// + // paint + //////////////////////////////////////////////// + + public final static Date getLocalInstance() + { + return new Date(Calendar.getInstance()); + } + + public final static Date getInstance() + { + // Thanks for Theo Beisch (10/20/04) + return new Date(Calendar.getInstance(TimeZone.getTimeZone("GMT"))); + } + + //////////////////////////////////////////////// + // getDateString + //////////////////////////////////////////////// + + public final static String toDateString(int value) + { + if (value < 10) + return "0" + Integer.toString(value); + return Integer.toString(value); + } + + private final static String MONTH_STRING[] = { + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", + }; + + public final static String toMonthString(int value) + { + value -= Calendar.JANUARY; + if (0 <= value && value < 12) + return MONTH_STRING[value]; + return ""; + } + + private final static String WEEK_STRING[] = { + "Sun", + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + "Sat", + }; + + public final static String toWeekString(int value) + { + value -= Calendar.SUNDAY; + if (0 <= value && value < 7) + return WEEK_STRING[value]; + return ""; + } + + public final static String toTimeString(int value) + { + String str = ""; + if (value < 10) + str += "0"; + str += Integer.toString(value); + return str; + } + + public String getDateString() + { + // Thanks for Theo Beisch (10/20/04) + Calendar cal = getCalendar(); + return + toWeekString(cal.get(Calendar.DAY_OF_WEEK)) +", " + + toTimeString(cal.get(Calendar.DATE)) + " " + + toMonthString(cal.get(Calendar.MONTH)) + " " + + Integer.toString(cal.get(Calendar.YEAR)) + " " + + toTimeString(cal.get(Calendar.HOUR_OF_DAY)) + ":" + + toTimeString(cal.get(Calendar.MINUTE)) + ":" + + toTimeString(cal.get(Calendar.SECOND)) + " GMT"; + } + + //////////////////////////////////////////////// + // getTimeString + //////////////////////////////////////////////// + + public String getTimeString() + { + // Thanks for Theo Beisch (10/20/04) + Calendar cal = getCalendar(); + return + toDateString(cal.get(Calendar.HOUR_OF_DAY)) + + (((cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") + + toDateString(cal.get(Calendar.MINUTE)); + } + +} + diff --git a/router/java/src/org/cybergarage/http/HTML.java b/router/java/src/org/cybergarage/http/HTML.java index 0d06e7ca53862d1d237cbaf7544a5a688dda2ccb..0442494c16d945832786b49aa1b4de699742cdd2 100644 --- a/router/java/src/org/cybergarage/http/HTML.java +++ b/router/java/src/org/cybergarage/http/HTML.java @@ -1,22 +1,22 @@ -/****************************************************************** -* -* CyberHTTP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: HTML.java -* -* Revision; -* -* 01/05/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.http; - -public class HTML -{ - public static final String CONTENT_TYPE = "text/html; charset=\"utf-8\""; -} - +/****************************************************************** +* +* CyberHTTP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: HTML.java +* +* Revision; +* +* 01/05/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.http; + +public class HTML +{ + public static final String CONTENT_TYPE = "text/html; charset=\"utf-8\""; +} + diff --git a/router/java/src/org/cybergarage/http/HTTP.java b/router/java/src/org/cybergarage/http/HTTP.java index 554da7f257f423ec711be699b4ddb895d0c1bcc6..9455436f729f13fdc7fd82f59a92f06fd4c90f61 100644 --- a/router/java/src/org/cybergarage/http/HTTP.java +++ b/router/java/src/org/cybergarage/http/HTTP.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002 * * File: HTTP.java -* -* Revision: -* -* 11/18/02 -* - first revision. +* +* Revision: +* +* 11/18/02 +* - first revision. * 08/30/03 * - Giordano Sassaroli <sassarol@cefriel.it> * - Problem : the method getPort should return the default http port 80 when a port is not specified @@ -27,58 +27,57 @@ * - Added Range and MYNAME; * ******************************************************************/ - + package org.cybergarage.http; - + import java.net.URL; - -public class HTTP -{ + +public class HTTP +{ //////////////////////////////////////////////// // Constants //////////////////////////////////////////////// public static final String HOST = "HOST"; - public static final String VERSION = "1.1"; + public static final String VERSION = "1.1"; public static final String VERSION_10 = "1.0"; public static final String VERSION_11 = "1.1"; - public static final String CRLF = "\r\n"; + public static final String CRLF = "\r\n"; public static final byte CR = '\r'; public static final byte LF = '\n'; public static final String TAB = "\t"; - + public static final String SOAP_ACTION = "SOAPACTION"; public static final String M_SEARCH = "M-SEARCH"; public static final String NOTIFY = "NOTIFY"; - public static final String POST = "POST"; - public static final String GET = "GET"; + public static final String POST = "POST"; + public static final String GET = "GET"; public static final String HEAD = "HEAD"; public static final String SUBSCRIBE = "SUBSCRIBE"; public static final String UNSUBSCRIBE = "UNSUBSCRIBE"; - - public static final String DATE = "Date"; + + public static final String DATE = "Date"; public static final String CACHE_CONTROL = "Cache-Control"; public static final String NO_CACHE = "no-cache"; public static final String MAX_AGE = "max-age"; public static final String CONNECTION = "Connection"; public static final String CLOSE = "close"; public static final String KEEP_ALIVE = "Keep-Alive"; - public static final String CONTENT_TYPE = "Content-Type"; + public static final String CONTENT_TYPE = "Content-Type"; public static final String CHARSET = "charset"; - public static final String CONTENT_LENGTH = "Content-Length"; + public static final String CONTENT_LENGTH = "Content-Length"; + public static final String CONTENT_LANGUAGE = "Content-Language"; public static final String CONTENT_RANGE = "Content-Range"; public static final String CONTENT_RANGE_BYTES = "bytes"; - // Thanks for Brent Hills (10/20/04) public static final String RANGE = "Range"; public static final String TRANSFER_ENCODING = "Transfer-Encoding"; public static final String CHUNKED = "Chunked"; public static final String LOCATION = "Location"; - public static final String SERVER = "Server"; - - + public static final String SERVER = "Server"; + public static final String ST = "ST"; public static final String MX = "MX"; public static final String MAN = "MAN"; @@ -90,13 +89,16 @@ public class HTTP public static final String SEQ = "SEQ"; public final static String CALLBACK = "CALLBACK"; public final static String TIMEOUT = "TIMEOUT"; + + public final static String BOOTID_UPNP_ORG = "BOOTID.UPNP.ORG"; + // Thanks for Brent Hills (10/20/04) public final static String MYNAME = "MYNAME"; - - public static final String REQEST_LINE_DELIM = " "; - public static final String HEADER_LINE_DELIM = " :"; - public static final String STATUS_LINE_DELIM = " "; - + + public static final String REQEST_LINE_DELIM = " "; + public static final String HEADER_LINE_DELIM = " :"; + public static final String STATUS_LINE_DELIM = " "; + public static final int DEFAULT_PORT = 80; public static final int DEFAULT_CHUNK_SIZE = 512 * 1024; public static final int DEFAULT_TIMEOUT = 30; @@ -105,53 +107,53 @@ public class HTTP // URL //////////////////////////////////////////////// - public static final boolean isAbsoluteURL(String urlStr) - { - try { - new URL(urlStr); - return true; - } - catch (Exception e) { - return false; - } - } - - public static final String getHost(String urlStr) - { - try { - URL url = new URL(urlStr); - return url.getHost(); - } - catch (Exception e) { - return ""; - } - } - - public static final int getPort(String urlStr) - { - try { - URL url = new URL(urlStr); + public static final boolean isAbsoluteURL(String urlStr) + { + try { + new URL(urlStr); + return true; + } + catch (Exception e) { + return false; + } + } + + public static final String getHost(String urlStr) + { + try { + URL url = new URL(urlStr); + return url.getHost(); + } + catch (Exception e) { + return ""; + } + } + + public static final int getPort(String urlStr) + { + try { + URL url = new URL(urlStr); // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (08/30/03) - int port = url.getPort(); + int port = url.getPort(); if (port <= 0) port = DEFAULT_PORT; return port; - } - catch (Exception e) { - return DEFAULT_PORT; - } - } - + } + catch (Exception e) { + return DEFAULT_PORT; + } + } + public static final String getRequestHostURL(String host, int port) { String reqHost = "http://" + host + ":" + port; return reqHost; } - public static final String toRelativeURL(String urlStr, boolean withParam) + public static final String toRelativeURL(String urlStr, boolean withParam) { String uri = urlStr; - if (isAbsoluteURL(urlStr) == false) { + if (isAbsoluteURL(urlStr) == false) { if (0 < urlStr.length() && urlStr.charAt(0) != '/') uri = "/" + urlStr; } @@ -171,28 +173,28 @@ public class HTTP } return uri; } - + public static final String toRelativeURL(String urlStr) { return toRelativeURL(urlStr, true); } - - public static final String getAbsoluteURL(String baseURLStr, String relURlStr) - { - try { - URL baseURL = new URL(baseURLStr); - String url = - baseURL.getProtocol() + "://" + - baseURL.getHost() + ":" + - baseURL.getPort() + - toRelativeURL(relURlStr); - return url; - } - catch (Exception e) { - return ""; - } + + public static final String getAbsoluteURL(String baseURLStr, String relURlStr) + { + try { + URL baseURL = new URL(baseURLStr); + String url = + baseURL.getProtocol() + "://" + + baseURL.getHost() + ":" + + baseURL.getPort() + + toRelativeURL(relURlStr); + return url; + } + catch (Exception e) { + return ""; + } } - + //////////////////////////////////////////////// // Chunk Size //////////////////////////////////////////////// @@ -209,5 +211,5 @@ public class HTTP return chunkSize; } -} +} diff --git a/router/java/src/org/cybergarage/http/HTTPHeader.java b/router/java/src/org/cybergarage/http/HTTPHeader.java index b6ff370d6ab988f35f4d31ca1b454f24f070b31b..859746382a49549e6ff8d98a009ecf6c9e8527c0 100644 --- a/router/java/src/org/cybergarage/http/HTTPHeader.java +++ b/router/java/src/org/cybergarage/http/HTTPHeader.java @@ -5,36 +5,36 @@ * Copyright (C) Satoshi Konno 2002 * * File: HTTPHeader.java -* -* Revision; -* -* 11/19/02 -* - first revision. +* +* Revision; +* +* 11/19/02 +* - first revision. * 05/26/04 * - Jan Newmarch <jan.newmarch@infotech.monash.edu.au> (05/26/04) * - Fixed getValue() to compare using String::equals() instead of String::startWidth(). * ******************************************************************/ - + package org.cybergarage.http; - + import java.io.IOException; import java.io.LineNumberReader; import java.io.StringReader; import org.cybergarage.util.Debug; - -public class HTTPHeader + +public class HTTPHeader { - private static int MAX_LENGTH = 1024; - private String name; - private String value; - - public HTTPHeader(String name, String value) - { - setName(name); - setValue(value); - } + private static int MAX_LENGTH = 1024; + private String name; + private String value; + + public HTTPHeader(String name, String value) + { + setName(name); + setValue(value); + } public HTTPHeader(String lineStr) { @@ -50,30 +50,30 @@ public class HTTPHeader setName(name.trim()); setValue(value.trim()); } - + //////////////////////////////////////////////// // Member //////////////////////////////////////////////// - public void setName(String name) - { - this.name = name; - } - - public void setValue(String value) - { - this.value = value; - } - - public String getName() - { - return name; - } - - public String getValue() - { - return value; - } + public void setName(String name) + { + this.name = name; + } + + public void setValue(String value) + { + this.value = value; + } + + public String getName() + { + return name; + } + + public String getValue() + { + return value; + } public boolean hasName() { @@ -81,68 +81,68 @@ public class HTTPHeader return false; return true; } - - //////////////////////////////////////////////// - // static methods - //////////////////////////////////////////////// - - public final static String getValue(LineNumberReader reader, String name) - { - String bigName = name.toUpperCase(); - try { - String lineStr = reader.readLine(); - while (lineStr != null && 0 < lineStr.length()) { + + //////////////////////////////////////////////// + // static methods + //////////////////////////////////////////////// + + public final static String getValue(LineNumberReader reader, String name) + { + String bigName = name.toUpperCase(); + try { + String lineStr = reader.readLine(); + while (lineStr != null && 0 < lineStr.length()) { HTTPHeader header = new HTTPHeader(lineStr); - if (header.hasName() == false) { - lineStr = reader.readLine(); - continue; - } + if (header.hasName() == false) { + lineStr = reader.readLine(); + continue; + } String bigLineHeaderName = header.getName().toUpperCase(); - // 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(); - } - } + // 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) + Debug.warning(e); + return ""; + } + return ""; + } + + public final static String getValue(String data, String name) { - /* Thanks for Stephan Mehlhase (2010-10-26) */ + /* Thanks for Stephan Mehlhase (2010-10-26) */ StringReader strReader = new StringReader(data); LineNumberReader lineReader = new LineNumberReader(strReader, Math.min(data.length(), MAX_LENGTH)); - return getValue(lineReader, name); - } - - public final static String getValue(byte[] data, String name) - { - return getValue(new String(data), name); - } - - public final static int getIntegerValue(String data, String name) + return getValue(lineReader, name); + } + + public final static String getValue(byte[] data, String name) + { + return getValue(new String(data), name); + } + + public final static int getIntegerValue(String data, String name) { try { return Integer.parseInt(getValue(data, name)); } catch (Exception e) { return 0; - } - } - - public final static int getIntegerValue(byte[] data, String name) - { + } + } + + public final static int getIntegerValue(byte[] data, String name) + { try { return Integer.parseInt(getValue(data, name)); } catch (Exception e) { return 0; } - } + } } diff --git a/router/java/src/org/cybergarage/http/HTTPPacket.java b/router/java/src/org/cybergarage/http/HTTPPacket.java index 9a7575f32d5eba598d297fd97bd9532569fcfcd7..0dc0cf2fb46deba45761cdbedaa4e36aab818d01 100644 --- a/router/java/src/org/cybergarage/http/HTTPPacket.java +++ b/router/java/src/org/cybergarage/http/HTTPPacket.java @@ -610,6 +610,20 @@ public class HTTPPacket return getHeaderValue(HTTP.CONTENT_TYPE); } + //////////////////////////////////////////////// + // ContentLanguage + //////////////////////////////////////////////// + + public void setContentLanguage(String code) + { + setHeader(HTTP.CONTENT_LANGUAGE, code); + } + + public String getContentLanguage() + { + return getHeaderValue(HTTP.CONTENT_LANGUAGE); + } + //////////////////////////////////////////////// // Charset //////////////////////////////////////////////// diff --git a/router/java/src/org/cybergarage/http/HTTPRequest.java b/router/java/src/org/cybergarage/http/HTTPRequest.java index 6735427244c4728c87ffe6e758bd17488edc2790..c2339b5af730abe91312937c9417c5b7c213850e 100644 --- a/router/java/src/org/cybergarage/http/HTTPRequest.java +++ b/router/java/src/org/cybergarage/http/HTTPRequest.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: HTTPRequest.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 05/23/03 * - Giordano Sassaroli <sassarol@cefriel.it> * - Add a relative URL check to setURI(). @@ -51,9 +51,9 @@ * - Fixed post() to output the chunk size as a hex string. * ******************************************************************/ - + package org.cybergarage.http; - + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -72,17 +72,17 @@ import org.cybergarage.util.Debug; * @author Stefano "Kismet" Lenzi * @version 1.8 * - */ -public class HTTPRequest extends HTTPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPRequest() - { + */ +public class HTTPRequest extends HTTPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPRequest() + { setVersion(HTTP.VERSION_10); - } + } public HTTPRequest(InputStream in) { @@ -95,23 +95,23 @@ public class HTTPRequest extends HTTPPacket setSocket(httpSock); } - //////////////////////////////////////////////// - // Method - //////////////////////////////////////////////// - - private String method = null; - - public void setMethod(String value) - { - method = value; - } - - public String getMethod() - { - if (method != null) + //////////////////////////////////////////////// + // Method + //////////////////////////////////////////////// + + private String method = null; + + public void setMethod(String value) + { + method = value; + } + + public String getMethod() + { + if (method != null) return method; - return getFirstLineToken(0); - } + return getFirstLineToken(0); + } public boolean isMethod(String method) { @@ -120,16 +120,16 @@ public class HTTPRequest extends HTTPPacket return false; return headerMethod.equalsIgnoreCase(method); } - - public boolean isGetRequest() + + public boolean isGetRequest() + { + return isMethod(HTTP.GET); + } + + public boolean isPostRequest() { - return isMethod(HTTP.GET); - } - - public boolean isPostRequest() - { return isMethod(HTTP.POST); - } + } public boolean isHeadRequest() { @@ -151,33 +151,33 @@ public class HTTPRequest extends HTTPPacket return isMethod(HTTP.NOTIFY); } - //////////////////////////////////////////////// - // URI - //////////////////////////////////////////////// - - private String uri = null; - - public void setURI(String value, boolean isCheckRelativeURL) - { + //////////////////////////////////////////////// + // URI + //////////////////////////////////////////////// + + private String uri = null; + + public void setURI(String value, boolean isCheckRelativeURL) + { uri = value; if (isCheckRelativeURL == false) return; // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03) uri = HTTP.toRelativeURL(uri); - } + } public void setURI(String value) { setURI(value, false); } - public String getURI() + public String getURI() { - if (uri != null) - return uri; + if (uri != null) + return uri; return getFirstLineToken(1); - } - + } + //////////////////////////////////////////////// // URI Parameter //////////////////////////////////////////////// @@ -246,21 +246,21 @@ public class HTTPRequest extends HTTPPacket return requestPort; } - //////////////////////////////////////////////// - // Socket - //////////////////////////////////////////////// - - private HTTPSocket httpSocket = null; - - public void setSocket(HTTPSocket value) - { - httpSocket = value; - } - - public HTTPSocket getSocket() - { - return httpSocket; - } + //////////////////////////////////////////////// + // Socket + //////////////////////////////////////////////// + + private HTTPSocket httpSocket = null; + + public void setSocket(HTTPSocket value) + { + httpSocket = value; + } + + public HTTPSocket getSocket() + { + return httpSocket; + } /////////////////////////// ///////////////////// // local address/port @@ -275,25 +275,25 @@ public class HTTPRequest extends HTTPPacket { return getSocket().getLocalPort(); } - - //////////////////////////////////////////////// - // parseRequest - //////////////////////////////////////////////// - - public boolean parseRequestLine(String lineStr) - { - StringTokenizer st = new StringTokenizer(lineStr, HTTP.REQEST_LINE_DELIM); - if (st.hasMoreTokens() == false) - return false; - setMethod(st.nextToken()); - if (st.hasMoreTokens() == false) - return false; - setURI(st.nextToken()); - if (st.hasMoreTokens() == false) - return false; - setVersion(st.nextToken()); - return true; - } + + //////////////////////////////////////////////// + // parseRequest + //////////////////////////////////////////////// + + public boolean parseRequestLine(String lineStr) + { + StringTokenizer st = new StringTokenizer(lineStr, HTTP.REQEST_LINE_DELIM); + if (st.hasMoreTokens() == false) + return false; + setMethod(st.nextToken()); + if (st.hasMoreTokens() == false) + return false; + setURI(st.nextToken()); + if (st.hasMoreTokens() == false) + return false; + setVersion(st.nextToken()); + return true; + } //////////////////////////////////////////////// // First Line @@ -311,22 +311,22 @@ public class HTTPRequest extends HTTPPacket return getMethod() + " " + getURI() + " " + getHTTPVersion() + HTTP.CRLF; } - //////////////////////////////////////////////// - // getHeader - //////////////////////////////////////////////// - - public String getHeader() - { - StringBuffer str = new StringBuffer(); - - str.append(getFirstLineString()); - + //////////////////////////////////////////////// + // getHeader + //////////////////////////////////////////////// + + public String getHeader() + { + StringBuffer str = new StringBuffer(); + + str.append(getFirstLineString()); + String headerString = getHeaderString(); str.append(headerString); - - return str.toString(); - } - + + return str.toString(); + } + //////////////////////////////////////////////// // isKeepAlive //////////////////////////////////////////////// @@ -353,9 +353,9 @@ public class HTTPRequest extends HTTPPacket return super.read(getSocket()); } - //////////////////////////////////////////////// - // POST (Response) - //////////////////////////////////////////////// + //////////////////////////////////////////////// + // POST (Response) + //////////////////////////////////////////////// public boolean post(HTTPResponse httpRes) { @@ -380,15 +380,15 @@ public class HTTPRequest extends HTTPPacket return httpSock.post(httpRes, offset, length, isHeadRequest()); //httpSock.close(); } - + //////////////////////////////////////////////// // POST (Request) //////////////////////////////////////////////// private Socket postSocket = null; - public HTTPResponse post(String host, int port, boolean isKeepAlive) - { + public HTTPResponse post(String host, int port, boolean isKeepAlive) + { HTTPResponse httpRes = new HTTPResponse(); setHost(host); @@ -401,15 +401,15 @@ public class HTTPRequest extends HTTPPacket InputStream in = null; try { - if (postSocket == null){ + if (postSocket == null){ // Thanks for Hao Hu postSocket = new Socket(); postSocket.connect(new InetSocketAddress(host, port), HTTPServer.DEFAULT_TIMEOUT); - } - - out = postSocket.getOutputStream(); - PrintStream pout = new PrintStream(out); - pout.print(getHeader()); + } + + out = postSocket.getOutputStream(); + PrintStream pout = new PrintStream(out); + pout.print(getHeader()); pout.print(HTTP.CRLF); boolean isChunkedRequest = isChunked(); @@ -418,7 +418,7 @@ public class HTTPRequest extends HTTPPacket int contentLength = 0; if (content != null) contentLength = content.length(); - + if (0 < contentLength) { if (isChunkedRequest == true) { // Thanks for Lee Peik Feng <pflee@users.sourceforge.net> (07/07/05) @@ -436,7 +436,7 @@ public class HTTPRequest extends HTTPPacket pout.print(HTTP.CRLF); } - pout.flush(); + pout.flush(); in = postSocket.getInputStream(); httpRes.set(in, isHeaderRequest); @@ -466,7 +466,7 @@ public class HTTPRequest extends HTTPPacket } return httpRes; - } + } public HTTPResponse post(String host, int port) { @@ -505,20 +505,20 @@ public class HTTPRequest extends HTTPPacket return returnResponse(HTTPStatus.BAD_REQUEST); } - //////////////////////////////////////////////// - // toString - //////////////////////////////////////////////// - - public String toString() - { - StringBuffer str = new StringBuffer(); - - str.append(getHeader()); - str.append(HTTP.CRLF); - str.append(getContentString()); - - return str.toString(); - } + //////////////////////////////////////////////// + // toString + //////////////////////////////////////////////// + + public String toString() + { + StringBuffer str = new StringBuffer(); + + str.append(getHeader()); + str.append(HTTP.CRLF); + str.append(getContentString()); + + return str.toString(); + } public void print() { diff --git a/router/java/src/org/cybergarage/http/HTTPRequestListener.java b/router/java/src/org/cybergarage/http/HTTPRequestListener.java index 12fcf349ed4db18331ce073c10e3761a31894a95..2612a92830006353f5527a50390679076a9c3689 100644 --- a/router/java/src/org/cybergarage/http/HTTPRequestListener.java +++ b/router/java/src/org/cybergarage/http/HTTPRequestListener.java @@ -5,17 +5,17 @@ * Copyright (C) Satoshi Konno 2002 * * File: HTTPRequestListener.java -* -* Revision; -* -* 12/13/02 -* - first revision. +* +* Revision; +* +* 12/13/02 +* - first revision. * ******************************************************************/ - -package org.cybergarage.http; - -public interface HTTPRequestListener -{ - public void httpRequestRecieved(HTTPRequest httpReq); + +package org.cybergarage.http; + +public interface HTTPRequestListener +{ + public void httpRequestRecieved(HTTPRequest httpReq); } diff --git a/router/java/src/org/cybergarage/http/HTTPResponse.java b/router/java/src/org/cybergarage/http/HTTPResponse.java index e028e02f52b9710e359846798f55a12d6fe360d3..92428dff38b2d6d78194b742f92d4de92961e66a 100644 --- a/router/java/src/org/cybergarage/http/HTTPResponse.java +++ b/router/java/src/org/cybergarage/http/HTTPResponse.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: HTTPResponse.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 10/22/03 * - Changed to initialize a content length header. * 10/22/04 @@ -17,23 +17,23 @@ * ******************************************************************/ -package org.cybergarage.http; +package org.cybergarage.http; import java.io.InputStream; - -public class HTTPResponse extends HTTPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPResponse() - { + +public class HTTPResponse extends HTTPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPResponse() + { setVersion(HTTP.VERSION_11); setContentType(HTML.CONTENT_TYPE); setServer(HTTPServer.getName()); setContent(""); - } + } public HTTPResponse(HTTPResponse httpRes) { @@ -49,25 +49,25 @@ public class HTTPResponse extends HTTPPacket { this(httpSock.getInputStream()); } - - //////////////////////////////////////////////// - // Status Line - //////////////////////////////////////////////// + + //////////////////////////////////////////////// + // Status Line + //////////////////////////////////////////////// private int statusCode = 0; - - public void setStatusCode(int code) + + public void setStatusCode(int code) { - statusCode = code; - } - - public int getStatusCode() + statusCode = code; + } + + public int getStatusCode() { if (statusCode != 0) - return statusCode; + return statusCode; HTTPStatus httpStatus = new HTTPStatus(getFirstLine()); - return httpStatus.getStatusCode(); - } + return httpStatus.getStatusCode(); + } public boolean isSuccessful() { @@ -78,20 +78,20 @@ public class HTTPResponse extends HTTPPacket { return "HTTP/" + getVersion() + " " + getStatusCode() + " " + HTTPStatus.code2String(statusCode) + HTTP.CRLF; } - - //////////////////////////////////////////////// - // getHeader - //////////////////////////////////////////////// - - public String getHeader() - { - StringBuffer str = new StringBuffer(); - - str.append(getStatusLineString()); + + //////////////////////////////////////////////// + // getHeader + //////////////////////////////////////////////// + + public String getHeader() + { + StringBuffer str = new StringBuffer(); + + str.append(getStatusLineString()); str.append(getHeaderString()); - - return str.toString(); - } + + return str.toString(); + } //////////////////////////////////////////////// // toString diff --git a/router/java/src/org/cybergarage/http/HTTPServerThread.java b/router/java/src/org/cybergarage/http/HTTPServerThread.java index 70524edbe3ec9e0c90d95ed083d989746eaee0bb..7ce1941b5a4842fefbbbefd4d097a5fcbdca8f1e 100644 --- a/router/java/src/org/cybergarage/http/HTTPServerThread.java +++ b/router/java/src/org/cybergarage/http/HTTPServerThread.java @@ -1,54 +1,54 @@ -/****************************************************************** -* -* CyberHTTP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: HTTPServerThread.java -* -* Revision; -* -* 10/10/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.http; - -import java.net.Socket; - -public class HTTPServerThread extends Thread -{ - private HTTPServer httpServer; - private Socket sock; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPServerThread(HTTPServer httpServer, Socket sock) - { - super("Cyber.HTTPServerThread"); - this.httpServer = httpServer; - this.sock = sock; - } - - //////////////////////////////////////////////// - // run - //////////////////////////////////////////////// - - public void run() - { - HTTPSocket httpSock = new HTTPSocket(sock); - if (httpSock.open() == false) - return; - HTTPRequest httpReq = new HTTPRequest(); - httpReq.setSocket(httpSock); - while (httpReq.read() == true) { - httpServer.performRequestListener(httpReq); - if (httpReq.isKeepAlive() == false) - break; - } - httpSock.close(); - } -} +/****************************************************************** +* +* CyberHTTP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: HTTPServerThread.java +* +* Revision; +* +* 10/10/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.http; + +import java.net.Socket; + +public class HTTPServerThread extends Thread +{ + private HTTPServer httpServer; + private Socket sock; + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPServerThread(HTTPServer httpServer, Socket sock) + { + super("Cyber.HTTPServerThread"); + this.httpServer = httpServer; + this.sock = sock; + } + + //////////////////////////////////////////////// + // run + //////////////////////////////////////////////// + + public void run() + { + HTTPSocket httpSock = new HTTPSocket(sock); + if (httpSock.open() == false) + return; + HTTPRequest httpReq = new HTTPRequest(); + httpReq.setSocket(httpSock); + while (httpReq.read() == true) { + httpServer.performRequestListener(httpReq); + if (httpReq.isKeepAlive() == false) + break; + } + httpSock.close(); + } +} diff --git a/router/java/src/org/cybergarage/http/HTTPStatus.java b/router/java/src/org/cybergarage/http/HTTPStatus.java index 651fecb34b974a5eee27061c2eaf5f35d5653736..50af3cbd6e835bac11fde91ad3a14c5996af308e 100644 --- a/router/java/src/org/cybergarage/http/HTTPStatus.java +++ b/router/java/src/org/cybergarage/http/HTTPStatus.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002 * * File: HTTPStatus.java -* -* Revision; -* -* 12/17/02 -* - first revision. +* +* Revision; +* +* 12/17/02 +* - first revision. * 09/03/03 * - Added CONTINUE_STATUS. * 10/20/04 @@ -22,105 +22,105 @@ * - Fixed set() to read multi words of the response sring such as Not Found. * ******************************************************************/ - + package org.cybergarage.http; - + import java.util.StringTokenizer; import org.cybergarage.util.Debug; - -public class HTTPStatus -{ - //////////////////////////////////////////////// - // Code - //////////////////////////////////////////////// - + +public class HTTPStatus +{ + //////////////////////////////////////////////// + // Code + //////////////////////////////////////////////// + public static final int CONTINUE = 100; - public static final int OK = 200; + public static final int OK = 200; // Thanks for Brent Hills (10/20/04) public static final int PARTIAL_CONTENT = 206; - public static final int BAD_REQUEST = 400; + public static final int BAD_REQUEST = 400; public static final int NOT_FOUND = 404; public static final int PRECONDITION_FAILED = 412; // Thanks for Brent Hills (10/20/04) public static final int INVALID_RANGE = 416; public static final int INTERNAL_SERVER_ERROR = 500; - public static final String code2String(int code) - { - switch (code) { + public static final String code2String(int code) + { + switch (code) { case CONTINUE: return "Continue"; - case OK: return "OK"; + case OK: return "OK"; case PARTIAL_CONTENT: return "Partial Content"; case BAD_REQUEST: return "Bad Request"; case NOT_FOUND: return "Not Found"; case PRECONDITION_FAILED: return "Precondition Failed"; case INVALID_RANGE: return "Invalid Range"; case INTERNAL_SERVER_ERROR: return "Internal Server Error"; - } - return ""; - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPStatus() - { - setVersion(""); - setStatusCode(0); - setReasonPhrase(""); - } - - public HTTPStatus(String ver, int code, String reason) - { - setVersion(ver); - setStatusCode(code); - setReasonPhrase(reason); - } + } + return ""; + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPStatus() + { + setVersion(""); + setStatusCode(0); + setReasonPhrase(""); + } + + public HTTPStatus(String ver, int code, String reason) + { + setVersion(ver); + setStatusCode(code); + setReasonPhrase(reason); + } public HTTPStatus(String lineStr) { set(lineStr); } - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private String version = ""; - private int statusCode = 0; - private String reasonPhrase = ""; - - public void setVersion(String value) - { - version = value; - } - - public void setStatusCode(int value) - { - statusCode = value; - } - - public void setReasonPhrase(String value) - { - reasonPhrase = value; - } - - public String getVersion() - { - return version; - } - - public int getStatusCode() - { - return statusCode; - } - - public String getReasonPhrase() - { - return reasonPhrase; - } + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private String version = ""; + private int statusCode = 0; + private String reasonPhrase = ""; + + public void setVersion(String value) + { + version = value; + } + + public void setStatusCode(int value) + { + statusCode = value; + } + + public void setReasonPhrase(String value) + { + reasonPhrase = value; + } + + public String getVersion() + { + return version; + } + + public int getStatusCode() + { + return statusCode; + } + + public String getReasonPhrase() + { + return reasonPhrase; + } //////////////////////////////////////////////// // Status diff --git a/router/java/src/org/cybergarage/http/Parameter.java b/router/java/src/org/cybergarage/http/Parameter.java index fb29ae994fe07ca3cabd5f59487aa1f9c247fd07..2ad834070450d180b90651c1c2904e1aa7138345 100644 --- a/router/java/src/org/cybergarage/http/Parameter.java +++ b/router/java/src/org/cybergarage/http/Parameter.java @@ -1,61 +1,61 @@ -/****************************************************************** -* -* CyberHTTP for Java -* -* Copyright (C) Satoshi Konno 2002-2004 -* -* File: Parameter.java -* -* Revision; -* -* 02/01/04 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.http; - -public class Parameter -{ - private String name = new String(); - private String value = new String(); - - public Parameter() - { - } - - public Parameter(String name, String value) - { - setName(name); - setValue(value); - } - - //////////////////////////////////////////////// - // name - //////////////////////////////////////////////// - - public void setName(String name) - { - this.name = name; - } - - public String getName() - { - return name; - } - - //////////////////////////////////////////////// - // value - //////////////////////////////////////////////// - - public void setValue(String value) - { - this.value = value; - } - - public String getValue() - { - return value; - } -} - +/****************************************************************** +* +* CyberHTTP for Java +* +* Copyright (C) Satoshi Konno 2002-2004 +* +* File: Parameter.java +* +* Revision; +* +* 02/01/04 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.http; + +public class Parameter +{ + private String name = new String(); + private String value = new String(); + + public Parameter() + { + } + + public Parameter(String name, String value) + { + setName(name); + setValue(value); + } + + //////////////////////////////////////////////// + // name + //////////////////////////////////////////////// + + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + //////////////////////////////////////////////// + // value + //////////////////////////////////////////////// + + public void setValue(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } +} + diff --git a/router/java/src/org/cybergarage/http/ParameterList.java b/router/java/src/org/cybergarage/http/ParameterList.java index 9f395be6ad52f49f1e597653813bd0c8cd0c1dd4..868676dcf06ec0c639805171339c206fb48e7120 100644 --- a/router/java/src/org/cybergarage/http/ParameterList.java +++ b/router/java/src/org/cybergarage/http/ParameterList.java @@ -1,58 +1,58 @@ -/****************************************************************** -* -* CyberHTTP for Java -* -* Copyright (C) Satoshi Konno 2002-2004 -* -* File: ParameterList.java -* -* Revision; -* -* 02/01/04 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.http; - -import java.util.Vector; - -public class ParameterList extends Vector -{ - public ParameterList() - { - } - - public Parameter at(int n) - { - return (Parameter)get(n); - } - - public Parameter getParameter(int n) - { - return (Parameter)get(n); - } - - public Parameter getParameter(String name) - { - if (name == null) - return null; - - int nLists = size(); - for (int n=0; n<nLists; n++) { - Parameter param = at(n); - if (name.compareTo(param.getName()) == 0) - return param; - } - return null; - } - - public String getValue(String name) - { - Parameter param = getParameter(name); - if (param == null) - return ""; - return param.getValue(); - } -} - +/****************************************************************** +* +* CyberHTTP for Java +* +* Copyright (C) Satoshi Konno 2002-2004 +* +* File: ParameterList.java +* +* Revision; +* +* 02/01/04 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.http; + +import java.util.Vector; + +public class ParameterList extends Vector +{ + public ParameterList() + { + } + + public Parameter at(int n) + { + return (Parameter)get(n); + } + + public Parameter getParameter(int n) + { + return (Parameter)get(n); + } + + public Parameter getParameter(String name) + { + if (name == null) + return null; + + int nLists = size(); + for (int n=0; n<nLists; n++) { + Parameter param = at(n); + if (name.compareTo(param.getName()) == 0) + return param; + } + return null; + } + + public String getValue(String name) + { + Parameter param = getParameter(name); + if (param == null) + return ""; + return param.getValue(); + } +} + diff --git a/router/java/src/org/cybergarage/net/HostInterface.java b/router/java/src/org/cybergarage/net/HostInterface.java index b4453c93d3d7b0162ede272cb28d0a5a9f65ba4c..7529f20896cd0862102801097c8932972d96621d 100644 --- a/router/java/src/org/cybergarage/net/HostInterface.java +++ b/router/java/src/org/cybergarage/net/HostInterface.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: HostInterface.java -* -* Revision; -* -* 05/12/03 -* - first revision. +* +* Revision; +* +* 05/12/03 +* - first revision. * 05/13/03 * - Added support for IPv6 and loopback address. * 02/15/04 @@ -22,9 +22,9 @@ * - Changed isUseAddress() to isUsableAddress(). * ******************************************************************/ - -package org.cybergarage.net; - + +package org.cybergarage.net; + import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; @@ -35,9 +35,9 @@ import java.util.Enumeration; import java.util.Vector; import org.cybergarage.util.Debug; - -public class HostInterface -{ + +public class HostInterface +{ //////////////////////////////////////////////// // Constants //////////////////////////////////////////////// diff --git a/router/java/src/org/cybergarage/soap/SOAP.java b/router/java/src/org/cybergarage/soap/SOAP.java index bc44b35a8205644985eb011a0b8478b4c2224dcb..e3e46fa0ed9da0356c5c9ee9f518df772ffc47e1 100644 --- a/router/java/src/org/cybergarage/soap/SOAP.java +++ b/router/java/src/org/cybergarage/soap/SOAP.java @@ -5,45 +5,45 @@ * Copyright (C) Satoshi Konno 2002 * * File: SOAP.java -* -* Revision; -* -* 12/11/02 -* - first revision. +* +* Revision; +* +* 12/11/02 +* - first revision. * ******************************************************************/ - -package org.cybergarage.soap; + +package org.cybergarage.soap; import org.cybergarage.xml.Node; import org.cybergarage.xml.Parser; - -public class SOAP -{ - public static final String ENVELOPE = "Envelope"; - public static final String BODY = "Body"; - public static final String RESPONSE = "Response"; - public static final String FAULT = "Fault"; - public static final String FAULT_CODE = "faultcode"; - public static final String FAULT_STRING = "faultstring"; - public static final String FAULTACTOR = "faultactor"; - public static final String DETAIL = "detail"; - - public static final String RESULTSTATUS = "ResultStatus"; - public static final String UPNP_ERROR = "UPnPError"; - public static final String ERROR_CODE = "errorCode"; - public static final String ERROR_DESCRIPTION = "errorDescription"; - - //public static final String XMLNS = "SOAP-ENV"; - public static final String XMLNS = "s"; - public static final String METHODNS = "u"; + +public class SOAP +{ + public static final String ENVELOPE = "Envelope"; + public static final String BODY = "Body"; + public static final String RESPONSE = "Response"; + public static final String FAULT = "Fault"; + public static final String FAULT_CODE = "faultcode"; + public static final String FAULT_STRING = "faultstring"; + public static final String FAULTACTOR = "faultactor"; + public static final String DETAIL = "detail"; + + public static final String RESULTSTATUS = "ResultStatus"; + public static final String UPNP_ERROR = "UPnPError"; + public static final String ERROR_CODE = "errorCode"; + public static final String ERROR_DESCRIPTION = "errorDescription"; + + //public static final String XMLNS = "SOAP-ENV"; + public static final String XMLNS = "s"; + public static final String METHODNS = "u"; public static final String DELIM = ":"; - - public static final String XMLNS_URL = "http://schemas.xmlsoap.org/soap/envelope/"; - public static final String ENCSTYLE_URL = "http://schemas.xmlsoap.org/soap/encoding/"; - - public static final String CONTENT_TYPE = "text/xml; charset=\"utf-8\""; - public static final String VERSION_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; + + public static final String XMLNS_URL = "http://schemas.xmlsoap.org/soap/envelope/"; + public static final String ENCSTYLE_URL = "http://schemas.xmlsoap.org/soap/encoding/"; + + public static final String CONTENT_TYPE = "text/xml; charset=\"utf-8\""; + public static final String VERSION_HEADER = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; //////////////////////////////////////////////// // createEnvelopeBodyNode @@ -78,5 +78,5 @@ public class SOAP { return xmlParser; } -} +} diff --git a/router/java/src/org/cybergarage/soap/SOAPRequest.java b/router/java/src/org/cybergarage/soap/SOAPRequest.java index f355b0a92e28280684837f452c73320a8ea97a45..06448ffc2db5b4a3f1b031c3bd7b9b7264b0b894 100644 --- a/router/java/src/org/cybergarage/soap/SOAPRequest.java +++ b/router/java/src/org/cybergarage/soap/SOAPRequest.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002 * * File: SOAPRequest.java -* -* Revision; -* -* 12/11/02 -* - first revision. +* +* Revision; +* +* 12/11/02 +* - first revision. * 02/13/04 * - Ralf G. R. Bergs <Ralf@Ber.gs>, Inma Marin Lopez <inma@dif.um.es>. * - Added XML header, <?xml version=\"1.0\"?> to setContent(). @@ -17,9 +17,9 @@ * - Changed the XML header to <?xml version="1.0" encoding="utf-8"?> in setContent(). * ******************************************************************/ - -package org.cybergarage.soap; - + +package org.cybergarage.soap; + import java.io.ByteArrayInputStream; import org.cybergarage.http.HTTP; @@ -29,20 +29,20 @@ import org.cybergarage.util.Debug; import org.cybergarage.xml.Node; import org.cybergarage.xml.Parser; import org.cybergarage.xml.ParserException; - -public class SOAPRequest extends HTTPRequest + +public class SOAPRequest extends HTTPRequest { private final static String SOAPACTION = "SOAPACTION"; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SOAPRequest() + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SOAPRequest() { - setContentType(SOAP.CONTENT_TYPE); - setMethod(HTTP.POST); - } + setContentType(SOAP.CONTENT_TYPE); + setMethod(HTTP.POST); + } public SOAPRequest(HTTPRequest httpReq) { @@ -75,33 +75,33 @@ public class SOAPRequest extends HTTPRequest return false; return soapAction.equals(value); } - - //////////////////////////////////////////////// - // post - //////////////////////////////////////////////// - - public SOAPResponse postMessage(String host, int port) - { - HTTPResponse httpRes = post(host, port); + + //////////////////////////////////////////////// + // post + //////////////////////////////////////////////// + + public SOAPResponse postMessage(String host, int port) + { + HTTPResponse httpRes = post(host, port); - SOAPResponse soapRes = new SOAPResponse(httpRes); - - byte content[] = soapRes.getContent(); - if (content.length <= 0) - return soapRes; - - try { - ByteArrayInputStream byteIn = new ByteArrayInputStream(content); - Parser xmlParser = SOAP.getXMLParser(); - Node rootNode = xmlParser.parse(byteIn); - soapRes.setEnvelopeNode(rootNode); - } - catch (Exception e) { - Debug.warning(e); - } - - return soapRes; - } + SOAPResponse soapRes = new SOAPResponse(httpRes); + + byte content[] = soapRes.getContent(); + if (content.length <= 0) + return soapRes; + + try { + ByteArrayInputStream byteIn = new ByteArrayInputStream(content); + Parser xmlParser = SOAP.getXMLParser(); + Node rootNode = xmlParser.parse(byteIn); + soapRes.setEnvelopeNode(rootNode); + } + catch (Exception e) { + Debug.warning(e); + } + + return soapRes; + } //////////////////////////////////////////////// // Node diff --git a/router/java/src/org/cybergarage/soap/SOAPResponse.java b/router/java/src/org/cybergarage/soap/SOAPResponse.java index 4326cd2cc87c4e285beca85ad7eac6ade2b1bd95..4ee8341a39a0180f9bea735e360889bf835ec8c4 100644 --- a/router/java/src/org/cybergarage/soap/SOAPResponse.java +++ b/router/java/src/org/cybergarage/soap/SOAPResponse.java @@ -34,21 +34,21 @@ public class SOAPResponse extends HTTPResponse public SOAPResponse() { setRootNode(SOAP.createEnvelopeBodyNode()); - setContentType(XML.CONTENT_TYPE); + setContentType(XML.DEFAULT_CONTENT_TYPE); } public SOAPResponse(HTTPResponse httpRes) { super(httpRes); setRootNode(SOAP.createEnvelopeBodyNode()); - setContentType(XML.CONTENT_TYPE); + setContentType(XML.DEFAULT_CONTENT_TYPE); } public SOAPResponse(SOAPResponse soapRes) { super(soapRes); setEnvelopeNode(soapRes.getEnvelopeNode()); - setContentType(XML.CONTENT_TYPE); + setContentType(XML.DEFAULT_CONTENT_TYPE); } //////////////////////////////////////////////// diff --git a/router/java/src/org/cybergarage/upnp/ActionList.java b/router/java/src/org/cybergarage/upnp/ActionList.java index f18130c46bb118ebbf4ca85985a129f815014a96..e3df549316d6b90c1d9a24d5fbcb1ca7946a4ddf 100644 --- a/router/java/src/org/cybergarage/upnp/ActionList.java +++ b/router/java/src/org/cybergarage/upnp/ActionList.java @@ -1,45 +1,45 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: ActionList.java -* -* Revision: -* -* 12/05/02 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ActionList.java +* +* Revision: +* +* 12/05/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp; + +import java.util.Vector; + +public class ActionList extends Vector +{ + //////////////////////////////////////////////// + // 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 -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "actionList"; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public ActionList() - { - } - - //////////////////////////////////////////////// - // Methods - //////////////////////////////////////////////// - - public Action getAction(int n) - { - return (Action)get(n); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/Device.java b/router/java/src/org/cybergarage/upnp/Device.java index 2457b3609779878266a9f639c95d653e6ce7190b..cb0a92b1391227cc2d4219080c965fde84def4f8 100644 --- a/router/java/src/org/cybergarage/upnp/Device.java +++ b/router/java/src/org/cybergarage/upnp/Device.java @@ -1,98 +1,98 @@ /****************************************************************** -* -* CyberLink for Java -* -* Copyright (C) Satoshi Konno 2002-2004 -* -* File: Device.java -* -* Revision: -* -* 11/28/02 -* - first revision. -* 02/26/03 -* - URLBase is updated automatically. -* - Description of a root device is returned from the XML node tree. -* 05/13/03 -* - URLBase is updated when the request is received. -* - Changed to create socket threads each local interfaces. -* (HTTP, SSDPSearch) -* 06/17/03 -* - Added notify all state variables when a new subscription is received. -* 06/18/03 -* - Fixed a announce bug when the bind address is null on J2SE v 1.4.1_02 and Redhat 9. -* 09/02/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Problem : bad request response sent even with successful subscriptions -* - Error : a return statement is missing in the httpRequestRecieved method -* 10/21/03 -* - Updated a udn field by a original uuid. -* 10/22/03 -* - Added setActionListener(). -* - Added setQueryListener(). -* 12/12/03 -* - Added a static() to initialize UPnP class. -* 12/25/03 -* - Added advertiser functions. -* 01/05/04 -* - Added isExpired(). -* 03/23/04 -* - Oliver Newell <newell@media-rush.com> -* - Changed to update the UDN only when the field is null. -* 04/21/04 -* - Added isDeviceType(). -* 06/18/04 -* - Added setNMPRMode() and isNMPRMode(). -* - Changed getDescriptionData() to update only when the NMPR mode is false. -* 06/21/04 -* - Changed start() to send a bye-bye before the announce. -* - Changed annouce(), byebye() and deviceSearchReceived() to send the SSDP -* messsage four times when the NMPR and the Wireless mode are true. -* 07/02/04 -* - Fixed announce() and byebye() to send the upnp::rootdevice message despite embedded devices. -* - Fixed getRootNode() to return the root node when the device is embedded. -* 07/24/04 -* - Thanks for Stefano Lenzi <kismet-sl@users.sourceforge.net> -* - Added getParentDevice(). -* 10/20/04 -* - Brent Hills <bhills@openshores.com> -* - Changed postSearchResponse() to add MYNAME header. -* 11/19/04 -* - Theo Beisch <theo.beisch@gmx.de> -* - Added getStateVariable(String serviceType, String name). -* 03/22/05 -* - Changed httpPostRequestRecieved() to return the bad request when the post request isn't the soap action. -* 03/23/05 -* - Added loadDescription(String) to load the description from memory. -* 03/30/05 -* - Added getDeviceByDescriptionURI(). -* - Added getServiceBySCPDURL(). -* 03/31/05 -* - Changed httpGetRequestRecieved() to return the description stream using -* Device::getDescriptionData() and Service::getSCPDData() at first. -* 04/25/05 -* - Thanks for Mikael Hakman <mhakman@dkab.net> -* Changed announce() and byebye() to close the socket after the posting. -* 04/25/05 -* - Thanks for Mikael Hakman <mhakman@dkab.net> -* Changed deviceSearchResponse() answer with USN:UDN::<device-type> when request ST is device type. -* 04/25/05 -* - Thanks for Mikael Hakman <mhakman@dkab.net> -* - Changed getDescriptionData() to add a XML declaration at first line. -* 04/25/05 -* - Thanks for Mikael Hakman <mhakman@dkab.net> -* - Added a new setActionListener() and serQueryListner() to include the sub devices. -* 07/24/05 -* - Thanks for Stefano Lenzi <kismet-sl@users.sourceforge.net> -* - Fixed a bug of getParentDevice() to return the parent device normally. -* 02/21/06 -* - Changed httpRequestRecieved() not to ignore HEAD requests. -* 04/12/06 -* - Added setUserData() and getUserData() to set a user original data object. -* 03/29/08 -* - Added isRunning() to know whether the device is running. -* -******************************************************************/ + * + * CyberLink for Java + * + * Copyright (C) Satoshi Konno 2002-2004 + * + * File: Device.java + * + * Revision: + * + * 11/28/02 + * - first revision. + * 02/26/03 + * - URLBase is updated automatically. + * - Description of a root device is returned from the XML node tree. + * 05/13/03 + * - URLBase is updated when the request is received. + * - Changed to create socket threads each local interfaces. + * (HTTP, SSDPSearch) + * 06/17/03 + * - Added notify all state variables when a new subscription is received. + * 06/18/03 + * - Fixed a announce bug when the bind address is null on J2SE v 1.4.1_02 and Redhat 9. + * 09/02/03 + * - Giordano Sassaroli <sassarol@cefriel.it> + * - Problem : bad request response sent even with successful subscriptions + * - Error : a return statement is missing in the httpRequestRecieved method + * 10/21/03 + * - Updated a udn field by a original uuid. + * 10/22/03 + * - Added setActionListener(). + * - Added setQueryListener(). + * 12/12/03 + * - Added a static() to initialize UPnP class. + * 12/25/03 + * - Added advertiser functions. + * 01/05/04 + * - Added isExpired(). + * 03/23/04 + * - Oliver Newell <newell@media-rush.com> + * - Changed to update the UDN only when the field is null. + * 04/21/04 + * - Added isDeviceType(). + * 06/18/04 + * - Added setNMPRMode() and isNMPRMode(). + * - Changed getDescriptionData() to update only when the NMPR mode is false. + * 06/21/04 + * - Changed start() to send a bye-bye before the announce. + * - Changed annouce(), byebye() and deviceSearchReceived() to send the SSDP + * messsage four times when the NMPR and the Wireless mode are true. + * 07/02/04 + * - Fixed announce() and byebye() to send the upnp::rootdevice message despite embedded devices. + * - Fixed getRootNode() to return the root node when the device is embedded. + * 07/24/04 + * - Thanks for Stefano Lenzi <kismet-sl@users.sourceforge.net> + * - Added getParentDevice(). + * 10/20/04 + * - Brent Hills <bhills@openshores.com> + * - Changed postSearchResponse() to add MYNAME header. + * 11/19/04 + * - Theo Beisch <theo.beisch@gmx.de> + * - Added getStateVariable(String serviceType, String name). + * 03/22/05 + * - Changed httpPostRequestRecieved() to return the bad request when the post request isn't the soap action. + * 03/23/05 + * - Added loadDescription(String) to load the description from memory. + * 03/30/05 + * - Added getDeviceByDescriptionURI(). + * - Added getServiceBySCPDURL(). + * 03/31/05 + * - Changed httpGetRequestRecieved() to return the description stream using + * Device::getDescriptionData() and Service::getSCPDData() at first. + * 04/25/05 + * - Thanks for Mikael Hakman <mhakman@dkab.net> + * Changed announce() and byebye() to close the socket after the posting. + * 04/25/05 + * - Thanks for Mikael Hakman <mhakman@dkab.net> + * Changed deviceSearchResponse() answer with USN:UDN::<device-type> when request ST is device type. + * 04/25/05 + * - Thanks for Mikael Hakman <mhakman@dkab.net> + * - Changed getDescriptionData() to add a XML declaration at first line. + * 04/25/05 + * - Thanks for Mikael Hakman <mhakman@dkab.net> + * - Added a new setActionListener() and serQueryListner() to include the sub devices. + * 07/24/05 + * - Thanks for Stefano Lenzi <kismet-sl@users.sourceforge.net> + * - Fixed a bug of getParentDevice() to return the parent device normally. + * 02/21/06 + * - Changed httpRequestRecieved() not to ignore HEAD requests. + * 04/12/06 + * - Added setUserData() and getUserData() to set a user original data object. + * 03/29/08 + * - Added isRunning() to know whether the device is running. + * + ******************************************************************/ package org.cybergarage.upnp; @@ -101,6 +101,7 @@ import java.io.InputStream; import java.net.InetAddress; import java.net.URL; import java.util.Calendar; +import java.util.HashMap; import org.cybergarage.http.HTTP; import org.cybergarage.http.HTTPRequest; @@ -123,6 +124,7 @@ import org.cybergarage.upnp.device.NTS; import org.cybergarage.upnp.device.ST; import org.cybergarage.upnp.device.SearchListener; import org.cybergarage.upnp.device.USN; +import org.cybergarage.upnp.device.PresentationListener; import org.cybergarage.upnp.event.Subscriber; import org.cybergarage.upnp.event.Subscription; import org.cybergarage.upnp.event.SubscriptionRequest; @@ -143,12 +145,12 @@ import org.cybergarage.xml.Parser; import org.cybergarage.xml.ParserException; import org.cybergarage.xml.XML; -public class Device implements org.cybergarage.http.HTTPRequestListener, SearchListener -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - +public class Device implements org.cybergarage.http.HTTPRequestListener, + SearchListener { + // ////////////////////////////////////////////// + // Constants + // ////////////////////////////////////////////// + public final static String ELEM_NAME = "device"; public final static String UPNP_ROOTDEVICE = "upnp:rootdevice"; @@ -159,16 +161,16 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL public final static int HTTP_DEFAULT_PORT = 4004; public final static String DEFAULT_DESCRIPTION_URI = "/description.xml"; - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// + public final static String DEFAULT_PRESENTATION_URI = "/presentation"; + + // ////////////////////////////////////////////// + // Member + // ////////////////////////////////////////////// private Node rootNode; private Node deviceNode; - public Node getRootNode() - { + public Node getRootNode() { if (rootNode != null) return rootNode; if (deviceNode == null) @@ -176,54 +178,46 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return deviceNode.getRootNode(); } - public Node getDeviceNode() - { + public Node getDeviceNode() { return deviceNode; } - public void setRootNode(Node node) - { + public void setRootNode(Node node) { rootNode = node; } - public void setDeviceNode(Node node) - { + public void setDeviceNode(Node node) { deviceNode = node; } - - //////////////////////////////////////////////// - // Initialize - //////////////////////////////////////////////// - - static - { + + // ////////////////////////////////////////////// + // Initialize + // ////////////////////////////////////////////// + + static { UPnP.initialize(); } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - public Device(Node root, Node device) - { + // ////////////////////////////////////////////// + // Constructor + // ////////////////////////////////////////////// + + public Device(Node root, Node device) { rootNode = root; deviceNode = device; setUUID(UPnP.createUUID()); setWirelessMode(false); } - public Device() - { + public Device() { this(null, null); } - - public Device(Node device) - { + + public Device(Node device) { this(null, device); } - public Device(File descriptionFile) throws InvalidDescriptionException - { + public Device(File descriptionFile) throws InvalidDescriptionException { this(null, null); loadDescription(descriptionFile); } @@ -231,151 +225,251 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL /** * @since 1.8.0 */ - public Device(InputStream input) throws InvalidDescriptionException - { + public Device(InputStream input) throws InvalidDescriptionException { this(null, null); loadDescription(input); } - - public Device(String descriptionFileName) throws InvalidDescriptionException - { + public Device(String descriptionFileName) + throws InvalidDescriptionException { this(new File(descriptionFileName)); } - //////////////////////////////////////////////// + // ////////////////////////////////////////////// // Mutex - //////////////////////////////////////////////// - + // ////////////////////////////////////////////// + private Mutex mutex = new Mutex(); - - public void lock() - { + + public void lock() { mutex.lock(); } - - public void unlock() - { + + public void unlock() { mutex.unlock(); } - - //////////////////////////////////////////////// - // getAbsoluteURL - //////////////////////////////////////////////// - - public String getAbsoluteURL(String urlString) - { + + // ////////////////////////////////////////////// + // getAbsoluteURL + // ////////////////////////////////////////////// + + public String getAbsoluteURL(String urlString, String baseURLStr, + String locationURLStr) { + if ((urlString == null) || (urlString.length() <= 0)) + return ""; + try { URL url = new URL(urlString); return url.toString(); - } - catch (Exception e) {} - - Device rootDev = getRootDevice(); - String urlBaseStr = rootDev.getURLBase(); - - // Thanks for Steven Yen (2003/09/03) - if (urlBaseStr == null || urlBaseStr.length() <= 0) { - String location = rootDev.getLocation(); - String locationHost = HTTP.getHost(location); - int locationPort = HTTP.getPort(location); - urlBaseStr = HTTP.getRequestHostURL(locationHost, locationPort); + } catch (Exception e) { + } + + if ((baseURLStr == null) || (baseURLStr.length() <= 0)) { + if ((locationURLStr != null) && (0 < locationURLStr.length())) { + if (!locationURLStr.endsWith("/") || !urlString.startsWith("/")) { + String absUrl = locationURLStr + urlString; + try { + URL url = new URL(absUrl); + return url.toString(); + } catch (Exception e) { + } + } else { + String absUrl = locationURLStr + urlString.substring(1); + try { + URL url = new URL(absUrl); + return url.toString(); + } catch (Exception e) { + } + } + + String absUrl = HTTP.getAbsoluteURL(locationURLStr, urlString); + try { + URL url = new URL(absUrl); + return url.toString(); + } catch (Exception e) { + } + + // Thanks for Steven Yen (2003/09/03) + Device rootDev = getRootDevice(); + if (rootDev != null) { + String location = rootDev.getLocation(); + String locationHost = HTTP.getHost(location); + int locationPort = HTTP.getPort(location); + baseURLStr = HTTP.getRequestHostURL(locationHost, + locationPort); + } + } } - urlString = HTTP.toRelativeURL(urlString); - String absUrl = urlBaseStr + urlString; - try { - URL url = new URL(absUrl); - return url.toString(); + if ((baseURLStr != null) && (0 < baseURLStr.length())) { + if (!baseURLStr.endsWith("/") || !urlString.startsWith("/")) { + String absUrl = baseURLStr + urlString; + try { + URL url = new URL(absUrl); + return url.toString(); + } catch (Exception e) { + } + } else { + String absUrl = baseURLStr + urlString.substring(1); + try { + URL url = new URL(absUrl); + return url.toString(); + } catch (Exception e) { + } + } + + String absUrl = HTTP.getAbsoluteURL(baseURLStr, urlString); + try { + URL url = new URL(absUrl); + return url.toString(); + } catch (Exception e) { + } } - catch (Exception e) {} - - absUrl = HTTP.getAbsoluteURL(urlBaseStr, urlString); - try { - URL url = new URL(absUrl); - return url.toString(); + + return urlString; + } + + public String getAbsoluteURL(String urlString) { + String baseURLStr = null; + String locationURLStr = null; + + Device rootDev = getRootDevice(); + if (rootDev != null) { + baseURLStr = rootDev.getURLBase(); + locationURLStr = rootDev.getLocation(); } - catch (Exception e) {} - - return ""; + + return getAbsoluteURL(urlString, baseURLStr, locationURLStr); } - //////////////////////////////////////////////// - // NMPR - //////////////////////////////////////////////// - - public void setNMPRMode(boolean flag) - { + // ////////////////////////////////////////////// + // NMPR + // ////////////////////////////////////////////// + + public void setNMPRMode(boolean flag) { Node devNode = getDeviceNode(); if (devNode == null) return; if (flag == true) { devNode.setNode(UPnP.INMPR03, UPnP.INMPR03_VERSION); devNode.removeNode(Device.URLBASE_NAME); - } - else { + } else { devNode.removeNode(UPnP.INMPR03); } } - public boolean isNMPRMode() - { + public boolean isNMPRMode() { Node devNode = getDeviceNode(); if (devNode == null) return false; return (devNode.getNode(UPnP.INMPR03) != null) ? true : false; } - - //////////////////////////////////////////////// - // Wireless - //////////////////////////////////////////////// - + + // ////////////////////////////////////////////// + // Wireless + // ////////////////////////////////////////////// + private boolean wirelessMode; - - public void setWirelessMode(boolean flag) - { + + public void setWirelessMode(boolean flag) { wirelessMode = flag; } - public boolean isWirelessMode() - { + public boolean isWirelessMode() { return wirelessMode; } - public int getSSDPAnnounceCount() - { + public int getSSDPAnnounceCount() { if (isNMPRMode() == true && isWirelessMode() == true) return UPnP.INMPR03_DISCOVERY_OVER_WIRELESS_COUNT; return 1; } - //////////////////////////////////////////////// - // Device UUID - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // Device UUID + // ////////////////////////////////////////////// private String devUUID; - - private void setUUID(String uuid) - { - devUUID = uuid; - } - - private String getUUID() - { - return devUUID; - } - - private void updateUDN() - { - setUDN("uuid:" + getUUID()); - } - - //////////////////////////////////////////////// - // Root Device - //////////////////////////////////////////////// - - public Device getRootDevice() - { + + private void setUUID(String uuid) { + this.devUUID = uuid; + } + + public String getUUID() { + return this.devUUID; + } + + private void updateUDN() { + setUDN("uuid:" + getUUID()); + } + + // ////////////////////////////////////////////// + // BootId + // ////////////////////////////////////////////// + + private int bootId; + + private void updateBootId() { + this.bootId = UPnP.createBootId(); + } + + public int getBootId() { + return this.bootId; + } + + // ////////////////////////////////////////////// + // configID + // ////////////////////////////////////////////// + + private final static String CONFIG_ID = "configId"; + + private void updateConfigId(Device dev) { + int configId = 0; + + DeviceList cdevList = dev.getDeviceList(); + int cdevCnt = cdevList.size(); + for (int n = 0; n < cdevCnt; n++) { + Device cdev = cdevList.getDevice(n); + updateConfigId(cdev); + configId += cdev.getConfigId(); + configId &= UPnP.CONFIGID_UPNP_ORG_MAX; + } + + ServiceList serviceList = dev.getServiceList(); + int serviceCnt = serviceList.size(); + for (int n = 0; n < serviceCnt; n++) { + Service service = serviceList.getService(n); + service.updateConfigId(); + configId += service.getConfigId(); + configId &= UPnP.CONFIGID_UPNP_ORG_MAX; + } + + Node devNode = getDeviceNode(); + if (devNode == null) + return; + + String devDescXml = devNode.toString(); + configId += UPnP.caluculateConfigId(devDescXml); + configId &= UPnP.CONFIGID_UPNP_ORG_MAX; + devNode.setAttribute(CONFIG_ID, configId); + } + + public void updateConfigId() { + updateConfigId(this); + } + + public int getConfigId() { + Node devNode = getDeviceNode(); + if (devNode == null) + return 0; + return devNode.getAttributeIntegerValue(CONFIG_ID); + } + + // ////////////////////////////////////////////// + // Root Device + // ////////////////////////////////////////////// + + public Device getRootDevice() { Node rootNode = getRootNode(); if (rootNode == null) return null; @@ -385,31 +479,33 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return new Device(rootNode, devNode); } - //////////////////////////////////////////////// - // Parent Device - //////////////////////////////////////////////// - + // ////////////////////////////////////////////// + // Parent Device + // ////////////////////////////////////////////// + // Thanks for Stefano Lenzi (07/24/04) /** * * @return A Device that contain this object.<br> - * Return <code>null</code> if this is a root device. - * @author Stefano "Kismet" Lenzi + * Return <code>null</code> if this is a root device. + * @author Stefano "Kismet" Lenzi */ - public Device getParentDevice() { - if(isRootDevice()) + public Device getParentDevice() { + if (isRootDevice()) return null; Node devNode = getDeviceNode(); Node aux = null; - //<device><deviceList><device> + // <device><deviceList><device> aux = devNode.getParentNode().getParentNode(); return new Device(aux); } + /** * Add a Service to device without checking for duplicate or syntax error * - * @param s Add Service s to the Device + * @param s + * Add Service s to the Device */ public void addService(Service s) { Node serviceListNode = getDeviceNode().getNode(ServiceList.ELEM_NAME); @@ -425,46 +521,47 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL * This method set or reset the root node of the Device and itself<br> * <br> * Note: This method should be used to create a dynamic<br> - * Device withtout writing any XML that describe the device<br>. + * Device withtout writing any XML that describe the device<br> + * . * - * @param d Add Device d to the Device + * @param d + * Add Device d to the Device * - * @author Stefano "Kismet" Lenzi - kismet-sl@users.sourceforge.net - 2005 + * @author Stefano "Kismet" Lenzi - kismet-sl@users.sourceforge.net - 2005 * */ public void addDevice(Device d) { Node deviceListNode = getDeviceNode().getNode(DeviceList.ELEM_NAME); if (deviceListNode == null) { - //deviceListNode = new Node(ServiceList.ELEM_NAME); twa wrong ELEM_NAME; + // deviceListNode = new Node(ServiceList.ELEM_NAME); twa wrong + // ELEM_NAME; deviceListNode = new Node(DeviceList.ELEM_NAME); getDeviceNode().addNode(deviceListNode); } deviceListNode.addNode(d.getDeviceNode()); d.setRootNode(null); - if(getRootNode()==null){ + if (getRootNode() == null) { Node root = new Node(RootDescription.ROOT_ELEMENT); - root.setNameSpace("",RootDescription.ROOT_ELEMENT_NAMESPACE); + root.setNameSpace("", RootDescription.ROOT_ELEMENT_NAMESPACE); Node spec = new Node(RootDescription.SPECVERSION_ELEMENT); - Node maj =new Node(RootDescription.MAJOR_ELEMENT); + Node maj = new Node(RootDescription.MAJOR_ELEMENT); maj.setValue("1"); - Node min =new Node(RootDescription.MINOR_ELEMENT); + Node min = new Node(RootDescription.MINOR_ELEMENT); min.setValue("0"); spec.addNode(maj); spec.addNode(min); - root.addNode(spec); + root.addNode(spec); setRootNode(root); - } - } - + } + } - //////////////////////////////////////////////// - // UserData - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // UserData + // ////////////////////////////////////////////// - private DeviceData getDeviceData() - { + private DeviceData getDeviceData() { Node node = getDeviceNode(); - DeviceData userData = (DeviceData)node.getUserData(); + DeviceData userData = (DeviceData) node.getUserData(); if (userData == null) { userData = new DeviceData(); node.setUserData(userData); @@ -472,121 +569,117 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } return userData; } - - //////////////////////////////////////////////// - // Description - //////////////////////////////////////////////// - private void setDescriptionFile(File file) - { + // ////////////////////////////////////////////// + // Description + // ////////////////////////////////////////////// + + private void setDescriptionFile(File file) { getDeviceData().setDescriptionFile(file); } - public File getDescriptionFile() - { + public File getDescriptionFile() { return getDeviceData().getDescriptionFile(); } - private void setDescriptionURI(String uri) - { + private void setDescriptionURI(String uri) { getDeviceData().setDescriptionURI(uri); } - private String getDescriptionURI() - { + private String getDescriptionURI() { return getDeviceData().getDescriptionURI(); } - private boolean isDescriptionURI(String uri) - { + private boolean isDescriptionURI(String uri) { String descriptionURI = getDescriptionURI(); if (uri == null || descriptionURI == null) return false; return descriptionURI.equals(uri); } - public String getDescriptionFilePath() - { + public String getDescriptionFilePath() { File descriptionFile = getDescriptionFile(); if (descriptionFile == null) return ""; return descriptionFile.getAbsoluteFile().getParent(); } - + /** * @since 1.8.0 */ - public boolean loadDescription(InputStream input) throws InvalidDescriptionException - { + public boolean loadDescription(InputStream input) + throws InvalidDescriptionException { try { Parser parser = UPnP.getXMLParser(); rootNode = parser.parse(input); if (rootNode == null) - throw new InvalidDescriptionException(Description.NOROOT_EXCEPTION); + throw new InvalidDescriptionException( + Description.NOROOT_EXCEPTION); deviceNode = rootNode.getNode(Device.ELEM_NAME); if (deviceNode == null) - throw new InvalidDescriptionException(Description.NOROOTDEVICE_EXCEPTION); - } - catch (ParserException e) { + throw new InvalidDescriptionException( + Description.NOROOTDEVICE_EXCEPTION); + } catch (ParserException e) { throw new InvalidDescriptionException(e); } - + if (initializeLoadedDescription() == false) return false; setDescriptionFile(null); - + return true; - } + } - public boolean loadDescription(String descString) throws InvalidDescriptionException - { + public boolean loadDescription(String descString) + throws InvalidDescriptionException { try { Parser parser = UPnP.getXMLParser(); rootNode = parser.parse(descString); if (rootNode == null) - throw new InvalidDescriptionException(Description.NOROOT_EXCEPTION); + throw new InvalidDescriptionException( + Description.NOROOT_EXCEPTION); deviceNode = rootNode.getNode(Device.ELEM_NAME); if (deviceNode == null) - throw new InvalidDescriptionException(Description.NOROOTDEVICE_EXCEPTION); - } - catch (ParserException e) { + throw new InvalidDescriptionException( + Description.NOROOTDEVICE_EXCEPTION); + } catch (ParserException e) { throw new InvalidDescriptionException(e); } - + if (initializeLoadedDescription() == false) return false; setDescriptionFile(null); - + return true; } - - public boolean loadDescription(File file) throws InvalidDescriptionException - { + + public boolean loadDescription(File file) + throws InvalidDescriptionException { try { Parser parser = UPnP.getXMLParser(); rootNode = parser.parse(file); if (rootNode == null) - throw new InvalidDescriptionException(Description.NOROOT_EXCEPTION, file); + throw new InvalidDescriptionException( + Description.NOROOT_EXCEPTION, file); deviceNode = rootNode.getNode(Device.ELEM_NAME); if (deviceNode == null) - throw new InvalidDescriptionException(Description.NOROOTDEVICE_EXCEPTION, file); - } - catch (ParserException e) { + throw new InvalidDescriptionException( + Description.NOROOTDEVICE_EXCEPTION, file); + } catch (ParserException e) { throw new InvalidDescriptionException(e); } - + if (initializeLoadedDescription() == false) return false; setDescriptionFile(file); - + return true; } - private boolean initializeLoadedDescription() - { + private boolean initializeLoadedDescription() { setDescriptionURI(DEFAULT_DESCRIPTION_URI); setLeaseTime(DEFAULT_LEASE_TIME); setHTTPPort(HTTP_DEFAULT_PORT); @@ -594,66 +687,61 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL // Thanks for Oliver Newell (03/23/04) if (hasUDN() == false) updateUDN(); - + return true; } - - //////////////////////////////////////////////// - // isDeviceNode - //////////////////////////////////////////////// - public static boolean isDeviceNode(Node node) - { + // ////////////////////////////////////////////// + // isDeviceNode + // ////////////////////////////////////////////// + + public static boolean isDeviceNode(Node node) { return Device.ELEM_NAME.equals(node.getName()); } - - //////////////////////////////////////////////// - // Root Device - //////////////////////////////////////////////// - public boolean isRootDevice(){ - return getRootNode().getNode("device").getNodeValue(UDN).equals(getUDN()); + // ////////////////////////////////////////////// + // Root Device + // ////////////////////////////////////////////// + + public boolean isRootDevice() { + return getRootNode().getNode("device").getNodeValue(UDN) + .equals(getUDN()); } - - //////////////////////////////////////////////// - // Root Device - //////////////////////////////////////////////// - public void setSSDPPacket(SSDPPacket packet) - { + // ////////////////////////////////////////////// + // Root Device + // ////////////////////////////////////////////// + + public void setSSDPPacket(SSDPPacket packet) { getDeviceData().setSSDPPacket(packet); } - public SSDPPacket getSSDPPacket() - { + public SSDPPacket getSSDPPacket() { if (isRootDevice() == false) return null; return getDeviceData().getSSDPPacket(); } - - //////////////////////////////////////////////// - // Location - //////////////////////////////////////////////// - public void setLocation(String value) - { + // ////////////////////////////////////////////// + // Location + // ////////////////////////////////////////////// + + public void setLocation(String value) { getDeviceData().setLocation(value); } - public String getLocation() - { + public String getLocation() { SSDPPacket packet = getSSDPPacket(); if (packet != null) return packet.getLocation(); return getDeviceData().getLocation(); } - //////////////////////////////////////////////// - // LeaseTime - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // LeaseTime + // ////////////////////////////////////////////// - public void setLeaseTime(int value) - { + public void setLeaseTime(int value) { getDeviceData().setLeaseTime(value); Advertiser adv = getAdvertiser(); if (adv != null) { @@ -662,48 +750,44 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } } - public int getLeaseTime() - { + public int getLeaseTime() { SSDPPacket packet = getSSDPPacket(); if (packet != null) - return packet.getLeaseTime(); + return packet.getLeaseTime(); return getDeviceData().getLeaseTime(); } - //////////////////////////////////////////////// - // TimeStamp - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // TimeStamp + // ////////////////////////////////////////////// - public long getTimeStamp() - { + public long getTimeStamp() { SSDPPacket packet = getSSDPPacket(); if (packet != null) - return packet.getTimeStamp(); + return packet.getTimeStamp(); return 0; } - public long getElapsedTime() - { + public long getElapsedTime() { return (System.currentTimeMillis() - getTimeStamp()) / 1000; } - public boolean isExpired() - { + public boolean isExpired() { long elipsedTime = getElapsedTime(); - long leaseTime = getLeaseTime() + UPnP.DEFAULT_EXPIRED_DEVICE_EXTRA_TIME; + long leaseTime = getLeaseTime() + + UPnP.DEFAULT_EXPIRED_DEVICE_EXTRA_TIME; if (leaseTime < elipsedTime) return true; return false; } - - //////////////////////////////////////////////// - // URL Base - //////////////////////////////////////////////// + + // ////////////////////////////////////////////// + // URL Base + // ////////////////////////////////////////////// private final static String URLBASE_NAME = "URLBase"; - - private void setURLBase(String value) - { + + private void setURLBase(String value) { if (isRootDevice() == true) { Node node = getRootNode().getNode(URLBASE_NAME); if (node != null) { @@ -719,249 +803,254 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } } - private void updateURLBase(String host) - { + private void updateURLBase(String host) { String urlBase = HostInterface.getHostURL(host, getHTTPPort(), ""); setURLBase(urlBase); } - - public String getURLBase() - { + + public String getURLBase() { if (isRootDevice() == true) return getRootNode().getNodeValue(URLBASE_NAME); return ""; } - //////////////////////////////////////////////// - // deviceType - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // deviceType + // ////////////////////////////////////////////// private final static String DEVICE_TYPE = "deviceType"; - - public void setDeviceType(String value) - { + + public void setDeviceType(String value) { getDeviceNode().setNode(DEVICE_TYPE, value); } - public String getDeviceType() - { + public String getDeviceType() { return getDeviceNode().getNodeValue(DEVICE_TYPE); } - public boolean isDeviceType(String value) - { + public boolean isDeviceType(String value) { if (value == null) return false; return value.equals(getDeviceType()); } - //////////////////////////////////////////////// - // friendlyName - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // friendlyName + // ////////////////////////////////////////////// private final static String FRIENDLY_NAME = "friendlyName"; - - public void setFriendlyName(String value) - { + + public void setFriendlyName(String value) { getDeviceNode().setNode(FRIENDLY_NAME, value); } - public String getFriendlyName() - { + public String getFriendlyName() { return getDeviceNode().getNodeValue(FRIENDLY_NAME); } - //////////////////////////////////////////////// - // manufacture - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // manufacture + // ////////////////////////////////////////////// private final static String MANUFACTURE = "manufacturer"; - - public void setManufacture(String value) - { + + public void setManufacture(String value) { getDeviceNode().setNode(MANUFACTURE, value); } - public String getManufacture() - { + public String getManufacture() { return getDeviceNode().getNodeValue(MANUFACTURE); } - //////////////////////////////////////////////// - // manufactureURL - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // manufactureURL + // ////////////////////////////////////////////// private final static String MANUFACTURE_URL = "manufacturerURL"; - - public void setManufactureURL(String value) - { + + public void setManufactureURL(String value) { getDeviceNode().setNode(MANUFACTURE_URL, value); } - public String getManufactureURL() - { + public String getManufactureURL() { return getDeviceNode().getNodeValue(MANUFACTURE_URL); } - //////////////////////////////////////////////// - // modelDescription - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // modelDescription + // ////////////////////////////////////////////// private final static String MODEL_DESCRIPTION = "modelDescription"; - - public void setModelDescription(String value) - { + + public void setModelDescription(String value) { getDeviceNode().setNode(MODEL_DESCRIPTION, value); } - public String getModelDescription() - { + public String getModelDescription() { return getDeviceNode().getNodeValue(MODEL_DESCRIPTION); } - //////////////////////////////////////////////// - // modelName - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // modelName + // ////////////////////////////////////////////// private final static String MODEL_NAME = "modelName"; - - public void setModelName(String value) - { + + public void setModelName(String value) { getDeviceNode().setNode(MODEL_NAME, value); } - public String getModelName() - { + public String getModelName() { return getDeviceNode().getNodeValue(MODEL_NAME); } - //////////////////////////////////////////////// - // modelNumber - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // modelNumber + // ////////////////////////////////////////////// private final static String MODEL_NUMBER = "modelNumber"; - - public void setModelNumber(String value) - { + + public void setModelNumber(String value) { getDeviceNode().setNode(MODEL_NUMBER, value); } - public String getModelNumber() - { + public String getModelNumber() { return getDeviceNode().getNodeValue(MODEL_NUMBER); } - //////////////////////////////////////////////// - // modelURL - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // modelURL + // ////////////////////////////////////////////// private final static String MODEL_URL = "modelURL"; - - public void setModelURL(String value) - { + + public void setModelURL(String value) { getDeviceNode().setNode(MODEL_URL, value); } - public String getModelURL() - { + public String getModelURL() { return getDeviceNode().getNodeValue(MODEL_URL); } - //////////////////////////////////////////////// - // serialNumber - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // serialNumber + // ////////////////////////////////////////////// private final static String SERIAL_NUMBER = "serialNumber"; - - public void setSerialNumber(String value) - { + + public void setSerialNumber(String value) { getDeviceNode().setNode(SERIAL_NUMBER, value); } - public String getSerialNumber() - { + public String getSerialNumber() { return getDeviceNode().getNodeValue(SERIAL_NUMBER); } - //////////////////////////////////////////////// - // UDN - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // UDN + // ////////////////////////////////////////////// private final static String UDN = "UDN"; - - public void setUDN(String value) - { + + public void setUDN(String value) { getDeviceNode().setNode(UDN, value); } - public String getUDN() - { + public String getUDN() { return getDeviceNode().getNodeValue(UDN); } - public boolean hasUDN() - { + public boolean hasUDN() { String udn = getUDN(); if (udn == null || udn.length() <= 0) return false; return true; } - - //////////////////////////////////////////////// - // UPC - //////////////////////////////////////////////// + + // ////////////////////////////////////////////// + // UPC + // ////////////////////////////////////////////// private final static String UPC = "UPC"; - - public void setUPC(String value) - { + + public void setUPC(String value) { getDeviceNode().setNode(UPC, value); } - public String getUPC() - { + public String getUPC() { return getDeviceNode().getNodeValue(UPC); } - //////////////////////////////////////////////// - // presentationURL - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // presentationURL + // ////////////////////////////////////////////// private final static String presentationURL = "presentationURL"; - - public void setPresentationURL(String value) - { + private PresentationListener presentationListener; + + public void setPresentationURL(String value) { getDeviceNode().setNode(presentationURL, value); } - public String getPresentationURL() - { + public String getPresentationURL() { return getDeviceNode().getNodeValue(presentationURL); } - //////////////////////////////////////////////// - // deviceList - //////////////////////////////////////////////// + public boolean removePresentationURL() { + return getDeviceNode().removeNode(presentationURL); + } + + private boolean isPresentationRequest(HTTPRequest httpReq) { + if (!httpReq.isGetRequest()) + return false; + String urlPath = httpReq.getURI(); + if (urlPath == null) + return false; + String presentationURL = getPresentationURL(); + if (presentationURL == null) + return false; + return urlPath.startsWith(presentationURL); + } + + public void setPresentationListener(PresentationListener listener) { + this.presentationListener = listener; - public DeviceList getDeviceList() - { + if (listener != null) { + setPresentationURL(DEFAULT_PRESENTATION_URI); + } else { + removePresentationURL(); + } + } + + public boolean hasPresentationListener() { + return (this.presentationListener != null) ? true : false; + } + + public PresentationListener getPresentationListener() { + return this.presentationListener; + } + + // ////////////////////////////////////////////// + // deviceList + // ////////////////////////////////////////////// + + public DeviceList getDeviceList() { DeviceList devList = new DeviceList(); Node devListNode = getDeviceNode().getNode(DeviceList.ELEM_NAME); if (devListNode == null) return devList; int nNode = devListNode.getNNodes(); - for (int n=0; n<nNode; n++) { + for (int n = 0; n < nNode; n++) { Node node = devListNode.getNode(n); if (Device.isDeviceNode(node) == false) continue; Device dev = new Device(node); devList.add(dev); - } + } return devList; } - public boolean isDevice(String name) - { + public boolean isDevice(String name) { if (name == null) return false; if (name.endsWith(getUDN()) == true) @@ -972,12 +1061,11 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return true; return false; } - - public Device getDevice(String name) - { + + public Device getDevice(String name) { DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); if (dev.isDevice(name) == true) return dev; @@ -987,12 +1075,11 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } return null; } - - public Device getDeviceByDescriptionURI(String uri) - { + + public Device getDeviceByDescriptionURI(String uri) { DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); if (dev.isDescriptionURI(uri) == true) return dev; @@ -1002,151 +1089,144 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } return null; } - - //////////////////////////////////////////////// - // serviceList - //////////////////////////////////////////////// - public ServiceList getServiceList() - { + // ////////////////////////////////////////////// + // serviceList + // ////////////////////////////////////////////// + + public ServiceList getServiceList() { ServiceList serviceList = new ServiceList(); Node serviceListNode = getDeviceNode().getNode(ServiceList.ELEM_NAME); if (serviceListNode == null) return serviceList; int nNode = serviceListNode.getNNodes(); - for (int n=0; n<nNode; n++) { + for (int n = 0; n < nNode; n++) { Node node = serviceListNode.getNode(n); if (Service.isServiceNode(node) == false) continue; Service service = new Service(node); serviceList.add(service); - } + } return serviceList; } - public Service getService(String name) - { + public Service getService(String name) { ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); if (service.isService(name) == true) return service; } - + DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); Service service = dev.getService(name); if (service != null) return service; } - + return null; } - public Service getServiceBySCPDURL(String searchUrl) - { + public Service getServiceBySCPDURL(String searchUrl) { ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); if (service.isSCPDURL(searchUrl) == true) return service; } - + DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); Service service = dev.getServiceBySCPDURL(searchUrl); if (service != null) return service; } - + return null; } - public Service getServiceByControlURL(String searchUrl) - { + public Service getServiceByControlURL(String searchUrl) { ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); if (service.isControlURL(searchUrl) == true) return service; } - + DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); Service service = dev.getServiceByControlURL(searchUrl); if (service != null) return service; } - + return null; } - public Service getServiceByEventSubURL(String searchUrl) - { + public Service getServiceByEventSubURL(String searchUrl) { ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); if (service.isEventSubURL(searchUrl) == true) return service; } - + DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); Service service = dev.getServiceByEventSubURL(searchUrl); if (service != null) return service; } - + return null; } - public Service getSubscriberService(String uuid) - { + public Service getSubscriberService(String uuid) { ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); String sid = service.getSID(); if (uuid.equals(sid) == true) return service; } - + DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); Service service = dev.getSubscriberService(uuid); if (service != null) return service; } - + return null; } - //////////////////////////////////////////////// - // StateVariable - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // StateVariable + // ////////////////////////////////////////////// - public StateVariable getStateVariable(String serviceType, String name) - { + public StateVariable getStateVariable(String serviceType, String name) { if (serviceType == null && name == null) return null; - + ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); // Thanks for Theo Beisch (11/09/04) if (serviceType != null) { @@ -1157,38 +1237,36 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL if (stateVar != null) return stateVar; } - + DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); StateVariable stateVar = dev.getStateVariable(serviceType, name); if (stateVar != null) return stateVar; } - + return null; } - public StateVariable getStateVariable(String name) - { + public StateVariable getStateVariable(String name) { return getStateVariable(null, name); } - - //////////////////////////////////////////////// - // Action - //////////////////////////////////////////////// - public Action getAction(String name) - { + // ////////////////////////////////////////////// + // Action + // ////////////////////////////////////////////// + + public Action getAction(String name) { ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); ActionList actionList = service.getActionList(); int actionCnt = actionList.size(); - for (int i=0; i<actionCnt; i++) { - Action action = (Action)actionList.getAction(i); + for (int i = 0; i < actionCnt; i++) { + Action action = (Action) actionList.getAction(i); String actionName = action.getName(); if (actionName == null) continue; @@ -1196,107 +1274,154 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return action; } } - + DeviceList devList = getDeviceList(); int devCnt = devList.size(); - for (int n=0; n<devCnt; n++) { + for (int n = 0; n < devCnt; n++) { Device dev = devList.getDevice(n); Action action = dev.getAction(name); if (action != null) return action; } + + return null; + } + + // ////////////////////////////////////////////// + // iconList + // ////////////////////////////////////////////// + + private HashMap<String, byte[]> iconBytesMap = new HashMap<String, byte[]>(); + + public boolean isIconBytesURI(String uri) { + byte iconBytes[] = iconBytesMap.get(uri); + if (iconBytes == null) + return false; + return true; + } + + public Icon getIconByURI(String uri) { + IconList iconList = getIconList(); + if (iconList.size() <= 0) + return null; + + int nIcon = iconList.size(); + for (int n = 0; n < nIcon; n++) { + Icon icon = iconList.getIcon(n); + if (icon.isURL(uri)) + return icon; + } return null; } - //////////////////////////////////////////////// - // iconList - //////////////////////////////////////////////// + public boolean addIcon(Icon icon) { + Node deviceNode = getDeviceNode(); + if (deviceNode == null) + return false; + + Node iconListNode = deviceNode.getNode(IconList.ELEM_NAME); + if (iconListNode == null) { + iconListNode = new Node(IconList.ELEM_NAME); + deviceNode.addNode(iconListNode); + } + + Node iconNode = new Node(Icon.ELEM_NAME); + if (icon.getIconNode() != null) { + iconNode.set(icon.getIconNode()); + } + iconListNode.addNode(iconNode); + + if (icon.hasURL() && icon.hasBytes()) { + iconBytesMap.put(icon.getURL(), icon.getBytes()); + } + + return true; + } - public IconList getIconList() - { + public IconList getIconList() { IconList iconList = new IconList(); Node iconListNode = getDeviceNode().getNode(IconList.ELEM_NAME); if (iconListNode == null) return iconList; int nNode = iconListNode.getNNodes(); - for (int n=0; n<nNode; n++) { + for (int n = 0; n < nNode; n++) { Node node = iconListNode.getNode(n); if (Icon.isIconNode(node) == false) continue; Icon icon = new Icon(node); + if (icon.hasURL()) { + String iconURL = icon.getURL(); + byte iconBytes[] = iconBytesMap.get(iconURL); + if (iconBytes != null) { + icon.setBytes(iconBytes); + } + } iconList.add(icon); - } + } return iconList; } - - public Icon getIcon(int n) - { + + public Icon getIcon(int n) { IconList iconList = getIconList(); - if (n < 0 && (iconList.size()-1) < n) + if (n < 0 && (iconList.size() - 1) < n) return null; return iconList.getIcon(n); } - public Icon getSmallestIcon() - { - Icon smallestIcon = null; + public Icon getSmallestIcon() { + Icon smallestIcon = null; IconList iconList = getIconList(); int iconCount = iconList.size(); - for (int n=0; n < iconCount; n++) { + for (int n = 0; n < iconCount; n++) { Icon icon = iconList.getIcon(n); if (null == smallestIcon) { smallestIcon = icon; continue; } if (icon.getWidth() < smallestIcon.getWidth()) - smallestIcon = icon; + smallestIcon = icon; } - + return smallestIcon; } - - //////////////////////////////////////////////// - // Notify - //////////////////////////////////////////////// - public String getLocationURL(String host) - { - return HostInterface.getHostURL(host, getHTTPPort(), getDescriptionURI()); + // ////////////////////////////////////////////// + // Notify + // ////////////////////////////////////////////// + + public String getLocationURL(String host) { + return HostInterface.getHostURL(host, getHTTPPort(), + getDescriptionURI()); } - private String getNotifyDeviceNT() - { + private String getNotifyDeviceNT() { if (isRootDevice() == false) - return getUDN(); + return getUDN(); return UPNP_ROOTDEVICE; } - private String getNotifyDeviceUSN() - { + private String getNotifyDeviceUSN() { if (isRootDevice() == false) - return getUDN(); + return getUDN(); return getUDN() + "::" + UPNP_ROOTDEVICE; } - private String getNotifyDeviceTypeNT() - { + private String getNotifyDeviceTypeNT() { return getDeviceType(); } - private String getNotifyDeviceTypeUSN() - { + private String getNotifyDeviceTypeUSN() { return getUDN() + "::" + getDeviceType(); } - - public final static void notifyWait() - { + + public final static void notifyWait() { TimerUtil.waitRandom(DEFAULT_DISCOVERY_WAIT_TIME); } - public void announce(String bindAddr) - { + + public void announce(String bindAddr) { String devLocation = getLocationURL(bindAddr); - + SSDPNotifySocket ssdpSock = new SSDPNotifySocket(bindAddr); SSDPNotifyRequest ssdpReq = new SSDPNotifyRequest(); @@ -1304,90 +1429,90 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL ssdpReq.setLeaseTime(getLeaseTime()); ssdpReq.setLocation(devLocation); ssdpReq.setNTS(NTS.ALIVE); - - // uuid:device-UUID(::upnp:rootdevice)* + ssdpReq.setBootId(getBootId()); + + // uuid:device-UUID(::upnp:rootdevice)* if (isRootDevice() == true) { - String devNT = getNotifyDeviceNT(); + String devNT = getNotifyDeviceNT(); String devUSN = getNotifyDeviceUSN(); ssdpReq.setNT(devNT); ssdpReq.setUSN(devUSN); ssdpSock.post(ssdpReq); - - String devUDN = getUDN(); - ssdpReq.setNT(devUDN); - ssdpReq.setUSN(devUDN); - ssdpSock.post(ssdpReq); + + String devUDN = getUDN(); + ssdpReq.setNT(devUDN); + ssdpReq.setUSN(devUDN); + ssdpSock.post(ssdpReq); } - - // uuid:device-UUID::urn:schemas-upnp-org:device:deviceType:v - String devNT = getNotifyDeviceTypeNT(); + + // uuid:device-UUID::urn:schemas-upnp-org:device:deviceType:v + String devNT = getNotifyDeviceTypeNT(); String devUSN = getNotifyDeviceTypeUSN(); ssdpReq.setNT(devNT); ssdpReq.setUSN(devUSN); ssdpSock.post(ssdpReq); - + // Thanks for Mikael Hakman (04/25/05) ssdpSock.close(); - + ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); service.announce(bindAddr); } DeviceList childDeviceList = getDeviceList(); int childDeviceCnt = childDeviceList.size(); - for (int n=0; n<childDeviceCnt; n++) { + for (int n = 0; n < childDeviceCnt; n++) { Device childDevice = childDeviceList.getDevice(n); childDevice.announce(bindAddr); } } - public void announce(){ + public void announce() { notifyWait(); InetAddress[] binds = getDeviceData().getHTTPBindAddress(); String[] bindAddresses; - if(binds!=null){ + if (binds != null) { bindAddresses = new String[binds.length]; for (int i = 0; i < binds.length; i++) { bindAddresses[i] = binds[i].getHostAddress(); } - }else{ + } else { int nHostAddrs = HostInterface.getNHostAddresses(); - bindAddresses = new String[nHostAddrs]; - for (int n=0; n<nHostAddrs; n++) { + bindAddresses = new String[nHostAddrs]; + for (int n = 0; n < nHostAddrs; n++) { bindAddresses[n] = HostInterface.getHostAddress(n); } - } + } for (int j = 0; j < bindAddresses.length; j++) { - if(bindAddresses[j] == null || bindAddresses[j].length() == 0) + if (bindAddresses[j] == null || bindAddresses[j].length() == 0) continue; int ssdpCount = getSSDPAnnounceCount(); - for (int i=0; i<ssdpCount; i++) + for (int i = 0; i < ssdpCount; i++) announce(bindAddresses[j]); - + } } - - public void byebye(String bindAddr) - { + + public void byebye(String bindAddr) { SSDPNotifySocket ssdpSock = new SSDPNotifySocket(bindAddr); - + SSDPNotifyRequest ssdpReq = new SSDPNotifyRequest(); ssdpReq.setNTS(NTS.BYEBYE); - - // uuid:device-UUID(::upnp:rootdevice)* + + // uuid:device-UUID(::upnp:rootdevice)* if (isRootDevice() == true) { - String devNT = getNotifyDeviceNT(); + String devNT = getNotifyDeviceNT(); String devUSN = getNotifyDeviceUSN(); ssdpReq.setNT(devNT); ssdpReq.setUSN(devUSN); ssdpSock.post(ssdpReq); } - - // uuid:device-UUID::urn:schemas-upnp-org:device:deviceType:v - String devNT = getNotifyDeviceTypeNT(); + + // uuid:device-UUID::urn:schemas-upnp-org:device:deviceType:v + String devNT = getNotifyDeviceTypeNT(); String devUSN = getNotifyDeviceTypeUSN(); ssdpReq.setNT(devNT); ssdpReq.setUSN(devUSN); @@ -1395,203 +1520,203 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL // Thanks for Mikael Hakman (04/25/05) ssdpSock.close(); - + ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); service.byebye(bindAddr); } DeviceList childDeviceList = getDeviceList(); int childDeviceCnt = childDeviceList.size(); - for (int n=0; n<childDeviceCnt; n++) { + for (int n = 0; n < childDeviceCnt; n++) { Device childDevice = childDeviceList.getDevice(n); childDevice.byebye(bindAddr); } } - public void byebye(){ + public void byebye() { InetAddress[] binds = getDeviceData().getHTTPBindAddress(); String[] bindAddresses; - if(binds!=null){ + if (binds != null) { bindAddresses = new String[binds.length]; for (int i = 0; i < binds.length; i++) { bindAddresses[i] = binds[i].getHostAddress(); } - }else{ + } else { int nHostAddrs = HostInterface.getNHostAddresses(); - bindAddresses = new String[nHostAddrs]; - for (int n=0; n<nHostAddrs; n++) { + bindAddresses = new String[nHostAddrs]; + for (int n = 0; n < nHostAddrs; n++) { bindAddresses[n] = HostInterface.getHostAddress(n); } - } - - for (int j = 0; j < bindAddresses.length; j++) { + } + + for (int j = 0; j < bindAddresses.length; j++) { if (bindAddresses[j] == null || bindAddresses[j].length() <= 0) continue; int ssdpCount = getSSDPAnnounceCount(); - for (int i=0; i<ssdpCount; i++) + for (int i = 0; i < ssdpCount; i++) byebye(bindAddresses[j]); - } + } } - //////////////////////////////////////////////// - // Search - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // Search + // ////////////////////////////////////////////// + + private static Calendar cal = Calendar.getInstance(); - private static Calendar cal = Calendar.getInstance(); - public boolean postSearchResponse(SSDPPacket ssdpPacket, String st, String usn) - { + public boolean postSearchResponse(SSDPPacket ssdpPacket, String st, + String usn) { String localAddr = ssdpPacket.getLocalAddress(); Device rootDev = getRootDevice(); String rootDevLocation = rootDev.getLocationURL(localAddr); - + SSDPSearchResponse ssdpRes = new SSDPSearchResponse(); ssdpRes.setLeaseTime(getLeaseTime()); ssdpRes.setDate(cal); ssdpRes.setST(st); ssdpRes.setUSN(usn); ssdpRes.setLocation(rootDevLocation); + ssdpRes.setBootId(getBootId()); // Thanks for Brent Hills (10/20/04) ssdpRes.setMYNAME(getFriendlyName()); int mx = ssdpPacket.getMX(); TimerUtil.waitRandom(mx * 1000); - + String remoteAddr = ssdpPacket.getRemoteAddress(); int remotePort = ssdpPacket.getRemotePort(); SSDPSearchResponseSocket ssdpResSock = new SSDPSearchResponseSocket(); if (Debug.isOn() == true) ssdpRes.print(); int ssdpCount = getSSDPAnnounceCount(); - for (int i=0; i<ssdpCount; i++) + for (int i = 0; i < ssdpCount; i++) ssdpResSock.post(remoteAddr, remotePort, ssdpRes); - + return true; } - - public void deviceSearchResponse(SSDPPacket ssdpPacket) - { + + public void deviceSearchResponse(SSDPPacket ssdpPacket) { String ssdpST = ssdpPacket.getST(); if (ssdpST == null) return; boolean isRootDevice = isRootDevice(); - + String devUSN = getUDN(); if (isRootDevice == true) devUSN += "::" + USN.ROOTDEVICE; - + if (ST.isAllDevice(ssdpST) == true) { - String devNT = getNotifyDeviceNT(); + String devNT = getNotifyDeviceNT(); int repeatCnt = (isRootDevice == true) ? 3 : 2; - for (int n=0; n<repeatCnt; n++) + for (int n = 0; n < repeatCnt; n++) postSearchResponse(ssdpPacket, devNT, devUSN); - } - else if (ST.isRootDevice(ssdpST) == true) { + } else if (ST.isRootDevice(ssdpST) == true) { if (isRootDevice == true) postSearchResponse(ssdpPacket, ST.ROOT_DEVICE, devUSN); - } - else if (ST.isUUIDDevice(ssdpST) == true) { + } else if (ST.isUUIDDevice(ssdpST) == true) { String devUDN = getUDN(); if (ssdpST.equals(devUDN) == true) postSearchResponse(ssdpPacket, devUDN, devUSN); - } - else if (ST.isURNDevice(ssdpST) == true) { - String devType= getDeviceType(); + } else if (ST.isURNDevice(ssdpST) == true) { + String devType = getDeviceType(); if (ssdpST.equals(devType) == true) { // Thanks for Mikael Hakman (04/25/05) devUSN = getUDN() + "::" + devType; postSearchResponse(ssdpPacket, devType, devUSN); } } - + ServiceList serviceList = getServiceList(); int serviceCnt = serviceList.size(); - for (int n=0; n<serviceCnt; n++) { + for (int n = 0; n < serviceCnt; n++) { Service service = serviceList.getService(n); service.serviceSearchResponse(ssdpPacket); } - + DeviceList childDeviceList = getDeviceList(); int childDeviceCnt = childDeviceList.size(); - for (int n=0; n<childDeviceCnt; n++) { + for (int n = 0; n < childDeviceCnt; n++) { Device childDevice = childDeviceList.getDevice(n); childDevice.deviceSearchResponse(ssdpPacket); } } - - public void deviceSearchReceived(SSDPPacket ssdpPacket) - { + + public void deviceSearchReceived(SSDPPacket ssdpPacket) { deviceSearchResponse(ssdpPacket); } - - //////////////////////////////////////////////// - // HTTP Server - //////////////////////////////////////////////// - public void setHTTPPort(int port) - { + // ////////////////////////////////////////////// + // HTTP Server + // ////////////////////////////////////////////// + + public void setHTTPPort(int port) { getDeviceData().setHTTPPort(port); } - - public int getHTTPPort() - { + + public int getHTTPPort() { return getDeviceData().getHTTPPort(); } - public void setHTTPBindAddress(InetAddress[] inets){ + public void setHTTPBindAddress(InetAddress[] inets) { this.getDeviceData().setHTTPBindAddress(inets); } - - public InetAddress[] getHTTPBindAddress(){ + + public InetAddress[] getHTTPBindAddress() { return this.getDeviceData().getHTTPBindAddress(); - } - + } + /** * * @return * @since 1.8 */ - public String getSSDPIPv4MulticastAddress(){ + public String getSSDPIPv4MulticastAddress() { return this.getDeviceData().getMulticastIPv4Address(); - } - + } + /** * * @param ip * @since 1.8 */ - public void getSSDPIPv4MulticastAddress(String ip){ + public void getSSDPIPv4MulticastAddress(String ip) { this.getDeviceData().setMulticastIPv4Address(ip); - } - + } + /** * * @return * @since 1.8 */ - public String getSSDPIPv6MulticastAddress(){ + public String getSSDPIPv6MulticastAddress() { return this.getDeviceData().getMulticastIPv6Address(); - } - + } + /** * * @param ip * @since 1.8 */ - public void getSSDPIPv6MulticastAddress(String ip){ + public void getSSDPIPv6MulticastAddress(String ip) { this.getDeviceData().setMulticastIPv6Address(ip); - } - - public void httpRequestRecieved(HTTPRequest httpReq) - { + } + + public void httpRequestRecieved(HTTPRequest httpReq) { if (Debug.isOn() == true) httpReq.print(); - + + if (hasPresentationListener() && isPresentationRequest(httpReq)) { + PresentationListener listener = getPresentationListener(); + listener.httpRequestRecieved(httpReq); + return; + } + if (httpReq.isGetRequest() == true || httpReq.isHeadRequest() == true) { httpGetRequestRecieved(httpReq); return; @@ -1601,7 +1726,8 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return; } - if (httpReq.isSubscribeRequest() == true || httpReq.isUnsubscribeRequest() == true) { + if (httpReq.isSubscribeRequest() == true + || httpReq.isUnsubscribeRequest() == true) { SubscriptionRequest subReq = new SubscriptionRequest(httpReq); deviceEventSubscriptionRecieved(subReq); return; @@ -1610,8 +1736,7 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL httpReq.returnBadRequest(); } - private synchronized byte[] getDescriptionData(String host) - { + private synchronized byte[] getDescriptionData(String host) { if (isNMPRMode() == false) updateURLBase(host); Node rootNode = getRootNode(); @@ -1624,73 +1749,87 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL desc += rootNode.toString(); return desc.getBytes(); } - - private void httpGetRequestRecieved(HTTPRequest httpReq) - { + + private void httpGetRequestRecieved(HTTPRequest httpReq) { String uri = httpReq.getURI(); Debug.message("httpGetRequestRecieved = " + uri); if (uri == null) { httpReq.returnBadRequest(); return; } - + Device embDev; Service embService; - + byte fileByte[] = new byte[0]; + String contentType = null; + String contentLanguage = null; + if (isDescriptionURI(uri) == true) { String localAddr = httpReq.getLocalAddress(); if ((localAddr == null) || (localAddr.length() <= 0)) localAddr = HostInterface.getInterface(); + contentType = XML.DEFAULT_CONTENT_TYPE; + contentLanguage = XML.DEFAULT_CONTENT_LANGUAGE; fileByte = getDescriptionData(localAddr); - } - else if ((embDev = getDeviceByDescriptionURI(uri)) != null) { + } else if ((embDev = getDeviceByDescriptionURI(uri)) != null) { String localAddr = httpReq.getLocalAddress(); + contentType = XML.DEFAULT_CONTENT_TYPE; + contentLanguage = XML.DEFAULT_CONTENT_LANGUAGE; fileByte = embDev.getDescriptionData(localAddr); - } - else if ((embService = getServiceBySCPDURL(uri)) != null) { + } else if ((embService = getServiceBySCPDURL(uri)) != null) { + contentType = XML.DEFAULT_CONTENT_TYPE; + contentLanguage = XML.DEFAULT_CONTENT_LANGUAGE; fileByte = embService.getSCPDData(); - } - else { + } else if (isIconBytesURI(uri) == true) { + Icon devIcon = getIconByURI(uri); + if (devIcon != null) { + contentType = devIcon.getMimeType(); + fileByte = devIcon.getBytes(); + } + } else { httpReq.returnBadRequest(); return; } - + HTTPResponse httpRes = new HTTPResponse(); - if (FileUtil.isXMLFileName(uri) == true) - httpRes.setContentType(XML.CONTENT_TYPE); httpRes.setStatusCode(HTTPStatus.OK); + if (contentType != null) { + httpRes.setContentType(contentType); + } + if (contentLanguage != null) { + // FIXME Check ACCEPT-LANGUAGE header in client request, and set a + // suitable code. + httpRes.setContentLanguage(contentLanguage); + } httpRes.setContent(fileByte); httpReq.post(httpRes); } - private void httpPostRequestRecieved(HTTPRequest httpReq) - { + private void httpPostRequestRecieved(HTTPRequest httpReq) { if (httpReq.isSOAPAction() == true) { - //SOAPRequest soapReq = new SOAPRequest(httpReq); + // SOAPRequest soapReq = new SOAPRequest(httpReq); soapActionRecieved(httpReq); return; } httpReq.returnBadRequest(); } - //////////////////////////////////////////////// - // SOAP - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // SOAP + // ////////////////////////////////////////////// - private void soapBadActionRecieved(HTTPRequest soapReq) - { + private void soapBadActionRecieved(HTTPRequest soapReq) { SOAPResponse soapRes = new SOAPResponse(); soapRes.setStatusCode(HTTPStatus.BAD_REQUEST); soapReq.post(soapRes); } - private void soapActionRecieved(HTTPRequest soapReq) - { + private void soapActionRecieved(HTTPRequest soapReq) { String uri = soapReq.getURI(); Service ctlService = getServiceByControlURL(uri); - if (ctlService != null) { + if (ctlService != null) { ActionRequest crlReq = new ActionRequest(soapReq); deviceControlRequestRecieved(crlReq, ctlService); return; @@ -1698,37 +1837,35 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL soapBadActionRecieved(soapReq); } - //////////////////////////////////////////////// - // controlAction - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // controlAction + // ////////////////////////////////////////////// - private void deviceControlRequestRecieved(ControlRequest ctlReq, Service service) - { + private void deviceControlRequestRecieved(ControlRequest ctlReq, + Service service) { if (ctlReq.isQueryControl() == true) deviceQueryControlRecieved(new QueryRequest(ctlReq), service); else deviceActionControlRecieved(new ActionRequest(ctlReq), service); } - private void invalidActionControlRecieved(ControlRequest ctlReq) - { + private void invalidActionControlRecieved(ControlRequest ctlReq) { ControlResponse actRes = new ActionResponse(); actRes.setFaultResponse(UPnPStatus.INVALID_ACTION); ctlReq.post(actRes); } - private void invalidArgumentsControlRecieved(ControlRequest ctlReq) - { - ControlResponse actRes = new ActionResponse(); - actRes.setFaultResponse(UPnPStatus.INVALID_ARGS); - ctlReq.post(actRes); - } + private void invalidArgumentsControlRecieved(ControlRequest ctlReq) { + ControlResponse actRes = new ActionResponse(); + actRes.setFaultResponse(UPnPStatus.INVALID_ARGS); + ctlReq.post(actRes); + } - private void deviceActionControlRecieved(ActionRequest ctlReq, Service service) - { + private void deviceActionControlRecieved(ActionRequest ctlReq, + Service service) { if (Debug.isOn() == true) ctlReq.print(); - + String actionName = ctlReq.getActionName(); Action action = service.getAction(actionName); if (action == null) { @@ -1737,18 +1874,17 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } ArgumentList actionArgList = action.getArgumentList(); ArgumentList reqArgList = ctlReq.getArgumentList(); - try { - actionArgList.setReqArgs(reqArgList); - } catch (IllegalArgumentException ex){ - invalidArgumentsControlRecieved(ctlReq); - return; - } + try { + actionArgList.setReqArgs(reqArgList); + } catch (IllegalArgumentException ex) { + invalidArgumentsControlRecieved(ctlReq); + return; + } if (action.performActionListener(ctlReq) == false) invalidActionControlRecieved(ctlReq); } - private void deviceQueryControlRecieved(QueryRequest ctlReq, Service service) - { + private void deviceQueryControlRecieved(QueryRequest ctlReq, Service service) { if (Debug.isOn() == true) ctlReq.print(); String varName = ctlReq.getVarName(); @@ -1761,19 +1897,18 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL invalidActionControlRecieved(ctlReq); } - //////////////////////////////////////////////// - // eventSubscribe - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // eventSubscribe + // ////////////////////////////////////////////// - private void upnpBadSubscriptionRecieved(SubscriptionRequest subReq, int code) - { + private void upnpBadSubscriptionRecieved(SubscriptionRequest subReq, + int code) { SubscriptionResponse subRes = new SubscriptionResponse(); subRes.setErrorResponse(code); subReq.post(subRes); } - private void deviceEventSubscriptionRecieved(SubscriptionRequest subReq) - { + private void deviceEventSubscriptionRecieved(SubscriptionRequest subReq) { String uri = subReq.getURI(); Service service = getServiceByEventSubURL(uri); if (service == null) { @@ -1796,36 +1931,35 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL deviceEventNewSubscriptionRecieved(service, subReq); return; } - + // SUBSCRIBE (RENEW) if (subReq.hasSID() == true) { deviceEventRenewSubscriptionRecieved(service, subReq); return; } - + upnpBadSubscriptionRecieved(subReq, HTTPStatus.PRECONDITION_FAILED); } - private void deviceEventNewSubscriptionRecieved(Service service, SubscriptionRequest subReq) - { + private void deviceEventNewSubscriptionRecieved(Service service, + SubscriptionRequest subReq) { String callback = subReq.getCallback(); try { new URL(callback); - } - catch (Exception e) { + } catch (Exception e) { upnpBadSubscriptionRecieved(subReq, HTTPStatus.PRECONDITION_FAILED); return; } long timeOut = subReq.getTimeout(); String sid = Subscription.createSID(); - + Subscriber sub = new Subscriber(); sub.setDeliveryURL(callback); sub.setTimeOut(timeOut); sub.setSID(sid); service.addSubscriber(sub); - + SubscriptionResponse subRes = new SubscriptionResponse(); subRes.setStatusCode(HTTPStatus.OK); subRes.setSID(sid); @@ -1836,12 +1970,12 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL if (Debug.isOn() == true) subRes.print(); - + service.notifyAllStateVariables(); } - private void deviceEventRenewSubscriptionRecieved(Service service, SubscriptionRequest subReq) - { + private void deviceEventRenewSubscriptionRecieved(Service service, + SubscriptionRequest subReq) { String sid = subReq.getSID(); Subscriber sub = service.getSubscriber(sid); @@ -1853,19 +1987,19 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL long timeOut = subReq.getTimeout(); sub.setTimeOut(timeOut); sub.renew(); - + SubscriptionResponse subRes = new SubscriptionResponse(); subRes.setStatusCode(HTTPStatus.OK); subRes.setSID(sid); subRes.setTimeout(timeOut); subReq.post(subRes); - + if (Debug.isOn() == true) subRes.print(); - } + } - private void deviceEventUnsubscriptionRecieved(Service service, SubscriptionRequest subReq) - { + private void deviceEventUnsubscriptionRecieved(Service service, + SubscriptionRequest subReq) { String sid = subReq.getSID(); Subscriber sub = service.getSubscriber(sid); @@ -1875,28 +2009,29 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } service.removeSubscriber(sub); - + SubscriptionResponse subRes = new SubscriptionResponse(); subRes.setStatusCode(HTTPStatus.OK); subReq.post(subRes); - + if (Debug.isOn() == true) subRes.print(); - } - - //////////////////////////////////////////////// - // Thread - //////////////////////////////////////////////// - - private HTTPServerList getHTTPServerList() - { + } + + // ////////////////////////////////////////////// + // Thread + // ////////////////////////////////////////////// + + private HTTPServerList getHTTPServerList() { return getDeviceData().getHTTPServerList(); } + /** * - * @param port The port to use for binding the SSDP service + * @param port + * The port to use for binding the SSDP service */ - public void setSSDPPort(int port){ + public void setSSDPPort(int port) { this.getDeviceData().setSSDPPort(port); } @@ -1904,36 +2039,35 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL * * @return The port to use for binding the SSDP service */ - public int getSSDPPort(){ + public int getSSDPPort() { return this.getDeviceData().getSSDPPort(); } - - /** * - * @param inets The IP that will be used for binding the SSDP service. - * Use <code>null</code> to get the default beahvior + * @param inets + * The IP that will be used for binding the SSDP service. Use + * <code>null</code> to get the default beahvior */ - public void setSSDPBindAddress(InetAddress[] inets){ + public void setSSDPBindAddress(InetAddress[] inets) { this.getDeviceData().setSSDPBindAddress(inets); } - - + /** * - * @return inets The IP that will be used for binding the SSDP service. - * null means the default setted by the class UPnP + * @return inets The IP that will be used for binding the SSDP service. null + * means the default setted by the class UPnP */ - public InetAddress[] getSSDPBindAddress(){ + public InetAddress[] getSSDPBindAddress() { return this.getDeviceData().getSSDPBindAddress(); - } - + } + /** * - * @param ip The IPv4 address used for Multicast comunication + * @param ip + * The IPv4 address used for Multicast comunication */ - public void setMulticastIPv4Address(String ip){ + public void setMulticastIPv4Address(String ip) { this.getDeviceData().setMulticastIPv4Address(ip); } @@ -1941,15 +2075,16 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL * * @return The IPv4 address used for Multicast comunication */ - public String getMulticastIPv4Address(){ + public String getMulticastIPv4Address() { return this.getDeviceData().getMulticastIPv4Address(); } - + /** * - * @param ip The IPv address used for Multicast comunication + * @param ip + * The IPv address used for Multicast comunication */ - public void setMulticastIPv6Address(String ip){ + public void setMulticastIPv6Address(String ip) { this.getDeviceData().setMulticastIPv6Address(ip); } @@ -1957,34 +2092,29 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL * * @return The IPv address used for Multicast comunication */ - public String getMulticastIPv6Address(){ + public String getMulticastIPv6Address() { return this.getDeviceData().getMulticastIPv6Address(); } - - private SSDPSearchSocketList getSSDPSearchSocketList() - { + private SSDPSearchSocketList getSSDPSearchSocketList() { return getDeviceData().getSSDPSearchSocketList(); } - private void setAdvertiser(Advertiser adv) - { + private void setAdvertiser(Advertiser adv) { getDeviceData().setAdvertiser(adv); } - - private Advertiser getAdvertiser() - { + + private Advertiser getAdvertiser() { return getDeviceData().getAdvertiser(); } - public boolean start() - { + public boolean start() { stop(true); - - //////////////////////////////////////// + + // ////////////////////////////////////// // HTTP Server - //////////////////////////////////////// - + // ////////////////////////////////////// + int retryCnt = 0; int bindPort = getHTTPPort(); HTTPServerList httpServerList = getHTTPServerList(); @@ -1998,48 +2128,54 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL httpServerList.addRequestListener(this); httpServerList.start(); - //////////////////////////////////////// + // ////////////////////////////////////// // SSDP Seach Socket - //////////////////////////////////////// - + // ////////////////////////////////////// + SSDPSearchSocketList ssdpSearchSockList = getSSDPSearchSocketList(); if (ssdpSearchSockList.open() == false) return false; ssdpSearchSockList.addSearchListener(this); ssdpSearchSockList.start(); - //////////////////////////////////////// + // ////////////////////////////////////// + // BOOTID/CONFIGID.UPNP.ORG + // ////////////////////////////////////// + + updateBootId(); + updateConfigId(); + + // ////////////////////////////////////// // Announce - //////////////////////////////////////// - + // ////////////////////////////////////// + announce(); - - //////////////////////////////////////// + + // ////////////////////////////////////// // Advertiser - //////////////////////////////////////// + // ////////////////////////////////////// Advertiser adv = new Advertiser(this); setAdvertiser(adv); adv.start(); - + return true; } - private boolean stop(boolean doByeBye) - { + private boolean stop(boolean doByeBye) { if (doByeBye == true) byebye(); - + HTTPServerList httpServerList = getHTTPServerList(); httpServerList.stop(); httpServerList.close(); httpServerList.clear(); - + SSDPSearchSocketList ssdpSearchSockList = getSSDPSearchSocketList(); ssdpSearchSockList.stop(); ssdpSearchSockList.close(); ssdpSearchSockList.clear(); - + Advertiser adv = getAdvertiser(); if (adv != null) { adv.stop(); @@ -2048,60 +2184,55 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL return true; } - - public boolean stop() - { + + public boolean stop() { return stop(true); } - public boolean isRunning() - { + public boolean isRunning() { return (getAdvertiser() != null) ? true : false; } - //////////////////////////////////////////////// + // ////////////////////////////////////////////// // Interface Address - //////////////////////////////////////////////// - - public String getInterfaceAddress() - { + // ////////////////////////////////////////////// + + public String getInterfaceAddress() { SSDPPacket ssdpPacket = getSSDPPacket(); if (ssdpPacket == null) return ""; return ssdpPacket.getLocalAddress(); } - //////////////////////////////////////////////// + // ////////////////////////////////////////////// // Acion/QueryListener - //////////////////////////////////////////////// - - public void setActionListener(ActionListener listener) - { + // ////////////////////////////////////////////// + + public void setActionListener(ActionListener listener) { ServiceList serviceList = getServiceList(); int nServices = serviceList.size(); - for (int n=0; n<nServices; n++) { + for (int n = 0; n < nServices; n++) { Service service = serviceList.getService(n); service.setActionListener(listener); } } - public void setQueryListener(QueryListener listener) - { + public void setQueryListener(QueryListener listener) { ServiceList serviceList = getServiceList(); int nServices = serviceList.size(); - for (int n=0; n<nServices; n++) { + for (int n = 0; n < nServices; n++) { Service service = serviceList.getService(n); service.setQueryListener(listener); } } - //////////////////////////////////////////////// + // ////////////////////////////////////////////// // Acion/QueryListener (includeSubDevices) - //////////////////////////////////////////////// + // ////////////////////////////////////////////// // Thanks for Mikael Hakman (04/25/05) - public void setActionListener(ActionListener listener, boolean includeSubDevices) - { + public void setActionListener(ActionListener listener, + boolean includeSubDevices) { setActionListener(listener); if (includeSubDevices == true) { DeviceList devList = getDeviceList(); @@ -2112,10 +2243,10 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } } } - + // Thanks for Mikael Hakman (04/25/05) - public void setQueryListener(QueryListener listener, boolean includeSubDevices) - { + public void setQueryListener(QueryListener listener, + boolean includeSubDevices) { setQueryListener(listener); if (includeSubDevices == true) { DeviceList devList = getDeviceList(); @@ -2127,50 +2258,40 @@ public class Device implements org.cybergarage.http.HTTPRequestListener, SearchL } } - //////////////////////////////////////////////// - // userData - //////////////////////////////////////////////// + // ////////////////////////////////////////////// + // userData + // ////////////////////////////////////////////// - private Object userData = null; - - public void setUserData(Object data) - { + private Object userData = null; + + public void setUserData(Object data) { userData = data; } - public Object getUserData() - { + public Object getUserData() { return userData; } - - //////////////////////////////////////////////// - // output - //////////////////////////////////////////////// - -/* - public void output(PrintWriter ps) - { - ps.println("deviceType = " + getDeviceType()); - ps.println("freindlyName = " + getFriendlyName()); - ps.println("presentationURL = " + getPresentationURL()); - DeviceList devList = getDeviceList(); - ps.println("devList = " + devList.size()); - - ServiceList serviceList = getServiceList(); - ps.println("serviceList = " + serviceList.size()); + // ////////////////////////////////////////////// + // output + // ////////////////////////////////////////////// - IconList iconList = getIconList(); - ps.println("iconList = " + iconList.size()); - } - - public void print() - { - PrintWriter pr = new PrintWriter(System.out); - output(pr); - pr.flush(); - } -*/ + /* + * public void output(PrintWriter ps) { ps.println("deviceType = " + + * getDeviceType()); ps.println("freindlyName = " + getFriendlyName()); + * ps.println("presentationURL = " + getPresentationURL()); + * + * DeviceList devList = getDeviceList(); ps.println("devList = " + + * devList.size()); + * + * ServiceList serviceList = getServiceList(); ps.println("serviceList = " + + * serviceList.size()); + * + * IconList iconList = getIconList(); ps.println("iconList = " + + * iconList.size()); } + * + * public void print() { PrintWriter pr = new PrintWriter(System.out); + * output(pr); pr.flush(); } + */ } - diff --git a/router/java/src/org/cybergarage/upnp/Icon.java b/router/java/src/org/cybergarage/upnp/Icon.java index 0f76c44a38bdfe90b2c7d48eee24ec254e117974..6f71ceeea63ed322c89f55e8f979140ea4700c5f 100644 --- a/router/java/src/org/cybergarage/upnp/Icon.java +++ b/router/java/src/org/cybergarage/upnp/Icon.java @@ -5,84 +5,96 @@ * Copyright (C) Satoshi Konno 2002 * * File: Icon.java -* -* Revision; -* -* 11/28/02 -* - first revision. +* +* Revision; +* +* 11/28/02 +* - first revision. * 04/12/06 * - Added setUserData() and getUserData() to set a user original data object. * ******************************************************************/ - -package org.cybergarage.upnp; - + +package org.cybergarage.upnp; + import org.cybergarage.xml.Node; - -public class Icon -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "icon"; - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private Node iconNode; - - public Node getIconNode() - { - return iconNode; - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Icon(Node node) - { - iconNode = node; - } - - //////////////////////////////////////////////// - // isIconNode - //////////////////////////////////////////////// - - public static boolean isIconNode(Node node) - { - return Icon.ELEM_NAME.equals(node.getName()); - } - - //////////////////////////////////////////////// - // mimeType - //////////////////////////////////////////////// - - private final static String MIME_TYPE = "mimeType"; - - public void setMimeType(String value) - { - getIconNode().setNode(MIME_TYPE, value); - } - - public String getMimeType() - { - return getIconNode().getNodeValue(MIME_TYPE); - } - - //////////////////////////////////////////////// - // width - //////////////////////////////////////////////// - - private final static String WIDTH = "width"; - - public void setWidth(String value) - { - getIconNode().setNode(WIDTH, value); - } - + +public class Icon +{ + //////////////////////////////////////////////// + // Constants + //////////////////////////////////////////////// + + public final static String ELEM_NAME = "icon"; + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private Node iconNode; + + public Node getIconNode() + { + return iconNode; + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Icon(Node node) + { + iconNode = node; + } + + public Icon() { + this(new Node(ELEM_NAME)); + } + + //////////////////////////////////////////////// + // isIconNode + //////////////////////////////////////////////// + + public static boolean isIconNode(Node node) + { + return Icon.ELEM_NAME.equals(node.getName()); + } + + //////////////////////////////////////////////// + // mimeType + //////////////////////////////////////////////// + + private final static String MIME_TYPE = "mimeType"; + + public void setMimeType(String value) + { + getIconNode().setNode(MIME_TYPE, value); + } + + public String getMimeType() + { + return getIconNode().getNodeValue(MIME_TYPE); + } + + public boolean hasMimeType() + { + String iconMimeType = getMimeType(); + if (iconMimeType == null) + return false; + return (0 < iconMimeType.length()) ? true : false; + } + + //////////////////////////////////////////////// + // width + //////////////////////////////////////////////// + + private final static String WIDTH = "width"; + + public void setWidth(String value) + { + getIconNode().setNode(WIDTH, value); + } + public void setWidth(int value) { try { @@ -91,26 +103,26 @@ public class Icon catch (Exception e) {}; } - public int getWidth() + public int getWidth() { - try { + try { return Integer.parseInt(getIconNode().getNodeValue(WIDTH)); } catch (Exception e) {}; - return 0; - } - - //////////////////////////////////////////////// - // height - //////////////////////////////////////////////// - - private final static String HEIGHT = "height"; - - public void setHeight(String value) - { - getIconNode().setNode(HEIGHT, value); - } - + return 0; + } + + //////////////////////////////////////////////// + // height + //////////////////////////////////////////////// + + private final static String HEIGHT = "height"; + + public void setHeight(String value) + { + getIconNode().setNode(HEIGHT, value); + } + public void setHeight(int value) { try { @@ -119,47 +131,77 @@ public class Icon catch (Exception e) {}; } - public int getHeight() - { + public int getHeight() + { try { return Integer.parseInt(getIconNode().getNodeValue(HEIGHT)); } catch (Exception e) {}; return 0; - } - - //////////////////////////////////////////////// - // depth - //////////////////////////////////////////////// - - private final static String DEPTH = "depth"; - - public void setDepth(String value) - { - getIconNode().setNode(DEPTH, value); - } - - public String getDepth() - { - return getIconNode().getNodeValue(DEPTH); - } - - //////////////////////////////////////////////// - // URL - //////////////////////////////////////////////// - - private final static String URL = "url"; - - public void setURL(String value) - { - getIconNode().setNode(URL, value); - } - - public String getURL() - { - return getIconNode().getNodeValue(URL); - } - + } + + //////////////////////////////////////////////// + // depth + //////////////////////////////////////////////// + + private final static String DEPTH = "depth"; + + public void setDepth(String value) + { + getIconNode().setNode(DEPTH, value); + } + + public void setDepth(int value) + { + try { + setDepth(Integer.toString(value)); + } + catch (Exception e) {}; + } + + public int getDepth() + { + try { + return Integer.parseInt(getIconNode().getNodeValue(DEPTH)); + } + catch (Exception e) {}; + return 0; + } + + //////////////////////////////////////////////// + // URL + //////////////////////////////////////////////// + + private final static String URL = "url"; + + public void setURL(String value) + { + getIconNode().setNode(URL, value); + } + + public String getURL() + { + return getIconNode().getNodeValue(URL); + } + + public boolean hasURL() + { + String iconURL = getURL(); + if (iconURL == null) + return false; + return (0 < iconURL.length()) ? true : false; + } + + public boolean isURL(String url) + { + if (url == null) + return false; + String iconURL = getURL(); + if (iconURL == null) + return false; + return iconURL.equals(url); + } + //////////////////////////////////////////////// // userData //////////////////////////////////////////////// @@ -175,4 +217,25 @@ public class Icon { return userData; } + + //////////////////////////////////////////////// + // Bytes + //////////////////////////////////////////////// + + private byte bytes[] = null; + + public void setBytes(byte data[]) + { + bytes = data; + } + + public boolean hasBytes() + { + return (bytes != null) ? true : false; + } + + public byte[]getBytes() + { + return bytes; + } } diff --git a/router/java/src/org/cybergarage/upnp/IconList.java b/router/java/src/org/cybergarage/upnp/IconList.java index a78f810cc9d060f352f1f8b9a13d75301321eef4..e6ef493ee541808e431b2cec43def999a1bb54fb 100644 --- a/router/java/src/org/cybergarage/upnp/IconList.java +++ b/router/java/src/org/cybergarage/upnp/IconList.java @@ -1,45 +1,45 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: IconList.java -* -* Revision; -* -* 12/04/02 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: IconList.java +* +* Revision; +* +* 12/04/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp; + +import java.util.Vector; + +public class IconList extends Vector +{ + //////////////////////////////////////////////// + // 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 -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "iconList"; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public IconList() - { - } - - //////////////////////////////////////////////// - // Methods - //////////////////////////////////////////////// - - public Icon getIcon(int n) - { - return (Icon)get(n); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/RootDescription.java b/router/java/src/org/cybergarage/upnp/RootDescription.java index 19b5ad92632e51efcd18b60c82ae90dd9281f335..02a600f61ddecbdf7193767751d200f7ba32130c 100644 --- a/router/java/src/org/cybergarage/upnp/RootDescription.java +++ b/router/java/src/org/cybergarage/upnp/RootDescription.java @@ -1,19 +1,19 @@ package org.cybergarage.upnp; - -/** - * @author Stefano "Kismet" Lenzi - kismet-sl@users.sourceforge.net <br> - * Copyright (c) 2005 - * - */ -public interface RootDescription { - - public final String ROOT_ELEMENT = "root"; - public final String ROOT_ELEMENT_NAMESPACE = "urn:schemas-upnp-org:device-1-0"; - - - public final String SPECVERSION_ELEMENT = "specVersion"; - public final String MAJOR_ELEMENT = "major"; - public final String MINOR_ELEMENT = "minor"; - public final String SERVICE_LIST_ELEMENT = "serviceList"; -} + +/** + * @author Stefano "Kismet" Lenzi - kismet-sl@users.sourceforge.net <br> + * Copyright (c) 2005 + * + */ +public interface RootDescription { + + public final String ROOT_ELEMENT = "root"; + public final String ROOT_ELEMENT_NAMESPACE = "urn:schemas-upnp-org:device-1-0"; + + + public final String SPECVERSION_ELEMENT = "specVersion"; + public final String MAJOR_ELEMENT = "major"; + public final String MINOR_ELEMENT = "minor"; + public final String SERVICE_LIST_ELEMENT = "serviceList"; +} diff --git a/router/java/src/org/cybergarage/upnp/Service.java b/router/java/src/org/cybergarage/upnp/Service.java index 3f517b0bfe2c034d5f2445776914081981876c7c..6393a376688fd83db44ee5fd1d5a2e2015eb55f8 100644 --- a/router/java/src/org/cybergarage/upnp/Service.java +++ b/router/java/src/org/cybergarage/upnp/Service.java @@ -121,7 +121,7 @@ public class Service //////////////////////////////////////////////// public static final String SCPD_ROOTNODE="scpd"; public static final String SCPD_ROOTNODE_NS="urn:schemas-upnp-org:service-1-0"; - + public static final String SPEC_VERSION="specVersion"; public static final String MAJOR="major"; public static final String MAJOR_VALUE="1"; @@ -142,8 +142,8 @@ public class Service sp.addNode(m); //Node scpd = new Node(SCPD_ROOTNODE,SCPD_ROOTNODE_NS); wrong! - Node scpd = new Node(SCPD_ROOTNODE); // better (twa) - scpd.addAttribute("xmlns",SCPD_ROOTNODE_NS); // better (twa) + Node scpd = new Node(SCPD_ROOTNODE); + scpd.addAttribute("xmlns",SCPD_ROOTNODE_NS); scpd.addNode(sp); getServiceData().setSCPDNode(scpd); } @@ -241,6 +241,31 @@ public class Service return getServiceNode().getNodeValue(SERVICE_ID); } + //////////////////////////////////////////////// + // configID + //////////////////////////////////////////////// + + private final static String CONFIG_ID = "configId"; + + public void updateConfigId() + { + Node scpdNode = getSCPDNode(); + if (scpdNode == null) + return; + + String scpdXml = scpdNode.toString(); + int configId = UPnP.caluculateConfigId(scpdXml); + scpdNode.setAttribute(CONFIG_ID, configId); + } + + public int getConfigId() + { + Node scpdNode = getSCPDNode(); + if (scpdNode == null) + return 0; + return scpdNode.getAttributeIntegerValue(CONFIG_ID); + } + //////////////////////////////////////////////// // isURL //////////////////////////////////////////////// @@ -340,6 +365,7 @@ public class Service catch (ParserException e) { throw new InvalidDescriptionException(e); } + return true; } @@ -349,8 +375,10 @@ public class Service Node scpdNode = parser.parse(file); if (scpdNode == null) return false; + ServiceData data = getServiceData(); data.setSCPDNode(scpdNode); + return true; } @@ -363,20 +391,22 @@ public class Service Node scpdNode = parser.parse(input); if (scpdNode == null) return false; + ServiceData data = getServiceData(); data.setSCPDNode(scpdNode); + return true; } public void setDescriptionURL(String value) { - getServiceData().setDescriptionURL(value); + getServiceData().setDescriptionURL(value); } public String getDescriptionURL() { - return getServiceData().getDescriptionURL(); + return getServiceData().getDescriptionURL(); } diff --git a/router/java/src/org/cybergarage/upnp/ServiceList.java b/router/java/src/org/cybergarage/upnp/ServiceList.java index 55dee276f039372cabd56d56f5807fb67857090a..a231324942f51a416a13dff804e7a87baf2eff91 100644 --- a/router/java/src/org/cybergarage/upnp/ServiceList.java +++ b/router/java/src/org/cybergarage/upnp/ServiceList.java @@ -1,52 +1,52 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: ServiceList.java -* -* Revision; -* -* 12/04/02 -* - first revision. -* 06/18/03 -* - Added caching a ArrayIndexOfBound exception. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ServiceList.java +* +* Revision; +* +* 12/04/02 +* - first revision. +* 06/18/03 +* - Added caching a ArrayIndexOfBound exception. +* +******************************************************************/ + +package org.cybergarage.upnp; + +import java.util.Vector; + +public class ServiceList extends Vector +{ + //////////////////////////////////////////////// + // 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 -{ - //////////////////////////////////////////////// - // 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; - } -} - diff --git a/router/java/src/org/cybergarage/upnp/ServiceStateTable.java b/router/java/src/org/cybergarage/upnp/ServiceStateTable.java index daddfbf861713e5c84e9e3f11851d58876bf941d..ab0a30557475c55e2689d2b12c2c6695d1d84162 100644 --- a/router/java/src/org/cybergarage/upnp/ServiceStateTable.java +++ b/router/java/src/org/cybergarage/upnp/ServiceStateTable.java @@ -1,45 +1,45 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: ServiceStateTable.java -* -* Revision: -* -* 12/06/02 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ServiceStateTable.java +* +* Revision: +* +* 12/06/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp; + +import java.util.Vector; + +public class ServiceStateTable extends Vector +{ + //////////////////////////////////////////////// + // 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 -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "serviceStateTable"; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public ServiceStateTable() - { - } - - //////////////////////////////////////////////// - // Methods - //////////////////////////////////////////////// - - public StateVariable getStateVariable(int n) - { - return (StateVariable)get(n); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/UPnP.java b/router/java/src/org/cybergarage/upnp/UPnP.java index caa00f5656d313c35dc039aaa22da12ccef91b6f..8e72378a34dc9db364100a1075ad83435a565172 100644 --- a/router/java/src/org/cybergarage/upnp/UPnP.java +++ b/router/java/src/org/cybergarage/upnp/UPnP.java @@ -45,7 +45,7 @@ public class UPnP public final static String XML_CLASS_PROPERTTY="cyberlink.upnp.xml.parser"; public final static String NAME = "CyberLinkJava"; - public final static String VERSION = "1.8"; + public final static String VERSION = "3.0"; public final static int SERVER_RETRY_COUNT = 100; public final static int DEFAULT_EXPIRED_DEVICE_EXTRA_TIME = 60; @@ -63,6 +63,8 @@ public class UPnP public final static String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; + public final static int CONFIGID_UPNP_ORG_MAX = 16777215; + //////////////////////////////////////////////// // Enable / Disable //////////////////////////////////////////////// @@ -189,6 +191,34 @@ public class UPnP toUUID((int)((time2 >> 32) | 0xE000) & 0xFFFF); } + //////////////////////////////////////////////// + // BootId + //////////////////////////////////////////////// + + public static final int createBootId() + { + return (int)(System.currentTimeMillis() / 1000L); + } + + //////////////////////////////////////////////// + // ConfigId + //////////////////////////////////////////////// + + public static final int caluculateConfigId(String configXml) + { + if (configXml == null) + return 0; + int configId = 0; + int configLen = configXml.length(); + for (int n=0; n<configLen; n++) { + configId += configXml.codePointAt(n); + if (configId < CONFIGID_UPNP_ORG_MAX) + continue; + configId = configId % CONFIGID_UPNP_ORG_MAX; + } + return configId; + } + //////////////////////////////////////////////// // XML Parser //////////////////////////////////////////////// diff --git a/router/java/src/org/cybergarage/upnp/UPnPStatus.java b/router/java/src/org/cybergarage/upnp/UPnPStatus.java index 0244a6b1df9d3f73a76e714e213b8e950a41101d..2ab429249430234a05576f925266bc0536031a5b 100644 --- a/router/java/src/org/cybergarage/upnp/UPnPStatus.java +++ b/router/java/src/org/cybergarage/upnp/UPnPStatus.java @@ -1,82 +1,82 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2004 -* -* File: UPnPStatus.java -* -* Revision; -* -* 11/18/02 -* - first revision. -* 01/03/04 -* - Changed the class name from UPnPError to UPnPStatus. -* -******************************************************************/ - -package org.cybergarage.upnp; -import org.cybergarage.http.HTTPStatus; - -public class UPnPStatus -{ - //////////////////////////////////////////////// - // Code - //////////////////////////////////////////////// - - public static final int INVALID_ACTION = 401; - public static final int INVALID_ARGS = 402; - public static final int OUT_OF_SYNC = 403; - public static final int INVALID_VAR = 404; - public static final int PRECONDITION_FAILED = 412; - public static final int ACTION_FAILED = 501; - - public static final String code2String(int code) - { - switch (code) { - case INVALID_ACTION: return "Invalid Action"; - case INVALID_ARGS: return "Invalid Args"; - case OUT_OF_SYNC: return "Out of Sync"; - case INVALID_VAR: return "Invalid Var"; - case PRECONDITION_FAILED: return "Precondition Failed"; - case ACTION_FAILED: return "Action Failed"; - default: return HTTPStatus.code2String(code); - } - } - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private int code; - private String description; - - public UPnPStatus() - { - setCode(0); - setDescription(""); - } - - public UPnPStatus(int code, String desc) - { - setCode(code); - setDescription(desc); - } - - public int getCode() { - return code; - } - - public void setCode(int code) { - this.code = code; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2004 +* +* File: UPnPStatus.java +* +* Revision; +* +* 11/18/02 +* - first revision. +* 01/03/04 +* - Changed the class name from UPnPError to UPnPStatus. +* +******************************************************************/ + +package org.cybergarage.upnp; +import org.cybergarage.http.HTTPStatus; + +public class UPnPStatus +{ + //////////////////////////////////////////////// + // Code + //////////////////////////////////////////////// + + public static final int INVALID_ACTION = 401; + public static final int INVALID_ARGS = 402; + public static final int OUT_OF_SYNC = 403; + public static final int INVALID_VAR = 404; + public static final int PRECONDITION_FAILED = 412; + public static final int ACTION_FAILED = 501; + + public static final String code2String(int code) + { + switch (code) { + case INVALID_ACTION: return "Invalid Action"; + case INVALID_ARGS: return "Invalid Args"; + case OUT_OF_SYNC: return "Out of Sync"; + case INVALID_VAR: return "Invalid Var"; + case PRECONDITION_FAILED: return "Precondition Failed"; + case ACTION_FAILED: return "Action Failed"; + default: return HTTPStatus.code2String(code); + } + } + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private int code; + private String description; + + public UPnPStatus() + { + setCode(0); + setDescription(""); + } + + public UPnPStatus(int code, String desc) + { + setCode(code); + setDescription(desc); + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/router/java/src/org/cybergarage/upnp/control/ActionListener.java b/router/java/src/org/cybergarage/upnp/control/ActionListener.java index 40f9244b5bf25aa46155c36177ebe8aae65fb0b2..180602aad177a612144cd58e73c511e48587a1de 100644 --- a/router/java/src/org/cybergarage/upnp/control/ActionListener.java +++ b/router/java/src/org/cybergarage/upnp/control/ActionListener.java @@ -1,23 +1,23 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: ActionListener.java -* -* Revision; -* -* 01/16/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import org.cybergarage.upnp.*; - -public interface ActionListener -{ - public boolean actionControlReceived(Action action); -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ActionListener.java +* +* Revision; +* +* 01/16/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import org.cybergarage.upnp.*; + +public interface ActionListener +{ + public boolean actionControlReceived(Action action); +} diff --git a/router/java/src/org/cybergarage/upnp/control/ActionRequest.java b/router/java/src/org/cybergarage/upnp/control/ActionRequest.java index e14db4b46c793b95978eeb165deb896966993c02..531b7d2147c77ef59c833cda617f6529d546b039 100644 --- a/router/java/src/org/cybergarage/upnp/control/ActionRequest.java +++ b/router/java/src/org/cybergarage/upnp/control/ActionRequest.java @@ -1,145 +1,145 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: ControlRequest.java -* -* Revision; -* -* 01/29/03 -* - first revision. -* 05/09/05 -* - Changed getActionName() to return when the delimiter is not found. -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import org.cybergarage.http.*; -import org.cybergarage.xml.*; -import org.cybergarage.soap.*; - -import org.cybergarage.upnp.*; - -public class ActionRequest extends ControlRequest -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public ActionRequest() - { - } - - public ActionRequest(HTTPRequest httpReq) - { - set(httpReq); - } - - //////////////////////////////////////////////// - // Action - //////////////////////////////////////////////// - - public Node getActionNode() - { - Node bodyNode = getBodyNode(); - if (bodyNode == null) - return null; - if (bodyNode.hasNodes() == false) - return null; - return bodyNode.getNode(0); - } - - public String getActionName() - { - Node node = getActionNode(); - if (node == null) - return ""; - String name = node.getName(); - if (name == null) - return ""; - int idx = name.indexOf(SOAP.DELIM)+1; - if (idx < 0) - return ""; - return name.substring(idx, name.length()); - } - - public ArgumentList getArgumentList() - { - Node actNode = getActionNode(); - int nArgNodes = actNode.getNNodes(); - ArgumentList argList = new ArgumentList(); - for (int n=0; n<nArgNodes; n++) { - Argument arg = new Argument(); - Node argNode = actNode.getNode(n); - arg.setName(argNode.getName()); - arg.setValue(argNode.getValue()); - argList.add(arg); - } - return argList; - } - - //////////////////////////////////////////////// - // setRequest - //////////////////////////////////////////////// - - public void setRequest(Action action, ArgumentList argList) - { - Service service = action.getService(); - - setRequestHost(service); - - setEnvelopeNode(SOAP.createEnvelopeBodyNode()); - Node envNode = getEnvelopeNode(); - Node bodyNode = getBodyNode(); - Node argNode = createContentNode(service, action, argList); - bodyNode.addNode(argNode); - setContent(envNode); - - String serviceType = service.getServiceType(); - String actionName = action.getName(); - String soapAction = "\"" + - serviceType + - "#" + actionName + - "\""; - setSOAPAction(soapAction); - } - - //////////////////////////////////////////////// - // Contents - //////////////////////////////////////////////// - - private Node createContentNode(Service service, Action action, ArgumentList argList) - { - String actionName = action.getName(); - String serviceType = service.getServiceType(); - - Node actionNode = new Node(); - actionNode.setName(Control.NS, actionName); - actionNode.setNameSpace(Control.NS, serviceType); - - int argListCnt = argList.size(); - for (int n=0; n<argListCnt; n++) { - Argument arg = argList.getArgument(n); - Node argNode = new Node(); - argNode.setName(arg.getName()); - argNode.setValue(arg.getValue()); - actionNode.addNode(argNode); - } - - return actionNode; - } - - //////////////////////////////////////////////// - // post - //////////////////////////////////////////////// - - public ActionResponse post() - { - SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort()); - return new ActionResponse(soapRes); - } -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ControlRequest.java +* +* Revision; +* +* 01/29/03 +* - first revision. +* 05/09/05 +* - Changed getActionName() to return when the delimiter is not found. +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import org.cybergarage.http.*; +import org.cybergarage.xml.*; +import org.cybergarage.soap.*; + +import org.cybergarage.upnp.*; + +public class ActionRequest extends ControlRequest +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public ActionRequest() + { + } + + public ActionRequest(HTTPRequest httpReq) + { + set(httpReq); + } + + //////////////////////////////////////////////// + // Action + //////////////////////////////////////////////// + + public Node getActionNode() + { + Node bodyNode = getBodyNode(); + if (bodyNode == null) + return null; + if (bodyNode.hasNodes() == false) + return null; + return bodyNode.getNode(0); + } + + public String getActionName() + { + Node node = getActionNode(); + if (node == null) + return ""; + String name = node.getName(); + if (name == null) + return ""; + int idx = name.indexOf(SOAP.DELIM)+1; + if (idx < 0) + return ""; + return name.substring(idx, name.length()); + } + + public ArgumentList getArgumentList() + { + Node actNode = getActionNode(); + int nArgNodes = actNode.getNNodes(); + ArgumentList argList = new ArgumentList(); + for (int n=0; n<nArgNodes; n++) { + Argument arg = new Argument(); + Node argNode = actNode.getNode(n); + arg.setName(argNode.getName()); + arg.setValue(argNode.getValue()); + argList.add(arg); + } + return argList; + } + + //////////////////////////////////////////////// + // setRequest + //////////////////////////////////////////////// + + public void setRequest(Action action, ArgumentList argList) + { + Service service = action.getService(); + + setRequestHost(service); + + setEnvelopeNode(SOAP.createEnvelopeBodyNode()); + Node envNode = getEnvelopeNode(); + Node bodyNode = getBodyNode(); + Node argNode = createContentNode(service, action, argList); + bodyNode.addNode(argNode); + setContent(envNode); + + String serviceType = service.getServiceType(); + String actionName = action.getName(); + String soapAction = "\"" + + serviceType + + "#" + actionName + + "\""; + setSOAPAction(soapAction); + } + + //////////////////////////////////////////////// + // Contents + //////////////////////////////////////////////// + + private Node createContentNode(Service service, Action action, ArgumentList argList) + { + String actionName = action.getName(); + String serviceType = service.getServiceType(); + + Node actionNode = new Node(); + actionNode.setName(Control.NS, actionName); + actionNode.setNameSpace(Control.NS, serviceType); + + int argListCnt = argList.size(); + for (int n=0; n<argListCnt; n++) { + Argument arg = argList.getArgument(n); + Node argNode = new Node(); + argNode.setName(arg.getName()); + argNode.setValue(arg.getValue()); + actionNode.addNode(argNode); + } + + return actionNode; + } + + //////////////////////////////////////////////// + // post + //////////////////////////////////////////////// + + public ActionResponse post() + { + SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort()); + return new ActionResponse(soapRes); + } +} + diff --git a/router/java/src/org/cybergarage/upnp/control/ActionResponse.java b/router/java/src/org/cybergarage/upnp/control/ActionResponse.java index 04c495a498c4c0735789eec6a68c7168f061e87a..a1e2cfc0ee65731d50b29755c1a88b0e19294c9b 100644 --- a/router/java/src/org/cybergarage/upnp/control/ActionResponse.java +++ b/router/java/src/org/cybergarage/upnp/control/ActionResponse.java @@ -1,120 +1,120 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: ActionResponse.java -* -* Revision; -* -* 01/29/03 -* - first revision. -* 09/02/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Problem : Action Responses do not contain the mandatory header field EXT -* - Error : ActionResponse class does not set the EXT header -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import org.cybergarage.upnp.*; -import org.cybergarage.http.*; -import org.cybergarage.soap.*; -import org.cybergarage.xml.*; - -public class ActionResponse extends ControlResponse -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public ActionResponse() - { - setHeader(HTTP.EXT, ""); - } - - public ActionResponse(SOAPResponse soapRes) - { - super(soapRes); - setHeader(HTTP.EXT, ""); - } - - - //////////////////////////////////////////////// - // Response - //////////////////////////////////////////////// - - public void setResponse(Action action) - { - setStatusCode(HTTPStatus.OK); - - Node bodyNode = getBodyNode(); - Node resNode = createResponseNode(action); - bodyNode.addNode(resNode); - - Node envNode = getEnvelopeNode(); - setContent(envNode); - } - - private Node createResponseNode(Action action) - { - String actionName = action.getName(); - Node actionNameResNode = new Node(SOAP.METHODNS + SOAP.DELIM + actionName + SOAP.RESPONSE); - - Service service = action.getService(); - if (service != null) { - actionNameResNode.setAttribute( - "xmlns:" + SOAP.METHODNS, - service.getServiceType()); - } - - ArgumentList argList = action.getArgumentList(); - int nArgs = argList.size(); - for (int n=0; n<nArgs; n++) { - Argument arg = argList.getArgument(n); - if (arg.isOutDirection() == false) - continue; - Node argNode = new Node(); - argNode.setName(arg.getName()); - argNode.setValue(arg.getValue()); - actionNameResNode.addNode(argNode); - } - - return actionNameResNode; - } - - //////////////////////////////////////////////// - // getResponse - //////////////////////////////////////////////// - - private Node getActionResponseNode() - { - Node bodyNode = getBodyNode(); - if (bodyNode == null || bodyNode.hasNodes() == false) - return null; - return bodyNode.getNode(0); - } - - - public ArgumentList getResponse() - { - ArgumentList argList = new ArgumentList(); - - Node resNode = getActionResponseNode(); - if (resNode == null) - return argList; - - int nArgs = resNode.getNNodes(); - for (int n=0; n<nArgs; n++) { - Node node = resNode.getNode(n); - String name = node.getName(); - String value = node.getValue(); - Argument arg = new Argument(name, value); - argList.add(arg); - } - - return argList; - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ActionResponse.java +* +* Revision; +* +* 01/29/03 +* - first revision. +* 09/02/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Problem : Action Responses do not contain the mandatory header field EXT +* - Error : ActionResponse class does not set the EXT header +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import org.cybergarage.upnp.*; +import org.cybergarage.http.*; +import org.cybergarage.soap.*; +import org.cybergarage.xml.*; + +public class ActionResponse extends ControlResponse +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public ActionResponse() + { + setHeader(HTTP.EXT, ""); + } + + public ActionResponse(SOAPResponse soapRes) + { + super(soapRes); + setHeader(HTTP.EXT, ""); + } + + + //////////////////////////////////////////////// + // Response + //////////////////////////////////////////////// + + public void setResponse(Action action) + { + setStatusCode(HTTPStatus.OK); + + Node bodyNode = getBodyNode(); + Node resNode = createResponseNode(action); + bodyNode.addNode(resNode); + + Node envNode = getEnvelopeNode(); + setContent(envNode); + } + + private Node createResponseNode(Action action) + { + String actionName = action.getName(); + Node actionNameResNode = new Node(SOAP.METHODNS + SOAP.DELIM + actionName + SOAP.RESPONSE); + + Service service = action.getService(); + if (service != null) { + actionNameResNode.setAttribute( + "xmlns:" + SOAP.METHODNS, + service.getServiceType()); + } + + ArgumentList argList = action.getArgumentList(); + int nArgs = argList.size(); + for (int n=0; n<nArgs; n++) { + Argument arg = argList.getArgument(n); + if (arg.isOutDirection() == false) + continue; + Node argNode = new Node(); + argNode.setName(arg.getName()); + argNode.setValue(arg.getValue()); + actionNameResNode.addNode(argNode); + } + + return actionNameResNode; + } + + //////////////////////////////////////////////// + // getResponse + //////////////////////////////////////////////// + + private Node getActionResponseNode() + { + Node bodyNode = getBodyNode(); + if (bodyNode == null || bodyNode.hasNodes() == false) + return null; + return bodyNode.getNode(0); + } + + + public ArgumentList getResponse() + { + ArgumentList argList = new ArgumentList(); + + Node resNode = getActionResponseNode(); + if (resNode == null) + return argList; + + int nArgs = resNode.getNNodes(); + for (int n=0; n<nArgs; n++) { + Node node = resNode.getNode(n); + String name = node.getName(); + String value = node.getValue(); + Argument arg = new Argument(name, value); + argList.add(arg); + } + + return argList; + } +} diff --git a/router/java/src/org/cybergarage/upnp/control/Control.java b/router/java/src/org/cybergarage/upnp/control/Control.java index 53549096ebe288a88cc8943d460be7c956504372..ea68a2f4af306458499611898cb19b727e34f61d 100644 --- a/router/java/src/org/cybergarage/upnp/control/Control.java +++ b/router/java/src/org/cybergarage/upnp/control/Control.java @@ -1,29 +1,29 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: Control.java -* -* Revision; -* -* 01/20/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -public class Control -{ - public final static String NS = "u"; - public final static String QUERY_SOAPACTION = "urn:schemas-upnp-org:control-1-0#QueryStateVariable"; - public final static String XMLNS = "urn:schemas-upnp-org:control-1-0"; - public final static String QUERY_STATE_VARIABLE = "QueryStateVariable"; - public final static String QUERY_STATE_VARIABLE_RESPONSE = "QueryStateVariableResponse"; - public final static String VAR_NAME = "varName"; - public final static String RETURN = "return"; -} - - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: Control.java +* +* Revision; +* +* 01/20/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +public class Control +{ + public final static String NS = "u"; + public final static String QUERY_SOAPACTION = "urn:schemas-upnp-org:control-1-0#QueryStateVariable"; + public final static String XMLNS = "urn:schemas-upnp-org:control-1-0"; + public final static String QUERY_STATE_VARIABLE = "QueryStateVariable"; + public final static String QUERY_STATE_VARIABLE_RESPONSE = "QueryStateVariableResponse"; + public final static String VAR_NAME = "varName"; + public final static String RETURN = "return"; +} + + diff --git a/router/java/src/org/cybergarage/upnp/control/ControlRequest.java b/router/java/src/org/cybergarage/upnp/control/ControlRequest.java index a605a2afad49f5ecbe72d220fe6f95d0c382ff6f..b5d519b4fd1272ab799797671c60da918d2e58dc 100644 --- a/router/java/src/org/cybergarage/upnp/control/ControlRequest.java +++ b/router/java/src/org/cybergarage/upnp/control/ControlRequest.java @@ -1,128 +1,128 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: ControlRequest.java -* -* Revision: -* -* 01/29/03 -* - first revision. -* 05/22/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Description: inserted a check at the beginning of the setRequestHost method -* - Problem : If the host does not start with a '/', the device could refuse the control action -* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices -* 09/02/03 -* - Giordano Sassaroli <sassarol@cefriel.it> / Suzan Foster -* - Problem : NullpointerException thrown for devices whose description use absolute urls -* - Error : the presence of a base url is not mandatory, the API code makes the assumption that control and event subscription urls are relative. -* If the baseUrl is not present, the request host and port should be extracted from the control/subscription url -* - Description: The method setRequestHost/setService should be changed as follows -* 02/17/04 -* - Rob van den Boomen <rob.van.den.boomen@philips.com> -* - Fixed to set a URLBase from the SSDP header when the URLBase of the description is null. -* 02/18/04 -* - Andre <andre@antiheld.net> -* - The xml nodes controlUrl and eventSubUrl can contain absolut urls, but these absolut urls may have -* different ports than the base url! (so seen on my SMC 7004ABR Barricade Router, where xml files are -* requested from port 80, but soap requests are made on port 5440). Therefore whenever a request is made, -* the port specified by the controlUrl or eventSubUrl node should be used, else no response will be returned -* (oddly, there was a response returned even on port 80, but with empty body tags. but the correct response -* finally came from port 5440). -* - Fixed to get the port from the control url when it is absolute. -* 03/20/04 -* - Thanks for Thomas Schulz <tsroyale at users.sourceforge.net> -* - Fixed setRequestHost() for Sony's UPnP stack when the URLBase has the path. -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import java.net.*; - -import org.cybergarage.http.*; -import org.cybergarage.soap.*; - -import org.cybergarage.upnp.*; - -public class ControlRequest extends SOAPRequest -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public ControlRequest() - { - } - - public ControlRequest(HTTPRequest httpReq) - { - set(httpReq); - } - - //////////////////////////////////////////////// - // Query - //////////////////////////////////////////////// - - public boolean isQueryControl() - { - return isSOAPAction(Control.QUERY_SOAPACTION); - } - - public boolean isActionControl() - { - return !isQueryControl(); - } - - //////////////////////////////////////////////// - // setRequest - //////////////////////////////////////////////// - - protected void setRequestHost(Service service) - { - String ctrlURL = service.getControlURL(); - - // Thanks for Thomas Schulz (2004/03/20) - String urlBase = service.getRootDevice().getURLBase(); - if (urlBase != null && 0 < urlBase.length()){ - try { - URL url = new URL(urlBase); - String basePath = url.getPath(); - int baseLen = basePath.length(); - if (0 < baseLen) { - if (1 < baseLen || (basePath.charAt(0) != '/')) - ctrlURL = basePath + ctrlURL; - } - } - catch (MalformedURLException e) {} - } - - // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03) - setURI(ctrlURL, true); - - // Thanks for Giordano Sassaroli <sassarol@cefriel.it> and Suzan Foster (09/02/03) - // Thanks for Andre <andre@antiheld.net> (02/18/04) - String postURL = ""; - if (HTTP.isAbsoluteURL(ctrlURL) == true) - postURL = ctrlURL; - - if (postURL == null || postURL.length() <= 0) - postURL = service.getRootDevice().getURLBase(); - - // Thanks for Rob van den Boomen <rob.van.den.boomen@philips.com> (02/17/04) - // BUGFIX, set urlbase from location string if not set in description.xml - if (postURL == null || postURL.length() <= 0) - postURL = service.getRootDevice().getLocation(); - - String reqHost = HTTP.getHost(postURL); - int reqPort = HTTP.getPort(postURL); - - setHost(reqHost, reqPort); - setRequestHost(reqHost); - setRequestPort(reqPort); - } - -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ControlRequest.java +* +* Revision: +* +* 01/29/03 +* - first revision. +* 05/22/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Description: inserted a check at the beginning of the setRequestHost method +* - Problem : If the host does not start with a '/', the device could refuse the control action +* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices +* 09/02/03 +* - Giordano Sassaroli <sassarol@cefriel.it> / Suzan Foster +* - Problem : NullpointerException thrown for devices whose description use absolute urls +* - Error : the presence of a base url is not mandatory, the API code makes the assumption that control and event subscription urls are relative. +* If the baseUrl is not present, the request host and port should be extracted from the control/subscription url +* - Description: The method setRequestHost/setService should be changed as follows +* 02/17/04 +* - Rob van den Boomen <rob.van.den.boomen@philips.com> +* - Fixed to set a URLBase from the SSDP header when the URLBase of the description is null. +* 02/18/04 +* - Andre <andre@antiheld.net> +* - The xml nodes controlUrl and eventSubUrl can contain absolut urls, but these absolut urls may have +* different ports than the base url! (so seen on my SMC 7004ABR Barricade Router, where xml files are +* requested from port 80, but soap requests are made on port 5440). Therefore whenever a request is made, +* the port specified by the controlUrl or eventSubUrl node should be used, else no response will be returned +* (oddly, there was a response returned even on port 80, but with empty body tags. but the correct response +* finally came from port 5440). +* - Fixed to get the port from the control url when it is absolute. +* 03/20/04 +* - Thanks for Thomas Schulz <tsroyale at users.sourceforge.net> +* - Fixed setRequestHost() for Sony's UPnP stack when the URLBase has the path. +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import java.net.*; + +import org.cybergarage.http.*; +import org.cybergarage.soap.*; + +import org.cybergarage.upnp.*; + +public class ControlRequest extends SOAPRequest +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public ControlRequest() + { + } + + public ControlRequest(HTTPRequest httpReq) + { + set(httpReq); + } + + //////////////////////////////////////////////// + // Query + //////////////////////////////////////////////// + + public boolean isQueryControl() + { + return isSOAPAction(Control.QUERY_SOAPACTION); + } + + public boolean isActionControl() + { + return !isQueryControl(); + } + + //////////////////////////////////////////////// + // setRequest + //////////////////////////////////////////////// + + protected void setRequestHost(Service service) + { + String ctrlURL = service.getControlURL(); + + // Thanks for Thomas Schulz (2004/03/20) + String urlBase = service.getRootDevice().getURLBase(); + if (urlBase != null && 0 < urlBase.length()){ + try { + URL url = new URL(urlBase); + String basePath = url.getPath(); + int baseLen = basePath.length(); + if (0 < baseLen) { + if (1 < baseLen || (basePath.charAt(0) != '/')) + ctrlURL = basePath + ctrlURL; + } + } + catch (MalformedURLException e) {} + } + + // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03) + setURI(ctrlURL, true); + + // Thanks for Giordano Sassaroli <sassarol@cefriel.it> and Suzan Foster (09/02/03) + // Thanks for Andre <andre@antiheld.net> (02/18/04) + String postURL = ""; + if (HTTP.isAbsoluteURL(ctrlURL) == true) + postURL = ctrlURL; + + if (postURL == null || postURL.length() <= 0) + postURL = service.getRootDevice().getURLBase(); + + // Thanks for Rob van den Boomen <rob.van.den.boomen@philips.com> (02/17/04) + // BUGFIX, set urlbase from location string if not set in description.xml + if (postURL == null || postURL.length() <= 0) + postURL = service.getRootDevice().getLocation(); + + String reqHost = HTTP.getHost(postURL); + int reqPort = HTTP.getPort(postURL); + + setHost(reqHost, reqPort); + setRequestHost(reqHost); + setRequestPort(reqPort); + } + +} diff --git a/router/java/src/org/cybergarage/upnp/control/ControlResponse.java b/router/java/src/org/cybergarage/upnp/control/ControlResponse.java index b764a6ae7324586f5479554d74c90ee943ee7e78..196d6b4df30a7147380eb6735e0101bc0d5add6a 100644 --- a/router/java/src/org/cybergarage/upnp/control/ControlResponse.java +++ b/router/java/src/org/cybergarage/upnp/control/ControlResponse.java @@ -1,173 +1,173 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: ControlResponse.java -* -* Revision; -* -* 01/29/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import org.cybergarage.http.*; -import org.cybergarage.xml.*; -import org.cybergarage.soap.*; - -import org.cybergarage.upnp.*; - -public class ControlResponse extends SOAPResponse -{ - public static final String FAULT_CODE = "Client"; - public static final String FAULT_STRING = "UPnPError"; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public ControlResponse() - { - setServer(UPnP.getServerName()); - } - - public ControlResponse(SOAPResponse soapRes) - { - super(soapRes); - } - - //////////////////////////////////////////////// - // FaultResponse - //////////////////////////////////////////////// - - public void setFaultResponse(int errCode, String errDescr) - { - setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); - - Node bodyNode = getBodyNode(); - Node faultNode = createFaultResponseNode(errCode, errDescr); - bodyNode.addNode(faultNode); - - Node envNode = getEnvelopeNode(); - setContent(envNode); - } - - public void setFaultResponse(int errCode) - { - setFaultResponse(errCode, UPnPStatus.code2String(errCode)); - } - - //////////////////////////////////////////////// - // createFaultResponseNode - //////////////////////////////////////////////// - - private Node createFaultResponseNode(int errCode, String errDescr) - { - // <s:Fault> - Node faultNode = new Node(SOAP.XMLNS + SOAP.DELIM + SOAP.FAULT); - - // <faultcode>s:Client</faultcode> - Node faultCodeNode = new Node(SOAP.FAULT_CODE); - faultCodeNode.setValue(SOAP.XMLNS + SOAP.DELIM + FAULT_CODE); - faultNode.addNode(faultCodeNode); - - // <faultstring>UPnPError</faultstring> - Node faultStringNode = new Node(SOAP.FAULT_STRING); - faultStringNode.setValue(FAULT_STRING); - faultNode.addNode(faultStringNode); - - // <detail> - Node detailNode = new Node(SOAP.DETAIL); - faultNode.addNode(detailNode); - - // <UPnPError xmlns="urn:schemas-upnp-org:control-1-0"> - Node upnpErrorNode = new Node(FAULT_STRING); - upnpErrorNode.setAttribute("xmlns", Control.XMLNS); - detailNode.addNode(upnpErrorNode); - - // <errorCode>error code</errorCode> - Node errorCodeNode = new Node(SOAP.ERROR_CODE); - errorCodeNode.setValue(errCode); - upnpErrorNode.addNode(errorCodeNode); - - // <errorDescription>error string</errorDescription> - Node errorDesctiprionNode = new Node(SOAP.ERROR_DESCRIPTION); - errorDesctiprionNode.setValue(errDescr); - upnpErrorNode.addNode(errorDesctiprionNode); - - return faultNode; - } - - private Node createFaultResponseNode(int errCode) - { - return createFaultResponseNode(errCode, UPnPStatus.code2String(errCode)); - } - - //////////////////////////////////////////////// - // UPnP Error - //////////////////////////////////////////////// - - private UPnPStatus upnpErr = new UPnPStatus(); - - private Node getUPnPErrorNode() - { - Node detailNode = getFaultDetailNode(); - if (detailNode == null) - return null; - return detailNode.getNodeEndsWith(SOAP.UPNP_ERROR); - } - - private Node getUPnPErrorCodeNode() - { - Node errorNode = getUPnPErrorNode(); - if (errorNode == null) - return null; - return errorNode.getNodeEndsWith(SOAP.ERROR_CODE); - } - - private Node getUPnPErrorDescriptionNode() - { - Node errorNode = getUPnPErrorNode(); - if (errorNode == null) - return null; - return errorNode.getNodeEndsWith(SOAP.ERROR_DESCRIPTION); - } - - public int getUPnPErrorCode() - { - Node errorCodeNode = getUPnPErrorCodeNode(); - if (errorCodeNode == null) - return -1; - String errorCodeStr = errorCodeNode.getValue(); - try { - return Integer.parseInt(errorCodeStr); - } - catch (Exception e) { - return -1; - } - } - - public String getUPnPErrorDescription() - { - Node errorDescNode = getUPnPErrorDescriptionNode(); - if (errorDescNode == null) - return ""; - return errorDescNode.getValue(); - } - - public UPnPStatus getUPnPError() - { - int code = 0; - String desc = ""; - code = getUPnPErrorCode(); - desc = getUPnPErrorDescription(); - upnpErr.setCode(code); - upnpErr.setDescription(desc); - return upnpErr; - } - -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ControlResponse.java +* +* Revision; +* +* 01/29/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import org.cybergarage.http.*; +import org.cybergarage.xml.*; +import org.cybergarage.soap.*; + +import org.cybergarage.upnp.*; + +public class ControlResponse extends SOAPResponse +{ + public static final String FAULT_CODE = "Client"; + public static final String FAULT_STRING = "UPnPError"; + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public ControlResponse() + { + setServer(UPnP.getServerName()); + } + + public ControlResponse(SOAPResponse soapRes) + { + super(soapRes); + } + + //////////////////////////////////////////////// + // FaultResponse + //////////////////////////////////////////////// + + public void setFaultResponse(int errCode, String errDescr) + { + setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); + + Node bodyNode = getBodyNode(); + Node faultNode = createFaultResponseNode(errCode, errDescr); + bodyNode.addNode(faultNode); + + Node envNode = getEnvelopeNode(); + setContent(envNode); + } + + public void setFaultResponse(int errCode) + { + setFaultResponse(errCode, UPnPStatus.code2String(errCode)); + } + + //////////////////////////////////////////////// + // createFaultResponseNode + //////////////////////////////////////////////// + + private Node createFaultResponseNode(int errCode, String errDescr) + { + // <s:Fault> + Node faultNode = new Node(SOAP.XMLNS + SOAP.DELIM + SOAP.FAULT); + + // <faultcode>s:Client</faultcode> + Node faultCodeNode = new Node(SOAP.FAULT_CODE); + faultCodeNode.setValue(SOAP.XMLNS + SOAP.DELIM + FAULT_CODE); + faultNode.addNode(faultCodeNode); + + // <faultstring>UPnPError</faultstring> + Node faultStringNode = new Node(SOAP.FAULT_STRING); + faultStringNode.setValue(FAULT_STRING); + faultNode.addNode(faultStringNode); + + // <detail> + Node detailNode = new Node(SOAP.DETAIL); + faultNode.addNode(detailNode); + + // <UPnPError xmlns="urn:schemas-upnp-org:control-1-0"> + Node upnpErrorNode = new Node(FAULT_STRING); + upnpErrorNode.setAttribute("xmlns", Control.XMLNS); + detailNode.addNode(upnpErrorNode); + + // <errorCode>error code</errorCode> + Node errorCodeNode = new Node(SOAP.ERROR_CODE); + errorCodeNode.setValue(errCode); + upnpErrorNode.addNode(errorCodeNode); + + // <errorDescription>error string</errorDescription> + Node errorDesctiprionNode = new Node(SOAP.ERROR_DESCRIPTION); + errorDesctiprionNode.setValue(errDescr); + upnpErrorNode.addNode(errorDesctiprionNode); + + return faultNode; + } + + private Node createFaultResponseNode(int errCode) + { + return createFaultResponseNode(errCode, UPnPStatus.code2String(errCode)); + } + + //////////////////////////////////////////////// + // UPnP Error + //////////////////////////////////////////////// + + private UPnPStatus upnpErr = new UPnPStatus(); + + private Node getUPnPErrorNode() + { + Node detailNode = getFaultDetailNode(); + if (detailNode == null) + return null; + return detailNode.getNodeEndsWith(SOAP.UPNP_ERROR); + } + + private Node getUPnPErrorCodeNode() + { + Node errorNode = getUPnPErrorNode(); + if (errorNode == null) + return null; + return errorNode.getNodeEndsWith(SOAP.ERROR_CODE); + } + + private Node getUPnPErrorDescriptionNode() + { + Node errorNode = getUPnPErrorNode(); + if (errorNode == null) + return null; + return errorNode.getNodeEndsWith(SOAP.ERROR_DESCRIPTION); + } + + public int getUPnPErrorCode() + { + Node errorCodeNode = getUPnPErrorCodeNode(); + if (errorCodeNode == null) + return -1; + String errorCodeStr = errorCodeNode.getValue(); + try { + return Integer.parseInt(errorCodeStr); + } + catch (Exception e) { + return -1; + } + } + + public String getUPnPErrorDescription() + { + Node errorDescNode = getUPnPErrorDescriptionNode(); + if (errorDescNode == null) + return ""; + return errorDescNode.getValue(); + } + + public UPnPStatus getUPnPError() + { + int code = 0; + String desc = ""; + code = getUPnPErrorCode(); + desc = getUPnPErrorDescription(); + upnpErr.setCode(code); + upnpErr.setDescription(desc); + return upnpErr; + } + +} diff --git a/router/java/src/org/cybergarage/upnp/control/QueryListener.java b/router/java/src/org/cybergarage/upnp/control/QueryListener.java index 8af1ea13e30549c7580a67e86be27e6e6343835d..17d96d7d8310977f8c2925e16dd24e121849ed28 100644 --- a/router/java/src/org/cybergarage/upnp/control/QueryListener.java +++ b/router/java/src/org/cybergarage/upnp/control/QueryListener.java @@ -1,25 +1,25 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: QueryListener.java -* -* Revision; -* -* 01/30/03 -* - first revision. -* 01/04/04 -* - Changed the interface. -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import org.cybergarage.upnp.*; - -public interface QueryListener -{ - public boolean queryControlReceived(StateVariable stateVar); -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: QueryListener.java +* +* Revision; +* +* 01/30/03 +* - first revision. +* 01/04/04 +* - Changed the interface. +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import org.cybergarage.upnp.*; + +public interface QueryListener +{ + public boolean queryControlReceived(StateVariable stateVar); +} diff --git a/router/java/src/org/cybergarage/upnp/control/QueryRequest.java b/router/java/src/org/cybergarage/upnp/control/QueryRequest.java index ad8b437e5a2d5a198a519eabb71d659a787cde5b..bd178f0f8179688ef85134aa3269078b8653dbf7 100644 --- a/router/java/src/org/cybergarage/upnp/control/QueryRequest.java +++ b/router/java/src/org/cybergarage/upnp/control/QueryRequest.java @@ -1,119 +1,119 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: QueryRequest.java -* -* Revision; -* -* 01/29/03 -* - first revision. -* 09/02/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Error : redundant code, the setRequest method in QueryRequest invokes setURI even if after a couple of rows setRequestHost is invoked -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import org.cybergarage.http.*; -import org.cybergarage.xml.*; -import org.cybergarage.soap.*; - -import org.cybergarage.upnp.*; - -public class QueryRequest extends ControlRequest -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public QueryRequest() - { - } - - public QueryRequest(HTTPRequest httpReq) - { - set(httpReq); - } - - //////////////////////////////////////////////// - // Qyery - //////////////////////////////////////////////// - - private Node getVarNameNode() - { - Node bodyNode = getBodyNode(); - if (bodyNode == null) - return null; - if (bodyNode.hasNodes() == false) - return null; - Node queryStateVarNode = bodyNode.getNode(0); - if (queryStateVarNode == null) - return null; - if (queryStateVarNode.hasNodes() == false) - return null; - return queryStateVarNode.getNode(0); - } - - public String getVarName() - { - Node node = getVarNameNode(); - if (node == null) - return ""; - return node.getValue(); - } - - //////////////////////////////////////////////// - // setRequest - //////////////////////////////////////////////// - - public void setRequest(StateVariable stateVar) - { - Service service = stateVar.getService(); - - String ctrlURL = service.getControlURL(); - - setRequestHost(service); - - setEnvelopeNode(SOAP.createEnvelopeBodyNode()); - Node envNode = getEnvelopeNode(); - Node bodyNode = getBodyNode(); - Node qeuryNode = createContentNode(stateVar); - bodyNode.addNode(qeuryNode); - setContent(envNode); - - setSOAPAction(Control.QUERY_SOAPACTION); - } - - //////////////////////////////////////////////// - // Contents - //////////////////////////////////////////////// - - private Node createContentNode(StateVariable stateVar) - { - Node queryVarNode = new Node(); - queryVarNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE); - queryVarNode.setNameSpace(Control.NS, Control.XMLNS); - - Node varNode = new Node(); - varNode.setName(Control.NS, Control.VAR_NAME); - varNode.setValue(stateVar.getName()); - queryVarNode.addNode(varNode); - - return queryVarNode; - } - - //////////////////////////////////////////////// - // post - //////////////////////////////////////////////// - - public QueryResponse post() - { - SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort()); - return new QueryResponse(soapRes); - } -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: QueryRequest.java +* +* Revision; +* +* 01/29/03 +* - first revision. +* 09/02/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Error : redundant code, the setRequest method in QueryRequest invokes setURI even if after a couple of rows setRequestHost is invoked +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import org.cybergarage.http.*; +import org.cybergarage.xml.*; +import org.cybergarage.soap.*; + +import org.cybergarage.upnp.*; + +public class QueryRequest extends ControlRequest +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public QueryRequest() + { + } + + public QueryRequest(HTTPRequest httpReq) + { + set(httpReq); + } + + //////////////////////////////////////////////// + // Qyery + //////////////////////////////////////////////// + + private Node getVarNameNode() + { + Node bodyNode = getBodyNode(); + if (bodyNode == null) + return null; + if (bodyNode.hasNodes() == false) + return null; + Node queryStateVarNode = bodyNode.getNode(0); + if (queryStateVarNode == null) + return null; + if (queryStateVarNode.hasNodes() == false) + return null; + return queryStateVarNode.getNode(0); + } + + public String getVarName() + { + Node node = getVarNameNode(); + if (node == null) + return ""; + return node.getValue(); + } + + //////////////////////////////////////////////// + // setRequest + //////////////////////////////////////////////// + + public void setRequest(StateVariable stateVar) + { + Service service = stateVar.getService(); + + String ctrlURL = service.getControlURL(); + + setRequestHost(service); + + setEnvelopeNode(SOAP.createEnvelopeBodyNode()); + Node envNode = getEnvelopeNode(); + Node bodyNode = getBodyNode(); + Node qeuryNode = createContentNode(stateVar); + bodyNode.addNode(qeuryNode); + setContent(envNode); + + setSOAPAction(Control.QUERY_SOAPACTION); + } + + //////////////////////////////////////////////// + // Contents + //////////////////////////////////////////////// + + private Node createContentNode(StateVariable stateVar) + { + Node queryVarNode = new Node(); + queryVarNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE); + queryVarNode.setNameSpace(Control.NS, Control.XMLNS); + + Node varNode = new Node(); + varNode.setName(Control.NS, Control.VAR_NAME); + varNode.setValue(stateVar.getName()); + queryVarNode.addNode(varNode); + + return queryVarNode; + } + + //////////////////////////////////////////////// + // post + //////////////////////////////////////////////// + + public QueryResponse post() + { + SOAPResponse soapRes = postMessage(getRequestHost(), getRequestPort()); + return new QueryResponse(soapRes); + } +} + diff --git a/router/java/src/org/cybergarage/upnp/control/QueryResponse.java b/router/java/src/org/cybergarage/upnp/control/QueryResponse.java index 75ba30c84e90186e02e91fde6e1b42bd8c6e7768..a8877371152f9c47da4094f35ef128f32ebde6d7 100644 --- a/router/java/src/org/cybergarage/upnp/control/QueryResponse.java +++ b/router/java/src/org/cybergarage/upnp/control/QueryResponse.java @@ -1,97 +1,97 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: QueryResponse.java -* -* Revision; -* -* 01/30/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import org.cybergarage.upnp.*; -import org.cybergarage.http.*; -import org.cybergarage.soap.*; -import org.cybergarage.xml.*; - -public class QueryResponse extends ControlResponse -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public QueryResponse() - { - } - - public QueryResponse(SOAPResponse soapRes) - { - super(soapRes); - } - - //////////////////////////////////////////////// - // Qyery - //////////////////////////////////////////////// - - private Node getReturnNode() - { - Node bodyNode = getBodyNode(); - if (bodyNode == null) - return null; - if (bodyNode.hasNodes() == false) - return null; - Node queryResNode = bodyNode.getNode(0); - if (queryResNode == null) - return null; - if (queryResNode.hasNodes() == false) - return null; - return queryResNode.getNode(0); - } - - public String getReturnValue() - { - Node node = getReturnNode(); - if (node == null) - return ""; - return node.getValue(); - } - - //////////////////////////////////////////////// - // Response - //////////////////////////////////////////////// - - public void setResponse(StateVariable stateVar) - { - String var = stateVar.getValue(); - - setStatusCode(HTTPStatus.OK); - - Node bodyNode = getBodyNode(); - Node resNode = createResponseNode(var); - bodyNode.addNode(resNode); - - Node envNodee = getEnvelopeNode(); - setContent(envNodee); - - } - - private Node createResponseNode(String var) - { - Node queryResNode = new Node(); - queryResNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE_RESPONSE); - queryResNode.setNameSpace(Control.NS, Control.XMLNS); - - Node returnNode = new Node(); - returnNode.setName(Control.RETURN); - returnNode.setValue(var); - queryResNode.addNode(returnNode); - - return queryResNode; - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: QueryResponse.java +* +* Revision; +* +* 01/30/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import org.cybergarage.upnp.*; +import org.cybergarage.http.*; +import org.cybergarage.soap.*; +import org.cybergarage.xml.*; + +public class QueryResponse extends ControlResponse +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public QueryResponse() + { + } + + public QueryResponse(SOAPResponse soapRes) + { + super(soapRes); + } + + //////////////////////////////////////////////// + // Qyery + //////////////////////////////////////////////// + + private Node getReturnNode() + { + Node bodyNode = getBodyNode(); + if (bodyNode == null) + return null; + if (bodyNode.hasNodes() == false) + return null; + Node queryResNode = bodyNode.getNode(0); + if (queryResNode == null) + return null; + if (queryResNode.hasNodes() == false) + return null; + return queryResNode.getNode(0); + } + + public String getReturnValue() + { + Node node = getReturnNode(); + if (node == null) + return ""; + return node.getValue(); + } + + //////////////////////////////////////////////// + // Response + //////////////////////////////////////////////// + + public void setResponse(StateVariable stateVar) + { + String var = stateVar.getValue(); + + setStatusCode(HTTPStatus.OK); + + Node bodyNode = getBodyNode(); + Node resNode = createResponseNode(var); + bodyNode.addNode(resNode); + + Node envNodee = getEnvelopeNode(); + setContent(envNodee); + + } + + private Node createResponseNode(String var) + { + Node queryResNode = new Node(); + queryResNode.setName(Control.NS, Control.QUERY_STATE_VARIABLE_RESPONSE); + queryResNode.setNameSpace(Control.NS, Control.XMLNS); + + Node returnNode = new Node(); + returnNode.setName(Control.RETURN); + returnNode.setValue(var); + queryResNode.addNode(returnNode); + + return queryResNode; + } +} diff --git a/router/java/src/org/cybergarage/upnp/control/RenewSubscriber.java b/router/java/src/org/cybergarage/upnp/control/RenewSubscriber.java index 7b8d2e05907caf7372a34d72347871b5f58769d6..8741472f4a863e746c8d1277340b66d7730b6b63 100644 --- a/router/java/src/org/cybergarage/upnp/control/RenewSubscriber.java +++ b/router/java/src/org/cybergarage/upnp/control/RenewSubscriber.java @@ -1,65 +1,65 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: RenewSubscriber.java -* -* Revision: -* -* 07/07/04 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.control; - -import org.cybergarage.util.*; -import org.cybergarage.upnp.*; - -public class RenewSubscriber extends ThreadCore -{ - public final static long INTERVAL = 120; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public RenewSubscriber(ControlPoint ctrlp) - { - setControlPoint(ctrlp); - } - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private ControlPoint ctrlPoint; - - public void setControlPoint(ControlPoint ctrlp) - { - ctrlPoint = ctrlp; - } - - public ControlPoint getControlPoint() - { - return ctrlPoint; - } - - //////////////////////////////////////////////// - // Thread - //////////////////////////////////////////////// - - public void run() - { - ControlPoint ctrlp = getControlPoint(); - long renewInterval = INTERVAL * 1000; - while (isRunnable() == true) { - try { - Thread.sleep(renewInterval); - } catch (InterruptedException e) {} - ctrlp.renewSubscriberService(); - } - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: RenewSubscriber.java +* +* Revision: +* +* 07/07/04 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.control; + +import org.cybergarage.util.*; +import org.cybergarage.upnp.*; + +public class RenewSubscriber extends ThreadCore +{ + public final static long INTERVAL = 120; + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public RenewSubscriber(ControlPoint ctrlp) + { + setControlPoint(ctrlp); + } + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private ControlPoint ctrlPoint; + + public void setControlPoint(ControlPoint ctrlp) + { + ctrlPoint = ctrlp; + } + + public ControlPoint getControlPoint() + { + return ctrlPoint; + } + + //////////////////////////////////////////////// + // Thread + //////////////////////////////////////////////// + + public void run() + { + ControlPoint ctrlp = getControlPoint(); + long renewInterval = INTERVAL * 1000; + while (isRunnable() == true) { + try { + Thread.sleep(renewInterval); + } catch (InterruptedException e) {} + ctrlp.renewSubscriberService(); + } + } +} diff --git a/router/java/src/org/cybergarage/upnp/device/Advertiser.java b/router/java/src/org/cybergarage/upnp/device/Advertiser.java index 373fea82d93c55ff64223e6c15fd4d54cad28bfb..5be3e0bcbe239ebb62a4f2ad8b4b78fe27b38f6a 100644 --- a/router/java/src/org/cybergarage/upnp/device/Advertiser.java +++ b/router/java/src/org/cybergarage/upnp/device/Advertiser.java @@ -1,68 +1,68 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: Advertiser.java -* -* Revision; -* -* 12/24/03 -* - first revision. -* 06/18/04 -* - Changed to advertise every 25%-50% of the periodic notification cycle for NMPR; -* -******************************************************************/ - -package org.cybergarage.upnp.device; - -import org.cybergarage.util.*; -import org.cybergarage.upnp.*; - -public class Advertiser extends ThreadCore -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Advertiser(Device dev) - { - setDevice(dev); - } - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private Device device; - - public void setDevice(Device dev) - { - device = dev; - } - - public Device getDevice() - { - return device; - } - - //////////////////////////////////////////////// - // Thread - //////////////////////////////////////////////// - - public void run() - { - Device dev = getDevice(); - long leaseTime = dev.getLeaseTime(); - long notifyInterval; - while (isRunnable() == true) { - notifyInterval = (leaseTime/4) + (long)((float)leaseTime * (Math.random() * 0.25f)); - notifyInterval *= 1000; - try { - Thread.sleep(notifyInterval); - } catch (InterruptedException e) {} - dev.announce(); - } - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: Advertiser.java +* +* Revision; +* +* 12/24/03 +* - first revision. +* 06/18/04 +* - Changed to advertise every 25%-50% of the periodic notification cycle for NMPR; +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +import org.cybergarage.util.*; +import org.cybergarage.upnp.*; + +public class Advertiser extends ThreadCore +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Advertiser(Device dev) + { + setDevice(dev); + } + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private Device device; + + public void setDevice(Device dev) + { + device = dev; + } + + public Device getDevice() + { + return device; + } + + //////////////////////////////////////////////// + // Thread + //////////////////////////////////////////////// + + public void run() + { + Device dev = getDevice(); + long leaseTime = dev.getLeaseTime(); + long notifyInterval; + while (isRunnable() == true) { + notifyInterval = (leaseTime/4) + (long)((float)leaseTime * (Math.random() * 0.25f)); + notifyInterval *= 1000; + try { + Thread.sleep(notifyInterval); + } catch (InterruptedException e) {} + dev.announce(); + } + } +} diff --git a/router/java/src/org/cybergarage/upnp/device/Description.java b/router/java/src/org/cybergarage/upnp/device/Description.java index fe42dc5ea6a88210e0b90cda2894f0115ee288f7..fbf539291f28af774cfb3839a3c1bd2ba937d6b6 100644 --- a/router/java/src/org/cybergarage/upnp/device/Description.java +++ b/router/java/src/org/cybergarage/upnp/device/Description.java @@ -1,24 +1,24 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: MAN.java -* -* Revision; -* -* 12/30/02 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: MAN.java +* +* Revision; +* +* 12/30/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +public class Description +{ + public final static String LOADING_EXCEPTION = "Couldn't load a specified description file "; + public final static String NOROOT_EXCEPTION = "Couldn't find a root node"; + public final static String NOROOTDEVICE_EXCEPTION = "Couldn't find a root device node"; +} -package org.cybergarage.upnp.device; - -public class Description -{ - public final static String LOADING_EXCEPTION = "Couldn't load a specified description file "; - public final static String NOROOT_EXCEPTION = "Couldn't find a root node"; - public final static String NOROOTDEVICE_EXCEPTION = "Couldn't find a root device node"; -} - diff --git a/router/java/src/org/cybergarage/upnp/device/Disposer.java b/router/java/src/org/cybergarage/upnp/device/Disposer.java index e6c0ddb8e9ed3a0b9f28fcad76442bb2d6b297dc..4fa4f2a6e0f05883ace7804bb282d1eb38c34545 100644 --- a/router/java/src/org/cybergarage/upnp/device/Disposer.java +++ b/router/java/src/org/cybergarage/upnp/device/Disposer.java @@ -1,65 +1,65 @@ -/****************************************************************** -* -* CyberLink for Java -* -* Copyright (C) Satoshi Konno 2002-2004 -* -* File: Disposer.java -* -* Revision: -* -* 01/05/04 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.device; - -import org.cybergarage.upnp.*; -import org.cybergarage.util.*; - -public class Disposer extends ThreadCore -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Disposer(ControlPoint ctrlp) - { - setControlPoint(ctrlp); - } - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private ControlPoint ctrlPoint; - - public void setControlPoint(ControlPoint ctrlp) - { - ctrlPoint = ctrlp; - } - - public ControlPoint getControlPoint() - { - return ctrlPoint; - } - - //////////////////////////////////////////////// - // Thread - //////////////////////////////////////////////// - - public void run() - { - ControlPoint ctrlp = getControlPoint(); - long monitorInterval = ctrlp.getExpiredDeviceMonitoringInterval() * 1000; - - while (isRunnable() == true) { - try { - Thread.sleep(monitorInterval); - } catch (InterruptedException e) {} - ctrlp.removeExpiredDevices(); - //ctrlp.print(); - } - } -} +/****************************************************************** +* +* CyberLink for Java +* +* Copyright (C) Satoshi Konno 2002-2004 +* +* File: Disposer.java +* +* Revision: +* +* 01/05/04 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +import org.cybergarage.upnp.*; +import org.cybergarage.util.*; + +public class Disposer extends ThreadCore +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Disposer(ControlPoint ctrlp) + { + setControlPoint(ctrlp); + } + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private ControlPoint ctrlPoint; + + public void setControlPoint(ControlPoint ctrlp) + { + ctrlPoint = ctrlp; + } + + public ControlPoint getControlPoint() + { + return ctrlPoint; + } + + //////////////////////////////////////////////// + // Thread + //////////////////////////////////////////////// + + public void run() + { + ControlPoint ctrlp = getControlPoint(); + long monitorInterval = ctrlp.getExpiredDeviceMonitoringInterval() * 1000; + + while (isRunnable() == true) { + try { + Thread.sleep(monitorInterval); + } catch (InterruptedException e) {} + ctrlp.removeExpiredDevices(); + //ctrlp.print(); + } + } +} diff --git a/router/java/src/org/cybergarage/upnp/device/InvalidDescriptionException.java b/router/java/src/org/cybergarage/upnp/device/InvalidDescriptionException.java index 5145245895ad6831b845da44c58b0bf80618344a..03e24c7b94c93677ce290b83f37548d9cb569255 100644 --- a/router/java/src/org/cybergarage/upnp/device/InvalidDescriptionException.java +++ b/router/java/src/org/cybergarage/upnp/device/InvalidDescriptionException.java @@ -5,37 +5,37 @@ * Copyright (C) Satoshi Konno 2002 * * File: InvalidDescriptionException.java -* -* Revision; -* -* 12/26/02 -* - first revision. +* +* Revision; +* +* 12/26/02 +* - first revision. * ******************************************************************/ -package org.cybergarage.upnp.device; - -import java.io.*; - -public class InvalidDescriptionException extends Exception +package org.cybergarage.upnp.device; + +import java.io.*; + +public class InvalidDescriptionException extends Exception { - public InvalidDescriptionException() + public InvalidDescriptionException() { super(); } - public InvalidDescriptionException(String s) + public InvalidDescriptionException(String s) { super(s); } - - public InvalidDescriptionException(String s, File file) + + public InvalidDescriptionException(String s, File file) { super(s + " (" + file.toString() + ")"); } - - public InvalidDescriptionException(Exception e) + + public InvalidDescriptionException(Exception e) { super(e.getMessage()); } -} +} diff --git a/router/java/src/org/cybergarage/upnp/device/MAN.java b/router/java/src/org/cybergarage/upnp/device/MAN.java index 1e0093f743a5e988c8fce4c27b1a6f4da2849f7b..9f970e2c284c2ae692a862e971f1877f4b246c5e 100644 --- a/router/java/src/org/cybergarage/upnp/device/MAN.java +++ b/router/java/src/org/cybergarage/upnp/device/MAN.java @@ -1,31 +1,31 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: MAN.java -* -* Revision; -* -* 12/30/02 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: MAN.java +* +* Revision; +* +* 12/30/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +public class MAN +{ + public final static String DISCOVER = "ssdp:discover"; + + public final static boolean isDiscover(String value) + { + if (value == null) + return false; + if (value.equals(MAN.DISCOVER) == true) + return true; + return value.equals("\"" + MAN.DISCOVER + "\""); + } +} -package org.cybergarage.upnp.device; - -public class MAN -{ - public final static String DISCOVER = "ssdp:discover"; - - public final static boolean isDiscover(String value) - { - if (value == null) - return false; - if (value.equals(MAN.DISCOVER) == true) - return true; - return value.equals("\"" + MAN.DISCOVER + "\""); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/device/NT.java b/router/java/src/org/cybergarage/upnp/device/NT.java index 1acb0d49058e89b7cf22f776fbdf777794aa72f8..ce6e314fde7ad4f160f2fe63a0a51020eb9f1076 100644 --- a/router/java/src/org/cybergarage/upnp/device/NT.java +++ b/router/java/src/org/cybergarage/upnp/device/NT.java @@ -1,30 +1,30 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: NT.java -* -* Revision; -* -* 12/09/02 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: NT.java +* +* Revision; +* +* 12/09/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +public class NT +{ + public final static String ROOTDEVICE = "upnp:rootdevice"; + public final static String EVENT = "upnp:event"; + + public final static boolean isRootDevice(String ntValue) + { + if (ntValue == null) + return false; + return ntValue.startsWith(ROOTDEVICE); + } +} -package org.cybergarage.upnp.device; - -public class NT -{ - public final static String ROOTDEVICE = "upnp:rootdevice"; - public final static String EVENT = "upnp:event"; - - public final static boolean isRootDevice(String ntValue) - { - if (ntValue == null) - return false; - return ntValue.startsWith(ROOTDEVICE); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/device/NTS.java b/router/java/src/org/cybergarage/upnp/device/NTS.java index 7eab5f19cc21a8257472fbfd59e177a63edb2797..5132e0392449c965ac54f1d2860ab7697844dd85 100644 --- a/router/java/src/org/cybergarage/upnp/device/NTS.java +++ b/router/java/src/org/cybergarage/upnp/device/NTS.java @@ -1,38 +1,38 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: NTS.java -* -* Revision; -* -* 12/09/02 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: NTS.java +* +* Revision; +* +* 12/09/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +public class NTS +{ + public final static String ALIVE = "ssdp:alive"; + public final static String BYEBYE = "ssdp:byebye"; + public final static String PROPCHANGE = "upnp:propchange"; + + public final static boolean isAlive(String ntsValue) + { + if (ntsValue == null) + return false; + return ntsValue.startsWith(NTS.ALIVE); + } + + public final static boolean isByeBye(String ntsValue) + { + if (ntsValue == null) + return false; + return ntsValue.startsWith(NTS.BYEBYE); + } +} -package org.cybergarage.upnp.device; - -public class NTS -{ - public final static String ALIVE = "ssdp:alive"; - public final static String BYEBYE = "ssdp:byebye"; - public final static String PROPCHANGE = "upnp:propchange"; - - public final static boolean isAlive(String ntsValue) - { - if (ntsValue == null) - return false; - return ntsValue.startsWith(NTS.ALIVE); - } - - public final static boolean isByeBye(String ntsValue) - { - if (ntsValue == null) - return false; - return ntsValue.startsWith(NTS.BYEBYE); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/device/NotifyListener.java b/router/java/src/org/cybergarage/upnp/device/NotifyListener.java index bac853ea571a5716994e93933ed5765ec5f9dd2d..e5abcc5bacff8a8d6f3f37bfba7663101c5774b2 100644 --- a/router/java/src/org/cybergarage/upnp/device/NotifyListener.java +++ b/router/java/src/org/cybergarage/upnp/device/NotifyListener.java @@ -5,19 +5,19 @@ * Copyright (C) Satoshi Konno 2002 * * File: DeviceNotifyListener.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * ******************************************************************/ - -package org.cybergarage.upnp.device; - -import org.cybergarage.upnp.ssdp.*; - -public interface NotifyListener -{ - public void deviceNotifyReceived(SSDPPacket ssdpPacket); + +package org.cybergarage.upnp.device; + +import org.cybergarage.upnp.ssdp.*; + +public interface NotifyListener +{ + public void deviceNotifyReceived(SSDPPacket ssdpPacket); } diff --git a/router/java/src/org/cybergarage/upnp/device/PresentationListener.java b/router/java/src/org/cybergarage/upnp/device/PresentationListener.java new file mode 100644 index 0000000000000000000000000000000000000000..e0ab853aa6e8d8c1175477e6eecfb7ff50b1ef45 --- /dev/null +++ b/router/java/src/org/cybergarage/upnp/device/PresentationListener.java @@ -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); +} diff --git a/router/java/src/org/cybergarage/upnp/device/ST.java b/router/java/src/org/cybergarage/upnp/device/ST.java index dcbfaf8ce8c5560ec5a8fb6668fdf1ca04848281..e0ef91ebc8bb9705bb6cbba39c38a07d1a1bfb5c 100644 --- a/router/java/src/org/cybergarage/upnp/device/ST.java +++ b/router/java/src/org/cybergarage/upnp/device/ST.java @@ -1,71 +1,71 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 +/****************************************************************** * -* File: ST.java -* -* Revision; -* -* 01/07/03 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: ST.java +* +* Revision; +* +* 01/07/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +public class ST +{ + public final static String ALL_DEVICE = "ssdp:all"; + public final static String ROOT_DEVICE = "upnp:rootdevice"; + public final static String UUID_DEVICE = "uuid"; + public final static String URN_DEVICE = "urn:schemas-upnp-org:device:"; + public final static String URN_SERVICE = "urn:schemas-upnp-org:service:"; + + public final static boolean isAllDevice(String value) + { + if (value == null) + return false; + if (value.equals(ALL_DEVICE) == true) + return true; + return value.equals("\"" + ALL_DEVICE + "\""); + } + + public final static boolean isRootDevice(String value) + { + if (value == null) + return false; + if (value.equals(ROOT_DEVICE) == true) + return true; + return value.equals("\"" + ROOT_DEVICE + "\""); + } + + public final static boolean isUUIDDevice(String value) + { + if (value == null) + return false; + if (value.startsWith(UUID_DEVICE) == true) + return true; + return value.startsWith("\"" + UUID_DEVICE); + } + + public final static boolean isURNDevice(String value) + { + if (value == null) + return false; + if (value.startsWith(URN_DEVICE) == true) + return true; + return value.startsWith("\"" + URN_DEVICE); + } + + public final static boolean isURNService(String value) + { + if (value == null) + return false; + if (value.startsWith(URN_SERVICE) == true) + return true; + return value.startsWith("\"" + URN_SERVICE); + } +} -package org.cybergarage.upnp.device; - -public class ST -{ - public final static String ALL_DEVICE = "ssdp:all"; - public final static String ROOT_DEVICE = "upnp:rootdevice"; - public final static String UUID_DEVICE = "uuid"; - public final static String URN_DEVICE = "urn:schemas-upnp-org:device:"; - public final static String URN_SERVICE = "urn:schemas-upnp-org:service:"; - - public final static boolean isAllDevice(String value) - { - if (value == null) - return false; - if (value.equals(ALL_DEVICE) == true) - return true; - return value.equals("\"" + ALL_DEVICE + "\""); - } - - public final static boolean isRootDevice(String value) - { - if (value == null) - return false; - if (value.equals(ROOT_DEVICE) == true) - return true; - return value.equals("\"" + ROOT_DEVICE + "\""); - } - - public final static boolean isUUIDDevice(String value) - { - if (value == null) - return false; - if (value.startsWith(UUID_DEVICE) == true) - return true; - return value.startsWith("\"" + UUID_DEVICE); - } - - public final static boolean isURNDevice(String value) - { - if (value == null) - return false; - if (value.startsWith(URN_DEVICE) == true) - return true; - return value.startsWith("\"" + URN_DEVICE); - } - - public final static boolean isURNService(String value) - { - if (value == null) - return false; - if (value.startsWith(URN_SERVICE) == true) - return true; - return value.startsWith("\"" + URN_SERVICE); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/device/SearchListener.java b/router/java/src/org/cybergarage/upnp/device/SearchListener.java index 758a37c272c93219cfb3a302e61ab173506d4ba2..66702e36481184a083f85b1ef03a0c86d8862611 100644 --- a/router/java/src/org/cybergarage/upnp/device/SearchListener.java +++ b/router/java/src/org/cybergarage/upnp/device/SearchListener.java @@ -1,23 +1,23 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SearchListener.java -* -* Revision; -* -* 11/18/02b -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.device; - -import org.cybergarage.upnp.ssdp.*; - -public interface SearchListener -{ - public void deviceSearchReceived(SSDPPacket ssdpPacket); -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SearchListener.java +* +* Revision; +* +* 11/18/02b +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +import org.cybergarage.upnp.ssdp.*; + +public interface SearchListener +{ + public void deviceSearchReceived(SSDPPacket ssdpPacket); +} diff --git a/router/java/src/org/cybergarage/upnp/device/SearchResponseListener.java b/router/java/src/org/cybergarage/upnp/device/SearchResponseListener.java index c87c41a37a131f6e3b2e9eed3b9c6a50def12e6d..10c845de7ebd013d62c87974fd32ce20ec16c01a 100644 --- a/router/java/src/org/cybergarage/upnp/device/SearchResponseListener.java +++ b/router/java/src/org/cybergarage/upnp/device/SearchResponseListener.java @@ -1,23 +1,23 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SearchResponseListener.java -* -* Revision; -* -* 11/18/02 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.device; - -import org.cybergarage.upnp.ssdp.*; - -public interface SearchResponseListener -{ - public void deviceSearchResponseReceived(SSDPPacket ssdpPacket); -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SearchResponseListener.java +* +* Revision; +* +* 11/18/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +import org.cybergarage.upnp.ssdp.*; + +public interface SearchResponseListener +{ + public void deviceSearchResponseReceived(SSDPPacket ssdpPacket); +} diff --git a/router/java/src/org/cybergarage/upnp/device/USN.java b/router/java/src/org/cybergarage/upnp/device/USN.java index 74c704027b94c1a1e7cc73bebc963fc2532841ea..ded49a13f3275ea3c7bc6d1f373f10fd1283a480 100644 --- a/router/java/src/org/cybergarage/upnp/device/USN.java +++ b/router/java/src/org/cybergarage/upnp/device/USN.java @@ -1,40 +1,40 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: USN.java -* -* Revision; -* -* 12/09/02 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: USN.java +* +* Revision; +* +* 12/09/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.device; + +public class USN +{ + public final static String ROOTDEVICE = "upnp:rootdevice"; + + public final static boolean isRootDevice(String usnValue) + { + if (usnValue == null) + return false; + return usnValue.endsWith(ROOTDEVICE); + } + + public final static String getUDN(String usnValue) + { + if (usnValue == null) + return ""; + int idx = usnValue.indexOf("::"); + if (idx < 0) + return usnValue.trim(); + String udnValue = new String(usnValue.getBytes(), 0, idx); + return udnValue.trim(); + } +} -package org.cybergarage.upnp.device; - -public class USN -{ - public final static String ROOTDEVICE = "upnp:rootdevice"; - - public final static boolean isRootDevice(String usnValue) - { - if (usnValue == null) - return false; - return usnValue.endsWith(ROOTDEVICE); - } - - public final static String getUDN(String usnValue) - { - if (usnValue == null) - return ""; - int idx = usnValue.indexOf("::"); - if (idx < 0) - return usnValue.trim(); - String udnValue = new String(usnValue.getBytes(), 0, idx); - return udnValue.trim(); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/event/EventListener.java b/router/java/src/org/cybergarage/upnp/event/EventListener.java index 900b9307cfdde93165b55c30c116bd5f5f74be3d..782adb5b795731fb3d462e3e844141c580a8baea 100644 --- a/router/java/src/org/cybergarage/upnp/event/EventListener.java +++ b/router/java/src/org/cybergarage/upnp/event/EventListener.java @@ -1,21 +1,21 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: EventListener.java -* -* Revision; -* -* 11/18/02 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.event; - -public interface EventListener -{ - public void eventNotifyReceived(String uuid, long seq, String varName, String value); -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: EventListener.java +* +* Revision; +* +* 11/18/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.event; + +public interface EventListener +{ + public void eventNotifyReceived(String uuid, long seq, String varName, String value); +} diff --git a/router/java/src/org/cybergarage/upnp/event/NotifyRequest.java b/router/java/src/org/cybergarage/upnp/event/NotifyRequest.java index 14bae34e108a012422b4b12eb82e4a53557c7ea5..f35a14cf6018d09aeef5f7871bcda262f5a05dc8 100644 --- a/router/java/src/org/cybergarage/upnp/event/NotifyRequest.java +++ b/router/java/src/org/cybergarage/upnp/event/NotifyRequest.java @@ -1,201 +1,201 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SOAPRequest.java -* -* Revision; -* -* 12/11/02 -* - first revision. -* 05/22/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Description: removed the xml namespace -* - Problem : Notification messages refer to uncorrect variable names -* - Error : The NotifyRequest class introduces the XML namespace in variable names, too -* 05/22/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Problem : Notification messages refer to uncorrect variable names -* - Error : The NotifyRequest class introduces the XML namespace in variable names, too -* - Description : removed the xml namespace -* 09/03/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Problem : Notification messages refer to uncorrect variable names -* - Error : The NotifyRequest class introduces the XML namespace in variable names, too -* - Description: removed the xml namespace -* 09/08/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Problem : when an event notification message is received and the message -* contains updates on more than one variable, only the first variable update -* is notified. -* - Error : the other xml nodes of the message are ignored -* - Fix : add two methods to the NotifyRequest for extracting the property array -* and modify the httpRequestRecieved method in ControlPoint -* -******************************************************************/ - -package org.cybergarage.upnp.event; - -import org.cybergarage.http.*; -import org.cybergarage.xml.*; -import org.cybergarage.soap.*; - -import org.cybergarage.upnp.device.*; - -public class NotifyRequest extends SOAPRequest -{ - private final static String XMLNS = "e"; - private final static String PROPERTY = "property"; - private final static String PROPERTYSET = "propertyset"; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public NotifyRequest() - { - } - - public NotifyRequest(HTTPRequest httpReq) - { - set(httpReq); - } - - //////////////////////////////////////////////// - // NT - //////////////////////////////////////////////// - - public void setNT(String value) - { - setHeader(HTTP.NT, value); - } - - //////////////////////////////////////////////// - // NTS - //////////////////////////////////////////////// - - public void setNTS(String value) - { - setHeader(HTTP.NTS, value); - } - - //////////////////////////////////////////////// - // SID - //////////////////////////////////////////////// - - public void setSID(String id) - { - setHeader(HTTP.SID, Subscription.toSIDHeaderString(id)); - } - - public String getSID() - { - return Subscription.getSID(getHeaderValue(HTTP.SID)); - } - - //////////////////////////////////////////////// - // SEQ - //////////////////////////////////////////////// - - public void setSEQ(long value) - { - setHeader(HTTP.SEQ, Long.toString(value)); - } - - public long getSEQ() - { - return getLongHeaderValue(HTTP.SEQ); - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public boolean setRequest(Subscriber sub, String varName, String value) - { - String callback = sub.getDeliveryURL(); - String sid = sub.getSID(); - long notifyCnt = sub.getNotifyCount(); - String host = sub.getDeliveryHost(); - String path = sub.getDeliveryPath(); - int port = sub.getDeliveryPort(); - - setMethod(HTTP.NOTIFY); - setURI(path); - setHost(host, port); - setNT(NT.EVENT); - setNTS(NTS.PROPCHANGE); - setSID(sid); - setSEQ(notifyCnt); - - setContentType(XML.CONTENT_TYPE); - Node propSetNode = createPropertySetNode(varName, value); - setContent(propSetNode); - - return true; - } - - private Node createPropertySetNode(String varName, String value) - { - Node propSetNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTYSET); - - propSetNode.setNameSpace(XMLNS, Subscription.XMLNS); - - Node propNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTY); - propSetNode.addNode(propNode); - - // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/22/03) - //Node varNameNode = new Node(XMLNS + SOAP.DELIM + varName); - Node varNameNode = new Node(varName); - varNameNode.setValue(value); - propNode.addNode(varNameNode); - - return propSetNode; - } - - private Node getVariableNode() - { - Node rootNode = getEnvelopeNode(); - if (rootNode == null) - return null; - if (rootNode.hasNodes() == false) - return null; - Node propNode = rootNode.getNode(0); - if (propNode.hasNodes() == false) - return null; - return propNode.getNode(0); - } - - // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03) - private Property getProperty(Node varNode) - { - Property prop = new Property(); - if (varNode == null) - return prop; - // remove the event namespace - String variableName = varNode.getName(); - int index = variableName.lastIndexOf(':'); - if (index != -1) - variableName = variableName.substring(index + 1); - prop.setName(variableName); - prop.setValue(varNode.getValue()); - return prop; - } - - // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03) - public PropertyList getPropertyList() { - PropertyList properties = new PropertyList(); - Node varSetNode = getEnvelopeNode(); - for (int i = 0; i<varSetNode.getNNodes(); i++){ - Node propNode = varSetNode.getNode(i); - if (propNode == null) - continue; - Property prop = getProperty(propNode.getNode(0)); - properties.add(prop); - } - return properties; - } - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SOAPRequest.java +* +* Revision; +* +* 12/11/02 +* - first revision. +* 05/22/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Description: removed the xml namespace +* - Problem : Notification messages refer to uncorrect variable names +* - Error : The NotifyRequest class introduces the XML namespace in variable names, too +* 05/22/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Problem : Notification messages refer to uncorrect variable names +* - Error : The NotifyRequest class introduces the XML namespace in variable names, too +* - Description : removed the xml namespace +* 09/03/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Problem : Notification messages refer to uncorrect variable names +* - Error : The NotifyRequest class introduces the XML namespace in variable names, too +* - Description: removed the xml namespace +* 09/08/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Problem : when an event notification message is received and the message +* contains updates on more than one variable, only the first variable update +* is notified. +* - Error : the other xml nodes of the message are ignored +* - Fix : add two methods to the NotifyRequest for extracting the property array +* and modify the httpRequestRecieved method in ControlPoint +* +******************************************************************/ + +package org.cybergarage.upnp.event; + +import org.cybergarage.http.*; +import org.cybergarage.xml.*; +import org.cybergarage.soap.*; + +import org.cybergarage.upnp.device.*; + +public class NotifyRequest extends SOAPRequest +{ + private final static String XMLNS = "e"; + private final static String PROPERTY = "property"; + private final static String PROPERTYSET = "propertyset"; + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public NotifyRequest() + { + } + + public NotifyRequest(HTTPRequest httpReq) + { + set(httpReq); + } + + //////////////////////////////////////////////// + // NT + //////////////////////////////////////////////// + + public void setNT(String value) + { + setHeader(HTTP.NT, value); + } + + //////////////////////////////////////////////// + // NTS + //////////////////////////////////////////////// + + public void setNTS(String value) + { + setHeader(HTTP.NTS, value); + } + + //////////////////////////////////////////////// + // SID + //////////////////////////////////////////////// + + public void setSID(String id) + { + setHeader(HTTP.SID, Subscription.toSIDHeaderString(id)); + } + + public String getSID() + { + return Subscription.getSID(getHeaderValue(HTTP.SID)); + } + + //////////////////////////////////////////////// + // SEQ + //////////////////////////////////////////////// + + public void setSEQ(long value) + { + setHeader(HTTP.SEQ, Long.toString(value)); + } + + public long getSEQ() + { + return getLongHeaderValue(HTTP.SEQ); + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public boolean setRequest(Subscriber sub, String varName, String value) + { + String callback = sub.getDeliveryURL(); + String sid = sub.getSID(); + long notifyCnt = sub.getNotifyCount(); + String host = sub.getDeliveryHost(); + String path = sub.getDeliveryPath(); + int port = sub.getDeliveryPort(); + + setMethod(HTTP.NOTIFY); + setURI(path); + setHost(host, port); + setNT(NT.EVENT); + setNTS(NTS.PROPCHANGE); + setSID(sid); + setSEQ(notifyCnt); + + setContentType(XML.DEFAULT_CONTENT_TYPE); + Node propSetNode = createPropertySetNode(varName, value); + setContent(propSetNode); + + return true; + } + + private Node createPropertySetNode(String varName, String value) + { + Node propSetNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTYSET); + + propSetNode.setNameSpace(XMLNS, Subscription.XMLNS); + + Node propNode = new Node(/*XMLNS + SOAP.DELIM + */PROPERTY); + propSetNode.addNode(propNode); + + // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/22/03) + //Node varNameNode = new Node(XMLNS + SOAP.DELIM + varName); + Node varNameNode = new Node(varName); + varNameNode.setValue(value); + propNode.addNode(varNameNode); + + return propSetNode; + } + + private Node getVariableNode() + { + Node rootNode = getEnvelopeNode(); + if (rootNode == null) + return null; + if (rootNode.hasNodes() == false) + return null; + Node propNode = rootNode.getNode(0); + if (propNode.hasNodes() == false) + return null; + return propNode.getNode(0); + } + + // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03) + private Property getProperty(Node varNode) + { + Property prop = new Property(); + if (varNode == null) + return prop; + // remove the event namespace + String variableName = varNode.getName(); + int index = variableName.lastIndexOf(':'); + if (index != -1) + variableName = variableName.substring(index + 1); + prop.setName(variableName); + prop.setValue(varNode.getValue()); + return prop; + } + + // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/08/03) + public PropertyList getPropertyList() { + PropertyList properties = new PropertyList(); + Node varSetNode = getEnvelopeNode(); + for (int i = 0; i<varSetNode.getNNodes(); i++){ + Node propNode = varSetNode.getNode(i); + if (propNode == null) + continue; + Property prop = getProperty(propNode.getNode(0)); + properties.add(prop); + } + return properties; + } + } \ No newline at end of file diff --git a/router/java/src/org/cybergarage/upnp/event/Property.java b/router/java/src/org/cybergarage/upnp/event/Property.java index a9c6d67b68a48874d287787352427b86da2229e2..5e9f5b47d9918d8dbf837a258e16a5f686f969f5 100644 --- a/router/java/src/org/cybergarage/upnp/event/Property.java +++ b/router/java/src/org/cybergarage/upnp/event/Property.java @@ -1,65 +1,65 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: Subscriber.java -* -* Revision; -* -* 01/29/03 -* - first revision. -* 05/22/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Problem : the setName method does not set the name of the property -* - Error : the method contains a bug: -* 06/18/03 -* - Fixed a bug when a null value is received to the name and the value of property. -* -******************************************************************/ - -package org.cybergarage.upnp.event; - -public class Property -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Property() - { - } - - //////////////////////////////////////////////// - // name - //////////////////////////////////////////////// - - private String name = ""; - - public String getName() { - return name; - } - - public void setName(String val) { - if (val == null) - val = ""; - name = val; - } - - //////////////////////////////////////////////// - // value - //////////////////////////////////////////////// - - private String value = ""; - - public String getValue() { - return value; - } - - public void setValue(String val) { - if (val == null) - val = ""; - value = val; - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: Subscriber.java +* +* Revision; +* +* 01/29/03 +* - first revision. +* 05/22/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Problem : the setName method does not set the name of the property +* - Error : the method contains a bug: +* 06/18/03 +* - Fixed a bug when a null value is received to the name and the value of property. +* +******************************************************************/ + +package org.cybergarage.upnp.event; + +public class Property +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Property() + { + } + + //////////////////////////////////////////////// + // name + //////////////////////////////////////////////// + + private String name = ""; + + public String getName() { + return name; + } + + public void setName(String val) { + if (val == null) + val = ""; + name = val; + } + + //////////////////////////////////////////////// + // value + //////////////////////////////////////////////// + + private String value = ""; + + public String getValue() { + return value; + } + + public void setValue(String val) { + if (val == null) + val = ""; + value = val; + } +} diff --git a/router/java/src/org/cybergarage/upnp/event/PropertyList.java b/router/java/src/org/cybergarage/upnp/event/PropertyList.java index f2d8a22a7599ffb52c635506d01ac73c0b6239f1..da84bfe2f4e3b5250ada857b18b15c64aaacb6cf 100644 --- a/router/java/src/org/cybergarage/upnp/event/PropertyList.java +++ b/router/java/src/org/cybergarage/upnp/event/PropertyList.java @@ -1,45 +1,45 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: PropertyList.java -* -* Revision; -* -* 09/08/03 -* - first revision. -* -******************************************************************/ +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: PropertyList.java +* +* Revision; +* +* 09/08/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.event; + +import java.util.*; + +public class PropertyList extends Vector +{ + //////////////////////////////////////////////// + // 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 -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "PropertyList"; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public PropertyList() - { - } - - //////////////////////////////////////////////// - // Methods - //////////////////////////////////////////////// - - public Property getProperty(int n) - { - return (Property)get(n); - } -} - diff --git a/router/java/src/org/cybergarage/upnp/event/Subscriber.java b/router/java/src/org/cybergarage/upnp/event/Subscriber.java index 8ade71c721938aa464b32e154ead68a130883704..ccfe75db7ff520d0d3095c6b9751fab60d01ed90 100644 --- a/router/java/src/org/cybergarage/upnp/event/Subscriber.java +++ b/router/java/src/org/cybergarage/upnp/event/Subscriber.java @@ -1,180 +1,180 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: Subscriber.java -* -* Revision; -* -* 01/29/03 -* - first revision. -* 07/31/04 -* - Added isExpired(). -* 10/26/04 -* - Oliver Newell <newell@media-rush.com> -* - Added support the intinite time and fixed a bug in isExpired(). -* -******************************************************************/ - -package org.cybergarage.upnp.event; - -import java.net.*; - -public class Subscriber -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Subscriber() - { - renew(); - } - - //////////////////////////////////////////////// - // SID - //////////////////////////////////////////////// - - private String SID = null; - - public String getSID() { - return SID; - } - - public void setSID(String sid) { - SID = sid; - } - - //////////////////////////////////////////////// - // deliveryURL - //////////////////////////////////////////////// - - private String ifAddr = ""; - - public void setInterfaceAddress(String addr) - { - ifAddr = addr; - } - - public String getInterfaceAddress() - { - return ifAddr; - } - - //////////////////////////////////////////////// - // deliveryURL - //////////////////////////////////////////////// - - private String deliveryURL = ""; - - public String getDeliveryURL() { - return deliveryURL; - } - - public void setDeliveryURL(String deliveryURL) { - this.deliveryURL = deliveryURL; - try { - URL url = new URL(deliveryURL); - deliveryHost = url.getHost(); - deliveryPath = url.getPath(); - deliveryPort = url.getPort(); - } - catch (Exception e) {} - } - - private String deliveryHost = ""; - private String deliveryPath = ""; - private int deliveryPort = 0; - - public String getDeliveryHost() { - return deliveryHost; - } - - public String getDeliveryPath() { - return deliveryPath; - } - - public int getDeliveryPort() { - return deliveryPort; - } - - - //////////////////////////////////////////////// - // Timeout - //////////////////////////////////////////////// - - private long timeOut = 0; - - public long getTimeOut() { - return timeOut; - } - - public void setTimeOut(long value) { - timeOut = value; - } - - public boolean isExpired() - { - long currTime = System.currentTimeMillis(); - - // Thanks for Oliver Newell (10/26/04) - if(timeOut == Subscription.INFINITE_VALUE ) - return false; - - // Thanks for Oliver Newell (10/26/04) - long expiredTime = getSubscriptionTime() + getTimeOut()*1000; - if (expiredTime < currTime) - return true; - - return false; - } - - //////////////////////////////////////////////// - // SubscriptionTIme - //////////////////////////////////////////////// - - private long subscriptionTime = 0; - - public long getSubscriptionTime() { - return subscriptionTime; - } - - public void setSubscriptionTime(long time) { - subscriptionTime = time; - } - - //////////////////////////////////////////////// - // SEQ - //////////////////////////////////////////////// - - private long notifyCount = 0; - - public long getNotifyCount() { - return notifyCount; - } - - public void setNotifyCount(int cnt) { - notifyCount = cnt; - } - - public void incrementNotifyCount() { - if (notifyCount == Long.MAX_VALUE) { - notifyCount = 1; - return; - } - notifyCount++; - } - - //////////////////////////////////////////////// - // renew - //////////////////////////////////////////////// - - public void renew() - { - setSubscriptionTime(System.currentTimeMillis()); - setNotifyCount(0); - } - -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: Subscriber.java +* +* Revision; +* +* 01/29/03 +* - first revision. +* 07/31/04 +* - Added isExpired(). +* 10/26/04 +* - Oliver Newell <newell@media-rush.com> +* - Added support the intinite time and fixed a bug in isExpired(). +* +******************************************************************/ + +package org.cybergarage.upnp.event; + +import java.net.*; + +public class Subscriber +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Subscriber() + { + renew(); + } + + //////////////////////////////////////////////// + // SID + //////////////////////////////////////////////// + + private String SID = null; + + public String getSID() { + return SID; + } + + public void setSID(String sid) { + SID = sid; + } + + //////////////////////////////////////////////// + // deliveryURL + //////////////////////////////////////////////// + + private String ifAddr = ""; + + public void setInterfaceAddress(String addr) + { + ifAddr = addr; + } + + public String getInterfaceAddress() + { + return ifAddr; + } + + //////////////////////////////////////////////// + // deliveryURL + //////////////////////////////////////////////// + + private String deliveryURL = ""; + + public String getDeliveryURL() { + return deliveryURL; + } + + public void setDeliveryURL(String deliveryURL) { + this.deliveryURL = deliveryURL; + try { + URL url = new URL(deliveryURL); + deliveryHost = url.getHost(); + deliveryPath = url.getPath(); + deliveryPort = url.getPort(); + } + catch (Exception e) {} + } + + private String deliveryHost = ""; + private String deliveryPath = ""; + private int deliveryPort = 0; + + public String getDeliveryHost() { + return deliveryHost; + } + + public String getDeliveryPath() { + return deliveryPath; + } + + public int getDeliveryPort() { + return deliveryPort; + } + + + //////////////////////////////////////////////// + // Timeout + //////////////////////////////////////////////// + + private long timeOut = 0; + + public long getTimeOut() { + return timeOut; + } + + public void setTimeOut(long value) { + timeOut = value; + } + + public boolean isExpired() + { + long currTime = System.currentTimeMillis(); + + // Thanks for Oliver Newell (10/26/04) + if(timeOut == Subscription.INFINITE_VALUE ) + return false; + + // Thanks for Oliver Newell (10/26/04) + long expiredTime = getSubscriptionTime() + getTimeOut()*1000; + if (expiredTime < currTime) + return true; + + return false; + } + + //////////////////////////////////////////////// + // SubscriptionTIme + //////////////////////////////////////////////// + + private long subscriptionTime = 0; + + public long getSubscriptionTime() { + return subscriptionTime; + } + + public void setSubscriptionTime(long time) { + subscriptionTime = time; + } + + //////////////////////////////////////////////// + // SEQ + //////////////////////////////////////////////// + + private long notifyCount = 0; + + public long getNotifyCount() { + return notifyCount; + } + + public void setNotifyCount(int cnt) { + notifyCount = cnt; + } + + public void incrementNotifyCount() { + if (notifyCount == Long.MAX_VALUE) { + notifyCount = 1; + return; + } + notifyCount++; + } + + //////////////////////////////////////////////// + // renew + //////////////////////////////////////////////// + + public void renew() + { + setSubscriptionTime(System.currentTimeMillis()); + setNotifyCount(0); + } + +} diff --git a/router/java/src/org/cybergarage/upnp/event/SubscriberList.java b/router/java/src/org/cybergarage/upnp/event/SubscriberList.java index 63bfdb7865a459c8db73b45b11e54f169be93671..53b8c0e2d34218fbd5e1ee5a99e6210cf65c9df7 100644 --- a/router/java/src/org/cybergarage/upnp/event/SubscriberList.java +++ b/router/java/src/org/cybergarage/upnp/event/SubscriberList.java @@ -1,46 +1,46 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SubscriberList.java -* -* Revision; -* -* 01/31/03 -* - first revision. -* 06/18/03 -* - Fixed to catch ArrayIndexOutOfBounds. -* -******************************************************************/ - -package org.cybergarage.upnp.event; - -import java.util.*; - -public class SubscriberList extends Vector -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SubscriberList() - { - } - - //////////////////////////////////////////////// - // Methods - //////////////////////////////////////////////// - - public Subscriber getSubscriber(int n) - { - Object obj = null; - try { - obj = get(n); - } - catch (Exception e) {} - return (Subscriber)obj; - } -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SubscriberList.java +* +* Revision; +* +* 01/31/03 +* - first revision. +* 06/18/03 +* - Fixed to catch ArrayIndexOutOfBounds. +* +******************************************************************/ + +package org.cybergarage.upnp.event; + +import java.util.*; + +public class SubscriberList extends Vector +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SubscriberList() + { + } + + //////////////////////////////////////////////// + // Methods + //////////////////////////////////////////////// + + public Subscriber getSubscriber(int n) + { + Object obj = null; + try { + obj = get(n); + } + catch (Exception e) {} + return (Subscriber)obj; + } +} + diff --git a/router/java/src/org/cybergarage/upnp/event/Subscription.java b/router/java/src/org/cybergarage/upnp/event/Subscription.java index 0685e4fa8b7fae8766d97c729a7b6007696c3c32..488ac75abfabc481b5d494b4a934119de12aa124 100644 --- a/router/java/src/org/cybergarage/upnp/event/Subscription.java +++ b/router/java/src/org/cybergarage/upnp/event/Subscription.java @@ -1,77 +1,77 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: ST.java -* -* Revision; -* -* 01/31/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.event; - -import org.cybergarage.upnp.*; - -public class Subscription -{ - public final static String XMLNS = "urn:schemas-upnp-org:event-1-0"; - public final static String TIMEOUT_HEADER = "Second-"; - public final static String INFINITE_STRING = "infinite"; - public final static int INFINITE_VALUE = -1; - public final static String UUID = "uuid:"; - public final static String SUBSCRIBE_METHOD = "SUBSCRIBE"; - public final static String UNSUBSCRIBE_METHOD = "UNSUBSCRIBE"; - - //////////////////////////////////////////////// - // Timeout - //////////////////////////////////////////////// - - public final static String toTimeoutHeaderString(long time) - { - if (time == Subscription.INFINITE_VALUE) - return Subscription.INFINITE_STRING; - return Subscription.TIMEOUT_HEADER + Long.toString(time); - } - - public final static long getTimeout(String headerValue) - { - int minusIdx = headerValue.indexOf('-'); - long timeout = Subscription.INFINITE_VALUE; - try { - String timeoutStr = headerValue.substring(minusIdx+1, headerValue.length()); - timeout = Long.parseLong(timeoutStr); - } - catch (Exception e) {} - return timeout; - } - - //////////////////////////////////////////////// - // SID - //////////////////////////////////////////////// - - public static final String createSID() - { - return UPnP.createUUID(); - } - - public final static String toSIDHeaderString(String id) - { - return Subscription.UUID + id; - } - - public final static String getSID(String headerValue) - { - if (headerValue == null) - return ""; - if (headerValue.startsWith(Subscription.UUID) == false) - return headerValue; - return headerValue.substring(Subscription.UUID.length(), headerValue.length()); - } - -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: ST.java +* +* Revision; +* +* 01/31/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.event; + +import org.cybergarage.upnp.*; + +public class Subscription +{ + public final static String XMLNS = "urn:schemas-upnp-org:event-1-0"; + public final static String TIMEOUT_HEADER = "Second-"; + public final static String INFINITE_STRING = "infinite"; + public final static int INFINITE_VALUE = -1; + public final static String UUID = "uuid:"; + public final static String SUBSCRIBE_METHOD = "SUBSCRIBE"; + public final static String UNSUBSCRIBE_METHOD = "UNSUBSCRIBE"; + + //////////////////////////////////////////////// + // Timeout + //////////////////////////////////////////////// + + public final static String toTimeoutHeaderString(long time) + { + if (time == Subscription.INFINITE_VALUE) + return Subscription.INFINITE_STRING; + return Subscription.TIMEOUT_HEADER + Long.toString(time); + } + + public final static long getTimeout(String headerValue) + { + int minusIdx = headerValue.indexOf('-'); + long timeout = Subscription.INFINITE_VALUE; + try { + String timeoutStr = headerValue.substring(minusIdx+1, headerValue.length()); + timeout = Long.parseLong(timeoutStr); + } + catch (Exception e) {} + return timeout; + } + + //////////////////////////////////////////////// + // SID + //////////////////////////////////////////////// + + public static final String createSID() + { + return UPnP.createUUID(); + } + + public final static String toSIDHeaderString(String id) + { + return Subscription.UUID + id; + } + + public final static String getSID(String headerValue) + { + if (headerValue == null) + return ""; + if (headerValue.startsWith(Subscription.UUID) == false) + return headerValue; + return headerValue.substring(Subscription.UUID.length(), headerValue.length()); + } + +} + diff --git a/router/java/src/org/cybergarage/upnp/event/SubscriptionRequest.java b/router/java/src/org/cybergarage/upnp/event/SubscriptionRequest.java index 4ba930c12c63efb46b9f01173f7bb1b32392513d..9f35d67599d6be937c016665d7bb91c3c918ce01 100644 --- a/router/java/src/org/cybergarage/upnp/event/SubscriptionRequest.java +++ b/router/java/src/org/cybergarage/upnp/event/SubscriptionRequest.java @@ -1,221 +1,221 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SubscriptionRequest.java -* -* Revision; -* -* 01/31/03 -* - first revision. -* 05/21/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Description: inserted a check at the beginning of the setService method -* - Problem : If the EventSubURL does not start with a '/', the device could refuse event subscription -* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices -* 09/02/03 -* - Giordano Sassaroli <sassarol@cefriel.it> -* - Problem : NullpointerException thrown for devices whose description use absolute urls -* - Error : the presence of a base url is not mandatory, the API code makes the assumption that control and event subscription urls are relative. If the baseUrl is not present, the request host and port should be extracted from the control/subscription url -* - Description: The method setRequestHost/setService should be changed as follows -* 06/11/04 -* - Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004) -* - Changed setServie() to get the host address from the SSDP Location field when the URLBase is null. -* 12/06/04 -* - Grzegorz Lehmann <grzegorz.lehmann@dai-labor.de> -* - Stefano Lenzi <kismet-sl@users.sourceforge.net> -* - Fixed getSID() to loop between getSID() and hasSID(); -* -********************************************************************/ - -package org.cybergarage.upnp.event; - -import org.cybergarage.http.*; - -import org.cybergarage.upnp.*; -import org.cybergarage.upnp.device.*; - -public class SubscriptionRequest extends HTTPRequest -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SubscriptionRequest(){ - setContentLength(0); - } - - public SubscriptionRequest(HTTPRequest httpReq){ - this(); - set(httpReq); - } - - //////////////////////////////////////////////// - // setRequest - //////////////////////////////////////////////// - - private void setService(Service service) - { - String eventSubURL = service.getEventSubURL(); - - // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03) - setURI(eventSubURL, true); - - String urlBaseStr = ""; - Device dev = service.getDevice(); - if (dev != null) - urlBaseStr = dev.getURLBase(); - - if (urlBaseStr == null || urlBaseStr.length() <= 0) { - Device rootDev = service.getRootDevice(); - if (rootDev != null) - urlBaseStr = rootDev.getURLBase(); - } - - // Thansk for Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004) - if (urlBaseStr == null || urlBaseStr.length() <= 0) { - Device rootDev = service.getRootDevice(); - if (rootDev != null) - urlBaseStr = rootDev.getLocation(); - } - - // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03) - if (urlBaseStr == null || urlBaseStr.length() <= 0) { - if (HTTP.isAbsoluteURL(eventSubURL)) - urlBaseStr = eventSubURL; - } - - String reqHost = HTTP.getHost(urlBaseStr); - int reqPort = HTTP.getPort(urlBaseStr); - - setHost(reqHost, reqPort); - setRequestHost(reqHost); - setRequestPort(reqPort); - } - - public void setSubscribeRequest(Service service, String callback, long timeout) - { - setMethod(Subscription.SUBSCRIBE_METHOD); - setService(service); - setCallback(callback); - setNT(NT.EVENT); - setTimeout(timeout); - } - - public void setRenewRequest(Service service, String uuid, long timeout) - { - setMethod(Subscription.SUBSCRIBE_METHOD); - setService(service); - setSID(uuid); - setTimeout(timeout); - } - - public void setUnsubscribeRequest(Service service) - { - setMethod(Subscription.UNSUBSCRIBE_METHOD); - setService(service); - setSID(service.getSID()); - } - - //////////////////////////////////////////////// - // NT - //////////////////////////////////////////////// - - public void setNT(String value) - { - setHeader(HTTP.NT, value); - } - - public String getNT() - { - return getHeaderValue(HTTP.NT); - } - - public boolean hasNT() - { - String nt = getNT(); - return (nt != null && 0 < nt.length()) ? true : false; - } - - //////////////////////////////////////////////// - // CALLBACK - //////////////////////////////////////////////// - - private final static String CALLBACK_START_WITH = "<"; - private final static String CALLBACK_END_WITH = ">"; - - public void setCallback(String value) - { - setStringHeader(HTTP.CALLBACK, value, CALLBACK_START_WITH, CALLBACK_END_WITH); - } - - public String getCallback() - { - return getStringHeaderValue(HTTP.CALLBACK, CALLBACK_START_WITH, CALLBACK_END_WITH); - } - - public boolean hasCallback() - { - String callback = getCallback(); - return (callback != null && 0 < callback.length()) ? true : false; - } - - //////////////////////////////////////////////// - // SID - //////////////////////////////////////////////// - - public void setSID(String id) - { - setHeader(HTTP.SID, Subscription.toSIDHeaderString(id)); - } - - public String getSID() - { - // Thanks for Grzegorz Lehmann and Stefano Lenzi(12/06/04) - String sid = Subscription.getSID(getHeaderValue(HTTP.SID)); - if (sid == null) - return ""; - return sid; - } - - public boolean hasSID() - { - String sid = getSID(); - return (sid != null && 0 < sid.length()) ? true : false; - } - - //////////////////////////////////////////////// - // Timeout - //////////////////////////////////////////////// - - public final void setTimeout(long value) - { - setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value)); - } - - public long getTimeout() - { - return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT)); - } - - //////////////////////////////////////////////// - // post (Response) - //////////////////////////////////////////////// - - public void post(SubscriptionResponse subRes) - { - super.post(subRes); - } - - //////////////////////////////////////////////// - // post - //////////////////////////////////////////////// - - public SubscriptionResponse post() - { - HTTPResponse httpRes = post(getRequestHost(), getRequestPort()); - return new SubscriptionResponse(httpRes); - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SubscriptionRequest.java +* +* Revision; +* +* 01/31/03 +* - first revision. +* 05/21/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Description: inserted a check at the beginning of the setService method +* - Problem : If the EventSubURL does not start with a '/', the device could refuse event subscription +* - Error : it is not an error, but adding the '/' when missing allows the integration with the Intel devices +* 09/02/03 +* - Giordano Sassaroli <sassarol@cefriel.it> +* - Problem : NullpointerException thrown for devices whose description use absolute urls +* - Error : the presence of a base url is not mandatory, the API code makes the assumption that control and event subscription urls are relative. If the baseUrl is not present, the request host and port should be extracted from the control/subscription url +* - Description: The method setRequestHost/setService should be changed as follows +* 06/11/04 +* - Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004) +* - Changed setServie() to get the host address from the SSDP Location field when the URLBase is null. +* 12/06/04 +* - Grzegorz Lehmann <grzegorz.lehmann@dai-labor.de> +* - Stefano Lenzi <kismet-sl@users.sourceforge.net> +* - Fixed getSID() to loop between getSID() and hasSID(); +* +********************************************************************/ + +package org.cybergarage.upnp.event; + +import org.cybergarage.http.*; + +import org.cybergarage.upnp.*; +import org.cybergarage.upnp.device.*; + +public class SubscriptionRequest extends HTTPRequest +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SubscriptionRequest(){ + setContentLength(0); + } + + public SubscriptionRequest(HTTPRequest httpReq){ + this(); + set(httpReq); + } + + //////////////////////////////////////////////// + // setRequest + //////////////////////////////////////////////// + + private void setService(Service service) + { + String eventSubURL = service.getEventSubURL(); + + // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (05/21/03) + setURI(eventSubURL, true); + + String urlBaseStr = ""; + Device dev = service.getDevice(); + if (dev != null) + urlBaseStr = dev.getURLBase(); + + if (urlBaseStr == null || urlBaseStr.length() <= 0) { + Device rootDev = service.getRootDevice(); + if (rootDev != null) + urlBaseStr = rootDev.getURLBase(); + } + + // Thansk for Markus Thurner <markus.thurner@fh-hagenberg.at> (06/11/2004) + if (urlBaseStr == null || urlBaseStr.length() <= 0) { + Device rootDev = service.getRootDevice(); + if (rootDev != null) + urlBaseStr = rootDev.getLocation(); + } + + // Thanks for Giordano Sassaroli <sassarol@cefriel.it> (09/02/03) + if (urlBaseStr == null || urlBaseStr.length() <= 0) { + if (HTTP.isAbsoluteURL(eventSubURL)) + urlBaseStr = eventSubURL; + } + + String reqHost = HTTP.getHost(urlBaseStr); + int reqPort = HTTP.getPort(urlBaseStr); + + setHost(reqHost, reqPort); + setRequestHost(reqHost); + setRequestPort(reqPort); + } + + public void setSubscribeRequest(Service service, String callback, long timeout) + { + setMethod(Subscription.SUBSCRIBE_METHOD); + setService(service); + setCallback(callback); + setNT(NT.EVENT); + setTimeout(timeout); + } + + public void setRenewRequest(Service service, String uuid, long timeout) + { + setMethod(Subscription.SUBSCRIBE_METHOD); + setService(service); + setSID(uuid); + setTimeout(timeout); + } + + public void setUnsubscribeRequest(Service service) + { + setMethod(Subscription.UNSUBSCRIBE_METHOD); + setService(service); + setSID(service.getSID()); + } + + //////////////////////////////////////////////// + // NT + //////////////////////////////////////////////// + + public void setNT(String value) + { + setHeader(HTTP.NT, value); + } + + public String getNT() + { + return getHeaderValue(HTTP.NT); + } + + public boolean hasNT() + { + String nt = getNT(); + return (nt != null && 0 < nt.length()) ? true : false; + } + + //////////////////////////////////////////////// + // CALLBACK + //////////////////////////////////////////////// + + private final static String CALLBACK_START_WITH = "<"; + private final static String CALLBACK_END_WITH = ">"; + + public void setCallback(String value) + { + setStringHeader(HTTP.CALLBACK, value, CALLBACK_START_WITH, CALLBACK_END_WITH); + } + + public String getCallback() + { + return getStringHeaderValue(HTTP.CALLBACK, CALLBACK_START_WITH, CALLBACK_END_WITH); + } + + public boolean hasCallback() + { + String callback = getCallback(); + return (callback != null && 0 < callback.length()) ? true : false; + } + + //////////////////////////////////////////////// + // SID + //////////////////////////////////////////////// + + public void setSID(String id) + { + setHeader(HTTP.SID, Subscription.toSIDHeaderString(id)); + } + + public String getSID() + { + // Thanks for Grzegorz Lehmann and Stefano Lenzi(12/06/04) + String sid = Subscription.getSID(getHeaderValue(HTTP.SID)); + if (sid == null) + return ""; + return sid; + } + + public boolean hasSID() + { + String sid = getSID(); + return (sid != null && 0 < sid.length()) ? true : false; + } + + //////////////////////////////////////////////// + // Timeout + //////////////////////////////////////////////// + + public final void setTimeout(long value) + { + setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value)); + } + + public long getTimeout() + { + return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT)); + } + + //////////////////////////////////////////////// + // post (Response) + //////////////////////////////////////////////// + + public void post(SubscriptionResponse subRes) + { + super.post(subRes); + } + + //////////////////////////////////////////////// + // post + //////////////////////////////////////////////// + + public SubscriptionResponse post() + { + HTTPResponse httpRes = post(getRequestHost(), getRequestPort()); + return new SubscriptionResponse(httpRes); + } +} diff --git a/router/java/src/org/cybergarage/upnp/event/SubscriptionResponse.java b/router/java/src/org/cybergarage/upnp/event/SubscriptionResponse.java index cf60ecd56286b9e1d3e7fa2d3182b00a909e8037..ef736f77a5c610454754cb15a6fc5a6be444be9f 100644 --- a/router/java/src/org/cybergarage/upnp/event/SubscriptionResponse.java +++ b/router/java/src/org/cybergarage/upnp/event/SubscriptionResponse.java @@ -1,84 +1,84 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SubscriptionResponse.java -* -* Revision; -* -* 01/29/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.event; - -import org.cybergarage.upnp.*; -import org.cybergarage.http.*; - -public class SubscriptionResponse extends HTTPResponse -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SubscriptionResponse() - { - setServer(UPnP.getServerName()); - } - - public SubscriptionResponse(HTTPResponse httpRes) - { - super(httpRes); - } - - //////////////////////////////////////////////// - // Error - //////////////////////////////////////////////// - - public void setResponse(int code) - { - setStatusCode(code); - setContentLength(0); - } - - //////////////////////////////////////////////// - // Error - //////////////////////////////////////////////// - - public void setErrorResponse(int code) - { - setStatusCode(code); - setContentLength(0); - } - - //////////////////////////////////////////////// - // SID - //////////////////////////////////////////////// - - public void setSID(String id) - { - setHeader(HTTP.SID, Subscription.toSIDHeaderString(id)); - } - - public String getSID() - { - return Subscription.getSID(getHeaderValue(HTTP.SID)); - } - - //////////////////////////////////////////////// - // Timeout - //////////////////////////////////////////////// - - public void setTimeout(long value) - { - setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value)); - } - - public long getTimeout() - { - return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT)); - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SubscriptionResponse.java +* +* Revision; +* +* 01/29/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.event; + +import org.cybergarage.upnp.*; +import org.cybergarage.http.*; + +public class SubscriptionResponse extends HTTPResponse +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SubscriptionResponse() + { + setServer(UPnP.getServerName()); + } + + public SubscriptionResponse(HTTPResponse httpRes) + { + super(httpRes); + } + + //////////////////////////////////////////////// + // Error + //////////////////////////////////////////////// + + public void setResponse(int code) + { + setStatusCode(code); + setContentLength(0); + } + + //////////////////////////////////////////////// + // Error + //////////////////////////////////////////////// + + public void setErrorResponse(int code) + { + setStatusCode(code); + setContentLength(0); + } + + //////////////////////////////////////////////// + // SID + //////////////////////////////////////////////// + + public void setSID(String id) + { + setHeader(HTTP.SID, Subscription.toSIDHeaderString(id)); + } + + public String getSID() + { + return Subscription.getSID(getHeaderValue(HTTP.SID)); + } + + //////////////////////////////////////////////// + // Timeout + //////////////////////////////////////////////// + + public void setTimeout(long value) + { + setHeader(HTTP.TIMEOUT, Subscription.toTimeoutHeaderString(value)); + } + + public long getTimeout() + { + return Subscription.getTimeout(getHeaderValue(HTTP.TIMEOUT)); + } +} diff --git a/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java b/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java index 57c60d0099db39c3132e6bede355a3fae24a0143..d92b1f7da7e9768afc09f70ff285aec510f3c644 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/HTTPMUSocket.java @@ -22,7 +22,7 @@ * 08/23/07 * - Thanks for Kazuyuki Shudo * - Changed receive() to throw IOException. -* 01/10/08 +* 01/10/08 * - Changed getLocalAddress() to return a brank string when the ssdpMultiGroup or ssdpMultiIf is null on Android m3-rc37a. * ******************************************************************/ diff --git a/router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java b/router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java index 78b4711d4d3e414fcf6859b32c29f246467d7c23..f26984f12327e8b2915e58779475654c89757917 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/HTTPUSocket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: HTTPMU.java -* -* Revision; -* -* 11/20/02 -* - first revision. +* +* Revision; +* +* 11/20/02 +* - first revision. * 12/12/03 * - Inma Mar?n <inma@DIF.UM.ES> * - Changed open(addr, port) to send IPv6 SSDP packets. @@ -20,49 +20,49 @@ * - Added to set a current timestamp when the packet are received. * ******************************************************************/ - -package org.cybergarage.upnp.ssdp; - + +package org.cybergarage.upnp.ssdp; + import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.InetSocketAddress; import org.cybergarage.util.Debug; - -public class HTTPUSocket -{ - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private DatagramSocket ssdpUniSock = null; + +public class HTTPUSocket +{ + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private DatagramSocket ssdpUniSock = null; //private MulticastSocket ssdpUniSock = null; - - public DatagramSocket getDatagramSocket() - { - return ssdpUniSock; - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPUSocket() + + public DatagramSocket getDatagramSocket() + { + return ssdpUniSock; + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPUSocket() { open(); - } - - public HTTPUSocket(String bindAddr, int bindPort) + } + + public HTTPUSocket(String bindAddr, int bindPort) { open(bindAddr, bindPort); - } + } public HTTPUSocket(int bindPort) { open(bindPort); } - + protected void finalize() { close(); @@ -166,66 +166,66 @@ public class HTTPUSocket return true; } - //////////////////////////////////////////////// - // close - //////////////////////////////////////////////// - - public boolean close() - { - if (ssdpUniSock == null) - return true; - - try { + //////////////////////////////////////////////// + // close + //////////////////////////////////////////////// + + public boolean close() + { + if (ssdpUniSock == null) + return true; + + try { ssdpUniSock.close(); - ssdpUniSock = null; - } - catch (Exception e) { - Debug.warning(e); - return false; - } - - return true; - } + ssdpUniSock = null; + } + catch (Exception e) { + Debug.warning(e); + return false; + } + + return true; + } + + //////////////////////////////////////////////// + // send + //////////////////////////////////////////////// - //////////////////////////////////////////////// - // 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); + 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("addr = " +ssdpUniSock.getLocalAddress().getHostName()); Debug.warning("port = " + ssdpUniSock.getLocalPort()); - Debug.warning(e); - return false; - } - return true; - } - - //////////////////////////////////////////////// - // reveive - //////////////////////////////////////////////// - - public SSDPPacket receive() - { - byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE]; - SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length); + Debug.warning(e); + return false; + } + return true; + } + + //////////////////////////////////////////////// + // reveive + //////////////////////////////////////////////// + + public SSDPPacket receive() + { + byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE]; + SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length); recvPacket.setLocalAddress(getLocalAddress()); - try { - ssdpUniSock.receive(recvPacket.getDatagramPacket()); + try { + ssdpUniSock.receive(recvPacket.getDatagramPacket()); recvPacket.setTimeStamp(System.currentTimeMillis()); - } - catch (Exception e) { + } + catch (Exception e) { //Debug.warning(e); - return null; - } - return recvPacket; - } + return null; + } + return recvPacket; + } //////////////////////////////////////////////// // join/leave @@ -260,5 +260,5 @@ public class HTTPUSocket return true; } */ -} - +} + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifyRequest.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifyRequest.java index 1df63ff6c6704c3593f1a03758cfd4c4dc22ddd4..e92f9133fd3afe9f5b40a399d22d0ddd23f655b5 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifyRequest.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifyRequest.java @@ -1,31 +1,31 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SSDPMSearchRequest.java -* -* Revision; -* -* 01/14/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.ssdp; - -import org.cybergarage.http.HTTP; - -public class SSDPNotifyRequest extends SSDPRequest -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SSDPNotifyRequest() - { - setMethod(HTTP.NOTIFY); - setURI("*"); - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SSDPMSearchRequest.java +* +* Revision; +* +* 01/14/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.ssdp; + +import org.cybergarage.http.HTTP; + +public class SSDPNotifyRequest extends SSDPRequest +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SSDPNotifyRequest() + { + setMethod(HTTP.NOTIFY); + setURI("*"); + } +} diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java index d2e0f2770566a632f222363193163785cb75f1ab..e198818f23448591241ed5635d397dae11ce747f 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: SSDPPacket.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 05/13/03 * - Added getLocalAddress(). * 11/01/04 @@ -20,25 +20,25 @@ * - Changed getRemoteAddress() to return the adresss instead of the host name. * ******************************************************************/ - -package org.cybergarage.upnp.ssdp; - -import java.net.*; - + +package org.cybergarage.upnp.ssdp; + +import java.net.*; + import org.cybergarage.http.*; -import org.cybergarage.upnp.device.*; - -public class SSDPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SSDPPacket(byte[] buf, int length) - { - dgmPacket = new DatagramPacket(buf, length); - } +import org.cybergarage.upnp.device.*; + +public class SSDPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SSDPPacket(byte[] buf, int length) + { + dgmPacket = new DatagramPacket(buf, length); + } //////////////////////////////////////////////// // DatagramPacket @@ -68,115 +68,115 @@ public class SSDPPacket } - //////////////////////////////////////////////// - // Time - //////////////////////////////////////////////// - - private long timeStamp; - - public void setTimeStamp(long value) - { - timeStamp = value; - } - - public long getTimeStamp() - { - return timeStamp; - } - - //////////////////////////////////////////////// - // Remote host - //////////////////////////////////////////////// + //////////////////////////////////////////////// + // Time + //////////////////////////////////////////////// + + private long timeStamp; + + public void setTimeStamp(long value) + { + timeStamp = value; + } + + public long getTimeStamp() + { + return timeStamp; + } + + //////////////////////////////////////////////// + // Remote host + //////////////////////////////////////////////// public InetAddress getRemoteInetAddress() { return getDatagramPacket().getAddress(); } - public String getRemoteAddress() - { + public String getRemoteAddress() + { // Thanks for Theo Beisch (11/09/04) - return getDatagramPacket().getAddress().getHostAddress(); - } - - public int getRemotePort() - { - return getDatagramPacket().getPort(); - } - - //////////////////////////////////////////////// - // Access Methods - //////////////////////////////////////////////// - - public byte[] packetBytes = null; - - public byte[] getData() - { - if (packetBytes != null) - return packetBytes; - - DatagramPacket packet = getDatagramPacket(); - int packetLen = packet.getLength(); - String packetData = new String(packet.getData(), 0, packetLen); - packetBytes = packetData.getBytes(); - - return packetBytes; - } - - //////////////////////////////////////////////// - // Access Methods - //////////////////////////////////////////////// - - public String getHost() - { - return HTTPHeader.getValue(getData(), HTTP.HOST); - } - - public String getCacheControl() - { - return HTTPHeader.getValue(getData(), HTTP.CACHE_CONTROL); - } - - public String getLocation() - { - return HTTPHeader.getValue(getData(), HTTP.LOCATION); - } - - public String getMAN() - { - return HTTPHeader.getValue(getData(), HTTP.MAN); - } + return getDatagramPacket().getAddress().getHostAddress(); + } + + public int getRemotePort() + { + return getDatagramPacket().getPort(); + } + + //////////////////////////////////////////////// + // Access Methods + //////////////////////////////////////////////// + + public byte[] packetBytes = null; + + public byte[] getData() + { + if (packetBytes != null) + return packetBytes; + + DatagramPacket packet = getDatagramPacket(); + int packetLen = packet.getLength(); + String packetData = new String(packet.getData(), 0, packetLen); + packetBytes = packetData.getBytes(); + + return packetBytes; + } + + //////////////////////////////////////////////// + // Access Methods + //////////////////////////////////////////////// + + public String getHost() + { + return HTTPHeader.getValue(getData(), HTTP.HOST); + } + + public String getCacheControl() + { + return HTTPHeader.getValue(getData(), HTTP.CACHE_CONTROL); + } + + public String getLocation() + { + return HTTPHeader.getValue(getData(), HTTP.LOCATION); + } + + public String getMAN() + { + return HTTPHeader.getValue(getData(), HTTP.MAN); + } public String getST() { return HTTPHeader.getValue(getData(), HTTP.ST); } - - public String getNT() - { - return HTTPHeader.getValue(getData(), HTTP.NT); - } - - public String getNTS() - { - return HTTPHeader.getValue(getData(), HTTP.NTS); - } - - public String getServer() - { - return HTTPHeader.getValue(getData(), HTTP.SERVER); - } - - public String getUSN() - { - return HTTPHeader.getValue(getData(), HTTP.USN); - } - - public int getMX() - { - return HTTPHeader.getIntegerValue(getData(), HTTP.MX); - } - + + public String getNT() + { + return HTTPHeader.getValue(getData(), HTTP.NT); + } + + public String getNTS() + { + return HTTPHeader.getValue(getData(), HTTP.NTS); + } + + public String getServer() + { + return HTTPHeader.getValue(getData(), HTTP.SERVER); + } + + public String getUSN() + { + return HTTPHeader.getValue(getData(), HTTP.USN); + } + + public int getMX() + { + return HTTPHeader.getIntegerValue(getData(), HTTP.MX); + } + //////////////////////////////////////////////// // Access Methods //////////////////////////////////////////////// @@ -197,39 +197,39 @@ public class SSDPPacket return isockaddr.getAddress(); } - //////////////////////////////////////////////// - // Access Methods (Extension) - //////////////////////////////////////////////// - - public boolean isRootDevice() - { - if (NT.isRootDevice(getNT()) == true) + //////////////////////////////////////////////// + // Access Methods (Extension) + //////////////////////////////////////////////// + + public boolean isRootDevice() + { + if (NT.isRootDevice(getNT()) == true) return true; - // Thanks for Theo Beisch (11/01/04) + // Thanks for Theo Beisch (11/01/04) if (ST.isRootDevice(getST()) == true) return true; - return USN.isRootDevice(getUSN()); - } - - public boolean isDiscover() - { - return MAN.isDiscover(getMAN()); - } - - public boolean isAlive() - { - return NTS.isAlive(getNTS()); - } - - public boolean isByeBye() - { - return NTS.isByeBye(getNTS()); - } - - public int getLeaseTime() - { - return SSDP.getLeaseTime(getCacheControl()); - } + return USN.isRootDevice(getUSN()); + } + + public boolean isDiscover() + { + return MAN.isDiscover(getMAN()); + } + + public boolean isAlive() + { + return NTS.isAlive(getNTS()); + } + + public boolean isByeBye() + { + return NTS.isByeBye(getNTS()); + } + + public int getLeaseTime() + { + return SSDP.getLeaseTime(getCacheControl()); + } //////////////////////////////////////////////// // toString @@ -240,4 +240,4 @@ public class SSDPPacket return new String(getData()); } } - + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPRequest.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPRequest.java index 17d6eaceaecfcc82dc34b264f26c9e9561c5da08..ca93d6f35b74c856b5e8e0a4d81e4311eb1f328e 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPRequest.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPRequest.java @@ -1,111 +1,125 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SSDPRequest.java -* -* Revision; -* -* 01/14/03 -* - first revision. -* 03/16/04 -* - Thanks for Darrell Young -* - Fixed to set v1.1 to the HTTP version.; -* -******************************************************************/ - -package org.cybergarage.upnp.ssdp; - -import java.io.InputStream; - -import org.cybergarage.http.*; - -public class SSDPRequest extends HTTPRequest -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SSDPRequest() - { - setVersion(HTTP.VERSION_11); - } - - public SSDPRequest(InputStream in) - { - super(in); - } - - //////////////////////////////////////////////// - // NT - //////////////////////////////////////////////// - - public void setNT(String value) - { - setHeader(HTTP.NT, value); - } - - public String getNT() - { - return getHeaderValue(HTTP.NT); - } - - //////////////////////////////////////////////// - // NTS - //////////////////////////////////////////////// - - public void setNTS(String value) - { - setHeader(HTTP.NTS, value); - } - - public String getNTS() - { - return getHeaderValue(HTTP.NTS); - } - - //////////////////////////////////////////////// - // Location - //////////////////////////////////////////////// - - public void setLocation(String value) - { - setHeader(HTTP.LOCATION, value); - } - - public String getLocation() - { - return getHeaderValue(HTTP.LOCATION); - } - - //////////////////////////////////////////////// - // USN - //////////////////////////////////////////////// - - public void setUSN(String value) - { - setHeader(HTTP.USN, value); - } - - public String getUSN() - { - return getHeaderValue(HTTP.USN); - } - - //////////////////////////////////////////////// - // CacheControl - //////////////////////////////////////////////// - - public void setLeaseTime(int len) - { - setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len)); - } - - public int getLeaseTime() - { - String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL); - return SSDP.getLeaseTime(cacheCtrl); - } -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SSDPRequest.java +* +* Revision; +* +* 01/14/03 +* - first revision. +* 03/16/04 +* - Thanks for Darrell Young +* - Fixed to set v1.1 to the HTTP version.; +* +******************************************************************/ + +package org.cybergarage.upnp.ssdp; + +import java.io.InputStream; + +import org.cybergarage.http.*; + +public class SSDPRequest extends HTTPRequest +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SSDPRequest() + { + setVersion(HTTP.VERSION_11); + } + + public SSDPRequest(InputStream in) + { + super(in); + } + + //////////////////////////////////////////////// + // NT + //////////////////////////////////////////////// + + public void setNT(String value) + { + setHeader(HTTP.NT, value); + } + + public String getNT() + { + return getHeaderValue(HTTP.NT); + } + + //////////////////////////////////////////////// + // NTS + //////////////////////////////////////////////// + + public void setNTS(String value) + { + setHeader(HTTP.NTS, value); + } + + public String getNTS() + { + return getHeaderValue(HTTP.NTS); + } + + //////////////////////////////////////////////// + // Location + //////////////////////////////////////////////// + + public void setLocation(String value) + { + setHeader(HTTP.LOCATION, value); + } + + public String getLocation() + { + return getHeaderValue(HTTP.LOCATION); + } + + //////////////////////////////////////////////// + // USN + //////////////////////////////////////////////// + + public void setUSN(String value) + { + setHeader(HTTP.USN, value); + } + + public String getUSN() + { + return getHeaderValue(HTTP.USN); + } + + //////////////////////////////////////////////// + // CacheControl + //////////////////////////////////////////////// + + public void setLeaseTime(int len) + { + setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len)); + } + + public int getLeaseTime() + { + String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL); + return SSDP.getLeaseTime(cacheCtrl); + } + + //////////////////////////////////////////////// + // BootId + //////////////////////////////////////////////// + + public void setBootId(int bootId) + { + setHeader(HTTP.BOOTID_UPNP_ORG, bootId); + } + + public int getBootId() + { + return getIntegerHeaderValue(HTTP.BOOTID_UPNP_ORG); + } +} diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java index fd96ed7c636799454cbef6091b7d164937b8c8fe..bdb85155601be7ae8170d4ca078c9e7acc20a52b 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java @@ -1,133 +1,147 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002 -* -* File: SSDPResponse.java -* -* Revision; -* -* 01/14/03 -* - first revision. -* 01/23/04 -* - Oliver Newell -* - Overided HTTPResponse::getHeader() for Intel UPnP control points. -* 03/16/04 -* - Thanks for Darrell Young -* - Fixed to set v1.1 to the HTTP version. -* 10/20/04 -* - Brent Hills <bhills@openshores.com> -* - Added setMYNAME() and getMYNAME(). -* -******************************************************************/ - -package org.cybergarage.upnp.ssdp; - -import java.io.InputStream; - -import org.cybergarage.http.*; - -public class SSDPResponse extends HTTPResponse -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SSDPResponse() - { - setVersion(HTTP.VERSION_11); - } - - public SSDPResponse(InputStream in) - { - super(in); - } - - //////////////////////////////////////////////// - // ST (SearchTarget) - //////////////////////////////////////////////// - - public void setST(String value) - { - setHeader(HTTP.ST, value); - } - - public String getST() - { - return getHeaderValue(HTTP.ST); - } - - //////////////////////////////////////////////// - // Location - //////////////////////////////////////////////// - - public void setLocation(String value) - { - setHeader(HTTP.LOCATION, value); - } - - public String getLocation() - { - return getHeaderValue(HTTP.LOCATION); - } - - //////////////////////////////////////////////// - // USN - //////////////////////////////////////////////// - - public void setUSN(String value) - { - setHeader(HTTP.USN, value); - } - - public String getUSN() - { - return getHeaderValue(HTTP.USN); - } - - //////////////////////////////////////////////// - // MYNAME - //////////////////////////////////////////////// - - public void setMYNAME(String value) - { - setHeader(HTTP.MYNAME, value); - } - - public String getMYNAME() - { - return getHeaderValue(HTTP.MYNAME); - } - - //////////////////////////////////////////////// - // CacheControl - //////////////////////////////////////////////// - - public void setLeaseTime(int len) - { - setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len)); - } - - public int getLeaseTime() - { - String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL); - return SSDP.getLeaseTime(cacheCtrl); - } - - //////////////////////////////////////////////// - // getHeader (Override) - //////////////////////////////////////////////// - - public String getHeader() - { - StringBuffer str = new StringBuffer(); - - str.append(getStatusLineString()); - str.append(getHeaderString()); - str.append(HTTP.CRLF); // for Intel UPnP control points. - - return str.toString(); - } - -} +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: SSDPResponse.java +* +* Revision; +* +* 01/14/03 +* - first revision. +* 01/23/04 +* - Oliver Newell +* - Overided HTTPResponse::getHeader() for Intel UPnP control points. +* 03/16/04 +* - Thanks for Darrell Young +* - Fixed to set v1.1 to the HTTP version. +* 10/20/04 +* - Brent Hills <bhills@openshores.com> +* - Added setMYNAME() and getMYNAME(). +* +******************************************************************/ + +package org.cybergarage.upnp.ssdp; + +import java.io.InputStream; + +import org.cybergarage.http.*; + +public class SSDPResponse extends HTTPResponse +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SSDPResponse() + { + setVersion(HTTP.VERSION_11); + } + + public SSDPResponse(InputStream in) + { + super(in); + } + + //////////////////////////////////////////////// + // ST (SearchTarget) + //////////////////////////////////////////////// + + public void setST(String value) + { + setHeader(HTTP.ST, value); + } + + public String getST() + { + return getHeaderValue(HTTP.ST); + } + + //////////////////////////////////////////////// + // Location + //////////////////////////////////////////////// + + public void setLocation(String value) + { + setHeader(HTTP.LOCATION, value); + } + + public String getLocation() + { + return getHeaderValue(HTTP.LOCATION); + } + + //////////////////////////////////////////////// + // USN + //////////////////////////////////////////////// + + public void setUSN(String value) + { + setHeader(HTTP.USN, value); + } + + public String getUSN() + { + return getHeaderValue(HTTP.USN); + } + + //////////////////////////////////////////////// + // MYNAME + //////////////////////////////////////////////// + + public void setMYNAME(String value) + { + setHeader(HTTP.MYNAME, value); + } + + public String getMYNAME() + { + return getHeaderValue(HTTP.MYNAME); + } + + //////////////////////////////////////////////// + // CacheControl + //////////////////////////////////////////////// + + public void setLeaseTime(int len) + { + setHeader(HTTP.CACHE_CONTROL, "max-age=" + Integer.toString(len)); + } + + public int getLeaseTime() + { + String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL); + return SSDP.getLeaseTime(cacheCtrl); + } + + //////////////////////////////////////////////// + // BootId + //////////////////////////////////////////////// + + public void setBootId(int bootId) + { + setHeader(HTTP.BOOTID_UPNP_ORG, bootId); + } + + public int getBootId() + { + return getIntegerHeaderValue(HTTP.BOOTID_UPNP_ORG); + } + + //////////////////////////////////////////////// + // getHeader (Override) + //////////////////////////////////////////////// + + public String getHeader() + { + StringBuffer str = new StringBuffer(); + + str.append(getStatusLineString()); + str.append(getHeaderString()); + str.append(HTTP.CRLF); // for Intel UPnP control points. + + return str.toString(); + } + +} diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchRequest.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchRequest.java index fbe7cf8123276a3c7a92d9584b044137ec02dabc..8f4478c3e8321a923c41ce4e32d816084907dc07 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchRequest.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchRequest.java @@ -5,26 +5,26 @@ * Copyright (C) Satoshi Konno 2002 * * File: SSDPMSearchRequest.java -* -* Revision; -* -* 11/19/02 -* - first revision. +* +* Revision; +* +* 11/19/02 +* - first revision. * ******************************************************************/ - -package org.cybergarage.upnp.ssdp; - + +package org.cybergarage.upnp.ssdp; + import org.cybergarage.net.*; import org.cybergarage.http.*; - + import org.cybergarage.upnp.device.*; - -public class SSDPSearchRequest extends SSDPRequest -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// + +public class SSDPSearchRequest extends SSDPRequest +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// public SSDPSearchRequest(String serachTarget, int mx) { @@ -35,16 +35,16 @@ public class SSDPSearchRequest extends SSDPRequest setHeader(HTTP.MX, Integer.toString(mx)); setHeader(HTTP.MAN, "\"" + MAN.DISCOVER + "\""); } - - public SSDPSearchRequest(String serachTarget) + + public SSDPSearchRequest(String serachTarget) { - this(serachTarget, SSDP.DEFAULT_MSEARCH_MX); - } - - public SSDPSearchRequest() + this(serachTarget, SSDP.DEFAULT_MSEARCH_MX); + } + + public SSDPSearchRequest() { - this(ST.ROOT_DEVICE); - } + this(ST.ROOT_DEVICE); + } //////////////////////////////////////////////// // HOST diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchResponse.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchResponse.java index 264f5442918ac192776590f23a26f112775937ce..a237fa5801767bbd8efe754e09e046f10cecf99c 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchResponse.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchResponse.java @@ -5,31 +5,31 @@ * Copyright (C) Satoshi Konno 2002 * * File: SSDPSearchResponse.java -* -* Revision; -* -* 01/14/03 -* - first revision. +* +* Revision; +* +* 01/14/03 +* - first revision. * ******************************************************************/ - -package org.cybergarage.upnp.ssdp; - + +package org.cybergarage.upnp.ssdp; + import org.cybergarage.http.*; -import org.cybergarage.upnp.*; - -public class SSDPSearchResponse extends SSDPResponse -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SSDPSearchResponse() - { - setStatusCode(HTTPStatus.OK); - setCacheControl(Device.DEFAULT_LEASE_TIME); - setHeader(HTTP.SERVER, UPnP.getServerName()); - setHeader(HTTP.EXT, ""); - } +import org.cybergarage.upnp.*; + +public class SSDPSearchResponse extends SSDPResponse +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SSDPSearchResponse() + { + setStatusCode(HTTPStatus.OK); + setCacheControl(Device.DEFAULT_LEASE_TIME); + setHeader(HTTP.SERVER, UPnP.getServerName()); + setHeader(HTTP.EXT, ""); + } } diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchSocket.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchSocket.java index 204ff84fe3e87a09e72af00c837ec620d76dffca..cb227f2f6836d1d2f7a07332f4641cd0c6c4ec75 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchSocket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchSocket.java @@ -21,7 +21,7 @@ * 08/23/07 * - Thanks for Kazuyuki Shudo * - Changed run() to catch IOException of HTTPMUSocket::receive(). -* 01/10/08 +* 01/10/08 * - Changed start() not to abort when the interface infomation is null on Android m3-rc37a. * ******************************************************************/ diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchSocketList.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchSocketList.java index 185bb15fcc14499a212a68d2f624719d65388390..ed0691367dfb0e45f38c028286df9227f06a55e0 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchSocketList.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPSearchSocketList.java @@ -61,9 +61,6 @@ public class SSDPSearchSocketList extends Vector this.multicastIPv6 = multicastIPv6; } - - - //////////////////////////////////////////////// // Methods //////////////////////////////////////////////// diff --git a/router/java/src/org/cybergarage/upnp/xml/ActionData.java b/router/java/src/org/cybergarage/upnp/xml/ActionData.java index 4982f408842e7541ef214637cfed1cdfc749fe1f..c232a2e4ed09036688ad635172c37db86929a9b2 100644 --- a/router/java/src/org/cybergarage/upnp/xml/ActionData.java +++ b/router/java/src/org/cybergarage/upnp/xml/ActionData.java @@ -1,57 +1,57 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: ActionData.java -* -* Revision; -* -* 03/28/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.xml; - -import org.cybergarage.upnp.control.*; - -public class ActionData extends NodeData -{ - public ActionData() - { - } - - //////////////////////////////////////////////// - // ActionListener - //////////////////////////////////////////////// - - private ActionListener actionListener = null; - - public ActionListener getActionListener() { - return actionListener; - } - - public void setActionListener(ActionListener actionListener) { - this.actionListener = actionListener; - } - - //////////////////////////////////////////////// - // ControlResponse - //////////////////////////////////////////////// - - private ControlResponse ctrlRes = null; - - public ControlResponse getControlResponse() - { - return ctrlRes; - } - - public void setControlResponse(ControlResponse res) - { - ctrlRes = res; - } - -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: ActionData.java +* +* Revision; +* +* 03/28/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.xml; + +import org.cybergarage.upnp.control.*; + +public class ActionData extends NodeData +{ + public ActionData() + { + } + + //////////////////////////////////////////////// + // ActionListener + //////////////////////////////////////////////// + + private ActionListener actionListener = null; + + public ActionListener getActionListener() { + return actionListener; + } + + public void setActionListener(ActionListener actionListener) { + this.actionListener = actionListener; + } + + //////////////////////////////////////////////// + // ControlResponse + //////////////////////////////////////////////// + + private ControlResponse ctrlRes = null; + + public ControlResponse getControlResponse() + { + return ctrlRes; + } + + public void setControlResponse(ControlResponse res) + { + ctrlRes = res; + } + +} + diff --git a/router/java/src/org/cybergarage/upnp/xml/DeviceData.java b/router/java/src/org/cybergarage/upnp/xml/DeviceData.java index 8ed1f443e300e45c4391cb1895823211454501e7..5204da61b7dfb0ff813f561ecb6f5c714a0b0aba 100644 --- a/router/java/src/org/cybergarage/upnp/xml/DeviceData.java +++ b/router/java/src/org/cybergarage/upnp/xml/DeviceData.java @@ -1,271 +1,271 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: DeviceData.java -* -* Revision; -* -* 03/28/03 -* - first revision. -* 12/25/03 -* - Added Advertiser functions. -* -******************************************************************/ - -package org.cybergarage.upnp.xml; - -import java.io.*; -import java.net.InetAddress; - -import org.cybergarage.util.*; -import org.cybergarage.http.*; - -import org.cybergarage.upnp.*; -import org.cybergarage.upnp.ssdp.*; -import org.cybergarage.upnp.device.*; - -public class DeviceData extends NodeData -{ - public DeviceData() - { - } - - //////////////////////////////////////////////// - // description - //////////////////////////////////////////////// - - private String descriptionURI = null; - private File descriptionFile = null; - - public File getDescriptionFile() { - return descriptionFile; - } - - public String getDescriptionURI() { - return descriptionURI; - } - - public void setDescriptionFile(File descriptionFile) { - this.descriptionFile = descriptionFile; - } - - public void setDescriptionURI(String descriptionURI) { - this.descriptionURI = descriptionURI; - } - - //////////////////////////////////////////////// - // description - //////////////////////////////////////////////// - - private String location = ""; - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } - - //////////////////////////////////////////////// - // LeaseTime - //////////////////////////////////////////////// - - private int leaseTime = Device.DEFAULT_LEASE_TIME; - - public int getLeaseTime() - { - return leaseTime; - } - - public void setLeaseTime(int val) - { - leaseTime = val; - } - - //////////////////////////////////////////////// - // HTTPServer - //////////////////////////////////////////////// - - private HTTPServerList httpServerList = null; - - public HTTPServerList getHTTPServerList() { - if(this.httpServerList==null){ - this.httpServerList = new HTTPServerList(this.httpBinds,this.httpPort); - } - return this.httpServerList; - } - - private InetAddress[] httpBinds = null; - - public void setHTTPBindAddress(InetAddress[] inets){ - this.httpBinds=inets; - } - - public InetAddress[] getHTTPBindAddress(){ - return this.httpBinds; - } - - //////////////////////////////////////////////// - // httpPort - //////////////////////////////////////////////// - - private int httpPort = Device.HTTP_DEFAULT_PORT; - - public int getHTTPPort() { - return httpPort; - } - - public void setHTTPPort(int port) { - httpPort = port; - } - - //////////////////////////////////////////////// - // controlActionListenerList - //////////////////////////////////////////////// - - private ListenerList controlActionListenerList = new ListenerList(); - - public ListenerList getControlActionListenerList() { - return controlActionListenerList; - } - -/* - public void setControlActionListenerList(ListenerList controlActionListenerList) { - this.controlActionListenerList = controlActionListenerList; - } -*/ - - //////////////////////////////////////////////// - // SSDPSearchSocket - //////////////////////////////////////////////// - - private SSDPSearchSocketList ssdpSearchSocketList = null; - private String ssdpMulticastIPv4 = SSDP.ADDRESS; - private String ssdpMulticastIPv6 = SSDP.getIPv6Address(); - private int ssdpPort = SSDP.PORT; - private InetAddress[] ssdpBinds = null; - - public SSDPSearchSocketList getSSDPSearchSocketList() { - if(this.ssdpSearchSocketList==null){ - this.ssdpSearchSocketList = new SSDPSearchSocketList(this.ssdpBinds,ssdpPort,ssdpMulticastIPv4,ssdpMulticastIPv6); - } - return ssdpSearchSocketList; - } - - /** - * - * @param port The port to use for binding the SSDP service. - * The port will be used as source port for all SSDP messages - * @since 1.8 - */ - public void setSSDPPort(int port){ - this.ssdpPort=port; - } - - /** - * - * @return The port used for binding the SSDP service. - * The port will be used as source port for all SSDP messages - */ - public int getSSDPPort(){ - return this.ssdpPort; - } - - - /** - * - * @param inets The <tt>InetAddress</tt> that will be binded for listing this service. - * Use <code>null</code> for the default behaviur. - * @see {@link UPnP} - * @see {@link USSDP} - * @see {@link HostInterface} - * @since 1.8 - */ - public void setSSDPBindAddress(InetAddress[] inets){ - this.ssdpBinds=inets; - } - - /** - * - * @return inets The <tt>InetAddress</tt> that will be binded for this service - * <code>null</code> means that defulat behaviur will be used - * @since 1.8 - */ - public InetAddress[] getSSDPBindAddress(){ - return this.ssdpBinds; - } - - /** - * - * @param ip The IPv4 address used as destination address for Multicast comunication - * @since 1.8 - */ - public void setMulticastIPv4Address(String ip){ - this.ssdpMulticastIPv4=ip; - } - - /** - * - * @return The IPv4 address used for Multicast comunication - */ - public String getMulticastIPv4Address(){ - return this.ssdpMulticastIPv4; - } - - /** - * - * @param ip The IPv6 address used as destination address for Multicast comunication - * @since 1.8 - */ - public void setMulticastIPv6Address(String ip){ - this.ssdpMulticastIPv6=ip; - } - - /** - * - * @return The IPv6 address used as destination address for Multicast comunication - * @since 1.8 - */ - public String getMulticastIPv6Address(){ - return this.ssdpMulticastIPv6; - } - - - - //////////////////////////////////////////////// - // SSDPPacket - //////////////////////////////////////////////// - - private SSDPPacket ssdpPacket = null; - - public SSDPPacket getSSDPPacket() { - return ssdpPacket; - } - - public void setSSDPPacket(SSDPPacket packet) { - ssdpPacket = packet; - } - - //////////////////////////////////////////////// - // Advertiser - //////////////////////////////////////////////// - - private Advertiser advertiser = null; - - public void setAdvertiser(Advertiser adv) - { - advertiser = adv; - } - - public Advertiser getAdvertiser() - { - return advertiser; - } - - -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: DeviceData.java +* +* Revision; +* +* 03/28/03 +* - first revision. +* 12/25/03 +* - Added Advertiser functions. +* +******************************************************************/ + +package org.cybergarage.upnp.xml; + +import java.io.*; +import java.net.InetAddress; + +import org.cybergarage.util.*; +import org.cybergarage.http.*; + +import org.cybergarage.upnp.*; +import org.cybergarage.upnp.ssdp.*; +import org.cybergarage.upnp.device.*; + +public class DeviceData extends NodeData +{ + public DeviceData() + { + } + + //////////////////////////////////////////////// + // description + //////////////////////////////////////////////// + + private String descriptionURI = null; + private File descriptionFile = null; + + public File getDescriptionFile() { + return descriptionFile; + } + + public String getDescriptionURI() { + return descriptionURI; + } + + public void setDescriptionFile(File descriptionFile) { + this.descriptionFile = descriptionFile; + } + + public void setDescriptionURI(String descriptionURI) { + this.descriptionURI = descriptionURI; + } + + //////////////////////////////////////////////// + // description + //////////////////////////////////////////////// + + private String location = ""; + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + //////////////////////////////////////////////// + // LeaseTime + //////////////////////////////////////////////// + + private int leaseTime = Device.DEFAULT_LEASE_TIME; + + public int getLeaseTime() + { + return leaseTime; + } + + public void setLeaseTime(int val) + { + leaseTime = val; + } + + //////////////////////////////////////////////// + // HTTPServer + //////////////////////////////////////////////// + + private HTTPServerList httpServerList = null; + + public HTTPServerList getHTTPServerList() { + if(this.httpServerList==null){ + this.httpServerList = new HTTPServerList(this.httpBinds,this.httpPort); + } + return this.httpServerList; + } + + private InetAddress[] httpBinds = null; + + public void setHTTPBindAddress(InetAddress[] inets){ + this.httpBinds=inets; + } + + public InetAddress[] getHTTPBindAddress(){ + return this.httpBinds; + } + + //////////////////////////////////////////////// + // httpPort + //////////////////////////////////////////////// + + private int httpPort = Device.HTTP_DEFAULT_PORT; + + public int getHTTPPort() { + return httpPort; + } + + public void setHTTPPort(int port) { + httpPort = port; + } + + //////////////////////////////////////////////// + // controlActionListenerList + //////////////////////////////////////////////// + + private ListenerList controlActionListenerList = new ListenerList(); + + public ListenerList getControlActionListenerList() { + return controlActionListenerList; + } + +/* + public void setControlActionListenerList(ListenerList controlActionListenerList) { + this.controlActionListenerList = controlActionListenerList; + } +*/ + + //////////////////////////////////////////////// + // SSDPSearchSocket + //////////////////////////////////////////////// + + private SSDPSearchSocketList ssdpSearchSocketList = null; + private String ssdpMulticastIPv4 = SSDP.ADDRESS; + private String ssdpMulticastIPv6 = SSDP.getIPv6Address(); + private int ssdpPort = SSDP.PORT; + private InetAddress[] ssdpBinds = null; + + public SSDPSearchSocketList getSSDPSearchSocketList() { + if(this.ssdpSearchSocketList==null){ + this.ssdpSearchSocketList = new SSDPSearchSocketList(this.ssdpBinds,ssdpPort,ssdpMulticastIPv4,ssdpMulticastIPv6); + } + return ssdpSearchSocketList; + } + + /** + * + * @param port The port to use for binding the SSDP service. + * The port will be used as source port for all SSDP messages + * @since 1.8 + */ + public void setSSDPPort(int port){ + this.ssdpPort=port; + } + + /** + * + * @return The port used for binding the SSDP service. + * The port will be used as source port for all SSDP messages + */ + public int getSSDPPort(){ + return this.ssdpPort; + } + + + /** + * + * @param inets The <tt>InetAddress</tt> that will be binded for listing this service. + * Use <code>null</code> for the default behaviur. + * @see {@link UPnP} + * @see {@link USSDP} + * @see {@link HostInterface} + * @since 1.8 + */ + public void setSSDPBindAddress(InetAddress[] inets){ + this.ssdpBinds=inets; + } + + /** + * + * @return inets The <tt>InetAddress</tt> that will be binded for this service + * <code>null</code> means that defulat behaviur will be used + * @since 1.8 + */ + public InetAddress[] getSSDPBindAddress(){ + return this.ssdpBinds; + } + + /** + * + * @param ip The IPv4 address used as destination address for Multicast comunication + * @since 1.8 + */ + public void setMulticastIPv4Address(String ip){ + this.ssdpMulticastIPv4=ip; + } + + /** + * + * @return The IPv4 address used for Multicast comunication + */ + public String getMulticastIPv4Address(){ + return this.ssdpMulticastIPv4; + } + + /** + * + * @param ip The IPv6 address used as destination address for Multicast comunication + * @since 1.8 + */ + public void setMulticastIPv6Address(String ip){ + this.ssdpMulticastIPv6=ip; + } + + /** + * + * @return The IPv6 address used as destination address for Multicast comunication + * @since 1.8 + */ + public String getMulticastIPv6Address(){ + return this.ssdpMulticastIPv6; + } + + + + //////////////////////////////////////////////// + // SSDPPacket + //////////////////////////////////////////////// + + private SSDPPacket ssdpPacket = null; + + public SSDPPacket getSSDPPacket() { + return ssdpPacket; + } + + public void setSSDPPacket(SSDPPacket packet) { + ssdpPacket = packet; + } + + //////////////////////////////////////////////// + // Advertiser + //////////////////////////////////////////////// + + private Advertiser advertiser = null; + + public void setAdvertiser(Advertiser adv) + { + advertiser = adv; + } + + public Advertiser getAdvertiser() + { + return advertiser; + } + + +} + diff --git a/router/java/src/org/cybergarage/upnp/xml/NodeData.java b/router/java/src/org/cybergarage/upnp/xml/NodeData.java index 638e404d71dccbba5189a5c665c7cfe8543dfab7..304ea53035dcd2231f66419f7870d8f85e5e892e 100644 --- a/router/java/src/org/cybergarage/upnp/xml/NodeData.java +++ b/router/java/src/org/cybergarage/upnp/xml/NodeData.java @@ -1,43 +1,43 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: ActionData.java -* -* Revision; -* -* 03/28/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.upnp.xml; - -import org.cybergarage.xml.*; - -public class NodeData -{ - public NodeData() - { - setNode(null); - } - - //////////////////////////////////////////////// - // Node - //////////////////////////////////////////////// - - private Node node; - - public void setNode(Node node) - { - this.node = node; - } - - public Node getNode() - { - return node; - } -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: ActionData.java +* +* Revision; +* +* 03/28/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.upnp.xml; + +import org.cybergarage.xml.*; + +public class NodeData +{ + public NodeData() + { + setNode(null); + } + + //////////////////////////////////////////////// + // Node + //////////////////////////////////////////////// + + private Node node; + + public void setNode(Node node) + { + this.node = node; + } + + public Node getNode() + { + return node; + } +} + diff --git a/router/java/src/org/cybergarage/upnp/xml/ServiceData.java b/router/java/src/org/cybergarage/upnp/xml/ServiceData.java index 5f5eeefda5863ff2a06b0ec135ec4d9c536312ff..f991f56f2a2ecf172d8319b95e204f523aae5eb1 100644 --- a/router/java/src/org/cybergarage/upnp/xml/ServiceData.java +++ b/router/java/src/org/cybergarage/upnp/xml/ServiceData.java @@ -1,112 +1,112 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: ServiceData.java -* -* Revision; -* -* 03/28/03 -* - first revision. -* 01/06/04 -* - Moved setQueryListener() and getQueryListener() to StateVariableData class. -* 03/30/05 -* - Removed setDescriptionURL() and getDescriptionURL(). -* -******************************************************************/ - -package org.cybergarage.upnp.xml; - -import org.cybergarage.util.*; -import org.cybergarage.xml.*; - -import org.cybergarage.upnp.event.*; - -public class ServiceData extends NodeData -{ - public ServiceData() - { - } - - //////////////////////////////////////////////// - // controlActionListenerList - //////////////////////////////////////////////// - - private ListenerList controlActionListenerList = new ListenerList(); - - public ListenerList getControlActionListenerList() { - return controlActionListenerList; - } - - //////////////////////////////////////////////// - // scpdNode - //////////////////////////////////////////////// - - private Node scpdNode = null; - - public Node getSCPDNode() { - return scpdNode; - } - - public void setSCPDNode(Node node) { - scpdNode = node; - } - - //////////////////////////////////////////////// - // SubscriberList - //////////////////////////////////////////////// - - private SubscriberList subscriberList = new SubscriberList(); - - public SubscriberList getSubscriberList() { - return subscriberList; - } - - //////////////////////////////////////////////// - // SID - //////////////////////////////////////////////// - - private String descriptionURL = ""; - - public String getDescriptionURL() { - return descriptionURL; - } - - public void setDescriptionURL(String descriptionURL) { - this.descriptionURL = descriptionURL; - } - - //////////////////////////////////////////////// - // SID - //////////////////////////////////////////////// - - private String sid = ""; - - public String getSID() { - return sid; - } - - public void setSID(String id) { - sid = id; - } - - //////////////////////////////////////////////// - // Timeout - //////////////////////////////////////////////// - - private long timeout = 0; - - public long getTimeout() - { - return timeout; - } - - public void setTimeout(long value) - { - timeout = value; - } - -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: ServiceData.java +* +* Revision; +* +* 03/28/03 +* - first revision. +* 01/06/04 +* - Moved setQueryListener() and getQueryListener() to StateVariableData class. +* 03/30/05 +* - Removed setDescriptionURL() and getDescriptionURL(). +* +******************************************************************/ + +package org.cybergarage.upnp.xml; + +import org.cybergarage.util.*; +import org.cybergarage.xml.*; + +import org.cybergarage.upnp.event.*; + +public class ServiceData extends NodeData +{ + public ServiceData() + { + } + + //////////////////////////////////////////////// + // controlActionListenerList + //////////////////////////////////////////////// + + private ListenerList controlActionListenerList = new ListenerList(); + + public ListenerList getControlActionListenerList() { + return controlActionListenerList; + } + + //////////////////////////////////////////////// + // scpdNode + //////////////////////////////////////////////// + + private Node scpdNode = null; + + public Node getSCPDNode() { + return scpdNode; + } + + public void setSCPDNode(Node node) { + scpdNode = node; + } + + //////////////////////////////////////////////// + // SubscriberList + //////////////////////////////////////////////// + + private SubscriberList subscriberList = new SubscriberList(); + + public SubscriberList getSubscriberList() { + return subscriberList; + } + + //////////////////////////////////////////////// + // SID + //////////////////////////////////////////////// + + private String descriptionURL = ""; + + public String getDescriptionURL() { + return descriptionURL; + } + + public void setDescriptionURL(String descriptionURL) { + this.descriptionURL = descriptionURL; + } + + //////////////////////////////////////////////// + // SID + //////////////////////////////////////////////// + + private String sid = ""; + + public String getSID() { + return sid; + } + + public void setSID(String id) { + sid = id; + } + + //////////////////////////////////////////////// + // Timeout + //////////////////////////////////////////////// + + private long timeout = 0; + + public long getTimeout() + { + return timeout; + } + + public void setTimeout(long value) + { + timeout = value; + } + +} + diff --git a/router/java/src/org/cybergarage/upnp/xml/StateVariableData.java b/router/java/src/org/cybergarage/upnp/xml/StateVariableData.java index c32c7c1ed949929804f22e3633be4d8babeb4999..695d4fba93f4955ce71e45a56715ec5412d99e9e 100644 --- a/router/java/src/org/cybergarage/upnp/xml/StateVariableData.java +++ b/router/java/src/org/cybergarage/upnp/xml/StateVariableData.java @@ -1,73 +1,73 @@ -/****************************************************************** -* -* CyberUPnP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File:StateVariableData.java -* -* Revision; -* -* 02/05/03 -* - first revision. -* 01/06/04 -* - Added setQueryListener() and getQueryListener(). -* -******************************************************************/ - -package org.cybergarage.upnp.xml; - -import org.cybergarage.upnp.control.*; - -public class StateVariableData extends NodeData -{ - public StateVariableData() - { - } - - //////////////////////////////////////////////// - // value - //////////////////////////////////////////////// - - private String value = ""; - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - //////////////////////////////////////////////// - // QueryListener - //////////////////////////////////////////////// - - private QueryListener queryListener = null; - - public QueryListener getQueryListener() { - return queryListener; - } - - public void setQueryListener(QueryListener queryListener) { - this.queryListener = queryListener; - } - - //////////////////////////////////////////////// - // QueryResponse - //////////////////////////////////////////////// - - private QueryResponse queryRes = null; - - public QueryResponse getQueryResponse() - { - return queryRes; - } - - public void setQueryResponse(QueryResponse res) - { - queryRes = res; - } - -} - +/****************************************************************** +* +* CyberUPnP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File:StateVariableData.java +* +* Revision; +* +* 02/05/03 +* - first revision. +* 01/06/04 +* - Added setQueryListener() and getQueryListener(). +* +******************************************************************/ + +package org.cybergarage.upnp.xml; + +import org.cybergarage.upnp.control.*; + +public class StateVariableData extends NodeData +{ + public StateVariableData() + { + } + + //////////////////////////////////////////////// + // value + //////////////////////////////////////////////// + + private String value = ""; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + //////////////////////////////////////////////// + // QueryListener + //////////////////////////////////////////////// + + private QueryListener queryListener = null; + + public QueryListener getQueryListener() { + return queryListener; + } + + public void setQueryListener(QueryListener queryListener) { + this.queryListener = queryListener; + } + + //////////////////////////////////////////////// + // QueryResponse + //////////////////////////////////////////////// + + private QueryResponse queryRes = null; + + public QueryResponse getQueryResponse() + { + return queryRes; + } + + public void setQueryResponse(QueryResponse res) + { + queryRes = res; + } + +} + diff --git a/router/java/src/org/cybergarage/util/FileUtil.java b/router/java/src/org/cybergarage/util/FileUtil.java index ef79f98349a6b899135fdcb2ef2f129c8d6fdb46..5c2744d4dad424d1e1436f6c54d3638de4e0e595 100644 --- a/router/java/src/org/cybergarage/util/FileUtil.java +++ b/router/java/src/org/cybergarage/util/FileUtil.java @@ -1,79 +1,79 @@ -/****************************************************************** -* -* CyberUtil for Java -* -* Copyright (C) Satoshi Konno 2002-2003 +/****************************************************************** * -* File: FileUtil.java -* -* Revision: -* -* 01/03/03 -* - first revision. -* -******************************************************************/ +* CyberUtil for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: FileUtil.java +* +* Revision: +* +* 01/03/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.util; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; + +public final class FileUtil +{ + public final static byte[] load(String fileName) + { + try { + FileInputStream fin=new FileInputStream(fileName); + return load(fin); + } + catch (Exception e) { + Debug.warning(e); + return new byte[0]; + } + } + + public final static byte[] load(File file) + { + try { + FileInputStream fin=new FileInputStream(file); + return load(fin); + } + catch (Exception e) { + Debug.warning(e); + return new byte[0]; + } + } -package org.cybergarage.util; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; + public final static byte[] load(FileInputStream fin) + { + byte readBuf[] = new byte[512*1024]; + + try { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + int readCnt = fin.read(readBuf); + while (0 < readCnt) { + bout.write(readBuf, 0, readCnt); + readCnt = fin.read(readBuf); + } + + fin.close(); + + return bout.toByteArray(); + } + catch (Exception e) { + Debug.warning(e); + return new byte[0]; + } + } + + public final static boolean isXMLFileName(String name) + { + if (StringUtil.hasData(name) == false) + return false; + String lowerName = name.toLowerCase(); + return lowerName.endsWith("xml"); + } +} -public final class FileUtil -{ - public final static byte[] load(String fileName) - { - try { - FileInputStream fin=new FileInputStream(fileName); - return load(fin); - } - catch (Exception e) { - Debug.warning(e); - return new byte[0]; - } - } - - public final static byte[] load(File file) - { - try { - FileInputStream fin=new FileInputStream(file); - return load(fin); - } - catch (Exception e) { - Debug.warning(e); - return new byte[0]; - } - } - - public final static byte[] load(FileInputStream fin) - { - byte readBuf[] = new byte[512*1024]; - - try { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - - int readCnt = fin.read(readBuf); - while (0 < readCnt) { - bout.write(readBuf, 0, readCnt); - readCnt = fin.read(readBuf); - } - - fin.close(); - - return bout.toByteArray(); - } - catch (Exception e) { - Debug.warning(e); - return new byte[0]; - } - } - - public final static boolean isXMLFileName(String name) - { - if (StringUtil.hasData(name) == false) - return false; - String lowerName = name.toLowerCase(); - return lowerName.endsWith("xml"); - } -} - diff --git a/router/java/src/org/cybergarage/util/ListenerList.java b/router/java/src/org/cybergarage/util/ListenerList.java index 19f5901a1b3d50a2824445c323f4a052c8e83e0a..11aeb24153261789edadbef3dedfe4880023c4e5 100644 --- a/router/java/src/org/cybergarage/util/ListenerList.java +++ b/router/java/src/org/cybergarage/util/ListenerList.java @@ -1,29 +1,29 @@ -/****************************************************************** -* -* CyberUtil for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: ListenerList.java -* -* Revision; -* -* 12/30/02 -* - first revision. -* -******************************************************************/ +* CyberUtil for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ListenerList.java +* +* Revision; +* +* 12/30/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.util; + +import java.util.Vector; -package org.cybergarage.util; - -import java.util.Vector; +public class ListenerList extends Vector +{ + public boolean add(Object obj) + { + if (0 <= indexOf(obj)) + return false; + return super.add(obj); + } +} -public class ListenerList extends Vector -{ - public boolean add(Object obj) - { - if (0 <= indexOf(obj)) - return false; - return super.add(obj); - } -} - diff --git a/router/java/src/org/cybergarage/util/Mutex.java b/router/java/src/org/cybergarage/util/Mutex.java index f26351271c317a5906d20e6666dc3072b8f97342..426b6598159ab801195a668674b4ac1296159263 100644 --- a/router/java/src/org/cybergarage/util/Mutex.java +++ b/router/java/src/org/cybergarage/util/Mutex.java @@ -1,54 +1,54 @@ -/****************************************************************** -* -* CyberUtil for Java -* -* Copyright (C) Satoshi Konno 2002-2004 -* -* File: Mutex.java -* -* Revision: -* -* 06/19/04 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.util; - -public class Mutex -{ - private boolean syncLock; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Mutex() - { - syncLock = false; - } - - //////////////////////////////////////////////// - // lock - //////////////////////////////////////////////// - - public synchronized void lock() - { - while(syncLock == true) { - try { - wait(); - } - catch (Exception e) { - Debug.warning(e); - }; - } - syncLock = true; - } - - public synchronized void unlock() - { - syncLock = false; - notifyAll(); - } - +/****************************************************************** +* +* CyberUtil for Java +* +* Copyright (C) Satoshi Konno 2002-2004 +* +* File: Mutex.java +* +* Revision: +* +* 06/19/04 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.util; + +public class Mutex +{ + private boolean syncLock; + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Mutex() + { + syncLock = false; + } + + //////////////////////////////////////////////// + // lock + //////////////////////////////////////////////// + + public synchronized void lock() + { + while(syncLock == true) { + try { + wait(); + } + catch (Exception e) { + Debug.warning(e); + }; + } + syncLock = true; + } + + public synchronized void unlock() + { + syncLock = false; + notifyAll(); + } + } \ No newline at end of file diff --git a/router/java/src/org/cybergarage/util/StringUtil.java b/router/java/src/org/cybergarage/util/StringUtil.java index b59eb929a101c1e7ed08cd2296b582211e69f098..a71cdb3732a5d466f0f200741ee48a5cd29fc346 100644 --- a/router/java/src/org/cybergarage/util/StringUtil.java +++ b/router/java/src/org/cybergarage/util/StringUtil.java @@ -1,123 +1,123 @@ -/****************************************************************** -* -* CyberUtil for Java -* -* Copyright (C) Satoshi Konno 2002-2003 +/****************************************************************** * -* File: FileUtil.java -* -* Revision: -* -* 01/12/03 -* - first revision. -* -******************************************************************/ +* CyberUtil for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: FileUtil.java +* +* Revision: +* +* 01/12/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.util; + +public final class StringUtil +{ + public final static boolean hasData(String value) + { + if (value == null) + return false; + if (value.length() <= 0) + return false; + return true; + } + + public final static int toInteger(String value) + { + try { + return Integer.parseInt(value); + } + catch (Exception e) { + Debug.warning(e); + } + return 0; + } + + public final static long toLong(String value) + { + try { + return Long.parseLong(value); + } + catch (Exception e) { + Debug.warning(e); + } + return 0; + } + + public final static int findOf(String str, String chars, int startIdx, int endIdx, int offset, boolean isEqual) + { + if (offset == 0) + return -1; + int charCnt = chars.length(); + int idx = startIdx; + while (true) { + if (0 < offset) { + if (endIdx < idx) + break; + } + else { + if (idx < endIdx) + break; + } + char strc = str.charAt(idx); + int noEqualCnt = 0; + for (int n=0; n<charCnt; n++) { + char charc = chars.charAt(n); + if (isEqual == true) { + if (strc == charc) + return idx; + } + else { + if (strc != charc) + noEqualCnt++; + if (noEqualCnt == charCnt) + return idx; + } + } + idx += offset; + } + return -1; + } + + public final static int findFirstOf(String str, String chars) + { + return findOf(str, chars, 0, (str.length()-1), 1, true); + } + + public final static int findFirstNotOf(String str, String chars) + { + return findOf(str, chars, 0, (str.length()-1), 1, false); + } + + public final static int findLastOf(String str, String chars) + { + return findOf(str, chars, (str.length()-1), 0, -1, true); + } + + public final static int findLastNotOf(String str, String chars) + { + return findOf(str, chars, (str.length()-1), 0, -1, false); + } + + public final static String trim(String trimStr, String trimChars) + { + int spIdx = findFirstNotOf(trimStr, trimChars); + if (spIdx < 0) { + String buf = trimStr; + return buf; + } + String trimStr2 = trimStr.substring(spIdx, trimStr.length()); + spIdx = findLastNotOf(trimStr2, trimChars); + if (spIdx < 0) { + String buf = trimStr2; + return buf; + } + String buf = trimStr2.substring(0, spIdx+1); + return buf; + } +} -package org.cybergarage.util; - -public final class StringUtil -{ - public final static boolean hasData(String value) - { - if (value == null) - return false; - if (value.length() <= 0) - return false; - return true; - } - - public final static int toInteger(String value) - { - try { - return Integer.parseInt(value); - } - catch (Exception e) { - Debug.warning(e); - } - return 0; - } - - public final static long toLong(String value) - { - try { - return Long.parseLong(value); - } - catch (Exception e) { - Debug.warning(e); - } - return 0; - } - - public final static int findOf(String str, String chars, int startIdx, int endIdx, int offset, boolean isEqual) - { - if (offset == 0) - return -1; - int charCnt = chars.length(); - int idx = startIdx; - while (true) { - if (0 < offset) { - if (endIdx < idx) - break; - } - else { - if (idx < endIdx) - break; - } - char strc = str.charAt(idx); - int noEqualCnt = 0; - for (int n=0; n<charCnt; n++) { - char charc = chars.charAt(n); - if (isEqual == true) { - if (strc == charc) - return idx; - } - else { - if (strc != charc) - noEqualCnt++; - if (noEqualCnt == charCnt) - return idx; - } - } - idx += offset; - } - return -1; - } - - public final static int findFirstOf(String str, String chars) - { - return findOf(str, chars, 0, (str.length()-1), 1, true); - } - - public final static int findFirstNotOf(String str, String chars) - { - return findOf(str, chars, 0, (str.length()-1), 1, false); - } - - public final static int findLastOf(String str, String chars) - { - return findOf(str, chars, (str.length()-1), 0, -1, true); - } - - public final static int findLastNotOf(String str, String chars) - { - return findOf(str, chars, (str.length()-1), 0, -1, false); - } - - public final static String trim(String trimStr, String trimChars) - { - int spIdx = findFirstNotOf(trimStr, trimChars); - if (spIdx < 0) { - String buf = trimStr; - return buf; - } - String trimStr2 = trimStr.substring(spIdx, trimStr.length()); - spIdx = findLastNotOf(trimStr2, trimChars); - if (spIdx < 0) { - String buf = trimStr2; - return buf; - } - String buf = trimStr2.substring(0, spIdx+1); - return buf; - } -} - diff --git a/router/java/src/org/cybergarage/util/ThreadCore.java b/router/java/src/org/cybergarage/util/ThreadCore.java index 245798dd6285bd5a822b442bbcc6e99d624d6dce..3446a08be08f38485b88af6fc420631619e63624 100644 --- a/router/java/src/org/cybergarage/util/ThreadCore.java +++ b/router/java/src/org/cybergarage/util/ThreadCore.java @@ -1,83 +1,83 @@ -/****************************************************************** -* -* CyberUtil for Java -* -* Copyright (C) Satoshi Konno 2002-2004 -* -* File: Thread.java -* -* Revision: -* -* 01/05/04 -* - first revision. -* 08/23/07 -* - Thanks for Kazuyuki Shudo -* - Changed stop() to stop more safety using Thread::interrupt(). -* -******************************************************************/ - -package org.cybergarage.util; - -public class ThreadCore implements Runnable -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public ThreadCore() - { - } - - //////////////////////////////////////////////// - // Thread - //////////////////////////////////////////////// - - private java.lang.Thread mThreadObject = null; - - public void setThreadObject(java.lang.Thread obj) { - mThreadObject = obj; - } - - public java.lang.Thread getThreadObject() { - return mThreadObject; - } - - public void start() - { - java.lang.Thread threadObject = getThreadObject(); - if (threadObject == null) { - threadObject = new java.lang.Thread(this,"Cyber.ThreadCore"); - setThreadObject(threadObject); - threadObject.start(); - } - } - - public void run() - { - } - - public boolean isRunnable() - { - return (Thread.currentThread() == getThreadObject()) ? true : false; - } - - public void stop() - { - java.lang.Thread threadObject = getThreadObject(); - if (threadObject != null) { - //threadObject.destroy(); - //threadObject.stop(); - - // Thanks for Kazuyuki Shudo (08/23/07) - threadObject.interrupt(); - - setThreadObject(null); - } - } - - public void restart() - { - stop(); - start(); - } -} +/****************************************************************** +* +* CyberUtil for Java +* +* Copyright (C) Satoshi Konno 2002-2004 +* +* File: Thread.java +* +* Revision: +* +* 01/05/04 +* - first revision. +* 08/23/07 +* - Thanks for Kazuyuki Shudo +* - Changed stop() to stop more safety using Thread::interrupt(). +* +******************************************************************/ + +package org.cybergarage.util; + +public class ThreadCore implements Runnable +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public ThreadCore() + { + } + + //////////////////////////////////////////////// + // Thread + //////////////////////////////////////////////// + + private java.lang.Thread mThreadObject = null; + + public void setThreadObject(java.lang.Thread obj) { + mThreadObject = obj; + } + + public java.lang.Thread getThreadObject() { + return mThreadObject; + } + + public void start() + { + java.lang.Thread threadObject = getThreadObject(); + if (threadObject == null) { + threadObject = new java.lang.Thread(this,"Cyber.ThreadCore"); + setThreadObject(threadObject); + threadObject.start(); + } + } + + public void run() + { + } + + public boolean isRunnable() + { + return (Thread.currentThread() == getThreadObject()) ? true : false; + } + + public void stop() + { + java.lang.Thread threadObject = getThreadObject(); + if (threadObject != null) { + //threadObject.destroy(); + //threadObject.stop(); + + // Thanks for Kazuyuki Shudo (08/23/07) + threadObject.interrupt(); + + setThreadObject(null); + } + } + + public void restart() + { + stop(); + start(); + } +} diff --git a/router/java/src/org/cybergarage/util/TimerUtil.java b/router/java/src/org/cybergarage/util/TimerUtil.java index 58087435bbfcf5a61d6e25e47a9080f527f58178..ecf5624eef9ba85e1597b6b3c7eeb5ca353475b0 100644 --- a/router/java/src/org/cybergarage/util/TimerUtil.java +++ b/router/java/src/org/cybergarage/util/TimerUtil.java @@ -1,37 +1,37 @@ -/****************************************************************** -* -* CyberUtil for Java -* -* Copyright (C) Satoshi Konno 2002-2003 -* -* File: TimerUtil.java -* -* Revision: -* -* 01/15/03 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.util; - -public final class TimerUtil -{ - public final static void wait(int waitTime) - { - try { - Thread.sleep(waitTime); - } - catch (Exception e) {} - } - - public final static void waitRandom(int time) - { - int waitTime = (int)(Math.random() * (double)time); - try { - Thread.sleep(waitTime); - } - catch (Exception e) {} - } -} - +/****************************************************************** +* +* CyberUtil for Java +* +* Copyright (C) Satoshi Konno 2002-2003 +* +* File: TimerUtil.java +* +* Revision: +* +* 01/15/03 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.util; + +public final class TimerUtil +{ + public final static void wait(int waitTime) + { + try { + Thread.sleep(waitTime); + } + catch (Exception e) {} + } + + public final static void waitRandom(int time) + { + int waitTime = (int)(Math.random() * (double)time); + try { + Thread.sleep(waitTime); + } + catch (Exception e) {} + } +} + diff --git a/router/java/src/org/cybergarage/xml/Attribute.java b/router/java/src/org/cybergarage/xml/Attribute.java index ce7c16e9e1a306333fcbfe12a504dc3d32415e63..282cf51cbaf5ae31b1579f34907258fe805fbdfb 100644 --- a/router/java/src/org/cybergarage/xml/Attribute.java +++ b/router/java/src/org/cybergarage/xml/Attribute.java @@ -1,61 +1,78 @@ -/****************************************************************** -* -* CyberXML for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: Attribute.java -* -* Revision; -* -* 11/27/02 -* - first revision. -* -******************************************************************/ - -package org.cybergarage.xml; - -public class Attribute -{ - private String name = new String(); - private String value = new String(); - - public Attribute() - { - } - - public Attribute(String name, String value) - { - setName(name); - setValue(value); - } - - //////////////////////////////////////////////// - // name - //////////////////////////////////////////////// - - public void setName(String name) - { - this.name = name; - } - - public String getName() - { - return name; - } - - //////////////////////////////////////////////// - // value - //////////////////////////////////////////////// - - public void setValue(String value) - { - this.value = value; - } - - public String getValue() - { - return value; - } -} - +* CyberXML for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: Attribute.java +* +* Revision; +* +* 11/27/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.xml; + +public class Attribute +{ + private String name = new String(); + private String value = new String(); + + public Attribute() + { + } + + public Attribute(String name, String value) + { + 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()); + } +} + diff --git a/router/java/src/org/cybergarage/xml/AttributeList.java b/router/java/src/org/cybergarage/xml/AttributeList.java index 7a0e67091ac7ece115e5ffbc8e3c74642640409a..57ea2774386ffb5ea601e0eea4e9d98269aeebcd 100644 --- a/router/java/src/org/cybergarage/xml/AttributeList.java +++ b/router/java/src/org/cybergarage/xml/AttributeList.java @@ -1,45 +1,45 @@ -/****************************************************************** -* -* CyberXML for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: AttributeList.java -* -* Revision; -* -* 11/27/02 -* - first revision. -* -******************************************************************/ +* CyberXML for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: AttributeList.java +* +* Revision; +* +* 11/27/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.xml; -package org.cybergarage.xml; - -import java.util.Vector; - -public class AttributeList extends Vector -{ - public AttributeList() - { - } - - public Attribute getAttribute(int n) - { - return (Attribute)get(n); - } - - public Attribute getAttribute(String name) - { - if (name == null) - return null; - - int nLists = size(); - for (int n=0; n<nLists; n++) { - Attribute elem = getAttribute(n); - if (name.compareTo(elem.getName()) == 0) - return elem; +import java.util.Vector; + +public class AttributeList extends Vector +{ + public AttributeList() + { + } + + public Attribute getAttribute(int n) + { + return (Attribute)get(n); + } + + public Attribute getAttribute(String name) + { + if (name == null) + return null; + + int nLists = size(); + for (int n=0; n<nLists; n++) { + Attribute elem = getAttribute(n); + if (name.compareTo(elem.getName()) == 0) + return elem; } - return null; - } -} - + return null; + } +} + diff --git a/router/java/src/org/cybergarage/xml/Node.java b/router/java/src/org/cybergarage/xml/Node.java index 7e34a084f7d35c3851dae420885da7f57248b21b..c81c39ec4fd0f00eaf52c8b318337a7c970667b4 100644 --- a/router/java/src/org/cybergarage/xml/Node.java +++ b/router/java/src/org/cybergarage/xml/Node.java @@ -61,6 +61,12 @@ public class Node setName(ns, name); } + public Node(Node otherNode) + { + this(); + set(otherNode); + } + //////////////////////////////////////////////// // parent node //////////////////////////////////////////////// @@ -189,6 +195,11 @@ public class Node return removeAttribute(getAttribute(name)); } + public void removeAllAttributes() + { + attrList.clear(); + } + public boolean hasAttributes() { if (0 < getNAttributes()) @@ -239,6 +250,51 @@ public class Node setAttribute("xmlns:" + ns, value); } + //////////////////////////////////////////////// + // set + //////////////////////////////////////////////// + + public boolean set(Node otherNode) { + if (otherNode == null) + return false; + + setName(otherNode.getName()); + setValue(otherNode.getValue()); + + removeAllAttributes(); + int nOtherAttributes = otherNode.getNAttributes(); + for (int n=0; n<nOtherAttributes; n++) { + Attribute otherAttr = otherNode.getAttribute(n); + Attribute thisAttr = new Attribute(otherAttr); + addAttribute(thisAttr); + } + + removeAllNodes(); + int nOtherChildNodes = otherNode.getNNodes(); + for (int n=0; n<nOtherChildNodes; n++) { + Node otherChildNode = otherNode.getNode(n); + Node thisChildNode = new Node(); + thisChildNode.set(otherChildNode); + addNode(thisChildNode); + } + + return true; + } + + //////////////////////////////////////////////// + // equals + //////////////////////////////////////////////// + + public boolean equals(Node otherNode) { + if (otherNode == null) + return false; + + String thisNodeString = toString(); + String otherNodeString = otherNode.toString(); + + return thisNodeString.equals(otherNodeString); + } + //////////////////////////////////////////////// // Child node //////////////////////////////////////////////// @@ -309,16 +365,30 @@ public class Node // Element (Child Node) //////////////////////////////////////////////// - public void setNode(String name, String value) { + public boolean hasNode(String name) { Node node = getNode(name); if (node != null) { - node.setValue(value); + return true; + } + return false; + } + + public void setNode(String name) { + if (hasNode(name)) { return; } - node = new Node(name); - node.setValue(value); + Node node = new Node(name); addNode(node); } + + public void setNode(String name, String value) { + Node node = getNode(name); + if (node == null) { + node = new Node(name); + addNode(node); + } + node.setValue(value); + } public String getNodeValue(String name) { Node node = getNode(name); diff --git a/router/java/src/org/cybergarage/xml/NodeList.java b/router/java/src/org/cybergarage/xml/NodeList.java index 806b6f22c83a55bcf6c22173d4f43c436a7a0777..3349c0bc9e3dc9420c997c72253b297b63d737aa 100644 --- a/router/java/src/org/cybergarage/xml/NodeList.java +++ b/router/java/src/org/cybergarage/xml/NodeList.java @@ -1,63 +1,63 @@ -/****************************************************************** -* -* CyberXML for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: NodeList.java -* -* Revision; -* -* 11/27/02 -* - first revision. -* -******************************************************************/ +* CyberXML for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: NodeList.java +* +* Revision; +* +* 11/27/02 +* - first revision. +* +******************************************************************/ + +package org.cybergarage.xml; -package org.cybergarage.xml; - -import java.util.Vector; - -public class NodeList extends Vector -{ - public NodeList() - { - } - - public Node getNode(int n) - { - return (Node)get(n); - } - - public Node getNode(String name) - { - if (name == null) - return null; - - int nLists = size(); - for (int n=0; n<nLists; n++) { - Node node = getNode(n); - String nodeName = node.getName(); - if (name.compareTo(nodeName) == 0) - return node; +import java.util.Vector; + +public class NodeList extends Vector +{ + public NodeList() + { + } + + public Node getNode(int n) + { + return (Node)get(n); + } + + public Node getNode(String name) + { + if (name == null) + return null; + + int nLists = size(); + for (int n=0; n<nLists; n++) { + Node node = getNode(n); + String nodeName = node.getName(); + if (name.compareTo(nodeName) == 0) + return node; } - return null; - } - - public Node getEndsWith(String name) - { - if (name == null) - return null; - - int nLists = size(); - for (int n=0; n<nLists; n++) { - Node node = getNode(n); - String nodeName = node.getName(); - if (nodeName == null) - continue; - if (nodeName.endsWith(name) == true) - return node; + return null; + } + + public Node getEndsWith(String name) + { + if (name == null) + return null; + + int nLists = size(); + for (int n=0; n<nLists; n++) { + Node node = getNode(n); + String nodeName = node.getName(); + if (nodeName == null) + continue; + if (nodeName.endsWith(name) == true) + return node; } - return null; - } -} - + return null; + } +} + diff --git a/router/java/src/org/cybergarage/xml/ParserException.java b/router/java/src/org/cybergarage/xml/ParserException.java index 87f1553e61f42091b212b3f835e49f31ba9a77ff..894e166cddf2dd519d071f4c4d25cd438bb24bd4 100644 --- a/router/java/src/org/cybergarage/xml/ParserException.java +++ b/router/java/src/org/cybergarage/xml/ParserException.java @@ -1,30 +1,30 @@ -/****************************************************************** -* -* CyberXML for Java -* -* Copyright (C) Satoshi Konno 2002 +/****************************************************************** * -* File: ParserException.java -* -* Revision; -* -* 11/27/02 -* - first revision. -* 12/26/03 -* - Changed to a sub class of Exception instead of SAXException. -* -******************************************************************/ - -package org.cybergarage.xml; - -public class ParserException extends Exception +* CyberXML for Java +* +* Copyright (C) Satoshi Konno 2002 +* +* File: ParserException.java +* +* Revision; +* +* 11/27/02 +* - first revision. +* 12/26/03 +* - Changed to a sub class of Exception instead of SAXException. +* +******************************************************************/ + +package org.cybergarage.xml; + +public class ParserException extends Exception { - public ParserException(Exception e) + public ParserException(Exception e) { super(e); - } + } - public ParserException(String s) + public ParserException(String s) { super(s); } diff --git a/router/java/src/org/cybergarage/xml/XML.java b/router/java/src/org/cybergarage/xml/XML.java index ce170358c81bfb4b3468abf8b6c6d0a0468b5daf..255344800fadcca1a3a29ebd01bd384e674f128c 100644 --- a/router/java/src/org/cybergarage/xml/XML.java +++ b/router/java/src/org/cybergarage/xml/XML.java @@ -5,22 +5,23 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: XML.java -* -* Revision; -* -* 01/05/03 +* +* Revision; +* +* 01/05/03 * - first revision. * 12/15/03 * - Terje Bakken -* - Added escapeXMLChars() +* - Added escapeXMLChars() * ******************************************************************/ - + package org.cybergarage.xml; -public class XML -{ - public final static String CONTENT_TYPE = "text/xml; charset=\"utf-8\""; +public class XML +{ + public final static String DEFAULT_CONTENT_TYPE = "text/xml; charset=\"utf-8\""; + public final static String DEFAULT_CONTENT_LANGUAGE = "en"; public final static String CHARSET_UTF8 = "utf-8"; //////////////////////////////////////////////// @@ -82,5 +83,5 @@ public class XML return outStr; } -} +} diff --git a/router/java/src/org/cybergarage/xml/parser/JaxpParser.java b/router/java/src/org/cybergarage/xml/parser/JaxpParser.java index ef4c1e0aa1846f33d2455e99da764b59331aea1d..9886911a0bd7f549976ae6da6fb0b1808a1550ed 100644 --- a/router/java/src/org/cybergarage/xml/parser/JaxpParser.java +++ b/router/java/src/org/cybergarage/xml/parser/JaxpParser.java @@ -1,141 +1,141 @@ -/****************************************************************** -* -* CyberXML for Java -* -* Copyright (C) Satoshi Konno 2004 -* -* Author: Markus Thurner (http://thoean.com) -* -* File: JaxpParser.java -* -* Revision; -* -* 06/15/04 -* - first revision. -* 01/08/08 -* - Fixed parse() not to occur null exception when the NamedNodeMap is null on Android. -* 02/08/08 -* - Change parse() to use Node::addValue() instead of the setValue(). -* -******************************************************************/ - -package org.cybergarage.xml.parser; - -import java.io.InputStream; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.cybergarage.xml.Node; -import org.cybergarage.xml.Parser; -import org.cybergarage.xml.ParserException; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.xml.sax.InputSource; - - -public class JaxpParser extends Parser -{ - - public JaxpParser() - { - super(); - } - - //////////////////////////////////////////////// - // parse (Node) - //////////////////////////////////////////////// - - public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode, int rank) - { - int domNodeType = domNode.getNodeType(); -// if (domNodeType != Node.ELEMENT_NODE) -// return; - - String domNodeName = domNode.getNodeName(); - String domNodeValue = domNode.getNodeValue(); - NamedNodeMap attrs = domNode.getAttributes(); - int arrrsLen = (attrs != null) ? attrs.getLength() : 0; - -// Debug.message("[" + rank + "] ELEM : " + domNodeName + ", " + domNodeValue + ", type = " + domNodeType + ", attrs = " + arrrsLen); - - if (domNodeType == org.w3c.dom.Node.TEXT_NODE) { - // Change to use Node::addValue() instead of the setValue(). (2008/02/07) - //parentNode.setValue(domNodeValue); - parentNode.addValue(domNodeValue); - return parentNode; - } - - if (domNodeType != org.w3c.dom.Node.ELEMENT_NODE) - return parentNode; - - org.cybergarage.xml.Node node = new org.cybergarage.xml.Node(); - node.setName(domNodeName); - node.setValue(domNodeValue); - - if (parentNode != null) - parentNode.addNode(node); - - NamedNodeMap attrMap = domNode.getAttributes(); - if (attrMap != null) { - int attrLen = attrMap.getLength(); - //Debug.message("attrLen = " + attrLen); - for (int n = 0; n<attrLen; n++) { - org.w3c.dom.Node attr = attrMap.item(n); - String attrName = attr.getNodeName(); - String attrValue = attr.getNodeValue(); - node.setAttribute(attrName, attrValue); - } - } - - org.w3c.dom.Node child = domNode.getFirstChild(); - if(child==null){ - node.setValue(""); - return node; - } - do{ - parse(node, child, rank+1); - child = child.getNextSibling(); - }while (child != null); - - return node; - } - - public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode) - { - return parse(parentNode, domNode, 0); - } - - /* (non-Javadoc) - * @see org.cybergarage.xml.Parser#parse(java.io.InputStream) - */ - public Node parse(InputStream inStream) throws ParserException - { - org.cybergarage.xml.Node root = null; - - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - InputSource inSrc = new InputSource(inStream); - Document doc = builder.parse(inSrc); - - org.w3c.dom.Element docElem = doc.getDocumentElement(); - - if (docElem != null) - root = parse(root, docElem); -/* - NodeList rootList = doc.getElementsByTagName("root"); - Debug.message("rootList = " + rootList.getLength()); - - if (0 < rootList.getLength()) - root = parse(root, rootList.item(0)); -*/ - } - catch (Exception e) { - throw new ParserException(e); - } - - return root; - } - -} +/****************************************************************** +* +* CyberXML for Java +* +* Copyright (C) Satoshi Konno 2004 +* +* Author: Markus Thurner (http://thoean.com) +* +* File: JaxpParser.java +* +* Revision; +* +* 06/15/04 +* - first revision. +* 01/08/08 +* - Fixed parse() not to occur null exception when the NamedNodeMap is null on Android. +* 02/08/08 +* - Change parse() to use Node::addValue() instead of the setValue(). +* +******************************************************************/ + +package org.cybergarage.xml.parser; + +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.cybergarage.xml.Node; +import org.cybergarage.xml.Parser; +import org.cybergarage.xml.ParserException; +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.xml.sax.InputSource; + + +public class JaxpParser extends Parser +{ + + public JaxpParser() + { + super(); + } + + //////////////////////////////////////////////// + // parse (Node) + //////////////////////////////////////////////// + + public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode, int rank) + { + int domNodeType = domNode.getNodeType(); +// if (domNodeType != Node.ELEMENT_NODE) +// return; + + String domNodeName = domNode.getNodeName(); + String domNodeValue = domNode.getNodeValue(); + NamedNodeMap attrs = domNode.getAttributes(); + int arrrsLen = (attrs != null) ? attrs.getLength() : 0; + +// Debug.message("[" + rank + "] ELEM : " + domNodeName + ", " + domNodeValue + ", type = " + domNodeType + ", attrs = " + arrrsLen); + + if (domNodeType == org.w3c.dom.Node.TEXT_NODE) { + // Change to use Node::addValue() instead of the setValue(). (2008/02/07) + //parentNode.setValue(domNodeValue); + parentNode.addValue(domNodeValue); + return parentNode; + } + + if (domNodeType != org.w3c.dom.Node.ELEMENT_NODE) + return parentNode; + + org.cybergarage.xml.Node node = new org.cybergarage.xml.Node(); + node.setName(domNodeName); + node.setValue(domNodeValue); + + if (parentNode != null) + parentNode.addNode(node); + + NamedNodeMap attrMap = domNode.getAttributes(); + if (attrMap != null) { + int attrLen = attrMap.getLength(); + //Debug.message("attrLen = " + attrLen); + for (int n = 0; n<attrLen; n++) { + org.w3c.dom.Node attr = attrMap.item(n); + String attrName = attr.getNodeName(); + String attrValue = attr.getNodeValue(); + node.setAttribute(attrName, attrValue); + } + } + + org.w3c.dom.Node child = domNode.getFirstChild(); + if(child==null){ + node.setValue(""); + return node; + } + do{ + parse(node, child, rank+1); + child = child.getNextSibling(); + }while (child != null); + + return node; + } + + public org.cybergarage.xml.Node parse(org.cybergarage.xml.Node parentNode, org.w3c.dom.Node domNode) + { + return parse(parentNode, domNode, 0); + } + + /* (non-Javadoc) + * @see org.cybergarage.xml.Parser#parse(java.io.InputStream) + */ + public Node parse(InputStream inStream) throws ParserException + { + org.cybergarage.xml.Node root = null; + + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + InputSource inSrc = new InputSource(inStream); + Document doc = builder.parse(inSrc); + + org.w3c.dom.Element docElem = doc.getDocumentElement(); + + if (docElem != null) + root = parse(root, docElem); +/* + NodeList rootList = doc.getElementsByTagName("root"); + Debug.message("rootList = " + rootList.getLength()); + + if (0 < rootList.getLength()) + root = parse(root, rootList.item(0)); +*/ + } + catch (Exception e) { + throw new ParserException(e); + } + + return root; + } + +}