Revert all changes to the org/cybergarage library

in the 2009-08-11 whitespace cleanup at ef1c23821d433903124f7612cbc46ac096fc985b
to make merging with the newer library easier.
This commit is contained in:
zzz
2012-05-25 19:52:39 +00:00
parent 3fbff71861
commit b033db969c
27 changed files with 2253 additions and 2267 deletions

View File

@ -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));
}
}

View File

@ -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 <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.*;
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 <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)
{
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;
}
}
}
}

View File

@ -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 <sassarol@cefriel.it>
* - 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 <sassarol@cefriel.it> (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<nHeaders; n++) {
HTTPHeader header = getHeader(n);
String headerName = header.getName();
if (headerName.equalsIgnoreCase(name) == true)
return header;
}
return null;
}
////////////////////////////////////////////////
// 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<nHeaders; n++) {
HTTPHeader header = getHeader(n);
String headerName = header.getName();
if (headerName.equalsIgnoreCase(name) == true)
return header;
}
return null;
}
public void clearHeaders()
{
@ -364,16 +364,16 @@ public class HTTPPacket
{
return (getHeader(name) != null) ? true : false;
}
public void setHeader(String name, String value)
{
HTTPHeader header = getHeader(name);
if (header != null) {
header.setValue(value);
return;
}
addHeader(name, value);
}
public void setHeader(String name, String value)
{
HTTPHeader header = getHeader(name);
if (header != null) {
header.setValue(value);
return;
}
addHeader(name, value);
}
public void setHeader(String name, int value)
{
@ -384,19 +384,19 @@ public class HTTPPacket
{
setHeader(name, Long.toString(value));
}
public void setHeader(HTTPHeader header)
{
setHeader(header.getName(), header.getValue());
}
public String getHeaderValue(String name)
{
HTTPHeader header = getHeader(name);
if (header == null)
return "";
return header.getValue();
}
public void setHeader(HTTPHeader header)
{
setHeader(header.getName(), header.getValue());
}
public String getHeaderValue(String name)
{
HTTPHeader header = getHeader(name);
if (header == null)
return "";
return header.getValue();
}
////////////////////////////////////////////////
// set*Value
@ -431,7 +431,7 @@ public class HTTPPacket
{
return getStringHeaderValue(name, "\"", "\"");
}
public void setIntegerHeader(String name, int value)
{
setHeader(name, Integer.toString(value));
@ -442,13 +442,13 @@ public class HTTPPacket
setHeader(name, Long.toString(value));
}
public int getIntegerHeaderValue(String name)
{
HTTPHeader header = getHeader(name);
if (header == null)
return 0;
return StringUtil.toInteger(header.getValue());
}
public int getIntegerHeaderValue(String name)
{
HTTPHeader header = getHeader(name);
if (header == null)
return 0;
return StringUtil.toInteger(header.getValue());
}
public long getLongHeaderValue(String name)
{
@ -457,7 +457,7 @@ public class HTTPPacket
return 0;
return StringUtil.toLong(header.getValue());
}
////////////////////////////////////////////////
// getHeader
////////////////////////////////////////////////
@ -475,48 +475,48 @@ public class HTTPPacket
return str.toString();
}
////////////////////////////////////////////////
// Contents
////////////////////////////////////////////////
private byte content[] = new byte[0];
public void setContent(byte data[], boolean updateWithContentLength)
{
////////////////////////////////////////////////
// Contents
////////////////////////////////////////////////
private byte content[] = new byte[0];
public void setContent(byte data[], boolean updateWithContentLength)
{
content = data;
if (updateWithContentLength == true)
setContentLength(data.length);
}
if (updateWithContentLength == true)
setContentLength(data.length);
}
public void setContent(byte data[])
{
setContent(data, true);
}
public void setContent(String data, boolean updateWithContentLength)
{
setContent(data.getBytes(), updateWithContentLength);
}
public void setContent(String data, boolean updateWithContentLength)
{
setContent(data.getBytes(), updateWithContentLength);
}
public void setContent(String data)
{
setContent(data, true);
}
public byte []getContent()
{
return content;
}
public String getContentString()
{
return new String(content);
public byte []getContent()
{
return content;
}
public String getContentString()
{
return new String(content);
}
public boolean hasContent()
{
return (content.length > 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;
}
*/
}
}

View File

@ -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().
@ -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 <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
////////////////////////////////////////////////
@ -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()
{

View File

@ -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();

View File

@ -37,7 +37,6 @@ public class HTTPServerThread extends Thread
// run
////////////////////////////////////////////////
@Override
public void run()
{
HTTPSocket httpSock = new HTTPSocket(sock);

View File

@ -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());

View File

@ -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 "";
}

View File

@ -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,28 +17,28 @@
* - Changed the XML header to <?xml version="1.0" encoding="utf-8"?> 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());

View File

@ -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 <Ralf@Ber.gs>, Inma Marin Lopez <inma@dif.um.es>.
* - Added XML header, <?xml version="1.0"?> to setContent().
@ -17,24 +17,24 @@
* - Changed the XML header to <?xml version="1.0" encoding="utf-8"?> 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());

View File

