2009-08-11 sponge

* Code Janitor time! Many fixes and documenting fixes that should be
      done in the future. for the most part, this is a general code cleanup.
    * On smaller/embedded systems, the "final" keyword cleanups will have
      more of an impact than on larger systems.
    * Document missing hashCode() methods.
    * Unhide more variables to make code easier to read.
This commit is contained in:
sponge
2009-08-11 21:58:56 +00:00
parent e5eea47b66
commit 3fbff71861
166 changed files with 2575 additions and 2417 deletions

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 11;
public final static long BUILD = 12;
/** for example "-test" */
public final static String EXTRA = "";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;

View File

@ -18,7 +18,6 @@ import java.util.Map;
import java.util.Set;
import net.i2p.crypto.SessionKeyManager;
import net.i2p.crypto.TransientSessionKeyManager;
import net.i2p.data.Destination;
import net.i2p.data.Hash;
import net.i2p.data.LeaseSet;
@ -114,7 +113,7 @@ public class ClientConnectionRunner {
t.setDaemon(true);
t.setPriority(I2PThread.MAX_PRIORITY);
t.start();
_out = _socket.getOutputStream(); // LINT -- OWCH! needs a better way so it can be final.
_out = _socket.getOutputStream(); // FIXME OWCH! needs a better way so it can be final. FIXME
_reader.startReading();
} catch (IOException ioe) {
_log.error("Error starting up the runner", ioe);

View File

@ -60,6 +60,7 @@ class LeaseRequestState {
public boolean getIsSuccessful() { return _successful; }
public void setIsSuccessful(boolean is) { _successful = is; }
@Override
public String toString() {
return "leaseSet request asking for " + _requestedLeaseSet
+ " having received " + _grantedLeaseSet

View File

@ -213,7 +213,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
*
* Key the cache on the source+dest pair.
*/
private static HashMap<String, LeaseSet> _leaseSetCache = new HashMap();
private final static HashMap<String, LeaseSet> _leaseSetCache = new HashMap();
private LeaseSet getReplyLeaseSet(boolean force) {
LeaseSet newLS = getContext().netDb().lookupLeaseSetLocally(_from.calculateHash());
if (newLS == null)
@ -313,7 +313,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
* lease).
*
*/
private static HashMap<String, Lease> _leaseCache = new HashMap();
private final static HashMap<String, Lease> _leaseCache = new HashMap();
private boolean getNextLease() {
_leaseSet = getContext().netDb().lookupLeaseSetLocally(_to.calculateHash());
if (_leaseSet == null) {
@ -453,7 +453,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
* before upper layers like streaming lib fail, even for low-bandwidth
* connections like IRC.
*/
private static HashMap<String, Long> _lastReplyRequestCache = new HashMap();
private final static HashMap<String, Long> _lastReplyRequestCache = new HashMap();
/**
* Send the message to the specified tunnel by creating a new garlic message containing
@ -752,7 +752,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
* Key the caches on the source+dest pair.
*
*/
private static HashMap<String, TunnelInfo> _tunnelCache = new HashMap();
private static final HashMap<String, TunnelInfo> _tunnelCache = new HashMap();
private static HashMap<String, TunnelInfo> _backloggedTunnelCache = new HashMap();
private TunnelInfo selectOutboundTunnel(Destination to) {
TunnelInfo tunnel;
@ -918,6 +918,7 @@ public class OutboundClientMessageOneShotJob extends JobImpl {
}
}
@Override
public String toString() {
return "sending " + _toString + " waiting for token " + _pendingToken
+ " for cloveId " + _cloveId;

View File

@ -9,8 +9,6 @@ package net.i2p.router.networkdb.kademlia;
*/
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

View File

@ -5,8 +5,6 @@ import java.util.List;
import net.i2p.data.DataStructure;
import net.i2p.data.Hash;
import net.i2p.data.LeaseSet;
import net.i2p.data.RouterInfo;
import net.i2p.data.i2np.DatabaseLookupMessage;
import net.i2p.data.i2np.DatabaseSearchReplyMessage;
import net.i2p.data.i2np.DatabaseStoreMessage;

View File

@ -22,7 +22,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import net.i2p.data.DataHelper;

View File

@ -42,6 +42,7 @@ public class PeerSelector {
*
* @return ordered list of Hash objects
*/
/* FIXME Exporting non-public type through public API FIXME */
public List selectMostReliablePeers(Hash key, int numClosest, Set alreadyChecked, KBucketSet kbuckets) {// LINT -- Exporting non-public type through public API
// get the peers closest to the key
List nearest = selectNearestExplicit(key, numClosest, alreadyChecked, kbuckets);
@ -55,6 +56,7 @@ public class PeerSelector {
*
* @return List of Hash for the peers selected, ordered by bucket (but intra bucket order is not defined)
*/
/* FIXME Exporting non-public type through public API FIXME */
public List selectNearestExplicit(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets) {// LINT -- Exporting non-public type through public API
if (true)
return selectNearestExplicitThin(key, maxNumRouters, peersToIgnore, kbuckets);
@ -91,6 +93,7 @@ public class PeerSelector {
*
* @return List of Hash for the peers selected, ordered by bucket (but intra bucket order is not defined)
*/
/* FIXME Exporting non-public type through public API FIXME */
public List selectNearestExplicitThin(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets) { // LINT -- Exporting non-public type through public API
if (peersToIgnore == null)
peersToIgnore = new HashSet(1);
@ -195,6 +198,7 @@ public class PeerSelector {
*
* @return List of Hash for the peers selected, ordered by bucket (but intra bucket order is not defined)
*/
/* FIXME Exporting non-public type through public API FIXME */
public List selectNearest(Hash key, int maxNumRouters, Set peersToIgnore, KBucketSet kbuckets) { // LINT -- Exporting non-public type through public API
// sure, this may not be exactly correct per kademlia (peers on the border of a kbucket in strict kademlia
// would behave differently) but I can see no reason to keep around an /additional/ more complicated algorithm.

View File

@ -63,6 +63,7 @@ class PersistentDataStore extends TransientDataStore {
writer.start();
}
@Override
public boolean isInitialized() { return _initialized; }
// this doesn't stop the read job or the writer, maybe it should?
@ -78,6 +79,7 @@ class PersistentDataStore extends TransientDataStore {
_dbDir = _facade.getDbDir();
}
@Override
public void rescan() {
if (_initialized)
_readJob.wakeup();
@ -176,7 +178,7 @@ class PersistentDataStore extends TransientDataStore {
*/
private class Writer implements Runnable {
private final Map<Hash, DataStructure>_keys;
private Object _waitLock;
private final Object _waitLock;
private volatile boolean _quit;
public Writer() {

View File

@ -27,7 +27,6 @@ import net.i2p.router.Job;
import net.i2p.router.JobImpl;
import net.i2p.router.RouterContext;
import net.i2p.router.TunnelInfo;
import net.i2p.router.message.SendMessageDirectJob;
import net.i2p.util.Log;
/**

View File

@ -50,7 +50,8 @@ public class PeerTestJob extends JobImpl {
/** number of peers to test each round */
private int getTestConcurrency() { return 1; }
public void startTesting(PeerManager manager) { // LINT -- Exporting non-public type through public API
// FIXME Exporting non-public type through public API FIXME
public void startTesting(PeerManager manager) {
_manager = manager;
_keepTesting = true;
this.getTiming().setStartAfter(getContext().clock().now() + DEFAULT_PEER_TEST_DELAY);

View File

@ -6,7 +6,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Properties;

View File

@ -152,6 +152,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
return _manager.wasUnreachable(dest);
}
@Override
public byte[] getIP(Hash dest) {
return _manager.getIP(dest);
}
@ -416,6 +417,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
}
}
@Override
public void queueLookup(byte[] ip) {
_geoIP.add(ip);
}
@ -426,6 +428,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
*
* @return two-letter lower-case country code or null
*/
@Override
public String getCountry(Hash peer) {
byte[] ip = TransportImpl.getIP(peer);
if (ip != null)
@ -452,6 +455,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
}
/** full name for a country code, or the code if we don't know the name */
@Override
public String getCountryName(String c) {
if (_geoIP == null)
return c;
@ -462,6 +466,7 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
}
/** Provide a consistent "look" for displaying router IDs in the console */
@Override
public String renderPeerHTML(Hash peer) {
String h = peer.toBase64().substring(0, 4);
StringBuilder buf = new StringBuilder(128);

View File

@ -28,7 +28,6 @@ import net.i2p.data.RouterInfo;
import net.i2p.data.i2np.I2NPMessage;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.Job;
import net.i2p.router.JobImpl;
import net.i2p.router.MessageSelector;
import net.i2p.router.OutNetMessage;
import net.i2p.router.Router;

View File

@ -13,7 +13,6 @@ import java.io.Writer;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -403,6 +402,7 @@ public class TransportManager implements TransportEventListener {
return rv;
}
@SuppressWarnings("static-access")
public TransportBid getNextBid(OutNetMessage msg) {
int unreachableTransports = 0;
Hash peer = msg.getTarget().getIdentity().calculateHash();
@ -427,6 +427,7 @@ public class TransportManager implements TransportEventListener {
// to us via TCP, send via TCP)
TransportBid bid = t.bid(msg.getTarget(), msg.getMessageSize());
if (bid != null) {
/* FIXME Accessing static field "TRANSIENT_FAIL" FIXME */
if (bid.getLatencyMs() == bid.TRANSIENT_FAIL)
// this keeps GetBids() from shitlisting for "no common transports"
msg.transportFailed(t.getStyle());

View File

@ -14,16 +14,12 @@ import net.i2p.util.Log;
import net.i2p.I2PAppContext;
import org.cybergarage.upnp.Action;
import org.cybergarage.upnp.ActionList;
import org.cybergarage.upnp.Argument;
import org.cybergarage.upnp.ArgumentList;
import org.cybergarage.upnp.ControlPoint;
import org.cybergarage.upnp.Device;
import org.cybergarage.upnp.DeviceList;
import org.cybergarage.upnp.Service;
import org.cybergarage.upnp.ServiceList;
import org.cybergarage.upnp.ServiceStateTable;
import org.cybergarage.upnp.StateVariable;
import org.cybergarage.upnp.device.DeviceChangeListener;
import org.cybergarage.upnp.event.EventListener;
import org.freenetproject.DetectedIP;
@ -373,7 +369,7 @@ public class UPnP extends ControlPoint implements DeviceChangeListener, EventLis
private String _lastAction;
private Service _lastService;
private ArgumentList _lastArgumentList;
private Object toStringLock = new Object();
private final Object toStringLock = new Object();
private String toString(String action, String arg, Service serv) {
synchronized(toStringLock) {
if ((!action.equals(_lastAction)) ||

View File

@ -9,7 +9,6 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.i2p.data.RouterAddress;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;

View File

@ -6,14 +6,12 @@ import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.zip.Adler32;
import net.i2p.data.Base64;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
import net.i2p.data.RouterIdentity;
import net.i2p.data.RouterInfo;
import net.i2p.data.SessionKey;
@ -24,7 +22,6 @@ import net.i2p.data.i2np.I2NPMessageHandler;
import net.i2p.router.OutNetMessage;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.util.Log;

View File

@ -555,6 +555,7 @@ public class NTCPTransport extends TransportImpl {
* to decide whether to enable inbound NTCP. SSU will have CSFI build a new
* NTCP address when it transitions to OK.
*/
@Override
public void forwardPortStatus(int port, boolean success, String reason) {
if (_log.shouldLog(Log.WARN)) {
if (success)
@ -564,6 +565,7 @@ public class NTCPTransport extends TransportImpl {
}
}
@Override
public int getRequestedPort() {
// would be nice to do this here but we can't easily get to the UDP transport.getRequested_Port()
// from here, so we do it in TransportManager.
@ -581,6 +583,7 @@ public class NTCPTransport extends TransportImpl {
* We have to be careful here because much of the router console code assumes
* that the reachability status is really just the UDP status.
*/
@Override
public short getReachabilityStatus() {
if (isAlive() && _myAddress != null) {
synchronized (_conLock) {

View File

@ -674,7 +674,8 @@ public class EstablishmentManager {
}
}
public void receiveRelayResponse(RemoteHostId bob, UDPPacketReader reader) {// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public void receiveRelayResponse(RemoteHostId bob, UDPPacketReader reader) {
long nonce = reader.getRelayResponseReader().readNonce();
OutboundEstablishState state = null;
synchronized (_liveIntroductions) {

View File

@ -210,7 +210,8 @@ public class InboundEstablishState {
public synchronized void setNextSendTime(long when) { _nextSend = when; }
/** RemoteHostId, uniquely identifies an attempt */
public RemoteHostId getRemoteHostId() { return _remoteHostId; }// LINT -- Exporting non-public type through public API
// FIXME Exporting non-public type through public API FIXME
public RemoteHostId getRemoteHostId() { return _remoteHostId; }
public synchronized void receiveSessionConfirmed(UDPPacketReader.SessionConfirmedReader conf) {
if (_receivedIdentity == null)

View File

@ -157,7 +157,8 @@ public class IntroductionManager {
return found;
}
public void receiveRelayIntro(RemoteHostId bob, UDPPacketReader reader) {// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public void receiveRelayIntro(RemoteHostId bob, UDPPacketReader reader) {
if (_context.router().isHidden())
return;
if (_log.shouldLog(Log.INFO))
@ -166,7 +167,8 @@ public class IntroductionManager {
_transport.send(_builder.buildHolePunch(reader));
}
public void receiveRelayRequest(RemoteHostId alice, UDPPacketReader reader) {// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public void receiveRelayRequest(RemoteHostId alice, UDPPacketReader reader) {
if (_context.router().isHidden())
return;
long tag = reader.getRelayRequestReader().readTag();

View File

@ -413,7 +413,8 @@ public class OutboundEstablishState {
}
/** uniquely identifies an attempt */
public RemoteHostId getRemoteHostId() { return _remoteHostId; }// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public RemoteHostId getRemoteHostId() { return _remoteHostId; }
/** we have received a real data packet, so we're done establishing */
public synchronized void dataReceived() {

View File

@ -879,7 +879,8 @@ public class PacketBuilder {
*/
private static final byte PEER_RELAY_INTRO_FLAG_BYTE = (UDPPacket.PAYLOAD_TYPE_RELAY_INTRO << 4);
public UDPPacket buildRelayIntro(RemoteHostId alice, PeerState charlie, UDPPacketReader.RelayRequestReader request) {// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public UDPPacket buildRelayIntro(RemoteHostId alice, PeerState charlie, UDPPacketReader.RelayRequestReader request) {
UDPPacket packet = UDPPacket.acquire(_context, false);
byte data[] = packet.getPacket().getData();
Arrays.fill(data, 0, data.length, (byte)0x0);
@ -929,7 +930,8 @@ public class PacketBuilder {
*/
private static final byte PEER_RELAY_RESPONSE_FLAG_BYTE = (UDPPacket.PAYLOAD_TYPE_RELAY_RESPONSE << 4);
public UDPPacket buildRelayResponse(RemoteHostId alice, PeerState charlie, long nonce, SessionKey aliceIntroKey) {// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public UDPPacket buildRelayResponse(RemoteHostId alice, PeerState charlie, long nonce, SessionKey aliceIntroKey) {
InetAddress aliceAddr = null;
try {
aliceAddr = InetAddress.getByAddress(alice.getIP());

View File

@ -36,7 +36,7 @@ public class PacketHandler {
/** let packets be up to 30s slow */
private static final long GRACE_PERIOD = Router.CLOCK_FUDGE_FACTOR + 30*1000;
/* FIXME Exporting non-public type through public API FIXME */
public PacketHandler(RouterContext ctx, UDPTransport transport, UDPEndpoint endpoint, EstablishmentManager establisher, InboundMessageFragments inbound, PeerTestManager testManager, IntroductionManager introManager) {// LINT -- Exporting non-public type through public API
_context = ctx;
_log = ctx.logManager().getLog(PacketHandler.class);

View File

@ -1003,7 +1003,8 @@ public class PeerState {
return MAX_RTO;
}
public RemoteHostId getRemoteHostId() { return _remoteHostId; }// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public RemoteHostId getRemoteHostId() { return _remoteHostId; }
public int add(OutboundMessageState state) {
if (_dead) {

View File

@ -124,8 +124,9 @@ public class UDPPacket {
void setMessageType(int type) { _messageType = type; }
int getFragmentCount() { return _fragmentCount; }
void setFragmentCount(int count) { _fragmentCount = count; }
public RemoteHostId getRemoteHost() {// LINT -- Exporting non-public type through public API
// FIXME Exporting non-public type through public API FIXME
public RemoteHostId getRemoteHost() {
if (_remoteHost == null) {
long before = System.currentTimeMillis();
InetAddress addr = _packet.getAddress();

View File

@ -9,7 +9,6 @@ import net.i2p.router.RouterContext;
import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/**

View File

@ -40,7 +40,7 @@ import net.i2p.util.SimpleTimer;
*
*/
public class UDPTransport extends TransportImpl implements TimedWeightedPriorityMessageQueue.FailedListener {
private RouterContext _context; // LINT -- field hides a field
private RouterContext _rContext;
private Log _log;
private UDPEndpoint _endpoint;
/** Peer (Hash) to PeerState */
@ -322,6 +322,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
public int getLocalPort() { return _externalListenPort; }
public InetAddress getLocalAddress() { return _externalListenHost; }
public int getExternalPort() { return _externalListenPort; }
@Override
public int getRequestedPort() {
if (_externalListenPort > 0)
return _externalListenPort;
@ -346,6 +347,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* @param ip publicly routable IPv4 only
* @param port 0 if unknown
*/
@Override
public void externalAddressReceived(String source, byte[] ip, int port) {
String s = RemoteHostId.toString(ip);
if (_log.shouldLog(Log.WARN))
@ -368,6 +370,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* If this is wrong, the peer test will figure it out and change the status.
* Don't do anything if UPnP claims failure.
*/
@Override
public void forwardPortStatus(int port, boolean success, String reason) {
if (_log.shouldLog(Log.WARN)) {
if (success)
@ -518,7 +521,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* get the state for the peer at the given remote host/port, or null
* if no state exists
*/
public PeerState getPeerState(RemoteHostId hostInfo) { // LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public PeerState getPeerState(RemoteHostId hostInfo) {
synchronized (_peersByRemoteHost) {
return (PeerState)_peersByRemoteHost.get(hostInfo);
}
@ -755,7 +759,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
}
public boolean isInDropList(RemoteHostId peer) { synchronized (_dropList) { return _dropList.contains(peer); } }// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public boolean isInDropList(RemoteHostId peer) { synchronized (_dropList) { return _dropList.contains(peer); } }
void dropPeer(Hash peer, boolean shouldShitlist, String why) {
PeerState state = getPeerState(peer);
@ -2182,6 +2187,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
}
private static final String PROP_REACHABILITY_STATUS_OVERRIDE = "i2np.udp.status";
@Override
public short getReachabilityStatus() {
String override = _context.getProperty(PROP_REACHABILITY_STATUS_OVERRIDE);
if (override == null)
@ -2201,7 +2207,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_testEvent.runTest();
}
public PeerState pickTestPeer(RemoteHostId dontInclude) {// LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public PeerState pickTestPeer(RemoteHostId dontInclude) {
List peers = null;
synchronized (_peersByIdent) {
peers = new ArrayList(_peersByIdent.values());

View File

@ -42,7 +42,7 @@ public class TunnelGateway {
protected Receiver _receiver;
protected long _lastFlush;
protected int _flushFrequency;
protected DelayedFlush _delayedFlush;// LINT -- Exporting non-public type through public API
protected DelayedFlush _delayedFlush;// FIXME Exporting non-public type through public API FIXME
protected int _messagesSent;
/**

View File

@ -12,8 +12,8 @@ import net.i2p.util.Log;
*
*/
public class TunnelGatewayZeroHop extends TunnelGateway {
private RouterContext _context; // LINT -- field hides a field
private Log _log; // LINT -- field hides a field
private RouterContext TunnelContext;
private Log TunnelLog;
private TunnelCreatorConfig _config;
private OutboundMessageDistributor _outDistributor;
private InboundMessageDistributor _inDistributor;
@ -23,11 +23,11 @@ public class TunnelGatewayZeroHop extends TunnelGateway {
*/
public TunnelGatewayZeroHop(RouterContext context, TunnelCreatorConfig config) {
super(context, null, null, null);
_context = context;
_log = context.logManager().getLog(TunnelGatewayZeroHop.class);
TunnelContext = context;
TunnelLog = context.logManager().getLog(TunnelGatewayZeroHop.class);
_config = config;
if (config.isInbound())
_inDistributor = new InboundMessageDistributor(_context, config.getDestination());
_inDistributor = new InboundMessageDistributor(TunnelContext, config.getDestination());
else
_outDistributor = new OutboundMessageDistributor(context, 400);
}
@ -53,8 +53,8 @@ public class TunnelGatewayZeroHop extends TunnelGateway {
*/
@Override
public void add(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("zero hop gateway: distribute " + (_config.isInbound() ? "inbound " : " outbound ")
if (TunnelLog.shouldLog(Log.DEBUG))
TunnelLog.debug("zero hop gateway: distribute " + (_config.isInbound() ? "inbound " : " outbound ")
+ " to " + (toRouter != null ? toRouter.toBase64().substring(0,4) : "" )
+ "." + (toTunnel != null ? toTunnel.getTunnelId() + "" : "")
+ ": " + msg);

View File

@ -51,7 +51,9 @@ class BuildExecutor implements Runnable {
// Get stat manager, get recognized bandwidth tiers
StatManager statMgr = _context.statManager();
String bwTiers = _context.router().getRouterInfo().BW_CAPABILITY_CHARS; // LINT -- Accessing static field "BW_CAPABILITY_CHARS"
@SuppressWarnings("static-access")
/* FIXME Accessing static field "BW_CAPABILITY_CHARS" FIXME */
String bwTiers = _context.router().getRouterInfo().BW_CAPABILITY_CHARS;
// For each bandwidth tier, create tunnel build agree/reject/expire stats
for (int i = 0; i < bwTiers.length(); i++) {
String bwTier = String.valueOf(bwTiers.charAt(i));

View File

@ -467,6 +467,7 @@ class BuildHandler {
return 0;
}
@SuppressWarnings("static-access")
private void handleReq(RouterInfo nextPeerInfo, BuildMessageState state, BuildRequestRecord req, Hash nextPeer) {
long ourId = req.readReceiveTunnelId();
long nextId = req.readNextTunnelId();
@ -626,7 +627,8 @@ class BuildHandler {
// send it to the reply tunnel on the reply peer within a new TunnelBuildReplyMessage
// (enough layers jrandom?)
TunnelBuildReplyMessage replyMsg = new TunnelBuildReplyMessage(_context);
for (int i = 0; i < state.msg.RECORD_COUNT; i++) // LINT -- Accessing Static field "RECORD_COUNT"
/* FIXME Accessing static field "RECORD_COUNT" FIXME */
for (int i = 0; i < state.msg.RECORD_COUNT; i++)
replyMsg.setRecord(i, state.msg.getRecord(i));
replyMsg.setUniqueId(req.readReplyMessageId());
replyMsg.setMessageExpiration(_context.clock().now() + 10*1000);

View File

@ -79,7 +79,8 @@ public class PooledTunnelCreatorConfig extends TunnelCreatorConfig {
public TunnelPool getTunnelPool() { return _pool; }
public void setTestJob(TestJob job) { _testJob = job; } // LINT -- Exporting non-public type through public API
/* FIXME Exporting non-public type through public API FIXME */
public void setTestJob(TestJob job) { _testJob = job; }
public void setExpireJob(Job job) { /* _expireJob = job; */ }
// Fix memory leaks caused by references if you need to use pairedTunnel

View File

@ -11,7 +11,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.i2p.data.DataHelper;
import net.i2p.data.Destination;

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)
{
setHeader(HTTP.CONTENT_TYPE, type);
}
public String getContentType()
{
return getHeaderValue(HTTP.CONTENT_TYPE);
}
////////////////////////////////////////////////
// ContentLength
////////////////////////////////////////////////
public void setContentLength(long len)
////////////////////////////////////////////////
// ContentType
////////////////////////////////////////////////
public void setContentType(String type)
{
setLongHeader(HTTP.CONTENT_LENGTH, len);
}
public long getContentLength()
{
return getLongHeaderValue(HTTP.CONTENT_LENGTH);
}
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);
}
////////////////////////////////////////////////
// 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 = value;
}
public String getMethod()
////////////////////////////////////////////////
// Method
////////////////////////////////////////////////
private String method = null;
public void setMethod(String value)
{
if (method != null)
method = value;
}
public String getMethod()
{
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()
public boolean isGetRequest()
{
return isMethod(HTTP.GET);
}
public boolean isPostRequest()
{
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,20 +490,21 @@ public class HTTPRequest extends HTTPPacket
return returnResponse(HTTPStatus.BAD_REQUEST);
}
////////////////////////////////////////////////
// toString
////////////////////////////////////////////////
public String toString()
{
StringBuilder str = new StringBuilder();
str.append(getHeader());
str.append(HTTP.CRLF);
str.append(getContentString());
return str.toString();
}
////////////////////////////////////////////////
// toString
////////////////////////////////////////////////
@Override
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,25 +78,26 @@ 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,6 +37,7 @@ 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,11 +45,12 @@ public class HTTPSocket
setOutputStream(socket.getOutputStream());
}
public void finalize()
{
close();
}
@Override
public void finalize()
{
close();
}
////////////////////////////////////////////////
// Socket
////////////////////////////////////////////////
@ -86,27 +87,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
////////////////////////////////////////////////
@ -140,20 +141,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;
@ -174,17 +175,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,6 +170,7 @@ 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,6 +179,7 @@ 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,13 +124,14 @@ public class ControlPoint implements HTTPRequestListener
setNMPRMode(false);
setRenewSubscriber(null);
}
}
public ControlPoint()
{
this(DEFAULT_SSDP_PORT, DEFAULT_EVENTSUB_PORT);
}
@Override
public void finalize()
{
stop();
@ -179,7 +180,7 @@ public class ControlPoint implements HTTPRequestListener
public void setHTTPPort(int port) {
httpPort = port;
}
////////////////////////////////////////////////
// NMPR
////////////////////////////////////////////////
@ -196,35 +197,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;
@ -237,16 +238,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)
{
@ -257,30 +258,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;
}
@ -291,18 +292,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
@ -311,9 +312,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)
@ -321,19 +322,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);
}
////////////////////////////////////////////////
@ -360,7 +361,7 @@ public class ControlPoint implements HTTPRequestListener
public void setExpiredDeviceMonitoringInterval(long interval)
{
expiredDeviceMonitoringInterval = interval;
expiredDeviceMonitoringInterval = interval;
}
public long getExpiredDeviceMonitoringInterval()
@ -378,9 +379,9 @@ public class ControlPoint implements HTTPRequestListener
return deviceDisposer;
}
////////////////////////////////////////////////
////////////////////////////////////////////////
// Notify
////////////////////////////////////////////////
////////////////////////////////////////////////
private ListenerList deviceNotifyListenerList = new ListenerList();
@ -402,7 +403,7 @@ public class ControlPoint implements HTTPRequestListener
listener.deviceNotifyReceived(ssdpPacket);
}
}
////////////////////////////////////////////////
// SearchResponse
////////////////////////////////////////////////
@ -486,12 +487,12 @@ public class ControlPoint implements HTTPRequestListener
addDevice(packet);
performSearchResponseListener(packet);
}
////////////////////////////////////////////////
// M-SEARCH
////////////////////////////////////////////////
private int searchMx = SSDP.DEFAULT_MSEARCH_MX;
////////////////////////////////////////////////
// M-SEARCH
////////////////////////////////////////////////
private int searchMx = SSDP.DEFAULT_MSEARCH_MX;
public int getSearchMx()
{
@ -506,8 +507,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)
@ -718,7 +719,7 @@ public class ControlPoint implements HTTPRequestListener
}
return null;
}
////////////////////////////////////////////////
// getSubscriberService
////////////////////////////////////////////////
@ -776,11 +777,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();
@ -790,8 +791,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);
@ -802,40 +803,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
@ -861,9 +862,9 @@ public class ControlPoint implements HTTPRequestListener
renewSub.start();
}
return true;
}
return true;
}
public boolean start(String target)
{
return start(target, SSDP.DEFAULT_MSEARCH_MX);
@ -874,24 +875,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();
SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
ssdpSearchResponseSocketList.stop();
ssdpSearchResponseSocketList.close();
ssdpSearchResponseSocketList.clear();
SSDPNotifySocketList _ssdpNotifySocketList = getSSDPNotifySocketList();
_ssdpNotifySocketList.stop();
_ssdpNotifySocketList.close();
_ssdpNotifySocketList.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
@ -913,8 +914,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,6 +51,7 @@ public class RenewSubscriber extends ThreadCore
// Thread
////////////////////////////////////////////////
@Override
public void run()
{
ControlPoint ctrlp = getControlPoint();

View File

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

View File

@ -49,6 +49,7 @@ 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,38 +21,39 @@
* - 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();
@ -90,52 +91,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)) {
@ -149,50 +150,50 @@ public class HTTPMUSocket
msock.setTimeToLive(4);
msock.send(dgmPacket);
msock.close();
}
catch (Exception e) {
Debug.warning(e);
return false;
}
return true;
}
public boolean send(String msg)
{
return send(msg, null, -1);
}
////////////////////////////////////////////////
// post (HTTPRequest)
////////////////////////////////////////////////
}
catch (Exception e) {
Debug.warning(e);
return false;
}
return true;
}
public boolean post(HTTPRequest req, String bindAddr, int bindPort)
{
public boolean send(String msg)
{
return send(msg, null, -1);
}
////////////////////////////////////////////////
// post (HTTPRequest)
////////////////////////////////////////////////
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());
}
catch (Exception e) {
//Debug.warning(e);
recvPacket.setTimeStamp(System.currentTimeMillis());
}
return recvPacket;
}
catch (Exception e) {
//Debug.warning(e);
}
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,46 +20,47 @@
* - 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();
@ -141,66 +142,66 @@ public class HTTPUSocket
return true;
}
////////////////////////////////////////////////
// close
////////////////////////////////////////////////
public boolean close()
{
if (ssdpUniSock == null)
return true;
try {
ssdpUniSock.close();
ssdpUniSock = null;
}
catch (Exception e) {
Debug.warning(e);
return false;
}
return true;
}
////////////////////////////////////////////////
// close
////////////////////////////////////////////////
////////////////////////////////////////////////
// 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);
}
public boolean close()
{
if (ssdpUniSock == null)
return true;
try {
ssdpUniSock.close();
ssdpUniSock = null;
}
catch (Exception e) {
Debug.warning("addr = " +ssdpUniSock.getLocalAddress().getHostName());
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);
ssdpUniSock.send(dgmPacket);
}
catch (Exception e) {
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
@ -235,5 +236,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,25 +21,24 @@
* - Added close() in stop().
*
******************************************************************/
package org.cybergarage.upnp.ssdp;
import java.net.*;
package org.cybergarage.upnp.ssdp;
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;
@ -48,24 +47,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)
@ -80,20 +79,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)
@ -110,23 +109,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,47 +197,48 @@ 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,6 +112,7 @@ 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,15 +12,16 @@
* - 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)

View File

@ -65,6 +65,7 @@ public class XmlPullParserException extends Exception {
*/
//NOTE: code that prints this and detail is difficult in J2ME
@Override
public void printStackTrace() {
if (detail == null) {
super.printStackTrace();