From 8545a971c94358c904a657859aff2fe9c943a49a Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Thu, 15 May 2014 14:05:17 +0200 Subject: [PATCH] jsproxy: Implement InternetInitializeAutoProxyDll and InternetDeinitializeAutoProxyDll. --- dlls/jsproxy/jsproxy.spec | 4 +- dlls/jsproxy/main.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/dlls/jsproxy/jsproxy.spec b/dlls/jsproxy/jsproxy.spec index 21943df1fc2..f557fe6c61d 100644 --- a/dlls/jsproxy/jsproxy.spec +++ b/dlls/jsproxy/jsproxy.spec @@ -1,5 +1,5 @@ -@ stub InternetInitializeAutoProxyDll +@ stdcall InternetInitializeAutoProxyDll(long str str ptr ptr) JSPROXY_InternetInitializeAutoProxyDll @ stub InternetInitializeExAutoProxyDll -@ stub InternetDeInitializeAutoProxyDll +@ stdcall InternetDeInitializeAutoProxyDll(str long) @ stub InternetDeInitializeExAutoProxyDll @ stub InternetGetProxyInfo diff --git a/dlls/jsproxy/main.c b/dlls/jsproxy/main.c index fa9703d74a8..9305ff8ea92 100644 --- a/dlls/jsproxy/main.c +++ b/dlls/jsproxy/main.c @@ -23,12 +23,23 @@ #include "windef.h" #include "winbase.h" +#include "winnls.h" +#include "wininet.h" #include "wine/debug.h" static HINSTANCE instance; WINE_DEFAULT_DEBUG_CHANNEL(jsproxy); +static CRITICAL_SECTION cs_jsproxy; +static CRITICAL_SECTION_DEBUG critsect_debug = +{ + 0, 0, &cs_jsproxy, + { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": cs_jsproxy") } +}; +static CRITICAL_SECTION cs_jsproxy = { &critsect_debug, -1, 0, 0, 0, 0 }; + /****************************************************************** * DllMain (jsproxy.@) */ @@ -46,3 +57,101 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved ) } return TRUE; } + +static inline void *heap_alloc( SIZE_T size ) +{ + return HeapAlloc( GetProcessHeap(), 0, size ); +} + +static inline BOOL heap_free( LPVOID mem ) +{ + return HeapFree( GetProcessHeap(), 0, mem ); +} + +static inline WCHAR *strdupAW( const char *src, DWORD len ) +{ + WCHAR *dst = NULL; + if (src) + { + int dst_len = MultiByteToWideChar( CP_ACP, 0, src, len, NULL, 0 ); + if ((dst = heap_alloc( (dst_len + 1) * sizeof(WCHAR) ))) len = MultiByteToWideChar( CP_ACP, 0, src, len, dst, dst_len ); + dst[dst_len] = 0; + } + return dst; +} + +static struct pac_script +{ + WCHAR *text; +} pac_script; +static struct pac_script *global_script = &pac_script; + +/****************************************************************** + * InternetDeInitializeAutoProxyDll (jsproxy.@) + */ +BOOL WINAPI InternetDeInitializeAutoProxyDll( LPSTR mime, DWORD reserved ) +{ + TRACE( "%s, %u\n", debugstr_a(mime), reserved ); + + EnterCriticalSection( &cs_jsproxy ); + + heap_free( global_script->text ); + global_script->text = NULL; + + LeaveCriticalSection( &cs_jsproxy ); + return TRUE; +} + +static WCHAR *load_script( const char *filename ) +{ + HANDLE handle; + DWORD size, bytes_read; + char *buffer; + int len; + WCHAR *script = NULL; + + handle = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 ); + if (handle == INVALID_HANDLE_VALUE) return NULL; + + size = GetFileSize( handle, NULL ); + if (!(buffer = heap_alloc( size ))) goto done; + if (!ReadFile( handle, buffer, size, &bytes_read, NULL ) || bytes_read != size) goto done; + + len = MultiByteToWideChar( CP_ACP, 0, buffer, size, NULL, 0 ); + if (!(script = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto done; + MultiByteToWideChar( CP_ACP, 0, buffer, size, script, len ); + script[len] = 0; + +done: + CloseHandle( handle ); + heap_free( buffer ); + return script; +} + +/****************************************************************** + * InternetInitializeAutoProxyDll (jsproxy.@) + */ +BOOL WINAPI JSPROXY_InternetInitializeAutoProxyDll( DWORD version, LPSTR tmpfile, LPSTR mime, + AutoProxyHelperFunctions *callbacks, + LPAUTO_PROXY_SCRIPT_BUFFER buffer ) +{ + BOOL ret = FALSE; + + TRACE( "%u, %s, %s, %p, %p\n", version, debugstr_a(tmpfile), debugstr_a(mime), callbacks, buffer ); + + if (callbacks) FIXME( "callbacks not supported\n" ); + + EnterCriticalSection( &cs_jsproxy ); + + if (global_script->text) + { + LeaveCriticalSection( &cs_jsproxy ); + return FALSE; + } + if (buffer && buffer->dwStructSize == sizeof(*buffer) && buffer->lpszScriptBuffer && + (global_script->text = strdupAW( buffer->lpszScriptBuffer, buffer->dwScriptBufferSize ))) ret = TRUE; + else if ((global_script->text = load_script( tmpfile ))) ret = TRUE; + + LeaveCriticalSection( &cs_jsproxy ); + return ret; +} -- 2.11.4.GIT