@ -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 <sassarol@cefriel.it>
* - 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<nodeCnt; n++) {
Node node = argumentListNode.getNode(n);
if (Argument.isArgumentNode(node) == false)
continue;
Argument argument = new Argument(getServiceNode(), node);
argumentList.add(argument);
}
return argumentList;
////////////////////////////////////////////////
// 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<nodeCnt; n++) {
Node node = argumentListNode.getNode(n);
if (Argument.isArgumentNode(node) == false)
continue;
Argument argument = new Argument(getServiceNode(), node);
argumentList.add(argument);
}
return argumentList;
}
public ArgumentList getInputArgumentList()
@ -179,7 +179,7 @@ public class Action
if (argName == null)
continue;
if (name.equals(argName) == true)
return arg;
return arg;
}
return null;
}
@ -272,8 +272,8 @@ public class Action
actionRes.setResponse(this);
}
else {
UPnPStatus _upnpStatus = getStatus();
actionRes.setFaultResponse(_upnpStatus.getCode(), _upnpStatus.getDescription());
UPnPStatus upnpStatus = getStatus();
actionRes.setFaultResponse(upnpStatus.getCode(), upnpStatus.getDescription());
}
if (Debug.isOn() == true)
actionRes.print();

View File

@ -5,11 +5,11 @@
* Copyright (C) Satoshi Konno 2002-2004
*
* File: ControlPoint.java
*
* Revision:
*
* 11/18/02
* - first revision.
*
* Revision:
*
* 11/18/02
* - first revision.
* 05/13/03
* - Changed to create socket threads each local interfaces.
* (HTTP, SSDPNotiry, SSDPSerachResponse)
@ -56,35 +56,35 @@
* - Changed addDevice() to use Parser::parse(URL).
*
*******************************************************************/
package org.cybergarage.upnp;
package org.cybergarage.upnp;
import org.cybergarage.net.*;
import org.cybergarage.util.*;
import org.cybergarage.xml.*;
import org.cybergarage.http.*;
import org.cybergarage.upnp.control.*;
import org.cybergarage.upnp.ssdp.*;
import org.cybergarage.upnp.ssdp.*;
import org.cybergarage.upnp.device.*;
import org.cybergarage.upnp.event.*;
import org.cybergarage.upnp.event.*;
import java.net.*;
public class ControlPoint implements HTTPRequestListener
{
public class ControlPoint implements HTTPRequestListener
{
private final static int DEFAULT_EVENTSUB_PORT = 8058;
private final static int DEFAULT_SSDP_PORT = 8008;
private final static int DEFAULT_EXPIRED_DEVICE_MONITORING_INTERVAL = 60;
private final static String DEFAULT_EVENTSUB_URI = "/evetSub";
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
private SSDPNotifySocketList ssdpNotifySocketList;
private SSDPSearchResponseSocketList ssdpSearchResponseSocketList;
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
private SSDPNotifySocketList ssdpNotifySocketList;
private SSDPSearchResponseSocketList ssdpSearchResponseSocketList;
private SSDPNotifySocketList getSSDPNotifySocketList()
{
@ -105,12 +105,12 @@ public class ControlPoint implements HTTPRequestListener
UPnP.initialize();
}
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
public ControlPoint(int ssdpPort, int httpPort)
{
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
public ControlPoint(int ssdpPort, int httpPort)
{
ssdpNotifySocketList = new SSDPNotifySocketList();
ssdpSearchResponseSocketList = new SSDPSearchResponseSocketList();
@ -124,14 +124,13 @@ public class ControlPoint implements HTTPRequestListener
setNMPRMode(false);
setRenewSubscriber(null);
}
}
public ControlPoint()
{
this(DEFAULT_SSDP_PORT, DEFAULT_EVENTSUB_PORT);
}
@Override
public void finalize()
{
stop();
@ -180,7 +179,7 @@ public class ControlPoint implements HTTPRequestListener
public void setHTTPPort(int port) {
httpPort = port;
}
////////////////////////////////////////////////
// NMPR
////////////////////////////////////////////////
@ -197,35 +196,35 @@ public class ControlPoint implements HTTPRequestListener
return nmprMode;
}
////////////////////////////////////////////////
// Device List
////////////////////////////////////////////////
private NodeList devNodeList = new NodeList();
private void addDevice(Node rootNode)
{
devNodeList.add(rootNode);
}
private synchronized void addDevice(SSDPPacket ssdpPacket)
////////////////////////////////////////////////
// Device List
////////////////////////////////////////////////
private NodeList devNodeList = new NodeList();
private void addDevice(Node rootNode)
{
devNodeList.add(rootNode);
}
private synchronized void addDevice(SSDPPacket ssdpPacket)
{
if (ssdpPacket.isRootDevice() == false)
return;
String usn = ssdpPacket.getUSN();
String udn = USN.getUDN(usn);
Device dev = getDevice(udn);
String usn = ssdpPacket.getUSN();
String udn = USN.getUDN(usn);
Device dev = getDevice(udn);
if (dev != null) {
dev.setSSDPPacket(ssdpPacket);
return;
return;
}
String location = ssdpPacket.getLocation();
try {
String location = ssdpPacket.getLocation();
try {
URL locationUrl = new URL(location);
Parser parser = UPnP.getXMLParser();
Node rootNode = parser.parse(locationUrl);
Node rootNode = parser.parse(locationUrl);
Device rootDev = getDevice(rootNode);
if (rootDev == null)
return;
@ -238,16 +237,16 @@ public class ControlPoint implements HTTPRequestListener
// control point application must implement the DeviceChangeListener interface
// to receive the notifications)
performAddDeviceListener( rootDev );
}
}
catch (MalformedURLException me) {
Debug.warning(ssdpPacket.toString());
Debug.warning(me);
}
catch (ParserException pe) {
catch (ParserException pe) {
Debug.warning(ssdpPacket.toString());
Debug.warning(pe);
}
}
Debug.warning(pe);
}
}
private Device getDevice(Node rootNode)
{
@ -258,30 +257,30 @@ public class ControlPoint implements HTTPRequestListener
return null;
return new Device(rootNode, devNode);
}
public DeviceList getDeviceList()
{
DeviceList devList = new DeviceList();
int nRoots = devNodeList.size();
for (int n=0; n<nRoots; n++) {
public DeviceList getDeviceList()
{
DeviceList devList = new DeviceList();
int nRoots = devNodeList.size();
for (int n=0; n<nRoots; n++) {
Node rootNode = devNodeList.getNode(n);
Device dev = getDevice(rootNode);
if (dev == null)
continue;
devList.add(dev);
}
return devList;
}
public Device getDevice(String name)
{
int nRoots = devNodeList.size();
for (int n=0; n<nRoots; n++) {
if (dev == null)
continue;
devList.add(dev);
}
return devList;
}
public Device getDevice(String name)
{
int nRoots = devNodeList.size();
for (int n=0; n<nRoots; n++) {
// AIOOB was thrown from here, maybe would be better to
// copy the list before traversal?
Node rootNode;
try {
rootNode = devNodeList.getNode(n);
rootNode = devNodeList.getNode(n);
} catch (ArrayIndexOutOfBoundsException aioob) {
break;
}
@ -292,18 +291,18 @@ public class ControlPoint implements HTTPRequestListener
return dev;
Device cdev = dev.getDevice(name);
if (cdev != null)
return cdev;
}
return null;
}
public boolean hasDevice(String name)
{
return (getDevice(name) != null) ? true : false;
}
private void removeDevice(Node rootNode)
{
return cdev;
}
return null;
}
public boolean hasDevice(String name)
{
return (getDevice(name) != null) ? true : false;
}
private void removeDevice(Node rootNode)
{
// Thanks for Oliver Newell (2004/10/16)
// Invoke device removal listener prior to actual removal so Device node
// remains valid for the duration of the listener (application may want
@ -312,9 +311,9 @@ public class ControlPoint implements HTTPRequestListener
if( dev != null && dev.isRootDevice() )
performRemoveDeviceListener( dev );
devNodeList.remove(rootNode);
}
devNodeList.remove(rootNode);
}
private void removeDevice(Device dev)
{
if (dev == null)
@ -322,19 +321,19 @@ public class ControlPoint implements HTTPRequestListener
removeDevice(dev.getRootNode());
}
private void removeDevice(String name)
{
Device dev = getDevice(name);
removeDevice(dev);
}
private void removeDevice(SSDPPacket packet)
{
if (packet.isByeBye() == false)
return;
String usn = packet.getUSN();
String udn = USN.getUDN(usn);
removeDevice(udn);
private void removeDevice(String name)
{
Device dev = getDevice(name);
removeDevice(dev);
}
private void removeDevice(SSDPPacket packet)
{
if (packet.isByeBye() == false)
return;
String usn = packet.getUSN();
String udn = USN.getUDN(usn);
removeDevice(udn);
}
////////////////////////////////////////////////
@ -361,7 +360,7 @@ public class ControlPoint implements HTTPRequestListener
public void setExpiredDeviceMonitoringInterval(long interval)
{
expiredDeviceMonitoringInterval = interval;
expiredDeviceMonitoringInterval = interval;
}
public long getExpiredDeviceMonitoringInterval()
@ -379,9 +378,9 @@ public class ControlPoint implements HTTPRequestListener
return deviceDisposer;
}
////////////////////////////////////////////////
////////////////////////////////////////////////
// Notify
////////////////////////////////////////////////
////////////////////////////////////////////////
private ListenerList deviceNotifyListenerList = new ListenerList();
@ -403,7 +402,7 @@ public class ControlPoint implements HTTPRequestListener
listener.deviceNotifyReceived(ssdpPacket);
}
}
////////////////////////////////////////////////
// SearchResponse
////////////////////////////////////////////////
@ -487,12 +486,12 @@ public class ControlPoint implements HTTPRequestListener
addDevice(packet);
performSearchResponseListener(packet);
}
////////////////////////////////////////////////
// M-SEARCH
////////////////////////////////////////////////
////////////////////////////////////////////////
// M-SEARCH
////////////////////////////////////////////////
private int searchMx = SSDP.DEFAULT_MSEARCH_MX;
private int searchMx = SSDP.DEFAULT_MSEARCH_MX;
public int getSearchMx()
{
@ -507,8 +506,8 @@ public class ControlPoint implements HTTPRequestListener
public void search(String target, int mx)
{
SSDPSearchRequest msReq = new SSDPSearchRequest(target, mx);
SSDPSearchResponseSocketList _ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
_ssdpSearchResponseSocketList.post(msReq);
SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
ssdpSearchResponseSocketList.post(msReq);
}
public void search(String target)
@ -719,7 +718,7 @@ public class ControlPoint implements HTTPRequestListener
}
return null;
}
////////////////////////////////////////////////
// getSubscriberService
////////////////////////////////////////////////
@ -777,11 +776,11 @@ public class ControlPoint implements HTTPRequestListener
return renewSubscriber;
}
////////////////////////////////////////////////
// run
////////////////////////////////////////////////
public boolean start(String target, int mx)
////////////////////////////////////////////////
// run
////////////////////////////////////////////////
public boolean start(String target, int mx)
{
stop();
@ -791,8 +790,8 @@ public class ControlPoint implements HTTPRequestListener
int retryCnt = 0;
int bindPort = getHTTPPort();
HTTPServerList _httpServerList = getHTTPServerList();
while (_httpServerList.open(bindPort) == false) {
HTTPServerList httpServerList = getHTTPServerList();
while (httpServerList.open(bindPort) == false) {
retryCnt++;
if (UPnP.SERVER_RETRY_COUNT < retryCnt) {
Debug.warning("Failed to open HTTP event listener port " + bindPort);
@ -803,40 +802,40 @@ public class ControlPoint implements HTTPRequestListener
setHTTPPort(bindPort - 1);
bindPort = getHTTPPort();
}
_httpServerList.addRequestListener(this);
_httpServerList.start();
httpServerList.addRequestListener(this);
httpServerList.start();
////////////////////////////////////////
// Notify Socket
////////////////////////////////////////
SSDPNotifySocketList _ssdpNotifySocketList = getSSDPNotifySocketList();
if (_ssdpNotifySocketList.open() == false) {
SSDPNotifySocketList ssdpNotifySocketList = getSSDPNotifySocketList();
if (ssdpNotifySocketList.open() == false) {
Debug.warning("Failed to open SSDP notify port 1900");
return false;
}
_ssdpNotifySocketList.setControlPoint(this);
_ssdpNotifySocketList.start();
ssdpNotifySocketList.setControlPoint(this);
ssdpNotifySocketList.start();
////////////////////////////////////////
// SeachResponse Socket
////////////////////////////////////////
int _ssdpPort = getSSDPPort();
int ssdpPort = getSSDPPort();
retryCnt = 0;
SSDPSearchResponseSocketList _ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
while (_ssdpSearchResponseSocketList.open(_ssdpPort) == false) {
SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
while (ssdpSearchResponseSocketList.open(ssdpPort) == false) {
retryCnt++;
if (UPnP.SERVER_RETRY_COUNT < retryCnt) {
Debug.warning("Failed to open SSDP search response port " + _ssdpPort);
Debug.warning("Failed to open SSDP search response port " + ssdpPort);
return false;
}
// I2P go down not up so we don't run into other I2P things
setSSDPPort(_ssdpPort - 1);
_ssdpPort = getSSDPPort();
setSSDPPort(ssdpPort - 1);
ssdpPort = getSSDPPort();
}
_ssdpSearchResponseSocketList.setControlPoint(this);
_ssdpSearchResponseSocketList.start();
ssdpSearchResponseSocketList.setControlPoint(this);
ssdpSearchResponseSocketList.start();
////////////////////////////////////////
// search root devices
@ -862,9 +861,9 @@ public class ControlPoint implements HTTPRequestListener
renewSub.start();
}
return true;
}
return true;
}
public boolean start(String target)
{
return start(target, SSDP.DEFAULT_MSEARCH_MX);
@ -875,24 +874,24 @@ public class ControlPoint implements HTTPRequestListener
return start(ST.ROOT_DEVICE, SSDP.DEFAULT_MSEARCH_MX);
}
public boolean stop()
public boolean stop()
{
unsubscribe();
SSDPNotifySocketList ssdpNotifySocketList = getSSDPNotifySocketList();
ssdpNotifySocketList.stop();
ssdpNotifySocketList.close();
ssdpNotifySocketList.clear();
SSDPNotifySocketList _ssdpNotifySocketList = getSSDPNotifySocketList();
_ssdpNotifySocketList.stop();
_ssdpNotifySocketList.close();
_ssdpNotifySocketList.clear();
SSDPSearchResponseSocketList _ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
_ssdpSearchResponseSocketList.stop();
_ssdpSearchResponseSocketList.close();
_ssdpSearchResponseSocketList.clear();
SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
ssdpSearchResponseSocketList.stop();
ssdpSearchResponseSocketList.close();
ssdpSearchResponseSocketList.clear();
HTTPServerList _httpServerList = getHTTPServerList();
_httpServerList.stop();
_httpServerList.close();
_httpServerList.clear();
HTTPServerList httpServerList = getHTTPServerList();
httpServerList.stop();
httpServerList.close();
httpServerList.clear();
////////////////////////////////////////
// Disposer
@ -914,8 +913,8 @@ public class ControlPoint implements HTTPRequestListener
setRenewSubscriber(null);
}
return true;
}
return true;
}
////////////////////////////////////////////////
// print

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,11 @@
* Copyright (C) Satoshi Konno 2002-2003
*
* File: Service.java
*
* Revision;
*
* 11/28/02
* - first revision.
*
* Revision;
*
* 11/28/02
* - first revision.
* 04/12/02
* - Holmes, Arran C <acholm@essex.ac.uk>
* - Fixed SERVICE_ID constant instead of "serviceId".
@ -63,12 +63,12 @@
*
******************************************************************/
package org.cybergarage.upnp;
package org.cybergarage.upnp;
import java.io.*;
import java.net.*;
import org.cybergarage.http.*;
import java.net.*;
import org.cybergarage.http.*;
import org.cybergarage.xml.*;
import org.cybergarage.util.*;
@ -77,35 +77,35 @@ import org.cybergarage.upnp.xml.*;
import org.cybergarage.upnp.device.*;
import org.cybergarage.upnp.control.*;
import org.cybergarage.upnp.event.*;
public class Service
{
////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////
public final static String ELEM_NAME = "service";
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
private Node serviceNode;
public Node getServiceNode()
{
return serviceNode;
}
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
public Service(Node node)
{
serviceNode = node;
}
public class Service
{
////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////
public final static String ELEM_NAME = "service";
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
private Node serviceNode;
public Node getServiceNode()
{
return serviceNode;
}
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
public Service(Node node)
{
serviceNode = node;
}
////////////////////////////////////////////////
// Mutex
////////////////////////////////////////////////
@ -122,78 +122,78 @@ public class Service
mutex.unlock();
}
////////////////////////////////////////////////
// isServiceNode
////////////////////////////////////////////////
public static boolean isServiceNode(Node node)
{
return Service.ELEM_NAME.equals(node.getName());
}
////////////////////////////////////////////////
// Device/Root Node
////////////////////////////////////////////////
private Node getDeviceNode()
{
Node node = getServiceNode().getParentNode();
if (node == null)
return null;
return node.getParentNode();
}
private Node getRootNode()
{
return getServiceNode().getRootNode();
}
////////////////////////////////////////////////
// Device
////////////////////////////////////////////////
public Device getDevice()
{
return new Device(getRootNode(), getDeviceNode());
}
////////////////////////////////////////////////
// isServiceNode
////////////////////////////////////////////////
public static boolean isServiceNode(Node node)
{
return Service.ELEM_NAME.equals(node.getName());
}
////////////////////////////////////////////////
// Device/Root Node
////////////////////////////////////////////////
private Node getDeviceNode()
{
Node node = getServiceNode().getParentNode();
if (node == null)
return null;
return node.getParentNode();
}
private Node getRootNode()
{
return getServiceNode().getRootNode();
}
////////////////////////////////////////////////
// Device
////////////////////////////////////////////////
public Device getDevice()
{
return new Device(getRootNode(), getDeviceNode());
}
public Device getRootDevice()
{
return getDevice().getRootDevice();
}
////////////////////////////////////////////////
// serviceType
////////////////////////////////////////////////
private final static String SERVICE_TYPE = "serviceType";
public void setServiceType(String value)
{
getServiceNode().setNode(SERVICE_TYPE, value);
}
public String getServiceType()
{
return getServiceNode().getNodeValue(SERVICE_TYPE);
}
////////////////////////////////////////////////
// serviceID
////////////////////////////////////////////////
private final static String SERVICE_ID = "serviceId";
public void setServiceID(String value)
{
getServiceNode().setNode(SERVICE_ID, value);
}
public String getServiceID()
{
return getServiceNode().getNodeValue(SERVICE_ID);
}
////////////////////////////////////////////////
// serviceType
////////////////////////////////////////////////
private final static String SERVICE_TYPE = "serviceType";
public void setServiceType(String value)
{
getServiceNode().setNode(SERVICE_TYPE, value);
}
public String getServiceType()
{
return getServiceNode().getNodeValue(SERVICE_TYPE);
}
////////////////////////////////////////////////
// serviceID
////////////////////////////////////////////////
private final static String SERVICE_ID = "serviceId";
public void setServiceID(String value)
{
getServiceNode().setNode(SERVICE_ID, value);
}
public String getServiceID()
{
return getServiceNode().getNodeValue(SERVICE_ID);
}
////////////////////////////////////////////////
// isURL
////////////////////////////////////////////////
@ -213,73 +213,73 @@ public class Service
return false;
}
////////////////////////////////////////////////
// SCPDURL
////////////////////////////////////////////////
private final static String SCPDURL = "SCPDURL";
public void setSCPDURL(String value)
{
getServiceNode().setNode(SCPDURL, value);
}
public String getSCPDURL()
{
return getServiceNode().getNodeValue(SCPDURL);
}
////////////////////////////////////////////////
// SCPDURL
////////////////////////////////////////////////
private final static String SCPDURL = "SCPDURL";
public void setSCPDURL(String value)
{
getServiceNode().setNode(SCPDURL, value);
}
public String getSCPDURL()
{
return getServiceNode().getNodeValue(SCPDURL);
}
public boolean isSCPDURL(String url)
{
return isURL(getSCPDURL(), url);
}
////////////////////////////////////////////////
// controlURL
////////////////////////////////////////////////
private final static String CONTROL_URL = "controlURL";
public void setControlURL(String value)
{
getServiceNode().setNode(CONTROL_URL, value);
}
public String getControlURL()
{
return getServiceNode().getNodeValue(CONTROL_URL);
}
////////////////////////////////////////////////
// controlURL
////////////////////////////////////////////////
private final static String CONTROL_URL = "controlURL";
public void setControlURL(String value)
{
getServiceNode().setNode(CONTROL_URL, value);
}
public String getControlURL()
{
return getServiceNode().getNodeValue(CONTROL_URL);
}
public boolean isControlURL(String url)
{
return isURL(getControlURL(), url);
}
////////////////////////////////////////////////
// eventSubURL
////////////////////////////////////////////////
private final static String EVENT_SUB_URL = "eventSubURL";
public void setEventSubURL(String value)
{
getServiceNode().setNode(EVENT_SUB_URL, value);
}
public String getEventSubURL()
{
return getServiceNode().getNodeValue(EVENT_SUB_URL);
}
////////////////////////////////////////////////
// eventSubURL
////////////////////////////////////////////////
private final static String EVENT_SUB_URL = "eventSubURL";
public void setEventSubURL(String value)
{
getServiceNode().setNode(EVENT_SUB_URL, value);
}
public String getEventSubURL()
{
return getServiceNode().getNodeValue(EVENT_SUB_URL);
}
public boolean isEventSubURL(String url)
{
return isURL(getEventSubURL(), url);
}
////////////////////////////////////////////////
// SCPD node
////////////////////////////////////////////////
////////////////////////////////////////////////
// SCPD node
////////////////////////////////////////////////
public boolean loadSCPD(String scpdStr) throws InvalidDescriptionException
{
try {
@ -307,32 +307,32 @@ public class Service
return true;
}
private Node getSCPDNode(URL scpdUrl) throws ParserException
{
private Node getSCPDNode(URL scpdUrl) throws ParserException
{
Parser parser = UPnP.getXMLParser();
return parser.parse(scpdUrl);
return parser.parse(scpdUrl);
}
private Node getSCPDNode(File scpdFile) throws ParserException
{
Parser parser = UPnP.getXMLParser();
return parser.parse(scpdFile);
}
private Node getSCPDNode()
{
ServiceData data = getServiceData();
Node scpdNode = data.getSCPDNode();
if (scpdNode != null)
return scpdNode;
String scpdURLStr = getSCPDURL();
try {
private Node getSCPDNode()
{
ServiceData data = getServiceData();
Node scpdNode = data.getSCPDNode();
if (scpdNode != null)
return scpdNode;
String scpdURLStr = getSCPDURL();
try {
URL scpdUrl = new URL(scpdURLStr);
scpdNode = getSCPDNode(scpdUrl);
}
scpdNode = getSCPDNode(scpdUrl);
}
catch (Exception e1) {
Device rootDev = getRootDevice();
Device rootDev = getRootDevice();
String urlBaseStr = rootDev.getURLBase();
// Thanks for Steven Yen (2003/09/03)
if (urlBaseStr == null || urlBaseStr.length() <= 0) {
@ -341,35 +341,35 @@ public class Service
int locationPort = HTTP.getPort(location);
urlBaseStr = HTTP.getRequestHostURL(locationHost, locationPort);
}
scpdURLStr = HTTP.toRelativeURL(scpdURLStr);
String newScpdURLStr = urlBaseStr + scpdURLStr;
try {
scpdURLStr = HTTP.toRelativeURL(scpdURLStr);
String newScpdURLStr = urlBaseStr + scpdURLStr;
try {
URL newScpdURL = new URL(newScpdURLStr);
scpdNode = getSCPDNode(newScpdURL);
}
catch (Exception e2) {
newScpdURLStr = HTTP.getAbsoluteURL(urlBaseStr, scpdURLStr);
try {
scpdNode = getSCPDNode(newScpdURL);
}
catch (Exception e2) {
newScpdURLStr = HTTP.getAbsoluteURL(urlBaseStr, scpdURLStr);
try {
URL newScpdURL = new URL(newScpdURLStr);
scpdNode = getSCPDNode(newScpdURL);
}
catch (Exception e3) {
scpdNode = getSCPDNode(newScpdURL);
}
catch (Exception e3) {
newScpdURLStr = rootDev.getDescriptionFilePath() + scpdURLStr;
try {
scpdNode = getSCPDNode(new File(newScpdURLStr));
}
catch (Exception e4) {
Debug.warning(e4);
}
}
}
}
}
data.setSCPDNode(scpdNode);
return scpdNode;
}
}
}
data.setSCPDNode(scpdNode);
return scpdNode;
}
public byte[] getSCPDData()
{
Node scpdNode = getSCPDNode();
@ -383,30 +383,30 @@ public class Service
return desc.getBytes();
}
////////////////////////////////////////////////
// actionList
////////////////////////////////////////////////
public ActionList getActionList()
{
ActionList actionList = new ActionList();
Node scdpNode = getSCPDNode();
if (scdpNode == null)
return actionList;
Node actionListNode = scdpNode.getNode(ActionList.ELEM_NAME);
if (actionListNode == null)
return actionList;
Node _serviceNode = getServiceNode();
int nNode = actionListNode.getNNodes();
for (int n=0; n<nNode; n++) {
Node node = actionListNode.getNode(n);
if (Action.isActionNode(node) == false)
continue;
Action action = new Action(_serviceNode, node);
actionList.add(action);
}
return actionList;
}
////////////////////////////////////////////////
// actionList
////////////////////////////////////////////////
public ActionList getActionList()
{
ActionList actionList = new ActionList();
Node scdpNode = getSCPDNode();
if (scdpNode == null)
return actionList;
Node actionListNode = scdpNode.getNode(ActionList.ELEM_NAME);
if (actionListNode == null)
return actionList;
Node serviceNode = getServiceNode();
int nNode = actionListNode.getNNodes();
for (int n=0; n<nNode; n++) {
Node node = actionListNode.getNode(n);
if (Action.isActionNode(node) == false)
continue;
Action action = new Action(serviceNode, node);
actionList.add(action);
}
return actionList;
}
public Action getAction(String actionName)
{
@ -422,28 +422,28 @@ public class Service
}
return null;
}
////////////////////////////////////////////////
// serviceStateTable
////////////////////////////////////////////////
public ServiceStateTable getServiceStateTable()
{
ServiceStateTable stateTable = new ServiceStateTable();
Node stateTableNode = getSCPDNode().getNode(ServiceStateTable.ELEM_NAME);
if (stateTableNode == null)
////////////////////////////////////////////////
// serviceStateTable
////////////////////////////////////////////////
public ServiceStateTable getServiceStateTable()
{
ServiceStateTable stateTable = new ServiceStateTable();
Node stateTableNode = getSCPDNode().getNode(ServiceStateTable.ELEM_NAME);
if (stateTableNode == null)
return stateTable;
Node _serviceNode = getServiceNode();
int nNode = stateTableNode.getNNodes();
for (int n=0; n<nNode; n++) {
Node node = stateTableNode.getNode(n);
if (StateVariable.isStateVariableNode(node) == false)
continue;
StateVariable serviceVar = new StateVariable(_serviceNode, node);
stateTable.add(serviceVar);
}
return stateTable;
}
Node serviceNode = getServiceNode();
int nNode = stateTableNode.getNNodes();
for (int n=0; n<nNode; n++) {
Node node = stateTableNode.getNode(n);
if (StateVariable.isStateVariableNode(node) == false)
continue;
StateVariable serviceVar = new StateVariable(serviceNode, node);
stateTable.add(serviceVar);
}
return stateTable;
}
public StateVariable getStateVariable(String name)
{

View File

@ -3,7 +3,7 @@
* CyberUPnP for Java
*
* Copyright (C) Satoshi Konno 2002
*
*
* File: ServiceList.java
*
* Revision;
@ -14,7 +14,7 @@
* - Added caching a ArrayIndexOfBound exception.
*
******************************************************************/
package org.cybergarage.upnp;
import java.util.*;
@ -46,7 +46,7 @@ public class ServiceList extends Vector
try {
obj = get(n);
}
catch (Exception e) {}
catch (Exception e) {};
return (Service)obj;
}
}

