|
Lines 7-29
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Oakland Software Incorporated - initial API and implementation |
9 |
* Oakland Software Incorporated - initial API and implementation |
|
|
10 |
* IBM Corporation - implementation |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.core.internal.net.proxy.unix; |
12 |
package org.eclipse.core.internal.net.proxy.unix; |
| 12 |
|
13 |
|
|
|
14 |
import java.io.IOException; |
| 13 |
import java.net.URI; |
15 |
import java.net.URI; |
| 14 |
import java.net.URISyntaxException; |
16 |
import java.util.Locale; |
|
|
17 |
import java.util.Properties; |
| 15 |
|
18 |
|
| 16 |
import org.eclipse.core.internal.net.AbstractProxyProvider; |
19 |
import org.eclipse.core.internal.net.AbstractProxyProvider; |
|
|
20 |
import org.eclipse.core.internal.net.Activator; |
| 17 |
import org.eclipse.core.internal.net.ProxyData; |
21 |
import org.eclipse.core.internal.net.ProxyData; |
| 18 |
import org.eclipse.core.net.proxy.IProxyData; |
22 |
import org.eclipse.core.net.proxy.IProxyData; |
| 19 |
|
23 |
|
| 20 |
public class UnixProxyProvider extends AbstractProxyProvider { |
24 |
public class UnixProxyProvider extends AbstractProxyProvider { |
| 21 |
|
25 |
|
|
|
26 |
public static boolean DEBUG = false; |
| 27 |
|
| 22 |
static { |
28 |
static { |
| 23 |
try { |
29 |
try { |
| 24 |
System.loadLibrary("libproxysupport"); //$NON-NLS-1$ |
30 |
System.loadLibrary("proxygnome"); //$NON-NLS-1$ |
|
|
31 |
// Start it up on the main thread, it seems to hand sometimes |
| 32 |
// otherwise |
| 33 |
gconfInit(); |
| 34 |
if (DEBUG) |
| 35 |
System.out.println("Loaded (Gnome) libraries"); //$NON-NLS-1$ |
| 25 |
} catch (UnsatisfiedLinkError ex) { |
36 |
} catch (UnsatisfiedLinkError ex) { |
| 26 |
// This will happen on systems that are missing Gnome libraries |
37 |
// Expected on systems that are missing Gnome libraries |
|
|
38 |
if (DEBUG) |
| 39 |
System.out.println("Missing gconf (Gnome) libraries"); //$NON-NLS-1$ |
| 27 |
} |
40 |
} |
| 28 |
} |
41 |
} |
| 29 |
|
42 |
|
|
Lines 45-59
Link Here
|
| 45 |
return new IProxyData[0]; |
58 |
return new IProxyData[0]; |
| 46 |
} |
59 |
} |
| 47 |
|
60 |
|
| 48 |
protected String[] getNonProxiedHosts() { |
61 |
public String[] getNonProxiedHosts() { |
|
|
62 |
String[] npHosts; |
| 63 |
|
| 64 |
// First try the environment variable which is a URL |
| 65 |
String npEnv = null; |
| 66 |
npEnv = getEnv("no_proxy"); //$NON-NLS-1$ |
| 67 |
if (npEnv != null) { |
| 68 |
if (DEBUG) |
| 69 |
System.out.println("got env no_proxy: " + npEnv); //$NON-NLS-1$ |
| 70 |
npHosts = npEnv.split(","); //$NON-NLS-1$ |
| 71 |
for (int i = 0; i < npHosts.length; i++) |
| 72 |
npHosts[i] = npHosts[i].trim(); |
| 73 |
return debugPrint(npHosts); |
| 74 |
} |
| 75 |
|
| 49 |
try { |
76 |
try { |
| 50 |
String[] npHosts = getGConfNonProxyHosts(); |
77 |
npHosts = getGConfNonProxyHosts(); |
| 51 |
if (npHosts != null && npHosts.length > 0) |
78 |
if (npHosts != null && npHosts.length > 0) { |
| 52 |
return npHosts; |
79 |
if (DEBUG) |
| 53 |
return getKdeNonProxyHosts(); |
80 |
System.out.println("got gnome no_proxy"); //$NON-NLS-1$ |
|
|
81 |
return debugPrint(npHosts); |
| 82 |
} |
| 54 |
} catch (UnsatisfiedLinkError ex) { |
83 |
} catch (UnsatisfiedLinkError ex) { |
|
|
84 |
// Expected on systems that are missing Gnome libraries |
| 55 |
// This has already been reported (the native code did not load) |
85 |
// This has already been reported (the native code did not load) |
| 56 |
} |
86 |
} |
|
|
87 |
|
| 57 |
return new String[] {}; |
88 |
return new String[] {}; |
| 58 |
} |
89 |
} |
| 59 |
|
90 |
|
|
Lines 61-109
Link Here
|
| 61 |
protected ProxyData getSystemProxyInfo(String protocol) { |
92 |
protected ProxyData getSystemProxyInfo(String protocol) { |
| 62 |
ProxyData pd = null; |
93 |
ProxyData pd = null; |
| 63 |
|
94 |
|
| 64 |
// First try the environment variable which is a URL |
95 |
String envName = null; |
| 65 |
// TODO: native calls for system properties, since System#getenx is |
96 |
String proxyEnv = null; |
| 66 |
// deprecated in 1.4 |
97 |
URI uri = null; |
| 67 |
String sysHttp = null; |
|
|
| 68 |
// System.getenv(protocol.toLowerCase() + "_proxy"); //$NON-NLS-1$ |
| 69 |
if (sysHttp != null) { |
| 70 |
URI uri = null; |
| 71 |
try { |
| 72 |
uri = new URI(sysHttp); |
| 73 |
} catch (URISyntaxException e) { |
| 74 |
return null; |
| 75 |
} |
| 76 |
|
98 |
|
| 77 |
pd = new ProxyData(protocol); |
99 |
try { |
| 78 |
pd.setHost(uri.getHost()); |
100 |
if (DEBUG) |
| 79 |
pd.setPort(uri.getPort()); |
101 |
System.out.println("getting ProxyData for: " + protocol); //$NON-NLS-1$ |
| 80 |
return pd; |
102 |
|
|
|
103 |
// protocol schemes are ISO 8859 (ASCII) |
| 104 |
protocol = protocol.toLowerCase(Locale.ENGLISH); |
| 105 |
|
| 106 |
// First try the environment variable which is a URL |
| 107 |
envName = protocol + "_proxy"; //$NON-NLS-1$ |
| 108 |
proxyEnv = getEnv(envName); |
| 109 |
if (DEBUG) |
| 110 |
System.out.println("got proxyEnv: " + proxyEnv); //$NON-NLS-1$ |
| 111 |
|
| 112 |
if (proxyEnv != null) { |
| 113 |
uri = new URI(proxyEnv); |
| 114 |
pd = new ProxyData(protocol); |
| 115 |
pd.setHost(uri.getHost()); |
| 116 |
pd.setPort(uri.getPort()); |
| 117 |
String userInfo = uri.getUserInfo(); |
| 118 |
if (userInfo != null) { |
| 119 |
String user = null; |
| 120 |
String password = null; |
| 121 |
int pwInd = userInfo.indexOf(':'); |
| 122 |
if (pwInd >= 0) { |
| 123 |
user = userInfo.substring(0, pwInd); |
| 124 |
password = userInfo.substring(pwInd + 1); |
| 125 |
} else { |
| 126 |
user = userInfo; |
| 127 |
} |
| 128 |
pd.setUserid(user); |
| 129 |
pd.setPassword(password); |
| 130 |
} |
| 131 |
|
| 132 |
if (DEBUG) |
| 133 |
System.out.println("env proxy data: " + pd); //$NON-NLS-1$ |
| 134 |
return pd; |
| 135 |
} |
| 136 |
} catch (Exception ex) { |
| 137 |
Activator.logError( |
| 138 |
"Problem during accessing system variable: " + envName, ex); //$NON-NLS-1$ |
| 81 |
} |
139 |
} |
| 82 |
|
140 |
|
| 83 |
try { |
141 |
try { |
| 84 |
// Then ask Gnome |
142 |
// Then ask Gnome |
| 85 |
pd = getGConfProxyInfo(protocol); |
143 |
pd = getGConfProxyInfo(protocol); |
|
|
144 |
if (DEBUG) |
| 145 |
System.out.println("Gnome proxy data: " + pd); //$NON-NLS-1$ |
| 146 |
return pd; |
| 86 |
|
147 |
|
| 87 |
if (pd != null) |
|
|
| 88 |
return pd; |
| 89 |
|
| 90 |
// Then ask KDE |
| 91 |
pd = getKdeProxyInfo(protocol); |
| 92 |
if (pd != null) |
| 93 |
return pd; |
| 94 |
} catch (UnsatisfiedLinkError ex) { |
148 |
} catch (UnsatisfiedLinkError ex) { |
| 95 |
// This has already been reported when the native code did not load |
149 |
// Expected on systems that are missing Gnome libraries |
|
|
150 |
// This has already been reported (the native code did not load) |
| 96 |
} |
151 |
} |
| 97 |
|
152 |
|
| 98 |
return null; |
153 |
return null; |
| 99 |
} |
154 |
} |
| 100 |
|
155 |
|
| 101 |
protected static native ProxyData getGConfProxyInfo(String protocol); |
156 |
private String getEnv(String env) { |
|
|
157 |
Properties props = new Properties(); |
| 158 |
try { |
| 159 |
props.load(Runtime.getRuntime().exec("env").getInputStream()); //$NON-NLS-1$ |
| 160 |
} catch (IOException e) { |
| 161 |
Activator.logError( |
| 162 |
"Problem during accessing system variable: " + env, e); //$NON-NLS-1$ |
| 163 |
} |
| 164 |
return props.getProperty(env); |
| 165 |
} |
| 102 |
|
166 |
|
| 103 |
protected static native String[] getGConfNonProxyHosts(); |
167 |
private String[] debugPrint(String[] strs) { |
|
|
168 |
if (DEBUG) { |
| 169 |
System.out.println("npHosts: "); //$NON-NLS-1$ |
| 170 |
for (int i = 0; i < strs.length; i++) |
| 171 |
System.out.println(i + ": " + strs[i]); //$NON-NLS-1$ |
| 172 |
} |
| 173 |
return strs; |
| 174 |
} |
| 104 |
|
175 |
|
| 105 |
protected static native ProxyData getKdeProxyInfo(String protocol); |
176 |
protected static native void gconfInit(); |
| 106 |
|
177 |
|
| 107 |
protected static native String[] getKdeNonProxyHosts(); |
178 |
protected static native ProxyData getGConfProxyInfo(String protocol); |
| 108 |
|
179 |
|
|
|
180 |
protected static native String[] getGConfNonProxyHosts(); |
| 109 |
} |
181 |
} |