jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 12047 320a714614e9
child 21354 fc38b5f28a90
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12047
diff changeset
     2
 * Copyright (c) 2004, 2012, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "jvm.h"
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    29
#include "jvm_md.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "sun_net_spi_DefaultProxySelector.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <stdio.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
    34
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <strings.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * These functions are used by the sun.net.spi.DefaultProxySelector class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * to access some platform specific settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This is the Solaris/Linux Gnome 2.x code using the GConf-2 library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Everything is loaded dynamically so no hard link with any library exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The GConf-2 settings used are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * - /system/http_proxy/use_http_proxy          boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * - /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
    48
 * - /system/http_proxy/use_same_proxy          boolean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * - /system/http_proxy/host                    string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * - /system/http_proxy/authentication_user     string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * - /system/http_proxy/authentication_password string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * - /system/http_proxy/port                    int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * - /system/proxy/socks_host                   string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * - /system/proxy/mode                         string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * - /system/proxy/ftp_host                     string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * - /system/proxy/secure_host                  string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * - /system/proxy/socks_port                   int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * - /system/proxy/ftp_port                     int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * - /system/proxy/secure_port                  int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * - /system/proxy/no_proxy_for                 list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * - /system/proxy/gopher_host                  string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * - /system/proxy/gopher_port                  int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
