From ce00aa019f344403a41eb56f9ed8799a97304b26 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 15 Aug 2008 14:42:41 +0200 Subject: [PATCH] winhttp: Implement WinHttpOpenRequest. --- dlls/winhttp/main.c | 14 ------ dlls/winhttp/session.c | 87 ++++++++++++++++++++++++++++++++++ dlls/winhttp/tests/winhttp.c | 13 +++-- dlls/winhttp/winhttp_private.h | 32 +++++++++++++ 4 files changed, 125 insertions(+), 21 deletions(-) diff --git a/dlls/winhttp/main.c b/dlls/winhttp/main.c index 613359048b0..44a1e428664 100644 --- a/dlls/winhttp/main.c +++ b/dlls/winhttp/main.c @@ -116,20 +116,6 @@ BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser(WINHTTP_CURRENT_USER_IE_PROXY_ return TRUE; } -/*********************************************************************** - * WinHttpOpenRequest (winhttp.@) - */ -HINTERNET WINAPI WinHttpOpenRequest (HINTERNET hConnect, LPCWSTR pwszVerb, LPCWSTR pwszObjectName, - LPCWSTR pwszVersion, LPCWSTR pwszReferrer, LPCWSTR* ppwszAcceptTypes, - DWORD dwFlags) -{ - FIXME("(%s, %s, %s, %s, 0x%x): stub\n", debugstr_w(pwszVerb), debugstr_w(pwszObjectName), - debugstr_w(pwszVersion), debugstr_w(pwszReferrer), dwFlags); - - SetLastError(ERROR_NOT_SUPPORTED); - return NULL; -} - /*********************************************************************** * WinHttpSendRequest (winhttp.@) */ diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c index 8f8ac2fa51f..9a668b31c17 100644 --- a/dlls/winhttp/session.c +++ b/dlls/winhttp/session.c @@ -182,6 +182,93 @@ end: return hconnect; } +/*********************************************************************** + * request_destroy (internal) + */ +static void request_destroy( object_header_t *hdr ) +{ + request_t *request = (request_t *)hdr; + int i; + + TRACE("%p\n", request); + + release_object( &request->connect->hdr ); + + heap_free( request->verb ); + heap_free( request->path ); + heap_free( request->version ); + heap_free( request->raw_headers ); + heap_free( request->status_text ); + for (i = 0; i < request->num_headers; i++) + { + heap_free( request->headers[i].field ); + heap_free( request->headers[i].value ); + } + heap_free( request->headers ); + heap_free( request ); +} + +static const object_vtbl_t request_vtbl = +{ + request_destroy, + NULL, + NULL +}; + +/*********************************************************************** + * WinHttpOpenRequest (winhttp.@) + */ +HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR object, LPCWSTR version, + LPCWSTR referrer, LPCWSTR *types, DWORD flags ) +{ + request_t *request; + connect_t *connect; + HINTERNET hrequest = NULL; + + TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect, debugstr_w(verb), debugstr_w(object), + debugstr_w(version), debugstr_w(referrer), types, flags); + + if (!(connect = (connect_t *)grab_object( hconnect ))) + { + set_last_error( ERROR_INVALID_HANDLE ); + return NULL; + } + if (connect->hdr.type != WINHTTP_HANDLE_TYPE_CONNECT) + { + release_object( &connect->hdr ); + set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + return NULL; + } + if (!(request = heap_alloc_zero( sizeof(request_t) ))) + { + release_object( &connect->hdr ); + return NULL; + } + request->hdr.type = WINHTTP_HANDLE_TYPE_REQUEST; + request->hdr.vtbl = &request_vtbl; + request->hdr.refs = 1; + request->hdr.flags = flags; + request->hdr.callback = connect->hdr.callback; + request->hdr.notify_mask = connect->hdr.notify_mask; + + addref_object( &connect->hdr ); + request->connect = connect; + list_add_head( &connect->hdr.children, &request->hdr.entry ); + + if (verb && !(request->verb = strdupW( verb ))) goto end; + if (object && !(request->path = strdupW( object ))) goto end; + if (version && !(request->version = strdupW( version ))) goto end; + + if (!(hrequest = alloc_handle( &request->hdr ))) goto end; + request->hdr.handle = hrequest; + +end: + release_object( &request->hdr ); + + TRACE("returning %p\n", hrequest); + return hrequest; +} + /*********************************************************************** * WinHttpCloseHandle (winhttp.@) */ diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index 5f6ce7c414d..abfa713a052 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -55,13 +55,12 @@ static void test_OpenRequest (void) skip("Network unreachable, skipping.\n"); goto done; } - todo_wine ok(request != NULL, - "WinHttpOpenrequest failed to open a request, error: %u.\n", GetLastError()); + ok(request != NULL, "WinHttpOpenrequest failed to open a request, error: %u.\n", GetLastError()); ret = WinHttpSendRequest(request, WINHTTP_NO_ADDITIONAL_HEADERS, 0, NULL, 0, 0, 0); todo_wine ok(ret == TRUE, "WinHttpSendRequest failed: %u\n", GetLastError()); ret = WinHttpCloseHandle(request); - todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret); + ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret); done: ret = WinHttpCloseHandle(connection); @@ -108,7 +107,7 @@ static void test_SendRequest (void) skip("Network unreachable, skipping.\n"); goto done; } - todo_wine ok(request != NULL, "WinHttpOpenrequest failed to open a request, error: %u.\n", GetLastError()); + ok(request != NULL, "WinHttpOpenrequest failed to open a request, error: %u.\n", GetLastError()); ret = WinHttpSendRequest(request, content_type, header_len, post_data, optional_len, total_len, 0); todo_wine ok(ret == TRUE, "WinHttpSendRequest failed: %u\n", GetLastError()); @@ -134,7 +133,7 @@ static void test_SendRequest (void) "Data read did not match, got '%s'.\n", buffer); ret = WinHttpCloseHandle(request); - todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret); + ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret); done: ret = WinHttpCloseHandle(connection); ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret); @@ -236,7 +235,7 @@ static void test_WinHttpAddHeaders(void) skip("Network unreachable, skipping.\n"); goto done; } - todo_wine ok(request != NULL, "WinHttpOpenRequest failed to open a request, error: %u.\n", GetLastError()); + ok(request != NULL, "WinHttpOpenRequest failed to open a request, error: %u.\n", GetLastError()); index = 0; len = sizeof(buffer); @@ -540,7 +539,7 @@ static void test_WinHttpAddHeaders(void) ok(ret == FALSE, "WinHttpQueryHeaders succeeded unexpectedly, found third header.\n"); ret = WinHttpCloseHandle(request); - todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret); + ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret); done: ret = WinHttpCloseHandle(connection); ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret); diff --git a/dlls/winhttp/winhttp_private.h b/dlls/winhttp/winhttp_private.h index 74398a680f3..0f8746645b8 100644 --- a/dlls/winhttp/winhttp_private.h +++ b/dlls/winhttp/winhttp_private.h @@ -78,6 +78,38 @@ typedef struct struct sockaddr_in sockaddr; } connect_t; +typedef struct +{ + int socket; + char *peek_msg; + char *peek_msg_mem; + size_t peek_len; +} netconn_t; + +typedef struct +{ + LPWSTR field; + LPWSTR value; + WORD flags; + WORD count; +} header_t; + +typedef struct +{ + object_header_t hdr; + connect_t *connect; + LPWSTR verb; + LPWSTR path; + LPWSTR version; + LPWSTR raw_headers; + netconn_t netconn; + LPWSTR status_text; + DWORD content_length; /* total number of bytes to be read (per chunk) */ + DWORD content_read; /* bytes read so far */ + header_t *headers; + DWORD num_headers; +} request_t; + object_header_t *addref_object( object_header_t * ); object_header_t *grab_object( HINTERNET ); void release_object( object_header_t * );