Commit 9efa9a63 authored by Kevin Kershaw's avatar Kevin Kershaw

Initial commit of ocap_ri trunk

parents

Too many changes to show.

To preserve performance only 226 of 226+ files are displayed.

<?xml version="1.0"?>
<!--
##############################################################################
#
# This buildfile builds the CyberGarage UPnP stack.
#
# @author Keith Mastranunzio - keith@flec.tv
#
##############################################################################
-->
<project name="cybergarage" default="build" basedir=".">
<property name="version" value="1.0"/>
<property name="javac.DEBUG" value="yes"/>
<property name="javac.OPTIMIZE" value="no"/>
<property name="javac.DEPRECATION" value="yes"/>
<property name="javac.TARGET" value="1.1"/>
<property name="jar.COMPRESS" value="no"/>
<property name="bindir.bin" value="${basedir}/bin"/>
<property name="bindir.classes" value="${bindir.bin}/classes"/>
<!-- Pull in target configuration properties -->
<property environment="env"/>
<property file="${env.OCAPROOT}/target/${env.OCAPTC}/buildrules.properties" />
<property file="${env.OCAPROOT}/tools/${env.OCAPHOST}/hostrules.properties" />
<property file="${env.OCAPROOT}/${build.java.PROPERTYFILE}" />
<property file="${env.OCAPROOT}/java/javadoc.properties" />
<target name="build"
description="Builds CyberGarage"
depends="init, build.java"/>
<target name="build.java"
description="Builds CyberGarage"
depends="init, mkdir, jar.java"/>
<target name="jar.java" depends="javac.java">
<jar destfile="${bindir.bin}/cybergarage${DATE}.jar"
compress="${jar.COMPRESS}">
<fileset dir="${bindir.classes}" includes="**/*.class" />
</jar>
</target>
<target name="javac.java">
<javac srcdir="${basedir}/src/java"
destdir="${bindir.classes}"
includes="**/*.java"
debug="${javac.DEBUG}"
optimize="${javac.OPTIMIZE}"
deprecation="${javac.DEPRECATION}"
target="${javac.TARGET}"
includeAntRuntime="no">
<classpath>
<filelist dir="${env.OCAPROOT}" files="${build.lib.CLASSPATH}"/>
</classpath>
<bootclasspath>
<filelist dir="${env.OCAPROOT}" files="${build.lib.BOOTCLASSPATH}" />
</bootclasspath>
</javac>
</target>
<target name="mkdir">
<mkdir dir="${bindir.bin}"/>
<mkdir dir="${bindir.classes}"/>
</target>
<target name="init">
<tstamp>
<format property="DATE" pattern="MMMMdyyyy"/>
</tstamp>
</target>
<target name="clean"
description="Cleans up intermediate files">
<delete dir="${bindir.classes}" quiet="true" />
</target>
<target name="purge"
description="Deletes generated binary files">
<delete dir="${bindir.classes}" quiet="true" />
<delete file="${bindir.bin}/*.jar" quiet="true" />
</target>
</project>
/******************************************************************
*
* CyberHTTP for Java
*
* Copyright (C) Satoshi Konno 2002-2003
*
* File : Date.java
*
* Revision;
*
* 01/05/03
* - first revision
* 10/20/04
* - Theo Beisch <theo.beisch@gmx.de>
* - Fixed the following methods to use HOUR_OF_DAY instead of HOUR.
* getHour(), getDateString() getTimeString()
* - Fixed getInstance() to return GMT instance.
*
******************************************************************/
package org.cybergarage.http;
import java.util.Calendar;
import java.util.TimeZone;
public class Date
{
private Calendar cal;
public Date(Calendar cal)
{
this.cal = cal;
}
public Calendar getCalendar()
{
return cal;
}
////////////////////////////////////////////////
// Time
////////////////////////////////////////////////
public int getHour()
{
// Thanks for Theo Beisch (10/20/04)
return getCalendar().get(Calendar.HOUR_OF_DAY);
}
public int getMinute()
{
return getCalendar().get(Calendar.MINUTE);
}
public int getSecond()
{
return getCalendar().get(Calendar.SECOND);
}
////////////////////////////////////////////////
// paint
////////////////////////////////////////////////
public final static Date getLocalInstance()
{
return new Date(Calendar.getInstance());
}
public final static Date getInstance()
{
// Thanks for Theo Beisch (10/20/04)
return new Date(Calendar.getInstance(TimeZone.getTimeZone("GMT")));
}
////////////////////////////////////////////////
// getDateString
////////////////////////////////////////////////
public final static String toDateString(int value)
{
if (value < 10)
return "0" + Integer.toString(value);
return Integer.toString(value);
}
private final static String MONTH_STRING[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
};
public final static String toMonthString(int value)
{
value -= Calendar.JANUARY;
if (0 <= value && value < 12)
return MONTH_STRING[value];
return "";
}
private final static String WEEK_STRING[] = {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
};
public final static String toWeekString(int value)
{
value -= Calendar.SUNDAY;
if (0 <= value && value < 7)
return WEEK_STRING[value];
return "";
}
public final static String toTimeString(int value)
{
String str = "";
if (value < 10)
str += "0";
str += Integer.toString(value);
return str;
}
public String getDateString()
{
// Thanks for Theo Beisch (10/20/04)
Calendar cal = getCalendar();
return
toWeekString(cal.get(Calendar.DAY_OF_WEEK)) +", " +
toTimeString(cal.get(Calendar.DATE)) + " " +
toMonthString(cal.get(Calendar.MONTH)) + " " +
Integer.toString(cal.get(Calendar.YEAR)) + " " +
toTimeString(cal.get(Calendar.HOUR_OF_DAY)) + ":" +
toTimeString(cal.get(Calendar.MINUTE)) + ":" +
toTimeString(cal.get(Calendar.SECOND)) + " GMT";
}
////////////////////////////////////////////////
// getTimeString
////////////////////////////////////////////////
public String getTimeString()
{
// Thanks for Theo Beisch (10/20/04)
Calendar cal = getCalendar();
return
toDateString(cal.get(Calendar.HOUR_OF_DAY)) +
(((cal.get(Calendar.SECOND) % 2) == 0) ? ":" : " ") +
toDateString(cal.get(Calendar.MINUTE));
}
}
/******************************************************************
*
* CyberHTTP for Java
*
* Copyright (C) Satoshi Konno 2002-2003
*
* File: HTML.java
*
* Revision;
*
* 01/05/03
* - first revision.
*
******************************************************************/
package org.cybergarage.http;
public class HTML
{
public static final String CONTENT_TYPE = "text/html; charset=\"utf-8\"";
}
/******************************************************************
*
* CyberHTTP for Java
*
* Copyright (C) Satoshi Konno 2002
*
* File: HTTP.java
*
* Revision:
*
* 11/18/02
* - first revision.
* 08/30/03
* - Giordano Sassaroli <sassarol@cefriel.it>
* - Problem : the method getPort should return the default http port 80 when a port is not specified
* - Description : the method is used in ControlRequest.setRequestHost() and in SubscriptionRequest.setService(). maybe the default port check could be done in these methods.
* 09/03/02
* - Added getRequestHostURL().
* 03/11/04
* - Added the following methods to send big content stream.
* post(HTTPResponse, byte[])
* post(HTTPResponse, InputStream)
* 05/26/04
* - Added NO_CATCH and MAX_AGE.
* 10/20/04
* - Brent Hills <bhills@openshores.com>
* - Added Range and MYNAME;
*
******************************************************************/
package org.cybergarage.http;
import java.net.*;
public class HTTP
{
////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////
public static final String HOST = "HOST";
public static final String VERSION = "1.1";
public static final String VERSION_10 = "1.0";
public static final String VERSION_11 = "1.1";
public static final String CRLF = "\r\n";
public static final String TAB = "\t";
public static final String SOAP_ACTION = "SOAPACTION";
public static final String M_SEARCH = "M-SEARCH";
public static final String NOTIFY = "NOTIFY";
public static final String POST = "POST";
public static final String GET = "GET";
public static final String HEAD = "HEAD";
public static final String SUBSCRIBE = "SUBSCRIBE";
public static final String UNSUBSCRIBE = "UNSUBSCRIBE";
public static final String DATE = "Date";
public static final String CACHE_CONTROL = "Cache-Control";
public static final String NO_CACHE = "no-cache";
public static final String MAX_AGE = "max-age";
public static final String CONNECTION = "Connection";
public static final String CLOSE = "close";
public static final String KEEP_ALIVE = "Keep-Alive";
public static final String CONTENT_TYPE = "Content-Type";
public static final String CONTENT_LENGTH = "Content-Length";
public static final String CONTENT_RANGE = "Content-Range";
public static final String CONTENT_RANGE_BYTES = "bytes";
// Thanks for Brent Hills (10/20/04)
public static final String RANGE = "Range";
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
public static final String CHUNKED = "Chunked";
public static final String LOCATION = "Location";
public static final String SERVER = "Server";
public static final String ST = "ST";
public static final String MX = "MX";
public static final String MAN = "MAN";
public static final String NT = "NT";
public static final String NTS = "NTS";
public static final String USN = "USN";
public static final String EXT = "EXT";
public static final String SID = "SID";
public static final String SEQ = "SEQ";
public final static String CALLBACK = "CALLBACK";
public final static String TIMEOUT = "TIMEOUT";
// Thanks for Brent Hills (10/20/04)
public final static String MYNAME = "MYNAME";
public static final String REQEST_LINE_DELIM = " ";
public static final String HEADER_LINE_DELIM = " :";
public static final String STATUS_LINE_DELIM = " ";
public static final int DEFAULT_PORT = 80;
public static final int DEFAULT_CHUNK_SIZE = 512 * 1024;
public static final int DEFAULT_TIMEOUT = 30;
////////////////////////////////////////////////
// URL
////////////////////////////////////////////////
public static final boolean isAbsoluteURL(String urlStr)
{
try {
URL url = new URL(urlStr);
return true;
}
catch (Exception e) {
return false;
}
}
public static final String getHost(String urlStr)
{
try {
URL url = new URL(urlStr);
return url.getHost();
}
catch (Exception e) {
return "";
}
}
public static final int getPort(String urlStr)
{
try {
URL url = new URL(urlStr);
// Thanks for Giordano Sassaroli <sassarol@cefriel.it> (08/30/03)
int port = url.getPort();
if (port <= 0)
port = DEFAULT_PORT;
return port;
}
catch (Exception e) {
return DEFAULT_PORT;
}
}
public static final String getRequestHostURL(String host, int port)
{
String reqHost = "http://" + host + ":" + port;
return reqHost;
}
public static final String toRelativeURL(String urlStr, boolean withParam)
{
String uri = urlStr;
if (isAbsoluteURL(urlStr) == true) {
if (0 < urlStr.length() && urlStr.charAt(0) != '/')
uri = "/" + urlStr;
}
else {
try{
URL url = new URL(urlStr);
uri = url.getPath();
if (withParam == true) {
String queryStr = url.getQuery();
if (!queryStr.equals("")){
uri += "?" + queryStr;
}
}
if (uri.endsWith("/"))
uri = uri.substring(0,uri.length()-1);
}catch(Exception e){}
}
return uri;
}
public static final String toRelativeURL(String urlStr)
{
return toRelativeURL(urlStr, true);
}
public static final String getAbsoluteURL(String baseURLStr, String relURlStr)
{
try {
URL baseURL = new URL(baseURLStr);
String url =
baseURL.getProtocol() + "://" +
baseURL.getHost() + ":" +
baseURL.getPort() +
toRelativeURL(relURlStr);
return url;
}
catch (Exception e) {
return "";
}
}
////////////////////////////////////////////////
// Chunk Size
////////////////////////////////////////////////
private static int chunkSize = DEFAULT_CHUNK_SIZE;
public static final void setChunkSize(int size)
{
chunkSize = size;
}
public static final int getChunkSize()
{
return chunkSize;
}
}
/******************************************************************
*
* CyberHTTP for Java
*
* Copyright (C) Satoshi Konno 2002
*
* File: HTTPHeader.java
*
* 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 org.cybergarage.util.*;
public class HTTPHeader
{
private String name;
private String value;
public HTTPHeader(String name, String value)
{
setName(name);
setValue(value);
}
public HTTPHeader(String lineStr)
{
setName("");
setValue("");
if (lineStr == null)
return;
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());
}
////////////////////////////////////////////////
// Member
////////////////////////////////////////////////
public void setName(String name)
{
this.name = name;
}
public void setValue(String value)
{
this.