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