/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jvm_md.h"
#include "jlong.h"
#include "sun_net_spi_DefaultProxySelector.h"
#include <dlfcn.h>
#include <stdio.h>
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
#include <string.h>
#else
#include <strings.h>
#endif
/**
* These functions are used by the sun.net.spi.DefaultProxySelector class
* to access some platform specific settings.
* Everything is loaded dynamically so no hard link with any library exists.
* The GConf-2 settings used are:
* - /system/http_proxy/use_http_proxy boolean
* - /system/http_proxy/use_authentcation boolean
* - /system/http_proxy/use_same_proxy boolean
* - /system/http_proxy/host string
* - /system/http_proxy/authentication_user string
* - /system/http_proxy/authentication_password string
* - /system/http_proxy/port int
* - /system/proxy/socks_host string
* - /system/proxy/secure_host string
* - /system/proxy/socks_port int
* - /system/proxy/secure_port int
* - /system/proxy/no_proxy_for list
* - /system/proxy/gopher_host string
* - /system/proxy/gopher_port int
*/
typedef void* gconf_client_get_default_func();
typedef char* gconf_client_get_string_func(void *, char *, void**);
typedef int gconf_client_get_int_func(void*, char *, void**);
typedef int gconf_client_get_bool_func(void*, char *, void**);
typedef int gconf_init_func(int, char**, void**);
typedef void g_type_init_func ();
static int gconf_ver = 0;
/*
* Class: sun_net_spi_DefaultProxySelector
* Method: init
* Signature: ()Z
*/
proxy_ctrID = (*env)->GetMethodID(env, proxy_class, "<init>", "(Ljava/net/Proxy$Type;Ljava/net/SocketAddress;)V");
isaddr_createUnresolvedID = (*env)->GetStaticMethodID(env, isaddr_class, "createUnresolved", "(Ljava/lang/String;I)Ljava/net/InetSocketAddress;");
/**
* Let's try to load le GConf-2 library
*/
gconf_ver = 2;
}
if (gconf_ver > 0) {
/*
* Now let's get pointer to the functions we need.
*/
my_get_default_func = (gconf_client_get_default_func*) dlsym(RTLD_DEFAULT, "gconf_client_get_default");
/**
* Try to connect to GConf.
*/
(*my_g_type_init_func)();
gconf_client = (*my_get_default_func)();
if (gconf_client != NULL) {
my_get_string_func = (gconf_client_get_string_func*) dlsym(RTLD_DEFAULT, "gconf_client_get_string");
my_get_bool_func != NULL) {
/**
* We did get all we need. Let's enable the System Proxy Settings.
*/
return JNI_TRUE;
}
}
}
}
return JNI_FALSE;
}
/*
* Class: sun_net_spi_DefaultProxySelector
* Method: getSystemProxy
*/
{
int pport = 0;
int use_proxy = 0;
int use_same_proxy = 0;
const char* urlhost;
const char *cproto;
if (gconf_ver > 0) {
if (gconf_client == NULL) {
(*my_g_type_init_func)();
gconf_client = (*my_get_default_func)();
}
if (gconf_client != NULL) {
/**
* We will have to check protocol by protocol as they do use different
* entries.
*/
if (use_same_proxy) {
if (use_proxy) {
}
}
/**
* HTTP:
* /system/http_proxy/use_http_proxy (boolean)
* /system/http_proxy/host (string)
* /system/http_proxy/port (integer)
*/
if (use_proxy) {
if (!use_same_proxy) {
}
}
}
/**
* HTTPS:
* /system/proxy/secure_host (string)
* /system/proxy/secure_port (integer)
*/
if (!use_same_proxy) {
}
if (use_proxy)
}
}
/**
* FTP:
*/
if (!use_same_proxy) {
}
if (use_proxy)
}
}
/**
* GOPHER:
* /system/proxy/gopher_host (string)
* /system/proxy/gopher_port (integer)
*/
if (!use_same_proxy) {
}
if (use_proxy)
}
}
/**
* SOCKS:
* /system/proxy/socks_host (string)
* /system/proxy/socks_port (integer)
*/
if (!use_same_proxy) {
}
if (use_proxy)
}
}
char *noproxyfor;
char *s;
/**
* check for the exclude list (aka "No Proxy For" list).
* It's a list of comma separated suffixes (e.g. domain name).
*/
if (noproxyfor != NULL) {
/**
* the URL host name matches with one of the sufixes,
* therefore we have to use a direct connection.
*/
use_proxy = 0;
break;
}
}
}
}
if (use_proxy) {
return proxy;
}
}
}
}
}
return no_proxy;
}