2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2012-05-15 10:15:32 +02:00
|
|
|
* Wininet - HTTP Implementation
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
|
|
|
* Copyright 1999 Corel Corporation
|
2002-06-22 01:59:49 +02:00
|
|
|
* Copyright 2002 CodeWeavers Inc.
|
2003-06-21 01:26:56 +02:00
|
|
|
* Copyright 2002 TransGaming Technologies Inc.
|
2004-02-09 23:07:42 +01:00
|
|
|
* Copyright 2004 Mike McCormack for CodeWeavers
|
2005-11-21 16:17:55 +01:00
|
|
|
* Copyright 2005 Aric Stewart for CodeWeavers
|
2007-01-04 19:23:17 +01:00
|
|
|
* Copyright 2006 Robert Shearman for CodeWeavers
|
2011-04-02 15:20:33 +02:00
|
|
|
* Copyright 2011 Jacek Caban for CodeWeavers
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
|
|
|
* Ulrich Czekalla
|
2003-06-21 01:26:56 +02:00
|
|
|
* David Hammerton
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
|
|
|
|
2000-06-23 17:47:14 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-06-29 17:21:03 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-02-13 12:12:29 +01:00
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
# include <zlib.h>
|
2008-12-09 11:33:25 +01:00
|
|
|
#endif
|
|
|
|
|
2015-02-16 11:17:08 +01:00
|
|
|
#include "winsock2.h"
|
|
|
|
#include "ws2ipdef.h"
|
2015-02-13 12:12:29 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-06-11 22:04:44 +02:00
|
|
|
#include <stdio.h>
|
2001-02-15 22:24:07 +01:00
|
|
|
#include <time.h>
|
2004-07-19 23:49:39 +02:00
|
|
|
#include <assert.h>
|
2016-06-29 17:21:03 +02:00
|
|
|
|
2001-11-06 23:31:19 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wininet.h"
|
|
|
|
#include "winerror.h"
|
2011-03-03 19:54:07 +01:00
|
|
|
#include "winternl.h"
|
2001-12-11 01:30:17 +01:00
|
|
|
#define NO_SHLWAPI_STREAM
|
2005-11-30 12:01:50 +01:00
|
|
|
#define NO_SHLWAPI_REG
|
|
|
|
#define NO_SHLWAPI_STRFCNS
|
|
|
|
#define NO_SHLWAPI_GDI
|
2001-11-06 23:31:19 +01:00
|
|
|
#include "shlwapi.h"
|
2007-05-21 15:26:26 +02:00
|
|
|
#include "sspi.h"
|
2008-03-12 02:24:23 +01:00
|
|
|
#include "wincrypt.h"
|
2011-10-31 20:55:15 +01:00
|
|
|
#include "winuser.h"
|
2001-11-06 23:31:19 +01:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
#include "internet.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2008-10-24 11:08:12 +02:00
|
|
|
#include "wine/exception.h"
|
2002-11-12 03:13:04 +01:00
|
|
|
#include "wine/unicode.h"
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2008-03-24 21:31:53 +01:00
|
|
|
static const WCHAR g_szHttp1_0[] = {'H','T','T','P','/','1','.','0',0};
|
2008-02-17 20:41:42 +01:00
|
|
|
static const WCHAR g_szHttp1_1[] = {'H','T','T','P','/','1','.','1',0};
|
2010-02-22 12:28:03 +01:00
|
|
|
static const WCHAR szOK[] = {'O','K',0};
|
2009-05-29 23:34:14 +02:00
|
|
|
static const WCHAR hostW[] = { 'H','o','s','t',0 };
|
2007-05-21 15:26:26 +02:00
|
|
|
static const WCHAR szAuthorization[] = { 'A','u','t','h','o','r','i','z','a','t','i','o','n',0 };
|
2005-12-13 17:07:41 +01:00
|
|
|
static const WCHAR szProxy_Authorization[] = { 'P','r','o','x','y','-','A','u','t','h','o','r','i','z','a','t','i','o','n',0 };
|
|
|
|
static const WCHAR szStatus[] = { 'S','t','a','t','u','s',0 };
|
2007-01-04 19:23:17 +01:00
|
|
|
static const WCHAR szKeepAlive[] = {'K','e','e','p','-','A','l','i','v','e',0};
|
2008-02-13 13:34:05 +01:00
|
|
|
static const WCHAR szGET[] = { 'G','E','T', 0 };
|
2009-07-22 11:56:33 +02:00
|
|
|
static const WCHAR szHEAD[] = { 'H','E','A','D', 0 };
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2009-05-29 23:34:14 +02:00
|
|
|
static const WCHAR szAccept[] = { 'A','c','c','e','p','t',0 };
|
|
|
|
static const WCHAR szAccept_Charset[] = { 'A','c','c','e','p','t','-','C','h','a','r','s','e','t', 0 };
|
|
|
|
static const WCHAR szAccept_Encoding[] = { 'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',0 };
|
|
|
|
static const WCHAR szAccept_Language[] = { 'A','c','c','e','p','t','-','L','a','n','g','u','a','g','e',0 };
|
|
|
|
static const WCHAR szAccept_Ranges[] = { 'A','c','c','e','p','t','-','R','a','n','g','e','s',0 };
|
|
|
|
static const WCHAR szAge[] = { 'A','g','e',0 };
|
|
|
|
static const WCHAR szAllow[] = { 'A','l','l','o','w',0 };
|
|
|
|
static const WCHAR szCache_Control[] = { 'C','a','c','h','e','-','C','o','n','t','r','o','l',0 };
|
|
|
|
static const WCHAR szConnection[] = { 'C','o','n','n','e','c','t','i','o','n',0 };
|
|
|
|
static const WCHAR szContent_Base[] = { 'C','o','n','t','e','n','t','-','B','a','s','e',0 };
|
2012-05-23 15:49:24 +02:00
|
|
|
static const WCHAR szContent_Disposition[] = { 'C','o','n','t','e','n','t','-','D','i','s','p','o','s','i','t','i','o','n',0 };
|
2009-05-29 23:34:14 +02:00
|
|
|
static const WCHAR szContent_Encoding[] = { 'C','o','n','t','e','n','t','-','E','n','c','o','d','i','n','g',0 };
|
|
|
|
static const WCHAR szContent_ID[] = { 'C','o','n','t','e','n','t','-','I','D',0 };
|
|
|
|
static const WCHAR szContent_Language[] = { 'C','o','n','t','e','n','t','-','L','a','n','g','u','a','g','e',0 };
|
|
|
|
static const WCHAR szContent_Length[] = { 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0 };
|
|
|
|
static const WCHAR szContent_Location[] = { 'C','o','n','t','e','n','t','-','L','o','c','a','t','i','o','n',0 };
|
|
|
|
static const WCHAR szContent_MD5[] = { 'C','o','n','t','e','n','t','-','M','D','5',0 };
|
|
|
|
static const WCHAR szContent_Range[] = { 'C','o','n','t','e','n','t','-','R','a','n','g','e',0 };
|
|
|
|
static const WCHAR szContent_Transfer_Encoding[] = { 'C','o','n','t','e','n','t','-','T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0 };
|
|
|
|
static const WCHAR szContent_Type[] = { 'C','o','n','t','e','n','t','-','T','y','p','e',0 };
|
|
|
|
static const WCHAR szCookie[] = { 'C','o','o','k','i','e',0 };
|
|
|
|
static const WCHAR szDate[] = { 'D','a','t','e',0 };
|
|
|
|
static const WCHAR szFrom[] = { 'F','r','o','m',0 };
|
|
|
|
static const WCHAR szETag[] = { 'E','T','a','g',0 };
|
|
|
|
static const WCHAR szExpect[] = { 'E','x','p','e','c','t',0 };
|
|
|
|
static const WCHAR szExpires[] = { 'E','x','p','i','r','e','s',0 };
|
|
|
|
static const WCHAR szIf_Match[] = { 'I','f','-','M','a','t','c','h',0 };
|
|
|
|
static const WCHAR szIf_Modified_Since[] = { 'I','f','-','M','o','d','i','f','i','e','d','-','S','i','n','c','e',0 };
|
|
|
|
static const WCHAR szIf_None_Match[] = { 'I','f','-','N','o','n','e','-','M','a','t','c','h',0 };
|
|
|
|
static const WCHAR szIf_Range[] = { 'I','f','-','R','a','n','g','e',0 };
|
|
|
|
static const WCHAR szIf_Unmodified_Since[] = { 'I','f','-','U','n','m','o','d','i','f','i','e','d','-','S','i','n','c','e',0 };
|
|
|
|
static const WCHAR szLast_Modified[] = { 'L','a','s','t','-','M','o','d','i','f','i','e','d',0 };
|
|
|
|
static const WCHAR szLocation[] = { 'L','o','c','a','t','i','o','n',0 };
|
|
|
|
static const WCHAR szMax_Forwards[] = { 'M','a','x','-','F','o','r','w','a','r','d','s',0 };
|
|
|
|
static const WCHAR szMime_Version[] = { 'M','i','m','e','-','V','e','r','s','i','o','n',0 };
|
|
|
|
static const WCHAR szPragma[] = { 'P','r','a','g','m','a',0 };
|
|
|
|
static const WCHAR szProxy_Authenticate[] = { 'P','r','o','x','y','-','A','u','t','h','e','n','t','i','c','a','t','e',0 };
|
|
|
|
static const WCHAR szProxy_Connection[] = { 'P','r','o','x','y','-','C','o','n','n','e','c','t','i','o','n',0 };
|
|
|
|
static const WCHAR szPublic[] = { 'P','u','b','l','i','c',0 };
|
|
|
|
static const WCHAR szRange[] = { 'R','a','n','g','e',0 };
|
|
|
|
static const WCHAR szReferer[] = { 'R','e','f','e','r','e','r',0 };
|
|
|
|
static const WCHAR szRetry_After[] = { 'R','e','t','r','y','-','A','f','t','e','r',0 };
|
|
|
|
static const WCHAR szServer[] = { 'S','e','r','v','e','r',0 };
|
|
|
|
static const WCHAR szSet_Cookie[] = { 'S','e','t','-','C','o','o','k','i','e',0 };
|
|
|
|
static const WCHAR szTransfer_Encoding[] = { 'T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0 };
|
|
|
|
static const WCHAR szUnless_Modified_Since[] = { 'U','n','l','e','s','s','-','M','o','d','i','f','i','e','d','-','S','i','n','c','e',0 };
|
|
|
|
static const WCHAR szUpgrade[] = { 'U','p','g','r','a','d','e',0 };
|
|
|
|
static const WCHAR szURI[] = { 'U','R','I',0 };
|
|
|
|
static const WCHAR szUser_Agent[] = { 'U','s','e','r','-','A','g','e','n','t',0 };
|
|
|
|
static const WCHAR szVary[] = { 'V','a','r','y',0 };
|
|
|
|
static const WCHAR szVia[] = { 'V','i','a',0 };
|
|
|
|
static const WCHAR szWarning[] = { 'W','a','r','n','i','n','g',0 };
|
|
|
|
static const WCHAR szWWW_Authenticate[] = { 'W','W','W','-','A','u','t','h','e','n','t','i','c','a','t','e',0 };
|
|
|
|
|
2013-07-19 12:02:18 +02:00
|
|
|
static const WCHAR emptyW[] = {0};
|
|
|
|
|
2009-05-29 23:34:14 +02:00
|
|
|
#define HTTP_REFERER szReferer
|
|
|
|
#define HTTP_ACCEPT szAccept
|
|
|
|
#define HTTP_USERAGENT szUser_Agent
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
#define HTTP_ADDHDR_FLAG_ADD 0x20000000
|
|
|
|
#define HTTP_ADDHDR_FLAG_ADD_IF_NEW 0x10000000
|
|
|
|
#define HTTP_ADDHDR_FLAG_COALESCE 0x40000000
|
|
|
|
#define HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA 0x40000000
|
|
|
|
#define HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON 0x01000000
|
|
|
|
#define HTTP_ADDHDR_FLAG_REPLACE 0x80000000
|
|
|
|
#define HTTP_ADDHDR_FLAG_REQ 0x02000000
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
#define COLLECT_TIME 60000
|
|
|
|
|
2007-05-21 15:26:26 +02:00
|
|
|
#define ARRAYSIZE(array) (sizeof(array)/sizeof((array)[0]))
|
|
|
|
|
|
|
|
struct HttpAuthInfo
|
|
|
|
{
|
|
|
|
LPWSTR scheme;
|
|
|
|
CredHandle cred;
|
|
|
|
CtxtHandle ctx;
|
|
|
|
TimeStamp exp;
|
|
|
|
ULONG attr;
|
2008-03-10 17:41:44 +01:00
|
|
|
ULONG max_token;
|
2007-05-21 15:26:26 +02:00
|
|
|
void *auth_data;
|
|
|
|
unsigned int auth_data_len;
|
|
|
|
BOOL finished; /* finished authenticating */
|
|
|
|
};
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2009-05-29 23:35:13 +02:00
|
|
|
|
2010-07-17 14:08:44 +02:00
|
|
|
typedef struct _basicAuthorizationData
|
2009-10-12 21:24:18 +02:00
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
|
2011-03-01 19:30:46 +01:00
|
|
|
LPWSTR host;
|
|
|
|
LPWSTR realm;
|
|
|
|
LPSTR authorization;
|
|
|
|
UINT authorizationLen;
|
2010-07-17 14:08:44 +02:00
|
|
|
} basicAuthorizationData;
|
|
|
|
|
|
|
|
typedef struct _authorizationData
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
|
|
|
|
LPWSTR host;
|
|
|
|
LPWSTR scheme;
|
|
|
|
LPWSTR domain;
|
|
|
|
UINT domain_len;
|
|
|
|
LPWSTR user;
|
|
|
|
UINT user_len;
|
|
|
|
LPWSTR password;
|
|
|
|
UINT password_len;
|
2009-10-12 21:24:18 +02:00
|
|
|
} authorizationData;
|
|
|
|
|
|
|
|
static struct list basicAuthorizationCache = LIST_INIT(basicAuthorizationCache);
|
2010-07-17 14:08:44 +02:00
|
|
|
static struct list authorizationCache = LIST_INIT(authorizationCache);
|
2009-10-12 21:24:18 +02:00
|
|
|
|
|
|
|
static CRITICAL_SECTION authcache_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &authcache_cs,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": authcache_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION authcache_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2013-04-25 10:15:19 +02:00
|
|
|
static DWORD HTTP_GetResponseHeaders(http_request_t *req, INT *len);
|
2009-11-30 20:01:00 +01:00
|
|
|
static DWORD HTTP_ProcessHeader(http_request_t *req, LPCWSTR field, LPCWSTR value, DWORD dwModifier);
|
2005-10-26 12:07:58 +02:00
|
|
|
static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer);
|
2009-11-30 20:01:00 +01:00
|
|
|
static DWORD HTTP_InsertCustomHeader(http_request_t *req, LPHTTPHEADERW lpHdr);
|
2009-07-13 01:41:50 +02:00
|
|
|
static INT HTTP_GetCustomHeaderIndex(http_request_t *req, LPCWSTR lpszField, INT index, BOOL Request);
|
|
|
|
static BOOL HTTP_DeleteCustomHeader(http_request_t *req, DWORD index);
|
2005-11-21 16:17:55 +01:00
|
|
|
static LPWSTR HTTP_build_req( LPCWSTR *list, int len );
|
2009-12-14 02:27:29 +01:00
|
|
|
static DWORD HTTP_HttpQueryInfoW(http_request_t*, DWORD, LPVOID, LPDWORD, LPDWORD);
|
2007-05-21 15:26:26 +02:00
|
|
|
static UINT HTTP_DecodeBase64(LPCWSTR base64, LPSTR bin);
|
2012-07-02 17:15:04 +02:00
|
|
|
static BOOL drain_content(http_request_t*,BOOL);
|
2011-05-10 11:26:43 +02:00
|
|
|
|
|
|
|
static CRITICAL_SECTION connection_pool_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG connection_pool_debug =
|
|
|
|
{
|
|
|
|
0, 0, &connection_pool_cs,
|
2017-07-07 18:24:05 +02:00
|
|
|
{ &connection_pool_debug.ProcessLocksList, &connection_pool_debug.ProcessLocksList },
|
2011-05-10 11:26:43 +02:00
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": connection_pool_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION connection_pool_cs = { &connection_pool_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
static struct list connection_pool = LIST_INIT(connection_pool);
|
|
|
|
static BOOL collector_running;
|
|
|
|
|
|
|
|
void server_addref(server_t *server)
|
|
|
|
{
|
|
|
|
InterlockedIncrement(&server->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
void server_release(server_t *server)
|
|
|
|
{
|
|
|
|
if(InterlockedDecrement(&server->ref))
|
|
|
|
return;
|
|
|
|
|
2012-05-25 16:35:32 +02:00
|
|
|
list_remove(&server->entry);
|
|
|
|
|
2012-06-11 10:22:38 +02:00
|
|
|
if(server->cert_chain)
|
|
|
|
CertFreeCertificateChain(server->cert_chain);
|
2012-05-25 16:35:32 +02:00
|
|
|
heap_free(server->name);
|
2012-11-19 11:47:19 +01:00
|
|
|
heap_free(server->scheme_host_port);
|
2012-05-25 16:35:32 +02:00
|
|
|
heap_free(server);
|
2011-05-10 11:26:43 +02:00
|
|
|
}
|
|
|
|
|
2012-11-19 11:47:19 +01:00
|
|
|
static BOOL process_host_port(server_t *server)
|
|
|
|
{
|
|
|
|
BOOL default_port;
|
|
|
|
size_t name_len;
|
|
|
|
WCHAR *buf;
|
|
|
|
|
|
|
|
static const WCHAR httpW[] = {'h','t','t','p',0};
|
|
|
|
static const WCHAR httpsW[] = {'h','t','t','p','s',0};
|
|
|
|
static const WCHAR formatW[] = {'%','s',':','/','/','%','s',':','%','u',0};
|
|
|
|
|
|
|
|
name_len = strlenW(server->name);
|
|
|
|
buf = heap_alloc((name_len + 10 /* strlen("://:<port>") */)*sizeof(WCHAR) + sizeof(httpsW));
|
|
|
|
if(!buf)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
sprintfW(buf, formatW, server->is_https ? httpsW : httpW, server->name, server->port);
|
|
|
|
server->scheme_host_port = buf;
|
|
|
|
|
|
|
|
server->host_port = server->scheme_host_port + 7 /* strlen("http://") */;
|
|
|
|
if(server->is_https)
|
|
|
|
server->host_port++;
|
|
|
|
|
|
|
|
default_port = server->port == (server->is_https ? INTERNET_DEFAULT_HTTPS_PORT : INTERNET_DEFAULT_HTTP_PORT);
|
|
|
|
server->canon_host_port = default_port ? server->name : server->host_port;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-17 19:18:32 +02:00
|
|
|
server_t *get_server(substr_t name, INTERNET_PORT port, BOOL is_https, BOOL do_create)
|
2011-05-10 11:26:43 +02:00
|
|
|
{
|
|
|
|
server_t *iter, *server = NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection(&connection_pool_cs);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(iter, &connection_pool, server_t, entry) {
|
2016-05-17 19:18:32 +02:00
|
|
|
if(iter->port == port && name.len == strlenW(iter->name) && !strncmpW(iter->name, name.str, name.len)
|
|
|
|
&& iter->is_https == is_https) {
|
2011-05-10 11:26:43 +02:00
|
|
|
server = iter;
|
|
|
|
server_addref(server);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 10:22:38 +02:00
|
|
|
if(!server && do_create) {
|
|
|
|
server = heap_alloc_zero(sizeof(*server));
|
2011-05-10 11:26:43 +02:00
|
|
|
if(server) {
|
2012-05-25 16:35:32 +02:00
|
|
|
server->ref = 2; /* list reference and return */
|
2011-05-10 11:26:43 +02:00
|
|
|
server->port = port;
|
2012-11-19 11:46:50 +01:00
|
|
|
server->is_https = is_https;
|
2011-05-10 11:26:43 +02:00
|
|
|
list_init(&server->conn_pool);
|
2016-05-17 19:18:32 +02:00
|
|
|
server->name = heap_strndupW(name.str, name.len);
|
2012-11-19 11:47:19 +01:00
|
|
|
if(server->name && process_host_port(server)) {
|
2011-05-10 11:26:43 +02:00
|
|
|
list_add_head(&connection_pool, &server->entry);
|
|
|
|
}else {
|
|
|
|
heap_free(server);
|
|
|
|
server = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&connection_pool_cs);
|
|
|
|
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
2012-05-25 16:35:48 +02:00
|
|
|
BOOL collect_connections(collect_type_t collect_type)
|
2011-05-10 11:26:43 +02:00
|
|
|
{
|
|
|
|
netconn_t *netconn, *netconn_safe;
|
|
|
|
server_t *server, *server_safe;
|
|
|
|
BOOL remaining = FALSE;
|
|
|
|
DWORD64 now;
|
|
|
|
|
|
|
|
now = GetTickCount64();
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(server, server_safe, &connection_pool, server_t, entry) {
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(netconn, netconn_safe, &server->conn_pool, netconn_t, pool_entry) {
|
2012-05-25 16:35:48 +02:00
|
|
|
if(collect_type > COLLECT_TIMEOUT || netconn->keep_until < now) {
|
2011-05-10 11:26:43 +02:00
|
|
|
TRACE("freeing %p\n", netconn);
|
|
|
|
list_remove(&netconn->pool_entry);
|
|
|
|
free_netconn(netconn);
|
|
|
|
}else {
|
|
|
|
remaining = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 16:35:48 +02:00
|
|
|
if(collect_type == COLLECT_CLEANUP) {
|
2012-05-25 16:35:32 +02:00
|
|
|
list_remove(&server->entry);
|
|
|
|
list_init(&server->entry);
|
|
|
|
server_release(server);
|
2011-05-10 11:26:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return remaining;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI collect_connections_proc(void *arg)
|
|
|
|
{
|
|
|
|
BOOL remaining_conns;
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* FIXME: Use more sophisticated method */
|
|
|
|
Sleep(5000);
|
|
|
|
|
|
|
|
EnterCriticalSection(&connection_pool_cs);
|
|
|
|
|
2012-05-25 16:35:48 +02:00
|
|
|
remaining_conns = collect_connections(COLLECT_TIMEOUT);
|
2011-05-10 11:26:43 +02:00
|
|
|
if(!remaining_conns)
|
|
|
|
collector_running = FALSE;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&connection_pool_cs);
|
|
|
|
}while(remaining_conns);
|
|
|
|
|
|
|
|
FreeLibraryAndExitThread(WININET_hModule, 0);
|
|
|
|
}
|
2005-12-13 17:07:41 +01:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetHeader (internal)
|
|
|
|
*
|
|
|
|
* Headers section must be held
|
|
|
|
*/
|
2009-07-13 01:41:50 +02:00
|
|
|
static LPHTTPHEADERW HTTP_GetHeader(http_request_t *req, LPCWSTR head)
|
2005-12-13 17:07:41 +01:00
|
|
|
{
|
|
|
|
int HeaderIndex = 0;
|
|
|
|
HeaderIndex = HTTP_GetCustomHeaderIndex(req, head, 0, TRUE);
|
|
|
|
if (HeaderIndex == -1)
|
|
|
|
return NULL;
|
|
|
|
else
|
2011-03-01 20:18:22 +01:00
|
|
|
return &req->custHeaders[HeaderIndex];
|
2005-12-13 17:07:41 +01:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
static WCHAR *get_host_header( http_request_t *req )
|
|
|
|
{
|
|
|
|
HTTPHEADERW *header;
|
|
|
|
WCHAR *ret = NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection( &req->headers_section );
|
|
|
|
if ((header = HTTP_GetHeader( req, hostW ))) ret = heap_strdupW( header->lpszValue );
|
2015-08-25 07:26:43 +02:00
|
|
|
else ret = heap_strdupW( req->server->canon_host_port );
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &req->headers_section );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
struct data_stream_vtbl_t {
|
|
|
|
BOOL (*end_of_data)(data_stream_t*,http_request_t*);
|
2017-03-09 18:20:28 +01:00
|
|
|
DWORD (*read)(data_stream_t*,http_request_t*,BYTE*,DWORD,DWORD*,BOOL);
|
2011-05-10 11:26:43 +02:00
|
|
|
BOOL (*drain_content)(data_stream_t*,http_request_t*);
|
2011-04-02 15:20:33 +02:00
|
|
|
void (*destroy)(data_stream_t*);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
data_stream_t data_stream;
|
|
|
|
|
|
|
|
BYTE buf[READ_BUFFER_SIZE];
|
|
|
|
DWORD buf_size;
|
|
|
|
DWORD buf_pos;
|
|
|
|
DWORD chunk_size;
|
2016-08-01 16:17:00 +02:00
|
|
|
|
|
|
|
enum {
|
|
|
|
CHUNKED_STREAM_STATE_READING_CHUNK_SIZE,
|
|
|
|
CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_SIZE,
|
|
|
|
CHUNKED_STREAM_STATE_READING_CHUNK,
|
|
|
|
CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_DATA,
|
|
|
|
CHUNKED_STREAM_STATE_DISCARD_EOL_AT_END,
|
|
|
|
CHUNKED_STREAM_STATE_END_OF_STREAM
|
|
|
|
} state;
|
2011-04-02 15:20:33 +02:00
|
|
|
} chunked_stream_t;
|
|
|
|
|
2011-04-05 16:18:38 +02:00
|
|
|
static inline void destroy_data_stream(data_stream_t *stream)
|
2011-04-02 15:20:33 +02:00
|
|
|
{
|
|
|
|
stream->vtbl->destroy(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_data_stream(http_request_t *req)
|
|
|
|
{
|
|
|
|
destroy_data_stream(req->data_stream);
|
|
|
|
req->data_stream = &req->netconn_stream.data_stream;
|
|
|
|
req->read_pos = req->read_size = req->netconn_stream.content_read = 0;
|
2015-06-12 19:46:04 +02:00
|
|
|
req->read_gzip = FALSE;
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
|
|
|
|
2014-12-19 16:49:48 +01:00
|
|
|
static void remove_header( http_request_t *request, const WCHAR *str, BOOL from_request )
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
index = HTTP_GetCustomHeaderIndex( request, str, 0, from_request );
|
|
|
|
if (index != -1) HTTP_DeleteCustomHeader( request, index );
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
|
|
|
}
|
|
|
|
|
2009-05-29 23:35:13 +02:00
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
typedef struct {
|
|
|
|
data_stream_t stream;
|
|
|
|
data_stream_t *parent_stream;
|
|
|
|
z_stream zstream;
|
|
|
|
BYTE buf[READ_BUFFER_SIZE];
|
|
|
|
DWORD buf_size;
|
|
|
|
DWORD buf_pos;
|
|
|
|
BOOL end_of_data;
|
|
|
|
} gzip_stream_t;
|
|
|
|
|
|
|
|
static BOOL gzip_end_of_data(data_stream_t *stream, http_request_t *req)
|
|
|
|
{
|
|
|
|
gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
|
2014-03-05 18:28:33 +01:00
|
|
|
return gzip_stream->end_of_data
|
|
|
|
|| (!gzip_stream->buf_size && gzip_stream->parent_stream->vtbl->end_of_data(gzip_stream->parent_stream, req));
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD gzip_read(data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size,
|
2017-03-09 18:20:28 +01:00
|
|
|
DWORD *read, BOOL allow_blocking)
|
2011-04-02 15:20:33 +02:00
|
|
|
{
|
|
|
|
gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
|
|
|
|
z_stream *zstream = &gzip_stream->zstream;
|
|
|
|
DWORD current_read, ret_read = 0;
|
|
|
|
int zres;
|
|
|
|
DWORD res = ERROR_SUCCESS;
|
|
|
|
|
2017-03-09 18:20:28 +01:00
|
|
|
TRACE("(%d %x)\n", size, allow_blocking);
|
2014-03-05 18:28:33 +01:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
while(size && !gzip_stream->end_of_data) {
|
2014-03-05 18:28:24 +01:00
|
|
|
if(!gzip_stream->buf_size) {
|
2011-04-02 15:20:33 +02:00
|
|
|
if(gzip_stream->buf_pos) {
|
|
|
|
if(gzip_stream->buf_size)
|
|
|
|
memmove(gzip_stream->buf, gzip_stream->buf+gzip_stream->buf_pos, gzip_stream->buf_size);
|
|
|
|
gzip_stream->buf_pos = 0;
|
|
|
|
}
|
|
|
|
res = gzip_stream->parent_stream->vtbl->read(gzip_stream->parent_stream, req, gzip_stream->buf+gzip_stream->buf_size,
|
2017-03-09 18:20:28 +01:00
|
|
|
sizeof(gzip_stream->buf)-gzip_stream->buf_size, ¤t_read, allow_blocking);
|
2011-04-02 15:20:33 +02:00
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
break;
|
2014-03-05 18:28:24 +01:00
|
|
|
|
2017-04-07 17:31:02 +02:00
|
|
|
gzip_stream->buf_size += current_read;
|
2014-03-05 18:28:24 +01:00
|
|
|
if(!current_read) {
|
2017-03-09 18:18:10 +01:00
|
|
|
WARN("unexpected end of data\n");
|
|
|
|
gzip_stream->end_of_data = TRUE;
|
2011-04-02 15:20:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zstream->next_in = gzip_stream->buf+gzip_stream->buf_pos;
|
2014-03-05 18:28:24 +01:00
|
|
|
zstream->avail_in = gzip_stream->buf_size;
|
2011-04-02 15:20:33 +02:00
|
|
|
zstream->next_out = buf+ret_read;
|
|
|
|
zstream->avail_out = size;
|
|
|
|
zres = inflate(&gzip_stream->zstream, 0);
|
|
|
|
current_read = size - zstream->avail_out;
|
|
|
|
size -= current_read;
|
|
|
|
ret_read += current_read;
|
|
|
|
gzip_stream->buf_size -= zstream->next_in - (gzip_stream->buf+gzip_stream->buf_pos);
|
|
|
|
gzip_stream->buf_pos = zstream->next_in-gzip_stream->buf;
|
|
|
|
if(zres == Z_STREAM_END) {
|
|
|
|
TRACE("end of data\n");
|
|
|
|
gzip_stream->end_of_data = TRUE;
|
|
|
|
inflateEnd(zstream);
|
|
|
|
}else if(zres != Z_OK) {
|
|
|
|
WARN("inflate failed %d: %s\n", zres, debugstr_a(zstream->msg));
|
|
|
|
if(!ret_read)
|
|
|
|
res = ERROR_INTERNET_DECODING_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-09 18:20:28 +01:00
|
|
|
if(ret_read)
|
|
|
|
allow_blocking = FALSE;
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("read %u bytes\n", ret_read);
|
2017-03-09 18:18:10 +01:00
|
|
|
if(ret_read)
|
|
|
|
res = ERROR_SUCCESS;
|
2011-04-02 15:20:33 +02:00
|
|
|
*read = ret_read;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
static BOOL gzip_drain_content(data_stream_t *stream, http_request_t *req)
|
|
|
|
{
|
|
|
|
gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
|
|
|
|
return gzip_stream->parent_stream->vtbl->drain_content(gzip_stream->parent_stream, req);
|
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
static void gzip_destroy(data_stream_t *stream)
|
|
|
|
{
|
|
|
|
gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
|
|
|
|
|
|
|
|
destroy_data_stream(gzip_stream->parent_stream);
|
|
|
|
|
|
|
|
if(!gzip_stream->end_of_data)
|
|
|
|
inflateEnd(&gzip_stream->zstream);
|
|
|
|
heap_free(gzip_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const data_stream_vtbl_t gzip_stream_vtbl = {
|
|
|
|
gzip_end_of_data,
|
|
|
|
gzip_read,
|
2011-05-10 11:26:43 +02:00
|
|
|
gzip_drain_content,
|
2011-04-02 15:20:33 +02:00
|
|
|
gzip_destroy
|
|
|
|
};
|
|
|
|
|
2009-05-29 23:35:13 +02:00
|
|
|
static voidpf wininet_zalloc(voidpf opaque, uInt items, uInt size)
|
|
|
|
{
|
2011-04-21 13:39:03 +02:00
|
|
|
return heap_alloc(items*size);
|
2009-05-29 23:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wininet_zfree(voidpf opaque, voidpf address)
|
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(address);
|
2009-05-29 23:35:13 +02:00
|
|
|
}
|
|
|
|
|
2014-03-05 18:28:33 +01:00
|
|
|
static DWORD init_gzip_stream(http_request_t *req, BOOL is_gzip)
|
2009-05-29 23:35:13 +02:00
|
|
|
{
|
|
|
|
gzip_stream_t *gzip_stream;
|
2014-12-19 16:49:48 +01:00
|
|
|
int zres;
|
2009-05-29 23:35:13 +02:00
|
|
|
|
2011-03-15 00:08:34 +01:00
|
|
|
gzip_stream = heap_alloc_zero(sizeof(gzip_stream_t));
|
2011-04-02 15:20:33 +02:00
|
|
|
if(!gzip_stream)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
gzip_stream->stream.vtbl = &gzip_stream_vtbl;
|
2009-05-29 23:35:13 +02:00
|
|
|
gzip_stream->zstream.zalloc = wininet_zalloc;
|
|
|
|
gzip_stream->zstream.zfree = wininet_zfree;
|
|
|
|
|
2014-03-05 18:28:33 +01:00
|
|
|
zres = inflateInit2(&gzip_stream->zstream, is_gzip ? 0x1f : -15);
|
2009-05-29 23:35:13 +02:00
|
|
|
if(zres != Z_OK) {
|
|
|
|
ERR("inflateInit failed: %d\n", zres);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(gzip_stream);
|
2011-04-02 15:20:33 +02:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2009-05-29 23:35:13 +02:00
|
|
|
}
|
|
|
|
|
2014-12-19 16:49:48 +01:00
|
|
|
remove_header(req, szContent_Length, FALSE);
|
2009-05-29 23:35:13 +02:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
if(req->read_size) {
|
|
|
|
memcpy(gzip_stream->buf, req->read_buf+req->read_pos, req->read_size);
|
|
|
|
gzip_stream->buf_size = req->read_size;
|
|
|
|
req->read_pos = req->read_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->read_gzip = TRUE;
|
|
|
|
gzip_stream->parent_stream = req->data_stream;
|
|
|
|
req->data_stream = &gzip_stream->stream;
|
|
|
|
return ERROR_SUCCESS;
|
2011-03-15 00:08:34 +01:00
|
|
|
}
|
|
|
|
|
2009-05-29 23:35:13 +02:00
|
|
|
#else
|
|
|
|
|
2014-03-05 18:28:33 +01:00
|
|
|
static DWORD init_gzip_stream(http_request_t *req, BOOL is_gzip)
|
2009-05-29 23:35:13 +02:00
|
|
|
{
|
|
|
|
ERR("gzip stream not supported, missing zlib.\n");
|
2011-04-02 15:20:33 +02:00
|
|
|
return ERROR_SUCCESS;
|
2011-03-15 00:08:34 +01:00
|
|
|
}
|
|
|
|
|
2009-05-29 23:35:13 +02:00
|
|
|
#endif
|
|
|
|
|
2004-07-19 22:09:20 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_FreeTokens (internal)
|
|
|
|
*
|
2013-04-30 16:58:00 +02:00
|
|
|
* Frees table of pointers.
|
2004-07-19 22:09:20 +02:00
|
|
|
*/
|
|
|
|
static void HTTP_FreeTokens(LPWSTR * token_array)
|
|
|
|
{
|
|
|
|
int i;
|
2011-06-01 11:50:53 +02:00
|
|
|
for (i = 0; token_array[i]; i++) heap_free(token_array[i]);
|
|
|
|
heap_free(token_array);
|
2004-07-19 22:09:20 +02:00
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
static void HTTP_FixURL(http_request_t *request)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
|
|
|
static const WCHAR szSlash[] = { '/',0 };
|
|
|
|
static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/', 0 };
|
|
|
|
|
|
|
|
/* If we don't have a path we set it to root */
|
2011-03-01 20:18:22 +01:00
|
|
|
if (NULL == request->path)
|
|
|
|
request->path = heap_strdupW(szSlash);
|
2005-11-21 16:17:55 +01:00
|
|
|
else /* remove \r and \n*/
|
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
int nLen = strlenW(request->path);
|
|
|
|
while ((nLen >0 ) && ((request->path[nLen-1] == '\r')||(request->path[nLen-1] == '\n')))
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
|
|
|
nLen--;
|
2011-03-01 20:18:22 +01:00
|
|
|
request->path[nLen]='\0';
|
2005-11-21 16:17:55 +01:00
|
|
|
}
|
|
|
|
/* Replace '\' with '/' */
|
|
|
|
while (nLen>0) {
|
|
|
|
nLen--;
|
2011-03-01 20:18:22 +01:00
|
|
|
if (request->path[nLen] == '\\') request->path[nLen]='/';
|
2005-11-21 16:17:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 11:33:05 +02:00
|
|
|
if(CSTR_EQUAL != CompareStringW( LOCALE_INVARIANT, NORM_IGNORECASE,
|
2011-03-01 20:18:22 +01:00
|
|
|
request->path, strlenW(request->path), szHttp, strlenW(szHttp) )
|
|
|
|
&& request->path[0] != '/') /* not an absolute path ?? --> fix it !! */
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2011-04-21 13:39:03 +02:00
|
|
|
WCHAR *fixurl = heap_alloc((strlenW(request->path) + 2)*sizeof(WCHAR));
|
2005-11-21 16:17:55 +01:00
|
|
|
*fixurl = '/';
|
2011-03-01 20:18:22 +01:00
|
|
|
strcpyW(fixurl + 1, request->path);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free( request->path );
|
2011-03-01 20:18:22 +01:00
|
|
|
request->path = fixurl;
|
2005-11-21 16:17:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-30 16:59:33 +02:00
|
|
|
static WCHAR* build_request_header(http_request_t *request, const WCHAR *verb,
|
|
|
|
const WCHAR *path, const WCHAR *version, BOOL use_cr)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2014-09-25 14:21:37 +02:00
|
|
|
static const WCHAR szSpace[] = {' ',0};
|
|
|
|
static const WCHAR szColon[] = {':',' ',0};
|
|
|
|
static const WCHAR szCr[] = {'\r',0};
|
|
|
|
static const WCHAR szLf[] = {'\n',0};
|
2005-11-21 16:17:55 +01:00
|
|
|
LPWSTR requestString;
|
|
|
|
DWORD len, n;
|
|
|
|
LPCWSTR *req;
|
2008-01-12 20:14:04 +01:00
|
|
|
UINT i;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
2005-11-21 16:17:55 +01:00
|
|
|
|
|
|
|
/* allocate space for an array of all the string pointers to be added */
|
2014-09-25 14:21:37 +02:00
|
|
|
len = request->nCustHeaders * 5 + 10;
|
|
|
|
if (!(req = heap_alloc( len * sizeof(const WCHAR *) )))
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2005-11-28 11:55:16 +01:00
|
|
|
/* add the verb, path and HTTP version string */
|
2005-11-21 16:17:55 +01:00
|
|
|
n = 0;
|
2005-11-28 11:55:16 +01:00
|
|
|
req[n++] = verb;
|
2005-11-21 16:17:55 +01:00
|
|
|
req[n++] = szSpace;
|
2005-11-28 11:55:16 +01:00
|
|
|
req[n++] = path;
|
2008-02-17 20:41:42 +01:00
|
|
|
req[n++] = szSpace;
|
|
|
|
req[n++] = version;
|
2013-04-30 16:59:33 +02:00
|
|
|
if (use_cr)
|
|
|
|
req[n++] = szCr;
|
|
|
|
req[n++] = szLf;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2008-01-04 20:37:14 +01:00
|
|
|
/* Append custom request headers */
|
2011-03-01 19:59:39 +01:00
|
|
|
for (i = 0; i < request->nCustHeaders; i++)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
if (request->custHeaders[i].wFlags & HDR_ISREQUEST)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
req[n++] = request->custHeaders[i].lpszField;
|
2005-11-21 16:17:55 +01:00
|
|
|
req[n++] = szColon;
|
2011-03-01 20:18:22 +01:00
|
|
|
req[n++] = request->custHeaders[i].lpszValue;
|
2013-04-30 16:59:33 +02:00
|
|
|
if (use_cr)
|
|
|
|
req[n++] = szCr;
|
|
|
|
req[n++] = szLf;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
|
|
|
TRACE("Adding custom header %s (%s)\n",
|
2011-03-01 20:18:22 +01:00
|
|
|
debugstr_w(request->custHeaders[i].lpszField),
|
|
|
|
debugstr_w(request->custHeaders[i].lpszValue));
|
2005-11-21 16:17:55 +01:00
|
|
|
}
|
|
|
|
}
|
2013-04-30 16:59:33 +02:00
|
|
|
if (use_cr)
|
|
|
|
req[n++] = szCr;
|
|
|
|
req[n++] = szLf;
|
2005-11-21 16:17:55 +01:00
|
|
|
req[n] = NULL;
|
2013-04-30 16:59:33 +02:00
|
|
|
|
2005-11-21 16:17:55 +01:00
|
|
|
requestString = HTTP_build_req( req, 4 );
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free( req );
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2005-11-21 16:17:55 +01:00
|
|
|
return requestString;
|
|
|
|
}
|
|
|
|
|
2013-04-30 16:58:00 +02:00
|
|
|
static WCHAR* build_response_header(http_request_t *request, BOOL use_cr)
|
|
|
|
{
|
|
|
|
static const WCHAR colonW[] = { ':',' ',0 };
|
|
|
|
static const WCHAR crW[] = { '\r',0 };
|
|
|
|
static const WCHAR lfW[] = { '\n',0 };
|
|
|
|
static const WCHAR status_fmt[] = { ' ','%','u',' ',0 };
|
|
|
|
const WCHAR **req;
|
|
|
|
WCHAR *ret, buf[14];
|
|
|
|
DWORD i, n = 0;
|
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
|
|
|
|
if (!(req = heap_alloc( (request->nCustHeaders * 5 + 8) * sizeof(WCHAR *) )))
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2013-04-30 16:58:00 +02:00
|
|
|
return NULL;
|
2014-09-25 14:21:37 +02:00
|
|
|
}
|
2013-04-30 16:58:00 +02:00
|
|
|
|
2013-04-30 17:00:18 +02:00
|
|
|
if (request->status_code)
|
2013-04-30 16:58:00 +02:00
|
|
|
{
|
|
|
|
req[n++] = request->version;
|
|
|
|
sprintfW(buf, status_fmt, request->status_code);
|
|
|
|
req[n++] = buf;
|
|
|
|
req[n++] = request->statusText;
|
|
|
|
if (use_cr)
|
|
|
|
req[n++] = crW;
|
|
|
|
req[n++] = lfW;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < request->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if(!(request->custHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
&& strcmpW(request->custHeaders[i].lpszField, szStatus))
|
|
|
|
{
|
|
|
|
req[n++] = request->custHeaders[i].lpszField;
|
|
|
|
req[n++] = colonW;
|
|
|
|
req[n++] = request->custHeaders[i].lpszValue;
|
|
|
|
if(use_cr)
|
|
|
|
req[n++] = crW;
|
|
|
|
req[n++] = lfW;
|
|
|
|
|
|
|
|
TRACE("Adding custom header %s (%s)\n",
|
|
|
|
debugstr_w(request->custHeaders[i].lpszField),
|
|
|
|
debugstr_w(request->custHeaders[i].lpszValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(use_cr)
|
|
|
|
req[n++] = crW;
|
|
|
|
req[n++] = lfW;
|
|
|
|
req[n] = NULL;
|
|
|
|
|
|
|
|
ret = HTTP_build_req(req, 0);
|
|
|
|
heap_free(req);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2013-04-30 16:58:00 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
static void HTTP_ProcessCookies( http_request_t *request )
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
int HeaderIndex;
|
2008-09-24 22:42:36 +02:00
|
|
|
int numCookies = 0;
|
2005-12-13 17:07:41 +01:00
|
|
|
LPHTTPHEADERW setCookieHeader;
|
|
|
|
|
2011-05-19 16:11:45 +02:00
|
|
|
if(request->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES)
|
|
|
|
return;
|
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
|
2011-05-19 16:11:45 +02:00
|
|
|
while((HeaderIndex = HTTP_GetCustomHeaderIndex(request, szSet_Cookie, numCookies++, FALSE)) != -1)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2011-05-19 16:11:45 +02:00
|
|
|
const WCHAR *data;
|
2016-05-16 22:45:41 +02:00
|
|
|
substr_t name;
|
2011-05-19 16:11:45 +02:00
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
setCookieHeader = &request->custHeaders[HeaderIndex];
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2011-05-19 16:11:45 +02:00
|
|
|
if (!setCookieHeader->lpszValue)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
data = strchrW(setCookieHeader->lpszValue, '=');
|
|
|
|
if(!data)
|
|
|
|
continue;
|
|
|
|
|
2016-05-16 22:45:41 +02:00
|
|
|
name = substr(setCookieHeader->lpszValue, data - setCookieHeader->lpszValue);
|
2011-05-19 16:11:45 +02:00
|
|
|
data++;
|
2016-05-16 22:45:41 +02:00
|
|
|
set_cookie(substrz(request->server->name), substrz(request->path), name, substrz(data), INTERNET_COOKIE_HTTPONLY);
|
2005-11-21 16:17:55 +01:00
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2005-11-21 16:17:55 +01:00
|
|
|
}
|
|
|
|
|
2009-10-12 21:24:18 +02:00
|
|
|
static void strip_spaces(LPWSTR start)
|
|
|
|
{
|
|
|
|
LPWSTR str = start;
|
|
|
|
LPWSTR end;
|
|
|
|
|
2014-10-30 23:38:20 +01:00
|
|
|
while (*str == ' ')
|
2009-10-12 21:24:18 +02:00
|
|
|
str++;
|
|
|
|
|
|
|
|
if (str != start)
|
|
|
|
memmove(start, str, sizeof(WCHAR) * (strlenW(str) + 1));
|
|
|
|
|
|
|
|
end = start + strlenW(start) - 1;
|
|
|
|
while (end >= start && *end == ' ')
|
|
|
|
{
|
|
|
|
*end = '\0';
|
|
|
|
end--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL is_basic_auth_value( LPCWSTR pszAuthValue, LPWSTR *pszRealm )
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
|
|
|
static const WCHAR szBasic[] = {'B','a','s','i','c'}; /* Note: not nul-terminated */
|
2009-10-12 21:24:18 +02:00
|
|
|
static const WCHAR szRealm[] = {'r','e','a','l','m'}; /* Note: not nul-terminated */
|
|
|
|
BOOL is_basic;
|
|
|
|
is_basic = !strncmpiW(pszAuthValue, szBasic, ARRAYSIZE(szBasic)) &&
|
2008-05-15 22:05:21 +02:00
|
|
|
((pszAuthValue[ARRAYSIZE(szBasic)] == ' ') || !pszAuthValue[ARRAYSIZE(szBasic)]);
|
2009-10-12 21:24:18 +02:00
|
|
|
if (is_basic && pszRealm)
|
|
|
|
{
|
|
|
|
LPCWSTR token;
|
|
|
|
LPCWSTR ptr = &pszAuthValue[ARRAYSIZE(szBasic)];
|
|
|
|
LPCWSTR realm;
|
|
|
|
ptr++;
|
|
|
|
*pszRealm=NULL;
|
|
|
|
token = strchrW(ptr,'=');
|
|
|
|
if (!token)
|
|
|
|
return TRUE;
|
|
|
|
realm = ptr;
|
2014-10-30 23:38:20 +01:00
|
|
|
while (*realm == ' ')
|
2009-10-12 21:24:18 +02:00
|
|
|
realm++;
|
|
|
|
if(!strncmpiW(realm, szRealm, ARRAYSIZE(szRealm)) &&
|
|
|
|
(realm[ARRAYSIZE(szRealm)] == ' ' || realm[ARRAYSIZE(szRealm)] == '='))
|
|
|
|
{
|
|
|
|
token++;
|
2014-10-30 23:38:20 +01:00
|
|
|
while (*token == ' ')
|
2009-10-12 21:24:18 +02:00
|
|
|
token++;
|
|
|
|
if (*token == '\0')
|
|
|
|
return TRUE;
|
|
|
|
*pszRealm = heap_strdupW(token);
|
|
|
|
strip_spaces(*pszRealm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_basic;
|
2007-05-21 15:26:26 +02:00
|
|
|
}
|
|
|
|
|
2009-09-02 11:44:43 +02:00
|
|
|
static void destroy_authinfo( struct HttpAuthInfo *authinfo )
|
|
|
|
{
|
|
|
|
if (!authinfo) return;
|
|
|
|
|
|
|
|
if (SecIsValidHandle(&authinfo->ctx))
|
|
|
|
DeleteSecurityContext(&authinfo->ctx);
|
|
|
|
if (SecIsValidHandle(&authinfo->cred))
|
|
|
|
FreeCredentialsHandle(&authinfo->cred);
|
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(authinfo->auth_data);
|
|
|
|
heap_free(authinfo->scheme);
|
|
|
|
heap_free(authinfo);
|
2009-09-02 11:44:43 +02:00
|
|
|
}
|
|
|
|
|
2015-04-30 11:50:26 +02:00
|
|
|
static UINT retrieve_cached_basic_authorization(const WCHAR *host, const WCHAR *realm, char **auth_data)
|
2009-10-12 21:24:18 +02:00
|
|
|
{
|
2010-07-17 14:08:44 +02:00
|
|
|
basicAuthorizationData *ad;
|
2009-10-12 21:24:18 +02:00
|
|
|
UINT rc = 0;
|
|
|
|
|
|
|
|
TRACE("Looking for authorization for %s:%s\n",debugstr_w(host),debugstr_w(realm));
|
|
|
|
|
|
|
|
EnterCriticalSection(&authcache_cs);
|
2010-07-17 14:08:44 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(ad, &basicAuthorizationCache, basicAuthorizationData, entry)
|
2009-10-12 21:24:18 +02:00
|
|
|
{
|
2015-04-30 11:50:26 +02:00
|
|
|
if (!strcmpiW(host, ad->host) && (!realm || !strcmpW(realm, ad->realm)))
|
2009-10-12 21:24:18 +02:00
|
|
|
{
|
|
|
|
TRACE("Authorization found in cache\n");
|
2011-04-21 13:39:03 +02:00
|
|
|
*auth_data = heap_alloc(ad->authorizationLen);
|
2011-03-01 19:30:46 +01:00
|
|
|
memcpy(*auth_data,ad->authorization,ad->authorizationLen);
|
|
|
|
rc = ad->authorizationLen;
|
2009-10-12 21:24:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&authcache_cs);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cache_basic_authorization(LPWSTR host, LPWSTR realm, LPSTR auth_data, UINT auth_data_len)
|
|
|
|
{
|
|
|
|
struct list *cursor;
|
2010-07-17 14:08:44 +02:00
|
|
|
basicAuthorizationData* ad = NULL;
|
2009-10-12 21:24:18 +02:00
|
|
|
|
|
|
|
TRACE("caching authorization for %s:%s = %s\n",debugstr_w(host),debugstr_w(realm),debugstr_an(auth_data,auth_data_len));
|
|
|
|
|
|
|
|
EnterCriticalSection(&authcache_cs);
|
|
|
|
LIST_FOR_EACH(cursor, &basicAuthorizationCache)
|
|
|
|
{
|
2010-07-17 14:08:44 +02:00
|
|
|
basicAuthorizationData *check = LIST_ENTRY(cursor,basicAuthorizationData,entry);
|
2011-03-01 19:30:46 +01:00
|
|
|
if (!strcmpiW(host,check->host) && !strcmpW(realm,check->realm))
|
2009-10-12 21:24:18 +02:00
|
|
|
{
|
|
|
|
ad = check;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ad)
|
|
|
|
{
|
|
|
|
TRACE("Found match in cache, replacing\n");
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(ad->authorization);
|
2011-04-21 13:39:03 +02:00
|
|
|
ad->authorization = heap_alloc(auth_data_len);
|
2011-03-01 19:30:46 +01:00
|
|
|
memcpy(ad->authorization, auth_data, auth_data_len);
|
|
|
|
ad->authorizationLen = auth_data_len;
|
2009-10-12 21:24:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-21 13:39:03 +02:00
|
|
|
ad = heap_alloc(sizeof(basicAuthorizationData));
|
2011-03-01 19:30:46 +01:00
|
|
|
ad->host = heap_strdupW(host);
|
2011-07-28 16:53:57 +02:00
|
|
|
ad->realm = heap_strdupW(realm);
|
2011-04-21 13:39:03 +02:00
|
|
|
ad->authorization = heap_alloc(auth_data_len);
|
2011-03-01 19:30:46 +01:00
|
|
|
memcpy(ad->authorization, auth_data, auth_data_len);
|
|
|
|
ad->authorizationLen = auth_data_len;
|
2009-10-12 21:24:18 +02:00
|
|
|
list_add_head(&basicAuthorizationCache,&ad->entry);
|
|
|
|
TRACE("authorization cached\n");
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&authcache_cs);
|
|
|
|
}
|
|
|
|
|
2010-07-17 14:08:44 +02:00
|
|
|
static BOOL retrieve_cached_authorization(LPWSTR host, LPWSTR scheme,
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_W *nt_auth_identity)
|
|
|
|
{
|
|
|
|
authorizationData *ad;
|
|
|
|
|
|
|
|
TRACE("Looking for authorization for %s:%s\n", debugstr_w(host), debugstr_w(scheme));
|
|
|
|
|
|
|
|
EnterCriticalSection(&authcache_cs);
|
|
|
|
LIST_FOR_EACH_ENTRY(ad, &authorizationCache, authorizationData, entry) {
|
|
|
|
if(!strcmpiW(host, ad->host) && !strcmpiW(scheme, ad->scheme)) {
|
|
|
|
TRACE("Authorization found in cache\n");
|
|
|
|
|
|
|
|
nt_auth_identity->User = heap_strdupW(ad->user);
|
|
|
|
nt_auth_identity->Password = heap_strdupW(ad->password);
|
2011-04-21 13:39:03 +02:00
|
|
|
nt_auth_identity->Domain = heap_alloc(sizeof(WCHAR)*ad->domain_len);
|
2010-07-17 14:08:44 +02:00
|
|
|
if(!nt_auth_identity->User || !nt_auth_identity->Password ||
|
|
|
|
(!nt_auth_identity->Domain && ad->domain_len)) {
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(nt_auth_identity->User);
|
|
|
|
heap_free(nt_auth_identity->Password);
|
|
|
|
heap_free(nt_auth_identity->Domain);
|
2010-07-17 14:08:44 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nt_auth_identity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
|
|
|
|
nt_auth_identity->UserLength = ad->user_len;
|
|
|
|
nt_auth_identity->PasswordLength = ad->password_len;
|
|
|
|
memcpy(nt_auth_identity->Domain, ad->domain, sizeof(WCHAR)*ad->domain_len);
|
|
|
|
nt_auth_identity->DomainLength = ad->domain_len;
|
|
|
|
LeaveCriticalSection(&authcache_cs);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&authcache_cs);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cache_authorization(LPWSTR host, LPWSTR scheme,
|
|
|
|
SEC_WINNT_AUTH_IDENTITY_W *nt_auth_identity)
|
|
|
|
{
|
|
|
|
authorizationData *ad;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
TRACE("Caching authorization for %s:%s\n", debugstr_w(host), debugstr_w(scheme));
|
|
|
|
|
|
|
|
EnterCriticalSection(&authcache_cs);
|
|
|
|
LIST_FOR_EACH_ENTRY(ad, &authorizationCache, authorizationData, entry)
|
|
|
|
if(!strcmpiW(host, ad->host) && !strcmpiW(scheme, ad->scheme)) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(found) {
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(ad->user);
|
|
|
|
heap_free(ad->password);
|
|
|
|
heap_free(ad->domain);
|
2010-07-17 14:08:44 +02:00
|
|
|
} else {
|
2011-04-21 13:39:03 +02:00
|
|
|
ad = heap_alloc(sizeof(authorizationData));
|
2010-07-17 14:08:44 +02:00
|
|
|
if(!ad) {
|
|
|
|
LeaveCriticalSection(&authcache_cs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ad->host = heap_strdupW(host);
|
|
|
|
ad->scheme = heap_strdupW(scheme);
|
|
|
|
list_add_head(&authorizationCache, &ad->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
ad->user = heap_strndupW(nt_auth_identity->User, nt_auth_identity->UserLength);
|
|
|
|
ad->password = heap_strndupW(nt_auth_identity->Password, nt_auth_identity->PasswordLength);
|
|
|
|
ad->domain = heap_strndupW(nt_auth_identity->Domain, nt_auth_identity->DomainLength);
|
|
|
|
ad->user_len = nt_auth_identity->UserLength;
|
|
|
|
ad->password_len = nt_auth_identity->PasswordLength;
|
|
|
|
ad->domain_len = nt_auth_identity->DomainLength;
|
|
|
|
|
|
|
|
if(!ad->host || !ad->scheme || !ad->user || !ad->password
|
|
|
|
|| (nt_auth_identity->Domain && !ad->domain)) {
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(ad->host);
|
|
|
|
heap_free(ad->scheme);
|
|
|
|
heap_free(ad->user);
|
|
|
|
heap_free(ad->password);
|
|
|
|
heap_free(ad->domain);
|
2010-07-17 14:08:44 +02:00
|
|
|
list_remove(&ad->entry);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(ad);
|
2010-07-17 14:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&authcache_cs);
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
static BOOL HTTP_DoAuthorization( http_request_t *request, LPCWSTR pszAuthValue,
|
2007-06-05 20:49:58 +02:00
|
|
|
struct HttpAuthInfo **ppAuthInfo,
|
2009-10-12 21:24:18 +02:00
|
|
|
LPWSTR domain_and_username, LPWSTR password,
|
|
|
|
LPWSTR host )
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
|
|
|
SECURITY_STATUS sec_status;
|
2007-06-05 20:49:58 +02:00
|
|
|
struct HttpAuthInfo *pAuthInfo = *ppAuthInfo;
|
2007-05-26 09:49:12 +02:00
|
|
|
BOOL first = FALSE;
|
2009-10-12 21:24:18 +02:00
|
|
|
LPWSTR szRealm = NULL;
|
2007-05-21 15:26:26 +02:00
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(pszAuthValue));
|
|
|
|
|
|
|
|
if (!pAuthInfo)
|
|
|
|
{
|
|
|
|
TimeStamp exp;
|
|
|
|
|
2007-05-26 09:49:12 +02:00
|
|
|
first = TRUE;
|
2011-04-21 13:39:03 +02:00
|
|
|
pAuthInfo = heap_alloc(sizeof(*pAuthInfo));
|
2007-05-21 15:26:26 +02:00
|
|
|
if (!pAuthInfo)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
SecInvalidateHandle(&pAuthInfo->cred);
|
|
|
|
SecInvalidateHandle(&pAuthInfo->ctx);
|
|
|
|
memset(&pAuthInfo->exp, 0, sizeof(pAuthInfo->exp));
|
|
|
|
pAuthInfo->attr = 0;
|
|
|
|
pAuthInfo->auth_data = NULL;
|
|
|
|
pAuthInfo->auth_data_len = 0;
|
|
|
|
pAuthInfo->finished = FALSE;
|
|
|
|
|
2009-10-12 21:24:18 +02:00
|
|
|
if (is_basic_auth_value(pszAuthValue,NULL))
|
2007-05-25 13:06:11 +02:00
|
|
|
{
|
|
|
|
static const WCHAR szBasic[] = {'B','a','s','i','c',0};
|
2009-07-17 01:10:41 +02:00
|
|
|
pAuthInfo->scheme = heap_strdupW(szBasic);
|
2007-05-25 13:06:11 +02:00
|
|
|
if (!pAuthInfo->scheme)
|
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(pAuthInfo);
|
2007-05-25 13:06:11 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2008-03-10 17:40:23 +01:00
|
|
|
PVOID pAuthData;
|
2007-05-21 15:26:26 +02:00
|
|
|
SEC_WINNT_AUTH_IDENTITY_W nt_auth_identity;
|
|
|
|
|
2009-07-17 01:10:41 +02:00
|
|
|
pAuthInfo->scheme = heap_strdupW(pszAuthValue);
|
2007-05-25 13:06:11 +02:00
|
|
|
if (!pAuthInfo->scheme)
|
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(pAuthInfo);
|
2007-05-25 13:06:11 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-10 17:40:23 +01:00
|
|
|
if (domain_and_username)
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2008-03-10 17:40:23 +01:00
|
|
|
WCHAR *user = strchrW(domain_and_username, '\\');
|
|
|
|
WCHAR *domain = domain_and_username;
|
2007-05-21 15:26:26 +02:00
|
|
|
|
2008-03-10 17:40:23 +01:00
|
|
|
/* FIXME: make sure scheme accepts SEC_WINNT_AUTH_IDENTITY before calling AcquireCredentialsHandle */
|
|
|
|
|
|
|
|
pAuthData = &nt_auth_identity;
|
|
|
|
|
|
|
|
if (user) user++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
user = domain_and_username;
|
|
|
|
domain = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nt_auth_identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
|
|
|
|
nt_auth_identity.User = user;
|
|
|
|
nt_auth_identity.UserLength = strlenW(nt_auth_identity.User);
|
|
|
|
nt_auth_identity.Domain = domain;
|
|
|
|
nt_auth_identity.DomainLength = domain ? user - domain - 1 : 0;
|
|
|
|
nt_auth_identity.Password = password;
|
|
|
|
nt_auth_identity.PasswordLength = strlenW(nt_auth_identity.Password);
|
2010-07-17 14:08:44 +02:00
|
|
|
|
|
|
|
cache_authorization(host, pAuthInfo->scheme, &nt_auth_identity);
|
2008-03-10 17:40:23 +01:00
|
|
|
}
|
2010-07-17 14:08:44 +02:00
|
|
|
else if(retrieve_cached_authorization(host, pAuthInfo->scheme, &nt_auth_identity))
|
|
|
|
pAuthData = &nt_auth_identity;
|
2008-03-10 17:40:23 +01:00
|
|
|
else
|
|
|
|
/* use default credentials */
|
|
|
|
pAuthData = NULL;
|
2007-05-21 15:26:26 +02:00
|
|
|
|
|
|
|
sec_status = AcquireCredentialsHandleW(NULL, pAuthInfo->scheme,
|
|
|
|
SECPKG_CRED_OUTBOUND, NULL,
|
2008-03-10 17:40:23 +01:00
|
|
|
pAuthData, NULL,
|
2007-05-21 15:26:26 +02:00
|
|
|
NULL, &pAuthInfo->cred,
|
|
|
|
&exp);
|
2010-07-17 14:08:44 +02:00
|
|
|
|
|
|
|
if(pAuthData && !domain_and_username) {
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(nt_auth_identity.User);
|
|
|
|
heap_free(nt_auth_identity.Domain);
|
|
|
|
heap_free(nt_auth_identity.Password);
|
2010-07-17 14:08:44 +02:00
|
|
|
}
|
|
|
|
|
2008-03-10 17:41:44 +01:00
|
|
|
if (sec_status == SEC_E_OK)
|
|
|
|
{
|
|
|
|
PSecPkgInfoW sec_pkg_info;
|
|
|
|
sec_status = QuerySecurityPackageInfoW(pAuthInfo->scheme, &sec_pkg_info);
|
|
|
|
if (sec_status == SEC_E_OK)
|
|
|
|
{
|
|
|
|
pAuthInfo->max_token = sec_pkg_info->cbMaxToken;
|
|
|
|
FreeContextBuffer(sec_pkg_info);
|
|
|
|
}
|
|
|
|
}
|
2007-05-21 15:26:26 +02:00
|
|
|
if (sec_status != SEC_E_OK)
|
|
|
|
{
|
|
|
|
WARN("AcquireCredentialsHandleW for scheme %s failed with error 0x%08x\n",
|
|
|
|
debugstr_w(pAuthInfo->scheme), sec_status);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(pAuthInfo->scheme);
|
|
|
|
heap_free(pAuthInfo);
|
2007-05-21 15:26:26 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 20:49:58 +02:00
|
|
|
*ppAuthInfo = pAuthInfo;
|
2007-05-21 15:26:26 +02:00
|
|
|
}
|
|
|
|
else if (pAuthInfo->finished)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((strlenW(pszAuthValue) < strlenW(pAuthInfo->scheme)) ||
|
|
|
|
strncmpiW(pszAuthValue, pAuthInfo->scheme, strlenW(pAuthInfo->scheme)))
|
|
|
|
{
|
|
|
|
ERR("authentication scheme changed from %s to %s\n",
|
|
|
|
debugstr_w(pAuthInfo->scheme), debugstr_w(pszAuthValue));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-10-12 21:24:18 +02:00
|
|
|
if (is_basic_auth_value(pszAuthValue,&szRealm))
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2008-03-10 17:40:23 +01:00
|
|
|
int userlen;
|
|
|
|
int passlen;
|
2009-10-12 21:24:18 +02:00
|
|
|
char *auth_data = NULL;
|
|
|
|
UINT auth_data_len = 0;
|
2007-05-21 15:28:02 +02:00
|
|
|
|
2009-10-12 21:24:18 +02:00
|
|
|
TRACE("basic authentication realm %s\n",debugstr_w(szRealm));
|
2007-05-21 15:28:02 +02:00
|
|
|
|
2009-10-12 21:24:18 +02:00
|
|
|
if (!domain_and_username)
|
|
|
|
{
|
|
|
|
if (host && szRealm)
|
|
|
|
auth_data_len = retrieve_cached_basic_authorization(host, szRealm,&auth_data);
|
|
|
|
if (auth_data_len == 0)
|
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(szRealm);
|
2009-10-12 21:24:18 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
userlen = WideCharToMultiByte(CP_UTF8, 0, domain_and_username, lstrlenW(domain_and_username), NULL, 0, NULL, NULL);
|
|
|
|
passlen = WideCharToMultiByte(CP_UTF8, 0, password, lstrlenW(password), NULL, 0, NULL, NULL);
|
2008-03-10 17:40:23 +01:00
|
|
|
|
2009-10-12 21:24:18 +02:00
|
|
|
/* length includes a nul terminator, which will be re-used for the ':' */
|
2011-04-21 13:39:03 +02:00
|
|
|
auth_data = heap_alloc(userlen + 1 + passlen);
|
2009-10-12 21:24:18 +02:00
|
|
|
if (!auth_data)
|
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(szRealm);
|
2009-10-12 21:24:18 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-05-21 15:28:02 +02:00
|
|
|
|
2009-10-12 21:24:18 +02:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, domain_and_username, -1, auth_data, userlen, NULL, NULL);
|
|
|
|
auth_data[userlen] = ':';
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, password, -1, &auth_data[userlen+1], passlen, NULL, NULL);
|
|
|
|
auth_data_len = userlen + 1 + passlen;
|
|
|
|
if (host && szRealm)
|
|
|
|
cache_basic_authorization(host, szRealm, auth_data, auth_data_len);
|
|
|
|
}
|
2007-05-21 15:28:02 +02:00
|
|
|
|
|
|
|
pAuthInfo->auth_data = auth_data;
|
2009-10-12 21:24:18 +02:00
|
|
|
pAuthInfo->auth_data_len = auth_data_len;
|
2007-05-21 15:28:02 +02:00
|
|
|
pAuthInfo->finished = TRUE;
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(szRealm);
|
2007-05-21 15:28:02 +02:00
|
|
|
return TRUE;
|
2007-05-21 15:26:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPCWSTR pszAuthData;
|
|
|
|
SecBufferDesc out_desc, in_desc;
|
|
|
|
SecBuffer out, in;
|
|
|
|
unsigned char *buffer;
|
|
|
|
ULONG context_req = ISC_REQ_CONNECTION | ISC_REQ_USE_DCE_STYLE |
|
|
|
|
ISC_REQ_MUTUAL_AUTH | ISC_REQ_DELEGATE;
|
|
|
|
|
|
|
|
in.BufferType = SECBUFFER_TOKEN;
|
|
|
|
in.cbBuffer = 0;
|
|
|
|
in.pvBuffer = NULL;
|
|
|
|
|
|
|
|
in_desc.ulVersion = 0;
|
|
|
|
in_desc.cBuffers = 1;
|
|
|
|
in_desc.pBuffers = ∈
|
|
|
|
|
|
|
|
pszAuthData = pszAuthValue + strlenW(pAuthInfo->scheme);
|
|
|
|
if (*pszAuthData == ' ')
|
|
|
|
{
|
|
|
|
pszAuthData++;
|
|
|
|
in.cbBuffer = HTTP_DecodeBase64(pszAuthData, NULL);
|
2011-04-21 13:39:03 +02:00
|
|
|
in.pvBuffer = heap_alloc(in.cbBuffer);
|
2007-05-21 15:26:26 +02:00
|
|
|
HTTP_DecodeBase64(pszAuthData, in.pvBuffer);
|
|
|
|
}
|
|
|
|
|
2011-04-21 13:39:03 +02:00
|
|
|
buffer = heap_alloc(pAuthInfo->max_token);
|
2007-05-21 15:26:26 +02:00
|
|
|
|
|
|
|
out.BufferType = SECBUFFER_TOKEN;
|
2008-03-10 17:41:44 +01:00
|
|
|
out.cbBuffer = pAuthInfo->max_token;
|
2007-05-21 15:26:26 +02:00
|
|
|
out.pvBuffer = buffer;
|
|
|
|
|
|
|
|
out_desc.ulVersion = 0;
|
|
|
|
out_desc.cBuffers = 1;
|
|
|
|
out_desc.pBuffers = &out;
|
|
|
|
|
2007-05-26 09:49:12 +02:00
|
|
|
sec_status = InitializeSecurityContextW(first ? &pAuthInfo->cred : NULL,
|
2008-01-24 20:30:11 +01:00
|
|
|
first ? NULL : &pAuthInfo->ctx,
|
2012-05-25 16:34:24 +02:00
|
|
|
first ? request->server->name : NULL,
|
2007-05-21 15:26:26 +02:00
|
|
|
context_req, 0, SECURITY_NETWORK_DREP,
|
|
|
|
in.pvBuffer ? &in_desc : NULL,
|
|
|
|
0, &pAuthInfo->ctx, &out_desc,
|
|
|
|
&pAuthInfo->attr, &pAuthInfo->exp);
|
|
|
|
if (sec_status == SEC_E_OK)
|
|
|
|
{
|
|
|
|
pAuthInfo->finished = TRUE;
|
|
|
|
pAuthInfo->auth_data = out.pvBuffer;
|
|
|
|
pAuthInfo->auth_data_len = out.cbBuffer;
|
|
|
|
TRACE("sending last auth packet\n");
|
|
|
|
}
|
|
|
|
else if (sec_status == SEC_I_CONTINUE_NEEDED)
|
|
|
|
{
|
|
|
|
pAuthInfo->auth_data = out.pvBuffer;
|
|
|
|
pAuthInfo->auth_data_len = out.cbBuffer;
|
|
|
|
TRACE("sending next auth packet\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("InitializeSecurityContextW returned error 0x%08x\n", sec_status);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(out.pvBuffer);
|
2009-09-02 11:44:43 +02:00
|
|
|
destroy_authinfo(pAuthInfo);
|
|
|
|
*ppAuthInfo = NULL;
|
2007-05-21 15:26:26 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
2004-06-14 19:57:26 +02:00
|
|
|
* HTTP_HttpAddRequestHeadersW (internal)
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static DWORD HTTP_HttpAddRequestHeadersW(http_request_t *request,
|
2004-03-30 06:36:09 +02:00
|
|
|
LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR lpszStart;
|
|
|
|
LPWSTR lpszEnd;
|
|
|
|
LPWSTR buffer;
|
2009-11-30 20:01:00 +01:00
|
|
|
DWORD len, res = ERROR_HTTP_INVALID_HEADER;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2008-02-19 00:18:02 +01:00
|
|
|
TRACE("copying header: %s\n", debugstr_wn(lpszHeader, dwHeaderLength));
|
2004-08-11 01:41:35 +02:00
|
|
|
|
2005-09-13 17:00:32 +02:00
|
|
|
if( dwHeaderLength == ~0U )
|
2004-08-11 01:41:35 +02:00
|
|
|
len = strlenW(lpszHeader);
|
|
|
|
else
|
|
|
|
len = dwHeaderLength;
|
2011-04-21 13:39:03 +02:00
|
|
|
buffer = heap_alloc(sizeof(WCHAR)*(len+1));
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW( buffer, lpszHeader, len + 1);
|
2004-08-11 01:41:35 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
lpszStart = buffer;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2004-09-24 00:53:50 +02:00
|
|
|
LPWSTR * pFieldAndValue;
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
lpszEnd = lpszStart;
|
|
|
|
|
|
|
|
while (*lpszEnd != '\0')
|
|
|
|
{
|
2009-06-15 00:29:31 +02:00
|
|
|
if (*lpszEnd == '\r' || *lpszEnd == '\n')
|
2000-06-11 22:04:44 +02:00
|
|
|
break;
|
|
|
|
lpszEnd++;
|
|
|
|
}
|
|
|
|
|
2004-07-14 01:34:28 +02:00
|
|
|
if (*lpszStart == '\0')
|
2000-06-11 22:04:44 +02:00
|
|
|
break;
|
|
|
|
|
2009-06-15 00:29:31 +02:00
|
|
|
if (*lpszEnd == '\r' || *lpszEnd == '\n')
|
2004-07-14 01:34:28 +02:00
|
|
|
{
|
|
|
|
*lpszEnd = '\0';
|
2009-06-15 00:29:31 +02:00
|
|
|
lpszEnd++; /* Jump over newline */
|
2004-07-14 01:34:28 +02:00
|
|
|
}
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("interpreting header %s\n", debugstr_w(lpszStart));
|
2009-04-24 18:31:06 +02:00
|
|
|
if (*lpszStart == '\0')
|
|
|
|
{
|
|
|
|
/* Skip 0-length headers */
|
|
|
|
lpszStart = lpszEnd;
|
2009-11-30 20:01:00 +01:00
|
|
|
res = ERROR_SUCCESS;
|
2009-04-24 18:31:06 +02:00
|
|
|
continue;
|
|
|
|
}
|
2004-09-24 00:53:50 +02:00
|
|
|
pFieldAndValue = HTTP_InterpretHttpHeader(lpszStart);
|
|
|
|
if (pFieldAndValue)
|
|
|
|
{
|
2014-12-08 02:51:30 +01:00
|
|
|
res = HTTP_ProcessHeader(request, pFieldAndValue[0],
|
|
|
|
pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ);
|
2004-09-24 00:53:50 +02:00
|
|
|
HTTP_FreeTokens(pFieldAndValue);
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-14 01:34:28 +02:00
|
|
|
lpszStart = lpszEnd;
|
2009-11-30 20:01:00 +01:00
|
|
|
} while (res == ERROR_SUCCESS);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(buffer);
|
2009-11-30 20:01:00 +01:00
|
|
|
return res;
|
2004-06-14 19:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpAddRequestHeadersW (WININET.@)
|
|
|
|
*
|
|
|
|
* Adds one or more HTTP header to the request handler
|
|
|
|
*
|
2008-02-19 00:18:02 +01:00
|
|
|
* NOTE
|
|
|
|
* On Windows if dwHeaderLength includes the trailing '\0', then
|
|
|
|
* HttpAddRequestHeadersW() adds it too. However this results in an
|
2012-05-15 10:15:32 +02:00
|
|
|
* invalid HTTP header which is rejected by some servers so we probably
|
2008-02-19 00:18:02 +01:00
|
|
|
* don't need to match Windows on that point.
|
|
|
|
*
|
2004-06-14 19:57:26 +02:00
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
|
|
|
|
LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
|
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_request_t *request;
|
2009-11-30 20:01:00 +01:00
|
|
|
DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
|
2004-06-14 19:57:26 +02:00
|
|
|
|
2008-02-19 00:18:02 +01:00
|
|
|
TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_wn(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier);
|
2004-06-14 19:57:26 +02:00
|
|
|
|
|
|
|
if (!lpszHeader)
|
|
|
|
return TRUE;
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
request = (http_request_t*) get_handle_object( hHttpRequest );
|
|
|
|
if (request && request->hdr.htype == WH_HHTTPREQ)
|
|
|
|
res = HTTP_HttpAddRequestHeadersW( request, lpszHeader, dwHeaderLength, dwModifier );
|
|
|
|
if( request )
|
|
|
|
WININET_Release( &request->hdr );
|
2004-06-14 19:57:26 +02:00
|
|
|
|
2009-11-30 20:01:00 +01:00
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
SetLastError(res);
|
|
|
|
return res == ERROR_SUCCESS;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HttpAddRequestHeadersA (WININET.@)
|
|
|
|
*
|
|
|
|
* Adds one or more HTTP header to the request handler
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpAddRequestHeadersA(HINTERNET hHttpRequest,
|
|
|
|
LPCSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
|
|
|
|
{
|
2016-04-27 14:18:12 +02:00
|
|
|
WCHAR *headers = NULL;
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL r;
|
|
|
|
|
2008-02-19 00:18:02 +01:00
|
|
|
TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_an(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier);
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2016-04-27 14:18:12 +02:00
|
|
|
if(lpszHeader)
|
|
|
|
headers = heap_strndupAtoW(lpszHeader, dwHeaderLength, &dwHeaderLength);
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2016-04-27 14:18:12 +02:00
|
|
|
r = HttpAddRequestHeadersW(hHttpRequest, headers, dwHeaderLength, dwModifier);
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2016-04-27 14:18:12 +02:00
|
|
|
heap_free(headers);
|
2004-03-30 06:36:09 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-09-27 11:40:33 +02:00
|
|
|
static void free_accept_types( WCHAR **accept_types )
|
|
|
|
{
|
|
|
|
WCHAR *ptr, **types = accept_types;
|
|
|
|
|
|
|
|
if (!types) return;
|
|
|
|
while ((ptr = *types))
|
|
|
|
{
|
|
|
|
heap_free( ptr );
|
|
|
|
types++;
|
|
|
|
}
|
|
|
|
heap_free( accept_types );
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR **convert_accept_types( const char **accept_types )
|
|
|
|
{
|
|
|
|
unsigned int count;
|
|
|
|
const char **types = accept_types;
|
|
|
|
WCHAR **typesW;
|
|
|
|
BOOL invalid_pointer = FALSE;
|
|
|
|
|
|
|
|
if (!types) return NULL;
|
|
|
|
count = 0;
|
|
|
|
while (*types)
|
|
|
|
{
|
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
/* find out how many there are */
|
|
|
|
if (*types && **types)
|
|
|
|
{
|
|
|
|
TRACE("accept type: %s\n", debugstr_a(*types));
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__EXCEPT_PAGE_FAULT
|
|
|
|
{
|
|
|
|
WARN("invalid accept type pointer\n");
|
|
|
|
invalid_pointer = TRUE;
|
|
|
|
}
|
|
|
|
__ENDTRY;
|
|
|
|
types++;
|
|
|
|
}
|
|
|
|
if (invalid_pointer) return NULL;
|
|
|
|
if (!(typesW = heap_alloc( sizeof(WCHAR *) * (count + 1) ))) return NULL;
|
|
|
|
count = 0;
|
|
|
|
types = accept_types;
|
|
|
|
while (*types)
|
|
|
|
{
|
|
|
|
if (*types && **types) typesW[count++] = heap_strdupAtoW( *types );
|
|
|
|
types++;
|
|
|
|
}
|
|
|
|
typesW[count] = NULL;
|
|
|
|
return typesW;
|
|
|
|
}
|
|
|
|
|
2002-11-12 03:13:04 +01:00
|
|
|
/***********************************************************************
|
2004-03-30 06:36:09 +02:00
|
|
|
* HttpOpenRequestA (WININET.@)
|
2002-11-12 03:13:04 +01:00
|
|
|
*
|
|
|
|
* Open a HTTP request handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a HTTP request handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
HINTERNET WINAPI HttpOpenRequestA(HINTERNET hHttpSession,
|
|
|
|
LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion,
|
|
|
|
LPCSTR lpszReferrer , LPCSTR *lpszAcceptTypes,
|
2007-08-30 16:21:33 +02:00
|
|
|
DWORD dwFlags, DWORD_PTR dwContext)
|
2002-11-12 03:13:04 +01:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR szVerb = NULL, szObjectName = NULL;
|
|
|
|
LPWSTR szVersion = NULL, szReferrer = NULL, *szAcceptTypes = NULL;
|
2013-10-09 22:36:49 +02:00
|
|
|
HINTERNET rc = NULL;
|
2008-05-07 13:19:37 +02:00
|
|
|
|
2007-08-30 16:21:33 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %p, %08x, %08lx)\n", hHttpSession,
|
2004-03-30 06:36:09 +02:00
|
|
|
debugstr_a(lpszVerb), debugstr_a(lpszObjectName),
|
|
|
|
debugstr_a(lpszVersion), debugstr_a(lpszReferrer), lpszAcceptTypes,
|
2003-06-21 01:26:56 +02:00
|
|
|
dwFlags, dwContext);
|
|
|
|
|
|
|
|
if (lpszVerb)
|
|
|
|
{
|
2009-07-17 01:17:13 +02:00
|
|
|
szVerb = heap_strdupAtoW(lpszVerb);
|
2003-08-15 05:47:30 +02:00
|
|
|
if ( !szVerb )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2002-12-07 00:20:31 +01:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (lpszObjectName)
|
|
|
|
{
|
2009-07-17 01:17:13 +02:00
|
|
|
szObjectName = heap_strdupAtoW(lpszObjectName);
|
2003-08-15 05:47:30 +02:00
|
|
|
if ( !szObjectName )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpszVersion)
|
|
|
|
{
|
2009-07-17 01:17:13 +02:00
|
|
|
szVersion = heap_strdupAtoW(lpszVersion);
|
2003-08-15 05:47:30 +02:00
|
|
|
if ( !szVersion )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpszReferrer)
|
|
|
|
{
|
2009-07-17 01:17:13 +02:00
|
|
|
szReferrer = heap_strdupAtoW(lpszReferrer);
|
2003-08-15 05:47:30 +02:00
|
|
|
if ( !szReferrer )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2011-09-27 11:40:33 +02:00
|
|
|
szAcceptTypes = convert_accept_types( lpszAcceptTypes );
|
|
|
|
rc = HttpOpenRequestW(hHttpSession, szVerb, szObjectName, szVersion, szReferrer,
|
|
|
|
(const WCHAR **)szAcceptTypes, dwFlags, dwContext);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
end:
|
2011-09-27 11:40:33 +02:00
|
|
|
free_accept_types(szAcceptTypes);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(szReferrer);
|
|
|
|
heap_free(szVersion);
|
|
|
|
heap_free(szObjectName);
|
|
|
|
heap_free(szVerb);
|
2003-06-21 01:26:56 +02:00
|
|
|
return rc;
|
2002-11-12 03:13:04 +01:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
/***********************************************************************
|
2007-01-13 02:17:20 +01:00
|
|
|
* HTTP_EncodeBase64
|
2003-07-22 05:17:52 +02:00
|
|
|
*/
|
2007-01-13 02:17:20 +01:00
|
|
|
static UINT HTTP_EncodeBase64( LPCSTR bin, unsigned int len, LPWSTR base64 )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
UINT n = 0, x;
|
2007-02-24 22:55:12 +01:00
|
|
|
static const CHAR HTTP_Base64Enc[] =
|
2003-07-22 05:17:52 +02:00
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
|
2007-01-13 02:17:20 +01:00
|
|
|
while( len > 0 )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
/* first 6 bits, all from bin[0] */
|
|
|
|
base64[n++] = HTTP_Base64Enc[(bin[0] & 0xfc) >> 2];
|
|
|
|
x = (bin[0] & 3) << 4;
|
|
|
|
|
|
|
|
/* next 6 bits, 2 from bin[0] and 4 from bin[1] */
|
2007-01-13 02:17:20 +01:00
|
|
|
if( len == 1 )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
base64[n++] = HTTP_Base64Enc[x];
|
|
|
|
base64[n++] = '=';
|
|
|
|
base64[n++] = '=';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
base64[n++] = HTTP_Base64Enc[ x | ( (bin[1]&0xf0) >> 4 ) ];
|
|
|
|
x = ( bin[1] & 0x0f ) << 2;
|
|
|
|
|
|
|
|
/* next 6 bits 4 from bin[1] and 2 from bin[2] */
|
2007-01-13 02:17:20 +01:00
|
|
|
if( len == 2 )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
base64[n++] = HTTP_Base64Enc[x];
|
|
|
|
base64[n++] = '=';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
base64[n++] = HTTP_Base64Enc[ x | ( (bin[2]&0xc0 ) >> 6 ) ];
|
|
|
|
|
|
|
|
/* last 6 bits, all from bin [2] */
|
|
|
|
base64[n++] = HTTP_Base64Enc[ bin[2] & 0x3f ];
|
|
|
|
bin += 3;
|
2007-01-13 02:17:20 +01:00
|
|
|
len -= 3;
|
2003-07-22 05:17:52 +02:00
|
|
|
}
|
|
|
|
base64[n] = 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2015-03-04 09:07:24 +01:00
|
|
|
static const signed char HTTP_Base64Dec[] =
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2015-03-04 09:07:24 +01:00
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00 */
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10 */
|
|
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /* 0x20 */
|
|
|
|
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 0x30 */
|
|
|
|
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40 */
|
|
|
|
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, /* 0x50 */
|
|
|
|
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60 */
|
|
|
|
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 0x70 */
|
2007-05-21 15:26:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_DecodeBase64
|
|
|
|
*/
|
|
|
|
static UINT HTTP_DecodeBase64( LPCWSTR base64, LPSTR bin )
|
|
|
|
{
|
|
|
|
unsigned int n = 0;
|
|
|
|
|
|
|
|
while(*base64)
|
|
|
|
{
|
|
|
|
signed char in[4];
|
|
|
|
|
2008-02-15 11:06:32 +01:00
|
|
|
if (base64[0] >= ARRAYSIZE(HTTP_Base64Dec) ||
|
2007-05-21 15:26:26 +02:00
|
|
|
((in[0] = HTTP_Base64Dec[base64[0]]) == -1) ||
|
2008-02-15 11:06:32 +01:00
|
|
|
base64[1] >= ARRAYSIZE(HTTP_Base64Dec) ||
|
2007-05-21 15:26:26 +02:00
|
|
|
((in[1] = HTTP_Base64Dec[base64[1]]) == -1))
|
|
|
|
{
|
|
|
|
WARN("invalid base64: %s\n", debugstr_w(base64));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (bin)
|
|
|
|
bin[n] = (unsigned char) (in[0] << 2 | in[1] >> 4);
|
|
|
|
n++;
|
|
|
|
|
|
|
|
if ((base64[2] == '=') && (base64[3] == '='))
|
|
|
|
break;
|
|
|
|
if (base64[2] > ARRAYSIZE(HTTP_Base64Dec) ||
|
|
|
|
((in[2] = HTTP_Base64Dec[base64[2]]) == -1))
|
|
|
|
{
|
|
|
|
WARN("invalid base64: %s\n", debugstr_w(&base64[2]));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (bin)
|
|
|
|
bin[n] = (unsigned char) (in[1] << 4 | in[2] >> 2);
|
|
|
|
n++;
|
|
|
|
|
|
|
|
if (base64[3] == '=')
|
|
|
|
break;
|
|
|
|
if (base64[3] > ARRAYSIZE(HTTP_Base64Dec) ||
|
|
|
|
((in[3] = HTTP_Base64Dec[base64[3]]) == -1))
|
|
|
|
{
|
|
|
|
WARN("invalid base64: %s\n", debugstr_w(&base64[3]));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (bin)
|
|
|
|
bin[n] = (unsigned char) (((in[2] << 6) & 0xc0) | in[3]);
|
|
|
|
n++;
|
|
|
|
|
|
|
|
base64 += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2015-04-30 11:50:26 +02:00
|
|
|
static WCHAR *encode_auth_data( const WCHAR *scheme, const char *data, UINT data_len )
|
|
|
|
{
|
|
|
|
WCHAR *ret;
|
|
|
|
UINT len, scheme_len = strlenW( scheme );
|
|
|
|
|
|
|
|
/* scheme + space + base64 encoded data (3/2/1 bytes data -> 4 bytes of characters) */
|
|
|
|
len = scheme_len + 1 + ((data_len + 2) * 4) / 3;
|
|
|
|
if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
|
|
|
|
memcpy( ret, scheme, scheme_len * sizeof(WCHAR) );
|
|
|
|
ret[scheme_len] = ' ';
|
|
|
|
HTTP_EncodeBase64( data, data_len, ret + scheme_len + 1 );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
/***********************************************************************
|
2008-05-09 15:18:51 +02:00
|
|
|
* HTTP_InsertAuthorization
|
2007-05-21 15:26:26 +02:00
|
|
|
*
|
|
|
|
* Insert or delete the authorization field in the request header.
|
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static BOOL HTTP_InsertAuthorization( http_request_t *request, struct HttpAuthInfo *pAuthInfo, LPCWSTR header )
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2015-04-30 11:50:26 +02:00
|
|
|
static const WCHAR wszBasic[] = {'B','a','s','i','c',0};
|
|
|
|
WCHAR *host, *authorization = NULL;
|
|
|
|
|
2008-03-12 14:27:46 +01:00
|
|
|
if (pAuthInfo)
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2008-03-12 14:27:46 +01:00
|
|
|
if (pAuthInfo->auth_data_len)
|
|
|
|
{
|
2015-04-30 11:50:26 +02:00
|
|
|
if (!(authorization = encode_auth_data(pAuthInfo->scheme, pAuthInfo->auth_data, pAuthInfo->auth_data_len)))
|
2008-03-12 14:27:46 +01:00
|
|
|
return FALSE;
|
2007-05-21 15:26:26 +02:00
|
|
|
|
2008-03-12 14:27:46 +01:00
|
|
|
/* clear the data as it isn't valid now that it has been sent to the
|
|
|
|
* server, unless it's Basic authentication which doesn't do
|
|
|
|
* connection tracking */
|
|
|
|
if (strcmpiW(pAuthInfo->scheme, wszBasic))
|
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(pAuthInfo->auth_data);
|
2008-03-12 14:27:46 +01:00
|
|
|
pAuthInfo->auth_data = NULL;
|
|
|
|
pAuthInfo->auth_data_len = 0;
|
|
|
|
}
|
2007-11-27 15:19:50 +01:00
|
|
|
}
|
2007-05-21 15:26:26 +02:00
|
|
|
|
2008-03-12 14:27:46 +01:00
|
|
|
TRACE("Inserting authorization: %s\n", debugstr_w(authorization));
|
2007-05-21 15:26:26 +02:00
|
|
|
|
2015-06-25 12:28:02 +02:00
|
|
|
HTTP_ProcessHeader(request, header, authorization,
|
|
|
|
HTTP_ADDHDR_FLAG_REQ | HTTP_ADDHDR_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(authorization);
|
2008-03-12 14:27:46 +01:00
|
|
|
}
|
2015-04-30 11:50:26 +02:00
|
|
|
else if (!strcmpW(header, szAuthorization) && (host = get_host_header(request)))
|
|
|
|
{
|
|
|
|
UINT data_len;
|
|
|
|
char *data;
|
|
|
|
|
|
|
|
if ((data_len = retrieve_cached_basic_authorization(host, NULL, &data)))
|
|
|
|
{
|
|
|
|
TRACE("Found cached basic authorization for %s\n", debugstr_w(host));
|
|
|
|
|
|
|
|
if (!(authorization = encode_auth_data(wszBasic, data, data_len)))
|
|
|
|
{
|
|
|
|
heap_free(data);
|
|
|
|
heap_free(host);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Inserting authorization: %s\n", debugstr_w(authorization));
|
|
|
|
|
2015-06-25 12:28:02 +02:00
|
|
|
HTTP_ProcessHeader(request, header, authorization,
|
|
|
|
HTTP_ADDHDR_FLAG_REQ | HTTP_ADDHDR_FLAG_REPLACE | HTTP_ADDHDR_FLAG_ADD);
|
2015-04-30 11:50:26 +02:00
|
|
|
heap_free(data);
|
|
|
|
heap_free(authorization);
|
|
|
|
}
|
|
|
|
heap_free(host);
|
|
|
|
}
|
2007-05-21 15:26:26 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-11-19 11:47:50 +01:00
|
|
|
static WCHAR *build_proxy_path_url(http_request_t *req)
|
2008-03-30 20:16:52 +02:00
|
|
|
{
|
2012-11-19 11:47:50 +01:00
|
|
|
DWORD size, len;
|
|
|
|
WCHAR *url;
|
|
|
|
|
|
|
|
len = strlenW(req->server->scheme_host_port);
|
|
|
|
size = len + strlenW(req->path) + 1;
|
|
|
|
if(*req->path != '/')
|
|
|
|
size++;
|
|
|
|
url = heap_alloc(size * sizeof(WCHAR));
|
|
|
|
if(!url)
|
|
|
|
return NULL;
|
2008-03-30 20:16:52 +02:00
|
|
|
|
2012-11-19 11:47:50 +01:00
|
|
|
memcpy(url, req->server->scheme_host_port, len*sizeof(WCHAR));
|
|
|
|
if(*req->path != '/')
|
|
|
|
url[len++] = '/';
|
2008-03-30 20:16:52 +02:00
|
|
|
|
2012-11-19 11:47:50 +01:00
|
|
|
strcpyW(url+len, req->path);
|
2011-08-22 21:31:14 +02:00
|
|
|
|
2008-03-30 20:16:52 +02:00
|
|
|
TRACE("url=%s\n", debugstr_w(url));
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2016-05-17 19:18:05 +02:00
|
|
|
static BOOL HTTP_DomainMatches(LPCWSTR server, substr_t domain)
|
2013-05-06 20:16:28 +02:00
|
|
|
{
|
|
|
|
static const WCHAR localW[] = { '<','l','o','c','a','l','>',0 };
|
2016-05-17 19:18:05 +02:00
|
|
|
const WCHAR *dot, *ptr;
|
|
|
|
int len;
|
2013-05-06 20:16:28 +02:00
|
|
|
|
2016-05-17 19:18:05 +02:00
|
|
|
if(domain.len == sizeof(localW)/sizeof(WCHAR)-1 && !strncmpiW(domain.str, localW, domain.len) && !strchrW(server, '.' ))
|
|
|
|
return TRUE;
|
2013-05-06 20:16:28 +02:00
|
|
|
|
2016-05-17 19:18:05 +02:00
|
|
|
if(domain.len && *domain.str != '*')
|
|
|
|
return domain.len == strlenW(server) && !strncmpiW(server, domain.str, domain.len);
|
|
|
|
|
|
|
|
if(domain.len < 2 || domain.str[1] != '.')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
dot = strchrW(server, '.');
|
|
|
|
if(!dot)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
len = strlenW(dot + 1);
|
|
|
|
if(len <= domain.len - 2)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* The server's domain is longer than the wildcard, so it
|
|
|
|
* could be a subdomain. Compare the last portion of the
|
|
|
|
* server's domain.
|
|
|
|
*/
|
|
|
|
ptr = dot + 1 + len - domain.len + 2;
|
|
|
|
if(!strncmpiW(ptr, domain.str+2, domain.len-2))
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
return *(ptr - 1) == '.';
|
|
|
|
|
|
|
|
return len == domain.len-2 && !strncmpiW(dot + 1, domain.str + 2, len);
|
2013-05-06 20:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL HTTP_ShouldBypassProxy(appinfo_t *lpwai, LPCWSTR server)
|
|
|
|
{
|
|
|
|
LPCWSTR ptr;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (!lpwai->proxyBypass) return FALSE;
|
|
|
|
ptr = lpwai->proxyBypass;
|
2016-05-17 19:18:05 +02:00
|
|
|
while(1) {
|
2013-05-06 20:16:28 +02:00
|
|
|
LPCWSTR tmp = ptr;
|
|
|
|
|
|
|
|
ptr = strchrW( ptr, ';' );
|
|
|
|
if (!ptr)
|
|
|
|
ptr = strchrW( tmp, ' ' );
|
2016-05-17 19:18:05 +02:00
|
|
|
if (!ptr)
|
2016-05-31 19:42:53 +02:00
|
|
|
ptr = tmp + strlenW(tmp);
|
2016-05-17 19:18:05 +02:00
|
|
|
ret = HTTP_DomainMatches( server, substr(tmp, ptr-tmp) );
|
|
|
|
if (ret || !*ptr)
|
|
|
|
break;
|
|
|
|
ptr++;
|
|
|
|
}
|
2013-05-06 20:16:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_DealWithProxy
|
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static BOOL HTTP_DealWithProxy(appinfo_t *hIC, http_session_t *session, http_request_t *request)
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
2013-03-06 13:30:49 +01:00
|
|
|
static const WCHAR protoHttp[] = { 'h','t','t','p',0 };
|
|
|
|
static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/',0 };
|
2006-10-13 15:43:54 +02:00
|
|
|
static WCHAR szNul[] = { 0 };
|
2016-05-17 19:19:59 +02:00
|
|
|
URL_COMPONENTSW UrlComponents = { sizeof(UrlComponents) };
|
|
|
|
server_t *new_server = NULL;
|
|
|
|
WCHAR *proxy;
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2016-05-17 19:19:59 +02:00
|
|
|
proxy = INTERNET_FindProxyForProtocol(hIC->proxy, protoHttp);
|
|
|
|
if(!proxy)
|
2003-07-22 05:17:52 +02:00
|
|
|
return FALSE;
|
2016-05-17 19:19:59 +02:00
|
|
|
if(CSTR_EQUAL != CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
|
|
|
|
proxy, strlenW(szHttp), szHttp, strlenW(szHttp))) {
|
|
|
|
WCHAR *proxy_url = heap_alloc(strlenW(proxy)*sizeof(WCHAR) + sizeof(szHttp));
|
2016-05-29 19:19:34 +02:00
|
|
|
if(!proxy_url) {
|
|
|
|
heap_free(proxy);
|
2016-05-17 19:19:59 +02:00
|
|
|
return FALSE;
|
2016-05-29 19:19:34 +02:00
|
|
|
}
|
2016-05-17 19:19:59 +02:00
|
|
|
strcpyW(proxy_url, szHttp);
|
|
|
|
strcatW(proxy_url, proxy);
|
|
|
|
heap_free(proxy);
|
|
|
|
proxy = proxy_url;
|
|
|
|
}
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2016-05-17 19:19:59 +02:00
|
|
|
UrlComponents.dwHostNameLength = 1;
|
|
|
|
if(InternetCrackUrlW(proxy, 0, 0, &UrlComponents) && UrlComponents.dwHostNameLength) {
|
|
|
|
if( !request->path )
|
|
|
|
request->path = szNul;
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2016-05-17 19:19:59 +02:00
|
|
|
new_server = get_server(substr(UrlComponents.lpszHostName, UrlComponents.dwHostNameLength),
|
2016-05-17 19:20:21 +02:00
|
|
|
UrlComponents.nPort, UrlComponents.nScheme == INTERNET_SCHEME_HTTPS, TRUE);
|
2016-05-17 19:19:59 +02:00
|
|
|
}
|
|
|
|
heap_free(proxy);
|
2012-05-25 16:34:24 +02:00
|
|
|
if(!new_server)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-11-16 14:38:56 +01:00
|
|
|
request->proxy = new_server;
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2012-05-25 16:34:24 +02:00
|
|
|
TRACE("proxy server=%s port=%d\n", debugstr_w(new_server->name), new_server->port);
|
2003-07-22 05:17:52 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-05-25 16:34:24 +02:00
|
|
|
static DWORD HTTP_ResolveName(http_request_t *request)
|
2006-12-07 01:52:50 +01:00
|
|
|
{
|
2012-11-16 14:38:56 +01:00
|
|
|
server_t *server = request->proxy ? request->proxy : request->server;
|
2015-02-16 11:16:53 +01:00
|
|
|
int addr_len;
|
2006-12-07 01:52:50 +01:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
if(server->addr_len)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
2006-12-07 01:52:50 +01:00
|
|
|
INTERNET_STATUS_RESOLVING_NAME,
|
2011-05-10 11:26:43 +02:00
|
|
|
server->name,
|
|
|
|
(strlenW(server->name)+1) * sizeof(WCHAR));
|
2006-12-07 01:52:50 +01:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
addr_len = sizeof(server->addr);
|
2015-02-16 11:16:53 +01:00
|
|
|
if (!GetAddress(server->name, server->port, (SOCKADDR*)&server->addr, &addr_len, server->addr_str))
|
2009-11-30 00:14:02 +01:00
|
|
|
return ERROR_INTERNET_NAME_NOT_RESOLVED;
|
2006-12-07 01:52:50 +01:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
server->addr_len = addr_len;
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
2006-12-07 01:52:50 +01:00
|
|
|
INTERNET_STATUS_NAME_RESOLVED,
|
2011-05-10 11:26:43 +02:00
|
|
|
server->addr_str, strlen(server->addr_str)+1);
|
2008-05-31 21:46:07 +02:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
TRACE("resolved %s to %s\n", debugstr_w(server->name), server->addr_str);
|
2009-11-30 00:14:02 +01:00
|
|
|
return ERROR_SUCCESS;
|
2006-12-07 01:52:50 +01:00
|
|
|
}
|
|
|
|
|
2016-05-17 19:14:38 +02:00
|
|
|
static WCHAR *compose_request_url(http_request_t *req)
|
2010-07-24 17:56:41 +02:00
|
|
|
{
|
2011-03-02 17:28:39 +01:00
|
|
|
static const WCHAR http[] = { 'h','t','t','p',':','/','/',0 };
|
|
|
|
static const WCHAR https[] = { 'h','t','t','p','s',':','/','/',0 };
|
2016-05-17 19:14:38 +02:00
|
|
|
const WCHAR *host, *scheme;
|
|
|
|
WCHAR *buf, *ptr;
|
|
|
|
size_t len;
|
2010-07-24 17:56:41 +02:00
|
|
|
|
2016-05-18 18:02:16 +02:00
|
|
|
host = req->server->canon_host_port;
|
2015-08-25 07:26:43 +02:00
|
|
|
|
2016-05-17 19:14:38 +02:00
|
|
|
if (req->server->is_https)
|
2011-03-02 17:28:39 +01:00
|
|
|
scheme = https;
|
|
|
|
else
|
|
|
|
scheme = http;
|
2016-05-17 19:14:38 +02:00
|
|
|
|
|
|
|
len = strlenW(scheme) + strlenW(host) + (req->path[0] != '/' ? 1 : 0) + strlenW(req->path);
|
|
|
|
ptr = buf = heap_alloc((len+1) * sizeof(WCHAR));
|
|
|
|
if(buf) {
|
|
|
|
strcpyW(ptr, scheme);
|
|
|
|
ptr += strlenW(ptr);
|
|
|
|
|
|
|
|
strcpyW(ptr, host);
|
|
|
|
ptr += strlenW(ptr);
|
|
|
|
|
|
|
|
if(req->path[0] != '/')
|
|
|
|
*ptr++ = '/';
|
|
|
|
|
|
|
|
strcpyW(ptr, req->path);
|
|
|
|
ptr += strlenW(ptr);
|
|
|
|
*ptr = 0;
|
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
|
2016-05-17 19:14:38 +02:00
|
|
|
return buf;
|
2010-07-24 17:56:41 +02:00
|
|
|
}
|
|
|
|
|
2008-02-26 20:20:41 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTPREQ_Destroy (internal)
|
|
|
|
*
|
|
|
|
* Deallocate request handle
|
|
|
|
*
|
|
|
|
*/
|
2009-07-07 21:46:09 +02:00
|
|
|
static void HTTPREQ_Destroy(object_header_t *hdr)
|
2008-02-26 20:20:41 +01:00
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_request_t *request = (http_request_t*) hdr;
|
2008-02-26 20:20:41 +01:00
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2013-10-04 16:52:43 +02:00
|
|
|
if(request->hCacheFile)
|
2011-03-01 19:59:39 +01:00
|
|
|
CloseHandle(request->hCacheFile);
|
2013-10-04 16:52:43 +02:00
|
|
|
if(request->req_file)
|
|
|
|
req_file_release(request->req_file);
|
2008-02-26 20:20:41 +01:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
request->headers_section.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection( &request->headers_section );
|
2011-11-16 16:29:44 +01:00
|
|
|
request->read_section.DebugInfo->Spare[0] = 0;
|
2011-03-01 19:59:39 +01:00
|
|
|
DeleteCriticalSection( &request->read_section );
|
2011-03-01 20:18:22 +01:00
|
|
|
WININET_Release(&request->session->hdr);
|
2008-02-26 20:20:41 +01:00
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
destroy_authinfo(request->authInfo);
|
|
|
|
destroy_authinfo(request->proxyAuthInfo);
|
2008-02-26 20:21:00 +01:00
|
|
|
|
2012-05-25 16:34:24 +02:00
|
|
|
if(request->server)
|
|
|
|
server_release(request->server);
|
2012-11-16 14:38:56 +01:00
|
|
|
if(request->proxy)
|
|
|
|
server_release(request->proxy);
|
2012-05-25 16:34:24 +02:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(request->path);
|
|
|
|
heap_free(request->verb);
|
|
|
|
heap_free(request->version);
|
|
|
|
heap_free(request->statusText);
|
2008-10-17 13:46:25 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
for (i = 0; i < request->nCustHeaders; i++)
|
2008-10-17 13:46:25 +02:00
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(request->custHeaders[i].lpszField);
|
|
|
|
heap_free(request->custHeaders[i].lpszValue);
|
2008-10-17 13:46:25 +02:00
|
|
|
}
|
2011-04-02 15:20:33 +02:00
|
|
|
destroy_data_stream(request->data_stream);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(request->custHeaders);
|
2008-10-17 13:46:25 +02:00
|
|
|
}
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
static void http_release_netconn(http_request_t *req, BOOL reuse)
|
2008-10-17 13:46:25 +02:00
|
|
|
{
|
2014-03-05 18:28:33 +01:00
|
|
|
TRACE("%p %p %x\n",req, req->netconn, reuse);
|
2011-05-10 11:26:43 +02:00
|
|
|
|
2013-12-11 10:48:41 +01:00
|
|
|
if(!is_valid_netconn(req->netconn))
|
2011-05-10 11:26:43 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(reuse && req->netconn->keep_alive) {
|
|
|
|
BOOL run_collector;
|
|
|
|
|
|
|
|
EnterCriticalSection(&connection_pool_cs);
|
2008-10-17 13:46:25 +02:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
list_add_head(&req->netconn->server->conn_pool, &req->netconn->pool_entry);
|
|
|
|
req->netconn->keep_until = GetTickCount64() + COLLECT_TIME;
|
|
|
|
req->netconn = NULL;
|
2008-10-17 13:46:25 +02:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
run_collector = !collector_running;
|
|
|
|
collector_running = TRUE;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&connection_pool_cs);
|
|
|
|
|
|
|
|
if(run_collector) {
|
|
|
|
HANDLE thread = NULL;
|
|
|
|
HMODULE module;
|
|
|
|
|
|
|
|
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR*)WININET_hModule, &module);
|
|
|
|
if(module)
|
|
|
|
thread = CreateThread(NULL, 0, collect_connections_proc, NULL, 0, NULL);
|
|
|
|
if(!thread) {
|
|
|
|
EnterCriticalSection(&connection_pool_cs);
|
|
|
|
collector_running = FALSE;
|
|
|
|
LeaveCriticalSection(&connection_pool_cs);
|
|
|
|
|
|
|
|
if(module)
|
|
|
|
FreeLibrary(module);
|
|
|
|
}
|
2011-12-30 21:55:42 +01:00
|
|
|
else
|
|
|
|
CloseHandle(thread);
|
2011-05-10 11:26:43 +02:00
|
|
|
}
|
2008-10-17 13:46:25 +02:00
|
|
|
return;
|
2011-05-10 11:26:43 +02:00
|
|
|
}
|
2008-10-17 13:46:25 +02:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
INTERNET_SendCallback(&req->hdr, req->hdr.dwContext,
|
2008-02-26 20:21:00 +01:00
|
|
|
INTERNET_STATUS_CLOSING_CONNECTION, 0, 0);
|
|
|
|
|
2013-12-11 10:48:41 +01:00
|
|
|
close_netconn(req->netconn);
|
2008-02-26 20:21:00 +01:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
INTERNET_SendCallback(&req->hdr, req->hdr.dwContext,
|
2008-02-26 20:21:00 +01:00
|
|
|
INTERNET_STATUS_CONNECTION_CLOSED, 0, 0);
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
static BOOL HTTP_KeepAlive(http_request_t *request)
|
2009-08-11 00:20:45 +02:00
|
|
|
{
|
|
|
|
WCHAR szVersion[10];
|
|
|
|
WCHAR szConnectionResponse[20];
|
|
|
|
DWORD dwBufferSize = sizeof(szVersion);
|
|
|
|
BOOL keepalive = FALSE;
|
|
|
|
|
|
|
|
/* as per RFC 2068, S8.1.2.1, if the client is HTTP/1.1 then assume that
|
|
|
|
* the connection is keep-alive by default */
|
2011-03-01 19:59:39 +01:00
|
|
|
if (HTTP_HttpQueryInfoW(request, HTTP_QUERY_VERSION, szVersion, &dwBufferSize, NULL) == ERROR_SUCCESS
|
2009-12-14 02:27:29 +01:00
|
|
|
&& !strcmpiW(szVersion, g_szHttp1_1))
|
2009-08-11 00:20:45 +02:00
|
|
|
{
|
|
|
|
keepalive = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwBufferSize = sizeof(szConnectionResponse);
|
2011-03-01 19:59:39 +01:00
|
|
|
if (HTTP_HttpQueryInfoW(request, HTTP_QUERY_PROXY_CONNECTION, szConnectionResponse, &dwBufferSize, NULL) == ERROR_SUCCESS
|
|
|
|
|| HTTP_HttpQueryInfoW(request, HTTP_QUERY_CONNECTION, szConnectionResponse, &dwBufferSize, NULL) == ERROR_SUCCESS)
|
2009-08-11 00:20:45 +02:00
|
|
|
{
|
|
|
|
keepalive = !strcmpiW(szConnectionResponse, szKeepAlive);
|
|
|
|
}
|
|
|
|
|
|
|
|
return keepalive;
|
|
|
|
}
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
static void HTTPREQ_CloseConnection(object_header_t *hdr)
|
|
|
|
{
|
|
|
|
http_request_t *req = (http_request_t*)hdr;
|
|
|
|
|
2012-07-02 17:15:04 +02:00
|
|
|
http_release_netconn(req, drain_content(req, FALSE));
|
2011-05-10 11:26:43 +02:00
|
|
|
}
|
|
|
|
|
2013-04-22 11:02:50 +02:00
|
|
|
static DWORD str_to_buffer(const WCHAR *str, void *buffer, DWORD *size, BOOL unicode)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
if (unicode)
|
|
|
|
{
|
2013-07-30 11:09:19 +02:00
|
|
|
WCHAR *buf = buffer;
|
|
|
|
|
|
|
|
if (str) len = strlenW(str);
|
|
|
|
else len = 0;
|
2013-04-22 11:02:50 +02:00
|
|
|
if (*size < (len + 1) * sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
*size = (len + 1) * sizeof(WCHAR);
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
2013-07-30 11:09:19 +02:00
|
|
|
if (str) strcpyW(buf, str);
|
|
|
|
else buf[0] = 0;
|
|
|
|
|
2013-04-22 11:02:50 +02:00
|
|
|
*size = len;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-30 11:09:19 +02:00
|
|
|
char *buf = buffer;
|
|
|
|
|
|
|
|
if (str) len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
|
|
|
|
else len = 1;
|
2013-04-22 11:02:50 +02:00
|
|
|
if (*size < len)
|
|
|
|
{
|
|
|
|
*size = len;
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
2013-07-30 11:09:19 +02:00
|
|
|
if (str) WideCharToMultiByte(CP_ACP, 0, str, -1, buf, *size, NULL, NULL);
|
|
|
|
else buf[0] = 0;
|
|
|
|
|
2013-04-22 11:02:50 +02:00
|
|
|
*size = len - 1;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD HTTPREQ_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
|
2008-03-12 02:23:20 +01:00
|
|
|
{
|
2009-07-13 01:41:50 +02:00
|
|
|
http_request_t *req = (http_request_t*)hdr;
|
2008-03-12 02:23:48 +01:00
|
|
|
|
2008-03-12 02:23:20 +01:00
|
|
|
switch(option) {
|
2009-08-11 00:20:45 +02:00
|
|
|
case INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO:
|
|
|
|
{
|
|
|
|
INTERNET_DIAGNOSTIC_SOCKET_INFO *info = buffer;
|
|
|
|
|
|
|
|
FIXME("INTERNET_DIAGNOSTIC_SOCKET_INFO stub\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(INTERNET_DIAGNOSTIC_SOCKET_INFO))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
*size = sizeof(INTERNET_DIAGNOSTIC_SOCKET_INFO);
|
|
|
|
/* FIXME: can't get a SOCKET from our connection since we don't use
|
|
|
|
* winsock
|
|
|
|
*/
|
|
|
|
info->Socket = 0;
|
|
|
|
/* FIXME: get source port from req->netConnection */
|
|
|
|
info->SourcePort = 0;
|
2012-11-19 11:48:08 +01:00
|
|
|
info->DestPort = req->server->port;
|
2009-08-11 00:20:45 +02:00
|
|
|
info->Flags = 0;
|
|
|
|
if (HTTP_KeepAlive(req))
|
|
|
|
info->Flags |= IDSI_FLAG_KEEP_ALIVE;
|
2012-11-19 11:48:08 +01:00
|
|
|
if (req->proxy)
|
2009-08-11 00:20:45 +02:00
|
|
|
info->Flags |= IDSI_FLAG_PROXY;
|
2013-12-11 10:48:41 +01:00
|
|
|
if (is_valid_netconn(req->netconn) && req->netconn->secure)
|
2009-08-11 00:20:45 +02:00
|
|
|
info->Flags |= IDSI_FLAG_SECURE;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-06-04 18:01:19 +02:00
|
|
|
case 98:
|
|
|
|
TRACE("Queried undocumented option 98, forwarding to INTERNET_OPTION_SECURITY_FLAGS\n");
|
|
|
|
/* fall through */
|
2009-06-23 08:29:00 +02:00
|
|
|
case INTERNET_OPTION_SECURITY_FLAGS:
|
|
|
|
{
|
2010-09-30 22:33:47 +02:00
|
|
|
DWORD flags;
|
2009-06-23 08:29:00 +02:00
|
|
|
|
|
|
|
if (*size < sizeof(ULONG))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
2013-12-11 10:48:41 +01:00
|
|
|
flags = is_valid_netconn(req->netconn) ? req->netconn->security_flags : req->security_flags | req->server->security_flags;
|
2010-09-30 22:33:47 +02:00
|
|
|
*(DWORD *)buffer = flags;
|
2012-05-25 16:35:12 +02:00
|
|
|
|
|
|
|
TRACE("INTERNET_OPTION_SECURITY_FLAGS %x\n", flags);
|
2009-06-23 08:29:00 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-12 02:23:20 +01:00
|
|
|
case INTERNET_OPTION_HANDLE_TYPE:
|
|
|
|
TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(ULONG))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD*)buffer = INTERNET_HANDLE_TYPE_HTTP_REQUEST;
|
|
|
|
return ERROR_SUCCESS;
|
2008-03-12 02:23:48 +01:00
|
|
|
|
|
|
|
case INTERNET_OPTION_URL: {
|
2016-05-18 18:02:30 +02:00
|
|
|
WCHAR *url;
|
|
|
|
DWORD res;
|
2008-03-12 02:23:48 +01:00
|
|
|
|
|
|
|
TRACE("INTERNET_OPTION_URL\n");
|
|
|
|
|
2016-05-18 18:02:30 +02:00
|
|
|
url = compose_request_url(req);
|
|
|
|
if(!url)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2008-07-03 14:34:40 +02:00
|
|
|
|
2016-05-18 18:02:30 +02:00
|
|
|
res = str_to_buffer(url, buffer, size, unicode);
|
|
|
|
heap_free(url);
|
|
|
|
return res;
|
2008-03-12 02:23:48 +01:00
|
|
|
}
|
2013-04-22 11:02:50 +02:00
|
|
|
case INTERNET_OPTION_USER_AGENT:
|
|
|
|
return str_to_buffer(req->session->appInfo->agent, buffer, size, unicode);
|
|
|
|
case INTERNET_OPTION_USERNAME:
|
|
|
|
return str_to_buffer(req->session->userName, buffer, size, unicode);
|
|
|
|
case INTERNET_OPTION_PASSWORD:
|
|
|
|
return str_to_buffer(req->session->password, buffer, size, unicode);
|
|
|
|
case INTERNET_OPTION_PROXY_USERNAME:
|
|
|
|
return str_to_buffer(req->session->appInfo->proxyUsername, buffer, size, unicode);
|
|
|
|
case INTERNET_OPTION_PROXY_PASSWORD:
|
|
|
|
return str_to_buffer(req->session->appInfo->proxyPassword, buffer, size, unicode);
|
2008-03-12 02:24:06 +01:00
|
|
|
|
2009-06-16 15:13:52 +02:00
|
|
|
case INTERNET_OPTION_CACHE_TIMESTAMPS: {
|
|
|
|
INTERNET_CACHE_ENTRY_INFOW *info;
|
|
|
|
INTERNET_CACHE_TIMESTAMPS *ts = buffer;
|
|
|
|
DWORD nbytes, error;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("INTERNET_OPTION_CACHE_TIMESTAMPS\n");
|
|
|
|
|
2016-05-17 19:14:38 +02:00
|
|
|
if(!req->req_file)
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
|
2009-06-16 15:13:52 +02:00
|
|
|
if (*size < sizeof(*ts))
|
|
|
|
{
|
|
|
|
*size = sizeof(*ts);
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
2016-05-17 19:14:38 +02:00
|
|
|
|
2009-06-16 15:13:52 +02:00
|
|
|
nbytes = 0;
|
2016-05-17 19:14:38 +02:00
|
|
|
ret = GetUrlCacheEntryInfoW(req->req_file->url, NULL, &nbytes);
|
2009-06-16 15:13:52 +02:00
|
|
|
error = GetLastError();
|
|
|
|
if (!ret && error == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
2011-04-21 13:39:03 +02:00
|
|
|
if (!(info = heap_alloc(nbytes)))
|
2009-06-16 15:13:52 +02:00
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
2016-05-17 19:14:38 +02:00
|
|
|
GetUrlCacheEntryInfoW(req->req_file->url, info, &nbytes);
|
2009-06-16 15:13:52 +02:00
|
|
|
|
|
|
|
ts->ftExpires = info->ExpireTime;
|
|
|
|
ts->ftLastModified = info->LastModifiedTime;
|
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(info);
|
2009-06-16 15:13:52 +02:00
|
|
|
*size = sizeof(*ts);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2008-03-12 02:24:06 +01:00
|
|
|
case INTERNET_OPTION_DATAFILE_NAME: {
|
|
|
|
DWORD req_size;
|
|
|
|
|
|
|
|
TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
|
|
|
|
|
2013-10-04 16:52:43 +02:00
|
|
|
if(!req->req_file) {
|
2008-03-12 02:24:06 +01:00
|
|
|
*size = 0;
|
|
|
|
return ERROR_INTERNET_ITEM_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(unicode) {
|
2013-10-04 16:52:43 +02:00
|
|
|
req_size = (lstrlenW(req->req_file->file_name)+1) * sizeof(WCHAR);
|
2008-03-12 02:24:06 +01:00
|
|
|
if(*size < req_size)
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = req_size;
|
2013-10-04 16:52:43 +02:00
|
|
|
memcpy(buffer, req->req_file->file_name, *size);
|
2008-03-12 02:24:06 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}else {
|
2013-10-04 16:52:43 +02:00
|
|
|
req_size = WideCharToMultiByte(CP_ACP, 0, req->req_file->file_name, -1, NULL, 0, NULL, NULL);
|
2008-03-12 02:24:06 +01:00
|
|
|
if (req_size > *size)
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
2013-10-04 16:52:43 +02:00
|
|
|
*size = WideCharToMultiByte(CP_ACP, 0, req->req_file->file_name,
|
2008-03-12 02:24:06 +01:00
|
|
|
-1, buffer, *size, NULL, NULL);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2008-03-12 02:24:23 +01:00
|
|
|
|
|
|
|
case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT: {
|
|
|
|
PCCERT_CONTEXT context;
|
|
|
|
|
2013-05-03 15:19:22 +02:00
|
|
|
if(!req->netconn)
|
|
|
|
return ERROR_INTERNET_INVALID_OPERATION;
|
|
|
|
|
2010-09-30 22:09:04 +02:00
|
|
|
if(*size < sizeof(INTERNET_CERTIFICATE_INFOA)) {
|
|
|
|
*size = sizeof(INTERNET_CERTIFICATE_INFOA);
|
2008-03-12 02:24:23 +01:00
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
context = (PCCERT_CONTEXT)NETCON_GetCert(req->netconn);
|
2008-03-12 02:24:23 +01:00
|
|
|
if(context) {
|
2010-09-30 22:09:04 +02:00
|
|
|
INTERNET_CERTIFICATE_INFOA *info = (INTERNET_CERTIFICATE_INFOA*)buffer;
|
2008-03-12 02:24:23 +01:00
|
|
|
DWORD len;
|
|
|
|
|
2012-06-17 16:18:36 +02:00
|
|
|
memset(info, 0, sizeof(*info));
|
2008-03-12 02:24:23 +01:00
|
|
|
info->ftExpiry = context->pCertInfo->NotAfter;
|
|
|
|
info->ftStart = context->pCertInfo->NotBefore;
|
2010-09-30 22:09:04 +02:00
|
|
|
len = CertNameToStrA(context->dwCertEncodingType,
|
2012-05-30 12:13:53 +02:00
|
|
|
&context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, NULL, 0);
|
2010-09-30 22:09:04 +02:00
|
|
|
info->lpszSubjectInfo = LocalAlloc(0, len);
|
|
|
|
if(info->lpszSubjectInfo)
|
|
|
|
CertNameToStrA(context->dwCertEncodingType,
|
2012-05-30 12:13:53 +02:00
|
|
|
&context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG,
|
2010-09-30 22:09:04 +02:00
|
|
|
info->lpszSubjectInfo, len);
|
|
|
|
len = CertNameToStrA(context->dwCertEncodingType,
|
2012-05-30 12:13:53 +02:00
|
|
|
&context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, NULL, 0);
|
2010-09-30 22:09:04 +02:00
|
|
|
info->lpszIssuerInfo = LocalAlloc(0, len);
|
|
|
|
if(info->lpszIssuerInfo)
|
|
|
|
CertNameToStrA(context->dwCertEncodingType,
|
2012-05-30 12:13:53 +02:00
|
|
|
&context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG,
|
2010-09-30 22:09:04 +02:00
|
|
|
info->lpszIssuerInfo, len);
|
2011-05-10 11:26:43 +02:00
|
|
|
info->dwKeySize = NETCON_GetCipherStrength(req->netconn);
|
2008-03-12 02:24:23 +01:00
|
|
|
CertFreeCertificateContext(context);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2012-06-15 11:38:24 +02:00
|
|
|
return ERROR_NOT_SUPPORTED;
|
2008-03-12 02:24:23 +01:00
|
|
|
}
|
2012-01-13 15:15:20 +01:00
|
|
|
case INTERNET_OPTION_CONNECT_TIMEOUT:
|
|
|
|
if (*size < sizeof(DWORD))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD *)buffer = req->connect_timeout;
|
2012-05-23 18:24:02 +02:00
|
|
|
return ERROR_SUCCESS;
|
2012-05-24 15:24:43 +02:00
|
|
|
case INTERNET_OPTION_REQUEST_FLAGS: {
|
|
|
|
DWORD flags = 0;
|
2012-05-23 18:24:02 +02:00
|
|
|
|
|
|
|
if (*size < sizeof(DWORD))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
2012-05-24 15:24:43 +02:00
|
|
|
/* FIXME: Add support for:
|
|
|
|
* INTERNET_REQFLAG_FROM_CACHE
|
|
|
|
* INTERNET_REQFLAG_CACHE_WRITE_DISABLED
|
|
|
|
*/
|
|
|
|
|
2012-11-19 11:48:08 +01:00
|
|
|
if(req->proxy)
|
2012-05-24 15:24:43 +02:00
|
|
|
flags |= INTERNET_REQFLAG_VIA_PROXY;
|
2013-04-30 17:00:18 +02:00
|
|
|
if(!req->status_code)
|
2012-05-24 15:24:43 +02:00
|
|
|
flags |= INTERNET_REQFLAG_NO_HEADERS;
|
2012-05-23 18:24:02 +02:00
|
|
|
|
2012-05-24 15:24:43 +02:00
|
|
|
TRACE("INTERNET_OPTION_REQUEST_FLAGS returning %x\n", flags);
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD*)buffer = flags;
|
2012-01-13 15:15:20 +01:00
|
|
|
return ERROR_SUCCESS;
|
2008-03-12 02:23:20 +01:00
|
|
|
}
|
2012-05-24 15:24:43 +02:00
|
|
|
}
|
2008-03-12 02:23:20 +01:00
|
|
|
|
2010-05-25 12:19:32 +02:00
|
|
|
return INET_QueryOption(hdr, option, buffer, size, unicode);
|
2008-03-12 02:23:20 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD HTTPREQ_SetOption(object_header_t *hdr, DWORD option, void *buffer, DWORD size)
|
2008-02-26 20:22:02 +01:00
|
|
|
{
|
2009-07-13 01:41:50 +02:00
|
|
|
http_request_t *req = (http_request_t*)hdr;
|
2008-02-26 20:22:02 +01:00
|
|
|
|
|
|
|
switch(option) {
|
2012-06-07 15:40:45 +02:00
|
|
|
case 99: /* Undocumented, seems to be INTERNET_OPTION_SECURITY_FLAGS with argument validation */
|
|
|
|
TRACE("Undocumented option 99\n");
|
|
|
|
|
|
|
|
if (!buffer || size != sizeof(DWORD))
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
if(*(DWORD*)buffer & ~SECURITY_SET_MASK)
|
|
|
|
return ERROR_INTERNET_OPTION_NOT_SETTABLE;
|
|
|
|
|
|
|
|
/* fall through */
|
2010-09-29 01:46:41 +02:00
|
|
|
case INTERNET_OPTION_SECURITY_FLAGS:
|
|
|
|
{
|
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
if (!buffer || size != sizeof(DWORD))
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
flags = *(DWORD *)buffer;
|
2012-06-06 17:38:30 +02:00
|
|
|
TRACE("INTERNET_OPTION_SECURITY_FLAGS %08x\n", flags);
|
|
|
|
flags &= SECURITY_SET_MASK;
|
|
|
|
req->security_flags |= flags;
|
2013-12-11 10:48:41 +01:00
|
|
|
if(is_valid_netconn(req->netconn))
|
2012-06-06 17:38:30 +02:00
|
|
|
req->netconn->security_flags |= flags;
|
2010-09-29 01:46:41 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2012-01-13 15:15:20 +01:00
|
|
|
case INTERNET_OPTION_CONNECT_TIMEOUT:
|
2012-01-13 15:15:48 +01:00
|
|
|
if (!buffer || size != sizeof(DWORD)) return ERROR_INVALID_PARAMETER;
|
2012-01-13 15:15:20 +01:00
|
|
|
req->connect_timeout = *(DWORD *)buffer;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2008-02-26 20:22:02 +01:00
|
|
|
case INTERNET_OPTION_SEND_TIMEOUT:
|
2012-01-13 15:15:48 +01:00
|
|
|
if (!buffer || size != sizeof(DWORD)) return ERROR_INVALID_PARAMETER;
|
|
|
|
req->send_timeout = *(DWORD *)buffer;
|
|
|
|
return ERROR_SUCCESS;
|
2011-05-04 13:47:32 +02:00
|
|
|
|
2012-01-13 15:15:48 +01:00
|
|
|
case INTERNET_OPTION_RECEIVE_TIMEOUT:
|
|
|
|
if (!buffer || size != sizeof(DWORD)) return ERROR_INVALID_PARAMETER;
|
|
|
|
req->receive_timeout = *(DWORD *)buffer;
|
|
|
|
return ERROR_SUCCESS;
|
2008-12-02 17:15:07 +01:00
|
|
|
|
|
|
|
case INTERNET_OPTION_USERNAME:
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(req->session->userName);
|
2011-03-01 20:18:22 +01:00
|
|
|
if (!(req->session->userName = heap_strdupW(buffer))) return ERROR_OUTOFMEMORY;
|
2008-12-02 17:15:07 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case INTERNET_OPTION_PASSWORD:
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(req->session->password);
|
2011-03-01 20:18:22 +01:00
|
|
|
if (!(req->session->password = heap_strdupW(buffer))) return ERROR_OUTOFMEMORY;
|
2008-12-02 17:15:07 +01:00
|
|
|
return ERROR_SUCCESS;
|
2013-04-22 11:02:50 +02:00
|
|
|
|
|
|
|
case INTERNET_OPTION_PROXY_USERNAME:
|
|
|
|
heap_free(req->session->appInfo->proxyUsername);
|
|
|
|
if (!(req->session->appInfo->proxyUsername = heap_strdupW(buffer))) return ERROR_OUTOFMEMORY;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case INTERNET_OPTION_PROXY_PASSWORD:
|
|
|
|
heap_free(req->session->appInfo->proxyPassword);
|
|
|
|
if (!(req->session->appInfo->proxyPassword = heap_strdupW(buffer))) return ERROR_OUTOFMEMORY;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2009-05-29 23:35:13 +02:00
|
|
|
case INTERNET_OPTION_HTTP_DECODING:
|
|
|
|
if(size != sizeof(BOOL))
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
req->decoding = *(BOOL*)buffer;
|
|
|
|
return ERROR_SUCCESS;
|
2008-02-26 20:22:02 +01:00
|
|
|
}
|
|
|
|
|
2012-03-08 12:19:14 +01:00
|
|
|
return INET_SetOption(hdr, option, buffer, size);
|
2008-02-26 20:22:02 +01:00
|
|
|
}
|
|
|
|
|
2012-11-02 13:49:22 +01:00
|
|
|
static void commit_cache_entry(http_request_t *req)
|
|
|
|
{
|
2016-05-17 19:14:38 +02:00
|
|
|
WCHAR *header;
|
|
|
|
DWORD header_len;
|
|
|
|
BOOL res;
|
2012-11-02 13:49:22 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", req);
|
|
|
|
|
|
|
|
CloseHandle(req->hCacheFile);
|
|
|
|
req->hCacheFile = NULL;
|
|
|
|
|
2016-05-17 19:14:38 +02:00
|
|
|
header = build_response_header(req, TRUE);
|
|
|
|
header_len = (header ? strlenW(header) : 0);
|
|
|
|
res = CommitUrlCacheEntryW(req->req_file->url, req->req_file->file_name, req->expires,
|
|
|
|
req->last_modified, NORMAL_CACHE_ENTRY,
|
|
|
|
header, header_len, NULL, 0);
|
|
|
|
if(res)
|
|
|
|
req->req_file->is_committed = TRUE;
|
|
|
|
else
|
|
|
|
WARN("CommitUrlCacheEntry failed: %u\n", GetLastError());
|
|
|
|
heap_free(header);
|
2012-11-02 13:49:22 +01:00
|
|
|
}
|
|
|
|
|
2012-11-02 13:49:05 +01:00
|
|
|
static void create_cache_entry(http_request_t *req)
|
|
|
|
{
|
2013-03-13 17:05:41 +01:00
|
|
|
static const WCHAR no_cacheW[] = {'n','o','-','c','a','c','h','e',0};
|
|
|
|
static const WCHAR no_storeW[] = {'n','o','-','s','t','o','r','e',0};
|
|
|
|
|
2012-11-02 13:49:05 +01:00
|
|
|
WCHAR file_name[MAX_PATH+1];
|
2016-05-17 19:14:38 +02:00
|
|
|
WCHAR *url;
|
2013-03-13 17:05:41 +01:00
|
|
|
BOOL b = TRUE;
|
2012-11-02 13:49:05 +01:00
|
|
|
|
|
|
|
/* FIXME: We should free previous cache file earlier */
|
2013-10-04 16:52:43 +02:00
|
|
|
if(req->req_file) {
|
|
|
|
req_file_release(req->req_file);
|
|
|
|
req->req_file = NULL;
|
|
|
|
}
|
|
|
|
if(req->hCacheFile) {
|
|
|
|
CloseHandle(req->hCacheFile);
|
|
|
|
req->hCacheFile = NULL;
|
|
|
|
}
|
2012-11-02 13:49:05 +01:00
|
|
|
|
2013-03-13 17:05:41 +01:00
|
|
|
if(req->hdr.dwFlags & INTERNET_FLAG_NO_CACHE_WRITE)
|
|
|
|
b = FALSE;
|
|
|
|
|
|
|
|
if(b) {
|
2014-09-25 14:21:37 +02:00
|
|
|
int header_idx;
|
|
|
|
|
|
|
|
EnterCriticalSection( &req->headers_section );
|
|
|
|
|
|
|
|
header_idx = HTTP_GetCustomHeaderIndex(req, szCache_Control, 0, FALSE);
|
2013-04-24 11:23:18 +02:00
|
|
|
if(header_idx != -1) {
|
|
|
|
WCHAR *ptr;
|
|
|
|
|
|
|
|
for(ptr=req->custHeaders[header_idx].lpszValue; *ptr; ) {
|
|
|
|
WCHAR *end;
|
|
|
|
|
|
|
|
while(*ptr==' ' || *ptr=='\t')
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
end = strchrW(ptr, ',');
|
|
|
|
if(!end)
|
|
|
|
end = ptr + strlenW(ptr);
|
|
|
|
|
|
|
|
if(!strncmpiW(ptr, no_cacheW, sizeof(no_cacheW)/sizeof(*no_cacheW)-1)
|
|
|
|
|| !strncmpiW(ptr, no_storeW, sizeof(no_storeW)/sizeof(*no_storeW)-1)) {
|
|
|
|
b = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = end;
|
|
|
|
if(*ptr == ',')
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &req->headers_section );
|
2013-03-13 17:05:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!b) {
|
|
|
|
if(!(req->hdr.dwFlags & INTERNET_FLAG_NEED_FILE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
FIXME("INTERNET_FLAG_NEED_FILE is not supported correctly\n");
|
|
|
|
}
|
|
|
|
|
2016-05-17 19:14:38 +02:00
|
|
|
url = compose_request_url(req);
|
|
|
|
if(!url) {
|
2012-11-02 13:49:05 +01:00
|
|
|
WARN("Could not get URL\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-08 15:59:20 +01:00
|
|
|
b = CreateUrlCacheEntryW(url, req->contentLength == ~0u ? 0 : req->contentLength, NULL, file_name, 0);
|
2012-11-02 13:49:05 +01:00
|
|
|
if(!b) {
|
|
|
|
WARN("Could not create cache entry: %08x\n", GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-04 16:52:43 +02:00
|
|
|
create_req_file(file_name, &req->req_file);
|
2016-05-17 19:14:38 +02:00
|
|
|
req->req_file->url = url;
|
2013-10-04 16:52:43 +02:00
|
|
|
|
|
|
|
req->hCacheFile = CreateFileW(file_name, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
|
2012-11-02 13:49:05 +01:00
|
|
|
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if(req->hCacheFile == INVALID_HANDLE_VALUE) {
|
|
|
|
WARN("Could not create file: %u\n", GetLastError());
|
|
|
|
req->hCacheFile = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(req->read_size) {
|
|
|
|
DWORD written;
|
|
|
|
|
|
|
|
b = WriteFile(req->hCacheFile, req->read_buf+req->read_pos, req->read_size, &written, NULL);
|
|
|
|
if(!b)
|
|
|
|
FIXME("WriteFile failed: %u\n", GetLastError());
|
2012-11-02 13:49:22 +01:00
|
|
|
|
|
|
|
if(req->data_stream->vtbl->end_of_data(req->data_stream, req))
|
|
|
|
commit_cache_entry(req);
|
2012-11-02 13:49:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 23:01:28 +02:00
|
|
|
/* read some more data into the read buffer (the read section must be held) */
|
2009-11-30 19:59:56 +01:00
|
|
|
static DWORD read_more_data( http_request_t *req, int maxlen )
|
2009-01-13 00:28:25 +01:00
|
|
|
{
|
2009-11-30 19:59:40 +01:00
|
|
|
DWORD res;
|
2009-05-14 16:45:38 +02:00
|
|
|
int len;
|
2009-01-13 00:28:25 +01:00
|
|
|
|
2009-05-29 23:35:13 +02:00
|
|
|
if (req->read_pos)
|
2009-05-14 16:45:38 +02:00
|
|
|
{
|
|
|
|
/* move existing data to the start of the buffer */
|
2009-05-29 23:35:13 +02:00
|
|
|
if(req->read_size)
|
|
|
|
memmove( req->read_buf, req->read_buf + req->read_pos, req->read_size );
|
2009-05-14 16:45:38 +02:00
|
|
|
req->read_pos = 0;
|
2009-01-13 00:28:25 +01:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:45:38 +02:00
|
|
|
if (maxlen == -1) maxlen = sizeof(req->read_buf);
|
2009-05-29 23:35:13 +02:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
res = NETCON_recv( req->netconn, req->read_buf + req->read_size,
|
2015-06-18 13:28:24 +02:00
|
|
|
maxlen - req->read_size, TRUE, &len );
|
2009-11-30 19:59:56 +01:00
|
|
|
if(res == ERROR_SUCCESS)
|
|
|
|
req->read_size += len;
|
2009-05-29 23:35:13 +02:00
|
|
|
|
2009-11-30 19:59:56 +01:00
|
|
|
return res;
|
2009-01-13 00:28:25 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 23:01:28 +02:00
|
|
|
/* remove some amount of data from the read buffer (the read section must be held) */
|
2009-07-13 01:41:50 +02:00
|
|
|
static void remove_data( http_request_t *req, int count )
|
2008-03-02 19:35:11 +01:00
|
|
|
{
|
2009-05-14 16:45:38 +02:00
|
|
|
if (!(req->read_size -= count)) req->read_pos = 0;
|
|
|
|
else req->read_pos += count;
|
|
|
|
}
|
2008-03-02 19:35:11 +01:00
|
|
|
|
2013-04-25 10:15:19 +02:00
|
|
|
static DWORD read_line( http_request_t *req, LPSTR buffer, DWORD *len )
|
2009-05-14 16:45:38 +02:00
|
|
|
{
|
|
|
|
int count, bytes_read, pos = 0;
|
2009-11-30 19:59:56 +01:00
|
|
|
DWORD res;
|
2008-03-02 19:35:11 +01:00
|
|
|
|
2009-05-28 23:01:28 +02:00
|
|
|
EnterCriticalSection( &req->read_section );
|
2009-05-14 16:45:38 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
2009-05-29 23:34:37 +02:00
|
|
|
BYTE *eol = memchr( req->read_buf + req->read_pos, '\n', req->read_size );
|
2008-03-02 19:35:11 +01:00
|
|
|
|
2009-05-14 16:45:38 +02:00
|
|
|
if (eol)
|
|
|
|
{
|
|
|
|
count = eol - (req->read_buf + req->read_pos);
|
|
|
|
bytes_read = count + 1;
|
|
|
|
}
|
|
|
|
else count = bytes_read = req->read_size;
|
2008-03-02 19:35:11 +01:00
|
|
|
|
2009-05-14 16:45:38 +02:00
|
|
|
count = min( count, *len - pos );
|
|
|
|
memcpy( buffer + pos, req->read_buf + req->read_pos, count );
|
|
|
|
pos += count;
|
|
|
|
remove_data( req, bytes_read );
|
|
|
|
if (eol) break;
|
2008-03-02 19:35:11 +01:00
|
|
|
|
2013-04-25 10:15:19 +02:00
|
|
|
if ((res = read_more_data( req, -1 )))
|
|
|
|
{
|
|
|
|
WARN( "read failed %u\n", res );
|
|
|
|
LeaveCriticalSection( &req->read_section );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
if (!req->read_size)
|
2009-05-14 16:45:38 +02:00
|
|
|
{
|
|
|
|
*len = 0;
|
2013-04-25 10:15:19 +02:00
|
|
|
TRACE( "returning empty string\n" );
|
2009-05-28 23:01:28 +02:00
|
|
|
LeaveCriticalSection( &req->read_section );
|
2013-04-25 10:15:19 +02:00
|
|
|
return ERROR_SUCCESS;
|
2009-05-14 16:45:38 +02:00
|
|
|
}
|
2008-03-02 19:35:11 +01:00
|
|
|
}
|
2009-05-28 23:01:28 +02:00
|
|
|
LeaveCriticalSection( &req->read_section );
|
2008-03-02 19:35:11 +01:00
|
|
|
|
2009-05-14 16:45:38 +02:00
|
|
|
if (pos < *len)
|
|
|
|
{
|
|
|
|
if (pos && buffer[pos - 1] == '\r') pos--;
|
|
|
|
*len = pos + 1;
|
|
|
|
}
|
|
|
|
buffer[*len - 1] = 0;
|
|
|
|
TRACE( "returning %s\n", debugstr_a(buffer));
|
2013-04-25 10:15:19 +02:00
|
|
|
return ERROR_SUCCESS;
|
2008-03-02 19:35:11 +01:00
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
/* check if we have reached the end of the data to read (the read section must be held) */
|
|
|
|
static BOOL end_of_read_data( http_request_t *req )
|
|
|
|
{
|
|
|
|
return !req->read_size && req->data_stream->vtbl->end_of_data(req->data_stream, req);
|
|
|
|
}
|
|
|
|
|
2017-03-09 18:20:28 +01:00
|
|
|
static DWORD read_http_stream(http_request_t *req, BYTE *buf, DWORD size, DWORD *read, BOOL allow_blocking)
|
2012-11-02 13:49:05 +01:00
|
|
|
{
|
|
|
|
DWORD res;
|
|
|
|
|
2017-03-09 18:20:28 +01:00
|
|
|
res = req->data_stream->vtbl->read(req->data_stream, req, buf, size, read, allow_blocking);
|
2017-03-09 18:19:03 +01:00
|
|
|
if(res != ERROR_SUCCESS)
|
2017-03-09 18:18:10 +01:00
|
|
|
*read = 0;
|
2012-11-02 13:49:05 +01:00
|
|
|
assert(*read <= size);
|
|
|
|
|
2012-11-02 13:49:22 +01:00
|
|
|
if(req->hCacheFile) {
|
|
|
|
if(*read) {
|
|
|
|
BOOL bres;
|
|
|
|
DWORD written;
|
2012-11-02 13:49:05 +01:00
|
|
|
|
2012-11-02 13:49:22 +01:00
|
|
|
bres = WriteFile(req->hCacheFile, buf, *read, &written, NULL);
|
|
|
|
if(!bres)
|
|
|
|
FIXME("WriteFile failed: %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2017-03-09 18:19:03 +01:00
|
|
|
if((res == ERROR_SUCCESS && !*read) || req->data_stream->vtbl->end_of_data(req->data_stream, req))
|
2012-11-02 13:49:22 +01:00
|
|
|
commit_cache_entry(req);
|
2012-11-02 13:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
/* fetch some more data into the read buffer (the read section must be held) */
|
2017-03-09 18:20:28 +01:00
|
|
|
static DWORD refill_read_buffer(http_request_t *req, BOOL allow_blocking, DWORD *read_bytes)
|
2011-04-02 15:20:33 +02:00
|
|
|
{
|
2012-11-02 13:49:05 +01:00
|
|
|
DWORD res, read=0;
|
2011-04-02 15:20:33 +02:00
|
|
|
|
|
|
|
if(req->read_size == sizeof(req->read_buf))
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
if(req->read_pos) {
|
|
|
|
if(req->read_size)
|
|
|
|
memmove(req->read_buf, req->read_buf+req->read_pos, req->read_size);
|
|
|
|
req->read_pos = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:49:05 +01:00
|
|
|
res = read_http_stream(req, req->read_buf+req->read_size, sizeof(req->read_buf) - req->read_size,
|
2017-03-09 18:20:28 +01:00
|
|
|
&read, allow_blocking);
|
2017-03-09 18:19:03 +01:00
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
return res;
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
req->read_size += read;
|
|
|
|
|
|
|
|
TRACE("read %u bytes, read_size %u\n", read, req->read_size);
|
2011-05-23 16:10:09 +02:00
|
|
|
if(read_bytes)
|
|
|
|
*read_bytes = read;
|
2011-04-02 15:20:33 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL netconn_end_of_data(data_stream_t *stream, http_request_t *req)
|
|
|
|
{
|
|
|
|
netconn_stream_t *netconn_stream = (netconn_stream_t*)stream;
|
2013-12-11 10:48:41 +01:00
|
|
|
return netconn_stream->content_read == netconn_stream->content_length || !is_valid_netconn(req->netconn);
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD netconn_read(data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size,
|
2017-03-09 18:20:28 +01:00
|
|
|
DWORD *read, BOOL allow_blocking)
|
2011-04-02 15:20:33 +02:00
|
|
|
{
|
|
|
|
netconn_stream_t *netconn_stream = (netconn_stream_t*)stream;
|
2013-04-25 10:15:19 +02:00
|
|
|
DWORD res = ERROR_SUCCESS;
|
2017-03-09 18:20:20 +01:00
|
|
|
int ret = 0;
|
2011-04-02 15:20:33 +02:00
|
|
|
|
|
|
|
size = min(size, netconn_stream->content_length-netconn_stream->content_read);
|
|
|
|
|
2013-12-11 10:48:41 +01:00
|
|
|
if(size && is_valid_netconn(req->netconn)) {
|
2017-03-09 18:20:28 +01:00
|
|
|
res = NETCON_recv(req->netconn, buf, size, allow_blocking, &ret);
|
2017-03-09 18:20:20 +01:00
|
|
|
if(res == ERROR_SUCCESS) {
|
|
|
|
if(!ret)
|
2014-03-05 18:27:36 +01:00
|
|
|
netconn_stream->content_length = netconn_stream->content_read;
|
2017-03-09 18:20:20 +01:00
|
|
|
netconn_stream->content_read += ret;
|
2014-03-05 18:27:36 +01:00
|
|
|
}
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
|
|
|
|
2017-03-09 18:20:20 +01:00
|
|
|
TRACE("res %u read %u bytes\n", res, ret);
|
2015-06-16 12:24:54 +02:00
|
|
|
*read = ret;
|
2013-04-25 10:15:19 +02:00
|
|
|
return res;
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
static BOOL netconn_drain_content(data_stream_t *stream, http_request_t *req)
|
|
|
|
{
|
|
|
|
netconn_stream_t *netconn_stream = (netconn_stream_t*)stream;
|
|
|
|
BYTE buf[1024];
|
2017-02-27 15:20:26 +01:00
|
|
|
int len, res;
|
|
|
|
size_t size;
|
2011-05-10 11:26:43 +02:00
|
|
|
|
2017-02-27 15:20:26 +01:00
|
|
|
if(netconn_stream->content_length == ~0u)
|
|
|
|
return FALSE;
|
2011-05-10 11:26:43 +02:00
|
|
|
|
2017-02-27 15:20:26 +01:00
|
|
|
while(netconn_stream->content_read < netconn_stream->content_length) {
|
|
|
|
size = min(sizeof(buf), netconn_stream->content_length-netconn_stream->content_read);
|
|
|
|
res = NETCON_recv(req->netconn, buf, size, FALSE, &len);
|
|
|
|
if(res || !len)
|
2011-05-10 11:26:43 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
netconn_stream->content_read += len;
|
2017-02-27 15:20:26 +01:00
|
|
|
}
|
2011-05-10 11:26:43 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
static void netconn_destroy(data_stream_t *stream)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static const data_stream_vtbl_t netconn_stream_vtbl = {
|
|
|
|
netconn_end_of_data,
|
|
|
|
netconn_read,
|
2011-05-10 11:26:43 +02:00
|
|
|
netconn_drain_content,
|
2011-04-02 15:20:33 +02:00
|
|
|
netconn_destroy
|
|
|
|
};
|
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
static char next_chunked_data_char(chunked_stream_t *stream)
|
2011-04-02 15:20:33 +02:00
|
|
|
{
|
2016-08-01 16:17:00 +02:00
|
|
|
assert(stream->buf_size);
|
2013-09-18 13:40:24 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
stream->buf_size--;
|
|
|
|
return stream->buf[stream->buf_pos++];
|
2009-05-14 16:45:38 +02:00
|
|
|
}
|
2008-03-26 11:31:21 +01:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
static BOOL chunked_end_of_data(data_stream_t *stream, http_request_t *req)
|
2009-05-14 16:45:38 +02:00
|
|
|
{
|
2011-04-02 15:20:33 +02:00
|
|
|
chunked_stream_t *chunked_stream = (chunked_stream_t*)stream;
|
2016-08-01 16:17:00 +02:00
|
|
|
return chunked_stream->state == CHUNKED_STREAM_STATE_END_OF_STREAM;
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
2008-03-26 11:31:21 +01:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
static DWORD chunked_read(data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size,
|
2017-03-09 18:20:28 +01:00
|
|
|
DWORD *read, BOOL allow_blocking)
|
2011-04-02 15:20:33 +02:00
|
|
|
{
|
|
|
|
chunked_stream_t *chunked_stream = (chunked_stream_t*)stream;
|
2016-08-01 16:17:00 +02:00
|
|
|
DWORD ret_read = 0, res = ERROR_SUCCESS;
|
|
|
|
BOOL continue_read = TRUE;
|
|
|
|
int read_bytes;
|
|
|
|
char ch;
|
2011-04-02 15:20:33 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
do {
|
|
|
|
TRACE("state %d\n", chunked_stream->state);
|
|
|
|
|
|
|
|
/* Ensure that we have data in the buffer for states that need it. */
|
|
|
|
if(!chunked_stream->buf_size) {
|
|
|
|
switch(chunked_stream->state) {
|
|
|
|
case CHUNKED_STREAM_STATE_READING_CHUNK_SIZE:
|
|
|
|
case CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_SIZE:
|
|
|
|
case CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_DATA:
|
|
|
|
case CHUNKED_STREAM_STATE_DISCARD_EOL_AT_END:
|
|
|
|
chunked_stream->buf_pos = 0;
|
2017-03-09 18:20:28 +01:00
|
|
|
res = NETCON_recv(req->netconn, chunked_stream->buf, sizeof(chunked_stream->buf), allow_blocking, &read_bytes);
|
2016-08-01 16:17:00 +02:00
|
|
|
if(res == ERROR_SUCCESS && read_bytes) {
|
|
|
|
chunked_stream->buf_size += read_bytes;
|
|
|
|
}else if(res == WSAEWOULDBLOCK) {
|
2017-03-09 18:18:10 +01:00
|
|
|
if(ret_read)
|
|
|
|
res = ERROR_SUCCESS;
|
2016-08-01 16:17:00 +02:00
|
|
|
continue_read = FALSE;
|
|
|
|
continue;
|
|
|
|
}else {
|
|
|
|
chunked_stream->state = CHUNKED_STREAM_STATE_END_OF_STREAM;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-03-26 11:31:21 +01:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
switch(chunked_stream->state) {
|
|
|
|
case CHUNKED_STREAM_STATE_READING_CHUNK_SIZE:
|
|
|
|
ch = next_chunked_data_char(chunked_stream);
|
|
|
|
|
|
|
|
if(ch >= '0' && ch <= '9') {
|
|
|
|
chunked_stream->chunk_size = chunked_stream->chunk_size * 16 + ch - '0';
|
|
|
|
}else if(ch >= 'a' && ch <= 'f') {
|
|
|
|
chunked_stream->chunk_size = chunked_stream->chunk_size * 16 + ch - 'a' + 10;
|
|
|
|
}else if (ch >= 'A' && ch <= 'F') {
|
|
|
|
chunked_stream->chunk_size = chunked_stream->chunk_size * 16 + ch - 'A' + 10;
|
|
|
|
}else if (ch == ';' || ch == '\r' || ch == '\n') {
|
|
|
|
TRACE("reading %u byte chunk\n", chunked_stream->chunk_size);
|
|
|
|
chunked_stream->buf_size++;
|
|
|
|
chunked_stream->buf_pos--;
|
|
|
|
if(req->contentLength == ~0u) req->contentLength = chunked_stream->chunk_size;
|
|
|
|
else req->contentLength += chunked_stream->chunk_size;
|
|
|
|
chunked_stream->state = CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_SIZE;
|
|
|
|
}
|
|
|
|
break;
|
2009-05-14 16:45:38 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
case CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_SIZE:
|
|
|
|
ch = next_chunked_data_char(chunked_stream);
|
|
|
|
if(ch == '\n')
|
|
|
|
chunked_stream->state = chunked_stream->chunk_size
|
|
|
|
? CHUNKED_STREAM_STATE_READING_CHUNK
|
|
|
|
: CHUNKED_STREAM_STATE_DISCARD_EOL_AT_END;
|
|
|
|
else if(ch != '\r')
|
|
|
|
WARN("unexpected char '%c'\n", ch);
|
|
|
|
break;
|
2009-05-14 16:45:38 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
case CHUNKED_STREAM_STATE_READING_CHUNK:
|
|
|
|
assert(chunked_stream->chunk_size);
|
|
|
|
if(!size) {
|
|
|
|
continue_read = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2011-04-02 15:20:33 +02:00
|
|
|
read_bytes = min(size, chunked_stream->chunk_size);
|
2009-06-07 21:19:06 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
if(chunked_stream->buf_size) {
|
|
|
|
if(read_bytes > chunked_stream->buf_size)
|
|
|
|
read_bytes = chunked_stream->buf_size;
|
2009-06-07 21:19:06 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
memcpy(buf+ret_read, chunked_stream->buf+chunked_stream->buf_pos, read_bytes);
|
|
|
|
chunked_stream->buf_pos += read_bytes;
|
|
|
|
chunked_stream->buf_size -= read_bytes;
|
|
|
|
}else {
|
|
|
|
res = NETCON_recv(req->netconn, (char*)buf+ret_read, read_bytes,
|
2017-03-09 18:20:28 +01:00
|
|
|
allow_blocking, (int*)&read_bytes);
|
2016-08-01 16:17:00 +02:00
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
continue_read = FALSE;
|
2011-04-02 15:20:33 +02:00
|
|
|
break;
|
2016-08-01 16:17:00 +02:00
|
|
|
}
|
2009-06-07 21:19:06 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
if(!read_bytes) {
|
|
|
|
chunked_stream->state = CHUNKED_STREAM_STATE_END_OF_STREAM;
|
|
|
|
continue;
|
|
|
|
}
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
2010-07-20 00:32:59 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
chunked_stream->chunk_size -= read_bytes;
|
|
|
|
size -= read_bytes;
|
|
|
|
ret_read += read_bytes;
|
|
|
|
if(!chunked_stream->chunk_size)
|
|
|
|
chunked_stream->state = CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_DATA;
|
2017-03-09 18:20:28 +01:00
|
|
|
allow_blocking = FALSE;
|
2016-08-01 16:17:00 +02:00
|
|
|
break;
|
2009-12-17 00:02:47 +01:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
case CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_DATA:
|
|
|
|
ch = next_chunked_data_char(chunked_stream);
|
|
|
|
if(ch == '\n')
|
|
|
|
chunked_stream->state = CHUNKED_STREAM_STATE_READING_CHUNK_SIZE;
|
|
|
|
else if(ch != '\r')
|
|
|
|
WARN("unexpected char '%c'\n", ch);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHUNKED_STREAM_STATE_DISCARD_EOL_AT_END:
|
|
|
|
ch = next_chunked_data_char(chunked_stream);
|
|
|
|
if(ch == '\n')
|
|
|
|
chunked_stream->state = CHUNKED_STREAM_STATE_END_OF_STREAM;
|
|
|
|
else if(ch != '\r')
|
|
|
|
WARN("unexpected char '%c'\n", ch);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHUNKED_STREAM_STATE_END_OF_STREAM:
|
|
|
|
continue_read = FALSE;
|
|
|
|
break;
|
2009-06-07 21:19:06 +02:00
|
|
|
}
|
2016-08-01 16:17:00 +02:00
|
|
|
} while(continue_read);
|
2011-04-02 15:20:33 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
if(ret_read)
|
|
|
|
res = ERROR_SUCCESS;
|
2017-03-09 18:18:10 +01:00
|
|
|
if(res != ERROR_SUCCESS)
|
2016-08-01 16:17:00 +02:00
|
|
|
return res;
|
2009-06-07 21:19:06 +02:00
|
|
|
|
2016-08-01 16:17:00 +02:00
|
|
|
TRACE("read %d bytes\n", ret_read);
|
2011-04-02 15:20:33 +02:00
|
|
|
*read = ret_read;
|
2016-08-01 16:17:00 +02:00
|
|
|
return ERROR_SUCCESS;
|
2009-06-07 21:19:06 +02:00
|
|
|
}
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
static BOOL chunked_drain_content(data_stream_t *stream, http_request_t *req)
|
|
|
|
{
|
|
|
|
chunked_stream_t *chunked_stream = (chunked_stream_t*)stream;
|
2016-08-01 16:17:00 +02:00
|
|
|
return chunked_stream->state == CHUNKED_STREAM_STATE_END_OF_STREAM;
|
2011-05-10 11:26:43 +02:00
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
static void chunked_destroy(data_stream_t *stream)
|
2009-06-07 21:19:06 +02:00
|
|
|
{
|
2011-04-02 15:20:33 +02:00
|
|
|
chunked_stream_t *chunked_stream = (chunked_stream_t*)stream;
|
|
|
|
heap_free(chunked_stream);
|
|
|
|
}
|
2009-06-07 21:19:06 +02:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
static const data_stream_vtbl_t chunked_stream_vtbl = {
|
|
|
|
chunked_end_of_data,
|
|
|
|
chunked_read,
|
2011-05-10 11:26:43 +02:00
|
|
|
chunked_drain_content,
|
2011-04-02 15:20:33 +02:00
|
|
|
chunked_destroy
|
|
|
|
};
|
|
|
|
|
|
|
|
/* set the request content length based on the headers */
|
2012-05-03 12:19:47 +02:00
|
|
|
static DWORD set_content_length(http_request_t *request)
|
2011-04-02 15:20:33 +02:00
|
|
|
{
|
|
|
|
static const WCHAR szChunked[] = {'c','h','u','n','k','e','d',0};
|
2014-06-25 14:41:47 +02:00
|
|
|
static const WCHAR headW[] = {'H','E','A','D',0};
|
2011-04-02 15:20:33 +02:00
|
|
|
WCHAR encoding[20];
|
|
|
|
DWORD size;
|
2009-06-07 21:19:06 +02:00
|
|
|
|
2014-06-25 14:41:47 +02:00
|
|
|
if(request->status_code == HTTP_STATUS_NO_CONTENT || !strcmpW(request->verb, headW)) {
|
2011-05-13 13:48:15 +02:00
|
|
|
request->contentLength = request->netconn_stream.content_length = 0;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
size = sizeof(request->contentLength);
|
|
|
|
if (HTTP_HttpQueryInfoW(request, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH,
|
|
|
|
&request->contentLength, &size, NULL) != ERROR_SUCCESS)
|
|
|
|
request->contentLength = ~0u;
|
|
|
|
request->netconn_stream.content_length = request->contentLength;
|
|
|
|
request->netconn_stream.content_read = request->read_size;
|
|
|
|
|
|
|
|
size = sizeof(encoding);
|
|
|
|
if (HTTP_HttpQueryInfoW(request, HTTP_QUERY_TRANSFER_ENCODING, encoding, &size, NULL) == ERROR_SUCCESS &&
|
|
|
|
!strcmpiW(encoding, szChunked))
|
|
|
|
{
|
|
|
|
chunked_stream_t *chunked_stream;
|
|
|
|
|
|
|
|
chunked_stream = heap_alloc(sizeof(*chunked_stream));
|
|
|
|
if(!chunked_stream)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
chunked_stream->data_stream.vtbl = &chunked_stream_vtbl;
|
|
|
|
chunked_stream->buf_size = chunked_stream->buf_pos = 0;
|
2016-08-01 16:17:00 +02:00
|
|
|
chunked_stream->chunk_size = 0;
|
|
|
|
chunked_stream->state = CHUNKED_STREAM_STATE_READING_CHUNK_SIZE;
|
2011-04-02 15:20:33 +02:00
|
|
|
|
|
|
|
if(request->read_size) {
|
|
|
|
memcpy(chunked_stream->buf, request->read_buf+request->read_pos, request->read_size);
|
|
|
|
chunked_stream->buf_size = request->read_size;
|
|
|
|
request->read_size = request->read_pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
request->data_stream = &chunked_stream->data_stream;
|
|
|
|
request->contentLength = ~0u;
|
2009-06-07 21:19:06 +02:00
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
if(request->decoding) {
|
|
|
|
int encoding_idx;
|
2011-03-17 01:01:19 +01:00
|
|
|
|
2014-03-05 18:28:33 +01:00
|
|
|
static const WCHAR deflateW[] = {'d','e','f','l','a','t','e',0};
|
2011-04-02 15:20:33 +02:00
|
|
|
static const WCHAR gzipW[] = {'g','z','i','p',0};
|
2011-03-17 01:01:19 +01:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
encoding_idx = HTTP_GetCustomHeaderIndex(request, szContent_Encoding, 0, FALSE);
|
2014-03-05 18:28:33 +01:00
|
|
|
if(encoding_idx != -1) {
|
|
|
|
if(!strcmpiW(request->custHeaders[encoding_idx].lpszValue, gzipW)) {
|
|
|
|
HTTP_DeleteCustomHeader(request, encoding_idx);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2014-03-05 18:28:33 +01:00
|
|
|
return init_gzip_stream(request, TRUE);
|
|
|
|
}
|
|
|
|
if(!strcmpiW(request->custHeaders[encoding_idx].lpszValue, deflateW)) {
|
|
|
|
HTTP_DeleteCustomHeader(request, encoding_idx);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2014-03-05 18:28:33 +01:00
|
|
|
return init_gzip_stream(request, FALSE);
|
|
|
|
}
|
2013-04-30 16:59:49 +02:00
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
2009-06-07 21:19:06 +02:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
return ERROR_SUCCESS;
|
2009-06-07 21:19:06 +02:00
|
|
|
}
|
|
|
|
|
2011-06-10 14:47:04 +02:00
|
|
|
static void send_request_complete(http_request_t *req, DWORD_PTR result, DWORD error)
|
2009-05-14 16:45:38 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2011-06-10 14:47:04 +02:00
|
|
|
|
|
|
|
iar.dwResult = result;
|
|
|
|
iar.dwError = error;
|
|
|
|
|
|
|
|
INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
2017-03-13 14:47:19 +01:00
|
|
|
static void HTTP_ReceiveRequestData(http_request_t *req)
|
2011-06-10 14:47:04 +02:00
|
|
|
{
|
2017-03-13 14:47:19 +01:00
|
|
|
DWORD res, read = 0;
|
2009-05-14 16:45:38 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", req);
|
|
|
|
|
2009-05-28 23:01:28 +02:00
|
|
|
EnterCriticalSection( &req->read_section );
|
2011-05-23 16:10:09 +02:00
|
|
|
|
2017-03-13 14:47:19 +01:00
|
|
|
res = refill_read_buffer(req, FALSE, &read);
|
|
|
|
if(res == ERROR_SUCCESS)
|
2017-03-09 18:19:03 +01:00
|
|
|
read += req->read_size;
|
2011-05-23 16:10:09 +02:00
|
|
|
|
2009-05-28 23:01:28 +02:00
|
|
|
LeaveCriticalSection( &req->read_section );
|
2009-05-14 16:45:38 +02:00
|
|
|
|
2017-03-09 18:19:03 +01:00
|
|
|
if(res != WSAEWOULDBLOCK && (res != ERROR_SUCCESS || !read)) {
|
2011-05-23 16:10:09 +02:00
|
|
|
WARN("res %u read %u, closing connection\n", res, read);
|
|
|
|
http_release_netconn(req, FALSE);
|
|
|
|
}
|
|
|
|
|
2017-03-09 18:19:03 +01:00
|
|
|
if(res != ERROR_SUCCESS && res != WSAEWOULDBLOCK) {
|
2011-06-10 14:47:04 +02:00
|
|
|
send_request_complete(req, 0, res);
|
2013-02-26 15:43:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-13 14:47:19 +01:00
|
|
|
send_request_complete(req, req->session->hdr.dwInternalFlags & INET_OPENURL ? (DWORD_PTR)req->hdr.hInternet : 1, 0);
|
2008-03-26 11:31:21 +01:00
|
|
|
}
|
|
|
|
|
2009-05-28 23:01:28 +02:00
|
|
|
/* read data from the http connection (the read section must be held) */
|
2017-03-09 18:20:28 +01:00
|
|
|
static DWORD HTTPREQ_Read(http_request_t *req, void *buffer, DWORD size, DWORD *read, BOOL allow_blocking)
|
2008-03-02 19:35:11 +01:00
|
|
|
{
|
2011-04-02 15:20:33 +02:00
|
|
|
DWORD current_read = 0, ret_read = 0;
|
|
|
|
DWORD res = ERROR_SUCCESS;
|
|
|
|
|
2009-05-28 23:01:28 +02:00
|
|
|
EnterCriticalSection( &req->read_section );
|
2009-06-07 21:19:06 +02:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
if(req->read_size) {
|
|
|
|
ret_read = min(size, req->read_size);
|
|
|
|
memcpy(buffer, req->read_buf+req->read_pos, ret_read);
|
|
|
|
req->read_size -= ret_read;
|
|
|
|
req->read_pos += ret_read;
|
2017-03-09 18:20:28 +01:00
|
|
|
allow_blocking = FALSE;
|
2009-05-14 16:45:38 +02:00
|
|
|
}
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
if(ret_read < size) {
|
2017-03-09 18:20:28 +01:00
|
|
|
res = read_http_stream(req, (BYTE*)buffer+ret_read, size-ret_read, ¤t_read, allow_blocking);
|
2017-03-09 18:19:03 +01:00
|
|
|
if(res == ERROR_SUCCESS)
|
|
|
|
ret_read += current_read;
|
|
|
|
else if(res == WSAEWOULDBLOCK && ret_read)
|
|
|
|
res = ERROR_SUCCESS;
|
2009-05-14 16:45:38 +02:00
|
|
|
}
|
|
|
|
|
2009-05-28 23:01:28 +02:00
|
|
|
LeaveCriticalSection( &req->read_section );
|
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
*read = ret_read;
|
|
|
|
TRACE( "retrieved %u bytes (%u)\n", ret_read, req->contentLength );
|
|
|
|
|
2017-03-09 18:19:03 +01:00
|
|
|
if(res != WSAEWOULDBLOCK && (!ret_read || res != ERROR_SUCCESS))
|
2011-05-13 13:48:00 +02:00
|
|
|
http_release_netconn(req, res == ERROR_SUCCESS);
|
2009-05-14 16:45:38 +02:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
return res;
|
2008-03-26 22:22:04 +01:00
|
|
|
}
|
|
|
|
|
2012-07-02 17:15:04 +02:00
|
|
|
static BOOL drain_content(http_request_t *req, BOOL blocking)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
2013-12-11 10:48:41 +01:00
|
|
|
if(!is_valid_netconn(req->netconn) || req->contentLength == -1)
|
2012-07-02 17:15:04 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if(!strcmpW(req->verb, szHEAD))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if(!blocking)
|
|
|
|
return req->data_stream->vtbl->drain_content(req->data_stream, req);
|
|
|
|
|
|
|
|
EnterCriticalSection( &req->read_section );
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
DWORD bytes_read, res;
|
|
|
|
BYTE buf[4096];
|
|
|
|
|
2017-03-09 18:20:28 +01:00
|
|
|
res = HTTPREQ_Read(req, buf, sizeof(buf), &bytes_read, TRUE);
|
2012-07-02 17:15:04 +02:00
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!bytes_read) {
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection( &req->read_section );
|
|
|
|
return ret;
|
|
|
|
}
|
2009-05-14 16:45:38 +02:00
|
|
|
|
2013-01-28 11:23:58 +01:00
|
|
|
typedef struct {
|
|
|
|
task_header_t hdr;
|
|
|
|
void *buf;
|
|
|
|
DWORD size;
|
2017-03-09 18:19:36 +01:00
|
|
|
DWORD read_pos;
|
2013-01-28 11:23:58 +01:00
|
|
|
DWORD *ret_read;
|
2017-03-09 18:19:36 +01:00
|
|
|
} read_file_task_t;
|
2013-01-28 11:23:58 +01:00
|
|
|
|
2017-03-09 18:19:36 +01:00
|
|
|
static void async_read_file_proc(task_header_t *hdr)
|
2009-01-15 16:41:42 +01:00
|
|
|
{
|
2017-03-09 18:19:36 +01:00
|
|
|
read_file_task_t *task = (read_file_task_t*)hdr;
|
2013-01-28 11:23:58 +01:00
|
|
|
http_request_t *req = (http_request_t*)task->hdr.hdr;
|
2017-03-09 18:19:36 +01:00
|
|
|
DWORD res = ERROR_SUCCESS, read = task->read_pos, complete_arg = 0;
|
2009-01-15 16:41:42 +01:00
|
|
|
|
2017-03-09 18:19:36 +01:00
|
|
|
TRACE("req %p buf %p size %u read_pos %u ret_read %p\n", req, task->buf, task->size, task->read_pos, task->ret_read);
|
|
|
|
|
|
|
|
if(task->buf) {
|
|
|
|
DWORD read_bytes;
|
|
|
|
while (read < task->size) {
|
2017-03-09 18:20:28 +01:00
|
|
|
res = HTTPREQ_Read(req, (char*)task->buf + read, task->size - read, &read_bytes, TRUE);
|
2017-03-09 18:19:36 +01:00
|
|
|
if (res != ERROR_SUCCESS || !read_bytes)
|
|
|
|
break;
|
|
|
|
read += read_bytes;
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
EnterCriticalSection(&req->read_section);
|
2017-03-09 18:20:28 +01:00
|
|
|
res = refill_read_buffer(req, TRUE, &read);
|
2017-03-09 18:19:36 +01:00
|
|
|
LeaveCriticalSection(&req->read_section);
|
2009-01-15 16:41:42 +01:00
|
|
|
|
2016-05-04 12:39:43 +02:00
|
|
|
if(task->ret_read)
|
2017-03-09 18:19:36 +01:00
|
|
|
complete_arg = read; /* QueryDataAvailable reports read bytes in request complete notification */
|
|
|
|
if(res != ERROR_SUCCESS || !read)
|
|
|
|
http_release_netconn(req, drain_content(req, FALSE));
|
2016-04-28 05:12:49 +02:00
|
|
|
}
|
|
|
|
|
2017-03-09 18:19:36 +01:00
|
|
|
TRACE("res %u read %u\n", res, read);
|
|
|
|
|
|
|
|
if(task->ret_read)
|
|
|
|
*task->ret_read = read;
|
|
|
|
|
|
|
|
/* FIXME: We should report bytes transferred before decoding content. */
|
|
|
|
INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_RESPONSE_RECEIVED, &read, sizeof(read));
|
|
|
|
|
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
complete_arg = res;
|
|
|
|
send_request_complete(req, res == ERROR_SUCCESS, complete_arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD async_read(http_request_t *req, void *buf, DWORD size, DWORD read_pos, DWORD *ret_read)
|
|
|
|
{
|
|
|
|
read_file_task_t *task;
|
|
|
|
|
|
|
|
task = alloc_async_task(&req->hdr, async_read_file_proc, sizeof(*task));
|
|
|
|
if(!task)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
task->buf = buf;
|
|
|
|
task->size = size;
|
|
|
|
task->read_pos = read_pos;
|
|
|
|
task->ret_read = ret_read;
|
|
|
|
|
|
|
|
INTERNET_AsyncCall(&task->hdr);
|
|
|
|
return ERROR_IO_PENDING;
|
2009-01-15 16:41:42 +01:00
|
|
|
}
|
|
|
|
|
2017-03-09 18:20:14 +01:00
|
|
|
static DWORD HTTPREQ_ReadFile(object_header_t *hdr, void *buf, DWORD size, DWORD *ret_read,
|
2009-01-15 16:41:42 +01:00
|
|
|
DWORD flags, DWORD_PTR context)
|
|
|
|
{
|
2009-07-13 01:41:50 +02:00
|
|
|
http_request_t *req = (http_request_t*)hdr;
|
2017-03-09 18:19:50 +01:00
|
|
|
DWORD res = ERROR_SUCCESS, read = 0, cread, error = ERROR_SUCCESS;
|
|
|
|
BOOL allow_blocking, notify_received = FALSE;
|
2009-01-15 16:41:42 +01:00
|
|
|
|
2016-05-04 12:39:43 +02:00
|
|
|
TRACE("(%p %p %u %x)\n", req, buf, size, flags);
|
|
|
|
|
2009-01-15 16:41:42 +01:00
|
|
|
if (flags & ~(IRF_ASYNC|IRF_NO_WAIT))
|
|
|
|
FIXME("these dwFlags aren't implemented: 0x%x\n", flags & ~(IRF_ASYNC|IRF_NO_WAIT));
|
|
|
|
|
2017-03-09 18:19:50 +01:00
|
|
|
allow_blocking = !(req->session->appInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC);
|
|
|
|
|
|
|
|
if(allow_blocking || TryEnterCriticalSection(&req->read_section)) {
|
|
|
|
if(allow_blocking)
|
|
|
|
EnterCriticalSection(&req->read_section);
|
|
|
|
if(hdr->dwError == ERROR_SUCCESS)
|
|
|
|
hdr->dwError = INTERNET_HANDLE_IN_USE;
|
|
|
|
else if(hdr->dwError == INTERNET_HANDLE_IN_USE)
|
|
|
|
hdr->dwError = ERROR_INTERNET_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
if(req->read_size) {
|
|
|
|
read = min(size, req->read_size);
|
|
|
|
memcpy(buf, req->read_buf + req->read_pos, read);
|
|
|
|
req->read_size -= read;
|
|
|
|
req->read_pos += read;
|
|
|
|
}
|
2009-01-15 16:41:42 +01:00
|
|
|
|
2017-03-09 18:19:50 +01:00
|
|
|
if(read < size && (!read || !(flags & IRF_NO_WAIT)) && !end_of_read_data(req)) {
|
|
|
|
LeaveCriticalSection(&req->read_section);
|
|
|
|
INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
|
|
|
|
EnterCriticalSection( &req->read_section );
|
|
|
|
notify_received = TRUE;
|
|
|
|
|
|
|
|
while(read < size) {
|
2017-03-09 18:20:28 +01:00
|
|
|
res = HTTPREQ_Read(req, (char*)buf+read, size-read, &cread, allow_blocking);
|
2017-03-09 18:19:50 +01:00
|
|
|
read += cread;
|
|
|
|
if (res != ERROR_SUCCESS || !cread)
|
|
|
|
break;
|
2009-05-28 23:01:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 18:19:50 +01:00
|
|
|
if(hdr->dwError == INTERNET_HANDLE_IN_USE)
|
|
|
|
hdr->dwError = ERROR_SUCCESS;
|
|
|
|
else
|
|
|
|
error = hdr->dwError;
|
2011-04-02 15:20:33 +02:00
|
|
|
|
2010-07-20 00:33:24 +02:00
|
|
|
LeaveCriticalSection( &req->read_section );
|
2017-03-09 18:19:50 +01:00
|
|
|
}else {
|
|
|
|
res = WSAEWOULDBLOCK;
|
2010-07-20 00:33:24 +02:00
|
|
|
}
|
|
|
|
|
2017-03-09 18:19:50 +01:00
|
|
|
if(res == WSAEWOULDBLOCK) {
|
|
|
|
if(!(flags & IRF_NO_WAIT))
|
|
|
|
return async_read(req, buf, size, read, ret_read);
|
|
|
|
if(!read)
|
|
|
|
return async_read(req, NULL, 0, 0, NULL);
|
|
|
|
res = ERROR_SUCCESS;
|
|
|
|
}
|
2009-01-15 16:41:42 +01:00
|
|
|
|
2012-11-23 15:18:31 +01:00
|
|
|
*ret_read = read;
|
2017-03-09 18:19:50 +01:00
|
|
|
if (res != ERROR_SUCCESS)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
if(notify_received)
|
2009-01-15 16:41:42 +01:00
|
|
|
INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_RESPONSE_RECEIVED,
|
2012-11-23 15:18:31 +01:00
|
|
|
&read, sizeof(read));
|
2017-03-09 18:19:50 +01:00
|
|
|
return error;
|
2009-01-15 16:41:42 +01:00
|
|
|
}
|
|
|
|
|
2009-11-30 00:13:39 +01:00
|
|
|
static DWORD HTTPREQ_WriteFile(object_header_t *hdr, const void *buffer, DWORD size, DWORD *written)
|
2008-02-26 20:21:34 +01:00
|
|
|
{
|
2009-11-30 00:13:21 +01:00
|
|
|
DWORD res;
|
2011-03-01 19:59:39 +01:00
|
|
|
http_request_t *request = (http_request_t*)hdr;
|
2008-02-26 20:21:34 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext, INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
|
2009-04-08 15:22:05 +02:00
|
|
|
|
2009-04-08 15:21:28 +02:00
|
|
|
*written = 0;
|
2011-05-10 11:26:43 +02:00
|
|
|
res = NETCON_send(request->netconn, buffer, size, 0, (LPINT)written);
|
2009-11-30 00:13:21 +01:00
|
|
|
if (res == ERROR_SUCCESS)
|
2011-03-01 20:18:22 +01:00
|
|
|
request->bytesWritten += *written;
|
2009-04-08 15:21:28 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext, INTERNET_STATUS_REQUEST_SENT, written, sizeof(DWORD));
|
2009-11-30 00:13:39 +01:00
|
|
|
return res;
|
2008-02-26 20:21:34 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD HTTPREQ_QueryDataAvailable(object_header_t *hdr, DWORD *available, DWORD flags, DWORD_PTR ctx)
|
2008-02-29 12:57:57 +01:00
|
|
|
{
|
2009-07-13 01:41:50 +02:00
|
|
|
http_request_t *req = (http_request_t*)hdr;
|
2017-03-09 18:20:02 +01:00
|
|
|
DWORD res = ERROR_SUCCESS, avail = 0, error = ERROR_SUCCESS;
|
|
|
|
BOOL allow_blocking, notify_received = FALSE;
|
2008-02-29 12:57:57 +01:00
|
|
|
|
|
|
|
TRACE("(%p %p %x %lx)\n", req, available, flags, ctx);
|
|
|
|
|
2017-03-09 18:20:02 +01:00
|
|
|
if (flags & ~(IRF_ASYNC|IRF_NO_WAIT))
|
|
|
|
FIXME("these dwFlags aren't implemented: 0x%x\n", flags & ~(IRF_ASYNC|IRF_NO_WAIT));
|
2008-02-29 12:57:57 +01:00
|
|
|
|
2017-03-09 18:20:02 +01:00
|
|
|
*available = 0;
|
|
|
|
allow_blocking = !(req->session->appInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC);
|
2008-02-29 12:57:57 +01:00
|
|
|
|
2017-03-09 18:20:02 +01:00
|
|
|
if(allow_blocking || TryEnterCriticalSection(&req->read_section)) {
|
|
|
|
if(allow_blocking)
|
|
|
|
EnterCriticalSection(&req->read_section);
|
|
|
|
if(hdr->dwError == ERROR_SUCCESS)
|
|
|
|
hdr->dwError = INTERNET_HANDLE_IN_USE;
|
|
|
|
else if(hdr->dwError == INTERNET_HANDLE_IN_USE)
|
|
|
|
hdr->dwError = ERROR_INTERNET_INTERNAL_ERROR;
|
2008-02-29 12:57:57 +01:00
|
|
|
|
2017-03-09 18:20:02 +01:00
|
|
|
avail = req->read_size;
|
2009-05-28 23:01:28 +02:00
|
|
|
|
2017-03-09 18:20:02 +01:00
|
|
|
if(!avail && !end_of_read_data(req)) {
|
|
|
|
LeaveCriticalSection(&req->read_section);
|
|
|
|
INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
|
|
|
|
EnterCriticalSection( &req->read_section );
|
|
|
|
notify_received = TRUE;
|
|
|
|
|
2017-03-09 18:20:28 +01:00
|
|
|
res = refill_read_buffer(req, allow_blocking, &avail);
|
2017-03-09 18:20:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(hdr->dwError == INTERNET_HANDLE_IN_USE)
|
|
|
|
hdr->dwError = ERROR_SUCCESS;
|
|
|
|
else
|
|
|
|
error = hdr->dwError;
|
|
|
|
|
|
|
|
LeaveCriticalSection( &req->read_section );
|
|
|
|
}else {
|
|
|
|
res = WSAEWOULDBLOCK;
|
2009-05-28 23:01:28 +02:00
|
|
|
}
|
|
|
|
|
2017-03-09 18:20:02 +01:00
|
|
|
if(res == WSAEWOULDBLOCK)
|
|
|
|
return async_read(req, NULL, 0, 0, available);
|
2008-02-29 12:57:57 +01:00
|
|
|
|
2017-03-09 18:20:02 +01:00
|
|
|
if (res != ERROR_SUCCESS)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
*available = avail;
|
|
|
|
if(notify_received)
|
|
|
|
INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_RESPONSE_RECEIVED,
|
|
|
|
&avail, sizeof(avail));
|
|
|
|
return error;
|
2008-02-29 12:57:57 +01:00
|
|
|
}
|
|
|
|
|
2013-10-04 16:52:58 +02:00
|
|
|
static DWORD HTTPREQ_LockRequestFile(object_header_t *hdr, req_file_t **ret)
|
|
|
|
{
|
|
|
|
http_request_t *req = (http_request_t*)hdr;
|
2013-10-04 16:53:22 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", req);
|
|
|
|
|
|
|
|
if(!req->req_file) {
|
|
|
|
WARN("No cache file name available\n");
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = req_file_addref(req->req_file);
|
|
|
|
return ERROR_SUCCESS;
|
2013-10-04 16:52:58 +02:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static const object_vtbl_t HTTPREQVtbl = {
|
2008-02-26 20:21:00 +01:00
|
|
|
HTTPREQ_Destroy,
|
2008-02-26 20:21:34 +01:00
|
|
|
HTTPREQ_CloseConnection,
|
2008-03-12 02:23:20 +01:00
|
|
|
HTTPREQ_QueryOption,
|
2008-02-26 20:22:02 +01:00
|
|
|
HTTPREQ_SetOption,
|
2008-03-02 19:35:11 +01:00
|
|
|
HTTPREQ_ReadFile,
|
2008-02-27 18:55:09 +01:00
|
|
|
HTTPREQ_WriteFile,
|
2008-02-29 12:57:57 +01:00
|
|
|
HTTPREQ_QueryDataAvailable,
|
2013-10-04 16:52:58 +02:00
|
|
|
NULL,
|
|
|
|
HTTPREQ_LockRequestFile
|
2008-02-26 20:20:41 +01:00
|
|
|
};
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
2004-03-30 06:36:09 +02:00
|
|
|
* HTTP_HttpOpenRequestW (internal)
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
|
|
|
* Open a HTTP request handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a HTTP request handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static DWORD HTTP_HttpOpenRequestW(http_session_t *session,
|
2009-11-30 20:00:44 +01:00
|
|
|
LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
|
|
|
|
LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
|
|
|
|
DWORD dwFlags, DWORD_PTR dwContext, HINTERNET *ret)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2011-05-10 11:26:43 +02:00
|
|
|
appinfo_t *hIC = session->appInfo;
|
2011-03-01 19:59:39 +01:00
|
|
|
http_request_t *request;
|
2016-12-15 18:35:53 +01:00
|
|
|
DWORD port, len;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("-->\n");
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
request = alloc_object(&session->hdr, &HTTPREQVtbl, sizeof(http_request_t));
|
|
|
|
if(!request)
|
2011-02-02 22:51:13 +01:00
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
request->hdr.htype = WH_HHTTPREQ;
|
|
|
|
request->hdr.dwFlags = dwFlags;
|
|
|
|
request->hdr.dwContext = dwContext;
|
2011-03-01 20:18:22 +01:00
|
|
|
request->contentLength = ~0u;
|
2011-02-02 22:51:13 +01:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
request->netconn_stream.data_stream.vtbl = &netconn_stream_vtbl;
|
|
|
|
request->data_stream = &request->netconn_stream.data_stream;
|
2012-01-13 15:15:04 +01:00
|
|
|
request->connect_timeout = session->connect_timeout;
|
2012-01-13 15:15:48 +01:00
|
|
|
request->send_timeout = session->send_timeout;
|
|
|
|
request->receive_timeout = session->receive_timeout;
|
2011-04-02 15:20:33 +02:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
InitializeCriticalSection( &request->headers_section );
|
|
|
|
request->headers_section.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": http_request_t.headers_section");
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
InitializeCriticalSection( &request->read_section );
|
2011-11-16 16:29:44 +01:00
|
|
|
request->read_section.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": http_request_t.read_section");
|
2004-07-19 23:49:39 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
WININET_AddRef( &session->hdr );
|
2011-03-01 20:18:22 +01:00
|
|
|
request->session = session;
|
2011-03-01 19:59:39 +01:00
|
|
|
list_add_head( &session->hdr.children, &request->hdr.entry );
|
2006-10-29 18:50:25 +01:00
|
|
|
|
2016-12-15 18:35:53 +01:00
|
|
|
port = session->hostPort;
|
|
|
|
if (port == INTERNET_INVALID_PORT_NUMBER)
|
|
|
|
port = (session->hdr.dwFlags & INTERNET_FLAG_SECURE) ?
|
|
|
|
INTERNET_DEFAULT_HTTPS_PORT : INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
|
|
|
|
request->server = get_server(substrz(session->hostName), port, (dwFlags & INTERNET_FLAG_SECURE) != 0, TRUE);
|
2012-05-25 16:34:24 +02:00
|
|
|
if(!request->server) {
|
|
|
|
WININET_Release(&request->hdr);
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2011-04-07 17:05:36 +02:00
|
|
|
if (dwFlags & INTERNET_FLAG_IGNORE_CERT_CN_INVALID)
|
2011-05-10 11:26:43 +02:00
|
|
|
request->security_flags |= SECURITY_FLAG_IGNORE_CERT_CN_INVALID;
|
2011-04-07 17:05:36 +02:00
|
|
|
if (dwFlags & INTERNET_FLAG_IGNORE_CERT_DATE_INVALID)
|
2011-05-10 11:26:43 +02:00
|
|
|
request->security_flags |= SECURITY_FLAG_IGNORE_CERT_DATE_INVALID;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2008-02-13 13:34:05 +01:00
|
|
|
if (lpszObjectName && *lpszObjectName) {
|
2002-06-22 01:59:49 +02:00
|
|
|
HRESULT rc;
|
2016-10-26 21:17:17 +02:00
|
|
|
WCHAR dummy;
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2016-10-26 21:17:17 +02:00
|
|
|
len = 1;
|
|
|
|
rc = UrlCanonicalizeW(lpszObjectName, &dummy, &len, URL_ESCAPE_SPACES_ONLY);
|
2002-06-22 01:59:49 +02:00
|
|
|
if (rc != E_POINTER)
|
2004-03-30 06:36:09 +02:00
|
|
|
len = strlenW(lpszObjectName)+1;
|
2011-04-21 13:39:03 +02:00
|
|
|
request->path = heap_alloc(len*sizeof(WCHAR));
|
2016-10-26 21:17:17 +02:00
|
|
|
rc = UrlCanonicalizeW(lpszObjectName, request->path, &len,
|
2001-01-21 22:09:00 +01:00
|
|
|
URL_ESCAPE_SPACES_ONLY);
|
2008-10-01 12:20:49 +02:00
|
|
|
if (rc != S_OK)
|
2002-06-22 01:59:49 +02:00
|
|
|
{
|
2006-10-05 13:18:56 +02:00
|
|
|
ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(lpszObjectName),rc);
|
2011-03-01 20:18:22 +01:00
|
|
|
strcpyW(request->path,lpszObjectName);
|
2002-06-22 01:59:49 +02:00
|
|
|
}
|
2009-05-29 23:34:25 +02:00
|
|
|
}else {
|
|
|
|
static const WCHAR slashW[] = {'/',0};
|
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
request->path = heap_strdupW(slashW);
|
2001-01-21 22:09:00 +01:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2008-02-13 13:34:05 +01:00
|
|
|
if (lpszReferrer && *lpszReferrer)
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_ProcessHeader(request, HTTP_REFERER, lpszReferrer, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2007-02-12 15:19:17 +01:00
|
|
|
if (lpszAcceptTypes)
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
|
|
|
int i;
|
2007-02-12 15:19:17 +01:00
|
|
|
for (i = 0; lpszAcceptTypes[i]; i++)
|
|
|
|
{
|
|
|
|
if (!*lpszAcceptTypes[i]) continue;
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_ProcessHeader(request, HTTP_ACCEPT, lpszAcceptTypes[i],
|
2007-02-12 15:19:17 +01:00
|
|
|
HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA |
|
|
|
|
HTTP_ADDHDR_FLAG_REQ |
|
2015-06-25 12:28:02 +02:00
|
|
|
(i == 0 ? (HTTP_ADDHDR_FLAG_REPLACE | HTTP_ADDHDR_FLAG_ADD) : 0));
|
2007-02-12 15:19:17 +01:00
|
|
|
}
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
request->verb = heap_strdupW(lpszVerb && *lpszVerb ? lpszVerb : szGET);
|
2012-12-10 10:59:24 +01:00
|
|
|
request->version = heap_strdupW(lpszVersion && *lpszVersion ? lpszVersion : g_szHttp1_1);
|
2008-02-17 20:41:42 +01:00
|
|
|
|
2013-05-06 20:16:28 +02:00
|
|
|
if (hIC->proxy && hIC->proxy[0] && !HTTP_ShouldBypassProxy(hIC, session->hostName))
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_DealWithProxy( hIC, session, request );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&session->hdr, dwContext,
|
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &request->hdr.hInternet,
|
2011-02-02 22:51:13 +01:00
|
|
|
sizeof(HINTERNET));
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2014-04-15 07:07:40 +02:00
|
|
|
TRACE("<-- (%p)\n", request);
|
2004-07-19 23:49:39 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
*ret = request->hdr.hInternet;
|
2011-02-02 22:51:13 +01:00
|
|
|
return ERROR_SUCCESS;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2009-11-30 20:00:28 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* HttpOpenRequestW (WININET.@)
|
|
|
|
*
|
|
|
|
* Open a HTTP request handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a HTTP request handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HINTERNET WINAPI HttpOpenRequestW(HINTERNET hHttpSession,
|
|
|
|
LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
|
|
|
|
LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
|
|
|
|
DWORD dwFlags, DWORD_PTR dwContext)
|
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_session_t *session;
|
2009-11-30 20:00:28 +01:00
|
|
|
HINTERNET handle = NULL;
|
2009-11-30 20:00:44 +01:00
|
|
|
DWORD res;
|
2009-11-30 20:00:28 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %s, %s, %s, %s, %p, %08x, %08lx)\n", hHttpSession,
|
|
|
|
debugstr_w(lpszVerb), debugstr_w(lpszObjectName),
|
|
|
|
debugstr_w(lpszVersion), debugstr_w(lpszReferrer), lpszAcceptTypes,
|
|
|
|
dwFlags, dwContext);
|
|
|
|
if(lpszAcceptTypes!=NULL)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;lpszAcceptTypes[i]!=NULL;i++)
|
|
|
|
TRACE("\taccept type: %s\n",debugstr_w(lpszAcceptTypes[i]));
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
session = (http_session_t*) get_handle_object( hHttpSession );
|
|
|
|
if (NULL == session || session->hdr.htype != WH_HHTTPSESSION)
|
2009-11-30 20:00:28 +01:00
|
|
|
{
|
2009-11-30 20:00:44 +01:00
|
|
|
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
|
|
|
|
goto lend;
|
2009-11-30 20:00:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* My tests seem to show that the windows version does not
|
|
|
|
* become asynchronous until after this point. And anyhow
|
|
|
|
* if this call was asynchronous then how would you get the
|
|
|
|
* necessary HINTERNET pointer returned by this function.
|
|
|
|
*
|
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
res = HTTP_HttpOpenRequestW(session, lpszVerb, lpszObjectName,
|
2009-11-30 20:00:44 +01:00
|
|
|
lpszVersion, lpszReferrer, lpszAcceptTypes,
|
|
|
|
dwFlags, dwContext, &handle);
|
2009-11-30 20:00:28 +01:00
|
|
|
lend:
|
2011-03-01 19:59:39 +01:00
|
|
|
if( session )
|
|
|
|
WININET_Release( &session->hdr );
|
2009-11-30 20:00:28 +01:00
|
|
|
TRACE("returning %p\n", handle);
|
2009-11-30 20:00:44 +01:00
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
SetLastError(res);
|
2009-11-30 20:00:28 +01:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2006-03-30 11:02:54 +02:00
|
|
|
static const LPCWSTR header_lookup[] = {
|
|
|
|
szMime_Version, /* HTTP_QUERY_MIME_VERSION = 0 */
|
|
|
|
szContent_Type, /* HTTP_QUERY_CONTENT_TYPE = 1 */
|
|
|
|
szContent_Transfer_Encoding,/* HTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2 */
|
|
|
|
szContent_ID, /* HTTP_QUERY_CONTENT_ID = 3 */
|
|
|
|
NULL, /* HTTP_QUERY_CONTENT_DESCRIPTION = 4 */
|
|
|
|
szContent_Length, /* HTTP_QUERY_CONTENT_LENGTH = 5 */
|
|
|
|
szContent_Language, /* HTTP_QUERY_CONTENT_LANGUAGE = 6 */
|
|
|
|
szAllow, /* HTTP_QUERY_ALLOW = 7 */
|
|
|
|
szPublic, /* HTTP_QUERY_PUBLIC = 8 */
|
|
|
|
szDate, /* HTTP_QUERY_DATE = 9 */
|
|
|
|
szExpires, /* HTTP_QUERY_EXPIRES = 10 */
|
|
|
|
szLast_Modified, /* HTTP_QUERY_LAST_MODIFIED = 11 */
|
|
|
|
NULL, /* HTTP_QUERY_MESSAGE_ID = 12 */
|
|
|
|
szURI, /* HTTP_QUERY_URI = 13 */
|
|
|
|
szFrom, /* HTTP_QUERY_DERIVED_FROM = 14 */
|
|
|
|
NULL, /* HTTP_QUERY_COST = 15 */
|
|
|
|
NULL, /* HTTP_QUERY_LINK = 16 */
|
|
|
|
szPragma, /* HTTP_QUERY_PRAGMA = 17 */
|
|
|
|
NULL, /* HTTP_QUERY_VERSION = 18 */
|
|
|
|
szStatus, /* HTTP_QUERY_STATUS_CODE = 19 */
|
|
|
|
NULL, /* HTTP_QUERY_STATUS_TEXT = 20 */
|
|
|
|
NULL, /* HTTP_QUERY_RAW_HEADERS = 21 */
|
|
|
|
NULL, /* HTTP_QUERY_RAW_HEADERS_CRLF = 22 */
|
|
|
|
szConnection, /* HTTP_QUERY_CONNECTION = 23 */
|
|
|
|
szAccept, /* HTTP_QUERY_ACCEPT = 24 */
|
|
|
|
szAccept_Charset, /* HTTP_QUERY_ACCEPT_CHARSET = 25 */
|
|
|
|
szAccept_Encoding, /* HTTP_QUERY_ACCEPT_ENCODING = 26 */
|
|
|
|
szAccept_Language, /* HTTP_QUERY_ACCEPT_LANGUAGE = 27 */
|
|
|
|
szAuthorization, /* HTTP_QUERY_AUTHORIZATION = 28 */
|
|
|
|
szContent_Encoding, /* HTTP_QUERY_CONTENT_ENCODING = 29 */
|
|
|
|
NULL, /* HTTP_QUERY_FORWARDED = 30 */
|
|
|
|
NULL, /* HTTP_QUERY_FROM = 31 */
|
|
|
|
szIf_Modified_Since, /* HTTP_QUERY_IF_MODIFIED_SINCE = 32 */
|
|
|
|
szLocation, /* HTTP_QUERY_LOCATION = 33 */
|
|
|
|
NULL, /* HTTP_QUERY_ORIG_URI = 34 */
|
|
|
|
szReferer, /* HTTP_QUERY_REFERER = 35 */
|
|
|
|
szRetry_After, /* HTTP_QUERY_RETRY_AFTER = 36 */
|
|
|
|
szServer, /* HTTP_QUERY_SERVER = 37 */
|
|
|
|
NULL, /* HTTP_TITLE = 38 */
|
|
|
|
szUser_Agent, /* HTTP_QUERY_USER_AGENT = 39 */
|
|
|
|
szWWW_Authenticate, /* HTTP_QUERY_WWW_AUTHENTICATE = 40 */
|
|
|
|
szProxy_Authenticate, /* HTTP_QUERY_PROXY_AUTHENTICATE = 41 */
|
|
|
|
szAccept_Ranges, /* HTTP_QUERY_ACCEPT_RANGES = 42 */
|
|
|
|
szSet_Cookie, /* HTTP_QUERY_SET_COOKIE = 43 */
|
|
|
|
szCookie, /* HTTP_QUERY_COOKIE = 44 */
|
|
|
|
NULL, /* HTTP_QUERY_REQUEST_METHOD = 45 */
|
|
|
|
NULL, /* HTTP_QUERY_REFRESH = 46 */
|
2012-05-23 15:49:24 +02:00
|
|
|
szContent_Disposition, /* HTTP_QUERY_CONTENT_DISPOSITION = 47 */
|
2006-03-30 11:02:54 +02:00
|
|
|
szAge, /* HTTP_QUERY_AGE = 48 */
|
|
|
|
szCache_Control, /* HTTP_QUERY_CACHE_CONTROL = 49 */
|
|
|
|
szContent_Base, /* HTTP_QUERY_CONTENT_BASE = 50 */
|
|
|
|
szContent_Location, /* HTTP_QUERY_CONTENT_LOCATION = 51 */
|
|
|
|
szContent_MD5, /* HTTP_QUERY_CONTENT_MD5 = 52 */
|
|
|
|
szContent_Range, /* HTTP_QUERY_CONTENT_RANGE = 53 */
|
|
|
|
szETag, /* HTTP_QUERY_ETAG = 54 */
|
2009-05-29 23:34:14 +02:00
|
|
|
hostW, /* HTTP_QUERY_HOST = 55 */
|
2006-03-30 11:02:54 +02:00
|
|
|
szIf_Match, /* HTTP_QUERY_IF_MATCH = 56 */
|
|
|
|
szIf_None_Match, /* HTTP_QUERY_IF_NONE_MATCH = 57 */
|
|
|
|
szIf_Range, /* HTTP_QUERY_IF_RANGE = 58 */
|
|
|
|
szIf_Unmodified_Since, /* HTTP_QUERY_IF_UNMODIFIED_SINCE = 59 */
|
|
|
|
szMax_Forwards, /* HTTP_QUERY_MAX_FORWARDS = 60 */
|
|
|
|
szProxy_Authorization, /* HTTP_QUERY_PROXY_AUTHORIZATION = 61 */
|
|
|
|
szRange, /* HTTP_QUERY_RANGE = 62 */
|
|
|
|
szTransfer_Encoding, /* HTTP_QUERY_TRANSFER_ENCODING = 63 */
|
|
|
|
szUpgrade, /* HTTP_QUERY_UPGRADE = 64 */
|
|
|
|
szVary, /* HTTP_QUERY_VARY = 65 */
|
|
|
|
szVia, /* HTTP_QUERY_VIA = 66 */
|
|
|
|
szWarning, /* HTTP_QUERY_WARNING = 67 */
|
|
|
|
szExpect, /* HTTP_QUERY_EXPECT = 68 */
|
|
|
|
szProxy_Connection, /* HTTP_QUERY_PROXY_CONNECTION = 69 */
|
|
|
|
szUnless_Modified_Since, /* HTTP_QUERY_UNLESS_MODIFIED_SINCE = 70 */
|
2005-12-13 17:07:41 +01:00
|
|
|
};
|
|
|
|
|
2006-03-30 11:02:54 +02:00
|
|
|
#define LAST_TABLE_HEADER (sizeof(header_lookup)/sizeof(header_lookup[0]))
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
2004-06-14 19:57:26 +02:00
|
|
|
* HTTP_HttpQueryInfoW (internal)
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static DWORD HTTP_HttpQueryInfoW(http_request_t *request, DWORD dwInfoLevel,
|
2009-12-14 02:27:29 +01:00
|
|
|
LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPHTTPHEADERW lphttpHdr = NULL;
|
2015-05-13 16:55:27 +02:00
|
|
|
BOOL request_only = !!(dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS);
|
2006-03-30 11:01:48 +02:00
|
|
|
INT requested_index = lpdwIndex ? *lpdwIndex : 0;
|
2008-12-08 17:51:08 +01:00
|
|
|
DWORD level = (dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK);
|
2006-03-30 11:01:48 +02:00
|
|
|
INT index = -1;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/* Find requested header structure */
|
2006-03-30 11:01:48 +02:00
|
|
|
switch (level)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2006-03-30 11:01:48 +02:00
|
|
|
case HTTP_QUERY_CUSTOM:
|
2014-09-25 14:21:37 +02:00
|
|
|
if (!lpBuffer)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
2011-03-01 19:59:39 +01:00
|
|
|
index = HTTP_GetCustomHeaderIndex(request, lpBuffer, requested_index, request_only);
|
2006-03-30 11:01:48 +02:00
|
|
|
break;
|
|
|
|
case HTTP_QUERY_RAW_HEADERS_CRLF:
|
2004-07-19 22:09:20 +02:00
|
|
|
{
|
2007-08-16 01:29:58 +02:00
|
|
|
LPWSTR headers;
|
2008-08-28 01:54:17 +02:00
|
|
|
DWORD len = 0;
|
2009-12-14 02:27:29 +01:00
|
|
|
DWORD res = ERROR_INVALID_PARAMETER;
|
2007-08-16 01:29:58 +02:00
|
|
|
|
|
|
|
if (request_only)
|
2013-04-30 16:59:33 +02:00
|
|
|
headers = build_request_header(request, request->verb, request->path, request->version, TRUE);
|
2007-08-16 01:29:58 +02:00
|
|
|
else
|
2013-04-30 16:58:00 +02:00
|
|
|
headers = build_response_header(request, TRUE);
|
2013-04-30 16:59:33 +02:00
|
|
|
if (!headers)
|
2014-09-25 14:21:37 +02:00
|
|
|
{
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2013-04-30 16:59:33 +02:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2014-09-25 14:21:37 +02:00
|
|
|
}
|
2007-08-16 01:29:58 +02:00
|
|
|
|
2013-04-30 16:59:33 +02:00
|
|
|
len = strlenW(headers) * sizeof(WCHAR);
|
2008-07-30 15:49:04 +02:00
|
|
|
if (len + sizeof(WCHAR) > *lpdwBufferLength)
|
2004-07-19 22:09:20 +02:00
|
|
|
{
|
2008-07-30 15:49:04 +02:00
|
|
|
len += sizeof(WCHAR);
|
2009-12-14 02:27:29 +01:00
|
|
|
res = ERROR_INSUFFICIENT_BUFFER;
|
2008-05-18 21:09:50 +02:00
|
|
|
}
|
|
|
|
else if (lpBuffer)
|
2007-08-16 01:29:58 +02:00
|
|
|
{
|
2013-04-30 16:59:33 +02:00
|
|
|
memcpy(lpBuffer, headers, len + sizeof(WCHAR));
|
2008-05-18 21:09:50 +02:00
|
|
|
TRACE("returning data: %s\n", debugstr_wn(lpBuffer, len / sizeof(WCHAR)));
|
2009-12-14 02:27:29 +01:00
|
|
|
res = ERROR_SUCCESS;
|
2007-08-16 01:29:58 +02:00
|
|
|
}
|
2008-05-18 21:09:50 +02:00
|
|
|
*lpdwBufferLength = len;
|
2004-07-21 23:17:03 +02:00
|
|
|
|
2013-04-30 16:58:00 +02:00
|
|
|
heap_free(headers);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return res;
|
2004-07-19 22:09:20 +02:00
|
|
|
}
|
2006-03-30 11:01:48 +02:00
|
|
|
case HTTP_QUERY_RAW_HEADERS:
|
2004-07-19 22:09:20 +02:00
|
|
|
{
|
2013-04-30 16:58:00 +02:00
|
|
|
LPWSTR headers;
|
|
|
|
DWORD len;
|
2004-07-19 22:09:20 +02:00
|
|
|
|
2013-04-30 16:59:33 +02:00
|
|
|
if (request_only)
|
|
|
|
headers = build_request_header(request, request->verb, request->path, request->version, FALSE);
|
|
|
|
else
|
|
|
|
headers = build_response_header(request, FALSE);
|
2014-09-25 14:21:37 +02:00
|
|
|
|
2013-04-30 16:58:00 +02:00
|
|
|
if (!headers)
|
2014-09-25 14:21:37 +02:00
|
|
|
{
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2013-04-30 16:58:00 +02:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2014-09-25 14:21:37 +02:00
|
|
|
}
|
2004-07-19 22:09:20 +02:00
|
|
|
|
2013-04-30 16:58:00 +02:00
|
|
|
len = strlenW(headers) * sizeof(WCHAR);
|
|
|
|
if (len > *lpdwBufferLength)
|
2004-07-19 22:09:20 +02:00
|
|
|
{
|
2013-04-30 16:58:00 +02:00
|
|
|
*lpdwBufferLength = len;
|
|
|
|
heap_free(headers);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2004-07-19 22:09:20 +02:00
|
|
|
}
|
2013-04-30 16:58:00 +02:00
|
|
|
|
|
|
|
if (lpBuffer)
|
2004-07-19 22:09:20 +02:00
|
|
|
{
|
2013-04-30 16:58:00 +02:00
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
TRACE("returning data: %s\n", debugstr_wn(headers, len / sizeof(WCHAR)));
|
|
|
|
|
2014-07-02 01:23:40 +02:00
|
|
|
for (i = 0; i < len / sizeof(WCHAR); i++)
|
2008-10-06 15:48:28 +02:00
|
|
|
{
|
2013-04-30 16:58:00 +02:00
|
|
|
if (headers[i] == '\n')
|
|
|
|
headers[i] = 0;
|
2008-10-06 15:48:28 +02:00
|
|
|
}
|
2014-07-02 01:23:40 +02:00
|
|
|
memcpy(lpBuffer, headers, len);
|
2004-07-19 22:09:20 +02:00
|
|
|
}
|
2013-04-30 16:58:00 +02:00
|
|
|
*lpdwBufferLength = len - sizeof(WCHAR);
|
2004-07-19 22:09:20 +02:00
|
|
|
|
2013-04-30 16:58:00 +02:00
|
|
|
heap_free(headers);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_SUCCESS;
|
2004-07-19 22:09:20 +02:00
|
|
|
}
|
2006-03-30 11:01:48 +02:00
|
|
|
case HTTP_QUERY_STATUS_TEXT:
|
2011-03-01 20:18:22 +01:00
|
|
|
if (request->statusText)
|
2005-12-13 17:07:41 +01:00
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
DWORD len = strlenW(request->statusText);
|
2005-12-13 17:07:41 +01:00
|
|
|
if (len + 1 > *lpdwBufferLength/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
*lpdwBufferLength = (len + 1) * sizeof(WCHAR);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2005-12-13 17:07:41 +01:00
|
|
|
}
|
2008-10-06 15:48:28 +02:00
|
|
|
if (lpBuffer)
|
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
memcpy(lpBuffer, request->statusText, (len + 1) * sizeof(WCHAR));
|
2008-10-06 15:48:28 +02:00
|
|
|
TRACE("returning data: %s\n", debugstr_wn(lpBuffer, len));
|
|
|
|
}
|
2005-12-13 17:07:41 +01:00
|
|
|
*lpdwBufferLength = len * sizeof(WCHAR);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_SUCCESS;
|
2005-12-13 17:07:41 +01:00
|
|
|
}
|
2006-05-30 15:55:42 +02:00
|
|
|
break;
|
2006-03-30 11:01:48 +02:00
|
|
|
case HTTP_QUERY_VERSION:
|
2011-03-01 20:18:22 +01:00
|
|
|
if (request->version)
|
2005-12-13 17:07:41 +01:00
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
DWORD len = strlenW(request->version);
|
2005-12-13 17:07:41 +01:00
|
|
|
if (len + 1 > *lpdwBufferLength/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
*lpdwBufferLength = (len + 1) * sizeof(WCHAR);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2005-12-13 17:07:41 +01:00
|
|
|
}
|
2008-10-06 15:48:28 +02:00
|
|
|
if (lpBuffer)
|
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
memcpy(lpBuffer, request->version, (len + 1) * sizeof(WCHAR));
|
2008-10-06 15:48:28 +02:00
|
|
|
TRACE("returning data: %s\n", debugstr_wn(lpBuffer, len));
|
|
|
|
}
|
2005-12-13 17:07:41 +01:00
|
|
|
*lpdwBufferLength = len * sizeof(WCHAR);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_SUCCESS;
|
2005-12-13 17:07:41 +01:00
|
|
|
}
|
2006-05-30 15:55:42 +02:00
|
|
|
break;
|
2009-05-29 23:35:13 +02:00
|
|
|
case HTTP_QUERY_CONTENT_ENCODING:
|
2011-04-02 15:20:33 +02:00
|
|
|
index = HTTP_GetCustomHeaderIndex(request, header_lookup[request->read_gzip ? HTTP_QUERY_CONTENT_TYPE : level],
|
2009-05-29 23:35:13 +02:00
|
|
|
requested_index,request_only);
|
|
|
|
break;
|
2012-05-03 12:20:25 +02:00
|
|
|
case HTTP_QUERY_STATUS_CODE: {
|
|
|
|
DWORD res = ERROR_SUCCESS;
|
|
|
|
|
2012-05-14 10:41:31 +02:00
|
|
|
if(request_only)
|
2014-09-25 14:21:37 +02:00
|
|
|
{
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2012-05-14 10:41:31 +02:00
|
|
|
return ERROR_HTTP_INVALID_QUERY_REQUEST;
|
2014-09-25 14:21:37 +02:00
|
|
|
}
|
2012-05-14 10:41:31 +02:00
|
|
|
|
|
|
|
if(requested_index)
|
2012-05-03 12:20:25 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
if(dwInfoLevel & HTTP_QUERY_FLAG_NUMBER) {
|
|
|
|
if(*lpdwBufferLength >= sizeof(DWORD))
|
|
|
|
*(DWORD*)lpBuffer = request->status_code;
|
|
|
|
else
|
|
|
|
res = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
*lpdwBufferLength = sizeof(DWORD);
|
|
|
|
}else {
|
|
|
|
WCHAR buf[12];
|
|
|
|
DWORD size;
|
|
|
|
static const WCHAR formatW[] = {'%','u',0};
|
|
|
|
|
2012-06-15 18:15:20 +02:00
|
|
|
size = sprintfW(buf, formatW, request->status_code) * sizeof(WCHAR);
|
2012-05-03 12:20:25 +02:00
|
|
|
|
2012-06-15 18:15:20 +02:00
|
|
|
if(size <= *lpdwBufferLength) {
|
|
|
|
memcpy(lpBuffer, buf, size+sizeof(WCHAR));
|
|
|
|
}else {
|
|
|
|
size += sizeof(WCHAR);
|
2012-05-03 12:20:25 +02:00
|
|
|
res = ERROR_INSUFFICIENT_BUFFER;
|
2012-06-15 18:15:20 +02:00
|
|
|
}
|
2012-05-03 12:20:25 +02:00
|
|
|
|
|
|
|
*lpdwBufferLength = size;
|
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2012-05-03 12:20:25 +02:00
|
|
|
return res;
|
|
|
|
}
|
2006-03-30 11:01:48 +02:00
|
|
|
default:
|
2006-03-30 11:02:54 +02:00
|
|
|
assert (LAST_TABLE_HEADER == (HTTP_QUERY_UNLESS_MODIFIED_SINCE + 1));
|
|
|
|
|
2008-12-08 17:51:08 +01:00
|
|
|
if (level < LAST_TABLE_HEADER && header_lookup[level])
|
2011-03-01 19:59:39 +01:00
|
|
|
index = HTTP_GetCustomHeaderIndex(request, header_lookup[level],
|
2006-03-30 11:02:54 +02:00
|
|
|
requested_index,request_only);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2006-03-30 11:01:48 +02:00
|
|
|
if (index >= 0)
|
2011-03-01 20:18:22 +01:00
|
|
|
lphttpHdr = &request->custHeaders[index];
|
2006-03-30 11:01:48 +02:00
|
|
|
|
2008-01-04 20:37:14 +01:00
|
|
|
/* Ensure header satisfies requested attributes */
|
2006-03-30 11:01:48 +02:00
|
|
|
if (!lphttpHdr ||
|
|
|
|
((dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS) &&
|
|
|
|
(~lphttpHdr->wFlags & HDR_ISREQUEST)))
|
2004-07-15 20:57:32 +02:00
|
|
|
{
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_HTTP_HEADER_NOT_FOUND;
|
2004-07-15 20:57:32 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-01-04 20:37:14 +01:00
|
|
|
/* coalesce value to requested type */
|
2008-10-06 15:48:28 +02:00
|
|
|
if (dwInfoLevel & HTTP_QUERY_FLAG_NUMBER && lpBuffer)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2008-10-06 15:48:28 +02:00
|
|
|
*(int *)lpBuffer = atoiW(lphttpHdr->lpszValue);
|
|
|
|
TRACE(" returning number: %d\n", *(int *)lpBuffer);
|
2009-12-14 02:27:29 +01:00
|
|
|
}
|
2008-10-06 15:48:28 +02:00
|
|
|
else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME && lpBuffer)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
time_t tmpTime;
|
|
|
|
struct tm tmpTM;
|
|
|
|
SYSTEMTIME *STHook;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
tmpTime = ConvertTimeString(lphttpHdr->lpszValue);
|
|
|
|
|
|
|
|
tmpTM = *gmtime(&tmpTime);
|
2008-10-06 15:48:28 +02:00
|
|
|
STHook = (SYSTEMTIME *)lpBuffer;
|
|
|
|
STHook->wDay = tmpTM.tm_mday;
|
|
|
|
STHook->wHour = tmpTM.tm_hour;
|
|
|
|
STHook->wMilliseconds = 0;
|
|
|
|
STHook->wMinute = tmpTM.tm_min;
|
|
|
|
STHook->wDayOfWeek = tmpTM.tm_wday;
|
|
|
|
STHook->wMonth = tmpTM.tm_mon + 1;
|
|
|
|
STHook->wSecond = tmpTM.tm_sec;
|
2013-04-01 15:06:26 +02:00
|
|
|
STHook->wYear = 1900+tmpTM.tm_year;
|
2009-12-14 02:27:29 +01:00
|
|
|
|
2008-10-06 15:48:28 +02:00
|
|
|
TRACE(" returning time: %04d/%02d/%02d - %d - %02d:%02d:%02d.%02d\n",
|
|
|
|
STHook->wYear, STHook->wMonth, STHook->wDay, STHook->wDayOfWeek,
|
|
|
|
STHook->wHour, STHook->wMinute, STHook->wSecond, STHook->wMilliseconds);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2005-12-08 12:44:45 +01:00
|
|
|
else if (lphttpHdr->lpszValue)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD len = (strlenW(lphttpHdr->lpszValue) + 1) * sizeof(WCHAR);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-31 22:09:54 +02:00
|
|
|
if (len > *lpdwBufferLength)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-31 22:09:54 +02:00
|
|
|
*lpdwBufferLength = len;
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2008-10-06 15:48:28 +02:00
|
|
|
if (lpBuffer)
|
|
|
|
{
|
|
|
|
memcpy(lpBuffer, lphttpHdr->lpszValue, len);
|
2009-12-14 02:27:29 +01:00
|
|
|
TRACE("! returning string: %s\n", debugstr_w(lpBuffer));
|
2008-10-06 15:48:28 +02:00
|
|
|
}
|
2004-03-31 22:09:54 +02:00
|
|
|
*lpdwBufferLength = len - sizeof(WCHAR);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2014-06-17 02:57:10 +02:00
|
|
|
if (lpdwIndex) (*lpdwIndex)++;
|
2014-09-25 14:21:37 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-12-14 02:27:29 +01:00
|
|
|
return ERROR_SUCCESS;
|
2004-06-14 19:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpQueryInfoW (WININET.@)
|
|
|
|
*
|
|
|
|
* Queries for information about an HTTP request
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel,
|
2009-12-14 02:27:29 +01:00
|
|
|
LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
|
2004-06-14 19:57:26 +02:00
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_request_t *request;
|
2009-12-14 02:27:29 +01:00
|
|
|
DWORD res;
|
2004-06-14 19:57:26 +02:00
|
|
|
|
|
|
|
if (TRACE_ON(wininet)) {
|
|
|
|
#define FE(x) { x, #x }
|
|
|
|
static const wininet_flag_info query_flags[] = {
|
|
|
|
FE(HTTP_QUERY_MIME_VERSION),
|
|
|
|
FE(HTTP_QUERY_CONTENT_TYPE),
|
|
|
|
FE(HTTP_QUERY_CONTENT_TRANSFER_ENCODING),
|
|
|
|
FE(HTTP_QUERY_CONTENT_ID),
|
|
|
|
FE(HTTP_QUERY_CONTENT_DESCRIPTION),
|
|
|
|
FE(HTTP_QUERY_CONTENT_LENGTH),
|
|
|
|
FE(HTTP_QUERY_CONTENT_LANGUAGE),
|
|
|
|
FE(HTTP_QUERY_ALLOW),
|
|
|
|
FE(HTTP_QUERY_PUBLIC),
|
|
|
|
FE(HTTP_QUERY_DATE),
|
|
|
|
FE(HTTP_QUERY_EXPIRES),
|
|
|
|
FE(HTTP_QUERY_LAST_MODIFIED),
|
|
|
|
FE(HTTP_QUERY_MESSAGE_ID),
|
|
|
|
FE(HTTP_QUERY_URI),
|
|
|
|
FE(HTTP_QUERY_DERIVED_FROM),
|
|
|
|
FE(HTTP_QUERY_COST),
|
|
|
|
FE(HTTP_QUERY_LINK),
|
|
|
|
FE(HTTP_QUERY_PRAGMA),
|
|
|
|
FE(HTTP_QUERY_VERSION),
|
|
|
|
FE(HTTP_QUERY_STATUS_CODE),
|
|
|
|
FE(HTTP_QUERY_STATUS_TEXT),
|
|
|
|
FE(HTTP_QUERY_RAW_HEADERS),
|
|
|
|
FE(HTTP_QUERY_RAW_HEADERS_CRLF),
|
|
|
|
FE(HTTP_QUERY_CONNECTION),
|
|
|
|
FE(HTTP_QUERY_ACCEPT),
|
|
|
|
FE(HTTP_QUERY_ACCEPT_CHARSET),
|
|
|
|
FE(HTTP_QUERY_ACCEPT_ENCODING),
|
|
|
|
FE(HTTP_QUERY_ACCEPT_LANGUAGE),
|
|
|
|
FE(HTTP_QUERY_AUTHORIZATION),
|
|
|
|
FE(HTTP_QUERY_CONTENT_ENCODING),
|
|
|
|
FE(HTTP_QUERY_FORWARDED),
|
|
|
|
FE(HTTP_QUERY_FROM),
|
|
|
|
FE(HTTP_QUERY_IF_MODIFIED_SINCE),
|
|
|
|
FE(HTTP_QUERY_LOCATION),
|
|
|
|
FE(HTTP_QUERY_ORIG_URI),
|
|
|
|
FE(HTTP_QUERY_REFERER),
|
|
|
|
FE(HTTP_QUERY_RETRY_AFTER),
|
|
|
|
FE(HTTP_QUERY_SERVER),
|
|
|
|
FE(HTTP_QUERY_TITLE),
|
|
|
|
FE(HTTP_QUERY_USER_AGENT),
|
|
|
|
FE(HTTP_QUERY_WWW_AUTHENTICATE),
|
|
|
|
FE(HTTP_QUERY_PROXY_AUTHENTICATE),
|
|
|
|
FE(HTTP_QUERY_ACCEPT_RANGES),
|
2005-12-13 17:07:41 +01:00
|
|
|
FE(HTTP_QUERY_SET_COOKIE),
|
|
|
|
FE(HTTP_QUERY_COOKIE),
|
2004-06-14 19:57:26 +02:00
|
|
|
FE(HTTP_QUERY_REQUEST_METHOD),
|
|
|
|
FE(HTTP_QUERY_REFRESH),
|
|
|
|
FE(HTTP_QUERY_CONTENT_DISPOSITION),
|
|
|
|
FE(HTTP_QUERY_AGE),
|
|
|
|
FE(HTTP_QUERY_CACHE_CONTROL),
|
|
|
|
FE(HTTP_QUERY_CONTENT_BASE),
|
|
|
|
FE(HTTP_QUERY_CONTENT_LOCATION),
|
|
|
|
FE(HTTP_QUERY_CONTENT_MD5),
|
|
|
|
FE(HTTP_QUERY_CONTENT_RANGE),
|
|
|
|
FE(HTTP_QUERY_ETAG),
|
|
|
|
FE(HTTP_QUERY_HOST),
|
|
|
|
FE(HTTP_QUERY_IF_MATCH),
|
|
|
|
FE(HTTP_QUERY_IF_NONE_MATCH),
|
|
|
|
FE(HTTP_QUERY_IF_RANGE),
|
|
|
|
FE(HTTP_QUERY_IF_UNMODIFIED_SINCE),
|
|
|
|
FE(HTTP_QUERY_MAX_FORWARDS),
|
|
|
|
FE(HTTP_QUERY_PROXY_AUTHORIZATION),
|
|
|
|
FE(HTTP_QUERY_RANGE),
|
|
|
|
FE(HTTP_QUERY_TRANSFER_ENCODING),
|
|
|
|
FE(HTTP_QUERY_UPGRADE),
|
|
|
|
FE(HTTP_QUERY_VARY),
|
|
|
|
FE(HTTP_QUERY_VIA),
|
|
|
|
FE(HTTP_QUERY_WARNING),
|
|
|
|
FE(HTTP_QUERY_CUSTOM)
|
|
|
|
};
|
|
|
|
static const wininet_flag_info modifier_flags[] = {
|
|
|
|
FE(HTTP_QUERY_FLAG_REQUEST_HEADERS),
|
|
|
|
FE(HTTP_QUERY_FLAG_SYSTEMTIME),
|
|
|
|
FE(HTTP_QUERY_FLAG_NUMBER),
|
|
|
|
FE(HTTP_QUERY_FLAG_COALESCE)
|
|
|
|
};
|
|
|
|
#undef FE
|
|
|
|
DWORD info_mod = dwInfoLevel & HTTP_QUERY_MODIFIER_FLAGS_MASK;
|
|
|
|
DWORD info = dwInfoLevel & HTTP_QUERY_HEADER_MASK;
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD i;
|
2004-06-14 19:57:26 +02:00
|
|
|
|
2009-12-04 23:39:37 +01:00
|
|
|
TRACE("(%p, 0x%08x)--> %d\n", hHttpRequest, dwInfoLevel, info);
|
2004-06-14 19:57:26 +02:00
|
|
|
TRACE(" Attribute:");
|
|
|
|
for (i = 0; i < (sizeof(query_flags) / sizeof(query_flags[0])); i++) {
|
|
|
|
if (query_flags[i].val == info) {
|
2005-01-07 18:09:39 +01:00
|
|
|
TRACE(" %s", query_flags[i].name);
|
2004-06-14 19:57:26 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == (sizeof(query_flags) / sizeof(query_flags[0]))) {
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE(" Unknown (%08x)", info);
|
2004-06-14 19:57:26 +02:00
|
|
|
}
|
|
|
|
|
2005-01-07 18:09:39 +01:00
|
|
|
TRACE(" Modifier:");
|
2004-06-14 19:57:26 +02:00
|
|
|
for (i = 0; i < (sizeof(modifier_flags) / sizeof(modifier_flags[0])); i++) {
|
|
|
|
if (modifier_flags[i].val & info_mod) {
|
2005-01-07 18:09:39 +01:00
|
|
|
TRACE(" %s", modifier_flags[i].name);
|
2004-06-14 19:57:26 +02:00
|
|
|
info_mod &= ~ modifier_flags[i].val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info_mod) {
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE(" Unknown (%08x)", info_mod);
|
2004-06-14 19:57:26 +02:00
|
|
|
}
|
2005-01-07 18:09:39 +01:00
|
|
|
TRACE("\n");
|
2004-06-14 19:57:26 +02:00
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
request = (http_request_t*) get_handle_object( hHttpRequest );
|
|
|
|
if (NULL == request || request->hdr.htype != WH_HHTTPREQ)
|
2004-06-14 19:57:26 +02:00
|
|
|
{
|
2009-12-14 02:27:29 +01:00
|
|
|
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
|
|
|
|
goto lend;
|
2004-06-14 19:57:26 +02:00
|
|
|
}
|
|
|
|
|
2007-08-16 01:55:15 +02:00
|
|
|
if (lpBuffer == NULL)
|
|
|
|
*lpdwBufferLength = 0;
|
2011-03-01 19:59:39 +01:00
|
|
|
res = HTTP_HttpQueryInfoW( request, dwInfoLevel,
|
2009-12-14 02:27:29 +01:00
|
|
|
lpBuffer, lpdwBufferLength, lpdwIndex);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
lend:
|
2011-03-01 19:59:39 +01:00
|
|
|
if( request )
|
|
|
|
WININET_Release( &request->hdr );
|
2004-07-19 23:49:39 +02:00
|
|
|
|
2009-12-14 02:27:29 +01:00
|
|
|
TRACE("%u <--\n", res);
|
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
SetLastError(res);
|
|
|
|
return res == ERROR_SUCCESS;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2002-11-12 03:13:04 +01:00
|
|
|
/***********************************************************************
|
2004-03-30 06:36:09 +02:00
|
|
|
* HttpQueryInfoA (WININET.@)
|
2002-11-12 03:13:04 +01:00
|
|
|
*
|
|
|
|
* Queries for information about an HTTP request
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL WINAPI HttpQueryInfoA(HINTERNET hHttpRequest, DWORD dwInfoLevel,
|
2002-11-12 03:13:04 +01:00
|
|
|
LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
|
|
|
|
{
|
|
|
|
BOOL result;
|
2004-03-30 22:37:49 +02:00
|
|
|
DWORD len;
|
|
|
|
WCHAR* bufferW;
|
|
|
|
|
2013-07-19 12:02:18 +02:00
|
|
|
TRACE("%p %x\n", hHttpRequest, dwInfoLevel);
|
|
|
|
|
2002-11-12 03:13:04 +01:00
|
|
|
if((dwInfoLevel & HTTP_QUERY_FLAG_NUMBER) ||
|
|
|
|
(dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME))
|
|
|
|
{
|
2004-03-30 22:37:49 +02:00
|
|
|
return HttpQueryInfoW( hHttpRequest, dwInfoLevel, lpBuffer,
|
|
|
|
lpdwBufferLength, lpdwIndex );
|
2002-11-12 03:13:04 +01:00
|
|
|
}
|
2004-03-30 22:37:49 +02:00
|
|
|
|
2007-08-16 01:55:15 +02:00
|
|
|
if (lpBuffer)
|
|
|
|
{
|
2008-02-18 20:37:35 +01:00
|
|
|
DWORD alloclen;
|
2007-08-16 01:55:15 +02:00
|
|
|
len = (*lpdwBufferLength)*sizeof(WCHAR);
|
2008-02-18 20:37:35 +01:00
|
|
|
if ((dwInfoLevel & HTTP_QUERY_HEADER_MASK) == HTTP_QUERY_CUSTOM)
|
|
|
|
{
|
|
|
|
alloclen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 ) * sizeof(WCHAR);
|
|
|
|
if (alloclen < len)
|
|
|
|
alloclen = len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
alloclen = len;
|
2011-04-21 13:39:03 +02:00
|
|
|
bufferW = heap_alloc(alloclen);
|
2007-08-16 01:55:15 +02:00
|
|
|
/* buffer is in/out because of HTTP_QUERY_CUSTOM */
|
|
|
|
if ((dwInfoLevel & HTTP_QUERY_HEADER_MASK) == HTTP_QUERY_CUSTOM)
|
2008-02-18 20:37:35 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, bufferW, alloclen / sizeof(WCHAR) );
|
2007-08-16 01:55:15 +02:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
bufferW = NULL;
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
2004-03-30 22:37:49 +02:00
|
|
|
result = HttpQueryInfoW( hHttpRequest, dwInfoLevel, bufferW,
|
|
|
|
&len, lpdwIndex );
|
|
|
|
if( result )
|
2002-11-12 03:13:04 +01:00
|
|
|
{
|
2004-07-21 23:17:03 +02:00
|
|
|
len = WideCharToMultiByte( CP_ACP,0, bufferW, len / sizeof(WCHAR) + 1,
|
2004-03-30 22:37:49 +02:00
|
|
|
lpBuffer, *lpdwBufferLength, NULL, NULL );
|
2004-07-21 23:17:03 +02:00
|
|
|
*lpdwBufferLength = len - 1;
|
|
|
|
|
|
|
|
TRACE("lpBuffer: %s\n", debugstr_a(lpBuffer));
|
2002-11-12 03:13:04 +01:00
|
|
|
}
|
2004-07-20 03:21:08 +02:00
|
|
|
else
|
|
|
|
/* since the strings being returned from HttpQueryInfoW should be
|
|
|
|
* only ASCII characters, it is reasonable to assume that all of
|
|
|
|
* the Unicode characters can be reduced to a single byte */
|
|
|
|
*lpdwBufferLength = len / sizeof(WCHAR);
|
2004-07-21 23:17:03 +02:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free( bufferW );
|
2002-11-12 03:13:04 +01:00
|
|
|
return result;
|
|
|
|
}
|
2000-10-28 02:30:23 +02:00
|
|
|
|
2016-05-18 18:03:09 +02:00
|
|
|
static WCHAR *get_redirect_url(http_request_t *request)
|
2000-10-28 02:30:23 +02:00
|
|
|
{
|
2009-11-30 20:01:17 +01:00
|
|
|
static WCHAR szHttp[] = {'h','t','t','p',0};
|
|
|
|
static WCHAR szHttps[] = {'h','t','t','p','s',0};
|
2011-03-01 20:18:22 +01:00
|
|
|
http_session_t *session = request->session;
|
2016-05-18 18:03:09 +02:00
|
|
|
URL_COMPONENTSW urlComponents = { sizeof(urlComponents) };
|
|
|
|
WCHAR *orig_url = NULL, *redirect_url = NULL, *combined_url = NULL;
|
|
|
|
DWORD url_length = 0, res;
|
|
|
|
BOOL b;
|
|
|
|
|
|
|
|
url_length = 0;
|
|
|
|
res = HTTP_HttpQueryInfoW(request, HTTP_QUERY_LOCATION, redirect_url, &url_length, NULL);
|
|
|
|
if(res == ERROR_INSUFFICIENT_BUFFER) {
|
|
|
|
redirect_url = heap_alloc(url_length);
|
|
|
|
res = HTTP_HttpQueryInfoW(request, HTTP_QUERY_LOCATION, redirect_url, &url_length, NULL);
|
|
|
|
}
|
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
heap_free(redirect_url);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2017-05-31 16:03:57 +02:00
|
|
|
urlComponents.dwSchemeLength = 1;
|
2017-08-07 14:20:19 +02:00
|
|
|
b = InternetCrackUrlW(redirect_url, url_length / sizeof(WCHAR), 0, &urlComponents);
|
2017-05-31 16:03:57 +02:00
|
|
|
if(b && urlComponents.dwSchemeLength &&
|
|
|
|
urlComponents.nScheme != INTERNET_SCHEME_HTTP && urlComponents.nScheme != INTERNET_SCHEME_HTTPS) {
|
|
|
|
TRACE("redirect to non-http URL\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
urlComponents.lpszScheme = (request->hdr.dwFlags & INTERNET_FLAG_SECURE) ? szHttps : szHttp;
|
2017-05-31 16:03:57 +02:00
|
|
|
urlComponents.dwSchemeLength = 0;
|
2014-06-19 15:14:45 +02:00
|
|
|
urlComponents.lpszHostName = request->server->name;
|
|
|
|
urlComponents.nPort = request->server->port;
|
2011-03-01 20:02:14 +01:00
|
|
|
urlComponents.lpszUserName = session->userName;
|
2011-03-01 20:18:22 +01:00
|
|
|
urlComponents.lpszUrlPath = request->path;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2016-05-18 18:03:09 +02:00
|
|
|
b = InternetCreateUrlW(&urlComponents, 0, NULL, &url_length);
|
|
|
|
if(!b && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
|
|
|
orig_url = heap_alloc(url_length);
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2016-05-18 18:03:09 +02:00
|
|
|
/* convert from bytes to characters */
|
|
|
|
url_length = url_length / sizeof(WCHAR) - 1;
|
|
|
|
b = InternetCreateUrlW(&urlComponents, 0, orig_url, &url_length);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2016-05-18 18:03:09 +02:00
|
|
|
if(b) {
|
|
|
|
url_length = 0;
|
|
|
|
b = InternetCombineUrlW(orig_url, redirect_url, NULL, &url_length, ICU_ENCODE_SPACES_ONLY);
|
|
|
|
if(!b && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
|
|
|
combined_url = heap_alloc(url_length * sizeof(WCHAR));
|
|
|
|
b = InternetCombineUrlW(orig_url, redirect_url, combined_url, &url_length, ICU_ENCODE_SPACES_ONLY);
|
|
|
|
if(!b) {
|
|
|
|
heap_free(combined_url);
|
|
|
|
combined_url = NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(orig_url);
|
2016-05-18 18:03:09 +02:00
|
|
|
heap_free(redirect_url);
|
2009-11-30 20:01:17 +01:00
|
|
|
return combined_url;
|
|
|
|
}
|
2005-11-21 16:17:55 +01:00
|
|
|
|
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_HandleRedirect (internal)
|
|
|
|
*/
|
2017-06-26 15:36:35 +02:00
|
|
|
static DWORD HTTP_HandleRedirect(http_request_t *request, WCHAR *url)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2017-06-26 15:36:35 +02:00
|
|
|
URL_COMPONENTSW urlComponents = { sizeof(urlComponents) };
|
2011-03-01 20:18:22 +01:00
|
|
|
http_session_t *session = request->session;
|
2017-06-26 15:36:35 +02:00
|
|
|
size_t url_len = strlenW(url);
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2017-06-26 15:36:35 +02:00
|
|
|
if(url[0] == '/')
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2009-11-30 20:01:17 +01:00
|
|
|
/* if it's an absolute path, keep the same session info */
|
2017-06-26 15:36:35 +02:00
|
|
|
urlComponents.lpszUrlPath = url;
|
|
|
|
urlComponents.dwUrlPathLength = url_len;
|
2005-11-21 16:17:55 +01:00
|
|
|
}
|
2009-11-30 20:01:17 +01:00
|
|
|
else
|
|
|
|
{
|
2016-05-18 18:02:46 +02:00
|
|
|
urlComponents.dwHostNameLength = 1;
|
|
|
|
urlComponents.dwUserNameLength = 1;
|
|
|
|
urlComponents.dwUrlPathLength = 1;
|
2017-06-26 15:36:35 +02:00
|
|
|
if(!InternetCrackUrlW(url, url_len, 0, &urlComponents))
|
2009-12-03 14:49:56 +01:00
|
|
|
return INTERNET_GetLastError();
|
2017-06-26 15:36:50 +02:00
|
|
|
|
|
|
|
if(!urlComponents.dwHostNameLength)
|
|
|
|
return ERROR_INTERNET_INVALID_URL;
|
2017-06-26 15:36:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext, INTERNET_STATUS_REDIRECT,
|
|
|
|
url, (url_len + 1) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if(urlComponents.dwHostNameLength) {
|
|
|
|
BOOL custom_port = FALSE;
|
|
|
|
substr_t host;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2016-05-18 18:02:02 +02:00
|
|
|
if(urlComponents.nScheme == INTERNET_SCHEME_HTTP) {
|
2012-01-24 17:31:17 +01:00
|
|
|
if(request->hdr.dwFlags & INTERNET_FLAG_SECURE) {
|
|
|
|
TRACE("redirect from secure page to non-secure page\n");
|
|
|
|
/* FIXME: warn about from secure redirect to non-secure page */
|
|
|
|
request->hdr.dwFlags &= ~INTERNET_FLAG_SECURE;
|
|
|
|
}
|
2009-10-27 10:03:36 +01:00
|
|
|
|
2016-05-17 19:20:21 +02:00
|
|
|
custom_port = urlComponents.nPort != INTERNET_DEFAULT_HTTP_PORT;
|
2016-05-18 18:02:02 +02:00
|
|
|
}else if(urlComponents.nScheme == INTERNET_SCHEME_HTTPS) {
|
2012-01-24 17:31:17 +01:00
|
|
|
if(!(request->hdr.dwFlags & INTERNET_FLAG_SECURE)) {
|
|
|
|
TRACE("redirect from non-secure page to secure page\n");
|
|
|
|
/* FIXME: notify about redirect to secure page */
|
|
|
|
request->hdr.dwFlags |= INTERNET_FLAG_SECURE;
|
|
|
|
}
|
2009-10-27 10:03:36 +01:00
|
|
|
|
2016-05-17 19:20:21 +02:00
|
|
|
custom_port = urlComponents.nPort != INTERNET_DEFAULT_HTTPS_PORT;
|
2012-01-24 17:31:17 +01:00
|
|
|
}
|
2009-10-27 10:03:36 +01:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(session->hostName);
|
2012-01-24 17:31:17 +01:00
|
|
|
|
2016-05-18 18:02:46 +02:00
|
|
|
session->hostName = heap_strndupW(urlComponents.lpszHostName, urlComponents.dwHostNameLength);
|
2014-06-19 15:14:40 +02:00
|
|
|
session->hostPort = urlComponents.nPort;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(session->userName);
|
2011-03-01 20:02:14 +01:00
|
|
|
session->userName = NULL;
|
2016-05-18 18:02:46 +02:00
|
|
|
if (urlComponents.dwUserNameLength)
|
|
|
|
session->userName = heap_strndupW(urlComponents.lpszUserName, urlComponents.dwUserNameLength);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
reset_data_stream(request);
|
2006-01-13 13:52:38 +01:00
|
|
|
|
2016-05-18 18:02:46 +02:00
|
|
|
host = substr(urlComponents.lpszHostName, urlComponents.dwHostNameLength);
|
|
|
|
|
|
|
|
if(host.len != strlenW(request->server->name) || strncmpiW(request->server->name, host.str, host.len)
|
|
|
|
|| request->server->port != urlComponents.nPort) {
|
2012-05-25 16:34:24 +02:00
|
|
|
server_t *new_server;
|
|
|
|
|
2016-05-18 18:02:46 +02:00
|
|
|
new_server = get_server(host, urlComponents.nPort, urlComponents.nScheme == INTERNET_SCHEME_HTTPS, TRUE);
|
2012-05-25 16:34:24 +02:00
|
|
|
server_release(request->server);
|
|
|
|
request->server = new_server;
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
2014-10-24 16:43:00 +02:00
|
|
|
|
|
|
|
if (custom_port)
|
|
|
|
HTTP_ProcessHeader(request, hostW, request->server->host_port, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
|
|
|
|
else
|
|
|
|
HTTP_ProcessHeader(request, hostW, request->server->name, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
|
2005-11-30 12:31:22 +01:00
|
|
|
}
|
2017-06-26 15:36:35 +02:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(request->path);
|
2016-05-18 18:02:46 +02:00
|
|
|
request->path = NULL;
|
2017-06-26 15:36:35 +02:00
|
|
|
if(urlComponents.dwUrlPathLength)
|
2005-11-30 12:31:22 +01:00
|
|
|
{
|
2016-12-14 16:47:50 +01:00
|
|
|
DWORD needed = 1;
|
2009-11-30 20:01:17 +01:00
|
|
|
HRESULT rc;
|
2016-12-14 16:47:50 +01:00
|
|
|
WCHAR dummy = 0;
|
2017-06-26 15:36:35 +02:00
|
|
|
WCHAR *path;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2017-06-26 15:36:35 +02:00
|
|
|
path = heap_strndupW(urlComponents.lpszUrlPath, urlComponents.dwUrlPathLength);
|
2016-12-14 16:47:50 +01:00
|
|
|
rc = UrlEscapeW(path, &dummy, &needed, URL_ESCAPE_SPACES_ONLY);
|
|
|
|
if (rc != E_POINTER)
|
|
|
|
ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(path),rc);
|
2011-04-21 13:39:03 +02:00
|
|
|
request->path = heap_alloc(needed*sizeof(WCHAR));
|
2011-03-01 20:18:22 +01:00
|
|
|
rc = UrlEscapeW(path, request->path, &needed,
|
2009-11-30 20:01:17 +01:00
|
|
|
URL_ESCAPE_SPACES_ONLY);
|
|
|
|
if (rc != S_OK)
|
|
|
|
{
|
|
|
|
ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(path),rc);
|
2016-05-18 18:02:46 +02:00
|
|
|
strcpyW(request->path, path);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
2017-07-09 16:00:39 +02:00
|
|
|
heap_free(path);
|
2005-11-30 12:31:22 +01:00
|
|
|
}
|
2007-11-04 02:24:49 +01:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
/* Remove custom content-type/length headers on redirects. */
|
2014-12-19 16:49:48 +01:00
|
|
|
remove_header(request, szContent_Type, TRUE);
|
|
|
|
remove_header(request, szContent_Length, TRUE);
|
2007-11-04 02:24:49 +01:00
|
|
|
|
2009-12-03 14:49:56 +01:00
|
|
|
return ERROR_SUCCESS;
|
2000-10-28 02:30:23 +02:00
|
|
|
}
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
2009-11-30 20:01:17 +01:00
|
|
|
* HTTP_build_req (internal)
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
2009-11-30 20:01:17 +01:00
|
|
|
* concatenate all the strings in the request together
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2009-11-30 20:01:17 +01:00
|
|
|
static LPWSTR HTTP_build_req( LPCWSTR *list, int len )
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2009-11-30 20:01:17 +01:00
|
|
|
LPCWSTR *t;
|
|
|
|
LPWSTR str;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
for( t = list; *t ; t++ )
|
|
|
|
len += strlenW( *t );
|
|
|
|
len++;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-04-21 13:39:03 +02:00
|
|
|
str = heap_alloc(len*sizeof(WCHAR));
|
2009-11-30 20:01:17 +01:00
|
|
|
*str = 0;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
for( t = list; *t ; t++ )
|
|
|
|
strcatW( str, *t );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
return str;
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
static void HTTP_InsertCookies(http_request_t *request)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2011-05-19 16:11:30 +02:00
|
|
|
WCHAR *cookies;
|
2014-07-15 17:13:03 +02:00
|
|
|
DWORD res;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2014-07-15 17:13:03 +02:00
|
|
|
res = get_cookie_header(request->server->name, request->path, &cookies);
|
|
|
|
if(res != ERROR_SUCCESS || !cookies)
|
2011-05-19 16:11:30 +02:00
|
|
|
return;
|
|
|
|
|
2015-06-25 12:28:02 +02:00
|
|
|
HTTP_HttpAddRequestHeadersW(request, cookies, strlenW(cookies),
|
|
|
|
HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
|
2011-05-19 16:11:30 +02:00
|
|
|
heap_free(cookies);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2011-10-22 07:55:14 +02:00
|
|
|
static WORD HTTP_ParseWkday(LPCWSTR day)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-11 18:22:23 +01:00
|
|
|
static const WCHAR days[7][4] = {{ 's','u','n',0 },
|
|
|
|
{ 'm','o','n',0 },
|
|
|
|
{ 't','u','e',0 },
|
|
|
|
{ 'w','e','d',0 },
|
|
|
|
{ 't','h','u',0 },
|
|
|
|
{ 'f','r','i',0 },
|
|
|
|
{ 's','a','t',0 }};
|
2013-03-12 23:28:49 +01:00
|
|
|
unsigned int i;
|
2011-03-11 18:22:23 +01:00
|
|
|
for (i = 0; i < sizeof(days)/sizeof(*days); i++)
|
|
|
|
if (!strcmpiW(day, days[i]))
|
|
|
|
return i;
|
|
|
|
|
2011-03-03 20:20:11 +01:00
|
|
|
/* Invalid */
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WORD HTTP_ParseMonth(LPCWSTR month)
|
|
|
|
{
|
|
|
|
static const WCHAR jan[] = { 'j','a','n',0 };
|
|
|
|
static const WCHAR feb[] = { 'f','e','b',0 };
|
|
|
|
static const WCHAR mar[] = { 'm','a','r',0 };
|
|
|
|
static const WCHAR apr[] = { 'a','p','r',0 };
|
|
|
|
static const WCHAR may[] = { 'm','a','y',0 };
|
|
|
|
static const WCHAR jun[] = { 'j','u','n',0 };
|
|
|
|
static const WCHAR jul[] = { 'j','u','l',0 };
|
|
|
|
static const WCHAR aug[] = { 'a','u','g',0 };
|
|
|
|
static const WCHAR sep[] = { 's','e','p',0 };
|
|
|
|
static const WCHAR oct[] = { 'o','c','t',0 };
|
|
|
|
static const WCHAR nov[] = { 'n','o','v',0 };
|
|
|
|
static const WCHAR dec[] = { 'd','e','c',0 };
|
|
|
|
|
|
|
|
if (!strcmpiW(month, jan)) return 1;
|
|
|
|
if (!strcmpiW(month, feb)) return 2;
|
|
|
|
if (!strcmpiW(month, mar)) return 3;
|
|
|
|
if (!strcmpiW(month, apr)) return 4;
|
|
|
|
if (!strcmpiW(month, may)) return 5;
|
|
|
|
if (!strcmpiW(month, jun)) return 6;
|
|
|
|
if (!strcmpiW(month, jul)) return 7;
|
|
|
|
if (!strcmpiW(month, aug)) return 8;
|
|
|
|
if (!strcmpiW(month, sep)) return 9;
|
|
|
|
if (!strcmpiW(month, oct)) return 10;
|
|
|
|
if (!strcmpiW(month, nov)) return 11;
|
|
|
|
if (!strcmpiW(month, dec)) return 12;
|
|
|
|
/* Invalid */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-04 20:43:54 +01:00
|
|
|
/* Parses the string pointed to by *str, assumed to be a 24-hour time HH:MM:SS,
|
|
|
|
* optionally preceded by whitespace.
|
|
|
|
* Upon success, returns TRUE, sets the wHour, wMinute, and wSecond fields of
|
|
|
|
* st, and sets *str to the first character after the time format.
|
2011-03-03 20:20:11 +01:00
|
|
|
*/
|
2011-03-04 20:43:54 +01:00
|
|
|
static BOOL HTTP_ParseTime(SYSTEMTIME *st, LPCWSTR *str)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
LPCWSTR ptr = *str;
|
|
|
|
WCHAR *nextPtr;
|
2011-03-03 20:20:11 +01:00
|
|
|
unsigned long num;
|
|
|
|
|
2011-03-04 20:43:54 +01:00
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
|
|
|
if (!nextPtr || nextPtr <= ptr || *nextPtr != ':')
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
ERR("unexpected time format %s\n", debugstr_w(ptr));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
if (num > 23)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
ERR("unexpected hour in time format %s\n", debugstr_w(ptr));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
ptr = nextPtr + 1;
|
|
|
|
st->wHour = (WORD)num;
|
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
|
|
|
if (!nextPtr || nextPtr <= ptr || *nextPtr != ':')
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
ERR("unexpected time format %s\n", debugstr_w(ptr));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
if (num > 59)
|
|
|
|
{
|
|
|
|
ERR("unexpected minute in time format %s\n", debugstr_w(ptr));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr = nextPtr + 1;
|
|
|
|
st->wMinute = (WORD)num;
|
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
|
|
|
if (!nextPtr || nextPtr <= ptr)
|
|
|
|
{
|
|
|
|
ERR("unexpected time format %s\n", debugstr_w(ptr));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (num > 59)
|
|
|
|
{
|
|
|
|
ERR("unexpected second in time format %s\n", debugstr_w(ptr));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr = nextPtr + 1;
|
|
|
|
*str = ptr;
|
|
|
|
st->wSecond = (WORD)num;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-03-03 20:20:11 +01:00
|
|
|
|
2011-03-04 20:43:54 +01:00
|
|
|
static BOOL HTTP_ParseDateAsAsctime(LPCWSTR value, FILETIME *ft)
|
|
|
|
{
|
|
|
|
static const WCHAR gmt[]= { 'G','M','T',0 };
|
|
|
|
WCHAR day[4], *dayPtr, month[4], *monthPtr, *nextPtr;
|
|
|
|
LPCWSTR ptr;
|
|
|
|
SYSTEMTIME st = { 0 };
|
|
|
|
unsigned long num;
|
2011-03-03 20:20:11 +01:00
|
|
|
|
2011-03-04 20:43:54 +01:00
|
|
|
for (ptr = value, dayPtr = day; *ptr && !isspaceW(*ptr) &&
|
|
|
|
dayPtr - day < sizeof(day) / sizeof(day[0]) - 1; ptr++, dayPtr++)
|
|
|
|
*dayPtr = *ptr;
|
|
|
|
*dayPtr = 0;
|
2011-10-22 07:55:14 +02:00
|
|
|
st.wDayOfWeek = HTTP_ParseWkday(day);
|
2011-03-04 20:43:54 +01:00
|
|
|
if (st.wDayOfWeek >= 7)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
ERR("unexpected weekday %s\n", debugstr_w(day));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
2017-05-17 14:35:47 +02:00
|
|
|
for (monthPtr = month; !isspaceW(*ptr) &&
|
2011-03-03 20:20:11 +01:00
|
|
|
monthPtr - month < sizeof(month) / sizeof(month[0]) - 1;
|
|
|
|
monthPtr++, ptr++)
|
|
|
|
*monthPtr = *ptr;
|
|
|
|
*monthPtr = 0;
|
|
|
|
st.wMonth = HTTP_ParseMonth(month);
|
|
|
|
if (!st.wMonth || st.wMonth > 12)
|
|
|
|
{
|
|
|
|
ERR("unexpected month %s\n", debugstr_w(month));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
2011-03-04 20:43:54 +01:00
|
|
|
if (!nextPtr || nextPtr <= ptr || !num || num > 31)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
ERR("unexpected day %s\n", debugstr_w(ptr));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr = nextPtr;
|
2011-03-04 20:43:54 +01:00
|
|
|
st.wDay = (WORD)num;
|
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (!HTTP_ParseTime(&st, &ptr))
|
|
|
|
return FALSE;
|
2011-03-03 20:20:11 +01:00
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
2011-03-04 20:43:54 +01:00
|
|
|
if (!nextPtr || nextPtr <= ptr || num < 1601 || num > 30827)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
ERR("unexpected year %s\n", debugstr_w(ptr));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
ptr = nextPtr;
|
|
|
|
st.wYear = (WORD)num;
|
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
/* asctime() doesn't report a timezone, but some web servers do, so accept
|
|
|
|
* with or without GMT.
|
|
|
|
*/
|
|
|
|
if (*ptr && strcmpW(ptr, gmt))
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
ERR("unexpected timezone %s\n", debugstr_w(ptr));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
return SystemTimeToFileTime(&st, ft);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL HTTP_ParseRfc1123Date(LPCWSTR value, FILETIME *ft)
|
|
|
|
{
|
|
|
|
static const WCHAR gmt[]= { 'G','M','T',0 };
|
|
|
|
WCHAR *nextPtr, day[4], month[4], *monthPtr;
|
|
|
|
LPCWSTR ptr;
|
|
|
|
unsigned long num;
|
2011-03-07 22:13:11 +01:00
|
|
|
SYSTEMTIME st = { 0 };
|
2011-03-04 20:43:54 +01:00
|
|
|
|
|
|
|
ptr = strchrW(value, ',');
|
|
|
|
if (!ptr)
|
|
|
|
return FALSE;
|
|
|
|
if (ptr - value != 3)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-10-22 07:55:14 +02:00
|
|
|
WARN("unexpected weekday %s\n", debugstr_wn(value, ptr - value));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
memcpy(day, value, (ptr - value) * sizeof(WCHAR));
|
|
|
|
day[3] = 0;
|
2011-10-22 07:55:14 +02:00
|
|
|
st.wDayOfWeek = HTTP_ParseWkday(day);
|
2011-03-04 20:43:54 +01:00
|
|
|
if (st.wDayOfWeek > 6)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-10-22 07:55:14 +02:00
|
|
|
WARN("unexpected weekday %s\n", debugstr_wn(value, ptr - value));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
ptr++;
|
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
2011-03-03 20:20:11 +01:00
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
2011-03-04 20:43:54 +01:00
|
|
|
if (!nextPtr || nextPtr <= ptr || !num || num > 31)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-10-22 07:55:14 +02:00
|
|
|
WARN("unexpected day %s\n", debugstr_w(value));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
ptr = nextPtr;
|
|
|
|
st.wDay = (WORD)num;
|
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
2017-05-17 14:35:47 +02:00
|
|
|
for (monthPtr = month; !isspaceW(*ptr) &&
|
2011-03-04 20:43:54 +01:00
|
|
|
monthPtr - month < sizeof(month) / sizeof(month[0]) - 1;
|
|
|
|
monthPtr++, ptr++)
|
|
|
|
*monthPtr = *ptr;
|
|
|
|
*monthPtr = 0;
|
|
|
|
st.wMonth = HTTP_ParseMonth(month);
|
|
|
|
if (!st.wMonth || st.wMonth > 12)
|
2011-03-03 20:20:11 +01:00
|
|
|
{
|
2011-10-22 07:55:14 +02:00
|
|
|
WARN("unexpected month %s\n", debugstr_w(month));
|
2011-03-03 20:20:11 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
|
|
|
if (!nextPtr || nextPtr <= ptr || num < 1601 || num > 30827)
|
|
|
|
{
|
|
|
|
ERR("unexpected year %s\n", debugstr_w(value));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr = nextPtr;
|
|
|
|
st.wYear = (WORD)num;
|
|
|
|
|
|
|
|
if (!HTTP_ParseTime(&st, &ptr))
|
|
|
|
return FALSE;
|
2011-03-03 20:20:11 +01:00
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (strcmpW(ptr, gmt))
|
|
|
|
{
|
|
|
|
ERR("unexpected time zone %s\n", debugstr_w(ptr));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return SystemTimeToFileTime(&st, ft);
|
|
|
|
}
|
|
|
|
|
2011-10-22 07:55:14 +02:00
|
|
|
static WORD HTTP_ParseWeekday(LPCWSTR day)
|
|
|
|
{
|
|
|
|
static const WCHAR days[7][10] = {{ 's','u','n','d','a','y',0 },
|
|
|
|
{ 'm','o','n','d','a','y',0 },
|
|
|
|
{ 't','u','e','s','d','a','y',0 },
|
|
|
|
{ 'w','e','d','n','e','s','d','a','y',0 },
|
|
|
|
{ 't','h','u','r','s','d','a','y',0 },
|
|
|
|
{ 'f','r','i','d','a','y',0 },
|
|
|
|
{ 's','a','t','u','r','d','a','y',0 }};
|
2013-03-12 23:28:49 +01:00
|
|
|
unsigned int i;
|
2011-10-22 07:55:14 +02:00
|
|
|
for (i = 0; i < sizeof(days)/sizeof(*days); i++)
|
|
|
|
if (!strcmpiW(day, days[i]))
|
|
|
|
return i;
|
|
|
|
|
|
|
|
/* Invalid */
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL HTTP_ParseRfc850Date(LPCWSTR value, FILETIME *ft)
|
|
|
|
{
|
|
|
|
static const WCHAR gmt[]= { 'G','M','T',0 };
|
|
|
|
WCHAR *nextPtr, day[10], month[4], *monthPtr;
|
|
|
|
LPCWSTR ptr;
|
|
|
|
unsigned long num;
|
|
|
|
SYSTEMTIME st = { 0 };
|
|
|
|
|
|
|
|
ptr = strchrW(value, ',');
|
|
|
|
if (!ptr)
|
|
|
|
return FALSE;
|
|
|
|
if (ptr - value == 3)
|
|
|
|
{
|
|
|
|
memcpy(day, value, (ptr - value) * sizeof(WCHAR));
|
|
|
|
day[3] = 0;
|
|
|
|
st.wDayOfWeek = HTTP_ParseWkday(day);
|
|
|
|
if (st.wDayOfWeek > 6)
|
|
|
|
{
|
|
|
|
ERR("unexpected weekday %s\n", debugstr_wn(value, ptr - value));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2011-10-24 22:21:10 +02:00
|
|
|
else if (ptr - value < sizeof(day) / sizeof(day[0]))
|
2011-10-22 07:55:14 +02:00
|
|
|
{
|
|
|
|
memcpy(day, value, (ptr - value) * sizeof(WCHAR));
|
|
|
|
day[ptr - value + 1] = 0;
|
|
|
|
st.wDayOfWeek = HTTP_ParseWeekday(day);
|
|
|
|
if (st.wDayOfWeek > 6)
|
|
|
|
{
|
|
|
|
ERR("unexpected weekday %s\n", debugstr_wn(value, ptr - value));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("unexpected weekday %s\n", debugstr_wn(value, ptr - value));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
|
|
|
if (!nextPtr || nextPtr <= ptr || !num || num > 31)
|
|
|
|
{
|
|
|
|
ERR("unexpected day %s\n", debugstr_w(value));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr = nextPtr;
|
|
|
|
st.wDay = (WORD)num;
|
|
|
|
|
|
|
|
if (*ptr != '-')
|
|
|
|
{
|
|
|
|
ERR("unexpected month format %s\n", debugstr_w(ptr));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
for (monthPtr = month; *ptr != '-' &&
|
|
|
|
monthPtr - month < sizeof(month) / sizeof(month[0]) - 1;
|
|
|
|
monthPtr++, ptr++)
|
|
|
|
*monthPtr = *ptr;
|
|
|
|
*monthPtr = 0;
|
|
|
|
st.wMonth = HTTP_ParseMonth(month);
|
|
|
|
if (!st.wMonth || st.wMonth > 12)
|
|
|
|
{
|
|
|
|
ERR("unexpected month %s\n", debugstr_w(month));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*ptr != '-')
|
|
|
|
{
|
|
|
|
ERR("unexpected year format %s\n", debugstr_w(ptr));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
num = strtoulW(ptr, &nextPtr, 10);
|
|
|
|
if (!nextPtr || nextPtr <= ptr || num < 1601 || num > 30827)
|
|
|
|
{
|
|
|
|
ERR("unexpected year %s\n", debugstr_w(value));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr = nextPtr;
|
|
|
|
st.wYear = (WORD)num;
|
|
|
|
|
|
|
|
if (!HTTP_ParseTime(&st, &ptr))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (strcmpW(ptr, gmt))
|
|
|
|
{
|
|
|
|
ERR("unexpected time zone %s\n", debugstr_w(ptr));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return SystemTimeToFileTime(&st, ft);
|
|
|
|
}
|
|
|
|
|
2011-03-04 20:43:54 +01:00
|
|
|
static BOOL HTTP_ParseDate(LPCWSTR value, FILETIME *ft)
|
|
|
|
{
|
2011-05-13 15:47:49 +02:00
|
|
|
static const WCHAR zero[] = { '0',0 };
|
2011-03-04 20:43:54 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
2011-05-13 15:47:49 +02:00
|
|
|
if (!strcmpW(value, zero))
|
|
|
|
{
|
|
|
|
ft->dwLowDateTime = ft->dwHighDateTime = 0;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else if (strchrW(value, ','))
|
2011-10-22 07:55:14 +02:00
|
|
|
{
|
2011-03-04 20:43:54 +01:00
|
|
|
ret = HTTP_ParseRfc1123Date(value, ft);
|
2011-10-22 07:55:14 +02:00
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
ret = HTTP_ParseRfc850Date(value, ft);
|
|
|
|
if (!ret)
|
|
|
|
ERR("unexpected date format %s\n", debugstr_w(value));
|
|
|
|
}
|
|
|
|
}
|
2011-03-04 20:43:54 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = HTTP_ParseDateAsAsctime(value, ft);
|
|
|
|
if (!ret)
|
|
|
|
ERR("unexpected date format %s\n", debugstr_w(value));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-03 20:20:11 +01:00
|
|
|
static void HTTP_ProcessExpires(http_request_t *request)
|
|
|
|
{
|
2011-03-03 19:54:07 +01:00
|
|
|
BOOL expirationFound = FALSE;
|
2011-03-03 20:20:11 +01:00
|
|
|
int headerIndex;
|
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
|
2011-03-03 19:54:47 +01:00
|
|
|
/* Look for a Cache-Control header with a max-age directive, as it takes
|
|
|
|
* precedence over the Expires header.
|
|
|
|
*/
|
|
|
|
headerIndex = HTTP_GetCustomHeaderIndex(request, szCache_Control, 0, FALSE);
|
2011-03-03 20:20:11 +01:00
|
|
|
if (headerIndex != -1)
|
|
|
|
{
|
2011-03-03 19:54:47 +01:00
|
|
|
LPHTTPHEADERW ccHeader = &request->custHeaders[headerIndex];
|
|
|
|
LPWSTR ptr;
|
|
|
|
|
|
|
|
for (ptr = ccHeader->lpszValue; ptr && *ptr; )
|
|
|
|
{
|
|
|
|
LPWSTR comma = strchrW(ptr, ','), end, equal;
|
|
|
|
|
|
|
|
if (comma)
|
|
|
|
end = comma;
|
|
|
|
else
|
|
|
|
end = ptr + strlenW(ptr);
|
|
|
|
for (equal = end - 1; equal > ptr && *equal != '='; equal--)
|
|
|
|
;
|
|
|
|
if (*equal == '=')
|
|
|
|
{
|
|
|
|
static const WCHAR max_age[] = {
|
|
|
|
'm','a','x','-','a','g','e',0 };
|
2011-03-03 20:20:11 +01:00
|
|
|
|
2011-03-03 19:54:47 +01:00
|
|
|
if (!strncmpiW(ptr, max_age, equal - ptr - 1))
|
|
|
|
{
|
|
|
|
LPWSTR nextPtr;
|
|
|
|
unsigned long age;
|
|
|
|
|
|
|
|
age = strtoulW(equal + 1, &nextPtr, 10);
|
|
|
|
if (nextPtr > equal + 1)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER ft;
|
|
|
|
|
|
|
|
NtQuerySystemTime( &ft );
|
|
|
|
/* Age is in seconds, FILETIME resolution is in
|
|
|
|
* 100 nanosecond intervals.
|
|
|
|
*/
|
|
|
|
ft.QuadPart += age * (ULONGLONG)1000000;
|
|
|
|
request->expires.dwLowDateTime = ft.u.LowPart;
|
|
|
|
request->expires.dwHighDateTime = ft.u.HighPart;
|
|
|
|
expirationFound = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (comma)
|
|
|
|
{
|
|
|
|
ptr = comma + 1;
|
|
|
|
while (isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ptr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!expirationFound)
|
|
|
|
{
|
|
|
|
headerIndex = HTTP_GetCustomHeaderIndex(request, szExpires, 0, FALSE);
|
|
|
|
if (headerIndex != -1)
|
2011-03-03 19:54:07 +01:00
|
|
|
{
|
2011-03-03 19:54:47 +01:00
|
|
|
LPHTTPHEADERW expiresHeader = &request->custHeaders[headerIndex];
|
|
|
|
FILETIME ft;
|
|
|
|
|
|
|
|
if (HTTP_ParseDate(expiresHeader->lpszValue, &ft))
|
|
|
|
{
|
|
|
|
expirationFound = TRUE;
|
|
|
|
request->expires = ft;
|
|
|
|
}
|
2011-03-03 19:54:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!expirationFound)
|
|
|
|
{
|
2011-03-03 19:54:07 +01:00
|
|
|
LARGE_INTEGER t;
|
2011-03-03 19:54:07 +01:00
|
|
|
|
|
|
|
/* With no known age, default to 10 minutes until expiration. */
|
2011-03-03 19:54:07 +01:00
|
|
|
NtQuerySystemTime( &t );
|
|
|
|
t.QuadPart += 10 * 60 * (ULONGLONG)10000000;
|
|
|
|
request->expires.dwLowDateTime = t.u.LowPart;
|
|
|
|
request->expires.dwHighDateTime = t.u.HighPart;
|
2011-03-03 20:20:11 +01:00
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2011-03-03 20:20:11 +01:00
|
|
|
}
|
|
|
|
|
2011-03-04 20:43:54 +01:00
|
|
|
static void HTTP_ProcessLastModified(http_request_t *request)
|
|
|
|
{
|
|
|
|
int headerIndex;
|
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
|
2011-03-04 20:43:54 +01:00
|
|
|
headerIndex = HTTP_GetCustomHeaderIndex(request, szLast_Modified, 0, FALSE);
|
|
|
|
if (headerIndex != -1)
|
|
|
|
{
|
|
|
|
LPHTTPHEADERW expiresHeader = &request->custHeaders[headerIndex];
|
|
|
|
FILETIME ft;
|
|
|
|
|
|
|
|
if (HTTP_ParseDate(expiresHeader->lpszValue, &ft))
|
|
|
|
request->last_modified = ft;
|
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2011-03-04 20:43:54 +01:00
|
|
|
}
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
static void http_process_keep_alive(http_request_t *req)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &req->headers_section );
|
|
|
|
|
2013-04-22 11:03:22 +02:00
|
|
|
if ((index = HTTP_GetCustomHeaderIndex(req, szConnection, 0, FALSE)) != -1)
|
|
|
|
req->netconn->keep_alive = !strcmpiW(req->custHeaders[index].lpszValue, szKeepAlive);
|
|
|
|
else if ((index = HTTP_GetCustomHeaderIndex(req, szProxy_Connection, 0, FALSE)) != -1)
|
2011-05-10 11:26:43 +02:00
|
|
|
req->netconn->keep_alive = !strcmpiW(req->custHeaders[index].lpszValue, szKeepAlive);
|
|
|
|
else
|
|
|
|
req->netconn->keep_alive = !strcmpiW(req->version, g_szHttp1_1);
|
2014-09-25 14:21:37 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &req->headers_section );
|
2011-05-10 11:26:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD open_http_connection(http_request_t *request, BOOL *reusing)
|
|
|
|
{
|
|
|
|
const BOOL is_https = (request->hdr.dwFlags & INTERNET_FLAG_SECURE) != 0;
|
|
|
|
netconn_t *netconn = NULL;
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
reset_data_stream(request);
|
|
|
|
|
2013-11-26 00:12:49 +01:00
|
|
|
if (request->netconn)
|
|
|
|
{
|
2013-12-11 10:48:41 +01:00
|
|
|
if (is_valid_netconn(request->netconn) && NETCON_is_alive(request->netconn))
|
2013-11-26 00:12:49 +01:00
|
|
|
{
|
|
|
|
*reusing = TRUE;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free_netconn(request->netconn);
|
|
|
|
request->netconn = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 16:34:24 +02:00
|
|
|
res = HTTP_ResolveName(request);
|
|
|
|
if(res != ERROR_SUCCESS)
|
2011-05-10 11:26:43 +02:00
|
|
|
return res;
|
|
|
|
|
|
|
|
EnterCriticalSection(&connection_pool_cs);
|
|
|
|
|
2012-05-25 16:34:24 +02:00
|
|
|
while(!list_empty(&request->server->conn_pool)) {
|
|
|
|
netconn = LIST_ENTRY(list_head(&request->server->conn_pool), netconn_t, pool_entry);
|
2011-05-10 11:26:43 +02:00
|
|
|
list_remove(&netconn->pool_entry);
|
|
|
|
|
2013-12-11 10:48:41 +01:00
|
|
|
if(is_valid_netconn(netconn) && NETCON_is_alive(netconn))
|
2011-05-10 11:26:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
TRACE("connection %p closed during idle\n", netconn);
|
|
|
|
free_netconn(netconn);
|
|
|
|
netconn = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&connection_pool_cs);
|
|
|
|
|
|
|
|
if(netconn) {
|
|
|
|
TRACE("<-- reusing %p netconn\n", netconn);
|
|
|
|
request->netconn = netconn;
|
|
|
|
*reusing = TRUE;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-11-16 14:38:56 +01:00
|
|
|
TRACE("connecting to %s, proxy %s\n", debugstr_w(request->server->name),
|
|
|
|
request->proxy ? debugstr_w(request->proxy->name) : "(null)");
|
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTING_TO_SERVER,
|
2012-05-25 16:34:24 +02:00
|
|
|
request->server->addr_str,
|
|
|
|
strlen(request->server->addr_str)+1);
|
2011-05-10 11:26:43 +02:00
|
|
|
|
2012-11-16 14:38:56 +01:00
|
|
|
res = create_netconn(is_https, request->proxy ? request->proxy : request->server, request->security_flags,
|
2012-05-25 16:51:20 +02:00
|
|
|
(request->hdr.ErrorMask & INTERNET_ERROR_MASK_COMBINED_SEC_CERT) != 0,
|
|
|
|
request->connect_timeout, &netconn);
|
2011-05-10 11:26:43 +02:00
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
ERR("create_netconn failed: %u\n", res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
request->netconn = netconn;
|
|
|
|
|
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTED_TO_SERVER,
|
2012-05-25 16:34:24 +02:00
|
|
|
request->server->addr_str, strlen(request->server->addr_str)+1);
|
2011-05-10 11:26:43 +02:00
|
|
|
|
|
|
|
*reusing = FALSE;
|
2012-05-25 16:34:24 +02:00
|
|
|
TRACE("Created connection to %s: %p\n", debugstr_w(request->server->name), netconn);
|
2011-05-10 11:26:43 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-05-06 11:32:53 +02:00
|
|
|
static char *build_ascii_request( const WCHAR *str, void *data, DWORD data_len, DWORD *out_len )
|
|
|
|
{
|
|
|
|
int len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
if (!(ret = heap_alloc( len + data_len ))) return NULL;
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
|
|
|
|
if (data_len) memcpy( ret + len - 1, data, data_len );
|
|
|
|
*out_len = len + data_len - 1;
|
|
|
|
ret[*out_len] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-02 15:06:36 +02:00
|
|
|
static void set_content_length_header( http_request_t *request, DWORD len, DWORD flags )
|
|
|
|
{
|
|
|
|
static const WCHAR fmtW[] =
|
|
|
|
{'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','u','\r','\n',0};
|
|
|
|
WCHAR buf[sizeof(fmtW)/sizeof(fmtW[0]) + 10];
|
|
|
|
|
|
|
|
sprintfW( buf, fmtW, len );
|
|
|
|
HTTP_HttpAddRequestHeadersW( request, buf, ~0u, flags );
|
|
|
|
}
|
|
|
|
|
2002-11-12 03:13:04 +01:00
|
|
|
/***********************************************************************
|
2009-11-30 20:01:17 +01:00
|
|
|
* HTTP_HttpSendRequestW (internal)
|
2002-11-12 03:13:04 +01:00
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
2011-03-03 02:09:45 +01:00
|
|
|
* ERROR_SUCCESS on success
|
|
|
|
* win32 error code on failure
|
2002-11-12 03:13:04 +01:00
|
|
|
*
|
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders,
|
2009-11-30 20:01:17 +01:00
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
|
|
|
|
DWORD dwContentLength, BOOL bEndRequest)
|
2009-05-04 20:49:15 +02:00
|
|
|
{
|
2014-05-06 11:32:53 +02:00
|
|
|
BOOL redirected = FALSE, secure_proxy_connect = FALSE, loop_next;
|
|
|
|
LPWSTR requestString = NULL;
|
|
|
|
INT responseLen, cnt;
|
2009-11-30 20:01:17 +01:00
|
|
|
DWORD res;
|
2009-05-04 20:49:15 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
TRACE("--> %p\n", request);
|
2009-05-04 20:49:15 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
assert(request->hdr.htype == WH_HHTTPREQ);
|
2009-05-04 20:49:15 +02:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
/* if the verb is NULL default to GET */
|
2011-03-01 20:18:22 +01:00
|
|
|
if (!request->verb)
|
|
|
|
request->verb = heap_strdupW(szGET);
|
2009-05-04 20:49:15 +02:00
|
|
|
|
2015-08-25 07:26:43 +02:00
|
|
|
HTTP_ProcessHeader(request, hostW, request->server->canon_host_port,
|
|
|
|
HTTP_ADDREQ_FLAG_ADD_IF_NEW | HTTP_ADDHDR_FLAG_REQ);
|
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
if (dwContentLength || strcmpW(request->verb, szGET))
|
2009-05-04 20:49:15 +02:00
|
|
|
{
|
2015-10-02 15:06:36 +02:00
|
|
|
set_content_length_header(request, dwContentLength, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
|
2011-03-01 20:18:22 +01:00
|
|
|
request->bytesToWrite = dwContentLength;
|
2009-05-04 20:49:15 +02:00
|
|
|
}
|
2011-03-01 20:18:22 +01:00
|
|
|
if (request->session->appInfo->agent)
|
2009-05-04 20:49:15 +02:00
|
|
|
{
|
2009-11-30 20:01:17 +01:00
|
|
|
WCHAR *agent_header;
|
|
|
|
static const WCHAR user_agent[] = {'U','s','e','r','-','A','g','e','n','t',':',' ','%','s','\r','\n',0};
|
|
|
|
int len;
|
2009-05-04 20:49:15 +02:00
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
len = strlenW(request->session->appInfo->agent) + strlenW(user_agent);
|
2011-04-21 13:39:03 +02:00
|
|
|
agent_header = heap_alloc(len * sizeof(WCHAR));
|
2011-03-01 20:18:22 +01:00
|
|
|
sprintfW(agent_header, user_agent, request->session->appInfo->agent);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_HttpAddRequestHeadersW(request, agent_header, strlenW(agent_header), HTTP_ADDREQ_FLAG_ADD_IF_NEW);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(agent_header);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
2011-03-01 19:59:39 +01:00
|
|
|
if (request->hdr.dwFlags & INTERNET_FLAG_PRAGMA_NOCACHE)
|
2009-05-04 20:49:15 +02:00
|
|
|
{
|
2009-11-30 20:01:17 +01:00
|
|
|
static const WCHAR pragma_nocache[] = {'P','r','a','g','m','a',':',' ','n','o','-','c','a','c','h','e','\r','\n',0};
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_HttpAddRequestHeadersW(request, pragma_nocache, strlenW(pragma_nocache), HTTP_ADDREQ_FLAG_ADD_IF_NEW);
|
2009-05-04 20:49:15 +02:00
|
|
|
}
|
2013-07-30 11:08:49 +02:00
|
|
|
if ((request->hdr.dwFlags & INTERNET_FLAG_NO_CACHE_WRITE) && strcmpW(request->verb, szGET))
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
2009-11-30 20:01:17 +01:00
|
|
|
static const WCHAR cache_control[] = {'C','a','c','h','e','-','C','o','n','t','r','o','l',':',
|
|
|
|
' ','n','o','-','c','a','c','h','e','\r','\n',0};
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_HttpAddRequestHeadersW(request, cache_control, strlenW(cache_control), HTTP_ADDREQ_FLAG_ADD_IF_NEW);
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2012-01-24 17:31:38 +01:00
|
|
|
/* add the headers the caller supplied */
|
|
|
|
if( lpszHeaders && dwHeaderLength )
|
|
|
|
HTTP_HttpAddRequestHeadersW(request, lpszHeaders, dwHeaderLength, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE);
|
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
do
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
2014-05-06 11:32:53 +02:00
|
|
|
DWORD len, data_len = dwOptionalLength;
|
2010-06-29 12:20:51 +02:00
|
|
|
BOOL reusing_connection;
|
2009-11-30 20:01:17 +01:00
|
|
|
char *ascii_req;
|
2006-03-09 16:11:59 +01:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
loop_next = FALSE;
|
2013-11-06 23:31:06 +01:00
|
|
|
|
2010-05-20 02:35:38 +02:00
|
|
|
if(redirected) {
|
2011-03-01 20:18:22 +01:00
|
|
|
request->contentLength = ~0u;
|
|
|
|
request->bytesToWrite = 0;
|
2010-05-20 02:35:38 +02:00
|
|
|
}
|
2005-11-29 11:25:31 +01:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
if (TRACE_ON(wininet))
|
2005-11-29 11:25:31 +01:00
|
|
|
{
|
2014-09-25 14:21:37 +02:00
|
|
|
HTTPHEADERW *host;
|
|
|
|
|
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
host = HTTP_GetHeader( request, hostW );
|
|
|
|
TRACE("Going to url %s %s\n", debugstr_w(host->lpszValue), debugstr_w(request->path));
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2005-11-29 11:25:31 +01:00
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_FixURL(request);
|
|
|
|
if (request->hdr.dwFlags & INTERNET_FLAG_KEEP_CONNECTION)
|
2005-11-28 17:31:02 +01:00
|
|
|
{
|
2015-06-25 12:28:02 +02:00
|
|
|
HTTP_ProcessHeader(request, szConnection, szKeepAlive,
|
|
|
|
HTTP_ADDHDR_FLAG_REQ | HTTP_ADDHDR_FLAG_REPLACE | HTTP_ADDHDR_FLAG_ADD);
|
2005-11-28 17:31:02 +01:00
|
|
|
}
|
2011-03-01 20:18:22 +01:00
|
|
|
HTTP_InsertAuthorization(request, request->authInfo, szAuthorization);
|
|
|
|
HTTP_InsertAuthorization(request, request->proxyAuthInfo, szProxy_Authorization);
|
2002-12-07 00:20:31 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
if (!(request->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES))
|
|
|
|
HTTP_InsertCookies(request);
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2014-05-06 11:32:53 +02:00
|
|
|
res = open_http_connection(request, &reusing_connection);
|
|
|
|
if (res != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!reusing_connection && (request->hdr.dwFlags & INTERNET_FLAG_SECURE))
|
|
|
|
{
|
|
|
|
if (request->proxy) secure_proxy_connect = TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = NETCON_secure_connect(request->netconn, request->server);
|
|
|
|
if (res != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WARN("failed to upgrade to secure connection\n");
|
|
|
|
http_release_netconn(request, FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (secure_proxy_connect)
|
|
|
|
{
|
|
|
|
static const WCHAR connectW[] = {'C','O','N','N','E','C','T',0};
|
|
|
|
const WCHAR *target = request->server->host_port;
|
2015-10-02 15:06:36 +02:00
|
|
|
|
|
|
|
if (HTTP_GetCustomHeaderIndex(request, szContent_Length, 0, TRUE) >= 0)
|
|
|
|
set_content_length_header(request, 0, HTTP_ADDREQ_FLAG_REPLACE);
|
|
|
|
|
2014-05-06 11:32:53 +02:00
|
|
|
requestString = build_request_header(request, connectW, target, g_szHttp1_1, TRUE);
|
|
|
|
}
|
|
|
|
else if (request->proxy && !(request->hdr.dwFlags & INTERNET_FLAG_SECURE))
|
2008-03-31 20:25:57 +02:00
|
|
|
{
|
2012-11-19 11:47:50 +01:00
|
|
|
WCHAR *url = build_proxy_path_url(request);
|
2013-04-30 16:59:33 +02:00
|
|
|
requestString = build_request_header(request, request->verb, url, request->version, TRUE);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(url);
|
2008-03-31 20:25:57 +02:00
|
|
|
}
|
|
|
|
else
|
2015-10-02 15:06:36 +02:00
|
|
|
{
|
|
|
|
if (request->proxy && HTTP_GetCustomHeaderIndex(request, szContent_Length, 0, TRUE) >= 0)
|
|
|
|
set_content_length_header(request, dwContentLength, HTTP_ADDREQ_FLAG_REPLACE);
|
|
|
|
|
2013-04-30 16:59:33 +02:00
|
|
|
requestString = build_request_header(request, request->verb, request->path, request->version, TRUE);
|
2015-10-02 15:06:36 +02:00
|
|
|
}
|
2002-12-07 00:20:31 +01:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
TRACE("Request header -> %s\n", debugstr_w(requestString) );
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
/* send the request as ASCII, tack on the optional data */
|
2014-05-06 11:32:53 +02:00
|
|
|
if (!lpOptional || redirected || secure_proxy_connect)
|
|
|
|
data_len = 0;
|
|
|
|
|
|
|
|
ascii_req = build_ascii_request( requestString, lpOptional, data_len, &len );
|
2009-11-30 20:01:17 +01:00
|
|
|
TRACE("full request -> %s\n", debugstr_a(ascii_req) );
|
2004-07-04 02:24:47 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
2009-11-30 20:01:17 +01:00
|
|
|
INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
|
2005-11-28 11:55:16 +01:00
|
|
|
|
2012-01-13 15:15:48 +01:00
|
|
|
NETCON_set_timeout( request->netconn, TRUE, request->send_timeout );
|
2011-05-10 11:26:43 +02:00
|
|
|
res = NETCON_send(request->netconn, ascii_req, len, 0, &cnt);
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free( ascii_req );
|
2011-05-10 11:26:43 +02:00
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
TRACE("send failed: %u\n", res);
|
|
|
|
if(!reusing_connection)
|
|
|
|
break;
|
|
|
|
http_release_netconn(request, FALSE);
|
|
|
|
loop_next = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
2005-11-28 11:55:16 +01:00
|
|
|
|
2014-05-06 11:32:53 +02:00
|
|
|
request->bytesWritten = data_len;
|
2005-11-28 11:55:16 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
2009-11-30 20:01:17 +01:00
|
|
|
INTERNET_STATUS_REQUEST_SENT,
|
|
|
|
&len, sizeof(DWORD));
|
2005-11-28 11:55:16 +01:00
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
if (bEndRequest)
|
|
|
|
{
|
|
|
|
DWORD dwBufferSize;
|
2005-11-28 11:55:16 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
2009-11-30 20:01:17 +01:00
|
|
|
INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
|
|
|
|
|
2013-04-25 10:15:19 +02:00
|
|
|
if (HTTP_GetResponseHeaders(request, &responseLen))
|
|
|
|
{
|
|
|
|
http_release_netconn(request, FALSE);
|
|
|
|
res = ERROR_INTERNET_CONNECTION_ABORTED;
|
|
|
|
goto lend;
|
|
|
|
}
|
2010-06-29 12:20:51 +02:00
|
|
|
/* FIXME: We should know that connection is closed before sending
|
|
|
|
* headers. Otherwise wrong callbacks are executed */
|
|
|
|
if(!responseLen && reusing_connection) {
|
|
|
|
TRACE("Connection closed by server, reconnecting\n");
|
2011-05-10 11:26:43 +02:00
|
|
|
http_release_netconn(request, FALSE);
|
2010-06-29 12:20:51 +02:00
|
|
|
loop_next = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
2011-05-10 11:26:43 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
2009-11-30 20:01:17 +01:00
|
|
|
INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen,
|
|
|
|
sizeof(DWORD));
|
2005-11-28 11:55:16 +01:00
|
|
|
|
2011-05-10 11:26:43 +02:00
|
|
|
http_process_keep_alive(request);
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_ProcessCookies(request);
|
2011-03-03 20:20:11 +01:00
|
|
|
HTTP_ProcessExpires(request);
|
2011-03-04 20:43:54 +01:00
|
|
|
HTTP_ProcessLastModified(request);
|
2005-11-28 11:55:16 +01:00
|
|
|
|
2012-05-03 12:19:47 +02:00
|
|
|
res = set_content_length(request);
|
2011-05-13 13:48:15 +02:00
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
goto lend;
|
|
|
|
if(!request->contentLength)
|
|
|
|
http_release_netconn(request, TRUE);
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
if (!(request->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT) && responseLen)
|
2006-12-07 01:53:27 +01:00
|
|
|
{
|
2016-05-18 18:03:09 +02:00
|
|
|
WCHAR *new_url;
|
|
|
|
|
2012-05-03 12:19:58 +02:00
|
|
|
switch(request->status_code) {
|
|
|
|
case HTTP_STATUS_REDIRECT:
|
|
|
|
case HTTP_STATUS_MOVED:
|
|
|
|
case HTTP_STATUS_REDIRECT_KEEP_VERB:
|
|
|
|
case HTTP_STATUS_REDIRECT_METHOD:
|
2016-05-18 18:03:09 +02:00
|
|
|
new_url = get_redirect_url(request);
|
|
|
|
if(!new_url)
|
2012-05-03 12:19:58 +02:00
|
|
|
break;
|
|
|
|
|
2011-06-01 11:50:32 +02:00
|
|
|
if (strcmpW(request->verb, szGET) && strcmpW(request->verb, szHEAD) &&
|
2012-05-03 12:19:58 +02:00
|
|
|
request->status_code != HTTP_STATUS_REDIRECT_KEEP_VERB)
|
2009-07-22 11:56:33 +02:00
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(request->verb);
|
2011-03-01 20:18:22 +01:00
|
|
|
request->verb = heap_strdupW(szGET);
|
2009-07-22 11:56:33 +02:00
|
|
|
}
|
2012-07-02 17:15:04 +02:00
|
|
|
http_release_netconn(request, drain_content(request, FALSE));
|
2016-05-18 18:03:09 +02:00
|
|
|
res = HTTP_HandleRedirect(request, new_url);
|
|
|
|
heap_free(new_url);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
|
|
|
heap_free(requestString);
|
|
|
|
loop_next = TRUE;
|
2006-12-07 01:53:27 +01:00
|
|
|
}
|
2009-05-06 15:57:56 +02:00
|
|
|
redirected = TRUE;
|
2006-12-07 01:53:27 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-01 19:59:39 +01:00
|
|
|
if (!(request->hdr.dwFlags & INTERNET_FLAG_NO_AUTH) && res == ERROR_SUCCESS)
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
|
|
|
WCHAR szAuthValue[2048];
|
|
|
|
dwBufferSize=2048;
|
2012-05-03 12:19:58 +02:00
|
|
|
if (request->status_code == HTTP_STATUS_DENIED)
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2015-08-25 07:26:43 +02:00
|
|
|
WCHAR *host = heap_strdupW( request->server->canon_host_port );
|
2007-05-21 15:26:26 +02:00
|
|
|
DWORD dwIndex = 0;
|
2011-03-01 19:59:39 +01:00
|
|
|
while (HTTP_HttpQueryInfoW(request,HTTP_QUERY_WWW_AUTHENTICATE,szAuthValue,&dwBufferSize,&dwIndex) == ERROR_SUCCESS)
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
if (HTTP_DoAuthorization(request, szAuthValue,
|
2011-03-01 20:18:22 +01:00
|
|
|
&request->authInfo,
|
|
|
|
request->session->userName,
|
2014-09-25 14:21:37 +02:00
|
|
|
request->session->password, host))
|
2007-06-05 20:49:58 +02:00
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(requestString);
|
2012-07-02 17:15:04 +02:00
|
|
|
if(!drain_content(request, TRUE)) {
|
|
|
|
FIXME("Could not drain content\n");
|
|
|
|
http_release_netconn(request, FALSE);
|
|
|
|
}
|
2007-06-05 20:49:58 +02:00
|
|
|
loop_next = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
heap_free( host );
|
2010-07-17 14:08:11 +02:00
|
|
|
|
|
|
|
if(!loop_next) {
|
|
|
|
TRACE("Cleaning wrong authorization data\n");
|
2011-03-01 20:18:22 +01:00
|
|
|
destroy_authinfo(request->authInfo);
|
|
|
|
request->authInfo = NULL;
|
2010-07-17 14:08:11 +02:00
|
|
|
}
|
2007-06-05 20:49:58 +02:00
|
|
|
}
|
2012-05-03 12:19:58 +02:00
|
|
|
if (request->status_code == HTTP_STATUS_PROXY_AUTH_REQ)
|
2007-06-05 20:49:58 +02:00
|
|
|
{
|
|
|
|
DWORD dwIndex = 0;
|
2011-03-01 19:59:39 +01:00
|
|
|
while (HTTP_HttpQueryInfoW(request,HTTP_QUERY_PROXY_AUTHENTICATE,szAuthValue,&dwBufferSize,&dwIndex) == ERROR_SUCCESS)
|
2007-06-05 20:49:58 +02:00
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
if (HTTP_DoAuthorization(request, szAuthValue,
|
2011-03-01 20:18:22 +01:00
|
|
|
&request->proxyAuthInfo,
|
|
|
|
request->session->appInfo->proxyUsername,
|
|
|
|
request->session->appInfo->proxyPassword,
|
2009-10-12 21:24:18 +02:00
|
|
|
NULL))
|
2007-05-21 15:26:26 +02:00
|
|
|
{
|
2013-04-22 11:02:09 +02:00
|
|
|
heap_free(requestString);
|
2012-07-02 17:15:04 +02:00
|
|
|
if(!drain_content(request, TRUE)) {
|
|
|
|
FIXME("Could not drain content\n");
|
|
|
|
http_release_netconn(request, FALSE);
|
|
|
|
}
|
2007-05-21 15:26:26 +02:00
|
|
|
loop_next = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-07-17 14:08:11 +02:00
|
|
|
|
|
|
|
if(!loop_next) {
|
|
|
|
TRACE("Cleaning wrong proxy authorization data\n");
|
2011-03-01 20:18:22 +01:00
|
|
|
destroy_authinfo(request->proxyAuthInfo);
|
|
|
|
request->proxyAuthInfo = NULL;
|
2010-07-17 14:08:11 +02:00
|
|
|
}
|
2007-05-21 15:26:26 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-06 11:32:53 +02:00
|
|
|
if (secure_proxy_connect && request->status_code == HTTP_STATUS_OK)
|
|
|
|
{
|
|
|
|
res = NETCON_secure_connect(request->netconn, request->server);
|
|
|
|
if (res != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WARN("failed to upgrade to secure proxy connection\n");
|
|
|
|
http_release_netconn( request, FALSE );
|
|
|
|
break;
|
|
|
|
}
|
2014-12-19 16:49:48 +01:00
|
|
|
remove_header(request, szProxy_Authorization, TRUE);
|
2014-05-06 11:32:53 +02:00
|
|
|
destroy_authinfo(request->proxyAuthInfo);
|
|
|
|
request->proxyAuthInfo = NULL;
|
|
|
|
|
|
|
|
secure_proxy_connect = FALSE;
|
|
|
|
loop_next = TRUE;
|
|
|
|
}
|
2005-11-30 12:31:22 +01:00
|
|
|
}
|
|
|
|
else
|
2009-12-03 14:48:54 +01:00
|
|
|
res = ERROR_SUCCESS;
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
while (loop_next);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
lend:
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(requestString);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
/* TODO: send notification for P3P header */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2012-11-02 13:49:05 +01:00
|
|
|
if(res == ERROR_SUCCESS)
|
|
|
|
create_cache_entry(request);
|
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
if (request->session->appInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2009-04-08 15:22:26 +02:00
|
|
|
{
|
2011-06-10 14:47:16 +02:00
|
|
|
if (res == ERROR_SUCCESS) {
|
2011-11-23 15:45:44 +01:00
|
|
|
if(bEndRequest && request->contentLength && request->bytesWritten == request->bytesToWrite)
|
2017-03-13 14:47:19 +01:00
|
|
|
HTTP_ReceiveRequestData(request);
|
2011-06-10 14:47:16 +02:00
|
|
|
else
|
|
|
|
send_request_complete(request,
|
|
|
|
request->session->hdr.dwInternalFlags & INET_OPENURL ? (DWORD_PTR)request->hdr.hInternet : 1, 0);
|
|
|
|
}else {
|
|
|
|
send_request_complete(request, 0, res);
|
|
|
|
}
|
2009-01-13 00:28:25 +01:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
TRACE("<--\n");
|
2009-12-03 14:48:54 +01:00
|
|
|
return res;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2013-01-28 11:23:19 +01:00
|
|
|
typedef struct {
|
|
|
|
task_header_t hdr;
|
|
|
|
WCHAR *headers;
|
|
|
|
DWORD headers_len;
|
|
|
|
void *optional;
|
|
|
|
DWORD optional_len;
|
|
|
|
DWORD content_len;
|
|
|
|
BOOL end_request;
|
|
|
|
} send_request_task_t;
|
|
|
|
|
2009-11-30 20:01:17 +01:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Helper functions for the HttpSendRequest(Ex) functions
|
|
|
|
*
|
|
|
|
*/
|
2013-01-28 11:23:19 +01:00
|
|
|
static void AsyncHttpSendRequestProc(task_header_t *hdr)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2013-01-28 11:23:19 +01:00
|
|
|
send_request_task_t *task = (send_request_task_t*)hdr;
|
|
|
|
http_request_t *request = (http_request_t*)task->hdr.hdr;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
TRACE("%p\n", request);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-28 11:23:19 +01:00
|
|
|
HTTP_HttpSendRequestW(request, task->headers, task->headers_len, task->optional,
|
|
|
|
task->optional_len, task->content_len, task->end_request);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-28 11:23:19 +01:00
|
|
|
heap_free(task->headers);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
static DWORD HTTP_HttpEndRequestW(http_request_t *request, DWORD dwFlags, DWORD_PTR dwContext)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2012-05-03 12:20:10 +02:00
|
|
|
INT responseLen;
|
2009-12-03 14:49:29 +01:00
|
|
|
DWORD res = ERROR_SUCCESS;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-12-11 10:48:41 +01:00
|
|
|
if(!is_valid_netconn(request->netconn)) {
|
2011-12-07 16:40:27 +01:00
|
|
|
WARN("Not connected\n");
|
|
|
|
send_request_complete(request, 0, ERROR_INTERNET_OPERATION_CANCELLED);
|
|
|
|
return ERROR_INTERNET_OPERATION_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
2009-11-30 20:01:17 +01:00
|
|
|
INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
|
|
|
|
|
2013-04-25 10:15:19 +02:00
|
|
|
if (HTTP_GetResponseHeaders(request, &responseLen) || !responseLen)
|
2009-12-03 14:49:29 +01:00
|
|
|
res = ERROR_HTTP_HEADER_NOT_FOUND;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_SendCallback(&request->hdr, request->hdr.dwContext,
|
2009-11-30 20:01:17 +01:00
|
|
|
INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen, sizeof(DWORD));
|
|
|
|
|
|
|
|
/* process cookies here. Is this right? */
|
2011-05-10 11:26:43 +02:00
|
|
|
http_process_keep_alive(request);
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_ProcessCookies(request);
|
2011-03-03 20:20:11 +01:00
|
|
|
HTTP_ProcessExpires(request);
|
2011-03-04 20:43:54 +01:00
|
|
|
HTTP_ProcessLastModified(request);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2012-05-03 12:19:47 +02:00
|
|
|
if ((res = set_content_length(request)) == ERROR_SUCCESS) {
|
2011-04-02 15:20:33 +02:00
|
|
|
if(!request->contentLength)
|
2011-05-10 11:26:43 +02:00
|
|
|
http_release_netconn(request, TRUE);
|
2011-04-02 15:20:33 +02:00
|
|
|
}
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-04-02 15:20:33 +02:00
|
|
|
if (res == ERROR_SUCCESS && !(request->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT))
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2012-05-03 12:20:10 +02:00
|
|
|
switch(request->status_code) {
|
|
|
|
case HTTP_STATUS_REDIRECT:
|
|
|
|
case HTTP_STATUS_MOVED:
|
|
|
|
case HTTP_STATUS_REDIRECT_METHOD:
|
|
|
|
case HTTP_STATUS_REDIRECT_KEEP_VERB: {
|
2016-05-18 18:03:09 +02:00
|
|
|
WCHAR *new_url;
|
|
|
|
|
|
|
|
new_url = get_redirect_url(request);
|
|
|
|
if(!new_url)
|
2012-05-03 12:20:10 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (strcmpW(request->verb, szGET) && strcmpW(request->verb, szHEAD) &&
|
|
|
|
request->status_code != HTTP_STATUS_REDIRECT_KEEP_VERB)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2012-05-03 12:20:10 +02:00
|
|
|
heap_free(request->verb);
|
|
|
|
request->verb = heap_strdupW(szGET);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
2012-07-02 17:15:04 +02:00
|
|
|
http_release_netconn(request, drain_content(request, FALSE));
|
2016-05-18 18:03:09 +02:00
|
|
|
res = HTTP_HandleRedirect(request, new_url);
|
|
|
|
heap_free(new_url);
|
|
|
|
if (res == ERROR_SUCCESS)
|
|
|
|
res = HTTP_HttpSendRequestW(request, NULL, 0, NULL, 0, 0, TRUE);
|
2012-05-03 12:20:10 +02:00
|
|
|
}
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:49:05 +01:00
|
|
|
if(res == ERROR_SUCCESS)
|
|
|
|
create_cache_entry(request);
|
|
|
|
|
2011-06-10 14:47:04 +02:00
|
|
|
if (res == ERROR_SUCCESS && request->contentLength)
|
2017-03-13 14:47:19 +01:00
|
|
|
HTTP_ReceiveRequestData(request);
|
2011-06-10 14:47:04 +02:00
|
|
|
else
|
2011-06-10 14:47:16 +02:00
|
|
|
send_request_complete(request, res == ERROR_SUCCESS, res);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2009-12-03 14:49:29 +01:00
|
|
|
return res;
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpEndRequestA (WININET.@)
|
|
|
|
*
|
|
|
|
* Ends an HTTP request that was started by HttpSendRequestEx
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpEndRequestA(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p, %08x, %08lx)\n", hRequest, lpBuffersOut, dwFlags, dwContext);
|
|
|
|
|
|
|
|
if (lpBuffersOut)
|
|
|
|
{
|
2009-12-21 13:58:18 +01:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2009-11-30 20:01:17 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HttpEndRequestW(hRequest, NULL, dwFlags, dwContext);
|
|
|
|
}
|
|
|
|
|
2013-01-29 12:04:16 +01:00
|
|
|
typedef struct {
|
|
|
|
task_header_t hdr;
|
|
|
|
DWORD flags;
|
|
|
|
DWORD context;
|
|
|
|
} end_request_task_t;
|
|
|
|
|
|
|
|
static void AsyncHttpEndRequestProc(task_header_t *hdr)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2013-01-29 12:04:16 +01:00
|
|
|
end_request_task_t *task = (end_request_task_t*)hdr;
|
|
|
|
http_request_t *req = (http_request_t*)task->hdr.hdr;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-29 12:04:16 +01:00
|
|
|
TRACE("%p\n", req);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-29 12:04:16 +01:00
|
|
|
HTTP_HttpEndRequestW(req, task->flags, task->context);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpEndRequestW (WININET.@)
|
|
|
|
*
|
|
|
|
* Ends an HTTP request that was started by HttpSendRequestEx
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpEndRequestW(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSW lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext)
|
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_request_t *request;
|
2009-12-03 14:49:29 +01:00
|
|
|
DWORD res;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-06-10 14:47:04 +02:00
|
|
|
TRACE("%p %p %x %lx -->\n", hRequest, lpBuffersOut, dwFlags, dwContext);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
|
|
|
if (lpBuffersOut)
|
|
|
|
{
|
2009-12-03 14:49:29 +01:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2009-11-30 20:01:17 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
request = (http_request_t*) get_handle_object( hRequest );
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
if (NULL == request || request->hdr.htype != WH_HHTTPREQ)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2009-12-03 14:49:29 +01:00
|
|
|
SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2011-03-01 19:59:39 +01:00
|
|
|
if (request)
|
|
|
|
WININET_Release( &request->hdr );
|
2009-11-30 20:01:17 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-03-01 19:59:39 +01:00
|
|
|
request->hdr.dwFlags |= dwFlags;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
if (request->session->appInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2013-01-29 12:04:16 +01:00
|
|
|
end_request_task_t *task;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-28 11:23:03 +01:00
|
|
|
task = alloc_async_task(&request->hdr, AsyncHttpEndRequestProc, sizeof(*task));
|
2013-01-29 12:04:16 +01:00
|
|
|
task->flags = dwFlags;
|
|
|
|
task->context = dwContext;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-29 12:04:16 +01:00
|
|
|
INTERNET_AsyncCall(&task->hdr);
|
2009-12-03 14:49:29 +01:00
|
|
|
res = ERROR_IO_PENDING;
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
else
|
2011-03-01 19:59:39 +01:00
|
|
|
res = HTTP_HttpEndRequestW(request, dwFlags, dwContext);
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
WININET_Release( &request->hdr );
|
2009-12-03 14:49:29 +01:00
|
|
|
TRACE("%u <--\n", res);
|
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
SetLastError(res);
|
|
|
|
return res == ERROR_SUCCESS;
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpSendRequestExA (WININET.@)
|
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server and allows chunked
|
|
|
|
* transfers.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE, call GetLastError() for more information.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSA lpBuffersIn,
|
|
|
|
LPINTERNET_BUFFERSA lpBuffersOut,
|
|
|
|
DWORD dwFlags, DWORD_PTR dwContext)
|
|
|
|
{
|
|
|
|
INTERNET_BUFFERSW BuffersInW;
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
DWORD headerlen;
|
|
|
|
LPWSTR header = NULL;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %08x, %08lx)\n", hRequest, lpBuffersIn,
|
|
|
|
lpBuffersOut, dwFlags, dwContext);
|
|
|
|
|
|
|
|
if (lpBuffersIn)
|
|
|
|
{
|
|
|
|
BuffersInW.dwStructSize = sizeof(LPINTERNET_BUFFERSW);
|
|
|
|
if (lpBuffersIn->lpcszHeader)
|
|
|
|
{
|
|
|
|
headerlen = MultiByteToWideChar(CP_ACP,0,lpBuffersIn->lpcszHeader,
|
|
|
|
lpBuffersIn->dwHeadersLength,0,0);
|
2011-04-21 13:39:03 +02:00
|
|
|
header = heap_alloc(headerlen*sizeof(WCHAR));
|
2009-11-30 20:01:17 +01:00
|
|
|
if (!(BuffersInW.lpcszHeader = header))
|
|
|
|
{
|
2009-12-21 13:58:53 +01:00
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
2009-11-30 20:01:17 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
BuffersInW.dwHeadersLength = MultiByteToWideChar(CP_ACP, 0,
|
|
|
|
lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength,
|
|
|
|
header, headerlen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
BuffersInW.lpcszHeader = NULL;
|
|
|
|
BuffersInW.dwHeadersTotal = lpBuffersIn->dwHeadersTotal;
|
|
|
|
BuffersInW.lpvBuffer = lpBuffersIn->lpvBuffer;
|
|
|
|
BuffersInW.dwBufferLength = lpBuffersIn->dwBufferLength;
|
|
|
|
BuffersInW.dwBufferTotal = lpBuffersIn->dwBufferTotal;
|
|
|
|
BuffersInW.Next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = HttpSendRequestExW(hRequest, lpBuffersIn ? &BuffersInW : NULL, NULL, dwFlags, dwContext);
|
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(header);
|
2009-11-30 20:01:17 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpSendRequestExW (WININET.@)
|
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server and allows chunked
|
|
|
|
* transfers
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE, call GetLastError() for more information.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestExW(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSW lpBuffersIn,
|
|
|
|
LPINTERNET_BUFFERSW lpBuffersOut,
|
|
|
|
DWORD dwFlags, DWORD_PTR dwContext)
|
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_request_t *request;
|
|
|
|
http_session_t *session;
|
2009-11-30 20:01:17 +01:00
|
|
|
appinfo_t *hIC;
|
2009-12-03 14:48:54 +01:00
|
|
|
DWORD res;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %08x, %08lx)\n", hRequest, lpBuffersIn,
|
|
|
|
lpBuffersOut, dwFlags, dwContext);
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
request = (http_request_t*) get_handle_object( hRequest );
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
if (NULL == request || request->hdr.htype != WH_HHTTPREQ)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
2009-12-03 14:48:54 +01:00
|
|
|
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
|
2009-11-30 20:01:17 +01:00
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
session = request->session;
|
2011-03-01 19:59:39 +01:00
|
|
|
assert(session->hdr.htype == WH_HHTTPSESSION);
|
2011-03-01 20:02:14 +01:00
|
|
|
hIC = session->appInfo;
|
2009-11-30 20:01:17 +01:00
|
|
|
assert(hIC->hdr.htype == WH_HINIT);
|
|
|
|
|
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
2013-01-28 11:23:19 +01:00
|
|
|
send_request_task_t *task;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-28 11:23:03 +01:00
|
|
|
task = alloc_async_task(&request->hdr, AsyncHttpSendRequestProc, sizeof(*task));
|
2009-11-30 20:01:17 +01:00
|
|
|
if (lpBuffersIn)
|
|
|
|
{
|
|
|
|
DWORD size = 0;
|
|
|
|
|
|
|
|
if (lpBuffersIn->lpcszHeader)
|
|
|
|
{
|
|
|
|
if (lpBuffersIn->dwHeadersLength == ~0u)
|
|
|
|
size = (strlenW( lpBuffersIn->lpcszHeader ) + 1) * sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
size = lpBuffersIn->dwHeadersLength * sizeof(WCHAR);
|
|
|
|
|
2013-01-28 11:23:19 +01:00
|
|
|
task->headers = heap_alloc(size);
|
|
|
|
memcpy(task->headers, lpBuffersIn->lpcszHeader, size);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
2013-01-28 11:23:19 +01:00
|
|
|
else task->headers = NULL;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-28 11:23:19 +01:00
|
|
|
task->headers_len = size / sizeof(WCHAR);
|
|
|
|
task->optional = lpBuffersIn->lpvBuffer;
|
|
|
|
task->optional_len = lpBuffersIn->dwBufferLength;
|
|
|
|
task->content_len = lpBuffersIn->dwBufferTotal;
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-28 11:23:19 +01:00
|
|
|
task->headers = NULL;
|
|
|
|
task->headers_len = 0;
|
|
|
|
task->optional = NULL;
|
|
|
|
task->optional_len = 0;
|
|
|
|
task->content_len = 0;
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 11:23:19 +01:00
|
|
|
task->end_request = FALSE;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-28 11:23:19 +01:00
|
|
|
INTERNET_AsyncCall(&task->hdr);
|
2009-12-03 14:48:54 +01:00
|
|
|
res = ERROR_IO_PENDING;
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lpBuffersIn)
|
2011-03-01 19:59:39 +01:00
|
|
|
res = HTTP_HttpSendRequestW(request, lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength,
|
2009-11-30 20:01:17 +01:00
|
|
|
lpBuffersIn->lpvBuffer, lpBuffersIn->dwBufferLength,
|
|
|
|
lpBuffersIn->dwBufferTotal, FALSE);
|
|
|
|
else
|
2011-03-01 19:59:39 +01:00
|
|
|
res = HTTP_HttpSendRequestW(request, NULL, 0, NULL, 0, 0, FALSE);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
2011-03-01 19:59:39 +01:00
|
|
|
if ( request )
|
|
|
|
WININET_Release( &request->hdr );
|
2009-11-30 20:01:17 +01:00
|
|
|
|
|
|
|
TRACE("<---\n");
|
2009-12-21 11:13:44 +01:00
|
|
|
SetLastError(res);
|
2009-12-03 14:48:54 +01:00
|
|
|
return res == ERROR_SUCCESS;
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpSendRequestW (WININET.@)
|
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders,
|
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
|
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_request_t *request;
|
|
|
|
http_session_t *session = NULL;
|
2009-11-30 20:01:17 +01:00
|
|
|
appinfo_t *hIC = NULL;
|
|
|
|
DWORD res = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %i, %p, %i)\n", hHttpRequest,
|
|
|
|
debugstr_wn(lpszHeaders, dwHeaderLength), dwHeaderLength, lpOptional, dwOptionalLength);
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
request = (http_request_t*) get_handle_object( hHttpRequest );
|
|
|
|
if (NULL == request || request->hdr.htype != WH_HHTTPREQ)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
|
|
|
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
session = request->session;
|
2011-03-01 19:59:39 +01:00
|
|
|
if (NULL == session || session->hdr.htype != WH_HHTTPSESSION)
|
2009-11-30 20:01:17 +01:00
|
|
|
{
|
|
|
|
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2011-03-01 20:02:14 +01:00
|
|
|
hIC = session->appInfo;
|
2009-11-30 20:01:17 +01:00
|
|
|
if (NULL == hIC || hIC->hdr.htype != WH_HINIT)
|
|
|
|
{
|
|
|
|
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
2013-01-28 11:23:19 +01:00
|
|
|
send_request_task_t *task;
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2013-01-28 11:23:03 +01:00
|
|
|
task = alloc_async_task(&request->hdr, AsyncHttpSendRequestProc, sizeof(*task));
|
2009-11-30 20:01:17 +01:00
|
|
|
if (lpszHeaders)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
if (dwHeaderLength == ~0u) size = (strlenW(lpszHeaders) + 1) * sizeof(WCHAR);
|
|
|
|
else size = dwHeaderLength * sizeof(WCHAR);
|
|
|
|
|
2013-01-28 11:23:19 +01:00
|
|
|
task->headers = heap_alloc(size);
|
|
|
|
memcpy(task->headers, lpszHeaders, size);
|
2009-11-30 20:01:17 +01:00
|
|
|
}
|
|
|
|
else
|
2013-01-28 11:23:19 +01:00
|
|
|
task->headers = NULL;
|
|
|
|
task->headers_len = dwHeaderLength;
|
|
|
|
task->optional = lpOptional;
|
|
|
|
task->optional_len = dwOptionalLength;
|
|
|
|
task->content_len = dwOptionalLength;
|
|
|
|
task->end_request = TRUE;
|
|
|
|
|
|
|
|
INTERNET_AsyncCall(&task->hdr);
|
2009-11-30 20:01:17 +01:00
|
|
|
res = ERROR_IO_PENDING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
res = HTTP_HttpSendRequestW(request, lpszHeaders,
|
2009-11-30 20:01:17 +01:00
|
|
|
dwHeaderLength, lpOptional, dwOptionalLength,
|
|
|
|
dwOptionalLength, TRUE);
|
|
|
|
}
|
|
|
|
lend:
|
2011-03-01 19:59:39 +01:00
|
|
|
if( request )
|
|
|
|
WININET_Release( &request->hdr );
|
2009-11-30 20:01:17 +01:00
|
|
|
|
2009-12-21 11:13:44 +01:00
|
|
|
SetLastError(res);
|
2009-11-30 20:01:17 +01:00
|
|
|
return res == ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpSendRequestA (WININET.@)
|
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders,
|
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
LPWSTR szHeaders=NULL;
|
|
|
|
DWORD nLen=dwHeaderLength;
|
|
|
|
if(lpszHeaders!=NULL)
|
|
|
|
{
|
|
|
|
nLen=MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,NULL,0);
|
2011-04-21 13:39:03 +02:00
|
|
|
szHeaders = heap_alloc(nLen*sizeof(WCHAR));
|
2009-11-30 20:01:17 +01:00
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,szHeaders,nLen);
|
|
|
|
}
|
2011-06-01 11:50:53 +02:00
|
|
|
result = HttpSendRequestW(hHttpRequest, szHeaders, nLen, lpOptional, dwOptionalLength);
|
|
|
|
heap_free(szHeaders);
|
2009-11-30 20:01:17 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-02-26 20:20:41 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTPSESSION_Destroy (internal)
|
|
|
|
*
|
|
|
|
* Deallocate session handle
|
|
|
|
*
|
|
|
|
*/
|
2009-07-07 21:46:09 +02:00
|
|
|
static void HTTPSESSION_Destroy(object_header_t *hdr)
|
2008-02-26 20:20:41 +01:00
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_session_t *session = (http_session_t*) hdr;
|
2008-02-26 20:20:41 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
TRACE("%p\n", session);
|
2008-02-26 20:20:41 +01:00
|
|
|
|
2011-03-01 20:02:14 +01:00
|
|
|
WININET_Release(&session->appInfo->hdr);
|
2008-02-26 20:20:41 +01:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(session->hostName);
|
|
|
|
heap_free(session->password);
|
|
|
|
heap_free(session->userName);
|
2008-02-26 20:20:41 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD HTTPSESSION_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
|
2008-03-12 02:23:20 +01:00
|
|
|
{
|
2012-01-13 15:15:20 +01:00
|
|
|
http_session_t *ses = (http_session_t *)hdr;
|
|
|
|
|
2008-03-12 02:23:20 +01:00
|
|
|
switch(option) {
|
|
|
|
case INTERNET_OPTION_HANDLE_TYPE:
|
|
|
|
TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(ULONG))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD*)buffer = INTERNET_HANDLE_TYPE_CONNECT_HTTP;
|
|
|
|
return ERROR_SUCCESS;
|
2012-01-13 15:15:20 +01:00
|
|
|
case INTERNET_OPTION_CONNECT_TIMEOUT:
|
|
|
|
TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(DWORD))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD *)buffer = ses->connect_timeout;
|
|
|
|
return ERROR_SUCCESS;
|
2012-01-13 15:15:48 +01:00
|
|
|
|
|
|
|
case INTERNET_OPTION_SEND_TIMEOUT:
|
|
|
|
TRACE("INTERNET_OPTION_SEND_TIMEOUT\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(DWORD))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD *)buffer = ses->send_timeout;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case INTERNET_OPTION_RECEIVE_TIMEOUT:
|
|
|
|
TRACE("INTERNET_OPTION_RECEIVE_TIMEOUT\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(DWORD))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD *)buffer = ses->receive_timeout;
|
|
|
|
return ERROR_SUCCESS;
|
2008-03-12 02:23:20 +01:00
|
|
|
}
|
|
|
|
|
2010-05-25 12:19:32 +02:00
|
|
|
return INET_QueryOption(hdr, option, buffer, size, unicode);
|
2008-03-12 02:23:20 +01:00
|
|
|
}
|
2008-02-26 20:20:41 +01:00
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD HTTPSESSION_SetOption(object_header_t *hdr, DWORD option, void *buffer, DWORD size)
|
2008-09-24 16:54:37 +02:00
|
|
|
{
|
2009-07-13 01:41:18 +02:00
|
|
|
http_session_t *ses = (http_session_t*)hdr;
|
2008-09-24 16:54:37 +02:00
|
|
|
|
|
|
|
switch(option) {
|
|
|
|
case INTERNET_OPTION_USERNAME:
|
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(ses->userName);
|
2011-03-01 20:02:14 +01:00
|
|
|
if (!(ses->userName = heap_strdupW(buffer))) return ERROR_OUTOFMEMORY;
|
2008-09-24 16:54:37 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
case INTERNET_OPTION_PASSWORD:
|
|
|
|
{
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(ses->password);
|
2011-03-01 20:02:14 +01:00
|
|
|
if (!(ses->password = heap_strdupW(buffer))) return ERROR_OUTOFMEMORY;
|
2013-04-22 11:02:50 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
case INTERNET_OPTION_PROXY_USERNAME:
|
|
|
|
{
|
|
|
|
heap_free(ses->appInfo->proxyUsername);
|
|
|
|
if (!(ses->appInfo->proxyUsername = heap_strdupW(buffer))) return ERROR_OUTOFMEMORY;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
case INTERNET_OPTION_PROXY_PASSWORD:
|
|
|
|
{
|
|
|
|
heap_free(ses->appInfo->proxyPassword);
|
|
|
|
if (!(ses->appInfo->proxyPassword = heap_strdupW(buffer))) return ERROR_OUTOFMEMORY;
|
2008-09-24 16:54:37 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2012-01-13 15:15:20 +01:00
|
|
|
case INTERNET_OPTION_CONNECT_TIMEOUT:
|
|
|
|
{
|
2012-01-13 15:15:48 +01:00
|
|
|
if (!buffer || size != sizeof(DWORD)) return ERROR_INVALID_PARAMETER;
|
2012-01-13 15:15:20 +01:00
|
|
|
ses->connect_timeout = *(DWORD *)buffer;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2012-01-13 15:15:48 +01:00
|
|
|
case INTERNET_OPTION_SEND_TIMEOUT:
|
|
|
|
{
|
|
|
|
if (!buffer || size != sizeof(DWORD)) return ERROR_INVALID_PARAMETER;
|
|
|
|
ses->send_timeout = *(DWORD *)buffer;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
case INTERNET_OPTION_RECEIVE_TIMEOUT:
|
|
|
|
{
|
|
|
|
if (!buffer || size != sizeof(DWORD)) return ERROR_INVALID_PARAMETER;
|
|
|
|
ses->receive_timeout = *(DWORD *)buffer;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2008-09-24 16:54:37 +02:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2012-03-08 12:19:14 +01:00
|
|
|
return INET_SetOption(hdr, option, buffer, size);
|
2008-09-24 16:54:37 +02:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static const object_vtbl_t HTTPSESSIONVtbl = {
|
2008-02-26 20:21:00 +01:00
|
|
|
HTTPSESSION_Destroy,
|
2008-02-26 20:21:34 +01:00
|
|
|
NULL,
|
2008-03-12 02:23:20 +01:00
|
|
|
HTTPSESSION_QueryOption,
|
2008-09-24 16:54:37 +02:00
|
|
|
HTTPSESSION_SetOption,
|
2008-02-27 18:55:09 +01:00
|
|
|
NULL,
|
2008-02-29 12:57:57 +01:00
|
|
|
NULL,
|
2008-03-02 19:35:11 +01:00
|
|
|
NULL,
|
2008-02-26 20:21:00 +01:00
|
|
|
NULL
|
2008-02-26 20:20:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_Connect (internal)
|
|
|
|
*
|
|
|
|
* Create http session handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a session handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-12-21 13:58:53 +01:00
|
|
|
DWORD HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
|
2011-03-01 20:02:14 +01:00
|
|
|
INTERNET_PORT serverPort, LPCWSTR lpszUserName,
|
2009-12-21 13:58:53 +01:00
|
|
|
LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
|
|
|
|
DWORD dwInternalFlags, HINTERNET *ret)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
http_session_t *session = NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
TRACE("-->\n");
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2008-01-31 15:47:25 +01:00
|
|
|
if (!lpszServerName || !lpszServerName[0])
|
2009-12-21 13:58:53 +01:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
2008-01-31 15:47:25 +01:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
assert( hIC->hdr.htype == WH_HINIT );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
session = alloc_object(&hIC->hdr, &HTTPSESSIONVtbl, sizeof(http_session_t));
|
|
|
|
if (!session)
|
2009-12-21 13:58:53 +01:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
/*
|
|
|
|
* According to my tests. The name is not resolved until a request is sent
|
|
|
|
*/
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
session->hdr.htype = WH_HHTTPSESSION;
|
|
|
|
session->hdr.dwFlags = dwFlags;
|
|
|
|
session->hdr.dwContext = dwContext;
|
|
|
|
session->hdr.dwInternalFlags |= dwInternalFlags;
|
2004-07-19 23:49:39 +02:00
|
|
|
|
2006-10-29 18:48:48 +01:00
|
|
|
WININET_AddRef( &hIC->hdr );
|
2011-03-01 20:02:14 +01:00
|
|
|
session->appInfo = hIC;
|
2011-03-01 19:59:39 +01:00
|
|
|
list_add_head( &hIC->hdr.children, &session->hdr.entry );
|
2006-10-29 18:48:48 +01:00
|
|
|
|
2011-03-01 20:02:14 +01:00
|
|
|
session->hostName = heap_strdupW(lpszServerName);
|
2006-03-10 13:28:52 +01:00
|
|
|
if (lpszUserName && lpszUserName[0])
|
2011-03-01 20:02:14 +01:00
|
|
|
session->userName = heap_strdupW(lpszUserName);
|
2007-05-21 15:26:26 +02:00
|
|
|
if (lpszPassword && lpszPassword[0])
|
2011-03-01 20:02:14 +01:00
|
|
|
session->password = heap_strdupW(lpszPassword);
|
|
|
|
session->hostPort = serverPort;
|
2012-05-14 13:49:29 +02:00
|
|
|
session->connect_timeout = hIC->connect_timeout;
|
2015-04-24 14:39:29 +02:00
|
|
|
session->send_timeout = 0;
|
|
|
|
session->receive_timeout = 0;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-05-13 07:17:25 +02:00
|
|
|
/* Don't send a handle created callback if this handle was created with InternetOpenUrl */
|
2011-03-01 19:59:39 +01:00
|
|
|
if (!(session->hdr.dwInternalFlags & INET_OPENURL))
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&hIC->hdr, dwContext,
|
2011-03-01 19:59:39 +01:00
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &session->hdr.hInternet,
|
2011-02-02 22:51:13 +01:00
|
|
|
sizeof(HINTERNET));
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
/*
|
2005-03-23 14:15:18 +01:00
|
|
|
* an INTERNET_STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on
|
2002-06-22 01:59:49 +02:00
|
|
|
* windows
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
TRACE("%p --> %p\n", hIC, session);
|
2009-12-21 13:58:53 +01:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
*ret = session->hdr.hInternet;
|
2011-02-02 22:51:13 +01:00
|
|
|
return ERROR_SUCCESS;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2004-07-15 20:57:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_clear_response_headers (internal)
|
|
|
|
*
|
|
|
|
* clear out any old response headers
|
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static void HTTP_clear_response_headers( http_request_t *request )
|
2004-07-15 20:57:32 +02:00
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
for( i=0; i<request->nCustHeaders; i++)
|
2004-07-15 20:57:32 +02:00
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
if( !request->custHeaders[i].lpszField )
|
2004-07-15 20:57:32 +02:00
|
|
|
continue;
|
2011-03-01 20:18:22 +01:00
|
|
|
if( !request->custHeaders[i].lpszValue )
|
2004-07-15 20:57:32 +02:00
|
|
|
continue;
|
2011-03-01 20:18:22 +01:00
|
|
|
if ( request->custHeaders[i].wFlags & HDR_ISREQUEST )
|
2004-07-15 20:57:32 +02:00
|
|
|
continue;
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_DeleteCustomHeader( request, i );
|
2005-03-10 12:14:24 +01:00
|
|
|
i--;
|
2004-07-15 20:57:32 +02:00
|
|
|
}
|
2014-09-25 14:21:37 +02:00
|
|
|
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2004-07-15 20:57:32 +02:00
|
|
|
}
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetResponseHeaders (internal)
|
|
|
|
*
|
|
|
|
* Read server response
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on error
|
|
|
|
*/
|
2013-04-25 10:15:19 +02:00
|
|
|
static DWORD HTTP_GetResponseHeaders(http_request_t *request, INT *len)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
INT cbreaks = 0;
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR buffer[MAX_REPLY_LEN];
|
2000-06-11 22:04:44 +02:00
|
|
|
DWORD buflen = MAX_REPLY_LEN;
|
2002-06-22 01:59:49 +02:00
|
|
|
INT rc = 0;
|
2004-03-30 06:36:09 +02:00
|
|
|
char bufferA[MAX_REPLY_LEN];
|
2009-06-23 07:30:38 +02:00
|
|
|
LPWSTR status_code = NULL, status_text = NULL;
|
2013-04-30 17:00:18 +02:00
|
|
|
DWORD res = ERROR_HTTP_INVALID_SERVER_RESPONSE;
|
2009-06-23 07:30:38 +02:00
|
|
|
BOOL codeHundred = FALSE;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
TRACE("-->\n");
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2013-12-11 10:48:41 +01:00
|
|
|
if(!is_valid_netconn(request->netconn))
|
2000-06-11 22:04:44 +02:00
|
|
|
goto lend;
|
|
|
|
|
2013-04-25 10:14:21 +02:00
|
|
|
/* clear old response headers (eg. from a redirect response) */
|
|
|
|
HTTP_clear_response_headers( request );
|
|
|
|
|
2012-01-13 15:15:48 +01:00
|
|
|
NETCON_set_timeout( request->netconn, FALSE, request->receive_timeout );
|
2008-02-17 20:41:56 +01:00
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* We should first receive 'HTTP/1.x nnn OK' where nnn is the status code.
|
|
|
|
*/
|
2009-03-04 12:42:43 +01:00
|
|
|
buflen = MAX_REPLY_LEN;
|
2013-04-25 10:15:19 +02:00
|
|
|
if ((res = read_line(request, bufferA, &buflen)))
|
2008-02-17 20:41:56 +01:00
|
|
|
goto lend;
|
2010-06-29 12:20:51 +02:00
|
|
|
|
2013-04-25 10:15:19 +02:00
|
|
|
if (!buflen) goto lend;
|
|
|
|
|
2009-03-04 12:42:43 +01:00
|
|
|
rc += buflen;
|
2008-02-17 20:41:56 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
|
2009-06-23 07:30:38 +02:00
|
|
|
/* check is this a status code line? */
|
|
|
|
if (!strncmpW(buffer, g_szHttp1_0, 4))
|
|
|
|
{
|
|
|
|
/* split the version from the status code */
|
|
|
|
status_code = strchrW( buffer, ' ' );
|
|
|
|
if( !status_code )
|
|
|
|
goto lend;
|
|
|
|
*status_code++=0;
|
2008-02-17 20:41:56 +01:00
|
|
|
|
2009-06-23 07:30:38 +02:00
|
|
|
/* split the status code from the status text */
|
|
|
|
status_text = strchrW( status_code, ' ' );
|
2013-07-19 12:02:18 +02:00
|
|
|
if( status_text )
|
|
|
|
*status_text++=0;
|
2008-02-17 20:41:56 +01:00
|
|
|
|
2012-05-03 12:19:47 +02:00
|
|
|
request->status_code = atoiW(status_code);
|
|
|
|
|
2009-06-23 07:30:38 +02:00
|
|
|
TRACE("version [%s] status code [%s] status text [%s]\n",
|
|
|
|
debugstr_w(buffer), debugstr_w(status_code), debugstr_w(status_text) );
|
2008-02-17 20:41:56 +01:00
|
|
|
|
2013-03-15 11:46:22 +01:00
|
|
|
codeHundred = request->status_code == HTTP_STATUS_CONTINUE;
|
2009-06-23 07:30:38 +02:00
|
|
|
}
|
|
|
|
else if (!codeHundred)
|
|
|
|
{
|
2010-02-22 12:28:03 +01:00
|
|
|
WARN("No status line at head of response (%s)\n", debugstr_w(buffer));
|
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(request->version);
|
|
|
|
heap_free(request->statusText);
|
2010-02-22 12:28:03 +01:00
|
|
|
|
2012-05-03 12:20:38 +02:00
|
|
|
request->status_code = HTTP_STATUS_OK;
|
2011-03-01 20:18:22 +01:00
|
|
|
request->version = heap_strdupW(g_szHttp1_0);
|
|
|
|
request->statusText = heap_strdupW(szOK);
|
2010-02-22 12:28:03 +01:00
|
|
|
|
2009-09-29 21:50:12 +02:00
|
|
|
goto lend;
|
2009-06-23 07:30:38 +02:00
|
|
|
}
|
|
|
|
} while (codeHundred);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2008-02-25 20:05:41 +01:00
|
|
|
/* Add status code */
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_ProcessHeader(request, szStatus, status_code,
|
2015-06-25 12:28:02 +02:00
|
|
|
HTTP_ADDHDR_FLAG_REPLACE | HTTP_ADDHDR_FLAG_ADD);
|
2008-02-25 20:05:41 +01:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(request->version);
|
|
|
|
heap_free(request->statusText);
|
2008-02-25 20:05:41 +01:00
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
request->version = heap_strdupW(buffer);
|
2013-07-19 12:02:18 +02:00
|
|
|
request->statusText = heap_strdupW(status_text ? status_text : emptyW);
|
2008-02-25 20:05:41 +01:00
|
|
|
|
|
|
|
/* Restore the spaces */
|
|
|
|
*(status_code-1) = ' ';
|
2013-07-19 12:02:18 +02:00
|
|
|
if (status_text)
|
|
|
|
*(status_text-1) = ' ';
|
2008-02-25 20:05:41 +01:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/* Parse each response line */
|
|
|
|
do
|
|
|
|
{
|
2013-04-30 17:00:18 +02:00
|
|
|
buflen = MAX_REPLY_LEN;
|
2013-04-25 10:15:19 +02:00
|
|
|
if (!read_line(request, bufferA, &buflen) && buflen)
|
2004-09-24 00:53:50 +02:00
|
|
|
{
|
|
|
|
LPWSTR * pFieldAndValue;
|
|
|
|
|
2005-01-26 22:09:04 +01:00
|
|
|
TRACE("got line %s, now interpreting\n", debugstr_a(bufferA));
|
2009-03-04 12:44:22 +01:00
|
|
|
|
|
|
|
if (!bufferA[0]) break;
|
2004-03-30 06:36:09 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
|
2004-07-19 22:09:20 +02:00
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
pFieldAndValue = HTTP_InterpretHttpHeader(buffer);
|
2009-06-04 16:52:59 +02:00
|
|
|
if (pFieldAndValue)
|
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_ProcessHeader(request, pFieldAndValue[0], pFieldAndValue[1],
|
2009-06-04 16:52:59 +02:00
|
|
|
HTTP_ADDREQ_FLAG_ADD );
|
|
|
|
HTTP_FreeTokens(pFieldAndValue);
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 17:00:18 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cbreaks++;
|
|
|
|
if (cbreaks >= 2)
|
|
|
|
break;
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
}while(1);
|
|
|
|
|
2013-04-25 10:15:19 +02:00
|
|
|
res = ERROR_SUCCESS;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
lend:
|
|
|
|
|
2013-04-25 10:15:19 +02:00
|
|
|
*len = rc;
|
2002-06-22 01:59:49 +02:00
|
|
|
TRACE("<--\n");
|
2013-04-25 10:15:19 +02:00
|
|
|
return res;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_InterpretHttpHeader (internal)
|
|
|
|
*
|
|
|
|
* Parse server response
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
2004-09-24 00:53:50 +02:00
|
|
|
* Pointer to array of field, value, NULL on success.
|
|
|
|
* NULL on error.
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2005-10-26 12:07:58 +02:00
|
|
|
static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-09-24 00:53:50 +02:00
|
|
|
LPWSTR * pTokenPair;
|
|
|
|
LPWSTR pszColon;
|
|
|
|
INT len;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-04-21 13:39:03 +02:00
|
|
|
pTokenPair = heap_alloc_zero(sizeof(*pTokenPair)*3);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
pszColon = strchrW(buffer, ':');
|
|
|
|
/* must have two tokens */
|
|
|
|
if (!pszColon)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-09-24 00:53:50 +02:00
|
|
|
HTTP_FreeTokens(pTokenPair);
|
2005-03-10 12:14:24 +01:00
|
|
|
if (buffer[0])
|
|
|
|
TRACE("No ':' in line: %s\n", debugstr_w(buffer));
|
2004-09-24 00:53:50 +02:00
|
|
|
return NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2011-04-21 13:39:03 +02:00
|
|
|
pTokenPair[0] = heap_alloc((pszColon - buffer + 1) * sizeof(WCHAR));
|
2004-09-24 00:53:50 +02:00
|
|
|
if (!pTokenPair[0])
|
|
|
|
{
|
|
|
|
HTTP_FreeTokens(pTokenPair);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy(pTokenPair[0], buffer, (pszColon - buffer) * sizeof(WCHAR));
|
|
|
|
pTokenPair[0][pszColon - buffer] = '\0';
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
/* skip colon */
|
|
|
|
pszColon++;
|
|
|
|
len = strlenW(pszColon);
|
2011-04-21 13:39:03 +02:00
|
|
|
pTokenPair[1] = heap_alloc((len + 1) * sizeof(WCHAR));
|
2004-09-24 00:53:50 +02:00
|
|
|
if (!pTokenPair[1])
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-09-24 00:53:50 +02:00
|
|
|
HTTP_FreeTokens(pTokenPair);
|
|
|
|
return NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2004-09-24 00:53:50 +02:00
|
|
|
memcpy(pTokenPair[1], pszColon, (len + 1) * sizeof(WCHAR));
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
strip_spaces(pTokenPair[0]);
|
|
|
|
strip_spaces(pTokenPair[1]);
|
|
|
|
|
|
|
|
TRACE("field(%s) Value(%s)\n", debugstr_w(pTokenPair[0]), debugstr_w(pTokenPair[1]));
|
|
|
|
return pTokenPair;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_ProcessHeader (internal)
|
|
|
|
*
|
|
|
|
* Stuff header into header tables according to <dwModifier>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-11-07 23:45:06 +01:00
|
|
|
#define COALESCEFLAGS (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
static DWORD HTTP_ProcessHeader(http_request_t *request, LPCWSTR field, LPCWSTR value, DWORD dwModifier)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPHTTPHEADERW lphttpHdr = NULL;
|
2014-09-25 14:21:37 +02:00
|
|
|
INT index;
|
2015-05-13 16:55:27 +02:00
|
|
|
BOOL request_only = !!(dwModifier & HTTP_ADDHDR_FLAG_REQ);
|
2009-11-30 20:01:00 +01:00
|
|
|
DWORD res = ERROR_HTTP_INVALID_HEADER;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("--> %s: %s - 0x%08x\n", debugstr_w(field), debugstr_w(value), dwModifier);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
EnterCriticalSection( &request->headers_section );
|
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
/* REPLACE wins out over ADD */
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE)
|
|
|
|
dwModifier &= ~HTTP_ADDHDR_FLAG_ADD;
|
|
|
|
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_ADD)
|
|
|
|
index = -1;
|
|
|
|
else
|
2011-03-01 19:59:39 +01:00
|
|
|
index = HTTP_GetCustomHeaderIndex(request, field, 0, request_only);
|
2005-12-13 17:07:41 +01:00
|
|
|
|
|
|
|
if (index >= 0)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_ADD_IF_NEW)
|
2014-09-25 14:21:37 +02:00
|
|
|
{
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-11-30 20:01:00 +01:00
|
|
|
return ERROR_HTTP_INVALID_HEADER;
|
2014-09-25 14:21:37 +02:00
|
|
|
}
|
2011-03-01 20:18:22 +01:00
|
|
|
lphttpHdr = &request->custHeaders[index];
|
2005-12-13 17:07:41 +01:00
|
|
|
}
|
|
|
|
else if (value)
|
|
|
|
{
|
|
|
|
HTTPHEADERW hdr;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
hdr.lpszField = (LPWSTR)field;
|
|
|
|
hdr.lpszValue = (LPWSTR)value;
|
|
|
|
hdr.wFlags = hdr.wCount = 0;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
hdr.wFlags |= HDR_ISREQUEST;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
res = HTTP_InsertCustomHeader(request, &hdr);
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
|
|
|
return res;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2007-01-13 02:16:49 +01:00
|
|
|
/* no value to delete */
|
2014-09-25 14:21:37 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
2005-12-13 17:07:41 +01:00
|
|
|
lphttpHdr->wFlags |= HDR_ISREQUEST;
|
2000-06-11 22:04:44 +02:00
|
|
|
else
|
|
|
|
lphttpHdr->wFlags &= ~HDR_ISREQUEST;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
HTTP_DeleteCustomHeader( request, index );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2013-08-29 15:26:18 +02:00
|
|
|
if (value && value[0])
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
HTTPHEADERW hdr;
|
|
|
|
|
|
|
|
hdr.lpszField = (LPWSTR)field;
|
|
|
|
hdr.lpszValue = (LPWSTR)value;
|
|
|
|
hdr.wFlags = hdr.wCount = 0;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
2005-12-13 17:07:41 +01:00
|
|
|
hdr.wFlags |= HDR_ISREQUEST;
|
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
res = HTTP_InsertCustomHeader(request, &hdr);
|
|
|
|
LeaveCriticalSection( &request->headers_section );
|
|
|
|
return res;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-11-30 20:01:00 +01:00
|
|
|
return ERROR_SUCCESS;
|
2005-12-13 17:07:41 +01:00
|
|
|
}
|
2007-11-07 23:45:06 +01:00
|
|
|
else if (dwModifier & COALESCEFLAGS)
|
2005-12-13 17:07:41 +01:00
|
|
|
{
|
|
|
|
LPWSTR lpsztmp;
|
|
|
|
WCHAR ch = 0;
|
|
|
|
INT len = 0;
|
|
|
|
INT origlen = strlenW(lphttpHdr->lpszValue);
|
|
|
|
INT valuelen = strlenW(value);
|
|
|
|
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
ch = ',';
|
|
|
|
lphttpHdr->wFlags |= HDR_COMMADELIMITED;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2005-12-13 17:07:41 +01:00
|
|
|
else if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
ch = ';';
|
|
|
|
lphttpHdr->wFlags |= HDR_COMMADELIMITED;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
len = origlen + valuelen + ((ch > 0) ? 2 : 0);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-04-22 12:35:05 +02:00
|
|
|
lpsztmp = heap_realloc(lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR));
|
2005-12-13 17:07:41 +01:00
|
|
|
if (lpsztmp)
|
|
|
|
{
|
|
|
|
lphttpHdr->lpszValue = lpsztmp;
|
|
|
|
/* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */
|
|
|
|
if (ch > 0)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
lphttpHdr->lpszValue[origlen] = ch;
|
|
|
|
origlen++;
|
|
|
|
lphttpHdr->lpszValue[origlen] = ' ';
|
|
|
|
origlen++;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2005-12-13 17:07:41 +01:00
|
|
|
|
|
|
|
memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR));
|
|
|
|
lphttpHdr->lpszValue[len] = '\0';
|
2009-11-30 20:01:00 +01:00
|
|
|
res = ERROR_SUCCESS;
|
2005-12-13 17:07:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-22 12:35:05 +02:00
|
|
|
WARN("heap_realloc (%d bytes) failed\n",len+1);
|
2009-11-30 20:01:00 +01:00
|
|
|
res = ERROR_OUTOFMEMORY;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
}
|
2009-11-30 20:01:00 +01:00
|
|
|
TRACE("<-- %d\n", res);
|
2014-09-25 14:21:37 +02:00
|
|
|
LeaveCriticalSection( &request->headers_section );
|
2009-11-30 20:01:00 +01:00
|
|
|
return res;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetCustomHeaderIndex (internal)
|
|
|
|
*
|
|
|
|
* Return index of custom header from header array
|
2014-09-25 14:21:37 +02:00
|
|
|
* Headers section must be held
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static INT HTTP_GetCustomHeaderIndex(http_request_t *request, LPCWSTR lpszField,
|
2006-03-30 11:20:04 +02:00
|
|
|
int requested_index, BOOL request_only)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD index;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2009-12-04 23:37:46 +01:00
|
|
|
TRACE("%s, %d, %d\n", debugstr_w(lpszField), requested_index, request_only);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
for (index = 0; index < request->nCustHeaders; index++)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2011-03-01 20:18:22 +01:00
|
|
|
if (strcmpiW(request->custHeaders[index].lpszField, lpszField))
|
2006-03-30 11:20:04 +02:00
|
|
|
continue;
|
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
if (request_only && !(request->custHeaders[index].wFlags & HDR_ISREQUEST))
|
2006-03-30 11:20:04 +02:00
|
|
|
continue;
|
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
if (!request_only && (request->custHeaders[index].wFlags & HDR_ISREQUEST))
|
2005-12-13 17:07:41 +01:00
|
|
|
continue;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
if (requested_index == 0)
|
2006-03-30 11:20:04 +02:00
|
|
|
break;
|
|
|
|
requested_index --;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2011-03-01 19:59:39 +01:00
|
|
|
if (index >= request->nCustHeaders)
|
2000-06-11 22:04:44 +02:00
|
|
|
index = -1;
|
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("Return: %d\n", index);
|
2000-06-11 22:04:44 +02:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_InsertCustomHeader (internal)
|
|
|
|
*
|
|
|
|
* Insert header into array
|
2014-09-25 14:21:37 +02:00
|
|
|
* Headers section must be held
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static DWORD HTTP_InsertCustomHeader(http_request_t *request, LPHTTPHEADERW lpHdr)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
INT count;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPHTTPHEADERW lph = NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("--> %s: %s\n", debugstr_w(lpHdr->lpszField), debugstr_w(lpHdr->lpszValue));
|
2011-03-01 19:59:39 +01:00
|
|
|
count = request->nCustHeaders + 1;
|
2000-06-11 22:04:44 +02:00
|
|
|
if (count > 1)
|
2011-04-22 12:35:05 +02:00
|
|
|
lph = heap_realloc_zero(request->custHeaders, sizeof(HTTPHEADERW) * count);
|
2000-06-11 22:04:44 +02:00
|
|
|
else
|
2011-04-21 13:39:03 +02:00
|
|
|
lph = heap_alloc_zero(sizeof(HTTPHEADERW) * count);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2009-11-30 20:01:00 +01:00
|
|
|
if (!lph)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
request->custHeaders = lph;
|
|
|
|
request->custHeaders[count-1].lpszField = heap_strdupW(lpHdr->lpszField);
|
|
|
|
request->custHeaders[count-1].lpszValue = heap_strdupW(lpHdr->lpszValue);
|
|
|
|
request->custHeaders[count-1].wFlags = lpHdr->wFlags;
|
|
|
|
request->custHeaders[count-1].wCount= lpHdr->wCount;
|
2011-03-01 19:59:39 +01:00
|
|
|
request->nCustHeaders++;
|
2009-11-30 20:01:00 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_DeleteCustomHeader (internal)
|
|
|
|
*
|
|
|
|
* Delete header from array
|
2014-09-25 14:21:37 +02:00
|
|
|
* If this function is called, the index may change.
|
|
|
|
* Headers section must be held
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2011-03-01 19:59:39 +01:00
|
|
|
static BOOL HTTP_DeleteCustomHeader(http_request_t *request, DWORD index)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2011-03-01 19:59:39 +01:00
|
|
|
if( request->nCustHeaders <= 0 )
|
2003-07-22 05:17:52 +02:00
|
|
|
return FALSE;
|
2011-03-01 19:59:39 +01:00
|
|
|
if( index >= request->nCustHeaders )
|
2003-07-22 05:17:52 +02:00
|
|
|
return FALSE;
|
2011-03-01 19:59:39 +01:00
|
|
|
request->nCustHeaders--;
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2011-06-01 11:50:53 +02:00
|
|
|
heap_free(request->custHeaders[index].lpszField);
|
|
|
|
heap_free(request->custHeaders[index].lpszValue);
|
2008-06-20 11:14:38 +02:00
|
|
|
|
2011-03-01 20:18:22 +01:00
|
|
|
memmove( &request->custHeaders[index], &request->custHeaders[index+1],
|
2011-03-01 19:59:39 +01:00
|
|
|
(request->nCustHeaders - index)* sizeof(HTTPHEADERW) );
|
2011-03-01 20:18:22 +01:00
|
|
|
memset( &request->custHeaders[request->nCustHeaders], 0, sizeof(HTTPHEADERW) );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
return TRUE;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2002-11-13 05:08:26 +01:00
|
|
|
|
2007-07-26 15:59:00 +02:00
|
|
|
|
2002-11-13 05:08:26 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* IsHostInProxyBypassList (@)
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI IsHostInProxyBypassList(DWORD flags, LPCSTR szHost, DWORD length)
|
|
|
|
{
|
2006-10-05 13:18:56 +02:00
|
|
|
FIXME("STUB: flags=%d host=%s length=%d\n",flags,szHost,length);
|
2002-11-13 05:08:26 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|