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

Collapse All | Expand All

(-)src/org/eclipse/core/net/proxy/IProxyService.java (+43 lines)
Lines 28-33 Link Here
28
	 * before calling the {@link #getProxyData()} or {@link #getProxyData(String)} method.
28
	 * before calling the {@link #getProxyData()} or {@link #getProxyData(String)} method.
29
	 * However, the {@link #getProxyDataForHost(String)} and {@link #getProxyDataForHost(String, String)}
29
	 * However, the {@link #getProxyDataForHost(String)} and {@link #getProxyDataForHost(String, String)}
30
	 * method will check the enablement and only return data if the service is enabled.
30
	 * method will check the enablement and only return data if the service is enabled.
31
	 * 
32
	 * <p>
33
	 * It the proxy should use system proxies, but {@link #hasSystemProxies()} returns <code>false</code>,
34
	 * this method will return <code>false</code>.
35
	 * </p>
36
	 * 
31
	 * @param enabled whether proxy support should be enabled
37
	 * @param enabled whether proxy support should be enabled
32
	 */
38
	 */
33
	void setProxiesEnabled(boolean enabled);
39
	void setProxiesEnabled(boolean enabled);
Lines 40-48 Link Here
40
	boolean isProxiesEnabled();
46
	boolean isProxiesEnabled();
41
	
47
	
42
	/**
48
	/**
49
	 * Return whether system proxy support is available.
50
	 * @return whether system proxy support is available
51
	 */
52
	boolean hasSystemProxies();
53
	
54
	/**
55
	 * Set whether system proxies should be used, when the proxy support is enabled.
56
	 * @param enabled
57
	 */
58
	void setSystemProxiesEnabled(boolean enabled);
59
	
60
	
61
	/**
62
	 * Return whether system proxy is used when the proxy support is enabled.
63
	 * @return whether system proxy is used when the proxy support is enabled
64
	 */
65
	boolean isSystemProxiesEnabled();
66
	
67
	/**
43
	 * Return the list of know proxy types and their settings.
68
	 * Return the list of know proxy types and their settings.
44
	 * Some of the returned proxy types may not be enabled (i.e,
69
	 * Some of the returned proxy types may not be enabled (i.e,
45
	 * their hosts may be <code>null</code>.
70
	 * their hosts may be <code>null</code>.
71
	 * 
72
	 * <p>
73
	 * This method gets proxies that are used when system proxy support 
74
	 * is disabled. 
75
	 * </p>
76
	 * 
46
	 * @return the list of know proxy types and their settings
77
	 * @return the list of know proxy types and their settings
47
	 */
78
	 */
48
	IProxyData[] getProxyData();
79
	IProxyData[] getProxyData();
Lines 63-68 Link Here
63
	 * Return the proxy data for the proxy of the given type
94
	 * Return the proxy data for the proxy of the given type
64
	 * or <code>null</code> if the proxy type is not known by this
95
	 * or <code>null</code> if the proxy type is not known by this
65
	 * service.
96
	 * service.
97
	 * 
98
	 * <p>
99
	 * This method gets proxies that are used when system proxy support 
100
	 * is disabled. 
101
	 * </p>
102
	 * 
66
	 * @param type the proxy type
103
	 * @param type the proxy type
67
	 * @return the proxy data for the proxy of the given type
104
	 * @return the proxy data for the proxy of the given type
68
	 * or <code>null</code>
105
	 * or <code>null</code>
Lines 92-97 Link Here
92
	 * If an unknown type is provided, it will be ignored. Any
129
	 * If an unknown type is provided, it will be ignored. Any
93
	 * known types that are not present in the list of the provided
130
	 * known types that are not present in the list of the provided
94
	 * proxy data will be unaffected.
131
	 * proxy data will be unaffected.
132
	 * 
133
	 * <p>
134
	 * This method sets proxies that are used when system proxy support 
135
	 * is disabled. Doesn't affect system proxies. 
136
	 * </p>
137
	 * 
95
	 * @param proxies the proxy data whose information is to be set.
138
	 * @param proxies the proxy data whose information is to be set.
96
	 * @throws CoreException if the proxy could not be set
139
	 * @throws CoreException if the proxy could not be set
97
	 */
140
	 */
(-)src/org/eclipse/core/internal/net/ProxyManager.java (-14 / +95 lines)
Lines 11-24 Link Here
11
package org.eclipse.core.internal.net;
11
package org.eclipse.core.internal.net;
12
12
13
import java.net.Authenticator;
13
import java.net.Authenticator;
14
import java.util.*;
14
import java.net.URI;
15
15
import java.net.URISyntaxException;
16
import org.eclipse.core.net.proxy.*;
16
import java.util.ArrayList;
17
import org.eclipse.core.runtime.*;
17
import java.util.List;
18
import java.util.Properties;
19
20
import org.eclipse.core.net.proxy.IProxyChangeEvent;
21
import org.eclipse.core.net.proxy.IProxyChangeListener;
22
import org.eclipse.core.net.proxy.IProxyData;
23
import org.eclipse.core.net.proxy.IProxyService;
24
import org.eclipse.core.runtime.Assert;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IConfigurationElement;
27
import org.eclipse.core.runtime.IExtension;
28
import org.eclipse.core.runtime.ISafeRunnable;
29
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.ListenerList;
31
import org.eclipse.core.runtime.Platform;
32
import org.eclipse.core.runtime.SafeRunner;
18
import org.eclipse.core.runtime.preferences.ConfigurationScope;
33
import org.eclipse.core.runtime.preferences.ConfigurationScope;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
34
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.preferences.InstanceScope;
35
import org.eclipse.core.runtime.preferences.InstanceScope;
21
import org.eclipse.core.runtime.preferences.IEclipsePreferences.*;
36
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
37
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
22
import org.eclipse.osgi.util.NLS;
38
import org.eclipse.osgi.util.NLS;
23
import org.osgi.service.prefs.BackingStoreException;
39
import org.osgi.service.prefs.BackingStoreException;
24
import org.osgi.service.prefs.Preferences;
40
import org.osgi.service.prefs.Preferences;
Lines 36-44 Link Here
36
	
52
	
37
	private static final String PREF_NON_PROXIED_HOSTS = "nonProxiedHosts"; //$NON-NLS-1$
53
	private static final String PREF_NON_PROXIED_HOSTS = "nonProxiedHosts"; //$NON-NLS-1$
38
	private static final String PREF_ENABLED = "proxiesEnabled"; //$NON-NLS-1$
54
	private static final String PREF_ENABLED = "proxiesEnabled"; //$NON-NLS-1$
55
	private static final String PREF_OS = "systemProxiesEnabled"; //$NON-NLS-1$
39
	
56
	
40
	private static IProxyService proxyManager;
57
	private static IProxyService proxyManager;
41
	
58
	
59
	private AbstractProxyProvider nativeProxyProvider;
60
	
42
	ListenerList listeners = new ListenerList(ListenerList.IDENTITY);
61
	ListenerList listeners = new ListenerList(ListenerList.IDENTITY);
43
	private String[] nonProxiedHosts;
62
	private String[] nonProxiedHosts;
44
	private final ProxyType[] proxies = new ProxyType[] {
63
	private final ProxyType[] proxies = new ProxyType[] {
Lines 49-54 Link Here
49
68
50
	private boolean migrated = false;
69
	private boolean migrated = false;
51
70
71
	private ProxyManager() {
72
		try {
73
			nativeProxyProvider = (AbstractProxyProvider) Class.forName(
74
					"org.eclipse.core.net.ProxyProvider").newInstance(); //$NON-NLS-1$
75
		} catch (ClassNotFoundException e) {
76
			// no class found
77
		} catch (Exception e) {
78
			Activator.logInfo("noNativeProxyProvider", e); //$NON-NLS-1$
79
		}
80
	}
81
52
	/**
82
	/**
53
	 * Return the proxy manager.
83
	 * Return the proxy manager.
54
	 * @return the proxy manager
84
	 * @return the proxy manager
Lines 160-166 Link Here
160
		for (int i = 0; i < proxyDatas.length; i++) {
190
		for (int i = 0; i < proxyDatas.length; i++) {
161
			IProxyData proxyData = proxyDatas[i];
191
			IProxyData proxyData = proxyDatas[i];
162
			ProxyType type = getType(proxyData);
192
			ProxyType type = getType(proxyData);
163
			if (type != null && type.setProxyData(proxyData, isProxiesEnabled())) {
193
			if (type != null && type.setProxyData(proxyData, internalIsProxiesEnabled())) {
164
				result.add(proxyData);
194
				result.add(proxyData);
165
			}
195
			}
166
		}
196
		}
Lines 182-188 Link Here
182
	 */
212
	 */
183
	public boolean isProxiesEnabled() {
213
	public boolean isProxiesEnabled() {
184
		checkMigrated();
214
		checkMigrated();
185
		return Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false);
215
		return internalIsProxiesEnabled()
216
				&& (!isSystemProxiesEnabled() || (isSystemProxiesEnabled() && hasSystemProxies()));
217
	}
218
219
	private boolean internalIsProxiesEnabled() {
220
		return Activator.getInstance().getPreferences().getBoolean(
221
				PREF_ENABLED, false);
186
	}
222
	}
187
223
188
	/* (non-Javadoc)
224
	/* (non-Javadoc)
Lines 190-196 Link Here
190
	 */
226
	 */
191
	public void setProxiesEnabled(boolean enabled) {
227
	public void setProxiesEnabled(boolean enabled) {
192
		checkMigrated();
228
		checkMigrated();
193
		boolean current = isProxiesEnabled();
229
		boolean current = internalIsProxiesEnabled();
194
		if (current == enabled)
230
		if (current == enabled)
195
			return;
231
			return;
196
		// Setting the preference will trigger the system property update
232
		// Setting the preference will trigger the system property update
Lines 198-206 Link Here
198
		Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled);
234
		Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled);
199
	}
235
	}
200
236
201
	private void internalSetEnabled(boolean enabled) {
237
	private void internalSetEnabled(boolean enabled, boolean systemEnabled) {
202
		Properties sysProps = System.getProperties();
238
		Properties sysProps = System.getProperties();
203
		sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
239
		sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
240
		sysProps.put("systemProxySet", systemEnabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
204
		updateSystemProperties();
241
		updateSystemProperties();
205
		try {
242
		try {
206
			Activator.getInstance().getPreferences().flush();
243
			Activator.getInstance().getPreferences().flush();
Lines 217-223 Link Here
217
	private void updateSystemProperties() {
254
	private void updateSystemProperties() {
218
		for (int i = 0; i < proxies.length; i++) {
255
		for (int i = 0; i < proxies.length; i++) {
219
			ProxyType type = proxies[i];
256
			ProxyType type = proxies[i];
220
			type.updateSystemProperties(internalGetProxyData(type.getName(), ProxyType.DO_NOT_VERIFY), isProxiesEnabled());
257
			type.updateSystemProperties(internalGetProxyData(type.getName(), ProxyType.DO_NOT_VERIFY), internalIsProxiesEnabled());
221
		}
258
		}
222
	}
259
	}
223
260
Lines 227-233 Link Here
227
		// Now initialize each proxy type
264
		// Now initialize each proxy type
228
		for (int i = 0; i < proxies.length; i++) {
265
		for (int i = 0; i < proxies.length; i++) {
229
			ProxyType type = proxies[i];
266
			ProxyType type = proxies[i];
230
			type.initialize(isProxiesEnabled());
267
			type.initialize(internalIsProxiesEnabled());
231
		}
268
		}
232
		registerAuthenticator();
269
		registerAuthenticator();
233
	}
270
	}
Lines 249-254 Link Here
249
286
250
	public IProxyData[] getProxyDataForHost(String host) {
287
	public IProxyData[] getProxyDataForHost(String host) {
251
		checkMigrated();
288
		checkMigrated();
289
		if (hasSystemProxies() && isSystemProxiesEnabled())
290
			try {
291
				System.out.println(new URI(host));
292
				return nativeProxyProvider.select(new URI(host));
293
			} catch (URISyntaxException e) {
294
				return new IProxyData[0];
295
			}
296
		
252
		if (isHostFiltered(host))
297
		if (isHostFiltered(host))
253
			return new IProxyData[0];
298
			return new IProxyData[0];
254
		IProxyData[] data = getProxyData();
299
		IProxyData[] data = getProxyData();
Lines 281-286 Link Here
281
	 */
326
	 */
282
	public IProxyData getProxyDataForHost(String host, String type) {
327
	public IProxyData getProxyDataForHost(String host, String type) {
283
		checkMigrated();
328
		checkMigrated();
329
		if (hasSystemProxies() && isSystemProxiesEnabled())
330
			try {
331
				URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$
332
				System.out.println(uri);
333
				return nativeProxyProvider.select(uri)[0];
334
			} catch (URISyntaxException e) {
335
				return null;
336
			}
337
			
284
		IProxyData[] data = getProxyDataForHost(host);
338
		IProxyData[] data = getProxyDataForHost(host);
285
		for (int i = 0; i < data.length; i++) {
339
		for (int i = 0; i < data.length; i++) {
286
			IProxyData proxyData = data[i];
340
			IProxyData proxyData = data[i];
Lines 341-347 Link Here
341
			if (instanceEnabled != null)
395
			if (instanceEnabled != null)
342
				netConfigurationPrefs.put(PREF_ENABLED, instanceEnabled);
396
				netConfigurationPrefs.put(PREF_ENABLED, instanceEnabled);
343
		}
397
		}
344
				
398
		
399
		// migrate enabled status
400
		if (netConfigurationPrefs.get(PREF_OS, null) == null) {
401
			String instanceEnabled = netInstancePrefs.get(PREF_OS, null);
402
			if (instanceEnabled != null)
403
				netConfigurationPrefs.put(PREF_OS, instanceEnabled);
404
		}
405
	
345
		// migrate non proxied hosts if not already set
406
		// migrate non proxied hosts if not already set
346
		if (netConfigurationPrefs.get(PREF_NON_PROXIED_HOSTS, null) == null) {
407
		if (netConfigurationPrefs.get(PREF_NON_PROXIED_HOSTS, null) == null) {
347
			String instanceNonProxiedHosts = netInstancePrefs.get(PREF_NON_PROXIED_HOSTS, null);
408
			String instanceNonProxiedHosts = netInstancePrefs.get(PREF_NON_PROXIED_HOSTS, null);
Lines 434-443 Link Here
434
	}
495
	}
435
496
436
	public void preferenceChange(PreferenceChangeEvent event) {
497
	public void preferenceChange(PreferenceChangeEvent event) {
437
		if (event.getKey().equals(PREF_ENABLED)) {
498
		if (event.getKey().equals(PREF_ENABLED) || event.getKey().equals(PREF_OS)) {
438
			checkMigrated();
499
			checkMigrated();
439
			internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false));
500
			internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false),
501
					Activator.getInstance().getPreferences().getBoolean(PREF_OS, false));
440
		}
502
		}
441
	}
503
	}
442
504
505
	public boolean hasSystemProxies() {
506
		return nativeProxyProvider != null;
507
	}
508
509
	public boolean isSystemProxiesEnabled() {
510
		checkMigrated();
511
		return Activator.getInstance().getPreferences().getBoolean(PREF_OS,
512
				false);
513
	}
514
515
	public void setSystemProxiesEnabled(boolean enabled) {
516
		checkMigrated();
517
		boolean current = isSystemProxiesEnabled();
518
		if (current == enabled)
519
			return;
520
		// Setting the preference will trigger the system property update
521
		// (see preferenceChange)
522
		Activator.getInstance().getPreferences().putBoolean(PREF_OS, enabled);
523
	}
443
}
524
}
(-)src/org/eclipse/core/internal/net/ProxyData.java (+15 lines)
Lines 83-86 Link Here
83
		requiresAuthentication = false;
83
		requiresAuthentication = false;
84
	}
84
	}
85
85
86
	public String toString() {
87
		StringBuffer stringBuffer = new StringBuffer();
88
		stringBuffer.append("host: "); //$NON-NLS-1$
89
		stringBuffer.append(host);
90
		stringBuffer.append(" port: "); //$NON-NLS-1$
91
		stringBuffer.append(port);
92
		stringBuffer.append(" user: "); //$NON-NLS-1$
93
		stringBuffer.append(user);
94
		stringBuffer.append(" password: "); //$NON-NLS-1$
95
		stringBuffer.append(password);
96
		stringBuffer.append(" reqAuth: "); //$NON-NLS-1$
97
		stringBuffer.append(requiresAuthentication);
98
		return stringBuffer.toString(); 
99
	}
100
86
}
101
}
(-)src/org/eclipse/core/internal/net/AbstractProxyProvider.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Oakland Software Incorporated and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Oakland Software Incorporated - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.internal.net;
12
13
import java.net.URI;
14
15
import org.eclipse.core.net.proxy.IProxyData;
16
17
/**
18
 * Returns eligible proxies based on the hosts configuration.
19
 * 
20
 * Subclasses implement the native code required to get the proxy information.
21
 * 
22
 * This intentionally has semantics similar to the Java ProxySelector class. The
23
 * idea is that when we drop support for Java versions earlier than 1.5 we can
24
 * easily re-implement this using the native Java support and remove the native
25
 * code associated with this implementation.
26
 * 
27
 * This is not intended to be subclassed by clients. This is not intended to be
28
 * instantiated by clients.
29
 * 
30
 * @since 3.4
31
 * 
32
 */
33
public abstract class AbstractProxyProvider {
34
35
	/**
36
	 * Return the IProxyData(s) that can be used with the given URI.
37
	 * 
38
	 * This considers the native proxy settings on the host. It includes the
39
	 * consideration of hosts for which no proxying is desired.
40
	 * 
41
	 * @param uri
42
	 *            the URI to for with the proxy is generated
43
	 * @return an array of IProxyData which are the applicable proxies for the
44
	 *         specified URI
45
	 * 
46
	 * @since 3.4
47
	 */
48
	public IProxyData[] select(URI uri) {
49
		String[] nonProxyHosts = getNonProxiedHosts();
50
		String host = uri.getHost();
51
52
		if (nonProxyHosts != null) {
53
			for (int npIndex = 0; npIndex < nonProxyHosts.length; npIndex++) {
54
				if (host.equals(nonProxyHosts[npIndex])) {
55
					return new IProxyData[0];
56
				}
57
			}
58
		}
59
60
		return getProxyData(uri);
61
	}
62
63
	protected abstract IProxyData[] getProxyData(URI uri);
64
65
	protected String[] getNonProxiedHosts() {
66
		// Default implementation, subclasses may override
67
		return new String[] {};
68
	}
69
70
}
(-)natives/unix/Debug/sources.mk (+17 lines)
Added Link Here
1
################################################################################
2
# Automatically-generated file. Do not edit!
3
################################################################################
4
5
O_SRCS := 
6
C_SRCS := 
7
S_SRCS := 
8
OBJ_SRCS := 
9
ASM_SRCS := 
10
OBJS := 
11
C_DEPS := 
12
LIBRARIES := 
13
14
# Every subdirectory with source files must be described here
15
SUBDIRS := \
16
. \
17
(-)src/org/eclipse/core/internal/net/WindowsProxyProvider.java (+18 lines)
Added Link Here
1
package org.eclipse.core.internal.net;
2
3
import java.net.URI;
4
5
import org.eclipse.core.net.proxy.IProxyData;
6
7
public class WindowsProxyProvider extends AbstractProxyProvider {
8
	
9
	public WindowsProxyProvider(){
10
		Activator.logInfo("winProxyProvider initialized", null); //$NON-NLS-1$
11
	}
12
13
	protected IProxyData[] getProxyData(URI uri) {
14
		// TODO Auto-generated method stub
15
		return null;
16
	}
17
18
}
(-)natives/unix/README.txt (+12 lines)
Added Link Here
1
The source for getting the native proxy info is in the top level unix directory.  If
2
there are more specific compile options, makefiles, etc, then they should be moved
3
to subdirectories, like in org.eclipse.core.filesystem.
4
5
The Debug directory actually has the make file; this is the makefile as generated by the CDT.
6
7
To build this, go into Debug and type "make", the library will be built in that same
8
directory.  Then you will need to copy the library to the correct org.eclipse.core.net.*
9
fragment.
10
11
There is no automatic build process for building the native code, instead the binary
12
shared libraries are checked in for each fragment, just like in org.eclipse.code.filesystem.
(-)natives/unix/Debug/objects.mk (+7 lines)
Added Link Here
1
################################################################################
2
# Automatically-generated file. Do not edit!
3
################################################################################
4
5
USER_OBJS :=
6
7
LIBS := -lgconf-2 -lORBit-2 -lgthread-2.0 -lrt -lgobject-2.0 -lglib-2.0
(-)natives/unix/getsystemproxy.c (+237 lines)
Added Link Here
1
/*
2
 * Copyright 2008 Oakland Software Incorporated and others
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Oakland Software Incorporated - initial API and implementation
10
 */
11
12
#include <jni.h>
13
14
#include <glib.h>
15
#include <glib/gslist.h>
16
#include <gconf/gconf-value.h>
17
#include <gconf/gconf-client.h>
18
19
#ifdef __linux__
20
#include <string.h>
21
#else
22
#include <strings.h>
23
#endif
24
25
static GConfClient *client= NULL;
26
27
static jclass proxyInfoClass;
28
static jclass stringClass;
29
static jmethodID proxyInfoConstructor;
30
static jmethodID toString;
31
32
static jmethodID hostMethod;
33
static jmethodID portMethod;
34
static jmethodID requiresAuthenticationMethod;
35
static jmethodID userMethod;
36
static jmethodID passwordMethod;
37
38
#define CHECK_NULL(X) { if ((X) == NULL) fprintf (stderr,"JNI error at line %d\n", __LINE__); } 
39
40
static void gconfInit(JNIEnv *env) {
41
	client = gconf_client_get_default();
42
	jclass cls= NULL;
43
	CHECK_NULL(cls = (*env)->FindClass(env, "org/eclipse/core/internal/net/ProxyData"));
44
	proxyInfoClass = (*env)->NewGlobalRef(env, cls);
45
46
	CHECK_NULL(cls = (*env)->FindClass(env, "java/lang/String"));
47
	stringClass = (*env)->NewGlobalRef(env, cls);
48
49
	CHECK_NULL(proxyInfoConstructor = (*env)->GetMethodID(env, proxyInfoClass, "<init>", "(Ljava/lang/String;)V"));
50
51
	CHECK_NULL(toString = (*env)->GetMethodID(env, proxyInfoClass, "toString", "()Ljava/lang/String;"));
52
53
	CHECK_NULL(hostMethod = (*env)->GetMethodID(env, proxyInfoClass, "setHost",
54
					"(Ljava/lang/String;)V"));
55
	CHECK_NULL(portMethod = (*env)->GetMethodID(env, proxyInfoClass, "setPort",
56
					"(I)V"));
57
	CHECK_NULL(requiresAuthenticationMethod= (*env)->GetMethodID(env, proxyInfoClass, "setRequiresAuthentication",
58
					"(Z)V"));
59
	CHECK_NULL(userMethod = (*env)->GetMethodID(env, proxyInfoClass, "setUserid",
60
					"(Ljava/lang/String;)V"));
61
	CHECK_NULL(passwordMethod = (*env)->GetMethodID(env, proxyInfoClass, "setPassword",
62
					"(Ljava/lang/String;)V"));
63
}
64
65
/*
66
 * Class:     org_eclipse_core_internal_net_UnixProxyProvider
67
 * Method:    getGConfProxyInfo
68
 * Signature: ([Ljava/lang/String);
69
 */
70
JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getGConfProxyInfo(
71
		JNIEnv *env, jclass clazz, jstring protocol) {
72
73
	jboolean isCopy;
74
	const char *cprotocol;
75
76
	jobject proxyInfo= NULL;
77
78
	if (client == NULL) {
79
		gconfInit(env);
80
	}
81
82
	CHECK_NULL(proxyInfo = (*env)->NewObject(env, proxyInfoClass, proxyInfoConstructor, protocol));
83
84
	cprotocol = (*env)->GetStringUTFChars(env, protocol, &isCopy);
85
	if (cprotocol == NULL)
86
		return NULL;
87
88
	//printf("cprotocol: %s\n", cprotocol);
89
90
	if (strcasecmp(cprotocol, "http") == 0) {
91
		gboolean useProxy = gconf_client_get_bool(client,
92
				"/system/http_proxy/use_http_proxy", NULL);
93
		if (!useProxy) {
94
			proxyInfo = NULL;
95
			goto exit;
96
		}
97
98
		gchar *host = gconf_client_get_string(client,
99
				"/system/http_proxy/host", NULL);
100
		jobject jhost = (*env)->NewStringUTF(env, host);
101
		(*env)->CallVoidMethod(env, proxyInfo, hostMethod, jhost);
102
103
		gint port = gconf_client_get_int(client, "/system/http_proxy/port",
104
				NULL);
105
		(*env)->CallVoidMethod(env, proxyInfo, portMethod, port);
106
107
		gboolean reqAuth = gconf_client_get_bool(client,
108
				"/system/http_proxy/use_authentication", NULL);
109
		(*env)->CallVoidMethod(env, proxyInfo,
110
				requiresAuthenticationMethod, reqAuth);
111
		if (reqAuth) {
112
113
			gchar *user = gconf_client_get_string(client,
114
					"/system/http_proxy/authentication_user", NULL);
115
			jobject juser = (*env)->NewStringUTF(env, user);
116
			(*env)->CallVoidMethod(env, proxyInfo, userMethod, juser);
117
118
			gchar *password = gconf_client_get_string(client,
119
					"/system/http_proxy/authentication_password", NULL);
120
			jobject jpassword = (*env)->NewStringUTF(env, password);
121
			(*env)->CallVoidMethod(env, proxyInfo, passwordMethod,
122
					jpassword);
123
		}
124
		goto exit;
125
	}
126
127
	// Everything else applies only if the system proxy mode is manual
128
	gchar *mode = gconf_client_get_string(client, "/system/proxy/mode", NULL);
129
	if (strcasecmp(mode, "manual") != 0) {
130
		proxyInfo = NULL;
131
		goto exit;
132
	}
133
134
	char selector[100];
135
136
	if (strcasecmp(cprotocol, "https") == 0) {
137
		strcpy(selector, "/system/proxy/secure_");
138
	} else if (strcasecmp(cprotocol, "socks") == 0) {
139
		strcpy(selector, "/system/proxy/socks_");
140
	} else if (strcasecmp(cprotocol, "ftp") == 0) {
141
		strcpy(selector, "/system/proxy/ftp_");
142
	} else {
143
		proxyInfo = NULL;
144
		goto exit;
145
	}
146
147
	char useSelector[100];
148
	strcpy(useSelector, selector);
149
150
	gchar *host = gconf_client_get_string(client, strcat(useSelector, "host"),
151
			NULL);
152
	jobject jhost = (*env)->NewStringUTF(env, host);
153
	(*env)->CallVoidMethod(env, proxyInfo, hostMethod, jhost);
154
155
	strcpy(useSelector, selector);
156
	gint port = gconf_client_get_int(client, strcat(useSelector, "port"), NULL);
157
	(*env)->CallVoidMethod(env, proxyInfo, portMethod, port);
158
159
	exit: if (isCopy == JNI_TRUE)
160
		(*env)->ReleaseStringUTFChars(env, protocol, cprotocol);
161
	return proxyInfo;
162
}
163
164
typedef struct {
165
	jobjectArray npHostArray;
166
	JNIEnv *env;
167
	int index;
168
} ListProcContext;
169
170
// user_data is the ListProcContext
171
void listProc(gpointer data, gpointer user_data) {
172
	ListProcContext *lpc = user_data;
173
	jobject jnpHost = (*lpc->env)->NewStringUTF(lpc->env, (char *)data);
174
	(*lpc->env)->SetObjectArrayElement(lpc->env, lpc->npHostArray,
175
			lpc->index++, jnpHost);
176
}
177
178
/*
179
 * Class:     org_eclipse_core_internal_net_UnixProxyProvider
180
 * Method:    getGConfNonProxyHosts
181
 * Signature: ()[Ljava/lang/String;
182
 */
183
JNIEXPORT jobjectArray JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getGConfNonProxyHosts(
184
		JNIEnv *env, jclass clazz) {
185
186
	if (client == NULL) {
187
		gconfInit(env);
188
	}
189
190
	GSList *npHosts;
191
	int size;
192
193
	npHosts = gconf_client_get_list(client, "/system/http_proxy/ignore_hosts",
194
			GCONF_VALUE_STRING, NULL);
195
	size = g_slist_length(npHosts);
196
197
	// TODO - I'm not sure this is really valid, it's from the JVM implementation
198
	// of ProxySelector
199
	if (size == 0) {
200
		npHosts = gconf_client_get_list(client, "/system/proxy/no_proxy_for",
201
				GCONF_VALUE_STRING, NULL);
202
	}
203
	size = g_slist_length(npHosts);
204
205
	jobjectArray ret = (*env)->NewObjectArray(env, size, stringClass, NULL);
206
207
	ListProcContext lpc;
208
	lpc.env = env;
209
	lpc.npHostArray = ret;
210
	lpc.index = 0;
211
212
	g_slist_foreach(npHosts, listProc, &lpc);
213
	return ret;
214
}
215
216
/*
217
 * Class:     org_eclipse_core_internal_net_UnixProxyProvider
218
 * Method:    getKdeProxyInfo
219
 * Signature: ([Ljava/lang/String);
220
 */
221
JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getKdeProxyInfo(
222
		JNIEnv *env, jclass clazz, jstring protocol) {
223
	//printf("getKdeProxyInfo - not implemented\n");
224
	return NULL;
225
}
226
227
/*
228
 * Class:     org_eclipse_core_internal_net_UnixProxyProvider
229
 * Method:    getKdeNonProxyHosts
230
 * Signature: ()Ljava/lang/String;
231
 */
232
JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getKdeNonProxyHosts(
233
		JNIEnv *env, jclass clazz) {
234
	//printf("getKdeNonProxyHosts - not implemented\n");
235
	return NULL;
236
}
237
(-)src/org/eclipse/core/internal/net/UnixProxyProvider.java (+80 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
		System.loadLibrary("proxysupport"); //$NON-NLS-1$
12
	}
13
14
	public UnixProxyProvider() {
15
			Activator.logInfo("linuxProxyProvider initialized", null); //$NON-NLS-1$
16
	}
17
18
	public IProxyData[] getProxyData(URI uri) {
19
		String protocol = uri.getScheme();
20
21
		ProxyData pd = getSystemProxyInfo(protocol);
22
23
		if (pd != null) {
24
			IProxyData[] pds = new IProxyData[1];
25
			pds[0] = pd;
26
			return pds;
27
		}
28
29
		return new IProxyData[0];
30
	}
31
32
	protected String[] getNonProxiedHosts() {
33
		String[] npHosts = getGConfNonProxyHosts();
34
		if (npHosts != null && npHosts.length > 0)
35
			return npHosts;
36
		return getKdeNonProxyHosts();
37
	}
38
39
	// Returns null if something wrong or there is no proxy for the protocol
40
	protected ProxyData getSystemProxyInfo(String protocol) {
41
		ProxyData pd;
42
43
		// First try the environment variable which is a URL
44
		String sysHttp = System.getenv(protocol.toLowerCase() + "_proxy"); //$NON-NLS-1$
45
		if (sysHttp != null) {
46
			URI uri = null;
47
			try {
48
				uri = new URI(sysHttp);
49
			} catch (URISyntaxException e) {
50
				return null;
51
			}
52
			
53
			pd = new ProxyData(protocol);
54
			pd.setHost(uri.getHost());
55
			pd.setPort(uri.getPort());
56
			return pd;
57
		}
58
59
		// Then ask Gnome
60
		pd = getGConfProxyInfo(protocol);
61
		if (pd != null)
62
			return pd;
63
64
		// Then ask KDE
65
		pd = getKdeProxyInfo(protocol);
66
		if (pd != null)
67
			return pd;
68
69
		return null;
70
	}
71
72
	protected static native ProxyData getGConfProxyInfo(String protocol);
73
74
	protected static native String[] getGConfNonProxyHosts();
75
76
	protected static native ProxyData getKdeProxyInfo(String protocol);
77
78
	protected static native String[] getKdeNonProxyHosts();
79
80
}
(-)natives/unix/Debug/subdir.mk (+24 lines)
Added Link Here
1
################################################################################
2
# Automatically-generated file. Do not edit!
3
################################################################################
4
5
# Add inputs and outputs from these tool invocations to the build variables 
6
C_SRCS += \
7
../getsystemproxy.c 
8
9
OBJS += \
10
./getsystemproxy.o 
11
12
C_DEPS += \
13
./getsystemproxy.d 
14
15
16
# Each subdirectory must supply rules for building sources it contributes
17
%.o: ../%.c
18
	@echo 'Building file: $<'
