28 #include "jni_util.h" 29 #include "jvm.h" 30 #include "jlong.h" 31 #include "sun_net_spi_DefaultProxySelector.h" 32 33 /** 34 * These functions are used by the sun.net.spi.DefaultProxySelector class 35 * to access some platform specific settings. 36 * This is the Windows code using the registry settings. 37 */ 38 39 static jclass proxy_class; 40 static jclass isaddr_class; 41 static jclass ptype_class; 42 static jmethodID isaddr_createUnresolvedID; 43 static jmethodID proxy_ctrID; 44 static jfieldID pr_no_proxyID; 45 static jfieldID ptype_httpID; 46 static jfieldID ptype_socksID; 47 48 #define CHECK_NULL(X) { if ((X) == NULL) fprintf (stderr,"JNI errror at line %d\n", __LINE__); } 49 50 51 /* 52 * Class: sun_net_spi_DefaultProxySelector 53 * Method: init 54 * Signature: ()Z 55 */ 56 JNIEXPORT jboolean JNICALL 57 Java_sun_net_spi_DefaultProxySelector_init(JNIEnv *env, jclass clazz) { 58 HKEY hKey; 59 LONG ret; 60 jclass cls; 61 62 /** 63 * Get all the method & field IDs for later use. 64 */ 65 CHECK_NULL(cls = (*env)->FindClass(env,"java/net/Proxy")); 66 proxy_class = (*env)->NewGlobalRef(env, cls); 67 CHECK_NULL(cls = (*env)->FindClass(env,"java/net/Proxy$Type")); 68 ptype_class = (*env)->NewGlobalRef(env, cls); 69 CHECK_NULL(cls = (*env)->FindClass(env, "java/net/InetSocketAddress")); 70 isaddr_class = (*env)->NewGlobalRef(env, cls); 71 proxy_ctrID = (*env)->GetMethodID(env, proxy_class, "<init>", "(Ljava/net/Proxy$Type;Ljava/net/SocketAddress;)V"); 72 pr_no_proxyID = (*env)->GetStaticFieldID(env, proxy_class, "NO_PROXY", "Ljava/net/Proxy;"); 73 ptype_httpID = (*env)->GetStaticFieldID(env, ptype_class, "HTTP", "Ljava/net/Proxy$Type;"); 74 ptype_socksID = (*env)->GetStaticFieldID(env, ptype_class, "SOCKS", "Ljava/net/Proxy$Type;"); 75 isaddr_createUnresolvedID = (*env)->GetStaticMethodID(env, isaddr_class, "createUnresolved", "(Ljava/lang/String;I)Ljava/net/InetSocketAddress;"); 76 77 /** 78 * Let's see if we can find the proper Registry entry. 79 */ 80 ret = RegOpenKeyEx(HKEY_CURRENT_USER, 81 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 82 0, KEY_READ, (PHKEY)&hKey); 83 if (ret == ERROR_SUCCESS) { 84 RegCloseKey(hKey); 85 /** 86 * It worked, we can probably rely on it then. 87 */ 88 return JNI_TRUE; 89 } 90 91 return JNI_FALSE; 92 } 93 94 #define MAX_STR_LEN 1024 95 | 28 #include "jni_util.h" 29 #include "jvm.h" 30 #include "jlong.h" 31 #include "sun_net_spi_DefaultProxySelector.h" 32 33 /** 34 * These functions are used by the sun.net.spi.DefaultProxySelector class 35 * to access some platform specific settings. 36 * This is the Windows code using the registry settings. 37 */ 38 39 static jclass proxy_class; 40 static jclass isaddr_class; 41 static jclass ptype_class; 42 static jmethodID isaddr_createUnresolvedID; 43 static jmethodID proxy_ctrID; 44 static jfieldID pr_no_proxyID; 45 static jfieldID ptype_httpID; 46 static jfieldID ptype_socksID; 47 48 /* 49 * Class: sun_net_spi_DefaultProxySelector 50 * Method: init 51 * Signature: ()Z 52 */ 53 JNIEXPORT jboolean JNICALL 54 Java_sun_net_spi_DefaultProxySelector_init(JNIEnv *env, jclass clazz) { 55 HKEY hKey; 56 LONG ret; 57 jclass cls; 58 59 /** 60 * Get all the method & field IDs for later use. 61 */ 62 cls = (*env)->FindClass(env,"java/net/Proxy"); 63 CHECK_NULL_RETURN(cls, JNI_FALSE); 64 proxy_class = (*env)->NewGlobalRef(env, cls); 65 CHECK_NULL_RETURN(proxy_class, JNI_FALSE); 66 cls = (*env)->FindClass(env,"java/net/Proxy$Type"); 67 CHECK_NULL_RETURN(cls, JNI_FALSE); 68 ptype_class = (*env)->NewGlobalRef(env, cls); 69 CHECK_NULL_RETURN(ptype_class, JNI_FALSE); 70 cls = (*env)->FindClass(env, "java/net/InetSocketAddress"); 71 CHECK_NULL_RETURN(cls, JNI_FALSE); 72 isaddr_class = (*env)->NewGlobalRef(env, cls); 73 CHECK_NULL_RETURN(isaddr_class, JNI_FALSE); 74 proxy_ctrID = (*env)->GetMethodID(env, proxy_class, "<init>", 75 "(Ljava/net/Proxy$Type;Ljava/net/SocketAddress;)V"); 76 CHECK_NULL_RETURN(proxy_ctrID, JNI_FALSE); 77 pr_no_proxyID = (*env)->GetStaticFieldID(env, proxy_class, "NO_PROXY", "Ljava/net/Proxy;"); 78 CHECK_NULL_RETURN(pr_no_proxyID, JNI_FALSE); 79 ptype_httpID = (*env)->GetStaticFieldID(env, ptype_class, "HTTP", "Ljava/net/Proxy$Type;"); 80 CHECK_NULL_RETURN(ptype_httpID, JNI_FALSE); 81 ptype_socksID = (*env)->GetStaticFieldID(env, ptype_class, "SOCKS", "Ljava/net/Proxy$Type;"); 82 CHECK_NULL_RETURN(ptype_socksID, JNI_FALSE); 83 isaddr_createUnresolvedID = (*env)->GetStaticMethodID(env, isaddr_class, "createUnresolved", 84 "(Ljava/lang/String;I)Ljava/net/InetSocketAddress;"); 85 CHECK_NULL_RETURN(isaddr_createUnresolvedID, JNI_FALSE); 86 87 /** 88 * Let's see if we can find the proper Registry entry. 89 */ 90 ret = RegOpenKeyEx(HKEY_CURRENT_USER, 91 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 92 0, KEY_READ, (PHKEY)&hKey); 93 if (ret == ERROR_SUCCESS) { 94 RegCloseKey(hKey); 95 /** 96 * It worked, we can probably rely on it then. 97 */ 98 return JNI_TRUE; 99 } 100 101 return JNI_FALSE; 102 } 103 104 #define MAX_STR_LEN 1024 105 |