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