19
	@echo 'Invoking: GCC C Compiler'
20
	gcc -I/usr/include/gconf/2 -I/usr/include/orbit-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include/ -O0 -fPIC -g3 -Wall -c -fmessage-length=0 -m32 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
21
	@echo 'Finished building: $<'
22
	@echo ' '
23
24
(-)natives/unix/Debug/makefile (+43 lines)
Added Link Here
1
################################################################################
2
# Automatically-generated file. Do not edit!
3
################################################################################
4
5
-include ../makefile.init
6
7
RM := rm -rf
8
9
# All of the sources participating in the build are defined here
10
-include sources.mk
11
-include subdir.mk
12
-include objects.mk
13
14
ifneq ($(MAKECMDGOALS),clean)
15
ifneq ($(strip $(C_DEPS)),)
16
-include $(C_DEPS)
17
endif
18
endif
19
20
-include ../makefile.defs
21
22
# Add inputs and outputs from these tool invocations to the build variables 
23
24
# All Target
25
all: libproxysupport.so
26
27
# Tool invocations
28
libproxysupport.so: $(OBJS) $(USER_OBJS)
29
	@echo 'Building target: $@'
30
	@echo 'Invoking: GCC C Linker'
31
	gcc -m32 -shared -o"libproxysupport.so" $(OBJS) $(USER_OBJS) $(LIBS)
