diff --git a/dlls/winhttp/Makefile.in b/dlls/winhttp/Makefile.in index bf26202401a..c83e630c769 100644 --- a/dlls/winhttp/Makefile.in +++ b/dlls/winhttp/Makefile.in @@ -8,7 +8,8 @@ IMPORTS = kernel32 C_SRCS = \ handle.c \ - main.c + main.c \ + session.c @MAKE_DLL_RULES@ diff --git a/dlls/winhttp/main.c b/dlls/winhttp/main.c index fb66360c9bc..e5c904b1945 100644 --- a/dlls/winhttp/main.c +++ b/dlls/winhttp/main.c @@ -83,16 +83,6 @@ HRESULT WINAPI DllUnregisterServer(void) return S_OK; } -/*********************************************************************** - * WinHttpCheckPlatform (winhttp.@) - */ -BOOL WINAPI WinHttpCheckPlatform(void) -{ - FIXME("stub\n"); - SetLastError(ERROR_NOT_SUPPORTED); - return FALSE; -} - /*********************************************************************** * WinHttpDetectAutoProxyConfigUrl (winhttp.@) */ @@ -126,21 +116,6 @@ BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser(WINHTTP_CURRENT_USER_IE_PROXY_ return TRUE; } -/*********************************************************************** - * WinHttpOpen (winhttp.@) - */ -HINTERNET WINAPI WinHttpOpen(LPCWSTR pwszUserAgent, DWORD dwAccessType, - LPCWSTR pwszProxyName, LPCWSTR pwszProxyByPass, - DWORD dwFlags) -{ - FIXME("(%s, %d, %s, %s, 0x%x): stub\n", debugstr_w(pwszUserAgent), - dwAccessType, debugstr_w(pwszProxyName), debugstr_w(pwszProxyByPass), - dwFlags); - - SetLastError(ERROR_NOT_SUPPORTED); - return NULL; -} - /*********************************************************************** * WinHttpConnect (winhttp.@) */ @@ -237,17 +212,6 @@ BOOL WINAPI WinHttpReadData (HINTERNET hInternet, LPVOID lpBuffer, DWORD dwNumbe return FALSE; } -/*********************************************************************** - * WinHttpReadData (winhttp.@) - */ -BOOL WINAPI WinHttpCloseHandle (HINTERNET hInternet) -{ - FIXME("stub\n"); - - SetLastError(ERROR_NOT_SUPPORTED); - return FALSE; -} - /*********************************************************************** * WinHttpWriteData (winhttp.@) */ diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c new file mode 100644 index 00000000000..76a878e5bd7 --- /dev/null +++ b/dlls/winhttp/session.c @@ -0,0 +1,121 @@ +/* + * Copyright 2008 Hans Leidekker for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "config.h" +#include "wine/port.h" +#include "wine/debug.h" + +#include + +#include "windef.h" +#include "winbase.h" +#include "winnls.h" +#include "winhttp.h" + +#include "winhttp_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(winhttp); + +static void set_last_error( DWORD error ) +{ + /* FIXME */ + SetLastError( error ); +} + +/*********************************************************************** + * WinHttpCheckPlatform (winhttp.@) + */ +BOOL WINAPI WinHttpCheckPlatform( void ) +{ + TRACE("\n"); + return TRUE; +} + +/*********************************************************************** + * session_destroy (internal) + */ +static void session_destroy( object_header_t *hdr ) +{ + session_t *session = (session_t *)hdr; + + TRACE("%p\n", session); + + heap_free( session->agent ); + heap_free( session->proxy_server ); + heap_free( session->proxy_bypass ); + heap_free( session->proxy_username ); + heap_free( session->proxy_password ); + heap_free( session ); +} + +static const object_vtbl_t session_vtbl = +{ + session_destroy, + NULL, + NULL +}; + +/*********************************************************************** + * WinHttpOpen (winhttp.@) + */ +HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags ) +{ + session_t *session; + HINTERNET handle = NULL; + + TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags); + + if (!(session = heap_alloc_zero( sizeof(session_t) ))) return NULL; + + session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION; + session->hdr.vtbl = &session_vtbl; + session->hdr.flags = flags; + session->hdr.refs = 1; + session->access = access; + + if (agent && !(session->agent = strdupW( agent ))) goto end; + if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end; + if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end; + + if (!(handle = alloc_handle( &session->hdr ))) goto end; + session->hdr.handle = handle; + +end: + release_object( &session->hdr ); + TRACE("returning %p\n", handle); + return handle; +} + +/*********************************************************************** + * WinHttpCloseHandle (winhttp.@) + */ +BOOL WINAPI WinHttpCloseHandle( HINTERNET handle ) +{ + object_header_t *hdr; + + TRACE("%p\n", handle); + + if (!(hdr = grab_object( handle ))) + { + set_last_error( ERROR_INVALID_HANDLE ); + return FALSE; + } + release_object( hdr ); + free_handle( handle ); + return TRUE; +} diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index b2dd2cf709e..2c7143ee8af 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -36,7 +36,7 @@ static void test_OpenRequest (void) session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); - todo_wine ok(session != NULL, "WinHttpOpen failed to open session.\n"); + ok(session != NULL, "WinHttpOpen failed to open session.\n"); /* Test with a bad server name */ SetLastError(0xdeadbeef); @@ -69,7 +69,7 @@ static void test_OpenRequest (void) ret = WinHttpCloseHandle(connection); todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret); ret = WinHttpCloseHandle(session); - todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret); + ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret); } @@ -98,7 +98,7 @@ static void test_SendRequest (void) session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); - todo_wine ok(session != NULL, "WinHttpOpen failed to open session.\n"); + ok(session != NULL, "WinHttpOpen failed to open session.\n"); connection = WinHttpConnect (session, test_site, INTERNET_DEFAULT_HTTP_PORT, 0); todo_wine ok(connection != NULL, @@ -142,7 +142,7 @@ static void test_SendRequest (void) ret = WinHttpCloseHandle(connection); todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret); ret = WinHttpCloseHandle(session); - todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret); + ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret); } static void test_WinHttpTimeFromSystemTime(void) @@ -227,7 +227,7 @@ static void test_WinHttpAddHeaders(void) session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); - todo_wine ok(session != NULL, "WinHttpOpen failed to open session.\n"); + ok(session != NULL, "WinHttpOpen failed to open session.\n"); connection = WinHttpConnect (session, test_site, INTERNET_DEFAULT_HTTP_PORT, 0); todo_wine ok(connection != NULL, @@ -549,7 +549,7 @@ static void test_WinHttpAddHeaders(void) ret = WinHttpCloseHandle(connection); todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret); ret = WinHttpCloseHandle(session); - todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret); + ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret); } diff --git a/dlls/winhttp/winhttp_private.h b/dlls/winhttp/winhttp_private.h index 7d06c87e91a..1d40fcbc90d 100644 --- a/dlls/winhttp/winhttp_private.h +++ b/dlls/winhttp/winhttp_private.h @@ -20,6 +20,7 @@ #define _WINE_WINHTTP_PRIVATE_H_ #include "wine/list.h" +#include "wine/unicode.h" typedef struct _object_header_t object_header_t; @@ -45,6 +46,23 @@ struct _object_header_t struct list children; }; +typedef struct +{ + object_header_t hdr; + LPWSTR agent; + DWORD access; + LPWSTR proxy_server; + LPWSTR proxy_bypass; + LPWSTR proxy_username; + LPWSTR proxy_password; +} session_t; + +object_header_t *addref_object( object_header_t * ); +object_header_t *grab_object( HINTERNET ); +void release_object( object_header_t * ); +HINTERNET alloc_handle( object_header_t * ); +BOOL free_handle( HINTERNET ); + static inline void *heap_alloc( SIZE_T size ) { return HeapAlloc( GetProcessHeap(), 0, size ); @@ -65,4 +83,14 @@ static inline BOOL heap_free( LPVOID mem ) return HeapFree( GetProcessHeap(), 0, mem ); } +static inline WCHAR *strdupW( const WCHAR *src ) +{ + WCHAR *dst; + + if (!src) return NULL; + dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ); + if (dst) strcpyW( dst, src ); + return dst; +} + #endif /* _WINE_WINHTTP_PRIVATE_H_ */