forked from I2P_Developers/i2p.i2p
Unmodified cybergarage-upnp from github rev 9499b03 2015-02-05 https://github.com/cybergarage/cybergarage-upnp/commits/master which is the same as rev 3ed1af9 2014-07-28 except for the addition of README.md which we aren't using. This is post-version 3.0. Omitted files: router/java/src/org/cybergarage/xml/parser/XercesParser.java router/java/src/org/cybergarage/xml/parser/XmlPullParser.java router/java/src/org/cybergarage/xml/parser/kXML2Parser.java chmod all files back to 644. Diverging from 2.1 checkin rev 59eae97dbb470d8c4a1e4dba3a9763e134bb0c53 in prep for merging. License unchanged. Compile tested only.
78 lines
1.9 KiB
Java
78 lines
1.9 KiB
Java
/******************************************************************
|
|
*
|
|
* CyberUPnP for Java
|
|
*
|
|
* Copyright (C) Satoshi Konno 2002-2003
|
|
*
|
|
* File: ST.java
|
|
*
|
|
* Revision;
|
|
*
|
|
* 01/31/03
|
|
* - first revision.
|
|
*
|
|
******************************************************************/
|
|
|
|
package org.cybergarage.upnp.event;
|
|
|
|
import org.cybergarage.upnp.*;
|
|
|
|
public class Subscription
|
|
{
|
|
public final static String XMLNS = "urn:schemas-upnp-org:event-1-0";
|
|
public final static String TIMEOUT_HEADER = "Second-";
|
|
public final static String INFINITE_STRING = "infinite";
|
|
public final static int INFINITE_VALUE = -1;
|
|
public final static String UUID = "uuid:";
|
|
public final static String SUBSCRIBE_METHOD = "SUBSCRIBE";
|
|
public final static String UNSUBSCRIBE_METHOD = "UNSUBSCRIBE";
|
|
|
|
////////////////////////////////////////////////
|
|
// Timeout
|
|
////////////////////////////////////////////////
|
|
|
|
public final static String toTimeoutHeaderString(long time)
|
|
{
|
|
if (time == Subscription.INFINITE_VALUE)
|
|
return Subscription.INFINITE_STRING;
|
|
return Subscription.TIMEOUT_HEADER + Long.toString(time);
|
|
}
|
|
|
|
public final static long getTimeout(String headerValue)
|
|
{
|
|
int minusIdx = headerValue.indexOf('-');
|
|
long timeout = Subscription.INFINITE_VALUE;
|
|
try {
|
|
String timeoutStr = headerValue.substring(minusIdx+1, headerValue.length());
|
|
timeout = Long.parseLong(timeoutStr);
|
|
}
|
|
catch (Exception e) {}
|
|
return timeout;
|
|
}
|
|
|
|
////////////////////////////////////////////////
|
|
// SID
|
|
////////////////////////////////////////////////
|
|
|
|
public static final String createSID()
|
|
{
|
|
return UPnP.createUUID();
|
|
}
|
|
|
|
public final static String toSIDHeaderString(String id)
|
|
{
|
|
return Subscription.UUID + id;
|
|
}
|
|
|
|
public final static String getSID(String headerValue)
|
|
{
|
|
if (headerValue == null)
|
|
return "";
|
|
if (headerValue.startsWith(Subscription.UUID) == false)
|
|
return headerValue;
|
|
return headerValue.substring(Subscription.UUID.length(), headerValue.length());
|
|
}
|
|
|
|
}
|
|
|