32
	@echo 'Finished building target: $@'
33
	@echo ' '
34
35
# Other Targets
36
clean:
37
	-$(RM) $(OBJS)$(C_DEPS)$(LIBRARIES) libproxysupport.so
38
	-@echo ' '
39
40
.PHONY: all clean dependents
41
.SECONDARY:
42
43
-include ../makefile.targets
(-)src/org/eclipse/ui/internal/net/messages.properties (+2 lines)
Lines 44-49 Link Here
44
ProxyPreferencePage_41=The host name cannot begin or end with a space character
44
ProxyPreferencePage_41=The host name cannot begin or end with a space character
45
ProxyPreferencePage_42=Invalid port
45
ProxyPreferencePage_42=Invalid port
46
ProxyPreferencePage_43=The port must be an integer
46
ProxyPreferencePage_43=The port must be an integer
47
ProxyPreferencePage_44=System proxy
48
ProxyPreferencePage_45=Specifies that a system proxy is used to access the Internet.
47
UserValidationDialog_0=Password Required
49
UserValidationDialog_0=Password Required
48
UserValidationDialog_1=Connect to: {0}
50
UserValidationDialog_1=Connect to: {0}
49
UserValidationDialog_2=&Password:
51
UserValidationDialog_2=&Password:
(-)src/org/eclipse/ui/internal/net/ProxyPreferencePage.java (-10 / +31 lines)
Lines 57-62 Link Here
57
	Text userid;
