summaryrefslogtreecommitdiffstats
path: root/src_native
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-11-11 14:40:18 +0100
committerBjörn Hagemeister2014-11-11 14:40:18 +0100
commite70ee5b59306ea37dd0c72603c61b33b1555def9 (patch)
treee6f09d76449da54463b9b4fa408b7dfba4b4b7bf /src_native
downloadproxy-vole-e70ee5b59306ea37dd0c72603c61b33b1555def9.tar.gz
proxy-vole-e70ee5b59306ea37dd0c72603c61b33b1555def9.tar.xz
proxy-vole-e70ee5b59306ea37dd0c72603c61b33b1555def9.zip
Added proxy java classes.
Diffstat (limited to 'src_native')
-rw-r--r--src_native/gnome/ProxySchemasGSettingsAccess.c117
-rw-r--r--src_native/gnome/ProxySchemasGSettingsAccess.h21
-rw-r--r--src_native/gnome/make2
-rwxr-xr-xsrc_native/win/proxy_util_w23/compile.bat1
-rw-r--r--src_native/win/proxy_util_w23/dllmain.cpp19
-rw-r--r--src_native/win/proxy_util_w23/proxy_util_w23.vcproj255
-rw-r--r--src_native/win/proxy_util_w23/proxy_util_w32.cpp205
-rw-r--r--src_native/win/proxy_util_w23/proxy_util_w32.h50
-rw-r--r--src_native/win/proxy_util_w23/stdafx.cpp2
-rw-r--r--src_native/win/proxy_util_w23/stdafx.h11
-rw-r--r--src_native/win/proxy_util_w23/targetver.h28
-rw-r--r--src_native/win/proxy_util_w32.sln20
-rw-r--r--src_native/win/proxy_util_w32.suobin0 -> 41984 bytes
13 files changed, 731 insertions, 0 deletions
diff --git a/src_native/gnome/ProxySchemasGSettingsAccess.c b/src_native/gnome/ProxySchemasGSettingsAccess.c
new file mode 100644
index 0000000..b6e08a9
--- /dev/null
+++ b/src_native/gnome/ProxySchemasGSettingsAccess.c
@@ -0,0 +1,117 @@
+#include "ProxySchemasGSettingsAccess.h"
+#include <gio/gio.h>
+#include <string.h>
+#include <stdlib.h>
+
+struct GSettingsList {
+ const char * schemaName;
+ GSettings* client;
+ struct GSettingsList * next;
+};
+
+struct GSettingsList * proxySchemas;
+
+int startsWith(const char *pre, const char *str) {
+ size_t lenpre = strlen(pre),
+ lenstr = strlen(str);
+ return lenstr < lenpre ? 0 : strncmp(pre, str, lenpre) == 0;
+}
+
+__attribute__((constructor)) void init() {
+ g_type_init();
+ proxySchemas = 0;
+ const gchar* const* schemas = g_settings_list_schemas();
+ while (*schemas) {
+ if (startsWith("org.gnome.system.proxy", (const char *)(*schemas))) {
+ struct GSettingsList * nclients = (struct GSettingsList *) malloc(sizeof(struct GSettingsList));
+ nclients->next = proxySchemas;
+ nclients->schemaName = *schemas;
+ nclients->client = g_settings_new(*schemas);
+ proxySchemas = nclients;
+ }
+ schemas++;
+ }
+}
+
+__attribute__((destructor)) void destroy() {
+ struct GSettingsList * proxySchemasIt = proxySchemas;
+ while (proxySchemasIt != 0) {
+ struct GSettingsList * next = proxySchemasIt->next;
+ free(proxySchemasIt);
+ proxySchemasIt = next;
+ }
+ proxySchemas = 0;
+}
+
+void convertKey(JNIEnv *env, jmethodID put, jobject hashMap, gchar* gkey, GSettings* schema, GVariant * gvalue) {
+ jstring key = (*env)->NewStringUTF(env, gkey);
+ jobject value = 0;
+
+ const GVariantType * t = g_variant_get_type(gvalue);
+ if (g_variant_type_equal(t, G_VARIANT_TYPE_STRING)) {
+ const gchar * gstring = g_variant_get_string(gvalue, 0);
+ value = (*env)->NewStringUTF(env, gstring);
+ } else if (g_variant_type_equal(t, G_VARIANT_TYPE_BOOLEAN)) {
+ jclass bClass = (*env)->FindClass(env, "java/lang/Boolean");
+ jmethodID valueOf = (*env)->GetStaticMethodID(env, bClass, "valueOf", "(Z)Ljava/lang/Boolean;");
+ value = (*env)->CallStaticObjectMethod(env, bClass, valueOf, g_variant_get_boolean(gvalue));
+ (*env)->DeleteLocalRef(env, bClass);
+ } else if (g_variant_type_equal(t, G_VARIANT_TYPE_INT32)) {
+ jclass bClass = (*env)->FindClass(env, "java/lang/Integer");
+ jmethodID valueOf = (*env)->GetStaticMethodID(env, bClass, "valueOf", "(I)Ljava/lang/Integer;");
+ value = (*env)->CallStaticObjectMethod(env, bClass, valueOf, g_variant_get_int32(gvalue));
+ (*env)->DeleteLocalRef(env, bClass);
+ } else if (g_variant_type_equal(t, G_VARIANT_TYPE_STRING_ARRAY)) {
+ int size = g_variant_n_children(gvalue);
+ jclass bClass = (*env)->FindClass(env, "java/util/ArrayList");
+ jmethodID init = (*env)->GetMethodID(env, bClass, "<init>", "(I)V");
+ jmethodID add = (*env)->GetMethodID(env, bClass, "add", "(Ljava/lang/Object;)Z");
+ value = (*env)->NewObject(env, bClass, init, size);
+ int i;
+ for (i = 0; i < size; i++) {
+ GVariant * gsvalue = g_variant_get_child_value(gvalue, i);
+ const gchar * gstring = g_variant_get_string(gsvalue, 0);
+ jobject svalue = (*env)->NewStringUTF(env, gstring);
+ (*env)->CallObjectMethod(env, value, add, svalue);
+ (*env)->DeleteLocalRef(env, svalue);
+ }
+ (*env)->DeleteLocalRef(env, bClass);
+ }
+
+ if (value != 0) {
+ (*env)->CallObjectMethod(env, hashMap, put, key, value);
+ (*env)->DeleteLocalRef(env, value);
+ }
+ (*env)->DeleteLocalRef(env, key);
+}
+
+void convertSchema(JNIEnv *env, jclass mapClass, jmethodID init, jmethodID put, jobject hashMap, const char * schemaName, GSettings* schema) {
+ jobject subHashMap = (*env)->NewObject(env, mapClass, init);
+ jstring jschemaName = (*env)->NewStringUTF(env, schemaName);
+ gchar** keys = g_settings_list_keys(schema);
+ while (*keys) {
+ convertKey(env, put, subHashMap, *keys, schema, g_settings_get_value(schema, *keys));
+ keys++;
+ }
+ (*env)->CallObjectMethod(env, hashMap, put, jschemaName, subHashMap);
+ (*env)->DeleteLocalRef(env, subHashMap);
+ (*env)->DeleteLocalRef(env, jschemaName);
+}
+
+JNIEXPORT jobject JNICALL Java_com_btr_proxy_search_desktop_gnome_ProxySchemasGSettingsAccess_getValueByKeyBySchema(JNIEnv *env, jclass c) {
+ jclass mapClass = (*env)->FindClass(env, "java/util/HashMap");
+
+ jmethodID init = (*env)->GetMethodID(env, mapClass, "<init>", "()V");
+ jobject hashMap = (*env)->NewObject(env, mapClass, init);
+
+ jmethodID put = (*env)->GetMethodID(env, mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+ struct GSettingsList * proxySchemasIt = proxySchemas;
+ while (proxySchemasIt != 0) {
+ convertSchema(env, mapClass, init, put, hashMap, proxySchemasIt->schemaName, proxySchemasIt->client);
+ proxySchemasIt = proxySchemasIt->next;
+ }
+
+ (*env)->DeleteLocalRef(env, mapClass);
+ return hashMap;
+}
+
diff --git a/src_native/gnome/ProxySchemasGSettingsAccess.h b/src_native/gnome/ProxySchemasGSettingsAccess.h
new file mode 100644
index 0000000..84c112d
--- /dev/null
+++ b/src_native/gnome/ProxySchemasGSettingsAccess.h
@@ -0,0 +1,21 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class com_btr_proxy_search_desktop_gnome_ProxySchemasGSettingsAccess */
+
+#ifndef _Included_com_btr_proxy_search_desktop_gnome_ProxySchemasGSettingsAccess
+#define _Included_com_btr_proxy_search_desktop_gnome_ProxySchemasGSettingsAccess
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: com_btr_proxy_search_desktop_gnome_ProxySchemasGSettingsAccess
+ * Method: getValueByKeyBySchema
+ * Signature: ()Ljava/util/Map;
+ */
+JNIEXPORT jobject JNICALL Java_com_btr_proxy_search_desktop_gnome_ProxySchemasGSettingsAccess_getValueByKeyBySchema
+ (JNIEnv *, jclass);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src_native/gnome/make b/src_native/gnome/make
new file mode 100644
index 0000000..dd2235d
--- /dev/null
+++ b/src_native/gnome/make
@@ -0,0 +1,2 @@
+gcc -fPIC -m32 -shared `pkg-config --cflags gio-2.0` ProxySchemasGSettingsAccess.c `pkg-config --libs gio-2.0` -I /usr/lib/jvm/java-6-openjdk-i386/include/ -o gsettings-x86.so
+gcc -fPIC -m64 -shared `pkg-config --cflags gio-2.0` ProxySchemasGSettingsAccess.c `pkg-config --libs gio-2.0` -I /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/include/linux/ -I /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/include -o gsettings-amd64.so \ No newline at end of file
diff --git a/src_native/win/proxy_util_w23/compile.bat b/src_native/win/proxy_util_w23/compile.bat
new file mode 100755
index 0000000..15e0669
--- /dev/null
+++ b/src_native/win/proxy_util_w23/compile.bat
@@ -0,0 +1 @@
+cl "-IC:/Program Files/Java/jdk1.6.0_21/include" "-IC:/Program Files/Java/jdk1.6.0_21/include/win32" -LD proxy_util_w32.cpp dllmain.cpp stdafx.cpp -Feproxy_util_amd64.dll winhttp.lib Advapi32.lib
diff --git a/src_native/win/proxy_util_w23/dllmain.cpp b/src_native/win/proxy_util_w23/dllmain.cpp
new file mode 100644
index 0000000..c54fd32
--- /dev/null
+++ b/src_native/win/proxy_util_w23/dllmain.cpp
@@ -0,0 +1,19 @@
+// dllmain.cpp : Entry point code.
+#include "stdafx.h"
+
+BOOL APIENTRY DllMain( HMODULE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved
+ )
+{
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
+
diff --git a/src_native/win/proxy_util_w23/proxy_util_w23.vcproj b/src_native/win/proxy_util_w23/proxy_util_w23.vcproj
new file mode 100644
index 0000000..5227b98
--- /dev/null
+++ b/src_native/win/proxy_util_w23/proxy_util_w23.vcproj
@@ -0,0 +1,255 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9,00"
+ Name="proxy_util_w32"
+ ProjectGUID="{9A61BBAC-DD8E-4952-AAE6-26C03CF474F2}"
+ RootNamespace="proxy_util_w23"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="C:\Programme\Java\jdk1.6.0_14\include\win32;C:\Programme\Java\jdk1.6.0_14\include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PROXY_UTIL_W23_EXPORTS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ UsePrecompiledHeader="2"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="Winhttp.lib AdvAPI32.Lib"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories="C:\Programme\Java\jdk1.6.0_14\include\win32;C:\Programme\Java\jdk1.6.0_14\include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PROXY_UTIL_W23_EXPORTS"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="2"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="Winhttp.lib AdvAPI32.Lib"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Quelldateien"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\dllmain.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ CompileAsManaged="0"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ CompileAsManaged="0"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath=".\proxy_util_w32.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\stdafx.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="1"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Headerdateien"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\proxy_util_w32.h"
+ >
+ </File>
+ <File
+ RelativePath=".\stdafx.h"
+ >
+ </File>
+ <File
+ RelativePath=".\targetver.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Ressourcendateien"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ <File
+ RelativePath=".\ReadMe.txt"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/src_native/win/proxy_util_w23/proxy_util_w32.cpp b/src_native/win/proxy_util_w23/proxy_util_w32.cpp
new file mode 100644
index 0000000..a62ed08
--- /dev/null
+++ b/src_native/win/proxy_util_w23/proxy_util_w32.cpp
@@ -0,0 +1,205 @@
+// proxy_util_w23.cpp : Main methods of the DLL.
+
+#include "stdafx.h"
+#include "proxy_util_w32.h"
+
+/*****************************************************************************
+ * Class: com_btr_proxy_search_desktop_win_Win32ProxyUtils
+ * Method: winHttpDetectAutoProxyConfigUrl
+ * Signature: (I)Ljava/lang/String;
+ ****************************************************************************/
+
+JNIEXPORT jstring JNICALL Java_com_btr_proxy_search_desktop_win_Win32ProxyUtils_winHttpDetectAutoProxyConfigUrl
+(JNIEnv *env, jobject source, jint mode) {
+
+
+ LPWSTR ppwszAutoConfigUrl = NULL;
+ BOOL result = WinHttpDetectAutoProxyConfigUrl( mode, &ppwszAutoConfigUrl );
+ if (ppwszAutoConfigUrl == NULL) {
+ return NULL;
+ }
+
+ jstring retValue = env->NewString((jchar*)ppwszAutoConfigUrl,
+ wcslen(ppwszAutoConfigUrl));
+
+ GlobalFree( ppwszAutoConfigUrl );
+
+ return retValue;
+}
+
+/*****************************************************************************
+ * Class: com_btr_proxy_search_desktop_win_Win32ProxyUtils
+ * Method: winHttpGetDefaultProxyConfiguration
+ * Signature: ()Ljava/lang/String;
+ ****************************************************************************/
+
+JNIEXPORT jstring JNICALL Java_com_btr_proxy_search_desktop_win_Win32ProxyUtils_winHttpGetDefaultProxyConfiguration
+(JNIEnv *env, jobject source) {
+
+ WINHTTP_PROXY_INFO proxyInfo;
+
+ // Retrieve the default proxy configuration.
+ BOOL result = WinHttpGetDefaultProxyConfiguration( &proxyInfo );
+ if (result == FALSE) {
+ // TODO what to do in case of error.
+ DWORD errorCode = GetLastError();
+ }
+
+ int proxyTypeLen = 0;
+ int proxyLen = 0;
+ int proxyBypassLen = 0;
+
+ LPWSTR proxyType = NULL;
+ if (proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY) {
+ proxyType = L"PROXY ";
+ proxyTypeLen = wcslen(proxyType);
+ } else
+ if (proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NO_PROXY) {
+ proxyType = L"DIRECT ";
+ proxyTypeLen = wcslen(proxyType);
+ }
+ if (proxyInfo.lpszProxy != NULL) {
+ proxyLen += wcslen(proxyInfo.lpszProxy);
+ }
+ if (proxyInfo.lpszProxyBypass != NULL) {
+ proxyBypassLen += wcslen(proxyInfo.lpszProxyBypass);
+ }
+
+ jstring retVal = proxyInfo.lpszProxy == NULL? NULL
+ : env->NewString((jchar*)proxyInfo.lpszProxy, wcslen(proxyInfo.lpszProxy));
+
+ if (proxyInfo.lpszProxy != NULL) {
+ GlobalFree( proxyInfo.lpszProxy );
+ }
+ if (proxyInfo.lpszProxyBypass != NULL) {
+ GlobalFree( proxyInfo.lpszProxyBypass );
+ }
+ return retVal;
+
+
+ //int retValueLen = proxyTypeLen+proxyLen+1+proxyBypassLen+1;
+ //int insertPos = 0;
+ //LPWSTR combined = new WCHAR[retValueLen];
+ //combined[retValueLen] = 0;
+
+ //wcsncat_s(combined, retValueLen, proxyType, proxyTypeLen);
+ //insertPos += proxyTypeLen;
+ //retValueLen -= proxyTypeLen;
+
+ //wcsncat_s(combined, retValueLen, proxyInfo.lpszProxy, proxyLen);
+ //insertPos += proxyLen;
+ //retValueLen -= proxyLen;
+
+ //wcsncat_s(combined, retValueLen, TEXT("|"), 1);
+ //insertPos += proxyLen;
+ //retValueLen -= proxyLen;
+
+ //wcsncat_s(combined, retValueLen, proxyInfo.lpszProxyBypass, proxyBypassLen);
+ //insertPos += proxyBypassLen;
+ //retValueLen -= proxyBypassLen;
+
+ // if (proxyInfo.lpszProxy != NULL) {
+ // GlobalFree( proxyInfo.lpszProxy );
+ // }
+ // if (proxyInfo.lpszProxyBypass != NULL) {
+ // GlobalFree( proxyInfo.lpszProxyBypass );
+ // }
+
+ //jstring retVal = env->NewString((jchar*)combined, wcslen(combined));
+
+ //return retVal;
+}
+
+/*****************************************************************************
+ * Class: com_btr_proxy_search_desktop_win_Win32ProxyUtils
+ * Method: WinHttpGetIEProxyConfigForCurrentUser
+ * Signature: ()Lcom/btr/proxy/search/desktop/win/Win32IESettings;
+ ****************************************************************************/
+
+JNIEXPORT jobject JNICALL Java_com_btr_proxy_search_desktop_win_Win32ProxyUtils_winHttpGetIEProxyConfigForCurrentUser
+(JNIEnv *env, jobject source) {
+
+ WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyInfo;
+
+ // Retrieve the IE proxy configuration.
+ BOOL result = WinHttpGetIEProxyConfigForCurrentUser( &ieProxyInfo );
+ if (result == FALSE) {
+ DWORD errorCode = GetLastError();
+ return NULL;
+ }
+
+ jboolean autoDetect = ieProxyInfo.fAutoDetect;
+ jstring autoConfigUrl = NULL;
+ jstring proxy = NULL;
+ jstring proxyBypass = NULL;
+
+ if (ieProxyInfo.lpszAutoConfigUrl != NULL) {
+ autoConfigUrl = env->NewString((jchar*)ieProxyInfo.lpszAutoConfigUrl, wcslen(ieProxyInfo.lpszAutoConfigUrl));
+ GlobalFree( ieProxyInfo.lpszAutoConfigUrl );
+ }
+ if (ieProxyInfo.lpszProxy != NULL) {
+ proxy = env->NewString((jchar*)ieProxyInfo.lpszProxy, wcslen(ieProxyInfo.lpszProxy));
+ GlobalFree( ieProxyInfo.lpszProxy );
+ }
+ if (ieProxyInfo.lpszProxyBypass != NULL) {
+ proxyBypass = env->NewString((jchar*)ieProxyInfo.lpszProxyBypass, wcslen(ieProxyInfo.lpszProxyBypass));
+ GlobalFree( ieProxyInfo.lpszProxyBypass );
+ }
+
+ // Build result container object.
+ jclass retValueClass = env->FindClass("com/btr/proxy/search/desktop/win/Win32IESettings");
+ if ( retValueClass == NULL ) {
+ return NULL;
+ }
+
+ jmethodID jmid = env->GetMethodID(retValueClass, "<init>", "(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
+ if (jmid == NULL) {
+ return NULL;
+ }
+
+ // Win32IESettings(boolean autoDetect, String autoConfigUrl, String proxy, String proxyBypass)
+ jobject retValue = env->NewObject(retValueClass, jmid, autoDetect, autoConfigUrl, proxy, proxyBypass);
+
+ return retValue;
+}
+
+/*****************************************************************************
+ * Class: com_btr_proxy_search_desktop_win_Win32ProxyUtils
+ * Method: readUserHomedir
+ * Signature: ()Ljava/lang/String;
+ ****************************************************************************/
+
+JNIEXPORT jstring JNICALL Java_com_btr_proxy_search_desktop_win_Win32ProxyUtils_readUserHomedir
+(JNIEnv *env, jobject source) {
+ HKEY key;
+ int result = RegOpenKeyEx(HKEY_CURRENT_USER,
+#ifdef _WIN64
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
+#else
+ L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
+#endif
+ 0, KEY_QUERY_VALUE, &key);
+ if (0 != ERROR_SUCCESS) {
+ LPWSTR errorMsg = L"ERROR: Key open failed";
+ return env->NewString((jchar*)errorMsg, wcslen(errorMsg));
+ }
+
+ BYTE pvData[1000];
+ DWORD dataSize = 1000;
+
+#ifdef _WIN64
+ result = RegQueryValueEx(key, "AppData", NULL, NULL, pvData, &dataSize);
+#else
+ result = RegQueryValueEx(key, L"AppData", NULL, NULL, pvData, &dataSize);
+#endif
+ RegCloseKey(key);
+ if (result != ERROR_SUCCESS) {
+ LPWSTR errorMsg = L"ERROR: Read value failed";
+ return env->NewString((jchar*)errorMsg, wcslen(errorMsg));
+ }
+
+ jstring retValue = env->NewString((jchar*)pvData, (dataSize-1)/2);
+ return retValue;
+}
+
+
diff --git a/src_native/win/proxy_util_w23/proxy_util_w32.h b/src_native/win/proxy_util_w23/proxy_util_w32.h
new file mode 100644
index 0000000..381b1e9
--- /dev/null
+++ b/src_native/win/proxy_util_w23/proxy_util_w32.h
@@ -0,0 +1,50 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class com_btr_proxy_search_desktop_win_Win32ProxyUtils */
+
+#ifndef _Included_com_btr_proxy_search_desktop_win_Win32ProxyUtils
+#define _Included_com_btr_proxy_search_desktop_win_Win32ProxyUtils
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*****************************************************************************
+ * Class: com_btr_proxy_search_desktop_win_Win32ProxyUtils
+ * Method: winHttpDetectAutoProxyConfigUrl
+ * Signature: (I)Ljava/lang/String;
+ ****************************************************************************/
+
+JNIEXPORT jstring JNICALL Java_com_btr_proxy_search_desktop_win_Win32ProxyUtils_winHttpDetectAutoProxyConfigUrl
+ (JNIEnv *, jobject, jint);
+
+/*****************************************************************************
+ * Class: com_btr_proxy_search_desktop_win_Win32ProxyUtils
+ * Method: winHttpGetDefaultProxyConfiguration
+ * Signature: ()Ljava/lang/String;
+ ****************************************************************************/
+
+JNIEXPORT jstring JNICALL Java_com_btr_proxy_search_desktop_win_Win32ProxyUtils_winHttpGetDefaultProxyConfiguration
+ (JNIEnv *, jobject);
+
+/*****************************************************************************
+ * Class: com_btr_proxy_search_desktop_win_Win32ProxyUtils
+ * Method: WinHttpGetIEProxyConfigForCurrentUser
+ * Signature: ()Lcom/btr/proxy/search/desktop/win/Win32IESettings;
+ ****************************************************************************/
+
+JNIEXPORT jobject JNICALL Java_com_btr_proxy_search_desktop_win_Win32ProxyUtils_winHttpGetIEProxyConfigForCurrentUser
+(JNIEnv *, jobject);
+
+/*****************************************************************************
+ * Class: com_btr_proxy_search_desktop_win_Win32ProxyUtils
+ * Method: readUserHomedir
+ * Signature: ()Ljava/lang/String;
+ ****************************************************************************/
+
+JNIEXPORT jstring JNICALL Java_com_btr_proxy_search_desktop_win_Win32ProxyUtils_readUserHomedir
+(JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src_native/win/proxy_util_w23/stdafx.cpp b/src_native/win/proxy_util_w23/stdafx.cpp
new file mode 100644
index 0000000..aa9cf23
--- /dev/null
+++ b/src_native/win/proxy_util_w23/stdafx.cpp
@@ -0,0 +1,2 @@
+// Used for precompiled headers.
+#include "stdafx.h"
diff --git a/src_native/win/proxy_util_w23/stdafx.h b/src_native/win/proxy_util_w23/stdafx.h
new file mode 100644
index 0000000..66875d0
--- /dev/null
+++ b/src_native/win/proxy_util_w23/stdafx.h
@@ -0,0 +1,11 @@
+// stdafx.h : Includefiles for Standardsystem-Includefiles
+
+#pragma once
+
+#include "targetver.h"
+
+#define WIN32_LEAN_AND_MEAN // No not include rarely used parts of Windows-Header .
+// Windows-Headerfiles:
+#include <windows.h>
+#include <winhttp.h>
+#include <Winreg.h> \ No newline at end of file
diff --git a/src_native/win/proxy_util_w23/targetver.h b/src_native/win/proxy_util_w23/targetver.h
new file mode 100644
index 0000000..24051b3
--- /dev/null
+++ b/src_native/win/proxy_util_w23/targetver.h
@@ -0,0 +1,28 @@
+#pragma once
+
+// This is autogenerated crap from Visual Studio. As I have the German version,
+// the comments are in German. Sorry for this.
+// -Bernd Rosstauscher
+
+// Die folgenden Makros definieren die mindestens erforderliche Plattform. Die mindestens erforderliche Plattform
+// ist die früheste Windows-, Internet Explorer-Version usw., die über die erforderlichen Features zur Ausführung
+// Ihrer Anwendung verfügt. Die Makros aktivieren alle Funktionen, die auf den Plattformversionen bis
+// einschließlich der angegebenen Version verfügbar sind.
+
+// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind.
+// Unter MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen.
+#ifndef WINVER // Gibt an, dass Windows Vista die mindestens erforderliche Plattform ist.
+#define WINVER 0x0600 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von Windows abzuzielen.
+#endif
+
+#ifndef _WIN32_WINNT // Gibt an, dass Windows Vista die mindestens erforderliche Plattform ist.
+#define _WIN32_WINNT 0x0600 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von Windows abzuzielen.
+#endif
+
+#ifndef _WIN32_WINDOWS // Gibt an, dass Windows 98 die mindestens erforderliche Plattform ist.
+#define _WIN32_WINDOWS 0x0410 // Ändern Sie den entsprechenden Wert, um auf mindestens Windows Me abzuzielen.
+#endif
+
+#ifndef _WIN32_IE // Gibt an, dass Internet Explorer 7.0 die mindestens erforderliche Plattform ist.
+#define _WIN32_IE 0x0700 // Ändern Sie den entsprechenden Wert, um auf andere Versionen von IE abzuzielen.
+#endif
diff --git a/src_native/win/proxy_util_w32.sln b/src_native/win/proxy_util_w32.sln
new file mode 100644
index 0000000..cc2ecd8
--- /dev/null
+++ b/src_native/win/proxy_util_w32.sln
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual C++ Express 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "proxy_util_w23", "proxy_util_w23\proxy_util_w23.vcproj", "{9A61BBAC-DD8E-4952-AAE6-26C03CF474F2}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {9A61BBAC-DD8E-4952-AAE6-26C03CF474F2}.Debug|Win32.ActiveCfg = Debug|Win32
+ {9A61BBAC-DD8E-4952-AAE6-26C03CF474F2}.Debug|Win32.Build.0 = Debug|Win32
+ {9A61BBAC-DD8E-4952-AAE6-26C03CF474F2}.Release|Win32.ActiveCfg = Release|Win32
+ {9A61BBAC-DD8E-4952-AAE6-26C03CF474F2}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/src_native/win/proxy_util_w32.suo b/src_native/win/proxy_util_w32.suo
new file mode 100644
index 0000000..049b84e
--- /dev/null
+++ b/src_native/win/proxy_util_w32.suo
Binary files differ