Commit 770ee204 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Implement WinHttpConnect.

parent 405e8cda
......@@ -117,19 +117,6 @@ BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser(WINHTTP_CURRENT_USER_IE_PROXY_
}
/***********************************************************************
* WinHttpConnect (winhttp.@)
*/
HINTERNET WINAPI WinHttpConnect (HINTERNET hSession, LPCWSTR pwszServerName,
INTERNET_PORT nServerPort, DWORD dwReserved)
{
FIXME("(%s, %d, 0x%x): stub\n", debugstr_w(pwszServerName), nServerPort, dwReserved);
SetLastError(ERROR_NOT_SUPPORTED);
return NULL;
}
/***********************************************************************
* WinHttpOpenRequest (winhttp.@)
*/
HINTERNET WINAPI WinHttpOpenRequest (HINTERNET hConnect, LPCWSTR pwszVerb, LPCWSTR pwszObjectName,
......
......@@ -102,6 +102,87 @@ end:
}
/***********************************************************************
* connect_destroy (internal)
*/
static void connect_destroy( object_header_t *hdr )
{
connect_t *connect = (connect_t *)hdr;
TRACE("%p\n", connect);
release_object( &connect->session->hdr );
heap_free( connect->hostname );
heap_free( connect->servername );
heap_free( connect->username );
heap_free( connect->password );
heap_free( connect );
}
static const object_vtbl_t connect_vtbl =
{
connect_destroy,
NULL,
NULL
};
/***********************************************************************
* WinHttpConnect (winhttp.@)
*/
HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved )
{
connect_t *connect;
session_t *session;
HINTERNET hconnect = NULL;
TRACE("%p, %s, %u, %x\n", hsession, debugstr_w(server), port, reserved);
if (!server)
{
set_last_error( ERROR_INVALID_PARAMETER );
return NULL;
}
if (!(session = (session_t *)grab_object( hsession )))
{
set_last_error( ERROR_INVALID_HANDLE );
return NULL;
}
if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
{
release_object( &session->hdr );
set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
return NULL;
}
if (!(connect = heap_alloc_zero( sizeof(connect_t) )))
{
release_object( &session->hdr );
return NULL;
}
connect->hdr.type = WINHTTP_HANDLE_TYPE_CONNECT;
connect->hdr.vtbl = &connect_vtbl;
connect->hdr.refs = 1;
connect->hdr.flags = session->hdr.flags;
connect->hdr.callback = session->hdr.callback;
connect->hdr.notify_mask = session->hdr.notify_mask;
addref_object( &session->hdr );
connect->session = session;
list_add_head( &session->hdr.children, &connect->hdr.entry );
if (server && !(connect->hostname = strdupW( server ))) goto end;
connect->hostport = port;
if (!(hconnect = alloc_handle( &connect->hdr ))) goto end;
connect->hdr.handle = hconnect;
end:
release_object( &connect->hdr );
TRACE("returning %p\n", hconnect);
return hconnect;
}
/***********************************************************************
* WinHttpCloseHandle (winhttp.@)
*/
BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
......
......@@ -42,13 +42,11 @@ static void test_OpenRequest (void)
SetLastError(0xdeadbeef);
connection = WinHttpConnect(session, NULL, INTERNET_DEFAULT_HTTP_PORT, 0);
ok (connection == NULL, "WinHttpConnect succeeded in opening connection to NULL server argument.\n");
todo_wine ok(GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
/* Test with a valid server name */
connection = WinHttpConnect (session, test_server, INTERNET_DEFAULT_HTTP_PORT, 0);
todo_wine ok(connection != NULL,
"WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
ok(connection != NULL, "WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
request = WinHttpOpenRequest(connection, NULL, NULL, NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
......@@ -67,7 +65,7 @@ static void test_OpenRequest (void)
done:
ret = WinHttpCloseHandle(connection);
todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
ret = WinHttpCloseHandle(session);
ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret);
......@@ -101,8 +99,7 @@ static void test_SendRequest (void)
ok(session != NULL, "WinHttpOpen failed to open session.\n");
connection = WinHttpConnect (session, test_site, INTERNET_DEFAULT_HTTP_PORT, 0);
todo_wine ok(connection != NULL,
"WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
ok(connection != NULL, "WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
request = WinHttpOpenRequest(connection, test_verb, test_file, NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_BYPASS_PROXY_CACHE);
......@@ -140,7 +137,7 @@ static void test_SendRequest (void)
todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret);
done:
ret = WinHttpCloseHandle(connection);
todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
ret = WinHttpCloseHandle(session);
ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret);
}
......@@ -230,8 +227,7 @@ static void test_WinHttpAddHeaders(void)
ok(session != NULL, "WinHttpOpen failed to open session.\n");
connection = WinHttpConnect (session, test_site, INTERNET_DEFAULT_HTTP_PORT, 0);
todo_wine ok(connection != NULL,
"WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
ok(connection != NULL, "WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
request = WinHttpOpenRequest(connection, test_verb, test_file, NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
......@@ -547,7 +543,7 @@ static void test_WinHttpAddHeaders(void)
todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret);
done:
ret = WinHttpCloseHandle(connection);
todo_wine ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
ret = WinHttpCloseHandle(session);
ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret);
......
......@@ -19,9 +19,17 @@
#ifndef _WINE_WINHTTP_PRIVATE_H_
#define _WINE_WINHTTP_PRIVATE_H_
#ifndef __WINE_CONFIG_H
# error You must include config.h to use this header
#endif
#include "wine/list.h"
#include "wine/unicode.h"
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
typedef struct _object_header_t object_header_t;
typedef struct
......@@ -57,6 +65,19 @@ typedef struct
LPWSTR proxy_password;
} session_t;
typedef struct
{
object_header_t hdr;
session_t *session;
LPWSTR hostname; /* final destination of the request */
LPWSTR servername; /* name of the server we directly connect to */
LPWSTR username;
LPWSTR password;
INTERNET_PORT hostport;
INTERNET_PORT serverport;
struct sockaddr_in sockaddr;
} connect_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