diff --git a/router/java/src/org/cybergarage/http/Date.java b/router/java/src/org/cybergarage/http/Date.java index a3424eb57..117964d34 100644 --- a/router/java/src/org/cybergarage/http/Date.java +++ b/router/java/src/org/cybergarage/http/Date.java @@ -1,8 +1,8 @@ /****************************************************************** * -* CyberHTTP for Java -* -* Copyright (C) Satoshi Konno 2002-2003 +* CyberHTTP for Java +* +* Copyright (C) Satoshi Konno 2002-2003 * * File : Date.java * @@ -16,7 +16,7 @@ * getHour(), getDateString() getTimeString() * - Fixed getInstance() to return GMT instance. * -******************************************************************/ +******************************************************************/ package org.cybergarage.http; @@ -136,15 +136,15 @@ public class Date public String getDateString() { // Thanks for Theo Beisch (10/20/04) - Calendar _cal = getCalendar(); + 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"; + 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"; } //////////////////////////////////////////////// @@ -154,11 +154,11 @@ public class Date public String getTimeString() { // Thanks for Theo Beisch (10/20/04) - Calendar _cal = getCalendar(); + Calendar cal = getCalendar(); return - toDateString(_cal.get(Calendar.HOUR_OF_DAY)) + - (((_cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") + - toDateString(_cal.get(Calendar.MINUTE)); + 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/HTTPHeader.java b/router/java/src/org/cybergarage/http/HTTPHeader.java index 9ea1610e9..d09446bdc 100644 --- a/router/java/src/org/cybergarage/http/HTTPHeader.java +++ b/router/java/src/org/cybergarage/http/HTTPHeader.java @@ -5,33 +5,33 @@ * 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 (05/26/04) * - Fixed getValue() to compare using String::equals() instead of String::startWidth(). * ******************************************************************/ - + package org.cybergarage.http; - -import java.io.*; + +import java.io.*; import org.cybergarage.util.*; - -public class HTTPHeader -{ - private String name; - private String value; - - public HTTPHeader(String name, String value) - { - setName(name); - setValue(value); - } + +public class HTTPHeader +{ + private String name; + private String value; + + public HTTPHeader(String name, String value) + { + setName(name); + setValue(value); + } public HTTPHeader(String lineStr) { @@ -42,35 +42,35 @@ public class HTTPHeader int colonIdx = lineStr.indexOf(':'); if (colonIdx < 0) return; - String _name = new String(lineStr.getBytes(), 0, colonIdx); - String _value = new String(lineStr.getBytes(), colonIdx+1, lineStr.length()-colonIdx-1); - setName(_name.trim()); - setValue(_value.trim()); + String name = new String(lineStr.getBytes(), 0, colonIdx); + String value = new String(lineStr.getBytes(), colonIdx+1, lineStr.length()-colonIdx-1); + 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() { @@ -78,67 +78,67 @@ 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 (05/26/04) - if (bigLineHeaderName.equals(bigName) == false) { - lineStr = reader.readLine(); - continue; - } - return header.getValue(); - } - } + // Thanks for Jan Newmarch (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) - { - StringReader strReader = new StringReader(data); - LineNumberReader lineReader = new LineNumberReader(strReader); - 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) + Debug.warning(e); + return ""; + } + return ""; + } + + public final static String getValue(String data, String name) + { + StringReader strReader = new StringReader(data); + LineNumberReader lineReader = new LineNumberReader(strReader); + 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 7a5ea924d..3c0c78e63 100644 --- a/router/java/src/org/cybergarage/http/HTTPPacket.java +++ b/router/java/src/org/cybergarage/http/HTTPPacket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: HTTPConnection.java -* -* Revision; -* -* 11/18/02 -* - first revision. +* +* Revision; +* +* 11/18/02 +* - first revision. * 09/02/03 * - Giordano Sassaroli * - Problem : The API is unable to receive responses from the Microsoft UPnP stack @@ -64,24 +64,24 @@ package org.cybergarage.http; -import java.io.*; -import java.util.*; - +import java.io.*; +import java.util.*; + import org.cybergarage.net.*; -import org.cybergarage.util.*; -import java.util.Calendar; - -public class HTTPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPPacket() +import org.cybergarage.util.*; +import java.util.Calendar; + +public class HTTPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPPacket() { setVersion(HTTP.VERSION); - setContentInputStream(null); - } + setContentInputStream(null); + } public HTTPPacket(HTTPPacket httpPacket) { @@ -134,13 +134,13 @@ public class HTTPPacket try { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - String _firstLine = reader.readLine(); - if (_firstLine == null || _firstLine.length() <= 0) + String firstLine = reader.readLine(); + if (firstLine == null || firstLine.length() <= 0) return false; - setFirstLine(_firstLine); + setFirstLine(firstLine); // Thanks for Giordano Sassaroli (09/03/03) - HTTPStatus httpStatus = new HTTPStatus(_firstLine); + HTTPStatus httpStatus = new HTTPStatus(firstLine); int statCode = httpStatus.getStatusCode(); if (statCode == HTTPStatus.CONTINUE){ //ad hoc code for managing iis non-standard behaviour @@ -186,7 +186,7 @@ public class HTTPPacket String chunkSizeLine = reader.readLine(); contentLen = Long.parseLong(new String(chunkSizeLine.getBytes(), 0, chunkSizeLine.length()-2)); } - catch (Exception e) {} + catch (Exception e) {}; } else contentLen = getContentLength(); @@ -231,7 +231,7 @@ public class HTTPPacket } catch (Exception e) { contentLen = 0; - } + }; } else contentLen = 0; @@ -312,47 +312,47 @@ public class HTTPPacket public boolean hasFirstLine() { - return (0 < firstLine.length()) ? true : false; + return (0 < firstLine.length()) ? true : false; } - //////////////////////////////////////////////// - // Header - //////////////////////////////////////////////// - - private Vector httpHeaderList = new Vector(); - - public int getNHeaders() - { - return httpHeaderList.size(); - } - - public void addHeader(HTTPHeader header) - { - httpHeaderList.add(header); - } - - public void addHeader(String name, String value) - { - HTTPHeader header = new HTTPHeader(name, value); - httpHeaderList.add(header); - } - - public HTTPHeader getHeader(int n) - { - return (HTTPHeader)httpHeaderList.get(n); - } - - public HTTPHeader getHeader(String name) - { - int nHeaders = getNHeaders(); - for (int n=0; n 0) ? true : false; - } + } //////////////////////////////////////////////// // Contents (InputStream) @@ -538,35 +538,35 @@ public class HTTPPacket { return (contentInput != null) ? true : false; } - - //////////////////////////////////////////////// - // ContentType - //////////////////////////////////////////////// - - public void setContentType(String type) + + //////////////////////////////////////////////// + // ContentType + //////////////////////////////////////////////// + + public void setContentType(String type) + { + setHeader(HTTP.CONTENT_TYPE, type); + } + + public String getContentType() + { + return getHeaderValue(HTTP.CONTENT_TYPE); + } + + //////////////////////////////////////////////// + // ContentLength + //////////////////////////////////////////////// + + public void setContentLength(long len) { - setHeader(HTTP.CONTENT_TYPE, type); - } - - public String getContentType() - { - return getHeaderValue(HTTP.CONTENT_TYPE); - } - - //////////////////////////////////////////////// - // ContentLength - //////////////////////////////////////////////// - - public void setContentLength(long len) - { - setLongHeader(HTTP.CONTENT_LENGTH, len); - } - - public long getContentLength() - { - return getLongHeaderValue(HTTP.CONTENT_LENGTH); - } - + setLongHeader(HTTP.CONTENT_LENGTH, len); + } + + public long getContentLength() + { + return getLongHeaderValue(HTTP.CONTENT_LENGTH); + } + //////////////////////////////////////////////// // Connection //////////////////////////////////////////////// @@ -650,21 +650,21 @@ public class HTTPPacket try { range[0] = Long.parseLong(firstPosStr); } - catch (NumberFormatException e) {} + catch (NumberFormatException e) {}; if (strToken.hasMoreTokens() == false) return range; String lastPosStr = strToken.nextToken("-/"); try { range[1] = Long.parseLong(lastPosStr); } - catch (NumberFormatException e) {} + catch (NumberFormatException e) {}; if (strToken.hasMoreTokens() == false) return range; String lengthStr = strToken.nextToken("/"); try { range[2] = Long.parseLong(lengthStr); } - catch (NumberFormatException e) {} + catch (NumberFormatException e) {}; return range; } @@ -686,10 +686,10 @@ public class HTTPPacket return range[2]; } - //////////////////////////////////////////////// - // CacheControl - //////////////////////////////////////////////// - + //////////////////////////////////////////////// + // CacheControl + //////////////////////////////////////////////// + public void setCacheControl(String directive) { setHeader(HTTP.CACHE_CONTROL, directive); @@ -701,29 +701,29 @@ public class HTTPPacket setHeader(HTTP.CACHE_CONTROL, strVal); } - public void setCacheControl(int value) - { + public void setCacheControl(int value) + { setCacheControl(HTTP.MAX_AGE, value); - } - - public String getCacheControl() - { - return getHeaderValue(HTTP.CACHE_CONTROL); - } - - //////////////////////////////////////////////// - // Server - //////////////////////////////////////////////// - - public void setServer(String name) - { - setHeader(HTTP.SERVER, name); - } - - public String getServer() - { - return getHeaderValue(HTTP.SERVER); - } + } + + public String getCacheControl() + { + return getHeaderValue(HTTP.CACHE_CONTROL); + } + + //////////////////////////////////////////////// + // Server + //////////////////////////////////////////////// + + public void setServer(String name) + { + setHeader(HTTP.SERVER, name); + } + + public String getServer() + { + return getHeaderValue(HTTP.SERVER); + } //////////////////////////////////////////////// // Host @@ -742,21 +742,21 @@ public class HTTPPacket return getHeaderValue(HTTP.HOST); } - - //////////////////////////////////////////////// - // Date - //////////////////////////////////////////////// - - public void setDate(Calendar cal) - { - Date date = new Date(cal); - setHeader(HTTP.DATE, date.getDateString()); - } - - public String getDate() - { - return getHeaderValue(HTTP.DATE); - } + + //////////////////////////////////////////////// + // Date + //////////////////////////////////////////////// + + public void setDate(Calendar cal) + { + Date date = new Date(cal); + setHeader(HTTP.DATE, date.getDateString()); + } + + public String getDate() + { + return getHeaderValue(HTTP.DATE); + } //////////////////////////////////////////////// // Connection @@ -804,5 +804,5 @@ public class HTTPPacket return false; } */ -} - +} + diff --git a/router/java/src/org/cybergarage/http/HTTPRequest.java b/router/java/src/org/cybergarage/http/HTTPRequest.java index c1c3b50f6..9e03adc89 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 * - Add a relative URL check to setURI(). @@ -46,24 +46,24 @@ * - Changed post() to suppot chunked stream. * ******************************************************************/ - + package org.cybergarage.http; - -import java.io.*; -import java.net.*; + +import java.io.*; +import java.net.*; import java.util.*; import org.cybergarage.util.Debug; - -public class HTTPRequest extends HTTPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPRequest() - { - } + +public class HTTPRequest extends HTTPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPRequest() + { + } public HTTPRequest(InputStream in) { @@ -76,23 +76,23 @@ public class HTTPRequest extends HTTPPacket setSocket(httpSock); } - //////////////////////////////////////////////// - // Method - //////////////////////////////////////////////// - - private String method = null; - - public void setMethod(String value) + //////////////////////////////////////////////// + // Method + //////////////////////////////////////////////// + + private String method = null; + + public void setMethod(String value) + { + method = value; + } + + public String getMethod() { - method = value; - } - - public String getMethod() - { - if (method != null) + if (method != null) return method; - return getFirstLineToken(0); - } + return getFirstLineToken(0); + } public boolean isMethod(String method) { @@ -101,16 +101,16 @@ public class HTTPRequest extends HTTPPacket return false; return headerMethod.equalsIgnoreCase(method); } - - public boolean isGetRequest() - { - return isMethod(HTTP.GET); - } - - public boolean isPostRequest() + + public boolean isGetRequest() { + return isMethod(HTTP.GET); + } + + public boolean isPostRequest() + { return isMethod(HTTP.POST); - } + } public boolean isHeadRequest() { @@ -132,33 +132,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 (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 //////////////////////////////////////////////// @@ -166,17 +166,17 @@ public class HTTPRequest extends HTTPPacket public ParameterList getParameterList() { ParameterList paramList = new ParameterList(); - String _uri = getURI(); - if (_uri == null) + String uri = getURI(); + if (uri == null) return paramList; - int paramIdx = _uri.indexOf('?'); + int paramIdx = uri.indexOf('?'); if (paramIdx < 0) return paramList; while (0 < paramIdx) { - int eqIdx = _uri.indexOf('=', (paramIdx+1)); - String name = _uri.substring(paramIdx+1, eqIdx); - int nextParamIdx = _uri.indexOf('&', (eqIdx+1)); - String value = _uri.substring(eqIdx+1, (0 < nextParamIdx) ? nextParamIdx : _uri.length()); + int eqIdx = uri.indexOf('=', (paramIdx+1)); + String name = uri.substring(paramIdx+1, eqIdx); + int nextParamIdx = uri.indexOf('&', (eqIdx+1)); + String value = uri.substring(eqIdx+1, (0 < nextParamIdx) ? nextParamIdx : uri.length()); Parameter param = new Parameter(name, value); paramList.add(param); paramIdx = nextParamIdx; @@ -227,21 +227,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 @@ -256,25 +256,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 @@ -292,22 +292,22 @@ public class HTTPRequest extends HTTPPacket return getMethod() + " " + getURI() + " " + getHTTPVersion() + HTTP.CRLF; } - //////////////////////////////////////////////// - // getHeader - //////////////////////////////////////////////// - - public String getHeader() - { - StringBuilder str = new StringBuilder(); - - str.append(getFirstLineString()); - + //////////////////////////////////////////////// + // getHeader + //////////////////////////////////////////////// + + public String getHeader() + { + StringBuilder str = new StringBuilder(); + + str.append(getFirstLineString()); + String headerString = getHeaderString(); str.append(headerString); - - return str.toString(); - } - + + return str.toString(); + } + //////////////////////////////////////////////// // isKeepAlive //////////////////////////////////////////////// @@ -334,9 +334,9 @@ public class HTTPRequest extends HTTPPacket return super.read(getSocket()); } - //////////////////////////////////////////////// - // POST (Response) - //////////////////////////////////////////////// + //////////////////////////////////////////////// + // POST (Response) + //////////////////////////////////////////////// public boolean post(HTTPResponse httpRes) { @@ -361,15 +361,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(); setConnection((isKeepAlive == true) ? HTTP.KEEP_ALIVE : HTTP.CLOSE); @@ -396,9 +396,9 @@ public class HTTPRequest extends HTTPPacket postSocket.connect(sa, 3000); } - out = postSocket.getOutputStream(); - PrintStream pout = new PrintStream(out); - pout.print(getHeader()); + out = postSocket.getOutputStream(); + PrintStream pout = new PrintStream(out); + pout.print(getHeader()); pout.print(HTTP.CRLF); boolean isChunkedRequest = isChunked(); @@ -407,7 +407,7 @@ public class HTTPRequest extends HTTPPacket int contentLength = 0; if (content != null) contentLength = content.length(); - + if (0 < contentLength) { if (isChunkedRequest == true) { String chunSizeBuf = Long.toString(contentLength); @@ -424,34 +424,34 @@ public class HTTPRequest extends HTTPPacket pout.print(HTTP.CRLF); } - pout.flush(); + pout.flush(); in = postSocket.getInputStream(); httpRes.set(in, isHeaderRequest); - } + } catch (Exception e) { - httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); + httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); // I2P addition Debug.warning(e); } finally { if (isKeepAlive == false) { try { in.close(); - } catch (Exception e) {} + } catch (Exception e) {}; if (in != null) try { out.close(); - } catch (Exception e) {} + } catch (Exception e) {}; if (out != null) try { postSocket.close(); - } catch (Exception e) {} + } catch (Exception e) {}; postSocket = null; } } return httpRes; - } + } public HTTPResponse post(String host, int port) { @@ -490,21 +490,20 @@ public class HTTPRequest extends HTTPPacket return returnResponse(HTTPStatus.BAD_REQUEST); } - //////////////////////////////////////////////// - // toString - //////////////////////////////////////////////// - - @Override - public String toString() - { - StringBuilder str = new StringBuilder(); - - str.append(getHeader()); - str.append(HTTP.CRLF); - str.append(getContentString()); - - return str.toString(); - } + //////////////////////////////////////////////// + // toString + //////////////////////////////////////////////// + + public String toString() + { + StringBuilder str = new StringBuilder(); + + 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/HTTPResponse.java b/router/java/src/org/cybergarage/http/HTTPResponse.java index 9d6818083..fd5700c26 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.*; import org.cybergarage.util.Debug; - -public class HTTPResponse extends HTTPPacket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPResponse() - { + +public class HTTPResponse extends HTTPPacket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPResponse() + { 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,26 +78,25 @@ public class HTTPResponse extends HTTPPacket { return "HTTP/" + getVersion() + " " + getStatusCode() + " " + HTTPStatus.code2String(statusCode) + HTTP.CRLF; } - - //////////////////////////////////////////////// - // getHeader - //////////////////////////////////////////////// - - public String getHeader() - { - StringBuilder str = new StringBuilder(); - - str.append(getStatusLineString()); + + //////////////////////////////////////////////// + // getHeader + //////////////////////////////////////////////// + + public String getHeader() + { + StringBuilder str = new StringBuilder(); + + str.append(getStatusLineString()); str.append(getHeaderString()); - - return str.toString(); - } + + return str.toString(); + } //////////////////////////////////////////////// // toString //////////////////////////////////////////////// - @Override public String toString() { StringBuilder str = new StringBuilder(); diff --git a/router/java/src/org/cybergarage/http/HTTPServerThread.java b/router/java/src/org/cybergarage/http/HTTPServerThread.java index ea3854010..40351ecaf 100644 --- a/router/java/src/org/cybergarage/http/HTTPServerThread.java +++ b/router/java/src/org/cybergarage/http/HTTPServerThread.java @@ -37,7 +37,6 @@ public class HTTPServerThread extends Thread // run //////////////////////////////////////////////// - @Override public void run() { HTTPSocket httpSock = new HTTPSocket(sock); diff --git a/router/java/src/org/cybergarage/http/HTTPSocket.java b/router/java/src/org/cybergarage/http/HTTPSocket.java index e75573356..6709aa41a 100644 --- a/router/java/src/org/cybergarage/http/HTTPSocket.java +++ b/router/java/src/org/cybergarage/http/HTTPSocket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: HTTPSocket.java -* -* Revision; -* -* 12/12/02 -* - first revision. +* +* Revision; +* +* 12/12/02 +* - first revision. * 03/11/04 * - Added the following methods about chunk size. * setChunkSize(), getChunkSize(). @@ -19,24 +19,24 @@ * - Changed post() to suppot chunked stream. * ******************************************************************/ - -package org.cybergarage.http; - -import java.io.*; -import java.net.*; + +package org.cybergarage.http; + +import java.io.*; +import java.net.*; import java.util.*; - -public class HTTPSocket -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public HTTPSocket(Socket socket) - { - setSocket(socket); + +public class HTTPSocket +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public HTTPSocket(Socket socket) + { + setSocket(socket); open(); - } + } public HTTPSocket(HTTPSocket socket) { @@ -45,12 +45,11 @@ public class HTTPSocket setOutputStream(socket.getOutputStream()); } - @Override - public void finalize() - { - close(); - } - + public void finalize() + { + close(); + } + //////////////////////////////////////////////// // Socket //////////////////////////////////////////////// @@ -87,27 +86,27 @@ public class HTTPSocket private InputStream sockIn = null; private OutputStream sockOut = null; - + private void setInputStream(InputStream in) { sockIn = in; } - public InputStream getInputStream() - { - return sockIn; - } + public InputStream getInputStream() + { + return sockIn; + } private void setOutputStream(OutputStream out) { sockOut = out; } - - private OutputStream getOutputStream() - { - return sockOut; - } - + + private OutputStream getOutputStream() + { + return sockOut; + } + //////////////////////////////////////////////// // open/close //////////////////////////////////////////////// @@ -141,20 +140,20 @@ public class HTTPSocket return true; } - //////////////////////////////////////////////// - // post - //////////////////////////////////////////////// - - private boolean post(HTTPResponse httpRes, byte content[], long contentOffset, long contentLength, boolean isOnlyHeader) - { + //////////////////////////////////////////////// + // post + //////////////////////////////////////////////// + + private boolean post(HTTPResponse httpRes, byte content[], long contentOffset, long contentLength, boolean isOnlyHeader) + { httpRes.setDate(Calendar.getInstance()); - OutputStream out = getOutputStream(); - + OutputStream out = getOutputStream(); + try { httpRes.setContentLength(contentLength); - - out.write(httpRes.getHeader().getBytes()); - out.write(HTTP.CRLF.getBytes()); + + out.write(httpRes.getHeader().getBytes()); + out.write(HTTP.CRLF.getBytes()); if (isOnlyHeader == true) { out.flush(); return true; @@ -175,17 +174,17 @@ public class HTTPSocket out.write("0".getBytes()); out.write(HTTP.CRLF.getBytes()); } - - out.flush(); - } - catch (Exception e) { - //Debug.warning(e); + + out.flush(); + } + catch (Exception e) { + //Debug.warning(e); return false; } - return true; + return true; } - + private boolean post(HTTPResponse httpRes, InputStream in, long contentOffset, long contentLength, boolean isOnlyHeader) { httpRes.setDate(Calendar.getInstance()); diff --git a/router/java/src/org/cybergarage/net/HostInterface.java b/router/java/src/org/cybergarage/net/HostInterface.java index 237dfb640..798f33dca 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,14 +22,14 @@ * - Changed isUseAddress() to isUsableAddress(). * ******************************************************************/ - -package org.cybergarage.net; - -import java.net.*; + +package org.cybergarage.net; + +import java.net.*; import java.util.*; - -public class HostInterface -{ + +public class HostInterface +{ //////////////////////////////////////////////// // Constants //////////////////////////////////////////////// @@ -101,7 +101,7 @@ public class HostInterface } } } - catch(Exception e){} + catch(Exception e){}; return nHostAddrs; } @@ -131,7 +131,7 @@ public class HostInterface } } } - catch(Exception e){} + catch(Exception e){}; return ""; } diff --git a/router/java/src/org/cybergarage/soap/SOAPRequest.java b/router/java/src/org/cybergarage/soap/SOAPRequest.java index 7fa54871c..35d31345f 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 , Inma Marin Lopez . * - Added XML header, to setContent(). @@ -17,28 +17,28 @@ * - Changed the XML header to in setContent(). * ******************************************************************/ - -package org.cybergarage.soap; - -import java.io.*; - -import org.cybergarage.http.*; -import org.cybergarage.xml.*; -import org.cybergarage.util.*; - -public class SOAPRequest extends HTTPRequest + +package org.cybergarage.soap; + +import java.io.*; + +import org.cybergarage.http.*; +import org.cybergarage.xml.*; +import org.cybergarage.util.*; + +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) { @@ -71,33 +71,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 @@ -170,7 +170,6 @@ public class SOAPRequest extends HTTPRequest // print //////////////////////////////////////////////// - @Override public void print() { Debug.message(toString()); diff --git a/router/java/src/org/cybergarage/soap/SOAPResponse.java b/router/java/src/org/cybergarage/soap/SOAPResponse.java index 51f0abf73..d21ac857f 100644 --- a/router/java/src/org/cybergarage/soap/SOAPResponse.java +++ b/router/java/src/org/cybergarage/soap/SOAPResponse.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002 * * File: SOAPResponse.java -* -* Revision; -* -* 12/17/02 -* - first revision. +* +* Revision; +* +* 12/17/02 +* - first revision. * 02/13/04 * - Ralf G. R. Bergs , Inma Marin Lopez . * - Added XML header, to setContent(). @@ -17,24 +17,24 @@ * - Changed the XML header to in setContent(). * ******************************************************************/ - -package org.cybergarage.soap; - -import org.cybergarage.http.*; + +package org.cybergarage.soap; + +import org.cybergarage.http.*; import org.cybergarage.util.Debug; -import org.cybergarage.xml.*; - -public class SOAPResponse extends HTTPResponse -{ - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SOAPResponse() +import org.cybergarage.xml.*; + +public class SOAPResponse extends HTTPResponse +{ + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SOAPResponse() { setRootNode(SOAP.createEnvelopeBodyNode()); setContentType(XML.CONTENT_TYPE); - } + } public SOAPResponse(HTTPResponse httpRes) { @@ -50,25 +50,25 @@ public class SOAPResponse extends HTTPResponse setContentType(XML.CONTENT_TYPE); } - //////////////////////////////////////////////// - // Node - //////////////////////////////////////////////// - - private Node rootNode; - - private void setRootNode(Node node) - { + //////////////////////////////////////////////// + // Node + //////////////////////////////////////////////// + + private Node rootNode; + + private void setRootNode(Node node) + { rootNode = node; - } - - private Node getRootNode() - { - return rootNode; - } - - //////////////////////////////////////////////// - // SOAP Basic - //////////////////////////////////////////////// + } + + private Node getRootNode() + { + return rootNode; + } + + //////////////////////////////////////////////// + // SOAP Basic + //////////////////////////////////////////////// public void setEnvelopeNode(Node node) { @@ -79,88 +79,88 @@ public class SOAPResponse extends HTTPResponse { return getRootNode(); } - - public Node getBodyNode() - { - Node envNode = getEnvelopeNode(); - if (envNode == null) - return null; - return envNode.getNodeEndsWith(SOAP.BODY); - } - - public Node getMethodResponseNode(String name) - { - Node bodyNode = getBodyNode(); - if (bodyNode == null) - return null; - String methodResName = name + SOAP.RESPONSE; - return bodyNode.getNodeEndsWith(methodResName); - } - - public Node getFaultNode() - { - Node bodyNode = getBodyNode(); - if (bodyNode == null) - return null; - return bodyNode.getNodeEndsWith(SOAP.FAULT); - } - - public Node getFaultCodeNode() - { - Node faultNode = getFaultNode(); - if (faultNode == null) - return null; - return faultNode.getNodeEndsWith(SOAP.FAULT_CODE); - } - - public Node getFaultStringNode() - { - Node faultNode = getFaultNode(); - if (faultNode == null) - return null; - return faultNode.getNodeEndsWith(SOAP.FAULT_STRING); - } - - public Node getFaultActorNode() - { - Node faultNode = getFaultNode(); - if (faultNode == null) - return null; - return faultNode.getNodeEndsWith(SOAP.FAULTACTOR); - } - - public Node getFaultDetailNode() - { - Node faultNode = getFaultNode(); - if (faultNode == null) - return null; - return faultNode.getNodeEndsWith(SOAP.DETAIL); - } - - public String getFaultCode() - { - Node node = getFaultCodeNode(); - if (node == null) - return ""; - return node.getValue(); - } - - public String getFaultString() - { - Node node = getFaultStringNode(); - if (node == null) - return ""; - return node.getValue(); - } - - public String getFaultActor() - { - Node node = getFaultActorNode(); - if (node == null) - return ""; - return node.getValue(); - } - + + public Node getBodyNode() + { + Node envNode = getEnvelopeNode(); + if (envNode == null) + return null; + return envNode.getNodeEndsWith(SOAP.BODY); + } + + public Node getMethodResponseNode(String name) + { + Node bodyNode = getBodyNode(); + if (bodyNode == null) + return null; + String methodResName = name + SOAP.RESPONSE; + return bodyNode.getNodeEndsWith(methodResName); + } + + public Node getFaultNode() + { + Node bodyNode = getBodyNode(); + if (bodyNode == null) + return null; + return bodyNode.getNodeEndsWith(SOAP.FAULT); + } + + public Node getFaultCodeNode() + { + Node faultNode = getFaultNode(); + if (faultNode == null) + return null; + return faultNode.getNodeEndsWith(SOAP.FAULT_CODE); + } + + public Node getFaultStringNode() + { + Node faultNode = getFaultNode(); + if (faultNode == null) + return null; + return faultNode.getNodeEndsWith(SOAP.FAULT_STRING); + } + + public Node getFaultActorNode() + { + Node faultNode = getFaultNode(); + if (faultNode == null) + return null; + return faultNode.getNodeEndsWith(SOAP.FAULTACTOR); + } + + public Node getFaultDetailNode() + { + Node faultNode = getFaultNode(); + if (faultNode == null) + return null; + return faultNode.getNodeEndsWith(SOAP.DETAIL); + } + + public String getFaultCode() + { + Node node = getFaultCodeNode(); + if (node == null) + return ""; + return node.getValue(); + } + + public String getFaultString() + { + Node node = getFaultStringNode(); + if (node == null) + return ""; + return node.getValue(); + } + + public String getFaultActor() + { + Node node = getFaultActorNode(); + if (node == null) + return ""; + return node.getValue(); + } + //////////////////////////////////////////////// // XML Contents //////////////////////////////////////////////// @@ -179,7 +179,6 @@ public class SOAPResponse extends HTTPResponse // print //////////////////////////////////////////////// - @Override public void print() { Debug.message(toString()); diff --git a/router/java/src/org/cybergarage/upnp/Action.java b/router/java/src/org/cybergarage/upnp/Action.java index 84fcb33d8..b58c1132a 100644 --- a/router/java/src/org/cybergarage/upnp/Action.java +++ b/router/java/src/org/cybergarage/upnp/Action.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2004 * * File: Action.java -* -* Revision; -* -* 12/05/02 -* - first revision. +* +* Revision; +* +* 12/05/02 +* - first revision. * 08/30/03 * - Gordano Sassaroli * - Problem : When invoking an action that has at least one out parameter, an error message is returned @@ -24,61 +24,61 @@ * - Changed postControlAction() to set the status code to the UPnPStatus. * ******************************************************************/ - -package org.cybergarage.upnp; + +package org.cybergarage.upnp; import org.cybergarage.xml.*; import org.cybergarage.util.*; - -import org.cybergarage.upnp.xml.*; + +import org.cybergarage.upnp.xml.*; import org.cybergarage.upnp.control.*; - -public class Action -{ - //////////////////////////////////////////////// - // Constants - //////////////////////////////////////////////// - - public final static String ELEM_NAME = "action"; - - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private Node serviceNode; - private Node actionNode; - - private Node getServiceNode() - { - return serviceNode; - } - - public Service getService() - { - return new Service(getServiceNode()); - } - - public Node getActionNode() - { - return actionNode; - } - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public Action(Node serviceNode, Node actionNode) - { - this.serviceNode = serviceNode; - this.actionNode = actionNode; - } + +public class Action +{ + //////////////////////////////////////////////// + // Constants + //////////////////////////////////////////////// + + public final static String ELEM_NAME = "action"; + + //////////////////////////////////////////////// + // Member + //////////////////////////////////////////////// + + private Node serviceNode; + private Node actionNode; + + private Node getServiceNode() + { + return serviceNode; + } + + public Service getService() + { + return new Service(getServiceNode()); + } + + public Node getActionNode() + { + return actionNode; + } + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public Action(Node serviceNode, Node actionNode) + { + this.serviceNode = serviceNode; + this.actionNode = actionNode; + } public Action(Action action) { this.serviceNode = action.getServiceNode(); this.actionNode = action.getActionNode(); } - + //////////////////////////////////////////////// // Mutex //////////////////////////////////////////////// @@ -95,50 +95,50 @@ public class Action mutex.unlock(); } - //////////////////////////////////////////////// - // isActionNode - //////////////////////////////////////////////// - - public static boolean isActionNode(Node node) - { - return Action.ELEM_NAME.equals(node.getName()); - } - - //////////////////////////////////////////////// - // name - //////////////////////////////////////////////// - - private final static String NAME = "name"; - - public void setName(String value) - { - getActionNode().setNode(NAME, value); - } - - public String getName() - { - return getActionNode().getNodeValue(NAME); - } - - //////////////////////////////////////////////// - // argumentList - //////////////////////////////////////////////// - - public ArgumentList getArgumentList() - { - ArgumentList argumentList = new ArgumentList(); - Node argumentListNode = getActionNode().getNode(ArgumentList.ELEM_NAME); - if (argumentListNode == null) - return argumentList; - int nodeCnt = argumentListNode.getNNodes(); - for (int n=0; n * - Changed open(addr, port) to send IPv6 SSDP packets. @@ -20,47 +20,46 @@ * - Added to set a current timestamp when the packet are received. * ******************************************************************/ - -package org.cybergarage.upnp.ssdp; - -import java.net.*; - -import org.cybergarage.util.*; - -public class HTTPUSocket -{ - //////////////////////////////////////////////// - // Member - //////////////////////////////////////////////// - - private DatagramSocket ssdpUniSock = null; + +package org.cybergarage.upnp.ssdp; + +import java.net.*; + +import org.cybergarage.util.*; + +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); } - - @Override + protected void finalize() { close(); @@ -142,66 +141,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 - //////////////////////////////////////////////// - - 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); + //////////////////////////////////////////////// + // send + //////////////////////////////////////////////// + + public boolean post(String addr, int port, String msg) + { + try { + InetAddress inetAddr = InetAddress.getByName(addr); + DatagramPacket dgmPacket = new DatagramPacket(msg.getBytes(), msg.length(), inetAddr, port); ssdpUniSock.send(dgmPacket); - } + } catch (Exception e) { - Debug.warning("addr = " +ssdpUniSock.getLocalAddress().getHostName()); + Debug.warning("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 @@ -236,5 +235,5 @@ public class HTTPUSocket return true; } */ -} - +} + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifySocket.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifySocket.java index ad5c26f75..75484bd16 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifySocket.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPNotifySocket.java @@ -5,11 +5,11 @@ * Copyright (C) Satoshi Konno 2002-2003 * * File: SSDPNotifySocket.java -* -* Revision; -* -* 11/20/02 -* - first revision. +* +* Revision; +* +* 11/20/02 +* - first revision. * 05/13/03 * - Added support for IPv6. * 02/20/04 @@ -21,24 +21,25 @@ * - Added close() in stop(). * ******************************************************************/ + +package org.cybergarage.upnp.ssdp; -package org.cybergarage.upnp.ssdp; - -import java.net.*; +import java.net.*; import org.cybergarage.net.*; +import org.cybergarage.util.*; import org.cybergarage.http.*; -import org.cybergarage.upnp.*; - -public class SSDPNotifySocket extends HTTPMUSocket implements Runnable +import org.cybergarage.upnp.*; + +public class SSDPNotifySocket extends HTTPMUSocket implements Runnable { private boolean useIPv6Address; - - //////////////////////////////////////////////// - // Constructor - //////////////////////////////////////////////// - - public SSDPNotifySocket(String bindAddr) + + //////////////////////////////////////////////// + // Constructor + //////////////////////////////////////////////// + + public SSDPNotifySocket(String bindAddr) { String addr = SSDP.ADDRESS; useIPv6Address = false; @@ -47,24 +48,24 @@ public class SSDPNotifySocket extends HTTPMUSocket implements Runnable useIPv6Address = true; } open(addr, SSDP.PORT, bindAddr); - setControlPoint(null); - } - - //////////////////////////////////////////////// - // ControlPoint - //////////////////////////////////////////////// - - private ControlPoint controlPoint = null; - - public void setControlPoint(ControlPoint ctrlp) - { - this.controlPoint = ctrlp; - } - - public ControlPoint getControlPoint() - { - return controlPoint; - } + setControlPoint(null); + } + + //////////////////////////////////////////////// + // ControlPoint + //////////////////////////////////////////////// + + private ControlPoint controlPoint = null; + + public void setControlPoint(ControlPoint ctrlp) + { + this.controlPoint = ctrlp; + } + + public ControlPoint getControlPoint() + { + return controlPoint; + } //////////////////////////////////////////////// // post (SSDPNotifySocket) @@ -79,20 +80,20 @@ public class SSDPNotifySocket extends HTTPMUSocket implements Runnable return post((HTTPRequest)req); } - //////////////////////////////////////////////// - // run - //////////////////////////////////////////////// - - private Thread deviceNotifyThread = null; - - public void run() - { + //////////////////////////////////////////////// + // run + //////////////////////////////////////////////// + + private Thread deviceNotifyThread = null; + + public void run() + { Thread thisThread = Thread.currentThread(); - + ControlPoint ctrlPoint = getControlPoint(); - - while (deviceNotifyThread == thisThread) { - Thread.yield(); + + while (deviceNotifyThread == thisThread) { + Thread.yield(); SSDPPacket packet = receive(); // Thanks for Mikael Hakman (04/20/05) @@ -109,23 +110,23 @@ public class SSDPNotifySocket extends HTTPMUSocket implements Runnable } if (ctrlPoint != null) - ctrlPoint.notifyReceived(packet); - } - } - - public void start() - { + ctrlPoint.notifyReceived(packet); + } + } + + public void start() + { deviceNotifyThread = new Thread(this, "UPnP-SSDPNotifySocket"); - deviceNotifyThread.setDaemon(true); - deviceNotifyThread.start(); - } - - public void stop() - { + deviceNotifyThread.setDaemon(true); + deviceNotifyThread.start(); + } + + public void stop() + { // Thanks for Mikael Hakman (04/20/05) close(); - deviceNotifyThread = null; - } + deviceNotifyThread = null; + } } - + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPPacket.java index 717856f93..d2e0f2770 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,48 +197,47 @@ 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 //////////////////////////////////////////////// - @Override public String toString() { return new String(getData()); } } - + diff --git a/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java b/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java index 3bbbfcbb8..31b4ed280 100644 --- a/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java +++ b/router/java/src/org/cybergarage/upnp/ssdp/SSDPResponse.java @@ -112,7 +112,6 @@ public class SSDPResponse extends HTTPResponse // getHeader (Override) //////////////////////////////////////////////// - @Override public String getHeader() { StringBuilder str = new StringBuilder(); diff --git a/router/java/src/org/cybergarage/util/ListenerList.java b/router/java/src/org/cybergarage/util/ListenerList.java index b02c0ddc8..afdeff0d6 100644 --- a/router/java/src/org/cybergarage/util/ListenerList.java +++ b/router/java/src/org/cybergarage/util/ListenerList.java @@ -3,7 +3,7 @@ * CyberUtil for Java * * Copyright (C) Satoshi Konno 2002 -* +* * File: ListenerList.java * * Revision; @@ -12,16 +12,15 @@ * - first revision. * ******************************************************************/ - + package org.cybergarage.util; import java.util.*; - + public class ListenerList extends Vector { private static final long serialVersionUID = 8039231561720446173L; - @Override public boolean add(Object obj) { if (0 <= indexOf(obj)) diff --git a/router/java/src/org/cybergarage/util/Mutex.java b/router/java/src/org/cybergarage/util/Mutex.java index aa13afe62..f26351271 100644 --- a/router/java/src/org/cybergarage/util/Mutex.java +++ b/router/java/src/org/cybergarage/util/Mutex.java @@ -40,7 +40,7 @@ public class Mutex } catch (Exception e) { Debug.warning(e); - } + }; } syncLock = true; } diff --git a/router/java/src/org/cybergarage/xml/Node.java b/router/java/src/org/cybergarage/xml/Node.java index 4fee0fdee..93ca5aa0b 100644 --- a/router/java/src/org/cybergarage/xml/Node.java +++ b/router/java/src/org/cybergarage/xml/Node.java @@ -74,10 +74,10 @@ public class Node public Node getRootNode() { Node rootNode = null; - Node _parentNode = getParentNode(); - while (_parentNode != null) { - rootNode = _parentNode; - _parentNode = rootNode.getParentNode(); + Node parentNode = getParentNode(); + while (parentNode != null) { + rootNode = parentNode; + parentNode = rootNode.getParentNode(); } return rootNode; } @@ -338,24 +338,24 @@ public class Node { String indentString = getIndentLevelString(indentLevel); - String _name = getName(); - String _value = getValue(); + String name = getName(); + String value = getValue(); if (hasNodes() == false || hasChildNode == false) { - ps.print(indentString + "<" + _name); + ps.print(indentString + "<" + name); outputAttributes(ps); // Thnaks for Tho Beisch (11/09/04) - if (_value == null || _value.length() == 0) { + if (value == null || value.length() == 0) { // No value, so use short notation ps.println(" />"); } else { - ps.println(">" + XML.escapeXMLChars(_value) + ""); + ps.println(">" + XML.escapeXMLChars(value) + ""); } return; } - ps.print(indentString + "<" + _name); + ps.print(indentString + "<" + name); outputAttributes(ps); ps.println(">"); @@ -365,7 +365,7 @@ public class Node cnode.output(ps, indentLevel+1, true); } - ps.println(indentString +""); + ps.println(indentString +""); } public String toString(boolean hasChildNode)