57
	Text userid;
58
	Text password;
58
	Text password;
59
	private IProxyService proxyService;
59
	private IProxyService proxyService;
60
	Button systemProxyConfigurationButton;
60
61
61
	public ProxyPreferencePage() {
62
	public ProxyPreferencePage() {
62
		super(NetUIMessages.ProxyPreferencePage_2);
63
		super(NetUIMessages.ProxyPreferencePage_2);
Lines 103-108 Link Here
103
				enableControls(!directConnectionToButton.getSelection());
104
				enableControls(!directConnectionToButton.getSelection());
104
			}
105
			}
105
		});
106
		});
107
		
108
		systemProxyConfigurationButton = new Button(composite, SWT.RADIO);
109
		systemProxyConfigurationButton.setLayoutData(new GridData());
110
		systemProxyConfigurationButton.setText(NetUIMessages.ProxyPreferencePage_44);
111
		systemProxyConfigurationButton
112
				.setToolTipText(NetUIMessages.ProxyPreferencePage_45);
113
		systemProxyConfigurationButton.addSelectionListener(new SelectionAdapter() {
114
			public void widgetSelected(SelectionEvent e) {
115
				enableControls(!systemProxyConfigurationButton.getSelection());
116
			}
117
		});
106
118
107
		manualProxyConfigurationButton = new Button(composite, SWT.RADIO);
