System.java (static): Set http.agent system property when not yet set.
authorMark Wielaard <mark@klomp.org>
Fri, 23 Jul 2004 11:49:59 +0000 (11:49 +0000)
committerMark Wielaard <mark@gcc.gnu.org>
Fri, 23 Jul 2004 11:49:59 +0000 (11:49 +0000)
       * java/lang/System.java (static): Set http.agent system property when
       not yet set.
       * gnu/java/net/protocol/http/Connection.java (static): Get httpAgent
       from system property inside AccessController.doPrivileged() call.
       (proxyPort): Made package private.
       (proxyInUse): Likewise.
       (proxyHost): Likewise.
       (userAgent): Likewise.

From-SVN: r85078

libjava/ChangeLog
libjava/gnu/java/net/protocol/http/Connection.java
libjava/java/lang/System.java

index c237e7f01eafd9e178ddf54680ee9fbf61af388a..e9dd6797d3463ada4ce953fabf1782ace6db440b 100644 (file)
@@ -1,3 +1,14 @@
+2004-07-23  Mark Wielaard  <mark@klomp.org>
+
+       * java/lang/System.java (static): Set http.agent system property when
+       not yet set.
+       * gnu/java/net/protocol/http/Connection.java (static): Get httpAgent
+       from system property inside AccessController.doPrivileged() call.
+       (proxyPort): Made package private.
+       (proxyInUse): Likewise.
+       (proxyHost): Likewise.
+       (userAgent): Likewise.
+
 2004-07-23  Mark Wielaard  <mark@klomp.org>
 
        * gnu/java/net/DefaultContentHandlerFactory.java: New dummy
index 44239e1721a3a19c8a37a0f77091c5a1acacb2ae..728d14a7e6b9d1329bb86fe69826315f6bd0253e 100644 (file)
@@ -1,5 +1,6 @@
 /* HttpURLConnection.java -- URLConnection class for HTTP protocol
-   Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -52,6 +53,8 @@ import java.net.ProtocolException;
 import java.net.Socket;
 import java.net.URL;
 import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -76,41 +79,45 @@ public final class Connection extends HttpURLConnection
    * The socket we are connected to
    */
   private Socket socket;
-  private static int proxyPort = 80;
-  private static boolean proxyInUse = false;
-  private static String proxyHost = null;
-
-  private static final String userAgent;
+  
+  // Properties depeending on system properties settings
+  static int proxyPort = 80;
+  static boolean proxyInUse = false;
+  static String proxyHost = null;
+  static String userAgent;
 
   static 
   {
-    // Recognize some networking properties listed at
-    // http://java.sun.com/j2se/1.4/docs/guide/net/properties.html.
-    String port = null;
-    proxyHost = System.getProperty("http.proxyHost");
-    if (proxyHost != null)
-      {
-       proxyInUse = true;
-       if ((port = System.getProperty("http.proxyPort")) != null)
-         {
-           try
-             {
-               proxyPort = Integer.parseInt(port);
-             }
-           catch (Throwable t)
-             {
-               // Nothing.  
-             }
-         }
-      }
+    // Make sure access control for system properties depends only on
+    // our class ProtectionDomain, not on any (indirect) callers.
+    AccessController.doPrivileged(new PrivilegedAction() {
+       public Object run()
+       {
+         // Recognize some networking properties listed at
+         // http://java.sun.com/j2se/1.4/docs/guide/net/properties.html.
+         String port = null;
+         proxyHost = System.getProperty("http.proxyHost");
+         if (proxyHost != null)
+           {
+             proxyInUse = true;
+             if ((port = System.getProperty("http.proxyPort")) != null)
+               {
+                 try
+                   {
+                     proxyPort = Integer.parseInt(port);
+                   }
+                 catch (Throwable t)
+                   {
+                     // Nothing.  
+                   }
+               }
+           }
+         
+         userAgent = System.getProperty("http.agent");
 
-    userAgent = "gnu-classpath/"
-      + System.getProperty("gnu.classpath.version")
-      + " ("
-      + System.getProperty("gnu.classpath.vm.shortname")
-      + "/"
-      + System.getProperty("java.vm.version")
-      + ")";
+         return null;
+       }
+      });
   }
 
   /**
index d75298718453fdf37feb7ce7cce4f21d7f00ed2d..a8c0c23c0db9845fca864e7d2996e29a2b289e07 100644 (file)
@@ -1,5 +1,6 @@
 /* System.java -- useful methods to interface with the system
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -98,6 +99,20 @@ public final class System
        defaultProperties.put("gnu.classpath.vm.shortname", value);
       }
 
+    // Network properties
+    if (defaultProperties.get("http.agent") == null)
+      {
+       String userAgent
+         = ("gnu-classpath/"
+            + defaultProperties.getProperty("gnu.classpath.version")
+            + " ("
+            + defaultProperties.getProperty("gnu.classpath.vm.shortname")
+            + "/"
+            + defaultProperties.getProperty("java.vm.version")
+            + ")");
+       defaultProperties.put("http.agent", userAgent);
+      }
+
     defaultProperties.put("gnu.cpu.endian",
                          isWordsBigEndian() ? "big" : "little");