From e70ee5b59306ea37dd0c72603c61b33b1555def9 Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Tue, 11 Nov 2014 14:40:18 +0100 Subject: Added proxy java classes. --- src_native/win/proxy_util_w23/compile.bat | 1 + src_native/win/proxy_util_w23/dllmain.cpp | 19 ++ .../win/proxy_util_w23/proxy_util_w23.vcproj | 255 +++++++++++++++++++++ src_native/win/proxy_util_w23/proxy_util_w32.cpp | 205 +++++++++++++++++ src_native/win/proxy_util_w23/proxy_util_w32.h | 50 ++++ src_native/win/proxy_util_w23/stdafx.cpp | 2 + src_native/win/proxy_util_w23/stdafx.h | 11 + src_native/win/proxy_util_w23/targetver.h | 28 +++ src_native/win/proxy_util_w32.sln | 20 ++ src_native/win/proxy_util_w32.suo | Bin 0 -> 41984 bytes 10 files changed, 591 insertions(+) create mode 100755 src_native/win/proxy_util_w23/compile.bat create mode 100644 src_native/win/proxy_util_w23/dllmain.cpp create mode 100644 src_native/win/proxy_util_w23/proxy_util_w23.vcproj create mode 100644 src_native/win/proxy_util_w23/proxy_util_w32.cpp create mode 100644 src_native/win/proxy_util_w23/proxy_util_w32.h create mode 100644 src_native/win/proxy_util_w23/stdafx.cpp create mode 100644 src_native/win/proxy_util_w23/stdafx.h create mode 100644 src_native/win/proxy_util_w23/targetver.h create mode 100644 src_native/win/proxy_util_w32.sln create mode 100644 src_native/win/proxy_util_w32.suo (limited to 'src_native/win') 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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, "", "(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 +/* 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 +#include +#include \ 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 Binary files /dev/null and b/src_native/win/proxy_util_w32.suo differ -- cgit v1.2.3-55-g7522