119
		manualProxyConfigurationButton = new Button(composite, SWT.RADIO);
108
		manualProxyConfigurationButton
120
		manualProxyConfigurationButton
Lines 201-207 Link Here
201
		entryList[0].hostname.addModifyListener(modifyListener);
213
		entryList[0].hostname.addModifyListener(modifyListener);
202
		entryList[0].port.addModifyListener(modifyListener);
214
		entryList[0].port.addModifyListener(modifyListener);
203
215
204
		initializeValues(proxyService.isProxiesEnabled());
216
		initializeValues(proxyService.isProxiesEnabled() , proxyService.isSystemProxiesEnabled());
217
		systemProxyConfigurationButton.setEnabled(proxyService.hasSystemProxies());
218
		
205
		applyDialogFont(composite);
219
		applyDialogFont(composite);
206
		
220
		
207
		// F1
221
		// F1
Lines 214-220 Link Here
214
	protected void performApply() {
228
	protected void performApply() {
215
		if (proxyService == null)
229
		if (proxyService == null)
216
			return;
230
			return;
217
		boolean proxiesEnabled = manualProxyConfigurationButton.getSelection();
231
		boolean manualProxiesEnabled = manualProxyConfigurationButton.getSelection();
232
		boolean systemProxiesEnabled = systemProxyConfigurationButton.getSelection();
218
233
219
		// Save the contents of the text fields to the proxy data.
234
		// Save the contents of the text fields to the proxy data.
220
		IProxyData[] proxyData = new IProxyData[entryList.length];
235
		IProxyData[] proxyData = new IProxyData[entryList.length];
Lines 223-230 Link Here
223
			proxyData[index] = entryList[index].getProxy();
238
			proxyData[index] = entryList[index].getProxy();
224
		}
239
		}