typedef void* gconf_client_get_default_func();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
typedef char* gconf_client_get_string_func(void *, char *, void**);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
typedef int   gconf_client_get_int_func(void*, char *, void**);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
typedef int   gconf_client_get_bool_func(void*, char *, void**);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
typedef int   gconf_init_func(int, char**, void**);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
typedef void  g_type_init_func ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
gconf_client_get_default_func* my_get_default_func = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
gconf_client_get_string_func* my_get_string_func = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
gconf_client_get_int_func* my_get_int_func = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
gconf_client_get_bool_func* my_get_bool_func = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
gconf_init_func* my_gconf_init_func = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
g_type_init_func* my_g_type_init_func = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
static jclass proxy_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
static jclass isaddr_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
static jclass ptype_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
static jmethodID isaddr_createUnresolvedID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
static jmethodID proxy_ctrID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
static jfieldID pr_no_proxyID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
static jfieldID ptype_httpID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
static jfieldID ptype_socksID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
static int gconf_ver = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
static void* gconf_client = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#define CHECK_NULL(X) { if ((X) == NULL) fprintf (stderr,"JNI errror at line %d\n", __LINE__); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Class:     sun_net_spi_DefaultProxySelector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Method:    init
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
Java_sun_net_spi_DefaultProxySelector_init(JNIEnv *env, jclass clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  jclass cls = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  CHECK_NULL(cls = (*env)->FindClass(env,"java/net/Proxy"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  proxy_class = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  CHECK_NULL(cls = (*env)->FindClass(env,"java/net/Proxy$Type"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  ptype_class = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  CHECK_NULL(cls = (*env)->FindClass(env, "java/net/InetSocketAddress"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  isaddr_class = (*env)->NewGlobalRef(env, cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  proxy_ctrID = (*env)->GetMethodID(env, proxy_class, "<init>", "(Ljava/net/Proxy$Type;Ljava/net/SocketAddress;)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  pr_no_proxyID = (*env)->GetStaticFieldID(env, proxy_class, "NO_PROXY", "Ljava/net/Proxy;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  ptype_httpID = (*env)->GetStaticFieldID(env, ptype_class, "HTTP", "Ljava/net/Proxy$Type;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  ptype_socksID = (*env)->GetStaticFieldID(env, ptype_class, "SOCKS", "Ljava/net/Proxy$Type;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  isaddr_createUnresolvedID = (*env)->GetStaticMethodID(env, isaddr_class, "createUnresolved", "(Ljava/lang/String;I)Ljava/net/InetSocketAddress;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
   * Let's try to load le GConf-2 library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
   114
  if (dlopen(JNI_LIB_NAME("gconf-2"), RTLD_GLOBAL | RTLD_LAZY) != NULL ||
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
   115
      dlopen(VERSIONED_JNI_LIB_NAME("gconf-2", "4"),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 7668
diff changeset
   116
             RTLD_GLOBAL | RTLD_LAZY) != NULL) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    gconf_ver = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  if (gconf_ver > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Now let's get pointer to the functions we need.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    my_g_type_init_func = (g_type_init_func*) dlsym(RTLD_DEFAULT, "g_type_init");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    my_get_default_func = (gconf_client_get_default_func*) dlsym(RTLD_DEFAULT, "gconf_client_get_default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    if (my_g_type_init_func != NULL && my_get_default_func != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
       * Try to connect to GConf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      (*my_g_type_init_func)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      gconf_client = (*my_get_default_func)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      if (gconf_client != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        my_get_string_func = (gconf_client_get_string_func*) dlsym(RTLD_DEFAULT, "gconf_client_get_string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        my_get_int_func = (gconf_client_get_int_func*) dlsym(RTLD_DEFAULT, "gconf_client_get_int");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        my_get_bool_func = (gconf_client_get_bool_func*) dlsym(RTLD_DEFAULT, "gconf_client_get_bool");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (my_get_int_func != NULL && my_get_string_func != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            my_get_bool_func != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
          /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
           * We did get all we need. Let's enable the System Proxy Settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
          return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * Class:     sun_net_spi_DefaultProxySelector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * Method:    getSystemProxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * Signature: ([Ljava/lang/String;Ljava/lang/String;)Ljava/net/Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
Java_sun_net_spi_DefaultProxySelector_getSystemProxy(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                                     jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                                     jstring proto,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                                     jstring host)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  char *phost = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  char *mode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  int pport = 0;
6886
d818a2dfb100 6989690: java/net native code compiler warnings
chegar
parents: 5506
diff changeset
   163
  int use_proxy = 0;
4922
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   164
  int use_same_proxy = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  const char* urlhost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
  jobject isa = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
  jobject proxy = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  jobject type_proxy = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  jobject no_proxy = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
  const char *cproto;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  jboolean isCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  if (gconf_ver > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    if (gconf_client == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      (*my_g_type_init_func)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      gconf_client = (*my_get_default_func)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    if (gconf_client != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
      cproto = (*env)->GetStringUTFChars(env, proto, &isCopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
      if (cproto != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * We will have to check protocol by protocol as they do use different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
4922
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   186
        use_same_proxy = (*my_get_bool_func)(gconf_client, "/system/http_proxy/use_same_proxy", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   187
        if (use_same_proxy) {
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   188
          use_proxy = (*my_get_bool_func)(gconf_client, "/system/http_proxy/use_http_proxy", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   189
          if (use_proxy) {
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   190
            phost = (*my_get_string_func)(gconf_client, "/system/http_proxy/host", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   191
            pport = (*my_get_int_func)(gconf_client, "/system/http_proxy/port", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   192
          }
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   193
        }
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   194
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         * HTTP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * /system/http_proxy/use_http_proxy (boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * /system/http_proxy/host (string)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * /system/http_proxy/port (integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (strcasecmp(cproto, "http") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
          use_proxy = (*my_get_bool_func)(gconf_client, "/system/http_proxy/use_http_proxy", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
          if (use_proxy) {
4922
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   204
            if (!use_same_proxy) {
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   205
              phost = (*my_get_string_func)(gconf_client, "/system/http_proxy/host", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   206
              pport = (*my_get_int_func)(gconf_client, "/system/http_proxy/port", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   207
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            CHECK_NULL(type_proxy = (*env)->GetStaticObjectField(env, ptype_class, ptype_httpID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * HTTPS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * /system/proxy/mode (string) [ "manual" means use proxy settings ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * /system/proxy/secure_host (string)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * /system/proxy/secure_port (integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (strcasecmp(cproto, "https") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
          mode =  (*my_get_string_func)(gconf_client, "/system/proxy/mode", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
          if (mode != NULL && (strcasecmp(mode,"manual") == 0)) {
4922
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   221
            if (!use_same_proxy) {
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   222
              phost = (*my_get_string_func)(gconf_client, "/system/proxy/secure_host", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   223
              pport = (*my_get_int_func)(gconf_client, "/system/proxy/secure_port", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   224
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            use_proxy = (phost != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if (use_proxy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
              type_proxy = (*env)->GetStaticObjectField(env, ptype_class, ptype_httpID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * FTP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         * /system/proxy/mode (string) [ "manual" means use proxy settings ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * /system/proxy/ftp_host (string)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         * /system/proxy/ftp_port (integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (strcasecmp(cproto, "ftp") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
          mode =  (*my_get_string_func)(gconf_client, "/system/proxy/mode", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
          if (mode != NULL && (strcasecmp(mode,"manual") == 0)) {
4922
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   240
            if (!use_same_proxy) {
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   241
              phost = (*my_get_string_func)(gconf_client, "/system/proxy/ftp_host", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   242
              pport = (*my_get_int_func)(gconf_client, "/system/proxy/ftp_port", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   243
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            use_proxy = (phost != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            if (use_proxy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
              type_proxy = (*env)->GetStaticObjectField(env, ptype_class, ptype_httpID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         * GOPHER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         * /system/proxy/mode (string) [ "manual" means use proxy settings ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         * /system/proxy/gopher_host (string)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
         * /system/proxy/gopher_port (integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (strcasecmp(cproto, "gopher") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
          mode =  (*my_get_string_func)(gconf_client, "/system/proxy/mode", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
          if (mode != NULL && (strcasecmp(mode,"manual") == 0)) {
4922
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   259
            if (!use_same_proxy) {
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   260
              phost = (*my_get_string_func)(gconf_client, "/system/proxy/gopher_host", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   261
              pport = (*my_get_int_func)(gconf_client, "/system/proxy/gopher_port", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   262
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            use_proxy = (phost != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (use_proxy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
              type_proxy = (*env)->GetStaticObjectField(env, ptype_class, ptype_httpID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         * SOCKS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         * /system/proxy/mode (string) [ "manual" means use proxy settings ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         * /system/proxy/socks_host (string)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * /system/proxy/socks_port (integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (strcasecmp(cproto, "socks") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
          mode =  (*my_get_string_func)(gconf_client, "/system/proxy/mode", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
          if (mode != NULL && (strcasecmp(mode,"manual") == 0)) {
4922
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   278
            if (!use_same_proxy) {
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   279
              phost = (*my_get_string_func)(gconf_client, "/system/proxy/socks_host", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   280
              pport = (*my_get_int_func)(gconf_client, "/system/proxy/socks_port", NULL);
16f23522269d 6912868: "java.net.useSystemProxies" behavior fails to check "use_same_proxy" in GNOME
chegar
parents: 2
diff changeset
   281
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            use_proxy = (phost != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (use_proxy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
              type_proxy = (*env)->GetStaticObjectField(env, ptype_class, ptype_socksID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (isCopy == JNI_TRUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
          (*env)->ReleaseStringUTFChars(env, proto, cproto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (use_proxy && (phost != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
          jstring jhost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
          char *noproxyfor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
          char *s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
          /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
           * check for the exclude list (aka "No Proxy For" list).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
           * It's a list of comma separated suffixes (e.g. domain name).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
           */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
          noproxyfor = (*my_get_string_func)(gconf_client, "/system/proxy/no_proxy_for", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
          if (noproxyfor != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            char *tmpbuf[512];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            s = strtok_r(noproxyfor, ", ", tmpbuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            urlhost = (*env)->GetStringUTFChars(env, host, &isCopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            if (urlhost != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
              while (s != NULL && strlen(s) <= strlen(urlhost)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                if (strcasecmp(urlhost+(strlen(urlhost) - strlen(s)), s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                   * the URL host name matches with one of the sufixes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                   * therefore we have to use a direct connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                  use_proxy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                s = strtok_r(NULL, ", ", tmpbuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
              if (isCopy == JNI_TRUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                (*env)->ReleaseStringUTFChars(env, host, urlhost);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
          if (use_proxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            jhost = (*env)->NewStringUTF(env, phost);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            isa = (*env)->CallStaticObjectMethod(env, isaddr_class, isaddr_createUnresolvedID, jhost, pport);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            proxy = (*env)->NewObject(env, proxy_class, proxy_ctrID, type_proxy, isa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            return proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
  CHECK_NULL(no_proxy = (*env)->GetStaticObjectField(env, proxy_class, pr_no_proxyID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
  return no_proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
}