diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index dc9b2fd..d06089e 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -1,5 +1,5 @@ // -// $Id: Application.java,v 1.19 2004/07/26 23:27:46 mdb Exp $ +// $Id: Application.java,v 1.20 2004/07/29 17:57:45 mdb Exp $ package com.threerings.getdown.data; @@ -358,8 +358,16 @@ public class Application cpbuf.append(rsrc.getLocal().getAbsolutePath()); } + String proxyHost, proxyPort = null; + int pargs = 0; + if ((proxyHost = System.getProperty("http.proxyHost")) != null) { + pargs = 2; + proxyPort = System.getProperty("http.proxyPort"); + } + // we'll need the JVM, classpath, JVM args, class name and app args - String[] args = new String[4 + _jvmargs.size() + _appargs.size()]; + String[] args = new String[ + 4 + _jvmargs.size() + pargs + _appargs.size()]; int idx = 0; // reconstruct the path to the JVM @@ -370,6 +378,12 @@ public class Application args[idx++] = "-classpath"; args[idx++] = cpbuf.toString(); + // if we have a proxy configuration, add those + if (proxyHost != null) { + args[idx++] = "-Dhttp.proxyHost=" + proxyHost; + args[idx++] = "-Dhttp.proxyPort=" + proxyPort; + } + // add the JVM arguments for (Iterator iter = _jvmargs.iterator(); iter.hasNext(); ) { args[idx++] = processArg((String)iter.next()); diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index dde165d..dffd51d 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -1,5 +1,5 @@ // -// $Id: Getdown.java,v 1.21 2004/07/28 08:05:44 mdb Exp $ +// $Id: Getdown.java,v 1.22 2004/07/29 17:57:45 mdb Exp $ package com.threerings.getdown.launcher; @@ -18,6 +18,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.net.URL; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -34,6 +35,7 @@ import com.threerings.getdown.data.Application; import com.threerings.getdown.data.Resource; import com.threerings.getdown.tools.Patcher; import com.threerings.getdown.util.ProgressObserver; +import com.threerings.getdown.util.ProxyUtil; /** * Manages the main control for the Getdown application updater and @@ -354,6 +356,21 @@ public class Getdown extends Thread Log.warning("Unable to redirect output to '" + log + "': " + ioe); } + // attempt to obtain our proxy information; it may be specified + // via system properties or we can autodetect it + if (System.getProperty("http.proxyHost") == null) { + try { + URL sample = new URL("http://www.threerings.net/"); + if (ProxyUtil.detectProxy(sample)) { + String host = ProxyUtil.getProxyIP(); + String port = ProxyUtil.getProxyPort(); + ProxyUtil.configureProxy(host, port); + } + } catch (Exception e) { + Log.warning("Failed to detect proxy: " + e); + } + } + try { Getdown app = new Getdown(appDir); app.start(); diff --git a/src/java/com/threerings/getdown/util/ProxyUtil.java b/src/java/com/threerings/getdown/util/ProxyUtil.java new file mode 100644 index 0000000..c9f55fa --- /dev/null +++ b/src/java/com/threerings/getdown/util/ProxyUtil.java @@ -0,0 +1,119 @@ +// +// $Id: ProxyUtil.java,v 1.1 2004/07/29 17:57:45 mdb Exp $ + +package com.threerings.getdown.util; + +import java.net.URL; + +import com.threerings.getdown.Log; + +/** + * Code to detect a user's proxy settings. + */ +public class ProxyUtil +{ + /** + * Detects whether or not there are proxy settings that should be used + * by this JVM. + * + * @return true if there are such settings, false if not. + */ + public static boolean detectProxy (URL sampleURL) + { + try { + // Look around for the 1.4.X plugin proxy detection + // class... Without it, cannot autodetect... + Class t = Class.forName("com.sun.java.browser.net.ProxyService"); + com.sun.java.browser.net.ProxyInfo[] pi = + com.sun.java.browser.net.ProxyService.getProxyInfo(sampleURL); + if (pi == null || pi.length == 0) { + Log.info("1.4.X reported NULL proxy (no proxy assumed)."); + return false; + + } else { + Log.info("1.4.X Proxy info getProxy: " + pi[0].getHost() + + " getPort: " + pi[0].getPort() + + " isSocks: " + pi[0].isSocks()); + _proxyIP = pi[0].getHost(); + _proxyPort = "" + pi[0].getPort(); + Log.info("Detected proxy " + _proxyIP + " port " + _proxyPort); + return true; + } + + } catch (Exception ee) { + Log.info("Sun Plugin 1.4.X proxy detection class not " + + "found: " + ee + ". Trying failover detection..."); + } + + try { + String key = "javaplugin.proxy.config.list"; + String proxyList = (String) + System.getProperties().getProperty(key); + proxyList = proxyList.toUpperCase(); + Log.info("Plugin proxy config list: " + proxyList); + + // Using HTTP proxy as proxy for HTTP proxy tunnelled SSL + // socket (should be listed FIRST).... + if (proxyList != null) { + // 6.0.0 1/14/03 1.3.1_06 appears to omit HTTP portion of + // 6.0.reported proxy list... Mod to accomodate this... + + // Expecting proxyList of "HTTP=XXX.XXX.XXX.XXX:Port" + // OR "XXX.XXX.XXX.XXX:Port" & assuming HTTP... + if (proxyList.indexOf("HTTP=") > -1) { + _proxyIP = proxyList.substring( + proxyList.indexOf("HTTP=") + 5, + proxyList.indexOf(":")); + } else { + _proxyIP = proxyList.substring( + 0, proxyList.indexOf(":")); + } + int endOfPort = proxyList.indexOf(","); + if (endOfPort < 1) { + endOfPort = proxyList.length(); + } + _proxyPort = proxyList.substring(proxyList.indexOf(":") + 1, + endOfPort); + Log.info("Detected proxy " + _proxyIP + " port " + _proxyPort); + return true; + } + + } catch (Exception e) { + Log.warning("Exception during failover auto proxy detect: " + e); + } + + return false; + } + + /** + * Returns the IP of the detected proxy. This is only valid after a + * call to {@link #detectProxy} that returns true. + */ + public static String getProxyIP () + { + return _proxyIP; + } + + /** + * Returns the port of the detected proxy. This is only valid after a + * call to {@link #detectProxy} that returns true. + */ + public static String getProxyPort () + { + return _proxyPort; + } + + /** + * Sets the necessary system properties to enact the use of this proxy + * host and port. + */ + public static void configureProxy (String host, String port) + { + System.setProperty("http.proxyHost", host); + System.setProperty("http.proxyPort", port); + } + + protected static String _proxyIP; + protected static String _proxyPort = "80"; + protected static boolean _useProxy = false; +}