225
240
226
		proxyService.setProxiesEnabled(proxiesEnabled);
241
		proxyService.setProxiesEnabled(manualProxiesEnabled || systemProxiesEnabled);
227
		if (proxiesEnabled) {
242
		
243
		if (manualProxiesEnabled) {
228
			try {
244
			try {
229
				proxyService.setNonProxiedHosts(
245
				proxyService.setNonProxiedHosts(
230
						nonHostComposite.getList());
246
						nonHostComposite.getList());
Lines 233-243 Link Here
233
				ErrorDialog.openError(getShell(), null, null, e.getStatus());
249
				ErrorDialog.openError(getShell(), null, null, e.getStatus());
234
			}
250
			}
235
		}
251
		}
252
		
253
		proxyService.setSystemProxiesEnabled(systemProxiesEnabled);
254
236
		Activator.getDefault().savePluginPreferences();
255
		Activator.getDefault().savePluginPreferences();
237
	}
256
	}
238
257
239
	protected void performDefaults() {
258
	protected void performDefaults() {
240
		directConnectionToButton.setSelection(true);
259
		directConnectionToButton.setSelection(true);
260
		systemProxyConfigurationButton.setSelection(false);
241
		manualProxyConfigurationButton.setSelection(false);
261
		manualProxyConfigurationButton.setSelection(false);
242
		useSameProxyButton.setSelection(false);
262
		useSameProxyButton.setSelection(false);
243
		enableProxyAuth.setSelection(false);
263
		enableProxyAuth.setSelection(false);
Lines 263-279 Link Here
263
	 * 
283
	 * 
264
	 * @param proxiesEnabled indicates if manual proxies are enabled or not.
284
	 * @param proxiesEnabled indicates if manual proxies are enabled or not.
265
	 */
285
	 */
266
	private void initializeValues(boolean proxiesEnabled) {
286
	private void initializeValues(boolean proxiesEnabled, boolean systemProxiesEnabled) {
267
268
		directConnectionToButton.setSelection(!proxiesEnabled);
287
		directConnectionToButton.setSelection(!proxiesEnabled);
269
		manualProxyConfigurationButton.setSelection(proxiesEnabled);
288
		manualProxyConfigurationButton.setSelection(proxiesEnabled && !systemProxiesEnabled);
289
		systemProxyConfigurationButton.setSelection(proxiesEnabled && systemProxiesEnabled);
290
		
270
291
271
		String[] nonHostLists = null;
292
		String[] nonHostLists = null;
272
		if (proxyService != null)
293
		if (proxyService != null)
273
			nonHostLists = proxyService.getNonProxiedHosts();
294
			nonHostLists = proxyService.getNonProxiedHosts();
274
		this.nonHostComposite.setList(nonHostLists == null ? new String[] {
295
		this.nonHostComposite.setList(nonHostLists == null ? new String[] {
275
				"localhost", "127.0.0.1" } : nonHostLists); //$NON-NLS-1$ //$NON-NLS-2$
296
				"localhost", "127.0.0.1" } : nonHostLists); //$NON-NLS-1$ //$NON-NLS-2$
276
		if (!proxiesEnabled) {
297
		if (proxiesEnabled && !systemProxiesEnabled) {
277
			this.useSameProxyButton.setSelection(false);
298
			this.useSameProxyButton.setSelection(false);
278
			this.enableProxyAuth.setSelection(false);
299
			this.enableProxyAuth.setSelection(false);
279
			this.userid.setText(""); //$NON-NLS-1$
300
			this.userid.setText(""); //$NON-NLS-1$
Lines 311-320 Link Here
311
		for (int index = 1; index < entryList.length; index++) {
332
		for (int index = 1; index < entryList.length; index++) {
312
			Entry entry = entryList[index];
333
			Entry entry = entryList[index];
313
			entry.loadPreviousValues();
334
			entry.loadPreviousValues();
314
			entry.updateEnablement(proxiesEnabled, useSameProtocol);
335
			entry.updateEnablement(proxiesEnabled && !systemProxiesEnabled, useSameProtocol);
315
		}
336
		}
316
337
317
		enableControls(proxiesEnabled);
338
		enableControls(proxiesEnabled && !systemProxiesEnabled);
318
	}
339
	}
319
340
320
	void enableControls(boolean enabled) {
341
	void enableControls(boolean enabled) {
(-)src/org/eclipse/ui/internal/net/NetUIMessages.java (+4 lines)
Lines 76-81 Link Here
76
	public static String ProxyPreferencePage_8;
76
	public static String ProxyPreferencePage_8;
77
77
78
	public static String ProxyPreferencePage_9;
78
	public static String ProxyPreferencePage_9;
79
	
80
	public static String ProxyPreferencePage_44;
81
	
82
	public static String ProxyPreferencePage_45;
79
83
80
	public static String TITLE_PREFERENCE_HOSTS_DIALOG;
84
	public static String TITLE_PREFERENCE_HOSTS_DIALOG;
81
85

Return to bug 180921