View File

@ -5,10 +5,10 @@
* Copyright (C) Satoshi Konno 2002
*
* File: StateVariable.java
*
* Revision;
*
* 12/06/02
*
* Revision;
*
* 12/06/02
* - first revision.
* 06/17/03
* - Added setSendEvents(), isSendEvents().
@ -41,28 +41,28 @@
* - Changed getAllowedValueList() to use AllowedValue instead of String as the member.
*
******************************************************************/
package org.cybergarage.upnp;
import org.cybergarage.xml.*;
package org.cybergarage.upnp;
import org.cybergarage.xml.*;
import org.cybergarage.util.*;
import org.cybergarage.upnp.control.*;
import org.cybergarage.upnp.xml.*;
public class StateVariable extends NodeData
{
////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////
public final static String ELEM_NAME = "stateVariable";
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
private Node stateVariableNode;
public class StateVariable extends NodeData
{
////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////
public final static String ELEM_NAME = "stateVariable";
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
private Node stateVariableNode;
private Node serviceNode;
public Node getServiceNode()
@ -72,73 +72,73 @@ public class StateVariable extends NodeData
public Service getService()
{
Node _serviceNode = getServiceNode();
if (_serviceNode == null)
Node serviceNode = getServiceNode();
if (serviceNode == null)
return null;
return new Service(_serviceNode);
return new Service(serviceNode);
}
public Node getStateVariableNode()
{
return stateVariableNode;
}
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
public Node getStateVariableNode()
{
return stateVariableNode;
}
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
public StateVariable()
{
this.serviceNode = null;
this.stateVariableNode = new Node();
}
public StateVariable(Node serviceNode, Node stateVarNode)
public StateVariable(Node serviceNode, Node stateVarNode)
{
this.serviceNode = serviceNode;
this.stateVariableNode = stateVarNode;
}
////////////////////////////////////////////////
// isStateVariableNode
////////////////////////////////////////////////
public static boolean isStateVariableNode(Node node)
{
return StateVariable.ELEM_NAME.equals(node.getName());
}
////////////////////////////////////////////////
// name
////////////////////////////////////////////////
private final static String NAME = "name";
public void setName(String value)
{
getStateVariableNode().setNode(NAME, value);
}
public String getName()
{
return getStateVariableNode().getNodeValue(NAME);
}
////////////////////////////////////////////////
// dataType
////////////////////////////////////////////////
private final static String DATATYPE = "dataType";
public void setDataType(String value)
{
getStateVariableNode().setNode(DATATYPE, value);
}
public String getDataType()
{
return getStateVariableNode().getNodeValue(DATATYPE);
}
this.serviceNode = serviceNode;
this.stateVariableNode = stateVarNode;
}
////////////////////////////////////////////////
// isStateVariableNode
////////////////////////////////////////////////
public static boolean isStateVariableNode(Node node)
{
return StateVariable.ELEM_NAME.equals(node.getName());
}
////////////////////////////////////////////////
// name
////////////////////////////////////////////////
private final static String NAME = "name";
public void setName(String value)
{
getStateVariableNode().setNode(NAME, value);
}
public String getName()
{
return getStateVariableNode().getNodeValue(NAME);
}
////////////////////////////////////////////////
// dataType
////////////////////////////////////////////////
private final static String DATATYPE = "dataType";
public void setDataType(String value)
{
getStateVariableNode().setNode(DATATYPE, value);
}
public String getDataType()
{
return getStateVariableNode().getNodeValue(DATATYPE);
}
////////////////////////////////////////////////
// dataType
@ -301,8 +301,8 @@ public class StateVariable extends NodeData
queryRes.setResponse(retVar);
}
else {
UPnPStatus _upnpStatus = retVar.getStatus();
queryRes.setFaultResponse(_upnpStatus.getCode(), _upnpStatus.getDescription());
UPnPStatus upnpStatus = retVar.getStatus();
queryRes.setFaultResponse(upnpStatus.getCode(), upnpStatus.getDescription());
}
queryReq.post(queryRes);
return true;

