diff options
author | Tomasz Zarna | 2008-04-25 10:40:52 +0000 |
---|---|---|
committer | Tomasz Zarna | 2008-04-25 10:40:52 +0000 |
commit | 608cb1c2a142c1785c64f0a9c752a57586d0fcf7 (patch) | |
tree | 57941cdfaa4a96205c503a84358013f52efa7bc4 /bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net | |
parent | 8bad68e595f10fdeaea93f282f33db7ae2fe5c62 (diff) | |
download | eclipse.platform.team-608cb1c2a142c1785c64f0a9c752a57586d0fcf7.tar.gz eclipse.platform.team-608cb1c2a142c1785c64f0a9c752a57586d0fcf7.tar.xz eclipse.platform.team-608cb1c2a142c1785c64f0a9c752a57586d0fcf7.zip |
bug 226462: [Proxy] Use system values for proxy settings on Linux (fix for UnixProxyProvider)
Diffstat (limited to 'bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net')
-rw-r--r-- | bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java | 142 |
1 files changed, 107 insertions, 35 deletions
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java index 60a288e79..f9d88cf3f 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java @@ -7,23 +7,36 @@ * * Contributors: * Oakland Software Incorporated - initial API and implementation + * IBM Corporation - implementation *******************************************************************************/ package org.eclipse.core.internal.net.proxy.unix; +import java.io.IOException; import java.net.URI; -import java.net.URISyntaxException; +import java.util.Locale; +import java.util.Properties; import org.eclipse.core.internal.net.AbstractProxyProvider; +import org.eclipse.core.internal.net.Activator; import org.eclipse.core.internal.net.ProxyData; import org.eclipse.core.net.proxy.IProxyData; public class UnixProxyProvider extends AbstractProxyProvider { + public static boolean DEBUG = false; + static { try { - System.loadLibrary("libproxysupport"); //$NON-NLS-1$ + System.loadLibrary("proxygnome"); //$NON-NLS-1$ + // Start it up on the main thread, it seems to hand sometimes + // otherwise + gconfInit(); + if (DEBUG) + System.out.println("Loaded (Gnome) libraries"); //$NON-NLS-1$ } catch (UnsatisfiedLinkError ex) { - // This will happen on systems that are missing Gnome libraries + // Expected on systems that are missing Gnome libraries + if (DEBUG) + System.out.println("Missing gconf (Gnome) libraries"); //$NON-NLS-1$ } } @@ -45,15 +58,36 @@ public class UnixProxyProvider extends AbstractProxyProvider { return new IProxyData[0]; } - protected String[] getNonProxiedHosts() { + public String[] getNonProxiedHosts() { + String[] npHosts; + + // First try the environment variable which is a URL + String npEnv = getEnv("no_proxy"); //$NON-NLS-1$ + if (npEnv != null) { + npHosts = npEnv.split(","); //$NON-NLS-1$ + for (int i = 0; i < npHosts.length; i++) + npHosts[i] = npHosts[i].trim(); + if (DEBUG) { + System.out.println("got env no_proxy: " + npEnv); //$NON-NLS-1$ + debugPrint(npHosts); + } + return npHosts; + } + try { - String[] npHosts = getGConfNonProxyHosts(); - if (npHosts != null && npHosts.length > 0) + npHosts = getGConfNonProxyHosts(); + if (npHosts != null && npHosts.length > 0) { + if (DEBUG) { + System.out.println("got gnome no_proxy"); //$NON-NLS-1$ + debugPrint(npHosts); + } return npHosts; - return getKdeNonProxyHosts(); + } } catch (UnsatisfiedLinkError ex) { + // Expected on systems that are missing Gnome libraries // This has already been reported (the native code did not load) } + return new String[] {}; } @@ -61,49 +95,87 @@ public class UnixProxyProvider extends AbstractProxyProvider { protected ProxyData getSystemProxyInfo(String protocol) { ProxyData pd = null; - // First try the environment variable which is a URL - // TODO: native calls for system properties, since System#getenx is - // deprecated in 1.4 - String sysHttp = null; - // System.getenv(protocol.toLowerCase() + "_proxy"); //$NON-NLS-1$ - if (sysHttp != null) { - URI uri = null; - try { - uri = new URI(sysHttp); - } catch (URISyntaxException e) { - return null; - } + String envName = null; + String proxyEnv = null; + URI uri = null; - pd = new ProxyData(protocol); - pd.setHost(uri.getHost()); - pd.setPort(uri.getPort()); - return pd; + try { + if (DEBUG) + System.out.println("getting ProxyData for: " + protocol); //$NON-NLS-1$ + + // protocol schemes are ISO 8859 (ASCII) + protocol = protocol.toLowerCase(Locale.ENGLISH); + + // First try the environment variable which is a URL + envName = protocol + "_proxy"; //$NON-NLS-1$ + proxyEnv = getEnv(envName); + if (DEBUG) + System.out.println("got proxyEnv: " + proxyEnv); //$NON-NLS-1$ + + if (proxyEnv != null) { + uri = new URI(proxyEnv); + pd = new ProxyData(protocol); + pd.setHost(uri.getHost()); + pd.setPort(uri.getPort()); + String userInfo = uri.getUserInfo(); + if (userInfo != null) { + String user = null; + String password = null; + int pwInd = userInfo.indexOf(':'); + if (pwInd >= 0) { + user = userInfo.substring(0, pwInd); + password = userInfo.substring(pwInd + 1); + } else { + user = userInfo; + } + pd.setUserid(user); + pd.setPassword(password); + } + + if (DEBUG) + System.out.println("env proxy data: " + pd); //$NON-NLS-1$ + return pd; + } + } catch (Exception ex) { + Activator.logError( + "Problem during accessing system variable: " + envName, ex); //$NON-NLS-1$ } try { // Then ask Gnome pd = getGConfProxyInfo(protocol); + if (DEBUG) + System.out.println("Gnome proxy data: " + pd); //$NON-NLS-1$ + return pd; - if (pd != null) - return pd; - - // Then ask KDE - pd = getKdeProxyInfo(protocol); - if (pd != null) - return pd; } catch (UnsatisfiedLinkError ex) { - // This has already been reported when the native code did not load + // Expected on systems that are missing Gnome libraries + // This has already been reported (the native code did not load) } return null; } - protected static native ProxyData getGConfProxyInfo(String protocol); + private String getEnv(String env) { + Properties props = new Properties(); + try { + props.load(Runtime.getRuntime().exec("env").getInputStream()); //$NON-NLS-1$ + } catch (IOException e) { + Activator.logError( + "Problem during accessing system variable: " + env, e); //$NON-NLS-1$ + } + return props.getProperty(env); + } - protected static native String[] getGConfNonProxyHosts(); + private void debugPrint(String[] strs) { + System.out.println("npHosts: "); //$NON-NLS-1$ + for (int i = 0; i < strs.length; i++) + System.out.println(i + ": " + strs[i]); //$NON-NLS-1$ + } - protected static native ProxyData getKdeProxyInfo(String protocol); + protected static native void gconfInit(); - protected static native String[] getKdeNonProxyHosts(); + protected static native ProxyData getGConfProxyInfo(String protocol); + protected static native String[] getGConfNonProxyHosts(); } |