### Eclipse Workspace Patch 1.0 #P org.eclipse.core.net Index: src/org/eclipse/core/internal/net/UnixProxyProvider.java =================================================================== RCS file: src/org/eclipse/core/internal/net/UnixProxyProvider.java diff -N src/org/eclipse/core/internal/net/UnixProxyProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/core/internal/net/UnixProxyProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,95 @@ +package org.eclipse.core.internal.net; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.eclipse.core.net.proxy.IProxyData; + +public class UnixProxyProvider extends AbstractProxyProvider { + + static { + try { + System.loadLibrary("proxysupport"); //$NON-NLS-1$ + } catch (UnsatisfiedLinkError ex) { + // This will happen on systems that are missing Gnome libraries + Activator.logInfo("Error loading native proxysupport code", ex); //$NON-NLS-1$ + } + } + + public UnixProxyProvider() { + Activator.logInfo("linuxProxyProvider initialized", null); //$NON-NLS-1$ + } + + public IProxyData[] getProxyData(URI uri) { + String protocol = uri.getScheme(); + + ProxyData pd = getSystemProxyInfo(protocol); + + if (pd != null) { + IProxyData[] pds = new IProxyData[1]; + pds[0] = pd; + return pds; + } + + return new IProxyData[0]; + } + + protected String[] getNonProxiedHosts() { + try { + String[] npHosts = getGConfNonProxyHosts(); + if (npHosts != null && npHosts.length > 0) + return npHosts; + return getKdeNonProxyHosts(); + } catch (UnsatisfiedLinkError ex) { + // This has already been reported (the native code did not load) + } + return new String[] {}; + } + + // Returns null if something wrong or there is no proxy for the protocol + protected ProxyData getSystemProxyInfo(String protocol) { + ProxyData pd = null; + + // First try the environment variable which is a URL + String sysHttp = System.getenv(protocol.toLowerCase() + "_proxy"); //$NON-NLS-1$ + if (sysHttp != null) { + URI uri = null; + try { + uri = new URI(sysHttp); + } catch (URISyntaxException e) { + return null; + } + + pd = new ProxyData(protocol); + pd.setHost(uri.getHost()); + pd.setPort(uri.getPort()); + return pd; + } + + try { + // Then ask Gnome + pd = getGConfProxyInfo(protocol); + + 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 + } + + return null; + } + + protected static native ProxyData getGConfProxyInfo(String protocol); + + protected static native String[] getGConfNonProxyHosts(); + + protected static native ProxyData getKdeProxyInfo(String protocol); + + protected static native String[] getKdeNonProxyHosts(); + +}