2008-08-15 14:42:15 +02:00
|
|
|
/*
|
|
|
|
* 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 <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winhttp.h"
|
2008-09-07 21:30:31 +02:00
|
|
|
#include "wincrypt.h"
|
2008-08-15 14:42:15 +02:00
|
|
|
|
|
|
|
#include "winhttp_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
|
|
|
|
|
2008-08-20 11:35:39 +02:00
|
|
|
void set_last_error( DWORD error )
|
2008-08-15 14:42:15 +02:00
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
SetLastError( error );
|
|
|
|
}
|
|
|
|
|
2008-09-07 21:29:44 +02:00
|
|
|
DWORD get_last_error( void )
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:43:07 +02:00
|
|
|
void send_callback( object_header_t *hdr, DWORD status, LPVOID info, DWORD buflen )
|
|
|
|
{
|
2008-09-03 12:31:52 +02:00
|
|
|
TRACE("%p, 0x%08x, %p, %u\n", hdr, status, info, buflen);
|
2008-08-20 11:34:34 +02:00
|
|
|
|
|
|
|
if (hdr->notify_mask & status) hdr->callback( hdr->handle, hdr->context, status, info, buflen );
|
2008-08-15 14:43:07 +02:00
|
|
|
}
|
|
|
|
|
2008-08-15 14:42:15 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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;
|
2008-09-16 12:31:35 +02:00
|
|
|
struct list *item, *next;
|
|
|
|
domain_t *domain;
|
2008-08-15 14:42:15 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", session);
|
|
|
|
|
2008-09-16 12:31:35 +02:00
|
|
|
LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache )
|
|
|
|
{
|
|
|
|
domain = LIST_ENTRY( item, domain_t, entry );
|
|
|
|
delete_domain( domain );
|
|
|
|
}
|
2008-08-15 14:42:15 +02:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_REDIRECT_POLICY:
|
|
|
|
{
|
|
|
|
if (!buffer || *buflen < sizeof(DWORD))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(DWORD);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(DWORD *)buffer = hdr->redirect_policy;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INVALID_PARAMETER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-03 16:58:06 +02:00
|
|
|
static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_PROXY:
|
|
|
|
{
|
|
|
|
WINHTTP_PROXY_INFO *pi = buffer;
|
|
|
|
|
|
|
|
FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WINHTTP_OPTION_REDIRECT_POLICY:
|
|
|
|
{
|
2008-09-16 11:51:58 +02:00
|
|
|
DWORD policy;
|
|
|
|
|
|
|
|
if (buflen != sizeof(policy))
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-09-03 16:58:06 +02:00
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
policy = *(DWORD *)buffer;
|
2008-09-03 16:58:06 +02:00
|
|
|
TRACE("0x%x\n", policy);
|
|
|
|
hdr->redirect_policy = policy;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-16 11:51:58 +02:00
|
|
|
case WINHTTP_OPTION_DISABLE_FEATURE:
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
2008-09-03 16:58:06 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INVALID_PARAMETER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
2008-09-03 16:58:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:42:15 +02:00
|
|
|
static const object_vtbl_t session_vtbl =
|
|
|
|
{
|
|
|
|
session_destroy,
|
2008-09-16 11:51:58 +02:00
|
|
|
session_query_option,
|
2008-09-03 16:58:06 +02:00
|
|
|
session_set_option
|
2008-08-15 14:42:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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;
|
2008-09-16 11:51:58 +02:00
|
|
|
session->hdr.redirect_policy = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
|
2008-09-16 12:31:35 +02:00
|
|
|
list_init( &session->cookie_cache );
|
2008-08-15 14:42:15 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:42:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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;
|
2008-09-03 12:31:52 +02:00
|
|
|
connect->hdr.context = session->hdr.context;
|
2008-08-15 14:42:28 +02:00
|
|
|
|
|
|
|
addref_object( &session->hdr );
|
|
|
|
connect->session = session;
|
|
|
|
list_add_head( &session->hdr.children, &connect->hdr.entry );
|
|
|
|
|
|
|
|
if (server && !(connect->hostname = strdupW( server ))) goto end;
|
2008-12-11 13:56:52 +01:00
|
|
|
connect->hostport = port;
|
2008-08-26 11:03:40 +02:00
|
|
|
|
|
|
|
if (server && !(connect->servername = strdupW( server ))) goto end;
|
2008-12-11 13:56:52 +01:00
|
|
|
connect->serverport = port;
|
2008-08-15 14:42:28 +02:00
|
|
|
|
|
|
|
if (!(hconnect = alloc_handle( &connect->hdr ))) goto end;
|
|
|
|
connect->hdr.handle = hconnect;
|
|
|
|
|
2008-08-15 14:43:07 +02:00
|
|
|
send_callback( &session->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hconnect, sizeof(hconnect) );
|
|
|
|
|
2008-08-15 14:42:28 +02:00
|
|
|
end:
|
|
|
|
release_object( &connect->hdr );
|
|
|
|
|
|
|
|
TRACE("returning %p\n", hconnect);
|
|
|
|
return hconnect;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:42:41 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* request_destroy (internal)
|
|
|
|
*/
|
|
|
|
static void request_destroy( object_header_t *hdr )
|
|
|
|
{
|
|
|
|
request_t *request = (request_t *)hdr;
|
2008-12-08 17:51:01 +01:00
|
|
|
DWORD i;
|
2008-08-15 14:42:41 +02:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2008-09-05 14:10:57 +02:00
|
|
|
static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_SECURITY_FLAGS:
|
|
|
|
{
|
2008-09-16 11:51:58 +02:00
|
|
|
DWORD flags;
|
2008-09-05 14:10:57 +02:00
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
if (!buffer || *buflen < sizeof(flags))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(flags);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = 0;
|
2008-09-05 14:10:57 +02:00
|
|
|
if (hdr->flags & WINHTTP_FLAG_SECURE) flags |= SECURITY_FLAG_SECURE;
|
|
|
|
*(DWORD *)buffer = flags;
|
2008-09-16 11:51:58 +02:00
|
|
|
*buflen = sizeof(flags);
|
2008-09-05 14:10:57 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-07 21:30:31 +02:00
|
|
|
case WINHTTP_OPTION_SERVER_CERT_CONTEXT:
|
|
|
|
{
|
|
|
|
const CERT_CONTEXT *cert;
|
|
|
|
request_t *request = (request_t *)hdr;
|
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
if (!buffer || *buflen < sizeof(cert))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(cert);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-07 21:30:31 +02:00
|
|
|
if (!(cert = netconn_get_certificate( &request->netconn ))) return FALSE;
|
2008-09-08 22:01:39 +02:00
|
|
|
*(CERT_CONTEXT **)buffer = (CERT_CONTEXT *)cert;
|
2008-09-07 21:30:31 +02:00
|
|
|
*buflen = sizeof(cert);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WINHTTP_OPTION_SECURITY_KEY_BITNESS:
|
|
|
|
{
|
2008-09-16 11:51:58 +02:00
|
|
|
if (!buffer || *buflen < sizeof(DWORD))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(DWORD);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-07 21:30:31 +02:00
|
|
|
*(DWORD *)buffer = 128; /* FIXME */
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-05 14:10:57 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INVALID_PARAMETER );
|
2008-09-05 14:10:57 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-03 16:58:06 +02:00
|
|
|
static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_PROXY:
|
|
|
|
{
|
|
|
|
WINHTTP_PROXY_INFO *pi = buffer;
|
|
|
|
|
|
|
|
FIXME("%u %s %s\n", pi->dwAccessType, debugstr_w(pi->lpszProxy), debugstr_w(pi->lpszProxyBypass));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WINHTTP_OPTION_DISABLE_FEATURE:
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
DWORD disable;
|
2008-09-03 16:58:06 +02:00
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
if (buflen != sizeof(DWORD))
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-17 04:41:26 +02:00
|
|
|
disable = *(DWORD *)buffer;
|
2008-09-03 16:58:06 +02:00
|
|
|
TRACE("0x%x\n", disable);
|
2008-09-16 12:32:11 +02:00
|
|
|
hdr->disable_flags |= disable;
|
2008-09-03 16:58:06 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WINHTTP_OPTION_AUTOLOGON_POLICY:
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
DWORD policy;
|
2008-09-03 16:58:06 +02:00
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
if (buflen != sizeof(DWORD))
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-17 04:41:26 +02:00
|
|
|
policy = *(DWORD *)buffer;
|
2008-09-03 16:58:06 +02:00
|
|
|
TRACE("0x%x\n", policy);
|
|
|
|
hdr->logon_policy = policy;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WINHTTP_OPTION_REDIRECT_POLICY:
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
DWORD policy;
|
2008-09-03 16:58:06 +02:00
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
if (buflen != sizeof(DWORD))
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-17 04:41:26 +02:00
|
|
|
policy = *(DWORD *)buffer;
|
2008-09-03 16:58:06 +02:00
|
|
|
TRACE("0x%x\n", policy);
|
|
|
|
hdr->redirect_policy = policy;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_INVALID_PARAMETER );
|
2008-09-03 16:58:06 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:42:41 +02:00
|
|
|
static const object_vtbl_t request_vtbl =
|
|
|
|
{
|
|
|
|
request_destroy,
|
2008-09-05 14:10:57 +02:00
|
|
|
request_query_option,
|
2008-09-03 16:58:06 +02:00
|
|
|
request_set_option
|
2008-08-15 14:42:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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;
|
2008-09-03 12:31:52 +02:00
|
|
|
request->hdr.context = connect->hdr.context;
|
2008-08-15 14:42:41 +02:00
|
|
|
|
|
|
|
addref_object( &connect->hdr );
|
|
|
|
request->connect = connect;
|
|
|
|
list_add_head( &connect->hdr.children, &request->hdr.entry );
|
|
|
|
|
2008-08-28 13:49:19 +02:00
|
|
|
if (!netconn_init( &request->netconn, request->hdr.flags & WINHTTP_FLAG_SECURE )) goto end;
|
2008-08-26 11:03:40 +02:00
|
|
|
|
2008-09-16 12:31:16 +02:00
|
|
|
if (!verb || !verb[0]) verb = getW;
|
|
|
|
if (!(request->verb = strdupW( verb ))) goto end;
|
2008-12-08 12:35:43 +01:00
|
|
|
|
|
|
|
if (object)
|
|
|
|
{
|
|
|
|
WCHAR *path, *p;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
len = strlenW( object ) + 1;
|
|
|
|
if (object[0] != '/') len++;
|
|
|
|
if (!(p = path = heap_alloc( len * sizeof(WCHAR) ))) goto end;
|
|
|
|
|
|
|
|
if (object[0] != '/') *p++ = '/';
|
|
|
|
strcpyW( p, object );
|
|
|
|
request->path = path;
|
|
|
|
}
|
|
|
|
else if (!(request->path = strdupW( slashW ))) goto end;
|
|
|
|
|
|
|
|
if (!version || !version[0]) version = http1_1;
|
2008-09-16 12:31:16 +02:00
|
|
|
if (!(request->version = strdupW( version ))) goto end;
|
2008-08-15 14:42:41 +02:00
|
|
|
|
|
|
|
if (!(hrequest = alloc_handle( &request->hdr ))) goto end;
|
|
|
|
request->hdr.handle = hrequest;
|
|
|
|
|
2008-08-15 14:43:07 +02:00
|
|
|
send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hrequest, sizeof(hrequest) );
|
|
|
|
|
2008-08-15 14:42:41 +02:00
|
|
|
end:
|
|
|
|
release_object( &request->hdr );
|
|
|
|
|
|
|
|
TRACE("returning %p\n", hrequest);
|
|
|
|
return hrequest;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:42:15 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* 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;
|
|
|
|
}
|
2008-08-15 14:43:07 +02:00
|
|
|
|
2008-09-03 12:31:24 +02:00
|
|
|
static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen )
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2008-09-17 04:41:26 +02:00
|
|
|
if (!buflen)
|
|
|
|
{
|
|
|
|
set_last_error( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-03 12:31:24 +02:00
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_CONTEXT_VALUE:
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
if (!buffer || *buflen < sizeof(DWORD_PTR))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(DWORD_PTR);
|
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-03 12:31:24 +02:00
|
|
|
*(DWORD_PTR *)buffer = hdr->context;
|
|
|
|
*buflen = sizeof(DWORD_PTR);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if (hdr->vtbl->query_option) ret = hdr->vtbl->query_option( hdr, option, buffer, buflen );
|
2008-09-16 11:51:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2008-09-03 12:31:24 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpQueryOption (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpQueryOption( HINTERNET handle, DWORD option, LPVOID buffer, LPDWORD buflen )
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
object_header_t *hdr;
|
|
|
|
|
|
|
|
TRACE("%p, %u, %p, %p\n", handle, option, buffer, buflen);
|
|
|
|
|
|
|
|
if (!(hdr = grab_object( handle )))
|
|
|
|
{
|
|
|
|
set_last_error( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = query_option( hdr, option, buffer, buflen );
|
|
|
|
|
|
|
|
release_object( hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen )
|
|
|
|
{
|
2008-09-03 16:58:06 +02:00
|
|
|
BOOL ret = TRUE;
|
2008-09-03 12:31:24 +02:00
|
|
|
|
2008-09-17 04:41:26 +02:00
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
set_last_error( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-03 12:31:24 +02:00
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_CONTEXT_VALUE:
|
|
|
|
{
|
2008-09-17 04:41:26 +02:00
|
|
|
if (buflen != sizeof(DWORD_PTR))
|
|
|
|
{
|
|
|
|
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-03 12:31:24 +02:00
|
|
|
hdr->context = *(DWORD_PTR *)buffer;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if (hdr->vtbl->set_option) ret = hdr->vtbl->set_option( hdr, option, buffer, buflen );
|
2008-09-16 11:51:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2008-09-17 04:41:26 +02:00
|
|
|
set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2008-09-03 12:31:24 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpSetOption (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpSetOption( HINTERNET handle, DWORD option, LPVOID buffer, DWORD buflen )
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
object_header_t *hdr;
|
|
|
|
|
|
|
|
TRACE("%p, %u, %p, %u\n", handle, option, buffer, buflen);
|
|
|
|
|
|
|
|
if (!(hdr = grab_object( handle )))
|
|
|
|
{
|
|
|
|
set_last_error( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = set_option( hdr, option, buffer, buflen );
|
|
|
|
|
|
|
|
release_object( hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:43:23 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpDetectAutoProxyConfigUrl (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
|
|
|
|
{
|
|
|
|
FIXME("0x%08x, %p\n", flags, url);
|
|
|
|
|
|
|
|
set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetDefaultProxyConfiguration (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
|
|
|
|
{
|
|
|
|
FIXME("%p\n", info);
|
|
|
|
|
|
|
|
info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
|
|
|
|
info->lpszProxy = NULL;
|
|
|
|
info->lpszProxyBypass = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *config )
|
|
|
|
{
|
|
|
|
TRACE("%p\n", config);
|
|
|
|
|
|
|
|
if (!config)
|
|
|
|
{
|
|
|
|
set_last_error( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: read from HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings */
|
|
|
|
|
|
|
|
FIXME("returning no proxy used\n");
|
|
|
|
config->fAutoDetect = FALSE;
|
|
|
|
config->lpszAutoConfigUrl = NULL;
|
|
|
|
config->lpszProxy = NULL;
|
|
|
|
config->lpszProxyBypass = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetProxyForUrl (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTOPROXY_OPTIONS *options,
|
|
|
|
WINHTTP_PROXY_INFO *info )
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p, %p\n", hsession, debugstr_w(url), options, info);
|
|
|
|
|
|
|
|
set_last_error( ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpSetDefaultProxyConfiguration (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
|
|
|
|
{
|
|
|
|
FIXME("%p [%u, %s, %s]\n", info, info->dwAccessType, debugstr_w(info->lpszProxy),
|
|
|
|
debugstr_w(info->lpszProxyBypass));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:43:07 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpSetStatusCallback (winhttp.@)
|
|
|
|
*/
|
|
|
|
WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback( HINTERNET handle, WINHTTP_STATUS_CALLBACK callback,
|
|
|
|
DWORD flags, DWORD_PTR reserved )
|
|
|
|
{
|
|
|
|
object_header_t *hdr;
|
|
|
|
WINHTTP_STATUS_CALLBACK ret;
|
|
|
|
|
|
|
|
TRACE("%p, %p, 0x%08x, 0x%lx\n", handle, callback, flags, reserved);
|
|
|
|
|
|
|
|
if (!(hdr = grab_object( handle )))
|
|
|
|
{
|
|
|
|
set_last_error( ERROR_INVALID_HANDLE );
|
|
|
|
return WINHTTP_INVALID_STATUS_CALLBACK;
|
|
|
|
}
|
|
|
|
ret = hdr->callback;
|
|
|
|
hdr->callback = callback;
|
|
|
|
hdr->notify_mask = flags;
|
|
|
|
|
|
|
|
release_object( hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
2008-08-15 14:44:16 +02:00
|
|
|
|
2008-08-20 11:35:15 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpSetTimeouts (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int send, int receive )
|
|
|
|
{
|
|
|
|
FIXME("%p, %d, %d, %d, %d\n", handle, resolve, connect, send, receive);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:44:16 +02:00
|
|
|
static const WCHAR wkday[7][4] =
|
|
|
|
{{'S','u','n', 0}, {'M','o','n', 0}, {'T','u','e', 0}, {'W','e','d', 0},
|
|
|
|
{'T','h','u', 0}, {'F','r','i', 0}, {'S','a','t', 0}};
|
|
|
|
static const WCHAR month[12][4] =
|
|
|
|
{{'J','a','n', 0}, {'F','e','b', 0}, {'M','a','r', 0}, {'A','p','r', 0},
|
|
|
|
{'M','a','y', 0}, {'J','u','n', 0}, {'J','u','l', 0}, {'A','u','g', 0},
|
|
|
|
{'S','e','p', 0}, {'O','c','t', 0}, {'N','o','v', 0}, {'D','e','c', 0}};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpTimeFromSystemTime (WININET.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
|
|
|
|
{
|
|
|
|
static const WCHAR format[] =
|
|
|
|
{'%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
|
|
|
|
'2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0};
|
|
|
|
|
|
|
|
TRACE("%p, %p\n", time, string);
|
|
|
|
|
|
|
|
if (!time || !string) return FALSE;
|
|
|
|
|
|
|
|
sprintfW( string, format,
|
|
|
|
wkday[time->wDayOfWeek],
|
|
|
|
time->wDay,
|
|
|
|
month[time->wMonth - 1],
|
|
|
|
time->wYear,
|
|
|
|
time->wHour,
|
|
|
|
time->wMinute,
|
|
|
|
time->wSecond );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpTimeToSystemTime (WININET.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpTimeToSystemTime( LPCWSTR string, SYSTEMTIME *time )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
const WCHAR *s = string;
|
|
|
|
WCHAR *end;
|
|
|
|
|
|
|
|
TRACE("%s, %p\n", debugstr_w(string), time);
|
|
|
|
|
|
|
|
if (!string || !time) return FALSE;
|
|
|
|
|
|
|
|
/* Windows does this too */
|
|
|
|
GetSystemTime( time );
|
|
|
|
|
|
|
|
/* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
|
|
|
|
* a SYSTEMTIME structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (*s && !isalphaW( *s )) s++;
|
|
|
|
if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
|
|
|
|
time->wDayOfWeek = 7;
|
|
|
|
|
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
if (toupperW( wkday[i][0] ) == toupperW( s[0] ) &&
|
|
|
|
toupperW( wkday[i][1] ) == toupperW( s[1] ) &&
|
|
|
|
toupperW( wkday[i][2] ) == toupperW( s[2] ) )
|
|
|
|
{
|
|
|
|
time->wDayOfWeek = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time->wDayOfWeek > 6) return TRUE;
|
|
|
|
while (*s && !isdigitW( *s )) s++;
|
|
|
|
time->wDay = strtolW( s, &end, 10 );
|
|
|
|
s = end;
|
|
|
|
|
|
|
|
while (*s && !isalphaW( *s )) s++;
|
|
|
|
if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
|
|
|
|
time->wMonth = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 12; i++)
|
|
|
|
{
|
|
|
|
if (toupperW( month[i][0]) == toupperW( s[0] ) &&
|
|
|
|
toupperW( month[i][1]) == toupperW( s[1] ) &&
|
|
|
|
toupperW( month[i][2]) == toupperW( s[2] ) )
|
|
|
|
{
|
|
|
|
time->wMonth = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (time->wMonth == 0) return TRUE;
|
|
|
|
|
|
|
|
while (*s && !isdigitW( *s )) s++;
|
|
|
|
if (*s == '\0') return TRUE;
|
|
|
|
time->wYear = strtolW( s, &end, 10 );
|
|
|
|
s = end;
|
|
|
|
|
|
|
|
while (*s && !isdigitW( *s )) s++;
|
|
|
|
if (*s == '\0') return TRUE;
|
|
|
|
time->wHour = strtolW( s, &end, 10 );
|
|
|
|
s = end;
|
|
|
|
|
|
|
|
while (*s && !isdigitW( *s )) s++;
|
|
|
|
if (*s == '\0') return TRUE;
|
|
|
|
time->wMinute = strtolW( s, &end, 10 );
|
|
|
|
s = end;
|
|
|
|
|
|
|
|
while (*s && !isdigitW( *s )) s++;
|
|
|
|
if (*s == '\0') return TRUE;
|
|
|
|
time->wSecond = strtolW( s, &end, 10 );
|
|
|
|
s = end;
|
|
|
|
|
|
|
|
time->wMilliseconds = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|