View | Details | Raw Unified | Return to bug 180921 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/net/UnixProxyProvider.java (+95 lines)
Added Link Here
1
package org.eclipse.core.internal.net;
2
3
import java.net.URI;
4
import java.net.URISyntaxException;
5
6
import org.eclipse.core.net.proxy.IProxyData;
7
8
public class UnixProxyProvider extends AbstractProxyProvider {
9
10
	static {
11
		try {
12
			System.loadLibrary("proxysupport"); //$NON-NLS-1$
13
		} catch (UnsatisfiedLinkError ex) {
14
			// This will happen on systems that are missing Gnome libraries
15
			Activator.logInfo("Error loading native proxysupport code", ex); //$NON-NLS-1$
16
		}
17
	}
18
19
	public UnixProxyProvider() {
20
		Activator.logInfo("linuxProxyProvider initialized", null); //$NON-NLS-1$
21
	}
22
23
	public IProxyData[] getProxyData(URI uri) {
24
		String protocol = uri.getScheme();
25
26
		ProxyData pd = getSystemProxyInfo(protocol);
27
28
		if (pd != null) {
29
			IProxyData[] pds = new IProxyData[1];
30
			pds[0] = pd;
31
			return pds;
32
		}
33
34
		return new IProxyData[0];
35
	}
36
37
	protected String[] getNonProxiedHosts() {
38
		try {
39
			String[] npHosts = getGConfNonProxyHosts();
40
			if (npHosts != null && npHosts.length > 0)
41
				return npHosts;
42
			return getKdeNonProxyHosts();
43
		} catch (UnsatisfiedLinkError ex) {
44
			// This has already been reported (the native code did not load)
45
		}
46
		return new String[] {};
47
	}
48
49
	// Returns null if something wrong or there is no proxy for the protocol
50
	protected ProxyData getSystemProxyInfo(String protocol) {
51
		ProxyData pd = null;
52
53
		// First try the environment variable which is a URL
54
		String sysHttp = System.getenv(protocol.toLowerCase() + "_proxy"); //$NON-NLS-1$
55
		if (sysHttp != null) {
56
			URI uri = null;
57
			try {
58
				uri = new URI(sysHttp);
59
			} catch (URISyntaxException e) {
60
				return null;
61
			}
62
63
			pd = new ProxyData(protocol);
64
			pd.setHost(uri.getHost());
65
			pd.setPort(uri.getPort());
66
			return pd;
67
		}
68
69
		try {
70
		    // Then ask Gnome
71
			pd = getGConfProxyInfo(protocol);
72
73
			if (pd != null)
74
				return pd;
75
76
			// Then ask KDE
77
			pd = getKdeProxyInfo(protocol);
78
			if (pd != null)
79
				return pd;
80
		} catch (UnsatisfiedLinkError ex) {
81
			// This has already been reported when the native code did not load
82
		}
83
84
		return null;
85
	}
86
87
	protected static native ProxyData getGConfProxyInfo(String protocol);
88
89
	protected static native String[] getGConfNonProxyHosts();
90
91
	protected static native ProxyData getKdeProxyInfo(String protocol);
92
93
	protected static native String[] getKdeNonProxyHosts();
94
95
}

Return to bug 180921