Index: java/net/InetAddress.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/InetAddress.java,v
retrieving revision 1.29
diff -u -r1.29 InetAddress.java
--- java/net/InetAddress.java 20 Mar 2004 14:04:44 -0000 1.29
+++ java/net/InetAddress.java 12 Apr 2004 11:08:18 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@@ -35,7 +35,6 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.net;
import gnu.classpath.Configuration;
@@ -47,6 +46,7 @@
import java.util.HashMap;
import java.util.StringTokenizer;
+
/**
* This class models an Internet address. It does not have a public
* constructor. Instead, new instances of this objects are created
@@ -81,17 +81,16 @@
* Percentage of cache entries to purge when the table gets full.
*/
private static final int DEFAULT_CACHE_PURGE_PCT = 30;
-
+
/**
* The special IP address INADDR_ANY.
*/
private static InetAddress inaddr_any;
-
+
/**
* Dummy InetAddress, used to bind socket to any (all) network interfaces.
*/
static InetAddress ANY_IF;
-
/**
* The size of the cache.
@@ -116,44 +115,43 @@
private static HashMap cache;
static
- {
- // load the shared library needed for name resolution
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary ("javanet");
- }
-
- // Look for properties that override default caching behavior
- cache_size = Integer.getInteger ("gnu.java.net.dns_cache_size",
- DEFAULT_CACHE_SIZE).intValue();
- cache_period = Integer.getInteger ("gnu.java.net.dns_cache_period",
- DEFAULT_CACHE_PERIOD * 60
- * 1000).intValue();
-
- cache_purge_pct = Integer.getInteger ("gnu.java.net.dns_cache_purge_pct",
- DEFAULT_CACHE_PURGE_PCT).
- intValue ();
-
- // Fallback to defaults if necessary
- if ((cache_purge_pct < 1) || (cache_purge_pct > 100))
- cache_purge_pct = DEFAULT_CACHE_PURGE_PCT;
-
- // Create the cache
- if (cache_size != 0)
- cache = new HashMap (cache_size);
+ {
+ // load the shared library needed for name resolution
+ if (Configuration.INIT_LOAD_LIBRARY)
+ System.loadLibrary("javanet");
+
+ // Look for properties that override default caching behavior
+ cache_size =
+ Integer.getInteger("gnu.java.net.dns_cache_size", DEFAULT_CACHE_SIZE)
+ .intValue();
+ cache_period =
+ Integer.getInteger("gnu.java.net.dns_cache_period",
+ DEFAULT_CACHE_PERIOD * 60 * 1000).intValue();
+
+ cache_purge_pct =
+ Integer.getInteger("gnu.java.net.dns_cache_purge_pct",
+ DEFAULT_CACHE_PURGE_PCT).intValue();
+
+ // Fallback to defaults if necessary
+ if ((cache_purge_pct < 1) || (cache_purge_pct > 100))
+ cache_purge_pct = DEFAULT_CACHE_PURGE_PCT;
+
+ // Create the cache
+ if (cache_size != 0)
+ cache = new HashMap(cache_size);
- // precompute the ANY_IF address
- try
- {
- ANY_IF = getInaddrAny ();
- }
- catch (UnknownHostException uhe)
- {
- // Hmmm, make one up and hope that it works.
- byte[] zeros = { 0, 0, 0, 0 };
- ANY_IF = new InetAddress (zeros);
- }
- }
+ // precompute the ANY_IF address
+ try
+ {
+ ANY_IF = getInaddrAny();
+ }
+ catch (UnknownHostException uhe)
+ {
+ // Hmmm, make one up and hope that it works.
+ byte[] zeros = { 0, 0, 0, 0 };
+ ANY_IF = new InetAddress(zeros);
+ }
+ }
/**
* The Serialized Form specifies that an int 'address' is saved/restored.
@@ -181,7 +179,7 @@
* The time this address was looked up.
*/
transient long lookup_time;
-
+
/**
* The field 'family' seems to be the AF_ value.
* FIXME: Much of the code in the other java.net classes does not make
@@ -198,7 +196,7 @@
*
* @param ipaddr The IP number of this address as an array of bytes
*/
- InetAddress (byte[] address)
+ InetAddress(byte[] address)
{
this (address, null, null);
}
@@ -211,9 +209,9 @@
* @param ipaddr The IP number of this address as an array of bytes
* @param hostname The hostname of this IP address.
*/
- InetAddress (byte[] address, String hostname)
+ InetAddress(byte[] address, String hostname)
{
- this (address, hostname, null);
+ this(address, hostname, null);
}
/**
@@ -226,22 +224,22 @@
* @param hostname_alias A backup hostname to use if hostname is null to
* prevent reverse lookup failures
*/
- InetAddress (byte[] ipaddr, String hostname, String hostname_alias)
+ InetAddress(byte[] ipaddr, String hostname, String hostname_alias)
{
- addr = new byte [ipaddr.length];
+ addr = new byte[ipaddr.length];
for (int i = 0; i < ipaddr.length; i++)
- addr [i] = ipaddr [i];
+ addr[i] = ipaddr[i];
this.hostName = hostname;
this.hostname_alias = hostname_alias;
lookup_time = System.currentTimeMillis();
- family = 2; /* AF_INET */
- address = addr [3] & 0xff;
- address |= ((addr [2] << 8) & 0xff00);
- address |= ((addr [1] << 16) & 0xff0000);
- address |= ((addr [0] << 24) & 0xff000000);
+ family = 2; /* AF_INET */
+ address = addr[3] & 0xff;
+ address |= ((addr[2] << 8) & 0xff00);
+ address |= ((addr[1] << 16) & 0xff0000);
+ address |= ((addr[0] << 24) & 0xff000000);
}
/**
@@ -257,75 +255,69 @@
{
// Mask against high order bits of 1110
if (addr.length == 4)
- return (addr [0] & 0xF0) == 0xE0;
-
+ return (addr[0] & 0xF0) == 0xE0;
+
return false;
}
/**
* Utility routine to check if the InetAddress in a wildcard address
- *
+ *
* @since 1.4
*/
public boolean isAnyLocalAddress()
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
- return equals (ANY_IF);
+ return equals(ANY_IF);
}
/**
* Utility routine to check if the InetAddress is a loopback address
- *
+ *
* @since 1.4
*/
public boolean isLoopbackAddress()
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
-
- return addr [0] == 0x7F;
+ return addr[0] == 0x7F;
}
/**
* Utility routine to check if InetAddress is a link local address
- *
+ *
* @since 1.4
*/
public boolean isLinkLocalAddress()
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
-
// XXX: This seems to not exist with IPv4 addresses
return false;
}
/**
* Utility routine to check if InetAddress is a site local address
- *
+ *
* @since 1.4
*/
public boolean isSiteLocalAddress()
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
-
// 10.0.0.0/8
- if (addr [0] == 0x0A)
+ if (addr[0] == 0x0A)
return true;
// XXX: Suns JDK 1.4.1 (on Linux) seems to have a bug here:
// it says 172.16.0.0 - 172.255.255.255 are site local addresses
-
// 172.16.0.0/12
- if (addr [0] == 0xAC
- && (addr [1] & 0xF0) == 0x01)
+ if (addr[0] == 0xAC && (addr[1] & 0xF0) == 0x01)
return true;
// 192.168.0.0/16
- if (addr [0] == 0xC0
- && addr [1] == 0xA8)
+ if (addr[0] == 0xC0 && addr[1] == 0xA8)
return true;
// XXX: Do we need to check more addresses here ?
@@ -334,48 +326,43 @@
/**
* Utility routine to check if InetAddress is a global multicast address
- *
+ *
* @since 1.4
*/
public boolean isMCGlobal()
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
-
// XXX: This seems to not exist with IPv4 addresses
return false;
}
/**
* Utility reoutine to check if InetAddress is a node local multicast address
- *
+ *
* @since 1.4
*/
public boolean isMCNodeLocal()
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
-
// XXX: This seems to not exist with IPv4 addresses
return false;
}
/**
* Utility reoutine to check if InetAddress is a link local multicast address
- *
+ *
* @since 1.4
*/
public boolean isMCLinkLocal()
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
-
- if (!isMulticastAddress())
+ if (! isMulticastAddress())
return false;
- return (addr [0] == 0xE0
- && addr [1] == 0x00
- && addr [2] == 0x00);
+ return (addr[0] == 0xE0 && addr[1] == 0x00 && addr[2] == 0x00);
}
/**
@@ -387,7 +374,6 @@
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
-
// XXX: This seems to not exist with IPv4 addresses
return false;
}
@@ -395,14 +381,13 @@
/**
* Utility reoutine to check if InetAddress is a organization local
* multicast address
- *
+ *
* @since 1.4
*/
public boolean isMCOrgLocal()
{
// This is the IPv4 implementation.
// Any class derived from InetAddress should override this.
-
// XXX: This seems to not exist with IPv4 addresses
return false;
}
@@ -420,15 +405,15 @@
try
{
- hostName = getHostByAddr (addr);
- return hostName;
+ hostName = getHostByAddr(addr);
+ return hostName;
}
catch (UnknownHostException e)
{
- if (hostname_alias != null)
- return hostname_alias;
- else
- return getHostAddress();
+ if (hostname_alias != null)
+ return hostname_alias;
+ else
+ return getHostAddress();
}
}
@@ -445,7 +430,7 @@
}
/**
- * Returns the IP address of this object as a String. The address is in
+ * Returns the IP address of this object as a String. The address is in
* the dotted octet notation, for example, "127.0.0.1".
*
* @return The IP address of this object in String form
@@ -454,16 +439,16 @@
*/
public String getHostAddress()
{
- StringBuffer sb = new StringBuffer (40);
-
+ StringBuffer sb = new StringBuffer(40);
+
for (int i = 0; i < addr.length; i++)
{
- sb.append (addr [i] & 0xff);
+ sb.append(addr[i] & 0xff);
- if (i < (addr.length - 1))
- sb.append (".");
+ if (i < (addr.length - 1))
+ sb.append(".");
}
-
+
return sb.toString();
}
@@ -480,10 +465,10 @@
int hash = 0;
int len = addr.length;
int i = len > 4 ? len - 4 : 0;
-
- for ( ; i < len; i++)
+
+ for (; i < len; i++)
hash = (hash << 8) | (addr[i] & 0xFF);
-
+
return hash;
}
@@ -497,11 +482,11 @@
* @return true if the passed in object's address is equal to this one's,
* false otherwise
*/
- public boolean equals (Object obj)
+ public boolean equals(Object obj)
{
if (! (obj instanceof InetAddress))
return false;
-
+
// "The Java Class Libraries" 2nd edition says "If a machine has
// multiple names instances of InetAddress for different name of
// that same machine are not equal. This is because they have
@@ -509,14 +494,14 @@
// JDK 1.2 API documentation. A little experimentation
// shows that the latter is correct.
byte[] addr2 = ((InetAddress) obj).addr;
-
+
if (addr.length != addr2.length)
return false;
-
+
for (int i = 0; i < addr.length; i++)
- if (addr [i] != addr2 [i])
+ if (addr[i] != addr2[i])
return false;
-
+
return true;
}
@@ -531,14 +516,14 @@
{
String host;
String address = getHostAddress();
-
+
if (hostName != null)
host = hostName;
else if (hostname_alias != null)
host = hostname_alias;
else
host = address;
-
+
return host + "/" + address;
}
@@ -554,10 +539,10 @@
*
* @since 1.4
*/
- public static InetAddress getByAddress (byte[] addr)
+ public static InetAddress getByAddress(byte[] addr)
throws UnknownHostException
{
- return getByAddress (null, addr);
+ return getByAddress(null, addr);
}
/**
@@ -571,55 +556,55 @@
*
* @since 1.4
*/
- public static InetAddress getByAddress (String host, byte[] addr)
+ public static InetAddress getByAddress(String host, byte[] addr)
throws UnknownHostException
{
if (addr.length == 4)
- return new Inet4Address (addr, host);
+ return new Inet4Address(addr, host);
if (addr.length == 16)
- return new Inet6Address (addr, host);
-
- throw new UnknownHostException ("IP address has illegal length");
+ return new Inet6Address(addr, host);
+
+ throw new UnknownHostException("IP address has illegal length");
}
-
+
/**
* If host is a valid numeric IP address, return the numeric address.
* Otherwise, return null.
*/
- private static byte[] aton (String hostname)
+ private static byte[] aton(String hostname)
{
- StringTokenizer st = new StringTokenizer (hostname, ".");
-
+ StringTokenizer st = new StringTokenizer(hostname, ".");
+
if (st.countTokens() == 4)
{
- int index;
- byte[] address = new byte [4];
-
- for (index = 0; index < 4; index++)
- {
- try
- {
- short n = Short.parseShort (st.nextToken());
-
- if ((n < 0) || (n > 255))
- break;
-
- address [index] = (byte) n;
- }
- catch (NumberFormatException e)
- {
- break;
- }
- }
+ int index;
+ byte[] address = new byte[4];
- if (index == 4)
- return address;
+ for (index = 0; index < 4; index++)
+ {
+ try
+ {
+ short n = Short.parseShort(st.nextToken());
+
+ if ((n < 0) || (n > 255))
+ break;
+
+ address[index] = (byte) n;
+ }
+ catch (NumberFormatException e)
+ {
+ break;
+ }
+ }
+
+ if (index == 4)
+ return address;
}
return null;
}
-
+
/**
* Returns an InetAddress object representing the IP address of the given
* hostname. This name can be either a hostname such as "www.urbanophile.com"
@@ -629,7 +614,7 @@
* the InetAddress array returned from GetAllByName.
*
* @param hostname The name of the desired host, or null for the local machine.
- *
+ *
* @return The address of the host as an InetAddress object.
*
* @exception UnknownHostException If no IP address for the host could
@@ -637,25 +622,25 @@
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
*/
- public static InetAddress getByName (String hostname)
+ public static InetAddress getByName(String hostname)
throws UnknownHostException
{
SecurityManager s = System.getSecurityManager();
if (s != null)
- s.checkConnect (hostname, -1);
-
+ s.checkConnect(hostname, -1);
+
// Default to current host if necessary
if (hostname == null || hostname.length() == 0)
return getLocalHost();
// Assume that the host string is an IP address
- byte[] address = aton (hostname);
+ byte[] address = aton(hostname);
if (address != null)
- return new InetAddress (address);
-
+ return new InetAddress(address);
+
// Try to resolve the host by DNS
- InetAddress[] addresses = getAllByName (hostname);
- return addresses [0];
+ InetAddress[] addresses = getAllByName(hostname);
+ return addresses[0];
}
/**
@@ -665,57 +650,57 @@
* dotted decimal format such as "127.0.0.1". If the value is null, the
* hostname of the local machine is supplied by default.
*
- * @param @param hostname The name of the desired host, or null for the
+ * @param hostname The name of the desired host, or null for the
* local machine.
*
* @return All addresses of the host as an array of InetAddress objects.
- *
+ *
* @exception UnknownHostException If no IP address for the host could
* be found
* @exception SecurityException If a security manager exists and its
* checkConnect method doesn't allow the operation
*/
- public static InetAddress[] getAllByName (String hostname)
+ public static InetAddress[] getAllByName(String hostname)
throws UnknownHostException
{
SecurityManager s = System.getSecurityManager();
if (s != null)
- s.checkConnect (hostname, -1);
-
+ s.checkConnect(hostname, -1);
+
// Default to current host if necessary
if (hostname == null)
{
- InetAddress local = getLocalHost();
- return getAllByName (local.getHostName());
+ InetAddress local = getLocalHost();
+ return getAllByName(local.getHostName());
}
// Check the cache for this host before doing a lookup
- InetAddress[] addresses = checkCacheFor (hostname);
-
+ InetAddress[] addresses = checkCacheFor(hostname);
+
if (addresses != null)
return addresses;
// Not in cache, try the lookup
- byte[][] iplist = getHostByName (hostname);
-
+ byte[][] iplist = getHostByName(hostname);
+
if (iplist.length == 0)
- throw new UnknownHostException (hostname);
+ throw new UnknownHostException(hostname);
- addresses = new InetAddress [iplist.length];
+ addresses = new InetAddress[iplist.length];
for (int i = 0; i < iplist.length; i++)
{
- if (iplist[i].length != 4)
- throw new UnknownHostException (hostname);
+ if (iplist[i].length != 4)
+ throw new UnknownHostException(hostname);
- // Don't store the hostname in order to force resolution of the
- // canonical names of these ip's when the user asks for the hostname
- // But do specify the host alias so if the IP returned won't
- // reverse lookup we don't throw an exception.
- addresses[i] = new InetAddress (iplist[i], null, hostname);
+ // Don't store the hostname in order to force resolution of the
+ // canonical names of these ip's when the user asks for the hostname
+ // But do specify the host alias so if the IP returned won't
+ // reverse lookup we don't throw an exception.
+ addresses[i] = new InetAddress(iplist[i], null, hostname);
}
- addToCache (hostname, addresses);
+ addToCache(hostname, addresses);
return addresses;
}
@@ -728,29 +713,28 @@
*
* @return The InetAddress for this hostname or null if not available
*/
- private static synchronized InetAddress[] checkCacheFor (String hostname)
+ private static synchronized InetAddress[] checkCacheFor(String hostname)
{
- InetAddress[]addresses = null;
+ InetAddress[] addresses = null;
if (cache_size == 0)
return (null);
- Object obj = cache.get (hostname);
+ Object obj = cache.get(hostname);
if (obj == null)
return (null);
if (obj instanceof InetAddress[])
- addresses = (InetAddress[])obj;
+ addresses = (InetAddress[]) obj;
if (addresses == null)
return (null);
if (cache_period != -1)
- if ((System.currentTimeMillis () - addresses[0].lookup_time) >
- cache_period)
+ if ((System.currentTimeMillis() - addresses[0].lookup_time) > cache_period)
{
- cache.remove (hostname);
- return (null);
+ cache.remove(hostname);
+ return (null);
}
return addresses;
@@ -765,19 +749,19 @@
* @param hostname The hostname to cache this address under
* @param obj The InetAddress or InetAddress array to store
*/
- private static synchronized void addToCache (String hostname, Object obj)
+ private static synchronized void addToCache(String hostname, Object obj)
{
if (cache_size == 0)
return;
-
+
// Check to see if hash table is full
if (cache_size != -1)
- if (cache.size () == cache_size)
+ if (cache.size() == cache_size)
{
- // FIXME Add code to purge later.
+ // FIXME Add code to purge later.
}
- cache.put (hostname, obj);
+ cache.put(hostname, obj);
}
/**
@@ -788,12 +772,12 @@
*
* @exception UnknownHostException If an error occurs
*/
- static InetAddress getInaddrAny () throws UnknownHostException
+ static InetAddress getInaddrAny() throws UnknownHostException
{
if (inaddr_any == null)
{
- byte[]tmp = lookupInaddrAny ();
- inaddr_any = new InetAddress (tmp);
+ byte[] tmp = lookupInaddrAny();
+ inaddr_any = new InetAddress(tmp);
}
return (inaddr_any);
@@ -821,7 +805,7 @@
public static InetAddress getLocalHost() throws UnknownHostException
{
String hostname = getLocalHostname();
- return getByName (hostname);
+ return getByName(hostname);
}
/**
@@ -834,19 +818,19 @@
* throw an UnknownHostException if the hostname cannot be determined.
*
* @param ip The IP address as a int array
- *
+ *
* @return The hostname
*
* @exception UnknownHostException If the reverse lookup fails
*/
- private static native String getHostByAddr (byte[] ip)
+ private static native String getHostByAddr(byte[] ip)
throws UnknownHostException;
/**
* Returns a list of all IP addresses for a given hostname. Will throw
* an UnknownHostException if the hostname cannot be resolved.
*/
- private static native byte[][] getHostByName (String hostname)
+ private static native byte[][] getHostByName(String hostname)
throws UnknownHostException;
/*
@@ -856,30 +840,30 @@
{
// FIXME: implement this
}
-
- private void readObject (ObjectInputStream ois)
+
+ private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException
{
ois.defaultReadObject();
- addr = new byte [4];
- addr [3] = (byte) address;
-
+ addr = new byte[4];
+ addr[3] = (byte) address;
+
for (int i = 2; i >= 0; --i)
- addr [i] = (byte) (address >>= 8);
-
- family = 2; /* AF_INET */
+ addr[i] = (byte) (address >>= 8);
+
+ family = 2; /* AF_INET */
}
- private void writeObject (ObjectOutputStream oos) throws IOException
+ private void writeObject(ObjectOutputStream oos) throws IOException
{
// Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address
// or a 16 byte IPv6 address.
int len = addr.length;
int i = len - 4;
-
+
for (; i < len; i++)
- address = address << 8 | (((int) addr [i]) & 0xFF);
-
+ address = address << 8 | (((int) addr[i]) & 0xFF);
+
oos.defaultWriteObject();
}
}
Index: java/net/SocketPermission.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/SocketPermission.java,v
retrieving revision 1.12
diff -u -r1.12 SocketPermission.java
--- java/net/SocketPermission.java 4 Nov 2003 10:07:50 -0000 1.12
+++ java/net/SocketPermission.java 12 Apr 2004 11:08:18 -0000
@@ -1,5 +1,5 @@
/* SocketPermission.java -- Class modeling permissions for socket operations
- Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -41,6 +41,7 @@
import java.security.Permission;
import java.security.PermissionCollection;
+
/**
* This class models a specific set of permssions for connecting to a
* host. There are two elements to this, the host/port combination and
@@ -103,12 +104,12 @@
*
* @author Aaron M. Renn (address@hidden)
*/
-public final class SocketPermission extends Permission
- implements Serializable
+public final class SocketPermission extends Permission implements Serializable
{
static final long serialVersionUID = -7204263841984476862L;
// FIXME: Needs serialization work, including readObject/writeObject methods.
+
/**
* A hostname/port combination as described above
*/
@@ -120,7 +121,7 @@
private String actions;
/**
- * Initializes a new instance of SocketPermission
with the
+ * Initializes a new instance of SocketPermission
with the
* specified host/port combination and actions string.
*
* @param hostport The hostname/port number combination
@@ -136,18 +137,18 @@
/**
* Tests this object for equality against another. This will be true if
- * and only if the passed object is an instance of
- * SocketPermission
and both its hostname/port combination
+ * and only if the passed object is an instance of
+ * SocketPermission
and both its hostname/port combination
* and permissions string are identical.
*
* @param obj The object to test against for equality
*
- * @return true
if object is equal to this object,
+ * @return true
if object is equal to this object,
* false
otherwise.
*/
public boolean equals(Object obj)
{
- if (!(obj instanceof SocketPermission))
+ if (! (obj instanceof SocketPermission))
return (false);
if (((SocketPermission) obj).hostport.equals(hostport))
@@ -158,7 +159,7 @@
}
/**
- * Returns a hash code value for this object. Overrides the
+ * Returns a hash code value for this object. Overrides the
* Permission.hashCode()
.
*
* @return A hash code
@@ -192,21 +193,21 @@
if (actions.indexOf("listen") != -1)
if (found)
- sb.append(",listen");
+ sb.append(",listen");
else
- {
+ {
sb.append("listen");
found = true;
- }
+ }
if (actions.indexOf("accept") != -1)
if (found)
sb.append(",accept");
else
- {
+ {
sb.append("accept");
found = true;
- }
+ }
if (found)
sb.append(",resolve");
@@ -231,7 +232,7 @@
/**
* Returns true if the permission object passed it is implied by the
- * this permission. This will be true if
+ * this permission. This will be true if
*
SocketPermission
* Permission
to check against
*
- * @return true
if the Permission
is implied by
+ * @return true
if the Permission
is implied by
* this object, false
otherwise.
*/
public boolean implies(Permission perm)
@@ -266,72 +267,78 @@
String ourlist = getActions();
String theirlist = p.getActions();
- if (!ourlist.startsWith(theirlist))
+ if (! ourlist.startsWith(theirlist))
return (false);
// Now check ports
- int ourfirstport = 0, ourlastport = 0, theirfirstport = 0, theirlastport =
- 0;
+ int ourfirstport = 0;
+
+ // Now check ports
+ int ourlastport = 0;
+
+ // Now check ports
+ int theirfirstport = 0;
+
+ // Now check ports
+ int theirlastport = 0;
// Get ours
if (hostport.indexOf(":") == -1)
{
- ourfirstport = 0;
- ourlastport = 65535;
+ ourfirstport = 0;
+ ourlastport = 65535;
}
else
{
- // FIXME: Needs bulletproofing.
- // This will dump if hostport if all sorts of bad data was passed to
- // the constructor
- String range = hostport.substring(hostport.indexOf(":") + 1);
- if (range.startsWith("-"))
- ourfirstport = 0;
- else if (range.indexOf("-") == -1)
- ourfirstport = Integer.parseInt(range);
- else
- ourfirstport =
- Integer.parseInt(range.substring(0, range.indexOf("-")));
-
- if (range.endsWith("-"))
- ourlastport = 65535;
- else if (range.indexOf("-") == -1)
- ourlastport = Integer.parseInt(range);
- else
- ourlastport =
- Integer.parseInt(range.
- substring(range.indexOf("-") + 1,
- range.length()));
+ // FIXME: Needs bulletproofing.
+ // This will dump if hostport if all sorts of bad data was passed to
+ // the constructor
+ String range = hostport.substring(hostport.indexOf(":") + 1);
+ if (range.startsWith("-"))
+ ourfirstport = 0;
+ else if (range.indexOf("-") == -1)
+ ourfirstport = Integer.parseInt(range);
+ else
+ ourfirstport =
+ Integer.parseInt(range.substring(0, range.indexOf("-")));
+
+ if (range.endsWith("-"))
+ ourlastport = 65535;
+ else if (range.indexOf("-") == -1)
+ ourlastport = Integer.parseInt(range);
+ else
+ ourlastport =
+ Integer.parseInt(range.substring(range.indexOf("-") + 1,
+ range.length()));
}
// Get theirs
if (p.hostport.indexOf(":") == -1)
{
- theirfirstport = 0;
- ourlastport = 65535;
+ theirfirstport = 0;
+ ourlastport = 65535;
}
else
{
- // This will dump if hostport if all sorts of bad data was passed to
- // the constructor
- String range = p.hostport.substring(hostport.indexOf(":") + 1);
- if (range.startsWith("-"))
- theirfirstport = 0;
- else if (range.indexOf("-") == -1)
- theirfirstport = Integer.parseInt(range);
- else
- theirfirstport =
- Integer.parseInt(range.substring(0, range.indexOf("-")));
-
- if (range.endsWith("-"))
- theirlastport = 65535;
- else if (range.indexOf("-") == -1)
- theirlastport = Integer.parseInt(range);
- else
- theirlastport =
- Integer.parseInt(range.
- substring(range.indexOf("-") + 1,
- range.length()));
+ // This will dump if hostport if all sorts of bad data was passed to
+ // the constructor
+ String range = p.hostport.substring(hostport.indexOf(":") + 1);
+ if (range.startsWith("-"))
+ theirfirstport = 0;
+ else if (range.indexOf("-") == -1)
+ theirfirstport = Integer.parseInt(range);
+ else
+ theirfirstport =
+ Integer.parseInt(range.substring(0, range.indexOf("-")));
+
+ if (range.endsWith("-"))
+ theirlastport = 65535;
+ else if (range.indexOf("-") == -1)
+ theirlastport = Integer.parseInt(range);
+ else
+ theirlastport =
+ Integer.parseInt(range.substring(range.indexOf("-") + 1,
+ range.length()));
}
// Now check them
@@ -339,7 +346,10 @@
return (false);
// Finally we can check the hosts
- String ourhost, theirhost;
+ String ourhost;
+
+ // Finally we can check the hosts
+ String theirhost;
// Get ours
if (hostport.indexOf(":") == -1)
@@ -358,20 +368,23 @@
return (true);
// Try the canonical names
- String ourcanonical = null, theircanonical = null;
+ String ourcanonical = null;
+
+ // Try the canonical names
+ String theircanonical = null;
try
{
- ourcanonical = InetAddress.getByName(ourhost).getHostName();
- theircanonical = InetAddress.getByName(theirhost).getHostName();
+ ourcanonical = InetAddress.getByName(ourhost).getHostName();
+ theircanonical = InetAddress.getByName(theirhost).getHostName();
}
catch (UnknownHostException e)
{
- // Who didn't resolve? Just assume current address is canonical enough
- // Is this ok to do?
- if (ourcanonical == null)
- ourcanonical = ourhost;
- if (theircanonical == null)
- theircanonical = theirhost;
+ // Who didn't resolve? Just assume current address is canonical enough
+ // Is this ok to do?
+ if (ourcanonical == null)
+ ourcanonical = ourhost;
+ if (theircanonical == null)
+ theircanonical = theirhost;
}
if (ourcanonical.equals(theircanonical))
@@ -380,9 +393,9 @@
// Well, last chance. Try for a wildcard
if (ourhost.indexOf("*.") != -1)
{
- String wild_domain = ourhost.substring(ourhost.indexOf("*" + 1));
- if (theircanonical.endsWith(wild_domain))
- return (true);
+ String wild_domain = ourhost.substring(ourhost.indexOf("*" + 1));
+ if (theircanonical.endsWith(wild_domain))
+ return (true);
}
// Didn't make it