### Eclipse Workspace Patch 1.0 #P org.eclipse.core.net Index: src/org/eclipse/core/internal/net/ProxyManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java,v retrieving revision 1.10 diff -u -r1.10 ProxyManager.java --- src/org/eclipse/core/internal/net/ProxyManager.java 19 Feb 2008 21:06:25 -0000 1.10 +++ src/org/eclipse/core/internal/net/ProxyManager.java 10 Mar 2008 12:13:19 -0000 @@ -39,6 +39,8 @@ private static IProxyService proxyManager; + private AbstractProxyProvider nativeProxyProvider; + ListenerList listeners = new ListenerList(ListenerList.IDENTITY); private String[] nonProxiedHosts; private final ProxyType[] proxies = new ProxyType[] { @@ -48,6 +50,17 @@ }; private boolean migrated = false; + + private ProxyManager() + { + try { + nativeProxyProvider = (AbstractProxyProvider)Class.forName("org.eclipse.core.net.ProxyProvider").newInstance(); //$NON-NLS-1$ + } catch (ClassNotFoundException e) { + // no class found + } catch (Exception e) { + Activator.logInfo("noNativeProxyProvider", e); //$NON-NLS-1$ + } + } /** * Return the proxy manager. Index: src/org/eclipse/core/internal/net/ProxyData.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyData.java,v retrieving revision 1.2 diff -u -r1.2 ProxyData.java --- src/org/eclipse/core/internal/net/ProxyData.java 9 Apr 2007 19:21:02 -0000 1.2 +++ src/org/eclipse/core/internal/net/ProxyData.java 10 Mar 2008 12:13:18 -0000 @@ -21,7 +21,8 @@ private String password; private boolean requiresAuthentication; - public ProxyData(String type, String host, int port, boolean requiresAuthentication) { + public ProxyData(String type, String host, int port, + boolean requiresAuthentication) { this.type = type; this.host = host; this.port = port; @@ -83,4 +84,19 @@ requiresAuthentication = false; } + public String toString() { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("host: "); //$NON-NLS-1$ + stringBuffer.append(host); + stringBuffer.append(" port: "); //$NON-NLS-1$ + stringBuffer.append(port); + stringBuffer.append(" user: "); //$NON-NLS-1$ + stringBuffer.append(user); + stringBuffer.append(" password: "); //$NON-NLS-1$ + stringBuffer.append(password); + stringBuffer.append(" reqAuth: "); //$NON-NLS-1$ + stringBuffer.append(requiresAuthentication); + return stringBuffer.toString(); + } + } Index: src/org/eclipse/core/internal/net/AbstractProxyProvider.java =================================================================== RCS file: src/org/eclipse/core/internal/net/AbstractProxyProvider.java diff -N src/org/eclipse/core/internal/net/AbstractProxyProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/core/internal/net/AbstractProxyProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2008 Oakland Software Incorporated and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oakland Software Incorporated - initial API and implementation + *******************************************************************************/ +package org.eclipse.core.internal.net; + +import java.net.URI; + +import org.eclipse.core.net.proxy.IProxyData; + +/** + * Returns eligible proxies based on the hosts configuration. + * + * Subclasses implement the native code required to get the proxy information. + * + * This intentionally has semantics similar to the Java ProxySelector class. The + * idea is that when we drop support for Java versions earlier than 1.5 we can + * easily re-implement this using the native Java support and remove the native + * code associated with this implementation. + * + * This is not intended to be subclassed by clients. This is not intended to be + * instantiated by clients. + * + * @since 3.4 + * + */ +public abstract class AbstractProxyProvider { + + /** + * Return the IProxyData(s) that can be used with the given URI. + * + * This considers the native proxy settings on the host. It includes the + * consideration of hosts for which no proxying is desired. + * + * @param uri + * the URI to for with the proxy is generated + * @return an array of IProxyData which are the applicable proxies for the + * specified URI + * + * @since 3.4 + */ + public IProxyData[] select(URI uri) { + String[] nonProxyHosts = getNonProxiedHosts(); + String host = uri.getHost(); + + if (nonProxyHosts != null) { + for (int npIndex = 0; npIndex < nonProxyHosts.length; npIndex++) { + if (host.equals(nonProxyHosts[npIndex])) { + return new IProxyData[0]; + } + } + } + + return getProxyData(uri); + } + + protected abstract IProxyData[] getProxyData(URI uri); + + protected String[] getNonProxiedHosts() { + // Default implementation, subclasses may override + return new String[] {}; + } + +} Index: natives/unix/Debug/sources.mk =================================================================== RCS file: natives/unix/Debug/sources.mk diff -N natives/unix/Debug/sources.mk --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ natives/unix/Debug/sources.mk 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,17 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +O_SRCS := +C_SRCS := +S_SRCS := +OBJ_SRCS := +ASM_SRCS := +OBJS := +C_DEPS := +LIBRARIES := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +. \ + Index: src/org/eclipse/core/internal/net/WindowsProxyProvider.java =================================================================== RCS file: src/org/eclipse/core/internal/net/WindowsProxyProvider.java diff -N src/org/eclipse/core/internal/net/WindowsProxyProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/core/internal/net/WindowsProxyProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,18 @@ +package org.eclipse.core.internal.net; + +import java.net.URI; + +import org.eclipse.core.net.proxy.IProxyData; + +public class WindowsProxyProvider extends AbstractProxyProvider { + + public WindowsProxyProvider(){ + Activator.logInfo("winProxyProvider initialized", null); //$NON-NLS-1$ + } + + protected IProxyData[] getProxyData(URI uri) { + // TODO Auto-generated method stub + return null; + } + +} Index: natives/unix/README.txt =================================================================== RCS file: natives/unix/README.txt diff -N natives/unix/README.txt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ natives/unix/README.txt 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,12 @@ +The source for getting the native proxy info is in the top level unix directory. If +there are more specific compile options, makefiles, etc, then they should be moved +to subdirectories, like in org.eclipse.core.filesystem. + +The Debug directory actually has the make file; this is the makefile as generated by the CDT. + +To build this, go into Debug and type "make", the library will be built in that same +directory. Then you will need to copy the library to the correct org.eclipse.core.net.* +fragment. + +There is no automatic build process for building the native code, instead the binary +shared libraries are checked in for each fragment, just like in org.eclipse.code.filesystem. Index: natives/unix/Debug/objects.mk =================================================================== RCS file: natives/unix/Debug/objects.mk diff -N natives/unix/Debug/objects.mk --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ natives/unix/Debug/objects.mk 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,7 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +USER_OBJS := + +LIBS := -lgconf-2 -lORBit-2 -lgthread-2.0 -lrt -lgobject-2.0 -lglib-2.0 Index: natives/unix/getsystemproxy.c =================================================================== RCS file: natives/unix/getsystemproxy.c diff -N natives/unix/getsystemproxy.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ natives/unix/getsystemproxy.c 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,237 @@ +/* + * Copyright 2008 Oakland Software Incorporated and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oakland Software Incorporated - initial API and implementation + */ + +#include + +#include +#include +#include +#include + +#ifdef __linux__ +#include +#else +#include +#endif + +static GConfClient *client= NULL; + +static jclass proxyInfoClass; +static jclass stringClass; +static jmethodID proxyInfoConstructor; +static jmethodID toString; + +static jmethodID hostMethod; +static jmethodID portMethod; +static jmethodID requiresAuthenticationMethod; +static jmethodID userMethod; +static jmethodID passwordMethod; + +#define CHECK_NULL(X) { if ((X) == NULL) fprintf (stderr,"JNI error at line %d\n", __LINE__); } + +static void gconfInit(JNIEnv *env) { + client = gconf_client_get_default(); + jclass cls= NULL; + CHECK_NULL(cls = (*env)->FindClass(env, "org/eclipse/core/internal/net/ProxyData")); + proxyInfoClass = (*env)->NewGlobalRef(env, cls); + + CHECK_NULL(cls = (*env)->FindClass(env, "java/lang/String")); + stringClass = (*env)->NewGlobalRef(env, cls); + + CHECK_NULL(proxyInfoConstructor = (*env)->GetMethodID(env, proxyInfoClass, "", "(Ljava/lang/String;)V")); + + CHECK_NULL(toString = (*env)->GetMethodID(env, proxyInfoClass, "toString", "()Ljava/lang/String;")); + + CHECK_NULL(hostMethod = (*env)->GetMethodID(env, proxyInfoClass, "setHost", + "(Ljava/lang/String;)V")); + CHECK_NULL(portMethod = (*env)->GetMethodID(env, proxyInfoClass, "setPort", + "(I)V")); + CHECK_NULL(requiresAuthenticationMethod= (*env)->GetMethodID(env, proxyInfoClass, "setRequiresAuthentication", + "(Z)V")); + CHECK_NULL(userMethod = (*env)->GetMethodID(env, proxyInfoClass, "setUserid", + "(Ljava/lang/String;)V")); + CHECK_NULL(passwordMethod = (*env)->GetMethodID(env, proxyInfoClass, "setPassword", + "(Ljava/lang/String;)V")); +} + +/* + * Class: org_eclipse_core_internal_net_UnixProxyProvider + * Method: getGConfProxyInfo + * Signature: ([Ljava/lang/String); + */ +JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getGConfProxyInfo( + JNIEnv *env, jclass clazz, jstring protocol) { + + jboolean isCopy; + const char *cprotocol; + + jobject proxyInfo= NULL; + + if (client == NULL) { + gconfInit(env); + } + + CHECK_NULL(proxyInfo = (*env)->NewObject(env, proxyInfoClass, proxyInfoConstructor, protocol)); + + cprotocol = (*env)->GetStringUTFChars(env, protocol, &isCopy); + if (cprotocol == NULL) + return NULL; + + //printf("cprotocol: %s\n", cprotocol); + + if (strcasecmp(cprotocol, "http") == 0) { + gboolean useProxy = gconf_client_get_bool(client, + "/system/http_proxy/use_http_proxy", NULL); + if (!useProxy) { + proxyInfo = NULL; + goto exit; + } + + gchar *host = gconf_client_get_string(client, + "/system/http_proxy/host", NULL); + jobject jhost = (*env)->NewStringUTF(env, host); + (*env)->CallVoidMethod(env, proxyInfo, hostMethod, jhost); + + gint port = gconf_client_get_int(client, "/system/http_proxy/port", + NULL); + (*env)->CallVoidMethod(env, proxyInfo, portMethod, port); + + gboolean reqAuth = gconf_client_get_bool(client, + "/system/http_proxy/use_authentication", NULL); + (*env)->CallVoidMethod(env, proxyInfo, + requiresAuthenticationMethod, reqAuth); + if (reqAuth) { + + gchar *user = gconf_client_get_string(client, + "/system/http_proxy/authentication_user", NULL); + jobject juser = (*env)->NewStringUTF(env, user); + (*env)->CallVoidMethod(env, proxyInfo, userMethod, juser); + + gchar *password = gconf_client_get_string(client, + "/system/http_proxy/authentication_password", NULL); + jobject jpassword = (*env)->NewStringUTF(env, password); + (*env)->CallVoidMethod(env, proxyInfo, passwordMethod, + jpassword); + } + goto exit; + } + + // Everything else applies only if the system proxy mode is manual + gchar *mode = gconf_client_get_string(client, "/system/proxy/mode", NULL); + if (strcasecmp(mode, "manual") != 0) { + proxyInfo = NULL; + goto exit; + } + + char selector[100]; + + if (strcasecmp(cprotocol, "https") == 0) { + strcpy(selector, "/system/proxy/secure_"); + } else if (strcasecmp(cprotocol, "socks") == 0) { + strcpy(selector, "/system/proxy/socks_"); + } else if (strcasecmp(cprotocol, "ftp") == 0) { + strcpy(selector, "/system/proxy/ftp_"); + } else { + proxyInfo = NULL; + goto exit; + } + + char useSelector[100]; + strcpy(useSelector, selector); + + gchar *host = gconf_client_get_string(client, strcat(useSelector, "host"), + NULL); + jobject jhost = (*env)->NewStringUTF(env, host); + (*env)->CallVoidMethod(env, proxyInfo, hostMethod, jhost); + + strcpy(useSelector, selector); + gint port = gconf_client_get_int(client, strcat(useSelector, "port"), NULL); + (*env)->CallVoidMethod(env, proxyInfo, portMethod, port); + + exit: if (isCopy == JNI_TRUE) + (*env)->ReleaseStringUTFChars(env, protocol, cprotocol); + return proxyInfo; +} + +typedef struct { + jobjectArray npHostArray; + JNIEnv *env; + int index; +} ListProcContext; + +// user_data is the ListProcContext +void listProc(gpointer data, gpointer user_data) { + ListProcContext *lpc = user_data; + jobject jnpHost = (*lpc->env)->NewStringUTF(lpc->env, (char *)data); + (*lpc->env)->SetObjectArrayElement(lpc->env, lpc->npHostArray, + lpc->index++, jnpHost); +} + +/* + * Class: org_eclipse_core_internal_net_UnixProxyProvider + * Method: getGConfNonProxyHosts + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getGConfNonProxyHosts( + JNIEnv *env, jclass clazz) { + + if (client == NULL) { + gconfInit(env); + } + + GSList *npHosts; + int size; + + npHosts = gconf_client_get_list(client, "/system/http_proxy/ignore_hosts", + GCONF_VALUE_STRING, NULL); + size = g_slist_length(npHosts); + + // TODO - I'm not sure this is really valid, it's from the JVM implementation + // of ProxySelector + if (size == 0) { + npHosts = gconf_client_get_list(client, "/system/proxy/no_proxy_for", + GCONF_VALUE_STRING, NULL); + } + size = g_slist_length(npHosts); + + jobjectArray ret = (*env)->NewObjectArray(env, size, stringClass, NULL); + + ListProcContext lpc; + lpc.env = env; + lpc.npHostArray = ret; + lpc.index = 0; + + g_slist_foreach(npHosts, listProc, &lpc); + return ret; +} + +/* + * Class: org_eclipse_core_internal_net_UnixProxyProvider + * Method: getKdeProxyInfo + * Signature: ([Ljava/lang/String); + */ +JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getKdeProxyInfo( + JNIEnv *env, jclass clazz, jstring protocol) { + //printf("getKdeProxyInfo - not implemented\n"); + return NULL; +} + +/* + * Class: org_eclipse_core_internal_net_UnixProxyProvider + * Method: getKdeNonProxyHosts + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jobject JNICALL Java_org_eclipse_core_internal_net_UnixProxyProvider_getKdeNonProxyHosts( + JNIEnv *env, jclass clazz) { + //printf("getKdeNonProxyHosts - not implemented\n"); + return NULL; +} + 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,80 @@ +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 { + System.loadLibrary("proxysupport"); //$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() { + String[] npHosts = getGConfNonProxyHosts(); + if (npHosts != null && npHosts.length > 0) + return npHosts; + return getKdeNonProxyHosts(); + } + + // Returns null if something wrong or there is no proxy for the protocol + protected ProxyData getSystemProxyInfo(String protocol) { + ProxyData pd; + + // 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; + } + + // Then ask Gnome + pd = getGConfProxyInfo(protocol); + if (pd != null) + return pd; + + // Then ask KDE + pd = getKdeProxyInfo(protocol); + if (pd != null) + return pd; + + 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(); + +} Index: natives/unix/Debug/subdir.mk =================================================================== RCS file: natives/unix/Debug/subdir.mk diff -N natives/unix/Debug/subdir.mk --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ natives/unix/Debug/subdir.mk 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,24 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +C_SRCS += \ +../getsystemproxy.c + +OBJS += \ +./getsystemproxy.o + +C_DEPS += \ +./getsystemproxy.d + + +# Each subdirectory must supply rules for building sources it contributes +%.o: ../%.c + @echo 'Building file: $<' + @echo 'Invoking: GCC C Compiler' + 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"$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + Index: natives/unix/Debug/makefile =================================================================== RCS file: natives/unix/Debug/makefile diff -N natives/unix/Debug/makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ natives/unix/Debug/makefile 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,43 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +-include ../makefile.init + +RM := rm -rf + +# All of the sources participating in the build are defined here +-include sources.mk +-include subdir.mk +-include objects.mk + +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(strip $(C_DEPS)),) +-include $(C_DEPS) +endif +endif + +-include ../makefile.defs + +# Add inputs and outputs from these tool invocations to the build variables + +# All Target +all: libproxysupport.so + +# Tool invocations +libproxysupport.so: $(OBJS) $(USER_OBJS) + @echo 'Building target: $@' + @echo 'Invoking: GCC C Linker' + gcc -m32 -shared -o"libproxysupport.so" $(OBJS) $(USER_OBJS) $(LIBS) + @echo 'Finished building target: $@' + @echo ' ' + +# Other Targets +clean: + -$(RM) $(OBJS)$(C_DEPS)$(LIBRARIES) libproxysupport.so + -@echo ' ' + +.PHONY: all clean dependents +.SECONDARY: + +-include ../makefile.targets