Commit ce00aa01 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Implement WinHttpOpenRequest.

parent 770ee204
......@@ -117,20 +117,6 @@ BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser(WINHTTP_CURRENT_USER_IE_PROXY_
}
/***********************************************************************
* 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.@)
*/
BOOL WINAPI WinHttpSendRequest (HINTERNET hRequest, LPCWSTR pwszHeaders, DWORD dwHeadersLength,
......
......@@ -183,6 +183,93 @@ end:
}
/***********************************************************************
* 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.@)
*/
BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
......
......@@ -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);
......
......@@ -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 * );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment