annotate src/java.base/unix/native/libnet/DefaultProxySelector.c @ 52882:c470f977ade8

8214014: Remove vestiges of gopher: protocol proxy support Reviewed-by: lancea, alanb
author rriggs
date Wed, 28 Nov 2018 16:04:36 -0500
parents 71c04702a3d5
children
rev   line source
duke@2 1 /*
clanger@43501 2 * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
duke@2 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@2 4 *
duke@2 5 * This code is free software; you can redistribute it and/or modify it
duke@2 6 * under the terms of the GNU General Public License version 2 only, as
ohair@5506 7 * published by the Free Software Foundation. Oracle designates this
duke@2 8 * particular file as subject to the "Classpath" exception as provided
ohair@5506 9 * by Oracle in the LICENSE file that accompanied this code.
duke@2 10 *
duke@2 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@2 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@2 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@2 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@2 15 * accompanied this code).
duke@2 16 *
duke@2 17 * You should have received a copy of the GNU General Public License version
duke@2 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@2 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@2 20 *
ohair@5506 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@5506 22 * or visit www.oracle.com if you need additional information or have any
ohair@5506 23 * questions.
duke@2 24 */
duke@2 25
clanger@43501 26 #include <dlfcn.h>
clanger@43501 27 #include <stdio.h>
clanger@43501 28 #include <stdlib.h>
clanger@43501 29 #include <string.h>
clanger@43501 30
duke@2 31 #include "jni.h"
duke@2 32 #include "jni_util.h"
duke@2 33 #include "jvm.h"
michaelm@12047 34 #include "jvm_md.h"
clanger@43501 35
clanger@43501 36 #include "proxy_util.h"
clanger@43501 37
duke@2 38 #include "sun_net_spi_DefaultProxySelector.h"
duke@2 39
dxu@22045 40
duke@2 41 /**
duke@2 42 * These functions are used by the sun.net.spi.DefaultProxySelector class
duke@2 43 * to access some platform specific settings.
duke@2 44 * This is the Solaris/Linux Gnome 2.x code using the GConf-2 library.
duke@2 45 * Everything is loaded dynamically so no hard link with any library exists.
duke@2 46 * The GConf-2 settings used are:
duke@2 47 * - /system/http_proxy/use_http_proxy boolean
duke@2 48 * - /system/http_proxy/use_authentcation boolean
chegar@4922 49 * - /system/http_proxy/use_same_proxy boolean
duke@2 50 * - /system/http_proxy/host string
duke@2 51 * - /system/http_proxy/authentication_user string
duke@2 52 * - /system/http_proxy/authentication_password string
duke@2 53 * - /system/http_proxy/port int
duke@2 54 * - /system/proxy/socks_host string
duke@2 55 * - /system/proxy/mode string
duke@2 56 * - /system/proxy/ftp_host string
duke@2 57 * - /system/proxy/secure_host string
duke@2 58 * - /system/proxy/socks_port int
duke@2 59 * - /system/proxy/ftp_port int
duke@2 60 * - /system/proxy/secure_port int
duke@2 61 * - /system/proxy/no_proxy_for list
dxu@21354 62 *
dxu@21354 63 * The following keys are not used in the new gnome 3
dxu@21354 64 * - /system/http_proxy/use_http_proxy
dxu@21354 65 * - /system/http_proxy/use_same_proxy
duke@2 66 */
duke@2 67 typedef void* gconf_client_get_default_func();
duke@2 68 typedef char* gconf_client_get_string_func(void *, char *, void**);
duke@2 69 typedef int gconf_client_get_int_func(void*, char *, void**);
duke@2 70 typedef int gconf_client_get_bool_func(void*, char *, void**);
duke@2 71 typedef int gconf_init_func(int, char**, void**);
duke@2 72 typedef void g_type_init_func ();
duke@2 73 gconf_client_get_default_func* my_get_default_func = NULL;
duke@2 74 gconf_client_get_string_func* my_get_string_func = NULL;
duke@2 75 gconf_client_get_int_func* my_get_int_func = NULL;
duke@2 76 gconf_client_get_bool_func* my_get_bool_func = NULL;
duke@2 77 gconf_init_func* my_gconf_init_func = NULL;
duke@2 78 g_type_init_func* my_g_type_init_func = NULL;
duke@2 79
dxu@21354 80
dxu@21354 81 /*
dxu@21354 82 * GProxyResolver provides synchronous and asynchronous network
dxu@21354 83 * proxy resolution. It is based on GSettings, which is the standard
dxu@21354 84 * of Gnome 3, to get system settings.
dxu@21354 85 *
dxu@21354 86 * In the current implementation, GProxyResolver has a higher priority
dxu@21354 87 * than the old GConf. And we only resolve the proxy synchronously. In
dxu@21354 88 * the future, we can also do the asynchronous network proxy resolution
dxu@21354 89 * if necessary.
dxu@21354 90 *
dxu@21354 91 */
dxu@21354 92 typedef struct _GProxyResolver GProxyResolver;
dxu@21354 93 typedef struct _GSocketConnectable GSocketConnectable;
dxu@21354 94 typedef struct GError GError;
dxu@21354 95 typedef GProxyResolver* g_proxy_resolver_get_default_func();
dxu@21354 96 typedef char** g_proxy_resolver_lookup_func();
dxu@21354 97 typedef GSocketConnectable* g_network_address_parse_uri_func();
dxu@21354 98 typedef const char* g_network_address_get_hostname_func();
dxu@21354 99 typedef unsigned short g_network_address_get_port_func();
dxu@21354 100 typedef void g_strfreev_func();
dxu@21354 101
dxu@21354 102 static g_proxy_resolver_get_default_func* g_proxy_resolver_get_default = NULL;
dxu@21354 103 static g_proxy_resolver_lookup_func* g_proxy_resolver_lookup = NULL;
dxu@21354 104 static g_network_address_parse_uri_func* g_network_address_parse_uri = NULL;
dxu@21354 105 static g_network_address_get_hostname_func* g_network_address_get_hostname = NULL;
dxu@21354 106 static g_network_address_get_port_func* g_network_address_get_port = NULL;
dxu@21354 107 static g_strfreev_func* g_strfreev = NULL;
dxu@21354 108
duke@2 109 static void* gconf_client = NULL;
dxu@21354 110 static int use_gproxyResolver = 0;
dxu@21354 111 static int use_gconf = 0;
dxu@21354 112
duke@2 113
dxu@21354 114 static int initGConf() {
dxu@21354 115 /**
dxu@21354 116 * Let's try to load GConf-2 library
dxu@21354 117 */
dxu@21354 118 if (dlopen(JNI_LIB_NAME("gconf-2"), RTLD_GLOBAL | RTLD_LAZY) != NULL ||
dxu@21354 119 dlopen(VERSIONED_JNI_LIB_NAME("gconf-2", "4"),
dxu@21354 120 RTLD_GLOBAL | RTLD_LAZY) != NULL)
dxu@21354 121 {
dxu@21354 122 /*
dxu@21354 123 * Now let's get pointer to the functions we need.
dxu@21354 124 */
dxu@21354 125 my_g_type_init_func =
dxu@21354 126 (g_type_init_func*)dlsym(RTLD_DEFAULT, "g_type_init");
dxu@21354 127 my_get_default_func =
dxu@21354 128 (gconf_client_get_default_func*)dlsym(RTLD_DEFAULT,
dxu@21354 129 "gconf_client_get_default");
dxu@21354 130
dxu@21354 131 if (my_g_type_init_func != NULL && my_get_default_func != NULL) {
dxu@21354 132 /**
dxu@21354 133 * Try to connect to GConf.
dxu@21354 134 */
dxu@21354 135 (*my_g_type_init_func)();
dxu@21354 136 gconf_client = (*my_get_default_func)();
dxu@21354 137 if (gconf_client != NULL) {
dxu@21354 138 my_get_string_func =
dxu@21354 139 (gconf_client_get_string_func*)dlsym(RTLD_DEFAULT,
dxu@21354 140 "gconf_client_get_string");
dxu@21354 141 my_get_int_func =
dxu@21354 142 (gconf_client_get_int_func*)dlsym(RTLD_DEFAULT,
dxu@21354 143 "gconf_client_get_int");
dxu@21354 144 my_get_bool_func =
dxu@21354 145 (gconf_client_get_bool_func*)dlsym(RTLD_DEFAULT,
dxu@21354 146 "gconf_client_get_bool");
dxu@21354 147 if (my_get_int_func != NULL && my_get_string_func != NULL &&
dxu@21354 148 my_get_bool_func != NULL)
dxu@21354 149 {
dxu@21354 150 /**
dxu@21354 151 * We did get all we need. Let's enable the System Proxy Settings.
dxu@21354 152 */
dxu@21354 153 return 1;
dxu@21354 154 }
dxu@21354 155 }
dxu@21354 156 }
dxu@21354 157 }
dxu@21354 158 return 0;
dxu@21354 159 }
dxu@21354 160
clanger@43501 161 static jobjectArray getProxyByGConf(JNIEnv *env, const char* cproto,
clanger@43501 162 const char* chost)
dxu@21354 163 {
dxu@21354 164 char *phost = NULL;
dxu@21354 165 char *mode = NULL;
dxu@21354 166 int pport = 0;
dxu@21354 167 int use_proxy = 0;
dxu@21354 168 int use_same_proxy = 0;
clanger@43501 169 jobjectArray proxy_array = NULL;
dxu@22045 170 jfieldID ptype_ID = ptype_httpID;
dxu@21354 171
clanger@43501 172 /* We only check manual proxy configurations */
dxu@21354 173 mode = (*my_get_string_func)(gconf_client, "/system/proxy/mode", NULL);
dxu@21354 174 if (mode && !strcasecmp(mode, "manual")) {
dxu@21354 175 /*
dxu@21354 176 * Even though /system/http_proxy/use_same_proxy is no longer used,
dxu@21354 177 * its value is set to false in gnome 3. So it is not harmful to check
dxu@21354 178 * it first in case jdk is used with an old gnome.
dxu@21354 179 */
dxu@21354 180 use_same_proxy = (*my_get_bool_func)(gconf_client, "/system/http_proxy/use_same_proxy", NULL);
dxu@21354 181 if (use_same_proxy) {
dxu@21354 182 phost = (*my_get_string_func)(gconf_client, "/system/http_proxy/host", NULL);
dxu@21354 183 pport = (*my_get_int_func)(gconf_client, "/system/http_proxy/port", NULL);
dxu@21354 184 use_proxy = (phost != NULL && pport != 0);
dxu@21354 185 }
dxu@21354 186
dxu@21354 187 if (!use_proxy) {
dxu@21354 188 /**
dxu@21354 189 * HTTP:
dxu@21354 190 * /system/http_proxy/use_http_proxy (boolean) - it's no longer used
dxu@21354 191 * /system/http_proxy/host (string)
dxu@21354 192 * /system/http_proxy/port (integer)
dxu@21354 193 */
dxu@21354 194 if (strcasecmp(cproto, "http") == 0) {
dxu@21354 195 phost = (*my_get_string_func)(gconf_client, "/system/http_proxy/host", NULL);
dxu@21354 196 pport = (*my_get_int_func)(gconf_client, "/system/http_proxy/port", NULL);
dxu@21354 197 use_proxy = (phost != NULL && pport != 0);
dxu@21354 198 }
dxu@21354 199
dxu@21354 200 /**
dxu@21354 201 * HTTPS:
dxu@21354 202 * /system/proxy/mode (string) [ "manual" means use proxy settings ]
dxu@21354 203 * /system/proxy/secure_host (string)
dxu@21354 204 * /system/proxy/secure_port (integer)
dxu@21354 205 */
dxu@21354 206 if (strcasecmp(cproto, "https") == 0) {
dxu@21354 207 phost = (*my_get_string_func)(gconf_client, "/system/proxy/secure_host", NULL);
dxu@21354 208 pport = (*my_get_int_func)(gconf_client, "/system/proxy/secure_port", NULL);
dxu@21354 209 use_proxy = (phost != NULL && pport != 0);
dxu@21354 210 }
dxu@21354 211
dxu@21354 212 /**
dxu@21354 213 * FTP:
dxu@21354 214 * /system/proxy/mode (string) [ "manual" means use proxy settings ]
dxu@21354 215 * /system/proxy/ftp_host (string)
dxu@21354 216 * /system/proxy/ftp_port (integer)
dxu@21354 217 */
dxu@21354 218 if (strcasecmp(cproto, "ftp") == 0) {
dxu@21354 219 phost = (*my_get_string_func)(gconf_client, "/system/proxy/ftp_host", NULL);
dxu@21354 220 pport = (*my_get_int_func)(gconf_client, "/system/proxy/ftp_port", NULL);
dxu@21354 221 use_proxy = (phost != NULL && pport != 0);
dxu@21354 222 }
dxu@21354 223
dxu@21354 224 /**
dxu@21354 225 * SOCKS:
dxu@21354 226 * /system/proxy/mode (string) [ "manual" means use proxy settings ]
dxu@21354 227 * /system/proxy/socks_host (string)
dxu@21354 228 * /system/proxy/socks_port (integer)
dxu@21354 229 */
dxu@21354 230 if (strcasecmp(cproto, "socks") == 0) {
dxu@21354 231 phost = (*my_get_string_func)(gconf_client, "/system/proxy/socks_host", NULL);
dxu@21354 232 pport = (*my_get_int_func)(gconf_client, "/system/proxy/socks_port", NULL);
dxu@21354 233 use_proxy = (phost != NULL && pport != 0);
dxu@21354 234 if (use_proxy)
dxu@22045 235 ptype_ID = ptype_socksID;
dxu@21354 236 }
dxu@21354 237 }
dxu@21354 238 }
dxu@21354 239
dxu@21354 240 if (use_proxy) {
dxu@21354 241 jstring jhost;
dxu@21354 242 char *noproxyfor;
dxu@21354 243 char *s;
dxu@21354 244
dxu@21354 245 /**
clanger@43501 246 * Check for the exclude list (aka "No Proxy For" list).
dxu@21354 247 * It's a list of comma separated suffixes (e.g. domain name).
dxu@21354 248 */
dxu@21354 249 noproxyfor = (*my_get_string_func)(gconf_client, "/system/proxy/no_proxy_for", NULL);
dxu@21354 250 if (noproxyfor != NULL) {
dxu@21354 251 char *tmpbuf[512];
dxu@21354 252 s = strtok_r(noproxyfor, ", ", tmpbuf);
dxu@21354 253
dxu@21354 254 while (s != NULL && strlen(s) <= strlen(chost)) {
dxu@21354 255 if (strcasecmp(chost+(strlen(chost) - strlen(s)), s) == 0) {
dxu@21354 256 /**
dxu@21354 257 * the URL host name matches with one of the sufixes,
dxu@21354 258 * therefore we have to use a direct connection.
dxu@21354 259 */
dxu@21354 260 use_proxy = 0;
dxu@21354 261 break;
dxu@21354 262 }
dxu@21354 263 s = strtok_r(NULL, ", ", tmpbuf);
dxu@21354 264 }
dxu@21354 265 }
clanger@43501 266 if (use_proxy) {
clanger@43501 267 jobject proxy = NULL;
clanger@43501 268 /* create a proxy array with one element. */
clanger@43501 269 proxy_array = (*env)->NewObjectArray(env, 1, proxy_class, NULL);
clanger@43501 270 if (proxy_array == NULL || (*env)->ExceptionCheck(env)) {
clanger@43501 271 return NULL;
clanger@43501 272 }
dxu@22045 273 proxy = createProxy(env, ptype_ID, phost, pport);
clanger@43501 274 if (proxy == NULL || (*env)->ExceptionCheck(env)) {
clanger@43501 275 return NULL;
clanger@43501 276 }
clanger@43501 277 (*env)->SetObjectArrayElement(env, proxy_array, 0, proxy);
clanger@43501 278 if ((*env)->ExceptionCheck(env)) {
clanger@43501 279 return NULL;
clanger@43501 280 }
clanger@43501 281 }
dxu@21354 282 }
dxu@21354 283
clanger@43501 284 return proxy_array;
dxu@21354 285 }
dxu@21354 286
dxu@21354 287 static int initGProxyResolver() {
dxu@21354 288 void *gio_handle;
dxu@21354 289
dxu@21354 290 gio_handle = dlopen("libgio-2.0.so", RTLD_LAZY);
dxu@21354 291 if (!gio_handle) {
dxu@21354 292 gio_handle = dlopen("libgio-2.0.so.0", RTLD_LAZY);
dxu@21354 293 if (!gio_handle) {
dxu@21354 294 return 0;
dxu@21354 295 }
dxu@21354 296 }
dxu@21354 297
dxu@21354 298 my_g_type_init_func = (g_type_init_func*)dlsym(gio_handle, "g_type_init");
dxu@21354 299
dxu@21354 300 g_proxy_resolver_get_default =
dxu@21354 301 (g_proxy_resolver_get_default_func*)dlsym(gio_handle,
dxu@21354 302 "g_proxy_resolver_get_default");
dxu@21354 303
dxu@21354 304 g_proxy_resolver_lookup =
dxu@21354 305 (g_proxy_resolver_lookup_func*)dlsym(gio_handle,
dxu@21354 306 "g_proxy_resolver_lookup");
dxu@21354 307
dxu@21354 308 g_network_address_parse_uri =
dxu@21354 309 (g_network_address_parse_uri_func*)dlsym(gio_handle,
dxu@21354 310 "g_network_address_parse_uri");
dxu@21354 311
dxu@21354 312 g_network_address_get_hostname =
dxu@21354 313 (g_network_address_get_hostname_func*)dlsym(gio_handle,
dxu@21354 314 "g_network_address_get_hostname");
dxu@21354 315
dxu@21354 316 g_network_address_get_port =
dxu@21354 317 (g_network_address_get_port_func*)dlsym(gio_handle,
dxu@21354 318 "g_network_address_get_port");
dxu@21354 319
dxu@21354 320 g_strfreev = (g_strfreev_func*)dlsym(gio_handle, "g_strfreev");
dxu@21354 321
dxu@21354 322 if (!my_g_type_init_func ||
dxu@21354 323 !g_proxy_resolver_get_default ||
dxu@21354 324 !g_proxy_resolver_lookup ||
dxu@21354 325 !g_network_address_parse_uri ||
dxu@21354 326 !g_network_address_get_hostname ||
dxu@21354 327 !g_network_address_get_port ||
dxu@21354 328 !g_strfreev)
dxu@21354 329 {
dxu@21354 330 dlclose(gio_handle);
dxu@21354 331 return 0;
dxu@21354 332 }
dxu@21354 333
dxu@21354 334 (*my_g_type_init_func)();
dxu@21354 335 return 1;
dxu@21354 336 }
dxu@21354 337
clanger@43501 338 static jobjectArray getProxyByGProxyResolver(JNIEnv *env, const char *cproto,
clanger@43501 339 const char *chost)
dxu@21354 340 {
dxu@21354 341 GProxyResolver* resolver = NULL;
dxu@21354 342 char** proxies = NULL;
dxu@21354 343 GError *error = NULL;
dxu@21354 344
dxu@21354 345 size_t protoLen = 0;
dxu@21354 346 size_t hostLen = 0;
dxu@21354 347 char* uri = NULL;
dxu@21354 348
clanger@43501 349 jobjectArray proxy_array = NULL;
dxu@21354 350
dxu@21354 351 resolver = (*g_proxy_resolver_get_default)();
dxu@21354 352 if (resolver == NULL) {
dxu@21354 353 return NULL;
dxu@21354 354 }
dxu@21354 355
clanger@43501 356 /* Construct the uri, cproto + "://" + chost */
dxu@21354 357 protoLen = strlen(cproto);
dxu@21354 358 hostLen = strlen(chost);
dxu@21354 359 uri = malloc(protoLen + hostLen + 4);
dxu@21354 360 if (!uri) {
clanger@43501 361 /* Out of memory */
dxu@21354 362 return NULL;
dxu@21354 363 }
dxu@21354 364 memcpy(uri, cproto, protoLen);
dxu@21354 365 memcpy(uri + protoLen, "://", 3);
dxu@21354 366 memcpy(uri + protoLen + 3, chost, hostLen + 1);
dxu@21354 367
dxu@21354 368 /*
dxu@21354 369 * Looks into the system proxy configuration to determine what proxy,
dxu@21354 370 * if any, to use to connect to uri. The returned proxy URIs are of
dxu@21354 371 * the form <protocol>://[user[:password]@]host:port or direct://,
dxu@21354 372 * where <protocol> could be http, rtsp, socks or other proxying protocol.
dxu@21354 373 * direct:// is used when no proxy is needed.
dxu@21354 374 */
dxu@21354 375 proxies = (*g_proxy_resolver_lookup)(resolver, uri, NULL, &error);
dxu@21354 376 free(uri);
dxu@21354 377
dxu@21354 378 if (proxies) {
dxu@21354 379 if (!error) {
dxu@21354 380 int i;
clanger@43501 381 int nr_proxies = 0;
clanger@43501 382 char** p = proxies;
clanger@43501 383 /* count the elements in the null terminated string vector. */
clanger@43501 384 while (*p) {
clanger@43501 385 nr_proxies++;
clanger@43501 386 p++;
clanger@43501 387 }
clanger@43501 388 /* create a proxy array that has to be filled. */
clanger@43501 389 proxy_array = (*env)->NewObjectArray(env, nr_proxies, proxy_class, NULL);
clanger@43501 390 if (proxy_array != NULL && !(*env)->ExceptionCheck(env)) {
clanger@43501 391 for (i = 0; proxies[i]; i++) {
clanger@43501 392 if (strncmp(proxies[i], "direct://", 9)) {
clanger@43501 393 GSocketConnectable* conn =
clanger@43501 394 (*g_network_address_parse_uri)(proxies[i], 0,
clanger@43501 395 &error);
clanger@43501 396 if (conn && !error) {
clanger@43501 397 const char *phost = NULL;
clanger@43501 398 unsigned short pport = 0;
clanger@43501 399 phost = (*g_network_address_get_hostname)(conn);
clanger@43501 400 pport = (*g_network_address_get_port)(conn);
clanger@43501 401 if (phost && pport > 0) {
clanger@43501 402 jobject proxy = NULL;
clanger@43501 403 jfieldID ptype_ID = ptype_httpID;
clanger@43501 404 if (!strncmp(proxies[i], "socks", 5))
clanger@43501 405 ptype_ID = ptype_socksID;
dxu@21354 406
clanger@43501 407 proxy = createProxy(env, ptype_ID, phost, pport);
clanger@43501 408 if (proxy == NULL || (*env)->ExceptionCheck(env)) {
clanger@43501 409 proxy_array = NULL;
clanger@43501 410 break;
clanger@43501 411 }
clanger@43501 412 (*env)->SetObjectArrayElement(env, proxy_array, i, proxy);
clanger@43501 413 if ((*env)->ExceptionCheck(env)) {
clanger@43501 414 proxy_array = NULL;
clanger@43501 415 break;
clanger@43501 416 }
clanger@43501 417 }
clanger@43501 418 }
clanger@43501 419 } else {
clanger@43501 420 /* direct connection - no proxy */
clanger@43501 421 jobject proxy = (*env)->GetStaticObjectField(env, proxy_class,
clanger@43501 422 pr_no_proxyID);
clanger@43501 423 if (proxy == NULL || (*env)->ExceptionCheck(env)) {
clanger@43501 424 proxy_array = NULL;
clanger@43501 425 break;
clanger@43501 426 }
clanger@43501 427 (*env)->SetObjectArrayElement(env, proxy_array, i, proxy);
clanger@43501 428 if ((*env)->ExceptionCheck(env)) {
clanger@43501 429 proxy_array = NULL;
clanger@43501 430 break;
dxu@21354 431 }
dxu@21354 432 }
dxu@21354 433 }
dxu@21354 434 }
dxu@21354 435 }
dxu@21354 436 (*g_strfreev)(proxies);
dxu@21354 437 }
dxu@21354 438
clanger@43501 439 return proxy_array;
dxu@21354 440 }
dxu@21354 441
duke@2 442 /*
duke@2 443 * Class: sun_net_spi_DefaultProxySelector
duke@2 444 * Method: init
duke@2 445 * Signature: ()Z
duke@2 446 */
duke@2 447 JNIEXPORT jboolean JNICALL
duke@2 448 Java_sun_net_spi_DefaultProxySelector_init(JNIEnv *env, jclass clazz) {
dxu@21354 449 use_gproxyResolver = initGProxyResolver();
dxu@21354 450 if (!use_gproxyResolver)
dxu@21354 451 use_gconf = initGConf();
duke@2 452
dxu@21354 453 if (use_gproxyResolver || use_gconf) {
dxu@22045 454 if (initJavaClass(env))
dxu@22045 455 return JNI_TRUE;
dxu@22045 456 }
dxu@22045 457 return JNI_FALSE;
duke@2 458 }
duke@2 459
duke@2 460 /*
duke@2 461 * Class: sun_net_spi_DefaultProxySelector
clanger@43501 462 * Method: getSystemProxies
clanger@43501 463 * Signature: ([Ljava/lang/String;Ljava/lang/String;)[Ljava/net/Proxy;
duke@2 464 */
clanger@43501 465 JNIEXPORT jobjectArray JNICALL
clanger@43501 466 Java_sun_net_spi_DefaultProxySelector_getSystemProxies(JNIEnv *env,
clanger@43501 467 jobject this,
clanger@43501 468 jstring proto,
clanger@43501 469 jstring host)
duke@2 470 {
dxu@21354 471 const char* cproto;
dxu@21354 472 const char* chost;
duke@2 473
dxu@21354 474 jboolean isProtoCopy;
dxu@21354 475 jboolean isHostCopy;
dxu@21354 476
clanger@43501 477 jobjectArray proxyArray = NULL;
dxu@21354 478
dxu@21354 479 cproto = (*env)->GetStringUTFChars(env, proto, &isProtoCopy);
dxu@21354 480
dxu@21354 481 if (cproto != NULL && (use_gproxyResolver || use_gconf)) {
dxu@21354 482 chost = (*env)->GetStringUTFChars(env, host, &isHostCopy);
dxu@21354 483 if (chost != NULL) {
dxu@21354 484 if (use_gproxyResolver)
clanger@43501 485 proxyArray = getProxyByGProxyResolver(env, cproto, chost);
dxu@21354 486 else if (use_gconf)
clanger@43501 487 proxyArray = getProxyByGConf(env, cproto, chost);
dxu@21354 488 if (isHostCopy == JNI_TRUE)
dxu@21354 489 (*env)->ReleaseStringUTFChars(env, host, chost);
dxu@21354 490 }
dxu@21354 491 if (isProtoCopy == JNI_TRUE)
dxu@21354 492 (*env)->ReleaseStringUTFChars(env, proto, cproto);
duke@2 493 }
clanger@43501 494 return proxyArray;
dxu@21354 495 }
chegar@4922 496