View File

@ -51,7 +51,6 @@ public class RenewSubscriber extends ThreadCore
// Thread
////////////////////////////////////////////////
@Override
public void run()
{
ControlPoint ctrlp = getControlPoint();

View File

@ -51,7 +51,6 @@ public class Advertiser extends ThreadCore
// Thread
////////////////////////////////////////////////
@Override
public void run()
{
Device dev = getDevice();

View File

@ -49,7 +49,6 @@ public class Disposer extends ThreadCore
// Thread
////////////////////////////////////////////////
@Override
public void run()
{
Thread.currentThread().setName("UPnP-Disposer");

View File

@ -5,11 +5,11 @@
* Copyright (C) Satoshi Konno 2002-2004
*
* File: HTTPMU.java
*
* Revision;
*
* 11/18/02
* - first revision.
*
* Revision;
*
* 11/18/02
* - first revision.
* 09/03/03
* - Changed to open the socket using setReuseAddress().
* 12/10/03
@ -21,39 +21,38 @@
* - Changed send() to set the TTL as 4.
*
******************************************************************/
package org.cybergarage.upnp.ssdp;
import java.net.*;
package org.cybergarage.upnp.ssdp;
import java.net.*;
import java.util.*;
import org.cybergarage.http.*;
import org.cybergarage.util.*;
public class HTTPMUSocket
{
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
private InetSocketAddress ssdpMultiGroup = null;
private MulticastSocket ssdpMultiSock = null;
import org.cybergarage.http.*;
import org.cybergarage.util.*;
public class HTTPMUSocket
{
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
private InetSocketAddress ssdpMultiGroup = null;
private MulticastSocket ssdpMultiSock = null;
private NetworkInterface ssdpMultiIf = null;
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////
public HTTPMUSocket()
{
}
public HTTPMUSocket(String addr, int port, String bindAddr)
{
open(addr, port, bindAddr);
}
public HTTPMUSocket(String addr, int port, String bindAddr)
{
open(addr, port, bindAddr);
}
@Override
protected void finalize()
{
close();
@ -91,52 +90,52 @@ public class HTTPMUSocket
return getMulticastInetAddress().getHostAddress();
}
////////////////////////////////////////////////
// open/close
////////////////////////////////////////////////
public boolean open(String addr, int port, String bindAddr)
{
try {
////////////////////////////////////////////////
// open/close
////////////////////////////////////////////////
public boolean open(String addr, int port, String bindAddr)
{
try {
ssdpMultiSock = new MulticastSocket(null);
ssdpMultiSock.setReuseAddress(true);
InetSocketAddress bindSockAddr = new InetSocketAddress(port);
ssdpMultiSock.bind(bindSockAddr);
ssdpMultiGroup = new InetSocketAddress(InetAddress.getByName(addr), port);
ssdpMultiIf = NetworkInterface.getByInetAddress(InetAddress.getByName(bindAddr));
ssdpMultiIf = NetworkInterface.getByInetAddress(InetAddress.getByName(bindAddr));
ssdpMultiSock.joinGroup(ssdpMultiGroup, ssdpMultiIf);
}
catch (Exception e) {
Debug.warning(e);
return false;
}
return true;
}
public boolean close()
{
if (ssdpMultiSock == null)
return true;
try {
ssdpMultiSock.leaveGroup(ssdpMultiGroup, ssdpMultiIf);
}
catch (Exception e) {
Debug.warning(e);
return false;
}
return true;
}
public boolean close()
{
if (ssdpMultiSock == null)
return true;
try {
ssdpMultiSock.leaveGroup(ssdpMultiGroup, ssdpMultiIf);
ssdpMultiSock = null;
}
catch (Exception e) {
//Debug.warning(e);
return false;
}
return true;
}
////////////////////////////////////////////////
// send
////////////////////////////////////////////////
public boolean send(String msg, String bindAddr, int bindPort)
{
}
catch (Exception e) {
//Debug.warning(e);
return false;
}
return true;
}
////////////////////////////////////////////////
// send
////////////////////////////////////////////////
public boolean send(String msg, String bindAddr, int bindPort)
{
try {
MulticastSocket msock;
if ((bindAddr) != null && (0 < bindPort)) {
@ -150,50 +149,50 @@ public class HTTPMUSocket
msock.setTimeToLive(4);
msock.send(dgmPacket);
msock.close();
}
catch (Exception e) {
Debug.warning(e);
return false;
}
return true;
}
}
catch (Exception e) {
Debug.warning(e);
return false;
}
return true;
}
public boolean send(String msg)
{
return send(msg, null, -1);
}
////////////////////////////////////////////////
// post (HTTPRequest)
////////////////////////////////////////////////
public boolean send(String msg)
{
return send(msg, null, -1);
}
////////////////////////////////////////////////
// post (HTTPRequest)
////////////////////////////////////////////////
public boolean post(HTTPRequest req, String bindAddr, int bindPort)
{
public boolean post(HTTPRequest req, String bindAddr, int bindPort)
{
return send(req.toString(), bindAddr, bindPort);
}
}
public boolean post(HTTPRequest req)
{
return send(req.toString(), null, -1);
}
////////////////////////////////////////////////
// reveive
////////////////////////////////////////////////
public SSDPPacket receive()
{
byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE];
////////////////////////////////////////////////
// reveive
////////////////////////////////////////////////
public SSDPPacket receive()
{
byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE];
SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length);
recvPacket.setLocalAddress(getLocalAddress());
try {
ssdpMultiSock.receive(recvPacket.getDatagramPacket());
recvPacket.setTimeStamp(System.currentTimeMillis());
recvPacket.setTimeStamp(System.currentTimeMillis());
}
catch (Exception e) {
//Debug.warning(e);
}
catch (Exception e) {
//Debug.warning(e);
}
return recvPacket;
}
return recvPacket;
}
}

View File

@ -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,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;
}
*/
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -112,7 +112,6 @@ public class SSDPResponse extends HTTPResponse
// getHeader (Override)
////////////////////////////////////////////////
@Override
public String getHeader()
{
StringBuilder str = new StringBuilder();

View File

@ -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))

View File

@ -40,7 +40,7 @@ public class Mutex
}
catch (Exception e) {
Debug.warning(e);
}
};
}
syncLock = true;
}

View File

@ -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 <node />
ps.println(" />");
} else {
ps.println(">" + XML.escapeXMLChars(_value) + "</" + _name + ">");
ps.println(">" + XML.escapeXMLChars(value) + "</" + name + ">");
}
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 +"</" + _name + ">");
ps.println(indentString +"</" + name + ">");
}
public String toString(boolean hasChildNode)