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 <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2013-03-15 10:39:00 +01:00
|
|
|
#include "winsock2.h"
|
|
|
|
#include "ws2ipdef.h"
|
2018-08-31 14:39:09 +02:00
|
|
|
#include "ws2tcpip.h"
|
2008-08-15 14:42:15 +02:00
|
|
|
#include "winhttp.h"
|
2009-07-14 21:53:14 +02:00
|
|
|
#include "winreg.h"
|
2019-03-29 16:34:17 +01:00
|
|
|
#include "winternl.h"
|
2019-11-20 14:29:06 +01:00
|
|
|
#include "iphlpapi.h"
|
|
|
|
#include "dhcpcsdk.h"
|
2011-11-18 10:36:04 +01:00
|
|
|
#define COBJMACROS
|
|
|
|
#include "ole2.h"
|
2011-11-21 12:33:51 +01:00
|
|
|
#include "dispex.h"
|
2011-11-18 10:36:04 +01:00
|
|
|
#include "activscp.h"
|
2008-08-15 14:42:15 +02:00
|
|
|
|
2018-08-27 14:36:38 +02:00
|
|
|
#include "wine/debug.h"
|
2008-08-15 14:42:15 +02:00
|
|
|
#include "winhttp_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
|
|
|
|
|
2018-09-10 13:24:34 +02:00
|
|
|
#define DEFAULT_RESOLVE_TIMEOUT 0
|
|
|
|
#define DEFAULT_CONNECT_TIMEOUT 20000
|
|
|
|
#define DEFAULT_SEND_TIMEOUT 30000
|
|
|
|
#define DEFAULT_RECEIVE_TIMEOUT 30000
|
|
|
|
#define DEFAULT_RECEIVE_RESPONSE_TIMEOUT ~0u
|
2009-07-21 22:52:22 +02:00
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
void send_callback( struct object_header *hdr, DWORD status, void *info, DWORD buflen )
|
2008-08-15 14:43:07 +02:00
|
|
|
{
|
2015-02-16 14:40:38 +01:00
|
|
|
if (hdr->callback && (hdr->notify_mask & status))
|
|
|
|
{
|
|
|
|
TRACE("%p, 0x%08x, %p, %u\n", hdr, status, info, buflen);
|
|
|
|
hdr->callback( hdr->handle, hdr->context, status, info, buflen );
|
|
|
|
TRACE("returning from 0x%08x callback\n", status);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static void session_destroy( struct object_header *hdr )
|
2008-08-15 14:42:15 +02:00
|
|
|
{
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session = (struct session *)hdr;
|
2008-08-15 14:42:15 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", session);
|
|
|
|
|
2015-07-22 10:02:01 +02:00
|
|
|
if (session->unload_event) SetEvent( session->unload_event );
|
2018-11-06 16:08:59 +01:00
|
|
|
destroy_cookies( session );
|
2015-07-22 10:02:01 +02:00
|
|
|
|
2018-10-05 14:59:10 +02:00
|
|
|
session->cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection( &session->cs );
|
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 );
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static BOOL session_query_option( struct object_header *hdr, DWORD option, void *buffer, DWORD *buflen )
|
2008-09-16 11:51:58 +02:00
|
|
|
{
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session = (struct session *)hdr;
|
2010-01-29 02:11:57 +01:00
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_REDIRECT_POLICY:
|
|
|
|
{
|
|
|
|
if (!buffer || *buflen < sizeof(DWORD))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(DWORD);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(DWORD *)buffer = hdr->redirect_policy;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-02-22 12:27:30 +01:00
|
|
|
case WINHTTP_OPTION_RESOLVE_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = session->resolve_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_CONNECT_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = session->connect_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_SEND_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = session->send_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_RECEIVE_TIMEOUT:
|
2018-09-10 13:24:34 +02:00
|
|
|
*(DWORD *)buffer = session->receive_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = session->receive_response_timeout;
|
2010-01-29 02:11:57 +01:00
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static BOOL session_set_option( struct object_header *hdr, DWORD option, void *buffer, DWORD buflen )
|
2008-09-03 16:58:06 +02:00
|
|
|
{
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session = (struct session *)hdr;
|
2010-01-29 02:11:57 +01:00
|
|
|
|
2008-09-03 16:58:06 +02:00
|
|
|
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))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( 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;
|
|
|
|
}
|
2017-09-12 09:59:06 +02:00
|
|
|
case WINHTTP_OPTION_SECURE_PROTOCOLS:
|
|
|
|
{
|
|
|
|
if (buflen != sizeof(session->secure_protocols))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2017-09-12 09:59:06 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-10-05 14:59:18 +02:00
|
|
|
EnterCriticalSection( &session->cs );
|
2017-09-12 09:59:06 +02:00
|
|
|
session->secure_protocols = *(DWORD *)buffer;
|
2018-10-05 14:59:18 +02:00
|
|
|
LeaveCriticalSection( &session->cs );
|
2017-09-12 09:59:06 +02:00
|
|
|
TRACE("0x%x\n", session->secure_protocols);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-16 11:51:58 +02:00
|
|
|
case WINHTTP_OPTION_DISABLE_FEATURE:
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-02-22 12:27:30 +01:00
|
|
|
case WINHTTP_OPTION_RESOLVE_TIMEOUT:
|
|
|
|
session->resolve_timeout = *(DWORD *)buffer;
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_CONNECT_TIMEOUT:
|
|
|
|
session->connect_timeout = *(DWORD *)buffer;
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_SEND_TIMEOUT:
|
|
|
|
session->send_timeout = *(DWORD *)buffer;
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_RECEIVE_TIMEOUT:
|
2018-09-10 13:24:34 +02:00
|
|
|
session->receive_timeout = *(DWORD *)buffer;
|
2010-01-29 02:11:57 +01:00
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
|
|
|
case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT:
|
|
|
|
session->receive_response_timeout = *(DWORD *)buffer;
|
|
|
|
return TRUE;
|
|
|
|
|
2012-11-04 23:01:08 +01:00
|
|
|
case WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH:
|
2019-08-02 11:01:37 +02:00
|
|
|
session->passport_flags = *(DWORD *)buffer;
|
2012-11-04 23:01:08 +01:00
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2015-07-22 10:02:01 +02:00
|
|
|
case WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT:
|
|
|
|
TRACE("WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT: %p\n", *(HANDLE *)buffer);
|
|
|
|
session->unload_event = *(HANDLE *)buffer;
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2016-09-07 18:57:30 +02:00
|
|
|
case WINHTTP_OPTION_MAX_CONNS_PER_SERVER:
|
|
|
|
FIXME("WINHTTP_OPTION_MAX_CONNS_PER_SERVER: %d\n", *(DWORD *)buffer);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2016-09-07 18:57:30 +02:00
|
|
|
case WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER:
|
|
|
|
FIXME("WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER: %d\n", *(DWORD *)buffer);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2008-09-03 16:58:06 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_INVALID_OPTION );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
2008-09-03 16:58:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static const struct object_vtbl session_vtbl =
|
2008-08-15 14:42:15 +02:00
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session;
|
2008-08-15 14:42:15 +02:00
|
|
|
HINTERNET handle = NULL;
|
|
|
|
|
|
|
|
TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags);
|
|
|
|
|
2018-11-22 21:15:51 +01:00
|
|
|
if (!(session = heap_alloc_zero( sizeof(struct session) ))) return NULL;
|
2008-08-15 14:42:15 +02:00
|
|
|
|
|
|
|
session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION;
|
|
|
|
session->hdr.vtbl = &session_vtbl;
|
|
|
|
session->hdr.flags = flags;
|
|
|
|
session->hdr.refs = 1;
|
2008-09-16 11:51:58 +02:00
|
|
|
session->hdr.redirect_policy = WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP;
|
2010-02-22 12:27:30 +01:00
|
|
|
session->resolve_timeout = DEFAULT_RESOLVE_TIMEOUT;
|
2010-01-29 01:45:15 +01:00
|
|
|
session->connect_timeout = DEFAULT_CONNECT_TIMEOUT;
|
|
|
|
session->send_timeout = DEFAULT_SEND_TIMEOUT;
|
2018-09-10 13:24:34 +02:00
|
|
|
session->receive_timeout = DEFAULT_RECEIVE_TIMEOUT;
|
|
|
|
session->receive_response_timeout = DEFAULT_RECEIVE_RESPONSE_TIMEOUT;
|
2008-09-16 12:31:35 +02:00
|
|
|
list_init( &session->cookie_cache );
|
2018-10-05 14:59:10 +02:00
|
|
|
InitializeCriticalSection( &session->cs );
|
|
|
|
session->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": session.cs");
|
2008-08-15 14:42:15 +02:00
|
|
|
|
|
|
|
if (agent && !(session->agent = strdupW( agent ))) goto end;
|
2009-07-14 22:01:48 +02:00
|
|
|
if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY)
|
|
|
|
{
|
|
|
|
WINHTTP_PROXY_INFO info;
|
|
|
|
|
|
|
|
WinHttpGetDefaultProxyConfiguration( &info );
|
|
|
|
session->access = info.dwAccessType;
|
|
|
|
if (info.lpszProxy && !(session->proxy_server = strdupW( info.lpszProxy )))
|
|
|
|
{
|
2012-07-19 10:22:59 +02:00
|
|
|
GlobalFree( info.lpszProxy );
|
|
|
|
GlobalFree( info.lpszProxyBypass );
|
2009-07-14 22:01:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (info.lpszProxyBypass && !(session->proxy_bypass = strdupW( info.lpszProxyBypass )))
|
|
|
|
{
|
2012-07-19 10:22:59 +02:00
|
|
|
GlobalFree( info.lpszProxy );
|
|
|
|
GlobalFree( info.lpszProxyBypass );
|
2009-07-14 22:01:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (access == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
|
|
|
|
{
|
|
|
|
session->access = access;
|
|
|
|
if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end;
|
|
|
|
if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end;
|
|
|
|
}
|
2008-08-15 14:42:15 +02:00
|
|
|
|
2020-06-22 21:39:21 +02:00
|
|
|
handle = alloc_handle( &session->hdr );
|
2008-08-15 14:42:15 +02:00
|
|
|
|
|
|
|
end:
|
|
|
|
release_object( &session->hdr );
|
|
|
|
TRACE("returning %p\n", handle);
|
2018-11-22 21:15:55 +01:00
|
|
|
if (handle) SetLastError( ERROR_SUCCESS );
|
2008-08-15 14:42:15 +02:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static void connect_destroy( struct object_header *hdr )
|
2008-08-15 14:42:28 +02:00
|
|
|
{
|
2018-11-22 21:15:52 +01:00
|
|
|
struct connect *connect = (struct connect *)hdr;
|
2008-08-15 14:42:28 +02:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static BOOL connect_query_option( struct object_header *hdr, DWORD option, void *buffer, DWORD *buflen )
|
2009-10-26 09:56:33 +01:00
|
|
|
{
|
2018-11-22 21:15:52 +01:00
|
|
|
struct connect *connect = (struct connect *)hdr;
|
2009-10-26 09:56:33 +01:00
|
|
|
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_PARENT_HANDLE:
|
|
|
|
{
|
|
|
|
if (!buffer || *buflen < sizeof(HINTERNET))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(HINTERNET);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2009-10-26 09:56:33 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
*(HINTERNET *)buffer = ((struct object_header *)connect->session)->handle;
|
2009-10-26 09:56:33 +01:00
|
|
|
*buflen = sizeof(HINTERNET);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-02-22 12:27:30 +01:00
|
|
|
case WINHTTP_OPTION_RESOLVE_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = connect->session->resolve_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_CONNECT_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = connect->session->connect_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_SEND_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = connect->session->send_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_RECEIVE_TIMEOUT:
|
2018-09-10 13:24:34 +02:00
|
|
|
*(DWORD *)buffer = connect->session->receive_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = connect->session->receive_response_timeout;
|
2010-01-29 02:11:57 +01:00
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2009-10-26 09:56:33 +01:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2009-10-26 09:56:33 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static const struct object_vtbl connect_vtbl =
|
2008-08-15 14:42:28 +02:00
|
|
|
{
|
|
|
|
connect_destroy,
|
2009-10-26 09:56:33 +01:00
|
|
|
connect_query_option,
|
2008-08-15 14:42:28 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-07-14 22:02:29 +02:00
|
|
|
static BOOL domain_matches(LPCWSTR server, LPCWSTR domain)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
if (!wcsicmp( domain, L"<local>" ) && !wcschr( server, '.' ))
|
2009-07-14 22:02:29 +02:00
|
|
|
ret = TRUE;
|
|
|
|
else if (*domain == '*')
|
|
|
|
{
|
|
|
|
if (domain[1] == '.')
|
|
|
|
{
|
|
|
|
LPCWSTR dot;
|
|
|
|
|
|
|
|
/* For a hostname to match a wildcard, the last domain must match
|
|
|
|
* the wildcard exactly. E.g. if the wildcard is *.a.b, and the
|
|
|
|
* hostname is www.foo.a.b, it matches, but a.b does not.
|
|
|
|
*/
|
2019-11-20 14:29:08 +01:00
|
|
|
dot = wcschr( server, '.' );
|
2009-07-14 22:02:29 +02:00
|
|
|
if (dot)
|
|
|
|
{
|
2019-11-20 14:29:08 +01:00
|
|
|
int len = lstrlenW( dot + 1 );
|
2009-07-14 22:02:29 +02:00
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
if (len > lstrlenW( domain + 2 ))
|
2009-07-14 22:02:29 +02:00
|
|
|
{
|
|
|
|
LPCWSTR ptr;
|
|
|
|
|
|
|
|
/* The server's domain is longer than the wildcard, so it
|
|
|
|
* could be a subdomain. Compare the last portion of the
|
|
|
|
* server's domain.
|
|
|
|
*/
|
2019-11-20 14:29:08 +01:00
|
|
|
ptr = dot + len + 1 - lstrlenW( domain + 2 );
|
|
|
|
if (!wcsicmp( ptr, domain + 2 ))
|
2009-07-14 22:02:29 +02:00
|
|
|
{
|
|
|
|
/* This is only a match if the preceding character is
|
|
|
|
* a '.', i.e. that it is a matching domain. E.g.
|
|
|
|
* if domain is '*.b.c' and server is 'www.ab.c' they
|
|
|
|
* do not match.
|
|
|
|
*/
|
|
|
|
ret = *(ptr - 1) == '.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2019-11-20 14:29:08 +01:00
|
|
|
ret = !wcsicmp( dot + 1, domain + 2 );
|
2009-07-14 22:02:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2019-11-20 14:29:08 +01:00
|
|
|
ret = !wcsicmp( server, domain );
|
2009-07-14 22:02:29 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-15 17:40:51 +02:00
|
|
|
/* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */
|
2009-07-14 22:02:29 +02:00
|
|
|
#define MAX_HOST_NAME_LENGTH 256
|
|
|
|
|
2018-11-22 21:15:51 +01:00
|
|
|
static BOOL should_bypass_proxy(struct session *session, LPCWSTR server)
|
2009-07-14 22:02:29 +02:00
|
|
|
{
|
|
|
|
LPCWSTR ptr;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2009-07-21 20:22:03 +02:00
|
|
|
if (!session->proxy_bypass) return FALSE;
|
2009-07-14 22:02:29 +02:00
|
|
|
ptr = session->proxy_bypass;
|
|
|
|
do {
|
|
|
|
LPCWSTR tmp = ptr;
|
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
ptr = wcschr( ptr, ';' );
|
2009-07-14 22:02:29 +02:00
|
|
|
if (!ptr)
|
2019-11-20 14:29:08 +01:00
|
|
|
ptr = wcschr( tmp, ' ' );
|
2009-07-14 22:02:29 +02:00
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
if (ptr - tmp < MAX_HOST_NAME_LENGTH)
|
|
|
|
{
|
|
|
|
WCHAR domain[MAX_HOST_NAME_LENGTH];
|
|
|
|
|
|
|
|
memcpy( domain, tmp, (ptr - tmp) * sizeof(WCHAR) );
|
|
|
|
domain[ptr - tmp] = 0;
|
|
|
|
ret = domain_matches( server, domain );
|
|
|
|
}
|
|
|
|
ptr += 1;
|
|
|
|
}
|
|
|
|
else if (*tmp)
|
|
|
|
ret = domain_matches( server, tmp );
|
|
|
|
} while (ptr && !ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-22 21:15:52 +01:00
|
|
|
BOOL set_server_for_hostname( struct connect *connect, const WCHAR *server, INTERNET_PORT port )
|
2009-07-14 22:03:26 +02:00
|
|
|
{
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session = connect->session;
|
2009-07-14 22:03:26 +02:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
if (session->proxy_server && !should_bypass_proxy(session, server))
|
|
|
|
{
|
|
|
|
LPCWSTR colon;
|
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
if ((colon = wcschr( session->proxy_server, ':' )))
|
2009-07-14 22:03:26 +02:00
|
|
|
{
|
2019-11-20 14:29:08 +01:00
|
|
|
if (!connect->servername || wcsnicmp( connect->servername,
|
2009-07-14 22:03:26 +02:00
|
|
|
session->proxy_server, colon - session->proxy_server - 1 ))
|
|
|
|
{
|
|
|
|
heap_free( connect->servername );
|
2011-11-25 14:55:13 +01:00
|
|
|
connect->resolved = FALSE;
|
2009-07-14 22:03:26 +02:00
|
|
|
if (!(connect->servername = heap_alloc(
|
|
|
|
(colon - session->proxy_server + 1) * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
memcpy( connect->servername, session->proxy_server,
|
|
|
|
(colon - session->proxy_server) * sizeof(WCHAR) );
|
|
|
|
connect->servername[colon - session->proxy_server] = 0;
|
|
|
|
if (*(colon + 1))
|
2019-11-20 14:29:08 +01:00
|
|
|
connect->serverport = wcstol( colon + 1, NULL, 10 );
|
2009-07-14 22:03:26 +02:00
|
|
|
else
|
2009-07-14 22:04:42 +02:00
|
|
|
connect->serverport = INTERNET_DEFAULT_PORT;
|
2009-07-14 22:03:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-20 14:29:08 +01:00
|
|
|
if (!connect->servername || wcsicmp( connect->servername,
|
2009-07-14 22:03:26 +02:00
|
|
|
session->proxy_server ))
|
|
|
|
{
|
|
|
|
heap_free( connect->servername );
|
2011-11-25 14:55:13 +01:00
|
|
|
connect->resolved = FALSE;
|
2009-07-14 22:03:26 +02:00
|
|
|
if (!(connect->servername = strdupW( session->proxy_server )))
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
2009-07-14 22:04:42 +02:00
|
|
|
connect->serverport = INTERNET_DEFAULT_PORT;
|
2009-07-14 22:03:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (server)
|
|
|
|
{
|
2009-10-21 13:18:18 +02:00
|
|
|
heap_free( connect->servername );
|
2011-11-25 14:55:13 +01:00
|
|
|
connect->resolved = FALSE;
|
2009-07-14 22:03:26 +02:00
|
|
|
if (!(connect->servername = strdupW( server )))
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
connect->serverport = port;
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:42:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpConnect (winhttp.@)
|
|
|
|
*/
|
|
|
|
HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved )
|
|
|
|
{
|
2018-11-22 21:15:52 +01:00
|
|
|
struct connect *connect;
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session;
|
2008-08-15 14:42:28 +02:00
|
|
|
HINTERNET hconnect = NULL;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %u, %x\n", hsession, debugstr_w(server), port, reserved);
|
|
|
|
|
|
|
|
if (!server)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2008-08-15 14:42:28 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-11-22 21:15:51 +01:00
|
|
|
if (!(session = (struct session *)grab_object( hsession )))
|
2008-08-15 14:42:28 +02:00
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
2008-08-15 14:42:28 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
|
|
|
|
{
|
|
|
|
release_object( &session->hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
|
2008-08-15 14:42:28 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-11-22 21:15:52 +01:00
|
|
|
if (!(connect = heap_alloc_zero( sizeof(struct connect) )))
|
2008-08-15 14:42:28 +02:00
|
|
|
{
|
|
|
|
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;
|
2012-10-22 10:24:50 +02:00
|
|
|
connect->hdr.redirect_policy = session->hdr.redirect_policy;
|
2008-08-15 14:42:28 +02:00
|
|
|
|
|
|
|
addref_object( &session->hdr );
|
|
|
|
connect->session = session;
|
|
|
|
|
2010-05-17 01:11:35 +02:00
|
|
|
if (!(connect->hostname = strdupW( server ))) goto end;
|
2008-12-11 13:56:52 +01:00
|
|
|
connect->hostport = port;
|
2011-09-05 11:46:51 +02:00
|
|
|
if (!set_server_for_hostname( connect, server, port )) goto end;
|
2008-08-15 14:42:28 +02:00
|
|
|
|
2020-06-22 21:39:21 +02:00
|
|
|
if ((hconnect = alloc_handle( &connect->hdr )))
|
|
|
|
{
|
|
|
|
send_callback( &session->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hconnect, sizeof(hconnect) );
|
|
|
|
}
|
2008-08-15 14:43:07 +02:00
|
|
|
|
2008-08-15 14:42:28 +02:00
|
|
|
end:
|
|
|
|
release_object( &connect->hdr );
|
2011-09-05 11:46:51 +02:00
|
|
|
release_object( &session->hdr );
|
2008-08-15 14:42:28 +02:00
|
|
|
TRACE("returning %p\n", hconnect);
|
2018-11-22 21:15:55 +01:00
|
|
|
if (hconnect) SetLastError( ERROR_SUCCESS );
|
2008-08-15 14:42:28 +02:00
|
|
|
return hconnect;
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static void request_destroy( struct object_header *hdr )
|
2008-08-15 14:42:41 +02:00
|
|
|
{
|
2018-11-22 21:15:54 +01:00
|
|
|
struct request *request = (struct request *)hdr;
|
2015-06-12 15:08:30 +02:00
|
|
|
unsigned int i, j;
|
2008-08-15 14:42:41 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", request);
|
|
|
|
|
2020-06-29 15:46:13 +02:00
|
|
|
stop_queue( &request->queue );
|
2008-08-15 14:42:41 +02:00
|
|
|
release_object( &request->connect->hdr );
|
|
|
|
|
2019-01-29 11:40:53 +01:00
|
|
|
if (request->cred_handle_initialized) FreeCredentialsHandle( &request->cred_handle );
|
2018-06-11 09:20:35 +02:00
|
|
|
CertFreeCertificateContext( request->server_cert );
|
2019-01-29 11:40:53 +01:00
|
|
|
CertFreeCertificateContext( request->client_cert );
|
2018-06-11 09:20:35 +02:00
|
|
|
|
2013-04-30 11:32:59 +02:00
|
|
|
destroy_authinfo( request->authinfo );
|
|
|
|
destroy_authinfo( request->proxy_authinfo );
|
|
|
|
|
2008-08-15 14:42:41 +02:00
|
|
|
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 );
|
2015-06-12 15:08:30 +02:00
|
|
|
for (i = 0; i < TARGET_MAX; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < SCHEME_MAX; j++)
|
|
|
|
{
|
|
|
|
heap_free( request->creds[i][j].username );
|
|
|
|
heap_free( request->creds[i][j].password );
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 21:39:22 +02:00
|
|
|
|
2008-08-15 14:42:41 +02:00
|
|
|
heap_free( request );
|
|
|
|
}
|
|
|
|
|
2010-04-22 16:34:48 +02:00
|
|
|
static void str_to_buffer( WCHAR *buffer, const WCHAR *str, LPDWORD buflen )
|
|
|
|
{
|
|
|
|
int len = 0;
|
2019-11-20 14:29:08 +01:00
|
|
|
if (str) len = lstrlenW( str );
|
2010-04-22 16:34:48 +02:00
|
|
|
if (buffer && *buflen > len)
|
|
|
|
{
|
2011-12-09 09:01:23 +01:00
|
|
|
if (str) memcpy( buffer, str, len * sizeof(WCHAR) );
|
2010-04-22 16:34:48 +02:00
|
|
|
buffer[len] = 0;
|
|
|
|
}
|
|
|
|
*buflen = len * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
2010-07-20 14:49:52 +02:00
|
|
|
static WCHAR *blob_to_str( DWORD encoding, CERT_NAME_BLOB *blob )
|
|
|
|
{
|
|
|
|
WCHAR *ret;
|
|
|
|
DWORD size, format = CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG;
|
|
|
|
|
|
|
|
size = CertNameToStrW( encoding, blob, format, NULL, 0 );
|
|
|
|
if ((ret = LocalAlloc( 0, size * sizeof(WCHAR) )))
|
|
|
|
CertNameToStrW( encoding, blob, format, ret, size );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-27 14:36:38 +02:00
|
|
|
static BOOL copy_sockaddr( const struct sockaddr *addr, SOCKADDR_STORAGE *addr_storage )
|
2013-03-15 10:39:00 +01:00
|
|
|
{
|
|
|
|
switch (addr->sa_family)
|
|
|
|
{
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *addr_in = (struct sockaddr_in *)addr_storage;
|
|
|
|
|
|
|
|
memcpy( addr_in, addr, sizeof(*addr_in) );
|
|
|
|
memset( addr_in + 1, 0, sizeof(*addr_storage) - sizeof(*addr_in) );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr_storage;
|
|
|
|
|
|
|
|
memcpy( addr_in6, addr, sizeof(*addr_in6) );
|
|
|
|
memset( addr_in6 + 1, 0, sizeof(*addr_storage) - sizeof(*addr_in6) );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ERR("unhandled family %u\n", addr->sa_family);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static BOOL request_query_option( struct object_header *hdr, DWORD option, void *buffer, DWORD *buflen )
|
2008-09-05 14:10:57 +02:00
|
|
|
{
|
2018-11-22 21:15:54 +01:00
|
|
|
struct request *request = (struct request *)hdr;
|
2010-01-29 02:11:57 +01:00
|
|
|
|
2008-09-05 14:10:57 +02:00
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case WINHTTP_OPTION_SECURITY_FLAGS:
|
|
|
|
{
|
2018-12-17 12:26:35 +01:00
|
|
|
DWORD flags;
|
2010-09-29 19:36:00 +02:00
|
|
|
int bits;
|
2008-09-05 14:10:57 +02:00
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
if (!buffer || *buflen < sizeof(flags))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(flags);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-12-17 12:26:35 +01:00
|
|
|
flags = request->security_flags;
|
2017-07-13 13:01:03 +02:00
|
|
|
if (request->netconn)
|
|
|
|
{
|
|
|
|
bits = netconn_get_cipher_strength( request->netconn );
|
|
|
|
if (bits >= 128)
|
|
|
|
flags |= SECURITY_FLAG_STRENGTH_STRONG;
|
|
|
|
else if (bits >= 56)
|
|
|
|
flags |= SECURITY_FLAG_STRENGTH_MEDIUM;
|
|
|
|
else
|
|
|
|
flags |= SECURITY_FLAG_STRENGTH_WEAK;
|
|
|
|
}
|
2008-09-05 14:10:57 +02:00
|
|
|
*(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;
|
|
|
|
|
2008-09-16 11:51:58 +02:00
|
|
|
if (!buffer || *buflen < sizeof(cert))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(cert);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-06-11 09:20:35 +02:00
|
|
|
if (!(cert = CertDuplicateCertificateContext( request->server_cert ))) 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;
|
|
|
|
}
|
2010-07-20 14:49:52 +02:00
|
|
|
case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT:
|
|
|
|
{
|
2018-06-11 09:20:35 +02:00
|
|
|
const CERT_CONTEXT *cert = request->server_cert;
|
2010-09-29 18:34:04 +02:00
|
|
|
const CRYPT_OID_INFO *oidInfo;
|
2010-07-20 14:49:52 +02:00
|
|
|
WINHTTP_CERTIFICATE_INFO *ci = buffer;
|
|
|
|
|
|
|
|
FIXME("partial stub\n");
|
|
|
|
|
|
|
|
if (!buffer || *buflen < sizeof(*ci))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(*ci);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2010-07-20 14:49:52 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2018-06-11 09:20:35 +02:00
|
|
|
if (!cert) return FALSE;
|
2010-07-20 14:49:52 +02:00
|
|
|
|
|
|
|
ci->ftExpiry = cert->pCertInfo->NotAfter;
|
|
|
|
ci->ftStart = cert->pCertInfo->NotBefore;
|
|
|
|
ci->lpszSubjectInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Subject );
|
|
|
|
ci->lpszIssuerInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Issuer );
|
|
|
|
ci->lpszProtocolName = NULL;
|
2018-06-11 09:20:35 +02:00
|
|
|
oidInfo = CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY, cert->pCertInfo->SignatureAlgorithm.pszObjId, 0 );
|
2010-09-29 18:34:04 +02:00
|
|
|
if (oidInfo)
|
|
|
|
ci->lpszSignatureAlgName = (LPWSTR)oidInfo->pwszName;
|
|
|
|
else
|
|
|
|
ci->lpszSignatureAlgName = NULL;
|
2010-07-20 14:49:52 +02:00
|
|
|
ci->lpszEncryptionAlgName = NULL;
|
2017-07-13 13:01:03 +02:00
|
|
|
ci->dwKeySize = request->netconn ? netconn_get_cipher_strength( request->netconn ) : 0;
|
2010-07-20 14:49:52 +02:00
|
|
|
|
|
|
|
*buflen = sizeof(*ci);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-09-07 21:30:31 +02:00
|
|
|
case WINHTTP_OPTION_SECURITY_KEY_BITNESS:
|
|
|
|
{
|
2008-09-16 11:51:58 +02:00
|
|
|
if (!buffer || *buflen < sizeof(DWORD))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(DWORD);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-16 11:51:58 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-07-13 13:01:03 +02:00
|
|
|
*(DWORD *)buffer = request->netconn ? netconn_get_cipher_strength( request->netconn ) : 0;
|
2008-09-07 21:30:31 +02:00
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2013-03-15 10:39:00 +01:00
|
|
|
case WINHTTP_OPTION_CONNECTION_INFO:
|
|
|
|
{
|
|
|
|
WINHTTP_CONNECTION_INFO *info = buffer;
|
|
|
|
struct sockaddr local;
|
|
|
|
socklen_t len = sizeof(local);
|
|
|
|
const struct sockaddr *remote = (const struct sockaddr *)&request->connect->sockaddr;
|
|
|
|
|
|
|
|
if (!buffer || *buflen < sizeof(*info))
|
|
|
|
{
|
|
|
|
*buflen = sizeof(*info);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2013-03-15 10:39:00 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-07-13 13:01:03 +02:00
|
|
|
if (!request->netconn)
|
2013-03-15 10:39:00 +01:00
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_STATE );
|
2013-03-15 10:39:00 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-07-13 13:01:03 +02:00
|
|
|
if (getsockname( request->netconn->socket, &local, &len )) return FALSE;
|
2018-08-27 14:36:38 +02:00
|
|
|
if (!copy_sockaddr( &local, &info->LocalAddress )) return FALSE;
|
|
|
|
if (!copy_sockaddr( remote, &info->RemoteAddress )) return FALSE;
|
2013-03-15 10:39:00 +01:00
|
|
|
info->cbSize = sizeof(*info);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-02-22 12:27:30 +01:00
|
|
|
case WINHTTP_OPTION_RESOLVE_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = request->resolve_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_CONNECT_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = request->connect_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_SEND_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = request->send_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_RECEIVE_TIMEOUT:
|
2018-09-10 13:24:34 +02:00
|
|
|
*(DWORD *)buffer = request->receive_timeout;
|
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT:
|
|
|
|
*(DWORD *)buffer = request->receive_response_timeout;
|
2010-01-29 02:11:57 +01:00
|
|
|
*buflen = sizeof(DWORD);
|
|
|
|
return TRUE;
|
2010-04-22 16:34:48 +02:00
|
|
|
|
|
|
|
case WINHTTP_OPTION_USERNAME:
|
|
|
|
str_to_buffer( buffer, request->connect->username, buflen );
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINHTTP_OPTION_PASSWORD:
|
|
|
|
str_to_buffer( buffer, request->connect->password, buflen );
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINHTTP_OPTION_PROXY_USERNAME:
|
|
|
|
str_to_buffer( buffer, request->connect->session->proxy_username, buflen );
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINHTTP_OPTION_PROXY_PASSWORD:
|
|
|
|
str_to_buffer( buffer, request->connect->session->proxy_password, buflen );
|
|
|
|
return TRUE;
|
|
|
|
|
2008-09-05 14:10:57 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2008-09-05 14:10:57 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-22 16:34:48 +02:00
|
|
|
static WCHAR *buffer_to_str( WCHAR *buffer, DWORD buflen )
|
|
|
|
{
|
|
|
|
WCHAR *ret;
|
|
|
|
if ((ret = heap_alloc( (buflen + 1) * sizeof(WCHAR))))
|
|
|
|
{
|
|
|
|
memcpy( ret, buffer, buflen * sizeof(WCHAR) );
|
|
|
|
ret[buflen] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_OUTOFMEMORY );
|
2010-04-22 16:34:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static BOOL request_set_option( struct object_header *hdr, DWORD option, void *buffer, DWORD buflen )
|
2008-09-03 16:58:06 +02:00
|
|
|
{
|
2018-11-22 21:15:54 +01:00
|
|
|
struct request *request = (struct request *)hdr;
|
2010-01-29 02:11:57 +01:00
|
|
|
|
2008-09-03 16:58:06 +02:00
|
|
|
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))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( 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))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( 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))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( 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;
|
|
|
|
}
|
2009-09-02 17:26:20 +02:00
|
|
|
case WINHTTP_OPTION_SECURITY_FLAGS:
|
2010-05-14 15:36:39 +02:00
|
|
|
{
|
|
|
|
DWORD flags;
|
2018-12-17 12:26:35 +01:00
|
|
|
static const DWORD accepted = SECURITY_FLAG_IGNORE_CERT_CN_INVALID |
|
|
|
|
SECURITY_FLAG_IGNORE_CERT_DATE_INVALID |
|
|
|
|
SECURITY_FLAG_IGNORE_UNKNOWN_CA |
|
|
|
|
SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE;
|
2010-05-14 15:36:39 +02:00
|
|
|
|
|
|
|
if (buflen < sizeof(DWORD))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2010-05-14 15:36:39 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
flags = *(DWORD *)buffer;
|
|
|
|
TRACE("0x%x\n", flags);
|
2018-12-17 12:26:35 +01:00
|
|
|
if (flags && (flags & ~accepted))
|
2010-05-14 15:36:39 +02:00
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2010-05-14 15:36:39 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2017-07-13 13:00:26 +02:00
|
|
|
request->security_flags = flags;
|
2009-09-02 17:26:20 +02:00
|
|
|
return TRUE;
|
2010-05-14 15:36:39 +02:00
|
|
|
}
|
2010-02-22 12:27:30 +01:00
|
|
|
case WINHTTP_OPTION_RESOLVE_TIMEOUT:
|
|
|
|
request->resolve_timeout = *(DWORD *)buffer;
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_CONNECT_TIMEOUT:
|
|
|
|
request->connect_timeout = *(DWORD *)buffer;
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_SEND_TIMEOUT:
|
|
|
|
request->send_timeout = *(DWORD *)buffer;
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2010-01-29 02:11:57 +01:00
|
|
|
case WINHTTP_OPTION_RECEIVE_TIMEOUT:
|
2018-09-10 13:24:34 +02:00
|
|
|
request->receive_timeout = *(DWORD *)buffer;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT:
|
|
|
|
request->receive_response_timeout = *(DWORD *)buffer;
|
2010-01-29 02:11:57 +01:00
|
|
|
return TRUE;
|
2010-04-22 16:34:48 +02:00
|
|
|
|
|
|
|
case WINHTTP_OPTION_USERNAME:
|
|
|
|
{
|
2018-11-22 21:15:52 +01:00
|
|
|
struct connect *connect = request->connect;
|
2010-04-22 16:34:48 +02:00
|
|
|
|
|
|
|
heap_free( connect->username );
|
|
|
|
if (!(connect->username = buffer_to_str( buffer, buflen ))) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WINHTTP_OPTION_PASSWORD:
|
|
|
|
{
|
2018-11-22 21:15:52 +01:00
|
|
|
struct connect *connect = request->connect;
|
2010-04-22 16:34:48 +02:00
|
|
|
|
|
|
|
heap_free( connect->password );
|
|
|
|
if (!(connect->password = buffer_to_str( buffer, buflen ))) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WINHTTP_OPTION_PROXY_USERNAME:
|
|
|
|
{
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session = request->connect->session;
|
2010-04-22 16:34:48 +02:00
|
|
|
|
|
|
|
heap_free( session->proxy_username );
|
|
|
|
if (!(session->proxy_username = buffer_to_str( buffer, buflen ))) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WINHTTP_OPTION_PROXY_PASSWORD:
|
|
|
|
{
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session = request->connect->session;
|
2010-04-22 16:34:48 +02:00
|
|
|
|
|
|
|
heap_free( session->proxy_password );
|
|
|
|
if (!(session->proxy_password = buffer_to_str( buffer, buflen ))) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-10-06 14:05:32 +02:00
|
|
|
case WINHTTP_OPTION_CLIENT_CERT_CONTEXT:
|
2019-01-29 11:40:53 +01:00
|
|
|
{
|
|
|
|
const CERT_CONTEXT *cert;
|
|
|
|
|
2016-10-06 14:05:32 +02:00
|
|
|
if (!(hdr->flags & WINHTTP_FLAG_SECURE))
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_STATE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-01-29 11:40:53 +01:00
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
CertFreeCertificateContext( request->client_cert );
|
|
|
|
request->client_cert = NULL;
|
|
|
|
}
|
|
|
|
else if (buflen >= sizeof(cert))
|
|
|
|
{
|
|
|
|
if (!(cert = CertDuplicateCertificateContext( buffer ))) return FALSE;
|
|
|
|
CertFreeCertificateContext( request->client_cert );
|
|
|
|
request->client_cert = cert;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2019-01-29 11:40:53 +01:00
|
|
|
if (request->cred_handle_initialized)
|
|
|
|
{
|
|
|
|
FreeCredentialsHandle( &request->cred_handle );
|
|
|
|
request->cred_handle_initialized = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2018-08-24 10:32:49 +02:00
|
|
|
case WINHTTP_OPTION_ENABLE_FEATURE:
|
|
|
|
if(buflen == sizeof( DWORD ) && *(DWORD *)buffer == WINHTTP_ENABLE_SSL_REVOCATION)
|
|
|
|
{
|
|
|
|
request->check_revocation = TRUE;
|
|
|
|
SetLastError( NO_ERROR );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2020-06-17 11:53:41 +02:00
|
|
|
case WINHTTP_OPTION_UPGRADE_TO_WEB_SOCKET:
|
|
|
|
request->flags |= REQUEST_FLAG_WEBSOCKET_UPGRADE;
|
|
|
|
return TRUE;
|
|
|
|
|
2018-09-04 15:43:59 +02:00
|
|
|
case WINHTTP_OPTION_CONNECT_RETRIES:
|
|
|
|
FIXME("WINHTTP_OPTION_CONNECT_RETRIES\n");
|
|
|
|
return TRUE;
|
2018-09-10 13:24:34 +02:00
|
|
|
|
2008-09-03 16:58:06 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented option %u\n", option);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_INVALID_OPTION );
|
2018-05-03 13:30:21 +02:00
|
|
|
return FALSE;
|
2008-09-03 16:58:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static const struct object_vtbl request_vtbl =
|
2008-08-15 14:42:41 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2018-11-26 12:08:57 +01:00
|
|
|
static BOOL add_accept_types_header( struct request *request, const WCHAR **types )
|
2011-07-26 09:26:07 +02:00
|
|
|
{
|
2018-11-26 12:08:57 +01:00
|
|
|
static const DWORD flags = WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA;
|
2011-07-26 09:26:07 +02:00
|
|
|
|
|
|
|
if (!types) return TRUE;
|
|
|
|
while (*types)
|
|
|
|
{
|
2020-04-07 10:22:04 +02:00
|
|
|
if (process_header( request, L"Accept", *types, flags, TRUE )) return FALSE;
|
2011-07-26 09:26:07 +02:00
|
|
|
types++;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-06 16:09:04 +01:00
|
|
|
static WCHAR *get_request_path( const WCHAR *object )
|
2018-10-04 10:32:01 +02:00
|
|
|
{
|
2019-11-20 14:29:08 +01:00
|
|
|
int len = object ? lstrlenW(object) : 0;
|
2018-11-06 16:09:04 +01:00
|
|
|
WCHAR *p, *ret;
|
|
|
|
|
|
|
|
if (!object || object[0] != '/') len++;
|
|
|
|
if (!(p = ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
|
|
|
|
if (!object || object[0] != '/') *p++ = '/';
|
2019-11-20 14:29:08 +01:00
|
|
|
if (object) lstrcpyW( p, object );
|
2018-11-06 16:09:04 +01:00
|
|
|
ret[len] = 0;
|
2018-10-04 10:32:01 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
2018-11-22 21:15:54 +01:00
|
|
|
struct request *request;
|
2018-11-22 21:15:52 +01:00
|
|
|
struct connect *connect;
|
2008-08-15 14:42:41 +02:00
|
|
|
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);
|
|
|
|
|
2018-10-04 10:32:01 +02:00
|
|
|
if (types && TRACE_ON(winhttp))
|
|
|
|
{
|
2012-04-23 14:50:15 +02:00
|
|
|
const WCHAR **iter;
|
|
|
|
TRACE("accept types:\n");
|
2018-10-04 10:32:01 +02:00
|
|
|
for (iter = types; *iter; iter++) TRACE(" %s\n", debugstr_w(*iter));
|
2012-04-23 14:50:15 +02:00
|
|
|
}
|
|
|
|
|
2018-11-22 21:15:52 +01:00
|
|
|
if (!(connect = (struct connect *)grab_object( hconnect )))
|
2008-08-15 14:42:41 +02:00
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
2008-08-15 14:42:41 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (connect->hdr.type != WINHTTP_HANDLE_TYPE_CONNECT)
|
|
|
|
{
|
|
|
|
release_object( &connect->hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
|
2008-08-15 14:42:41 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-11-22 21:15:54 +01:00
|
|
|
if (!(request = heap_alloc_zero( sizeof(struct request) )))
|
2008-08-15 14:42:41 +02:00
|
|
|
{
|
|
|
|
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;
|
2012-10-22 10:24:50 +02:00
|
|
|
request->hdr.redirect_policy = connect->hdr.redirect_policy;
|
2008-08-15 14:42:41 +02:00
|
|
|
|
|
|
|
addref_object( &connect->hdr );
|
|
|
|
request->connect = connect;
|
|
|
|
|
2010-02-22 12:27:30 +01:00
|
|
|
request->resolve_timeout = connect->session->resolve_timeout;
|
2010-01-29 01:45:15 +01:00
|
|
|
request->connect_timeout = connect->session->connect_timeout;
|
|
|
|
request->send_timeout = connect->session->send_timeout;
|
2018-09-10 13:24:34 +02:00
|
|
|
request->receive_timeout = connect->session->receive_timeout;
|
|
|
|
request->receive_response_timeout = connect->session->receive_response_timeout;
|
2008-08-26 11:03:40 +02:00
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
if (!verb || !verb[0]) verb = L"GET";
|
2008-09-16 12:31:16 +02:00
|
|
|
if (!(request->verb = strdupW( verb ))) goto end;
|
2018-11-06 16:09:04 +01:00
|
|
|
if (!(request->path = get_request_path( object ))) goto end;
|
2008-12-08 12:35:43 +01:00
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
if (!version || !version[0]) version = L"HTTP/1.1";
|
2008-09-16 12:31:16 +02:00
|
|
|
if (!(request->version = strdupW( version ))) goto end;
|
2018-11-26 12:08:57 +01:00
|
|
|
if (!(add_accept_types_header( request, types ))) goto end;
|
2008-08-15 14:42:41 +02:00
|
|
|
|
2020-06-22 21:39:21 +02:00
|
|
|
if ((hrequest = alloc_handle( &request->hdr )))
|
|
|
|
{
|
|
|
|
send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, &hrequest, sizeof(hrequest) );
|
|
|
|
}
|
2008-08-15 14:43:07 +02:00
|
|
|
|
2008-08-15 14:42:41 +02:00
|
|
|
end:
|
|
|
|
release_object( &request->hdr );
|
2011-09-05 11:46:51 +02:00
|
|
|
release_object( &connect->hdr );
|
2008-08-15 14:42:41 +02:00
|
|
|
TRACE("returning %p\n", hrequest);
|
2018-11-22 21:15:55 +01:00
|
|
|
if (hrequest) SetLastError( ERROR_SUCCESS );
|
2008-08-15 14:42:41 +02:00
|
|
|
return hrequest;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:42:15 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpCloseHandle (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
|
|
|
|
{
|
2018-11-15 12:38:50 +01:00
|
|
|
struct object_header *hdr;
|
2008-08-15 14:42:15 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", handle);
|
|
|
|
|
|
|
|
if (!(hdr = grab_object( handle )))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
2008-08-15 14:42:15 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
release_object( hdr );
|
|
|
|
free_handle( handle );
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_SUCCESS );
|
2008-08-15 14:42:15 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-08-15 14:43:07 +02:00
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static BOOL query_option( struct object_header *hdr, DWORD option, void *buffer, DWORD *buflen )
|
2008-09-03 12:31:24 +02:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2008-09-17 04:41:26 +02:00
|
|
|
if (!buflen)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2008-09-17 04:41:26 +02:00
|
|
|
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);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-17 04:41:26 +02:00
|
|
|
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);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( 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;
|
2018-11-15 12:38:50 +01:00
|
|
|
struct object_header *hdr;
|
2008-09-03 12:31:24 +02:00
|
|
|
|
|
|
|
TRACE("%p, %u, %p, %p\n", handle, option, buffer, buflen);
|
|
|
|
|
|
|
|
if (!(hdr = grab_object( handle )))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
2008-09-03 12:31:24 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = query_option( hdr, option, buffer, buflen );
|
|
|
|
|
|
|
|
release_object( hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
if (ret) SetLastError( ERROR_SUCCESS );
|
2008-09-03 12:31:24 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-15 12:38:50 +01:00
|
|
|
static BOOL set_option( struct object_header *hdr, DWORD option, void *buffer, DWORD buflen )
|
2008-09-03 12:31:24 +02:00
|
|
|
{
|
2008-09-03 16:58:06 +02:00
|
|
|
BOOL ret = TRUE;
|
2008-09-03 12:31:24 +02:00
|
|
|
|
2016-10-06 14:05:32 +02:00
|
|
|
if (!buffer && buflen)
|
2008-09-17 04:41:26 +02:00
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2008-09-17 04:41:26 +02:00
|
|
|
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))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INSUFFICIENT_BUFFER );
|
2008-09-17 04:41:26 +02:00
|
|
|
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);
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( 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;
|
2018-11-15 12:38:50 +01:00
|
|
|
struct object_header *hdr;
|
2008-09-03 12:31:24 +02:00
|
|
|
|
|
|
|
TRACE("%p, %u, %p, %u\n", handle, option, buffer, buflen);
|
|
|
|
|
|
|
|
if (!(hdr = grab_object( handle )))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
2008-09-03 12:31:24 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = set_option( hdr, option, buffer, buflen );
|
|
|
|
|
|
|
|
release_object( hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
if (ret) SetLastError( ERROR_SUCCESS );
|
2008-09-03 12:31:24 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-11-20 14:29:06 +01:00
|
|
|
static IP_ADAPTER_ADDRESSES *get_adapters(void)
|
|
|
|
{
|
|
|
|
ULONG err, size = 1024, flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
|
|
|
|
GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME;
|
|
|
|
IP_ADAPTER_ADDRESSES *tmp, *ret;
|
|
|
|
|
|
|
|
if (!(ret = heap_alloc( size ))) return NULL;
|
|
|
|
err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
|
|
|
|
while (err == ERROR_BUFFER_OVERFLOW)
|
|
|
|
{
|
|
|
|
if (!(tmp = heap_realloc( ret, size ))) break;
|
|
|
|
ret = tmp;
|
|
|
|
err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
|
|
|
|
}
|
|
|
|
if (err == ERROR_SUCCESS) return ret;
|
|
|
|
heap_free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR *detect_autoproxyconfig_url_dhcp(void)
|
|
|
|
{
|
|
|
|
IP_ADAPTER_ADDRESSES *adapters, *ptr;
|
|
|
|
DHCPCAPI_PARAMS_ARRAY send_params, recv_params;
|
|
|
|
DHCPCAPI_PARAMS param;
|
|
|
|
WCHAR name[MAX_ADAPTER_NAME_LENGTH + 1], *ret = NULL;
|
|
|
|
DWORD err, size;
|
|
|
|
BYTE *tmp, *buf = NULL;
|
|
|
|
|
|
|
|
if (!(adapters = get_adapters())) return NULL;
|
|
|
|
|
|
|
|
memset( &send_params, 0, sizeof(send_params) );
|
|
|
|
memset( ¶m, 0, sizeof(param) );
|
|
|
|
param.OptionId = OPTION_MSFT_IE_PROXY;
|
|
|
|
recv_params.nParams = 1;
|
|
|
|
recv_params.Params = ¶m;
|
|
|
|
|
|
|
|
for (ptr = adapters; ptr; ptr = ptr->Next)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, ptr->AdapterName, -1, name, ARRAY_SIZE(name) );
|
|
|
|
TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name), ptr->IfType, ptr->Dhcpv4Enabled );
|
|
|
|
|
|
|
|
if (ptr->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
|
|
|
|
/* FIXME: also skip adapters where DHCP is disabled */
|
|
|
|
|
|
|
|
size = 256;
|
|
|
|
if (!(buf = heap_alloc( size ))) goto done;
|
|
|
|
err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
|
|
|
|
buf, &size, NULL );
|
|
|
|
while (err == ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
if (!(tmp = heap_realloc( buf, size ))) goto done;
|
|
|
|
buf = tmp;
|
|
|
|
err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
|
|
|
|
buf, &size, NULL );
|
|
|
|
}
|
|
|
|
if (err == ERROR_SUCCESS && param.nBytesData)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, NULL, 0 );
|
|
|
|
if ((ret = heap_alloc( (len + 1) * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, ret, len );
|
|
|
|
ret[len] = 0;
|
|
|
|
}
|
|
|
|
TRACE("returning %s\n", debugstr_w(ret));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
heap_free( buf );
|
|
|
|
heap_free( adapters );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-15 09:11:05 +01:00
|
|
|
static char *get_computer_name( COMPUTER_NAME_FORMAT format )
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
DWORD size = 0;
|
|
|
|
|
|
|
|
GetComputerNameExA( format, NULL, &size );
|
|
|
|
if (GetLastError() != ERROR_MORE_DATA) return NULL;
|
|
|
|
if (!(ret = heap_alloc( size ))) return NULL;
|
|
|
|
if (!GetComputerNameExA( format, ret, &size ))
|
|
|
|
{
|
|
|
|
heap_free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL is_domain_suffix( const char *domain, const char *suffix )
|
|
|
|
{
|
|
|
|
int len_domain = strlen( domain ), len_suffix = strlen( suffix );
|
|
|
|
|
|
|
|
if (len_suffix > len_domain) return FALSE;
|
2020-03-27 11:33:54 +01:00
|
|
|
if (!stricmp( domain + len_domain - len_suffix, suffix )) return TRUE;
|
2011-11-15 09:11:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-18 11:23:20 +01:00
|
|
|
static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len )
|
2011-11-15 09:11:05 +01:00
|
|
|
{
|
2018-08-27 14:36:38 +02:00
|
|
|
return getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 );
|
2012-12-18 11:23:20 +01:00
|
|
|
}
|
2011-11-15 09:11:05 +01:00
|
|
|
|
2012-12-18 11:23:20 +01:00
|
|
|
static WCHAR *build_wpad_url( const char *hostname, const struct addrinfo *ai )
|
|
|
|
{
|
|
|
|
char name[NI_MAXHOST];
|
|
|
|
WCHAR *ret, *p;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
while (ai && ai->ai_family != AF_INET && ai->ai_family != AF_INET6) ai = ai->ai_next;
|
2011-11-15 09:11:05 +01:00
|
|
|
if (!ai) return NULL;
|
|
|
|
|
2012-12-18 11:23:20 +01:00
|
|
|
if (!reverse_lookup( ai, name, sizeof(name) )) hostname = name;
|
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
len = lstrlenW( L"http://" ) + strlen( hostname ) + lstrlenW( L"/wpad.dat" );
|
2012-12-18 11:23:20 +01:00
|
|
|
if (!(ret = p = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
|
2019-11-22 16:32:24 +01:00
|
|
|
lstrcpyW( p, L"http://" );
|
|
|
|
p += lstrlenW( L"http://" );
|
2012-12-18 11:23:20 +01:00
|
|
|
while (*hostname) { *p++ = *hostname++; }
|
2019-11-22 16:32:24 +01:00
|
|
|
lstrcpyW( p, L"/wpad.dat" );
|
2011-11-15 09:11:05 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-11-20 14:29:06 +01:00
|
|
|
static WCHAR *detect_autoproxyconfig_url_dns(void)
|
2014-05-15 14:06:02 +02:00
|
|
|
{
|
2019-11-20 14:29:06 +01:00
|
|
|
char *fqdn, *domain, *p;
|
2019-12-24 10:18:07 +01:00
|
|
|
WCHAR *ret = NULL;
|
2014-05-15 14:06:02 +02:00
|
|
|
|
2019-11-20 14:29:06 +01:00
|
|
|
if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return NULL;
|
|
|
|
if (!(domain = get_computer_name( ComputerNamePhysicalDnsDomain )))
|
2014-05-15 14:06:02 +02:00
|
|
|
{
|
2019-11-20 14:29:06 +01:00
|
|
|
heap_free( fqdn );
|
|
|
|
return NULL;
|
2014-05-15 14:06:02 +02:00
|
|
|
}
|
2019-11-20 14:29:06 +01:00
|
|
|
p = fqdn;
|
|
|
|
while ((p = strchr( p, '.' )) && is_domain_suffix( p + 1, domain ))
|
2014-05-15 14:06:02 +02:00
|
|
|
{
|
2019-11-20 14:29:06 +01:00
|
|
|
char *name;
|
|
|
|
struct addrinfo *ai;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (!(name = heap_alloc( sizeof("wpad") + strlen(p) )))
|
|
|
|
{
|
|
|
|
heap_free( fqdn );
|
|
|
|
heap_free( domain );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
strcpy( name, "wpad" );
|
|
|
|
strcat( name, p );
|
|
|
|
res = getaddrinfo( name, NULL, NULL, &ai );
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
ret = build_wpad_url( name, ai );
|
|
|
|
freeaddrinfo( ai );
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
TRACE("returning %s\n", debugstr_w(ret));
|
|
|
|
heap_free( name );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap_free( name );
|
|
|
|
p++;
|
2014-05-15 14:06:02 +02:00
|
|
|
}
|
2019-11-20 14:29:06 +01:00
|
|
|
heap_free( domain );
|
|
|
|
heap_free( fqdn );
|
2014-05-15 14:06:02 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:43:23 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpDetectAutoProxyConfigUrl (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
|
|
|
|
{
|
2011-11-15 09:11:05 +01:00
|
|
|
TRACE("0x%08x, %p\n", flags, url);
|
|
|
|
|
|
|
|
if (!flags || !url)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2011-11-15 09:11:05 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2019-11-20 14:29:06 +01:00
|
|
|
*url = NULL;
|
2012-06-30 23:41:54 +02:00
|
|
|
if (flags & WINHTTP_AUTO_DETECT_TYPE_DHCP)
|
|
|
|
{
|
2019-11-20 14:29:06 +01:00
|
|
|
*url = detect_autoproxyconfig_url_dhcp();
|
2012-06-30 23:41:54 +02:00
|
|
|
}
|
2011-11-15 09:11:05 +01:00
|
|
|
if (flags & WINHTTP_AUTO_DETECT_TYPE_DNS_A)
|
|
|
|
{
|
2019-11-20 14:29:06 +01:00
|
|
|
if (!*url) *url = detect_autoproxyconfig_url_dns();
|
2011-11-15 09:11:05 +01:00
|
|
|
}
|
2019-11-20 14:29:06 +01:00
|
|
|
if (!*url)
|
2013-10-14 15:57:59 +02:00
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_AUTODETECTION_FAILED );
|
2019-11-20 14:29:06 +01:00
|
|
|
return FALSE;
|
2013-10-14 15:57:59 +02:00
|
|
|
}
|
2019-11-20 14:29:06 +01:00
|
|
|
SetLastError( ERROR_SUCCESS );
|
|
|
|
return TRUE;
|
2008-08-15 14:43:23 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
static const WCHAR path_connections[] =
|
|
|
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections";
|
|
|
|
|
2011-11-16 09:42:17 +01:00
|
|
|
static const DWORD WINHTTP_SETTINGS_MAGIC = 0x18;
|
|
|
|
static const DWORD WININET_SETTINGS_MAGIC = 0x46;
|
|
|
|
static const DWORD PROXY_TYPE_DIRECT = 1;
|
|
|
|
static const DWORD PROXY_TYPE_PROXY = 2;
|
|
|
|
static const DWORD PROXY_USE_PAC_SCRIPT = 4;
|
|
|
|
static const DWORD PROXY_AUTODETECT_SETTINGS = 8;
|
|
|
|
|
|
|
|
struct connection_settings_header
|
2009-07-14 21:53:14 +02:00
|
|
|
{
|
|
|
|
DWORD magic;
|
|
|
|
DWORD unknown; /* always zero? */
|
2011-11-16 09:42:17 +01:00
|
|
|
DWORD flags; /* one or more of PROXY_* */
|
2009-07-14 21:53:14 +02:00
|
|
|
};
|
|
|
|
|
2009-07-14 22:00:38 +02:00
|
|
|
static inline void copy_char_to_wchar_sz(const BYTE *src, DWORD len, WCHAR *dst)
|
|
|
|
{
|
|
|
|
const BYTE *begin;
|
|
|
|
|
|
|
|
for (begin = src; src - begin < len; src++, dst++)
|
|
|
|
*dst = *src;
|
|
|
|
*dst = 0;
|
|
|
|
}
|
|
|
|
|
2008-08-15 14:43:23 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetDefaultProxyConfiguration (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
|
|
|
|
{
|
2009-07-14 22:00:38 +02:00
|
|
|
LONG l;
|
|
|
|
HKEY key;
|
2009-07-21 20:38:54 +02:00
|
|
|
BOOL got_from_reg = FALSE, direct = TRUE;
|
2019-11-28 08:48:32 +01:00
|
|
|
WCHAR *envproxy;
|
2009-07-14 22:00:38 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", info);
|
2008-08-15 14:43:23 +02:00
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
l = RegOpenKeyExW( HKEY_LOCAL_MACHINE, path_connections, 0, KEY_READ, &key );
|
2009-07-14 22:00:38 +02:00
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
DWORD type, size = 0;
|
2008-08-15 14:43:23 +02:00
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
l = RegQueryValueExW( key, L"WinHttpSettings", NULL, &type, NULL, &size );
|
2009-07-14 22:00:38 +02:00
|
|
|
if (!l && type == REG_BINARY &&
|
2011-11-16 09:42:17 +01:00
|
|
|
size >= sizeof(struct connection_settings_header) + 2 * sizeof(DWORD))
|
2009-07-14 22:00:38 +02:00
|
|
|
{
|
|
|
|
BYTE *buf = heap_alloc( size );
|
|
|
|
|
|
|
|
if (buf)
|
|
|
|
{
|
2011-11-16 09:42:17 +01:00
|
|
|
struct connection_settings_header *hdr =
|
|
|
|
(struct connection_settings_header *)buf;
|
2009-07-14 22:00:38 +02:00
|
|
|
DWORD *len = (DWORD *)(hdr + 1);
|
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
l = RegQueryValueExW( key, L"WinHttpSettings", NULL, NULL, buf,
|
2009-07-14 22:00:38 +02:00
|
|
|
&size );
|
2011-11-16 09:42:17 +01:00
|
|
|
if (!l && hdr->magic == WINHTTP_SETTINGS_MAGIC &&
|
2009-07-14 22:00:38 +02:00
|
|
|
hdr->unknown == 0)
|
|
|
|
{
|
2011-11-16 09:42:17 +01:00
|
|
|
if (hdr->flags & PROXY_TYPE_PROXY)
|
2009-07-14 22:00:38 +02:00
|
|
|
{
|
|
|
|
BOOL sane = FALSE;
|
2009-07-22 14:48:09 +02:00
|
|
|
LPWSTR proxy = NULL;
|
|
|
|
LPWSTR proxy_bypass = NULL;
|
2009-07-14 22:00:38 +02:00
|
|
|
|
|
|
|
/* Sanity-check length of proxy string */
|
|
|
|
if ((BYTE *)len - buf + *len <= size)
|
|
|
|
{
|
|
|
|
sane = TRUE;
|
2009-07-22 14:48:09 +02:00
|
|
|
proxy = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
|
|
|
|
if (proxy)
|
|
|
|
copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy );
|
2009-07-14 22:00:38 +02:00
|
|
|
len = (DWORD *)((BYTE *)(len + 1) + *len);
|
|
|
|
}
|
|
|
|
if (sane)
|
|
|
|
{
|
|
|
|
/* Sanity-check length of proxy bypass string */
|
|
|
|
if ((BYTE *)len - buf + *len <= size)
|
|
|
|
{
|
2009-07-22 14:48:09 +02:00
|
|
|
proxy_bypass = GlobalAlloc( 0, (*len + 1) * sizeof(WCHAR) );
|
|
|
|
if (proxy_bypass)
|
|
|
|
copy_char_to_wchar_sz( (BYTE *)(len + 1), *len, proxy_bypass );
|
2009-07-14 22:00:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sane = FALSE;
|
2009-07-22 14:48:09 +02:00
|
|
|
GlobalFree( proxy );
|
|
|
|
proxy = NULL;
|
2009-07-14 22:00:38 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-22 14:48:09 +02:00
|
|
|
info->lpszProxy = proxy;
|
|
|
|
info->lpszProxyBypass = proxy_bypass;
|
2009-07-14 22:00:38 +02:00
|
|
|
if (sane)
|
|
|
|
{
|
2009-07-21 20:38:54 +02:00
|
|
|
got_from_reg = TRUE;
|
2009-07-14 22:00:38 +02:00
|
|
|
direct = FALSE;
|
|
|
|
info->dwAccessType =
|
|
|
|
WINHTTP_ACCESS_TYPE_NAMED_PROXY;
|
2009-07-14 22:01:26 +02:00
|
|
|
TRACE("http proxy (from registry) = %s, bypass = %s\n",
|
|
|
|
debugstr_w(info->lpszProxy),
|
|
|
|
debugstr_w(info->lpszProxyBypass));
|
2009-07-14 22:00:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap_free( buf );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey( key );
|
|
|
|
}
|
2019-11-28 08:48:32 +01:00
|
|
|
if (!got_from_reg && (envproxy = _wgetenv( L"http_proxy" )))
|
2009-07-14 22:01:26 +02:00
|
|
|
{
|
2019-11-28 08:48:32 +01:00
|
|
|
WCHAR *colon, *http_proxy = NULL;
|
2009-07-14 22:01:26 +02:00
|
|
|
|
2019-11-28 08:48:32 +01:00
|
|
|
if (!(colon = wcschr( envproxy, ':' ))) http_proxy = envproxy;
|
2018-05-23 11:36:44 +02:00
|
|
|
else
|
2009-07-14 22:01:26 +02:00
|
|
|
{
|
2009-07-21 20:36:52 +02:00
|
|
|
if (*(colon + 1) == '/' && *(colon + 2) == '/')
|
|
|
|
{
|
|
|
|
/* It's a scheme, check that it's http */
|
2019-11-28 08:48:32 +01:00
|
|
|
if (!wcsncmp( envproxy, L"http://", 7 )) http_proxy = envproxy + 7;
|
|
|
|
else WARN("unsupported scheme in $http_proxy: %s\n", debugstr_w(envproxy));
|
2009-07-21 20:36:52 +02:00
|
|
|
}
|
2018-05-23 11:36:44 +02:00
|
|
|
else http_proxy = envproxy;
|
2009-07-21 20:36:52 +02:00
|
|
|
}
|
2018-05-23 11:36:44 +02:00
|
|
|
|
|
|
|
if (http_proxy && http_proxy[0])
|
2009-07-21 20:36:52 +02:00
|
|
|
{
|
2019-11-28 08:48:32 +01:00
|
|
|
direct = FALSE;
|
|
|
|
info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
|
|
|
|
info->lpszProxy = GlobalAlloc( 0, (lstrlenW(http_proxy) + 1) * sizeof(WCHAR) );
|
|
|
|
wcscpy( info->lpszProxy, http_proxy );
|
|
|
|
info->lpszProxyBypass = NULL;
|
|
|
|
TRACE("http proxy (from environment) = %s\n", debugstr_w(info->lpszProxy));
|
2009-07-14 22:01:26 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-14 22:00:38 +02:00
|
|
|
if (direct)
|
|
|
|
{
|
|
|
|
info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
|
|
|
|
info->lpszProxy = NULL;
|
|
|
|
info->lpszProxyBypass = NULL;
|
|
|
|
}
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_SUCCESS );
|
2008-08-15 14:43:23 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetIEProxyConfigForCurrentUser (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY_CONFIG *config )
|
|
|
|
{
|
2011-11-16 09:42:17 +01:00
|
|
|
HKEY hkey = NULL;
|
|
|
|
struct connection_settings_header *hdr = NULL;
|
|
|
|
DWORD type, offset, len, size = 0;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2008-08-15 14:43:23 +02:00
|
|
|
TRACE("%p\n", config);
|
|
|
|
|
|
|
|
if (!config)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2008-08-15 14:43:23 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-16 09:42:17 +01:00
|
|
|
memset( config, 0, sizeof(*config) );
|
|
|
|
config->fAutoDetect = TRUE;
|
2008-08-15 14:43:23 +02:00
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
if (RegOpenKeyExW( HKEY_CURRENT_USER, path_connections, 0, KEY_READ, &hkey ) ||
|
|
|
|
RegQueryValueExW( hkey, L"DefaultConnectionSettings", NULL, &type, NULL, &size ) ||
|
2011-11-16 09:42:17 +01:00
|
|
|
type != REG_BINARY || size < sizeof(struct connection_settings_header))
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (!(hdr = heap_alloc( size ))) goto done;
|
2019-11-22 16:32:24 +01:00
|
|
|
if (RegQueryValueExW( hkey, L"DefaultConnectionSettings", NULL, &type, (BYTE *)hdr, &size ) ||
|
2011-11-16 09:42:17 +01:00
|
|
|
hdr->magic != WININET_SETTINGS_MAGIC)
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-08-15 14:43:23 +02:00
|
|
|
|
2011-11-16 09:42:17 +01:00
|
|
|
config->fAutoDetect = (hdr->flags & PROXY_AUTODETECT_SETTINGS) != 0;
|
|
|
|
offset = sizeof(*hdr);
|
|
|
|
if (offset + sizeof(DWORD) > size) goto done;
|
|
|
|
len = *(DWORD *)((char *)hdr + offset);
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
if (len && hdr->flags & PROXY_TYPE_PROXY)
|
|
|
|
{
|
|
|
|
if (!(config->lpszProxy = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
|
|
|
|
copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszProxy );
|
|
|
|
}
|
|
|
|
offset += len;
|
|
|
|
if (offset + sizeof(DWORD) > size) goto done;
|
|
|
|
len = *(DWORD *)((char *)hdr + offset);
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
if (len && (hdr->flags & PROXY_TYPE_PROXY))
|
|
|
|
{
|
|
|
|
if (!(config->lpszProxyBypass = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
|
|
|
|
copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszProxyBypass );
|
|
|
|
}
|
|
|
|
offset += len;
|
|
|
|
if (offset + sizeof(DWORD) > size) goto done;
|
|
|
|
len = *(DWORD *)((char *)hdr + offset);
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
if (len && (hdr->flags & PROXY_USE_PAC_SCRIPT))
|
|
|
|
{
|
|
|
|
if (!(config->lpszAutoConfigUrl = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) goto done;
|
|
|
|
copy_char_to_wchar_sz( (const BYTE *)hdr + offset , len, config->lpszAutoConfigUrl );
|
|
|
|
}
|
|
|
|
ret = TRUE;
|
2008-08-15 14:43:23 +02:00
|
|
|
|
2011-11-16 09:42:17 +01:00
|
|
|
done:
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
heap_free( hdr );
|
|
|
|
if (!ret)
|
|
|
|
{
|
2014-04-14 17:10:23 +02:00
|
|
|
GlobalFree( config->lpszAutoConfigUrl );
|
2011-11-16 09:42:17 +01:00
|
|
|
config->lpszAutoConfigUrl = NULL;
|
2014-04-14 17:10:23 +02:00
|
|
|
GlobalFree( config->lpszProxy );
|
2011-11-16 09:42:17 +01:00
|
|
|
config->lpszProxy = NULL;
|
2014-04-14 17:10:23 +02:00
|
|
|
GlobalFree( config->lpszProxyBypass );
|
2011-11-16 09:42:17 +01:00
|
|
|
config->lpszProxyBypass = NULL;
|
|
|
|
}
|
2018-11-22 21:15:55 +01:00
|
|
|
else SetLastError( ERROR_SUCCESS );
|
2011-11-16 09:42:17 +01:00
|
|
|
return ret;
|
2008-08-15 14:43:23 +02:00
|
|
|
}
|
|
|
|
|
2014-05-15 14:05:48 +02:00
|
|
|
static BOOL parse_script_result( const char *result, WINHTTP_PROXY_INFO *info )
|
2011-11-18 10:36:04 +01:00
|
|
|
{
|
2014-05-15 14:05:48 +02:00
|
|
|
const char *p;
|
2011-11-18 10:36:04 +01:00
|
|
|
WCHAR *q;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
info->dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
|
|
|
|
info->lpszProxy = NULL;
|
|
|
|
info->lpszProxyBypass = NULL;
|
|
|
|
|
2014-05-15 14:05:48 +02:00
|
|
|
TRACE("%s\n", debugstr_a( result ));
|
2011-11-18 10:36:04 +01:00
|
|
|
|
2014-05-15 14:05:48 +02:00
|
|
|
p = result;
|
2011-11-18 10:36:04 +01:00
|
|
|
while (*p == ' ') p++;
|
2014-05-15 14:05:48 +02:00
|
|
|
len = strlen( p );
|
2019-03-29 16:34:17 +01:00
|
|
|
if (len >= 5 && !_strnicmp( p, "PROXY", sizeof("PROXY") - 1 ))
|
2011-11-18 10:36:04 +01:00
|
|
|
{
|
|
|
|
p += 5;
|
|
|
|
while (*p == ' ') p++;
|
|
|
|
if (!*p || *p == ';') return TRUE;
|
2014-05-15 14:05:48 +02:00
|
|
|
if (!(info->lpszProxy = q = strdupAW( p ))) return FALSE;
|
2011-11-18 10:36:04 +01:00
|
|
|
info->dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
|
|
|
|
for (; *q; q++)
|
|
|
|
{
|
|
|
|
if (*q == ' ' || *q == ';')
|
|
|
|
{
|
|
|
|
*q = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-15 14:05:48 +02:00
|
|
|
static char *download_script( const WCHAR *url, DWORD *out_size )
|
2011-11-18 10:36:04 +01:00
|
|
|
{
|
2019-11-22 16:32:24 +01:00
|
|
|
static const WCHAR *acceptW[] = {L"*/*", NULL};
|
2012-01-20 09:04:51 +01:00
|
|
|
HINTERNET ses, con = NULL, req = NULL;
|
2011-11-18 10:36:04 +01:00
|
|
|
WCHAR *hostname;
|
|
|
|
URL_COMPONENTSW uc;
|
2012-12-18 11:22:50 +01:00
|
|
|
DWORD status, size = sizeof(status), offset, to_read, bytes_read, flags = 0;
|
2011-11-18 10:36:04 +01:00
|
|
|
char *tmp, *buffer = NULL;
|
2014-05-15 14:05:48 +02:00
|
|
|
|
|
|
|
*out_size = 0;
|
2011-11-18 10:36:04 +01:00
|
|
|
|
|
|
|
memset( &uc, 0, sizeof(uc) );
|
|
|
|
uc.dwStructSize = sizeof(uc);
|
2016-08-31 21:21:00 +02:00
|
|
|
uc.dwHostNameLength = -1;
|
|
|
|
uc.dwUrlPathLength = -1;
|
2011-11-18 10:36:04 +01:00
|
|
|
if (!WinHttpCrackUrl( url, 0, 0, &uc )) return NULL;
|
|
|
|
if (!(hostname = heap_alloc( (uc.dwHostNameLength + 1) * sizeof(WCHAR) ))) return NULL;
|
|
|
|
memcpy( hostname, uc.lpszHostName, uc.dwHostNameLength * sizeof(WCHAR) );
|
|
|
|
hostname[uc.dwHostNameLength] = 0;
|
|
|
|
|
2012-01-20 09:04:51 +01:00
|
|
|
if (!(ses = WinHttpOpen( NULL, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0 ))) goto done;
|
2011-11-18 10:36:04 +01:00
|
|
|
if (!(con = WinHttpConnect( ses, hostname, uc.nPort, 0 ))) goto done;
|
|
|
|
if (uc.nScheme == INTERNET_SCHEME_HTTPS) flags |= WINHTTP_FLAG_SECURE;
|
|
|
|
if (!(req = WinHttpOpenRequest( con, NULL, uc.lpszUrlPath, NULL, NULL, acceptW, flags ))) goto done;
|
|
|
|
if (!WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 )) goto done;
|
2012-12-18 11:22:50 +01:00
|
|
|
|
2011-11-18 10:36:04 +01:00
|
|
|
if (!(WinHttpReceiveResponse( req, 0 ))) goto done;
|
2012-12-18 11:22:50 +01:00
|
|
|
if (!WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status,
|
|
|
|
&size, NULL ) || status != HTTP_STATUS_OK) goto done;
|
2011-11-18 10:36:04 +01:00
|
|
|
|
2012-12-18 11:22:50 +01:00
|
|
|
size = 4096;
|
2011-11-18 10:36:04 +01:00
|
|
|
if (!(buffer = heap_alloc( size ))) goto done;
|
|
|
|
to_read = size;
|
|
|
|
offset = 0;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!WinHttpReadData( req, buffer + offset, to_read, &bytes_read )) goto done;
|
|
|
|
if (!bytes_read) break;
|
|
|
|
to_read -= bytes_read;
|
|
|
|
offset += bytes_read;
|
2014-05-15 14:05:48 +02:00
|
|
|
*out_size += bytes_read;
|
2011-11-18 10:36:04 +01:00
|
|
|
if (!to_read)
|
|
|
|
{
|
|
|
|
to_read = size;
|
|
|
|
size *= 2;
|
|
|
|
if (!(tmp = heap_realloc( buffer, size ))) goto done;
|
|
|
|
buffer = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
WinHttpCloseHandle( req );
|
|
|
|
WinHttpCloseHandle( con );
|
2012-01-20 09:04:51 +01:00
|
|
|
WinHttpCloseHandle( ses );
|
2011-11-18 10:36:04 +01:00
|
|
|
heap_free( hostname );
|
2018-11-22 21:15:55 +01:00
|
|
|
if (!buffer) SetLastError( ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT );
|
2014-05-15 14:05:48 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AUTO_PROXY_SCRIPT_BUFFER
|
|
|
|
{
|
|
|
|
DWORD dwStructSize;
|
|
|
|
LPSTR lpszScriptBuffer;
|
|
|
|
DWORD dwScriptBufferSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
BOOL WINAPI InternetDeInitializeAutoProxyDll(LPSTR, DWORD);
|
|
|
|
BOOL WINAPI InternetGetProxyInfo(LPCSTR, DWORD, LPSTR, DWORD, LPSTR *, LPDWORD);
|
|
|
|
BOOL WINAPI InternetInitializeAutoProxyDll(DWORD, LPSTR, LPSTR, void *, struct AUTO_PROXY_SCRIPT_BUFFER *);
|
|
|
|
|
|
|
|
static BOOL run_script( char *script, DWORD size, const WCHAR *url, WINHTTP_PROXY_INFO *info )
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
char *result, *urlA;
|
|
|
|
DWORD len_result;
|
|
|
|
struct AUTO_PROXY_SCRIPT_BUFFER buffer;
|
2016-08-31 21:21:05 +02:00
|
|
|
URL_COMPONENTSW uc;
|
2014-05-15 14:05:48 +02:00
|
|
|
|
|
|
|
buffer.dwStructSize = sizeof(buffer);
|
|
|
|
buffer.lpszScriptBuffer = script;
|
|
|
|
buffer.dwScriptBufferSize = size;
|
|
|
|
|
|
|
|
if (!(urlA = strdupWA( url ))) return FALSE;
|
|
|
|
if (!(ret = InternetInitializeAutoProxyDll( 0, NULL, NULL, NULL, &buffer )))
|
|
|
|
{
|
|
|
|
heap_free( urlA );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-08-31 21:21:05 +02:00
|
|
|
|
|
|
|
memset( &uc, 0, sizeof(uc) );
|
|
|
|
uc.dwStructSize = sizeof(uc);
|
|
|
|
uc.dwHostNameLength = -1;
|
|
|
|
|
|
|
|
if (WinHttpCrackUrl( url, 0, 0, &uc ))
|
2014-05-15 14:05:48 +02:00
|
|
|
{
|
2016-08-31 21:21:05 +02:00
|
|
|
char *hostnameA = strdupWA_sized( uc.lpszHostName, uc.dwHostNameLength );
|
|
|
|
|
|
|
|
if ((ret = InternetGetProxyInfo( urlA, strlen(urlA),
|
|
|
|
hostnameA, strlen(hostnameA), &result, &len_result )))
|
|
|
|
{
|
|
|
|
ret = parse_script_result( result, info );
|
|
|
|
heap_free( result );
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_free( hostnameA );
|
2014-05-15 14:05:48 +02:00
|
|
|
}
|
|
|
|
heap_free( urlA );
|
|
|
|
return InternetDeInitializeAutoProxyDll( NULL, 0 );
|
2011-11-18 10:36:04 +01:00
|
|
|
}
|
|
|
|
|
2008-08-15 14:43:23 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetProxyForUrl (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTOPROXY_OPTIONS *options,
|
|
|
|
WINHTTP_PROXY_INFO *info )
|
|
|
|
{
|
2011-11-18 10:36:04 +01:00
|
|
|
WCHAR *detected_pac_url = NULL;
|
|
|
|
const WCHAR *pac_url;
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session;
|
2014-05-15 14:05:48 +02:00
|
|
|
char *script;
|
|
|
|
DWORD size;
|
2011-11-18 10:36:04 +01:00
|
|
|
BOOL ret = FALSE;
|
2008-08-15 14:43:23 +02:00
|
|
|
|
2011-11-18 10:36:04 +01:00
|
|
|
TRACE("%p, %s, %p, %p\n", hsession, debugstr_w(url), options, info);
|
|
|
|
|
2018-11-22 21:15:51 +01:00
|
|
|
if (!(session = (struct session *)grab_object( hsession )))
|
2011-11-18 10:36:04 +01:00
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
2011-11-18 10:36:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION)
|
|
|
|
{
|
|
|
|
release_object( &session->hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
|
2011-11-18 10:36:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!url || !options || !info ||
|
|
|
|
!(options->dwFlags & (WINHTTP_AUTOPROXY_AUTO_DETECT|WINHTTP_AUTOPROXY_CONFIG_URL)) ||
|
|
|
|
((options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT) && !options->dwAutoDetectFlags) ||
|
|
|
|
((options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT) &&
|
|
|
|
(options->dwFlags & WINHTTP_AUTOPROXY_CONFIG_URL)))
|
|
|
|
{
|
|
|
|
release_object( &session->hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2011-11-18 10:36:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (options->dwFlags & WINHTTP_AUTOPROXY_AUTO_DETECT &&
|
|
|
|
!WinHttpDetectAutoProxyConfigUrl( options->dwAutoDetectFlags, &detected_pac_url ))
|
|
|
|
goto done;
|
2012-11-01 14:45:59 +01:00
|
|
|
|
2011-11-18 10:36:04 +01:00
|
|
|
if (options->dwFlags & WINHTTP_AUTOPROXY_CONFIG_URL) pac_url = options->lpszAutoConfigUrl;
|
|
|
|
else pac_url = detected_pac_url;
|
|
|
|
|
2014-05-15 14:05:48 +02:00
|
|
|
if ((script = download_script( pac_url, &size )))
|
|
|
|
{
|
|
|
|
ret = run_script( script, size, url, info );
|
|
|
|
heap_free( script );
|
|
|
|
}
|
2011-11-18 10:36:04 +01:00
|
|
|
|
|
|
|
done:
|
|
|
|
GlobalFree( detected_pac_url );
|
|
|
|
release_object( &session->hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
if (ret) SetLastError( ERROR_SUCCESS );
|
2011-11-18 10:36:04 +01:00
|
|
|
return ret;
|
2008-08-15 14:43:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpSetDefaultProxyConfiguration (winhttp.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
|
|
|
|
{
|
2009-07-14 21:53:14 +02:00
|
|
|
LONG l;
|
|
|
|
HKEY key;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
const WCHAR *src;
|
|
|
|
|
|
|
|
TRACE("%p\n", info);
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2009-07-14 21:53:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
switch (info->dwAccessType)
|
|
|
|
{
|
|
|
|
case WINHTTP_ACCESS_TYPE_NO_PROXY:
|
|
|
|
break;
|
|
|
|
case WINHTTP_ACCESS_TYPE_NAMED_PROXY:
|
|
|
|
if (!info->lpszProxy)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2009-07-14 21:53:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Only ASCII characters are allowed */
|
|
|
|
for (src = info->lpszProxy; *src; src++)
|
|
|
|
if (*src > 0x7f)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2009-07-14 21:53:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (info->lpszProxyBypass)
|
|
|
|
{
|
|
|
|
for (src = info->lpszProxyBypass; *src; src++)
|
|
|
|
if (*src > 0x7f)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2009-07-14 21:53:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2009-07-14 21:53:14 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
l = RegCreateKeyExW( HKEY_LOCAL_MACHINE, path_connections, 0, NULL, 0,
|
2009-07-14 21:53:14 +02:00
|
|
|
KEY_WRITE, NULL, &key, NULL );
|
|
|
|
if (!l)
|
|
|
|
{
|
2011-11-16 09:42:17 +01:00
|
|
|
DWORD size = sizeof(struct connection_settings_header) + 2 * sizeof(DWORD);
|
2009-07-14 21:53:14 +02:00
|
|
|
BYTE *buf;
|
|
|
|
|
|
|
|
if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
|
|
|
|
{
|
2019-11-20 14:29:08 +01:00
|
|
|
size += lstrlenW( info->lpszProxy );
|
2009-07-14 21:53:14 +02:00
|
|
|
if (info->lpszProxyBypass)
|
2019-11-20 14:29:08 +01:00
|
|
|
size += lstrlenW( info->lpszProxyBypass );
|
2009-07-14 21:53:14 +02:00
|
|
|
}
|
|
|
|
buf = heap_alloc( size );
|
|
|
|
if (buf)
|
|
|
|
{
|
2011-11-16 09:42:17 +01:00
|
|
|
struct connection_settings_header *hdr =
|
|
|
|
(struct connection_settings_header *)buf;
|
2009-07-14 21:53:14 +02:00
|
|
|
DWORD *len = (DWORD *)(hdr + 1);
|
|
|
|
|
2011-11-16 09:42:17 +01:00
|
|
|
hdr->magic = WINHTTP_SETTINGS_MAGIC;
|
2009-07-14 21:53:14 +02:00
|
|
|
hdr->unknown = 0;
|
|
|
|
if (info->dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY)
|
|
|
|
{
|
|
|
|
BYTE *dst;
|
|
|
|
|
2011-11-16 09:42:17 +01:00
|
|
|
hdr->flags = PROXY_TYPE_PROXY;
|
2019-11-20 14:29:08 +01:00
|
|
|
*len++ = lstrlenW( info->lpszProxy );
|
2009-07-14 21:53:14 +02:00
|
|
|
for (dst = (BYTE *)len, src = info->lpszProxy; *src;
|
|
|
|
src++, dst++)
|
|
|
|
*dst = *src;
|
|
|
|
len = (DWORD *)dst;
|
|
|
|
if (info->lpszProxyBypass)
|
|
|
|
{
|
2019-11-20 14:29:08 +01:00
|
|
|
*len++ = lstrlenW( info->lpszProxyBypass );
|
2009-07-14 21:53:14 +02:00
|
|
|
for (dst = (BYTE *)len, src = info->lpszProxyBypass; *src;
|
|
|
|
src++, dst++)
|
|
|
|
*dst = *src;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*len++ = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-16 09:42:17 +01:00
|
|
|
hdr->flags = PROXY_TYPE_DIRECT;
|
2009-07-14 21:53:14 +02:00
|
|
|
*len++ = 0;
|
|
|
|
*len++ = 0;
|
|
|
|
}
|
2019-11-22 16:32:24 +01:00
|
|
|
l = RegSetValueExW( key, L"WinHttpSettings", 0, REG_BINARY, buf, size );
|
2009-07-14 21:53:14 +02:00
|
|
|
if (!l)
|
|
|
|
ret = TRUE;
|
|
|
|
heap_free( buf );
|
|
|
|
}
|
|
|
|
RegCloseKey( key );
|
|
|
|
}
|
2018-11-22 21:15:55 +01:00
|
|
|
if (ret) SetLastError( ERROR_SUCCESS );
|
2009-07-14 21:53:14 +02:00
|
|
|
return ret;
|
2008-08-15 14:43:23 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 11:00:25 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpCreateProxyResolver (winhttp.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WinHttpCreateProxyResolver( HINTERNET hsession, HINTERNET *hresolver )
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", hsession, hresolver);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpFreeProxyResult (winhttp.@)
|
|
|
|
*/
|
|
|
|
void WINAPI WinHttpFreeProxyResult( WINHTTP_PROXY_RESULT *result )
|
|
|
|
{
|
|
|
|
FIXME("%p\n", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpFreeProxyResultEx (winhttp.@)
|
|
|
|
*/
|
|
|
|
void WINAPI WinHttpFreeProxyResultEx( WINHTTP_PROXY_RESULT_EX *result )
|
|
|
|
{
|
|
|
|
FIXME("%p\n", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpFreeProxySettings (winhttp.@)
|
|
|
|
*/
|
|
|
|
void WINAPI WinHttpFreeProxySettings( WINHTTP_PROXY_SETTINGS *settings )
|
|
|
|
{
|
|
|
|
FIXME("%p\n", settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetProxyForUrlEx (winhttp.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WinHttpGetProxyForUrlEx( HINTERNET hresolver, const WCHAR *url, WINHTTP_AUTOPROXY_OPTIONS *options,
|
|
|
|
DWORD_PTR ctx )
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p, %lx\n", hresolver, debugstr_w(url), options, ctx);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetProxyForUrlEx2 (winhttp.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WinHttpGetProxyForUrlEx2( HINTERNET hresolver, const WCHAR *url, WINHTTP_AUTOPROXY_OPTIONS *options,
|
|
|
|
DWORD selection_len, BYTE *selection, DWORD_PTR ctx )
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p, %u, %p, %lx\n", hresolver, debugstr_w(url), options, selection_len, selection, ctx);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetProxyResult (winhttp.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WinHttpGetProxyResult( HINTERNET hresolver, WINHTTP_PROXY_RESULT *result )
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", hresolver, result);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetProxyResultEx (winhttp.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WinHttpGetProxyResultEx( HINTERNET hresolver, WINHTTP_PROXY_RESULT_EX *result )
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", hresolver, result);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpGetProxySettingsVersion (winhttp.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WinHttpGetProxySettingsVersion( HINTERNET hsession, DWORD *version )
|
|
|
|
{
|
|
|
|
FIXME("%p, %p\n", hsession, version);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpReadProxySettings (winhttp.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WinHttpReadProxySettings( HINTERNET hsession, const WCHAR *connection, BOOL use_defaults,
|
|
|
|
BOOL set_autodiscover, DWORD *version, BOOL *defaults_returned,
|
|
|
|
WINHTTP_PROXY_SETTINGS *settings)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %d, %d, %p, %p, %p\n", hsession, debugstr_w(connection), use_defaults, set_autodiscover,
|
|
|
|
version, defaults_returned, settings);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpResetAutoProxy (winhttp.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI WinHttpResetAutoProxy( HINTERNET hsession, DWORD flags )
|
|
|
|
{
|
|
|
|
FIXME("%p, %08x\n", hsession, flags);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI WinHttpWriteProxySettings( HINTERNET hsession, BOOL force, WINHTTP_PROXY_SETTINGS *settings )
|
|
|
|
{
|
|
|
|
FIXME("%p, %d, %p\n", hsession, force, settings);
|
|
|
|
return ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
2018-11-15 12:38:50 +01:00
|
|
|
struct object_header *hdr;
|
2008-08-15 14:43:07 +02:00
|
|
|
WINHTTP_STATUS_CALLBACK ret;
|
|
|
|
|
|
|
|
TRACE("%p, %p, 0x%08x, 0x%lx\n", handle, callback, flags, reserved);
|
|
|
|
|
|
|
|
if (!(hdr = grab_object( handle )))
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
2008-08-15 14:43:07 +02:00
|
|
|
return WINHTTP_INVALID_STATUS_CALLBACK;
|
|
|
|
}
|
|
|
|
ret = hdr->callback;
|
|
|
|
hdr->callback = callback;
|
|
|
|
hdr->notify_mask = flags;
|
|
|
|
|
|
|
|
release_object( hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_SUCCESS );
|
2008-08-15 14:43:07 +02:00
|
|
|
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 )
|
|
|
|
{
|
2009-07-07 10:14:11 +02:00
|
|
|
BOOL ret = TRUE;
|
2018-11-15 12:38:50 +01:00
|
|
|
struct object_header *hdr;
|
2009-07-07 10:14:11 +02:00
|
|
|
|
|
|
|
TRACE("%p, %d, %d, %d, %d\n", handle, resolve, connect, send, receive);
|
|
|
|
|
|
|
|
if (resolve < -1 || connect < -1 || send < -1 || receive < -1)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2009-07-07 10:14:11 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-29 01:45:15 +01:00
|
|
|
if (!(hdr = grab_object( handle )))
|
2009-07-07 10:14:11 +02:00
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
2009-07-07 10:14:11 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-29 01:45:15 +01:00
|
|
|
switch(hdr->type)
|
2009-07-07 10:14:11 +02:00
|
|
|
{
|
2018-09-10 13:24:34 +02:00
|
|
|
case WINHTTP_HANDLE_TYPE_REQUEST:
|
|
|
|
{
|
2018-11-22 21:15:54 +01:00
|
|
|
struct request *request = (struct request *)hdr;
|
2018-09-10 13:24:34 +02:00
|
|
|
request->connect_timeout = connect;
|
2009-07-07 10:14:11 +02:00
|
|
|
|
2018-09-10 13:24:34 +02:00
|
|
|
if (resolve < 0) resolve = 0;
|
|
|
|
request->resolve_timeout = resolve;
|
2010-02-22 12:27:30 +01:00
|
|
|
|
2018-09-10 13:24:34 +02:00
|
|
|
if (send < 0) send = 0;
|
|
|
|
request->send_timeout = send;
|
2009-07-23 18:11:32 +02:00
|
|
|
|
2018-09-10 13:24:34 +02:00
|
|
|
if (receive < 0) receive = 0;
|
|
|
|
request->receive_timeout = receive;
|
2009-07-07 10:14:11 +02:00
|
|
|
|
2018-09-10 13:24:34 +02:00
|
|
|
if (request->netconn)
|
|
|
|
{
|
|
|
|
if (netconn_set_timeout( request->netconn, TRUE, send )) ret = FALSE;
|
|
|
|
if (netconn_set_timeout( request->netconn, FALSE, receive )) ret = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WINHTTP_HANDLE_TYPE_SESSION:
|
|
|
|
{
|
2018-11-22 21:15:51 +01:00
|
|
|
struct session *session = (struct session *)hdr;
|
2018-09-10 13:24:34 +02:00
|
|
|
session->connect_timeout = connect;
|
2010-02-22 12:27:30 +01:00
|
|
|
|
2018-09-10 13:24:34 +02:00
|
|
|
if (resolve < 0) resolve = 0;
|
|
|
|
session->resolve_timeout = resolve;
|
2010-01-29 01:45:15 +01:00
|
|
|
|
2018-09-10 13:24:34 +02:00
|
|
|
if (send < 0) send = 0;
|
|
|
|
session->send_timeout = send;
|
2010-01-29 01:45:15 +01:00
|
|
|
|
2018-09-10 13:24:34 +02:00
|
|
|
if (receive < 0) receive = 0;
|
|
|
|
session->receive_timeout = receive;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE );
|
2018-09-10 13:24:34 +02:00
|
|
|
ret = FALSE;
|
2010-01-29 01:45:15 +01:00
|
|
|
}
|
2015-07-21 16:12:42 +02:00
|
|
|
release_object( hdr );
|
2018-11-22 21:15:55 +01:00
|
|
|
if (ret) SetLastError( ERROR_SUCCESS );
|
2009-07-07 10:14:11 +02:00
|
|
|
return ret;
|
2008-08-20 11:35:15 +02:00
|
|
|
}
|
|
|
|
|
2008-08-15 14:44:16 +02:00
|
|
|
static const WCHAR wkday[7][4] =
|
2019-11-22 16:32:24 +01:00
|
|
|
{L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat"};
|
2008-08-15 14:44:16 +02:00
|
|
|
static const WCHAR month[12][4] =
|
2019-11-22 16:32:24 +01:00
|
|
|
{L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"};
|
2008-08-15 14:44:16 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WinHttpTimeFromSystemTime (WININET.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
|
|
|
|
{
|
|
|
|
TRACE("%p, %p\n", time, string);
|
|
|
|
|
2015-08-03 11:27:31 +02:00
|
|
|
if (!time || !string)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2015-08-03 11:27:31 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-08-15 14:44:16 +02:00
|
|
|
|
2019-11-22 16:32:24 +01:00
|
|
|
swprintf( string, WINHTTP_TIME_FORMAT_BUFSIZE / sizeof(WCHAR),
|
|
|
|
L"%s, %02d %s %4d %02d:%02d:%02d GMT",
|
2008-08-15 14:44:16 +02:00
|
|
|
wkday[time->wDayOfWeek],
|
|
|
|
time->wDay,
|
|
|
|
month[time->wMonth - 1],
|
|
|
|
time->wYear,
|
|
|
|
time->wHour,
|
|
|
|
time->wMinute,
|
|
|
|
time->wSecond );
|
|
|
|
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_SUCCESS );
|
2008-08-15 14:44:16 +02:00
|
|
|
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);
|
|
|
|
|
2015-08-03 11:27:31 +02:00
|
|
|
if (!string || !time)
|
|
|
|
{
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2015-08-03 11:27:31 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-08-15 14:44:16 +02:00
|
|
|
|
|
|
|
/* Windows does this too */
|
|
|
|
GetSystemTime( time );
|
|
|
|
|
|
|
|
/* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
|
|
|
|
* a SYSTEMTIME structure.
|
|
|
|
*/
|
|
|
|
|
2018-11-22 21:15:55 +01:00
|
|
|
SetLastError( ERROR_SUCCESS );
|
2015-08-03 11:27:31 +02:00
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
while (*s && !iswalpha( *s )) s++;
|
2008-08-15 14:44:16 +02:00
|
|
|
if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
|
|
|
|
time->wDayOfWeek = 7;
|
|
|
|
|
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
{
|
2019-11-20 14:29:08 +01:00
|
|
|
if (towupper( wkday[i][0] ) == towupper( s[0] ) &&
|
|
|
|
towupper( wkday[i][1] ) == towupper( s[1] ) &&
|
|
|
|
towupper( wkday[i][2] ) == towupper( s[2] ) )
|
2008-08-15 14:44:16 +02:00
|
|
|
{
|
|
|
|
time->wDayOfWeek = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time->wDayOfWeek > 6) return TRUE;
|
2019-11-20 14:29:08 +01:00
|
|
|
while (*s && !iswdigit( *s )) s++;
|
|
|
|
time->wDay = wcstol( s, &end, 10 );
|
2008-08-15 14:44:16 +02:00
|
|
|
s = end;
|
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
while (*s && !iswalpha( *s )) s++;
|
2008-08-15 14:44:16 +02:00
|
|
|
if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
|
|
|
|
time->wMonth = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 12; i++)
|
|
|
|
{
|
2019-11-20 14:29:08 +01:00
|
|
|
if (towupper( month[i][0]) == towupper( s[0] ) &&
|
|
|
|
towupper( month[i][1]) == towupper( s[1] ) &&
|
|
|
|
towupper( month[i][2]) == towupper( s[2] ) )
|
2008-08-15 14:44:16 +02:00
|
|
|
{
|
|
|
|
time->wMonth = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (time->wMonth == 0) return TRUE;
|
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
while (*s && !iswdigit( *s )) s++;
|
2008-08-15 14:44:16 +02:00
|
|
|
if (*s == '\0') return TRUE;
|
2019-11-20 14:29:08 +01:00
|
|
|
time->wYear = wcstol( s, &end, 10 );
|
2008-08-15 14:44:16 +02:00
|
|
|
s = end;
|
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
while (*s && !iswdigit( *s )) s++;
|
2008-08-15 14:44:16 +02:00
|
|
|
if (*s == '\0') return TRUE;
|
2019-11-20 14:29:08 +01:00
|
|
|
time->wHour = wcstol( s, &end, 10 );
|
2008-08-15 14:44:16 +02:00
|
|
|
s = end;
|
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
while (*s && !iswdigit( *s )) s++;
|
2008-08-15 14:44:16 +02:00
|
|
|
if (*s == '\0') return TRUE;
|
2019-11-20 14:29:08 +01:00
|
|
|
time->wMinute = wcstol( s, &end, 10 );
|
2008-08-15 14:44:16 +02:00
|
|
|
s = end;
|
|
|
|
|
2019-11-20 14:29:08 +01:00
|
|
|
while (*s && !iswdigit( *s )) s++;
|
2008-08-15 14:44:16 +02:00
|
|
|
if (*s == '\0') return TRUE;
|
2019-11-20 14:29:08 +01:00
|
|
|
time->wSecond = wcstol( s, &end, 10 );
|
2008-08-15 14:44:16 +02:00
|
|
|
|
|
|
|
time->wMilliseconds = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|