2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2000-06-11 22:04:44 +02:00
|
|
|
* Wininet - Http Implementation
|
|
|
|
*
|
|
|
|
* 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
|
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"
|
2004-09-03 20:30:28 +02:00
|
|
|
#include "wine/port.h"
|
2000-06-23 17:47:14 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
#include <sys/types.h>
|
2000-06-23 17:47:14 +02:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
2006-01-05 14:37:06 +01:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
#endif
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-06-11 22:04:44 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2001-02-15 22:24:07 +01:00
|
|
|
#include <time.h>
|
2004-07-19 23:49:39 +02:00
|
|
|
#include <assert.h>
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2001-11-06 23:31:19 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wininet.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winerror.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"
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
#include "internet.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.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
|
|
|
|
2005-11-28 11:55:16 +01:00
|
|
|
static const WCHAR g_szHttp1_0[] = {' ','H','T','T','P','/','1','.','0',0 };
|
|
|
|
static const WCHAR g_szHttp1_1[] = {' ','H','T','T','P','/','1','.','1',0 };
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR g_szReferer[] = {'R','e','f','e','r','e','r',0};
|
|
|
|
static const WCHAR g_szAccept[] = {'A','c','c','e','p','t',0};
|
|
|
|
static const WCHAR g_szUserAgent[] = {'U','s','e','r','-','A','g','e','n','t',0};
|
2005-12-13 17:07:41 +01:00
|
|
|
static const WCHAR szHost[] = { 'H','o','s','t',0 };
|
|
|
|
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 };
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
#define MAXHOSTNAME 100
|
|
|
|
#define MAX_FIELD_VALUE_LEN 256
|
|
|
|
#define MAX_FIELD_LEN 256
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
#define HTTP_REFERER g_szReferer
|
|
|
|
#define HTTP_ACCEPT g_szAccept
|
|
|
|
#define HTTP_USERAGENT g_szUserAgent
|
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
|
|
|
|
|
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr);
|
|
|
|
static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr);
|
2005-10-26 12:07:58 +02:00
|
|
|
static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr);
|
|
|
|
static BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr);
|
|
|
|
static BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier);
|
|
|
|
static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer);
|
|
|
|
static BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr);
|
2005-12-13 17:07:41 +01:00
|
|
|
static INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField, INT index, BOOL Request);
|
2005-10-26 12:07:58 +02:00
|
|
|
static BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, DWORD index);
|
2005-11-21 16:17:55 +01:00
|
|
|
static LPWSTR HTTP_build_req( LPCWSTR *list, int len );
|
|
|
|
static BOOL HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr,
|
|
|
|
LPCWSTR username, LPCWSTR password );
|
2005-11-28 17:31:02 +01:00
|
|
|
static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD
|
|
|
|
dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD
|
|
|
|
lpdwIndex);
|
|
|
|
static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl,
|
|
|
|
LPCWSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD
|
2005-11-30 12:31:22 +01:00
|
|
|
dwOptionalLength, DWORD dwContentLength);
|
2005-12-13 17:07:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW req, LPCWSTR head)
|
|
|
|
{
|
|
|
|
int HeaderIndex = 0;
|
|
|
|
HeaderIndex = HTTP_GetCustomHeaderIndex(req, head, 0, TRUE);
|
|
|
|
if (HeaderIndex == -1)
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return &req->pCustHeaders[HeaderIndex];
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-19 22:09:20 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_Tokenize (internal)
|
|
|
|
*
|
|
|
|
* Tokenize a string, allocating memory for the tokens.
|
|
|
|
*/
|
|
|
|
static LPWSTR * HTTP_Tokenize(LPCWSTR string, LPCWSTR token_string)
|
|
|
|
{
|
|
|
|
LPWSTR * token_array;
|
|
|
|
int tokens = 0;
|
|
|
|
int i;
|
|
|
|
LPCWSTR next_token;
|
|
|
|
|
|
|
|
/* empty string has no tokens */
|
|
|
|
if (*string)
|
|
|
|
tokens++;
|
|
|
|
/* count tokens */
|
|
|
|
for (i = 0; string[i]; i++)
|
|
|
|
if (!strncmpW(string+i, token_string, strlenW(token_string)))
|
|
|
|
{
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD j;
|
2004-07-19 22:09:20 +02:00
|
|
|
tokens++;
|
|
|
|
/* we want to skip over separators, but not the null terminator */
|
|
|
|
for (j = 0; j < strlenW(token_string) - 1; j++)
|
|
|
|
if (!string[i+j])
|
|
|
|
break;
|
|
|
|
i += j;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add 1 for terminating NULL */
|
|
|
|
token_array = HeapAlloc(GetProcessHeap(), 0, (tokens+1) * sizeof(*token_array));
|
|
|
|
token_array[tokens] = NULL;
|
|
|
|
if (!tokens)
|
|
|
|
return token_array;
|
|
|
|
for (i = 0; i < tokens; i++)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
next_token = strstrW(string, token_string);
|
|
|
|
if (!next_token) next_token = string+strlenW(string);
|
|
|
|
len = next_token - string;
|
|
|
|
token_array[i] = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
|
|
|
|
memcpy(token_array[i], string, len*sizeof(WCHAR));
|
|
|
|
token_array[i][len] = '\0';
|
|
|
|
string = next_token+strlenW(token_string);
|
|
|
|
}
|
|
|
|
return token_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_FreeTokens (internal)
|
|
|
|
*
|
|
|
|
* Frees memory returned from HTTP_Tokenize.
|
|
|
|
*/
|
|
|
|
static void HTTP_FreeTokens(LPWSTR * token_array)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; token_array[i]; i++)
|
|
|
|
HeapFree(GetProcessHeap(), 0, token_array[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, token_array);
|
|
|
|
}
|
|
|
|
|
2005-11-21 16:17:55 +01:00
|
|
|
/* **********************************************************************
|
|
|
|
*
|
|
|
|
* Helper functions for the HttpSendRequest(Ex) functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void HTTP_FixVerb( LPWININETHTTPREQW lpwhr )
|
|
|
|
{
|
|
|
|
/* if the verb is NULL default to GET */
|
|
|
|
if (NULL == lpwhr->lpszVerb)
|
|
|
|
{
|
|
|
|
static const WCHAR szGET[] = { 'G','E','T', 0 };
|
|
|
|
lpwhr->lpszVerb = WININET_strdupW(szGET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HTTP_FixURL( LPWININETHTTPREQW lpwhr)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
if (NULL == lpwhr->lpszPath)
|
|
|
|
lpwhr->lpszPath = WININET_strdupW(szSlash);
|
|
|
|
else /* remove \r and \n*/
|
|
|
|
{
|
|
|
|
int nLen = strlenW(lpwhr->lpszPath);
|
|
|
|
while ((nLen >0 ) && ((lpwhr->lpszPath[nLen-1] == '\r')||(lpwhr->lpszPath[nLen-1] == '\n')))
|
|
|
|
{
|
|
|
|
nLen--;
|
|
|
|
lpwhr->lpszPath[nLen]='\0';
|
|
|
|
}
|
|
|
|
/* Replace '\' with '/' */
|
|
|
|
while (nLen>0) {
|
|
|
|
nLen--;
|
|
|
|
if (lpwhr->lpszPath[nLen] == '\\') lpwhr->lpszPath[nLen]='/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CSTR_EQUAL != CompareStringW( LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
|
|
|
|
lpwhr->lpszPath, strlenW(szHttp), szHttp, strlenW(szHttp) )
|
|
|
|
&& lpwhr->lpszPath[0] != '/') /* not an absolute path ?? --> fix it !! */
|
|
|
|
{
|
|
|
|
WCHAR *fixurl = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(strlenW(lpwhr->lpszPath) + 2)*sizeof(WCHAR));
|
|
|
|
*fixurl = '/';
|
|
|
|
strcpyW(fixurl + 1, lpwhr->lpszPath);
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpwhr->lpszPath );
|
|
|
|
lpwhr->lpszPath = fixurl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-28 11:55:16 +01:00
|
|
|
static LPWSTR HTTP_BuildHeaderRequestString( LPWININETHTTPREQW lpwhr, LPCWSTR verb, LPCWSTR path, BOOL http1_1 )
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
|
|
|
LPWSTR requestString;
|
|
|
|
DWORD len, n;
|
|
|
|
LPCWSTR *req;
|
|
|
|
INT i;
|
|
|
|
LPWSTR p;
|
|
|
|
|
|
|
|
static const WCHAR szSpace[] = { ' ',0 };
|
|
|
|
static const WCHAR szcrlf[] = {'\r','\n', 0};
|
|
|
|
static const WCHAR szColon[] = { ':',' ',0 };
|
|
|
|
static const WCHAR sztwocrlf[] = {'\r','\n','\r','\n', 0};
|
|
|
|
|
|
|
|
/* allocate space for an array of all the string pointers to be added */
|
2005-12-13 17:07:41 +01:00
|
|
|
len = (lpwhr->nCustHeaders)*4 + 9;
|
2005-11-21 16:17:55 +01:00
|
|
|
req = HeapAlloc( GetProcessHeap(), 0, len*sizeof(LPCWSTR) );
|
|
|
|
|
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;
|
|
|
|
req[n++] = http1_1 ? g_szHttp1_1 : g_szHttp1_0;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
|
|
|
/* Append custom request heades */
|
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
|
|
|
req[n++] = szcrlf;
|
|
|
|
req[n++] = lpwhr->pCustHeaders[i].lpszField;
|
|
|
|
req[n++] = szColon;
|
|
|
|
req[n++] = lpwhr->pCustHeaders[i].lpszValue;
|
|
|
|
|
|
|
|
TRACE("Adding custom header %s (%s)\n",
|
|
|
|
debugstr_w(lpwhr->pCustHeaders[i].lpszField),
|
|
|
|
debugstr_w(lpwhr->pCustHeaders[i].lpszValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( n >= len )
|
|
|
|
ERR("oops. buffer overrun\n");
|
|
|
|
|
|
|
|
req[n] = NULL;
|
|
|
|
requestString = HTTP_build_req( req, 4 );
|
|
|
|
HeapFree( GetProcessHeap(), 0, req );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set (header) termination string for request
|
|
|
|
* Make sure there's exactly two new lines at the end of the request
|
|
|
|
*/
|
|
|
|
p = &requestString[strlenW(requestString)-1];
|
|
|
|
while ( (*p == '\n') || (*p == '\r') )
|
|
|
|
p--;
|
|
|
|
strcpyW( p+1, sztwocrlf );
|
|
|
|
|
|
|
|
return requestString;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HTTP_ProcessHeaders( LPWININETHTTPREQW lpwhr )
|
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
static const WCHAR szSet_Cookie[] = { 'S','e','t','-','C','o','o','k','i','e',0 };
|
|
|
|
int HeaderIndex;
|
|
|
|
LPHTTPHEADERW setCookieHeader;
|
|
|
|
|
|
|
|
HeaderIndex = HTTP_GetCustomHeaderIndex(lpwhr, szSet_Cookie, 0, FALSE);
|
|
|
|
if (HeaderIndex == -1)
|
|
|
|
return;
|
|
|
|
setCookieHeader = &lpwhr->pCustHeaders[HeaderIndex];
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2005-11-28 11:24:41 +01:00
|
|
|
if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) && setCookieHeader->lpszValue)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
|
|
|
int nPosStart = 0, nPosEnd = 0, len;
|
|
|
|
static const WCHAR szFmt[] = { 'h','t','t','p',':','/','/','%','s','/',0};
|
|
|
|
|
|
|
|
while (setCookieHeader->lpszValue[nPosEnd] != '\0')
|
|
|
|
{
|
|
|
|
LPWSTR buf_cookie, cookie_name, cookie_data;
|
|
|
|
LPWSTR buf_url;
|
|
|
|
LPWSTR domain = NULL;
|
2005-12-13 17:07:41 +01:00
|
|
|
LPHTTPHEADERW Host;
|
|
|
|
|
2005-11-21 16:17:55 +01:00
|
|
|
int nEqualPos = 0;
|
|
|
|
while (setCookieHeader->lpszValue[nPosEnd] != ';' && setCookieHeader->lpszValue[nPosEnd] != ',' &&
|
|
|
|
setCookieHeader->lpszValue[nPosEnd] != '\0')
|
|
|
|
{
|
|
|
|
nPosEnd++;
|
|
|
|
}
|
|
|
|
if (setCookieHeader->lpszValue[nPosEnd] == ';')
|
|
|
|
{
|
|
|
|
/* fixme: not case sensitive, strcasestr is gnu only */
|
|
|
|
int nDomainPosEnd = 0;
|
|
|
|
int nDomainPosStart = 0, nDomainLength = 0;
|
|
|
|
static const WCHAR szDomain[] = {'d','o','m','a','i','n','=',0};
|
|
|
|
LPWSTR lpszDomain = strstrW(&setCookieHeader->lpszValue[nPosEnd], szDomain);
|
|
|
|
if (lpszDomain)
|
|
|
|
{ /* they have specified their own domain, lets use it */
|
|
|
|
while (lpszDomain[nDomainPosEnd] != ';' && lpszDomain[nDomainPosEnd] != ',' &&
|
|
|
|
lpszDomain[nDomainPosEnd] != '\0')
|
|
|
|
{
|
|
|
|
nDomainPosEnd++;
|
|
|
|
}
|
|
|
|
nDomainPosStart = strlenW(szDomain);
|
|
|
|
nDomainLength = (nDomainPosEnd - nDomainPosStart) + 1;
|
|
|
|
domain = HeapAlloc(GetProcessHeap(), 0, (nDomainLength + 1)*sizeof(WCHAR));
|
|
|
|
lstrcpynW(domain, &lpszDomain[nDomainPosStart], nDomainLength + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (setCookieHeader->lpszValue[nPosEnd] == '\0') break;
|
|
|
|
buf_cookie = HeapAlloc(GetProcessHeap(), 0, ((nPosEnd - nPosStart) + 1)*sizeof(WCHAR));
|
|
|
|
lstrcpynW(buf_cookie, &setCookieHeader->lpszValue[nPosStart], (nPosEnd - nPosStart) + 1);
|
|
|
|
TRACE("%s\n", debugstr_w(buf_cookie));
|
|
|
|
while (buf_cookie[nEqualPos] != '=' && buf_cookie[nEqualPos] != '\0')
|
|
|
|
{
|
|
|
|
nEqualPos++;
|
|
|
|
}
|
|
|
|
if (buf_cookie[nEqualPos] == '\0' || buf_cookie[nEqualPos + 1] == '\0')
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf_cookie);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cookie_name = HeapAlloc(GetProcessHeap(), 0, (nEqualPos + 1)*sizeof(WCHAR));
|
|
|
|
lstrcpynW(cookie_name, buf_cookie, nEqualPos + 1);
|
|
|
|
cookie_data = &buf_cookie[nEqualPos + 1];
|
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
Host = HTTP_GetHeader(lpwhr,szHost);
|
|
|
|
len = lstrlenW((domain ? domain : (Host?Host->lpszValue:NULL))) +
|
2005-11-21 16:17:55 +01:00
|
|
|
strlenW(lpwhr->lpszPath) + 9;
|
|
|
|
buf_url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
2005-12-13 17:07:41 +01:00
|
|
|
sprintfW(buf_url, szFmt, (domain ? domain : (Host?Host->lpszValue:NULL))); /* FIXME PATH!!! */
|
2005-11-21 16:17:55 +01:00
|
|
|
InternetSetCookieW(buf_url, cookie_name, cookie_data);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf_url);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf_cookie);
|
|
|
|
HeapFree(GetProcessHeap(), 0, cookie_name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, domain);
|
|
|
|
nPosStart = nPosEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void HTTP_AddProxyInfo( LPWININETHTTPREQW lpwhr )
|
|
|
|
{
|
2005-11-28 11:55:16 +01:00
|
|
|
LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW)lpwhr->hdr.lpwhparent;
|
|
|
|
LPWININETAPPINFOW hIC = (LPWININETAPPINFOW)lpwhs->hdr.lpwhparent;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2005-11-28 11:28:06 +01:00
|
|
|
assert(lpwhs->hdr.htype == WH_HHTTPSESSION);
|
|
|
|
assert(hIC->hdr.htype == WH_HINIT);
|
2005-11-21 16:17:55 +01:00
|
|
|
|
|
|
|
if (hIC && (hIC->lpszProxyUsername || hIC->lpszProxyPassword ))
|
|
|
|
HTTP_InsertProxyAuthorization(lpwhr, hIC->lpszProxyUsername,
|
|
|
|
hIC->lpszProxyPassword);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2004-06-14 19:57:26 +02:00
|
|
|
static BOOL WINAPI HTTP_HttpAddRequestHeadersW(LPWININETHTTPREQW lpwhr,
|
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;
|
2000-06-11 22:04:44 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
2004-08-11 01:41:35 +02:00
|
|
|
DWORD len;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("copying header: %s\n", debugstr_w(lpszHeader));
|
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;
|
|
|
|
buffer = HeapAlloc( GetProcessHeap(), 0, 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')
|
|
|
|
{
|
|
|
|
if (*lpszEnd == '\r' && *(lpszEnd + 1) == '\n')
|
|
|
|
break;
|
|
|
|
lpszEnd++;
|
|
|
|
}
|
|
|
|
|
2004-07-14 01:34:28 +02:00
|
|
|
if (*lpszStart == '\0')
|
2000-06-11 22:04:44 +02:00
|
|
|
break;
|
|
|
|
|
2004-07-14 01:34:28 +02:00
|
|
|
if (*lpszEnd == '\r')
|
|
|
|
{
|
|
|
|
*lpszEnd = '\0';
|
|
|
|
lpszEnd += 2; /* Jump over \r\n */
|
|
|
|
}
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("interpreting header %s\n", debugstr_w(lpszStart));
|
2004-09-24 00:53:50 +02:00
|
|
|
pFieldAndValue = HTTP_InterpretHttpHeader(lpszStart);
|
|
|
|
if (pFieldAndValue)
|
|
|
|
{
|
|
|
|
bSuccess = HTTP_ProcessHeader(lpwhr, pFieldAndValue[0],
|
|
|
|
pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ);
|
|
|
|
HTTP_FreeTokens(pFieldAndValue);
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-14 01:34:28 +02:00
|
|
|
lpszStart = lpszEnd;
|
2000-06-11 22:04:44 +02:00
|
|
|
} while (bSuccess);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
2004-06-14 19:57:26 +02:00
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpAddRequestHeadersW (WININET.@)
|
|
|
|
*
|
|
|
|
* Adds one or more HTTP header to the request handler
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
|
|
|
|
LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
|
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
LPWININETHTTPREQW lpwhr;
|
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_w(lpszHeader), dwHeaderLength,
|
2004-06-14 19:57:26 +02:00
|
|
|
dwModifier);
|
|
|
|
|
|
|
|
if (!lpszHeader)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest );
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2004-06-14 19:57:26 +02:00
|
|
|
}
|
|
|
|
bSuccess = HTTP_HttpAddRequestHeadersW( lpwhr, lpszHeader, dwHeaderLength, dwModifier );
|
2004-07-19 23:49:39 +02:00
|
|
|
lend:
|
|
|
|
if( lpwhr )
|
|
|
|
WININET_Release( &lpwhr->hdr );
|
2004-06-14 19:57:26 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
LPWSTR hdr;
|
|
|
|
BOOL r;
|
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_a(lpszHeader), dwHeaderLength,
|
2004-03-30 06:36:09 +02:00
|
|
|
dwModifier);
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, NULL, 0 );
|
|
|
|
hdr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, hdr, len );
|
2005-09-13 17:00:32 +02:00
|
|
|
if( dwHeaderLength != ~0U )
|
2004-03-30 06:36:09 +02:00
|
|
|
dwHeaderLength = len;
|
|
|
|
|
|
|
|
r = HttpAddRequestHeadersW( hHttpRequest, hdr, dwHeaderLength, dwModifier );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, hdr );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-09-28 00:05:23 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HttpEndRequestA (WININET.@)
|
|
|
|
*
|
|
|
|
* Ends an HTTP request that was started by HttpSendRequestEx
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2005-11-21 16:17:55 +01:00
|
|
|
BOOL WINAPI HttpEndRequestA(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD dwContext)
|
2002-09-28 00:05:23 +02:00
|
|
|
{
|
2005-11-21 16:17:55 +01:00
|
|
|
LPINTERNET_BUFFERSA ptr;
|
|
|
|
LPINTERNET_BUFFERSW lpBuffersOutW,ptrW;
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("(%p, %p, %08x, %08x): stub\n", hRequest, lpBuffersOut, dwFlags,
|
2005-11-21 16:17:55 +01:00
|
|
|
dwContext);
|
|
|
|
|
|
|
|
ptr = lpBuffersOut;
|
|
|
|
if (ptr)
|
|
|
|
lpBuffersOutW = (LPINTERNET_BUFFERSW)HeapAlloc(GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY, sizeof(INTERNET_BUFFERSW));
|
|
|
|
else
|
|
|
|
lpBuffersOutW = NULL;
|
|
|
|
|
|
|
|
ptrW = lpBuffersOutW;
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
if (ptr->lpvBuffer && ptr->dwBufferLength)
|
|
|
|
ptrW->lpvBuffer = HeapAlloc(GetProcessHeap(),0,ptr->dwBufferLength);
|
|
|
|
ptrW->dwBufferLength = ptr->dwBufferLength;
|
|
|
|
ptrW->dwBufferTotal= ptr->dwBufferTotal;
|
|
|
|
|
|
|
|
if (ptr->Next)
|
|
|
|
ptrW->Next = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(INTERNET_BUFFERSW));
|
|
|
|
|
|
|
|
ptr = ptr->Next;
|
|
|
|
ptrW = ptrW->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = HttpEndRequestW(hRequest, lpBuffersOutW, dwFlags, dwContext);
|
|
|
|
|
|
|
|
if (lpBuffersOutW)
|
|
|
|
{
|
|
|
|
ptrW = lpBuffersOutW;
|
|
|
|
while (ptrW)
|
|
|
|
{
|
|
|
|
LPINTERNET_BUFFERSW ptrW2;
|
|
|
|
|
|
|
|
FIXME("Do we need to translate info out of these buffer?\n");
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,(LPVOID)ptrW->lpvBuffer);
|
|
|
|
ptrW2 = ptrW->Next;
|
|
|
|
HeapFree(GetProcessHeap(),0,ptrW);
|
|
|
|
ptrW = ptrW2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2002-09-28 00:05:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpEndRequestW (WININET.@)
|
|
|
|
*
|
|
|
|
* Ends an HTTP request that was started by HttpSendRequestEx
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2005-11-21 16:17:55 +01:00
|
|
|
BOOL WINAPI HttpEndRequestW(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSW lpBuffersOut, DWORD dwFlags, DWORD dwContext)
|
2002-09-28 00:05:23 +02:00
|
|
|
{
|
2005-11-21 16:17:55 +01:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
LPWININETHTTPREQW lpwhr;
|
|
|
|
INT responseLen;
|
|
|
|
|
|
|
|
TRACE("-->\n");
|
|
|
|
lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hRequest );
|
|
|
|
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpwhr->hdr.dwFlags |= dwFlags;
|
|
|
|
lpwhr->hdr.dwContext = dwContext;
|
|
|
|
|
|
|
|
SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
|
|
|
|
|
|
|
|
responseLen = HTTP_GetResponseHeaders(lpwhr);
|
|
|
|
if (responseLen)
|
|
|
|
rc = TRUE;
|
|
|
|
|
|
|
|
SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen, sizeof(DWORD));
|
|
|
|
|
|
|
|
/* process headers here. Is this right? */
|
|
|
|
HTTP_ProcessHeaders(lpwhr);
|
|
|
|
|
|
|
|
/* We appear to do nothing with the buffer.. is that correct? */
|
|
|
|
|
2005-11-28 17:31:02 +01:00
|
|
|
if(!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT))
|
|
|
|
{
|
|
|
|
DWORD dwCode,dwCodeLength=sizeof(DWORD),dwIndex=0;
|
|
|
|
if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,&dwCode,&dwCodeLength,&dwIndex) &&
|
|
|
|
(dwCode==302 || dwCode==301))
|
|
|
|
{
|
|
|
|
WCHAR szNewLocation[2048];
|
|
|
|
DWORD dwBufferSize=2048;
|
|
|
|
dwIndex=0;
|
|
|
|
if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,&dwIndex))
|
|
|
|
{
|
|
|
|
static const WCHAR szGET[] = { 'G','E','T', 0 };
|
|
|
|
/* redirects are always GETs */
|
|
|
|
HeapFree(GetProcessHeap(),0,lpwhr->lpszVerb);
|
|
|
|
lpwhr->lpszVerb = WININET_strdupW(szGET);
|
2005-11-30 12:31:22 +01:00
|
|
|
return HTTP_HandleRedirect(lpwhr, szNewLocation, NULL, 0, NULL, 0, 0);
|
2005-11-28 17:31:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-21 16:17:55 +01:00
|
|
|
TRACE("%i <--\n",rc);
|
|
|
|
return rc;
|
2002-09-28 00:05:23 +02:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2004-03-30 06:36:09 +02:00
|
|
|
* HttpOpenRequestW (WININET.@)
|
2000-06-11 22:04:44 +02: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 HttpOpenRequestW(HINTERNET hHttpSession,
|
|
|
|
LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
|
|
|
|
LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
|
2000-06-11 22:04:44 +02:00
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs;
|
2004-02-07 02:03:41 +01:00
|
|
|
HINTERNET handle = NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %p, %08x, %08x)\n", hHttpSession,
|
2004-03-30 06:36:09 +02:00
|
|
|
debugstr_w(lpszVerb), debugstr_w(lpszObjectName),
|
|
|
|
debugstr_w(lpszVersion), debugstr_w(lpszReferrer), lpszAcceptTypes,
|
2003-06-21 01:26:56 +02:00
|
|
|
dwFlags, dwContext);
|
2002-12-07 00:20:31 +01:00
|
|
|
if(lpszAcceptTypes!=NULL)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;lpszAcceptTypes[i]!=NULL;i++)
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("\taccept type: %s\n",debugstr_w(lpszAcceptTypes[i]));
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs = (LPWININETHTTPSESSIONW) WININET_GetObject( hHttpSession );
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2002-06-22 01:59:49 +02: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.
|
|
|
|
*
|
|
|
|
*/
|
2004-07-19 23:49:39 +02:00
|
|
|
handle = HTTP_HttpOpenRequestW(lpwhs, lpszVerb, lpszObjectName,
|
|
|
|
lpszVersion, lpszReferrer, lpszAcceptTypes,
|
|
|
|
dwFlags, dwContext);
|
|
|
|
lend:
|
|
|
|
if( lpwhs )
|
|
|
|
WININET_Release( &lpwhs->hdr );
|
2004-02-07 02:03:41 +01:00
|
|
|
TRACE("returning %p\n", handle);
|
|
|
|
return handle;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
|
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,
|
2002-11-12 03:13:04 +01:00
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR szVerb = NULL, szObjectName = NULL;
|
|
|
|
LPWSTR szVersion = NULL, szReferrer = NULL, *szAcceptTypes = NULL;
|
2003-06-21 01:26:56 +02:00
|
|
|
INT len;
|
|
|
|
INT acceptTypesCount;
|
|
|
|
HINTERNET rc = FALSE;
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %p, %08x, %08x)\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)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, NULL, 0 );
|
|
|
|
szVerb = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
2003-08-15 05:47:30 +02:00
|
|
|
if ( !szVerb )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
2004-03-30 06:36:09 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, szVerb, len);
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
2002-12-07 00:20:31 +01:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (lpszObjectName)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpszObjectName, -1, NULL, 0 );
|
|
|
|
szObjectName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
2003-08-15 05:47:30 +02:00
|
|
|
if ( !szObjectName )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
2004-03-30 06:36:09 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszObjectName, -1, szObjectName, len );
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lpszVersion)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpszVersion, -1, NULL, 0 );
|
|
|
|
szVersion = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
2003-08-15 05:47:30 +02:00
|
|
|
if ( !szVersion )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
2004-03-30 06:36:09 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszVersion, -1, szVersion, len );
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lpszReferrer)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpszReferrer, -1, NULL, 0 );
|
|
|
|
szReferrer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
2003-08-15 05:47:30 +02:00
|
|
|
if ( !szReferrer )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
2004-03-30 06:36:09 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszReferrer, -1, szReferrer, len );
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
acceptTypesCount = 0;
|
|
|
|
if (lpszAcceptTypes)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
/* find out how many there are */
|
|
|
|
while (lpszAcceptTypes[acceptTypesCount])
|
|
|
|
acceptTypesCount++;
|
|
|
|
szAcceptTypes = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR *) * (acceptTypesCount+1));
|
2003-06-21 01:26:56 +02:00
|
|
|
acceptTypesCount = 0;
|
|
|
|
while (lpszAcceptTypes[acceptTypesCount])
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, lpszAcceptTypes[acceptTypesCount],
|
|
|
|
-1, NULL, 0 );
|
|
|
|
szAcceptTypes[acceptTypesCount] = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
2003-08-15 05:47:30 +02:00
|
|
|
if (!szAcceptTypes[acceptTypesCount] )
|
2003-06-21 01:26:56 +02:00
|
|
|
goto end;
|
2004-03-30 06:36:09 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszAcceptTypes[acceptTypesCount],
|
|
|
|
-1, szAcceptTypes[acceptTypesCount], len );
|
2003-06-21 01:26:56 +02:00
|
|
|
acceptTypesCount++;
|
|
|
|
}
|
2004-03-30 06:36:09 +02:00
|
|
|
szAcceptTypes[acceptTypesCount] = NULL;
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
else szAcceptTypes = 0;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
rc = HttpOpenRequestW(hHttpSession, szVerb, szObjectName,
|
|
|
|
szVersion, szReferrer,
|
|
|
|
(LPCWSTR*)szAcceptTypes, dwFlags, dwContext);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
end:
|
|
|
|
if (szAcceptTypes)
|
|
|
|
{
|
|
|
|
acceptTypesCount = 0;
|
|
|
|
while (szAcceptTypes[acceptTypesCount])
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, szAcceptTypes[acceptTypesCount]);
|
|
|
|
acceptTypesCount++;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, szAcceptTypes);
|
|
|
|
}
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, szReferrer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, szVersion);
|
|
|
|
HeapFree(GetProcessHeap(), 0, szObjectName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, 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
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_Base64
|
|
|
|
*/
|
2004-03-25 06:29:47 +01:00
|
|
|
static UINT HTTP_Base64( LPCWSTR bin, LPWSTR base64 )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
UINT n = 0, x;
|
2005-06-13 21:05:42 +02:00
|
|
|
static LPCSTR HTTP_Base64Enc =
|
2003-07-22 05:17:52 +02:00
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
|
|
|
|
while( bin[0] )
|
|
|
|
{
|
|
|
|
/* 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] */
|
|
|
|
if( !bin[1] )
|
|
|
|
{
|
|
|
|
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] */
|
|
|
|
if( !bin[2] )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
base64[n] = 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_EncodeBasicAuth
|
|
|
|
*
|
|
|
|
* Encode the basic authentication string for HTTP 1.1
|
|
|
|
*/
|
2004-03-25 06:29:47 +01:00
|
|
|
static LPWSTR HTTP_EncodeBasicAuth( LPCWSTR username, LPCWSTR password)
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
|
|
|
UINT len;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWSTR in, out;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szBasic[] = {'B','a','s','i','c',' ',0};
|
|
|
|
static const WCHAR szColon[] = {':',0};
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
len = lstrlenW( username ) + 1 + lstrlenW ( password ) + 1;
|
|
|
|
in = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
2003-07-22 05:17:52 +02:00
|
|
|
if( !in )
|
|
|
|
return NULL;
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
len = lstrlenW(szBasic) +
|
|
|
|
(lstrlenW( username ) + 1 + lstrlenW ( password ))*2 + 1 + 1;
|
2004-03-30 06:36:09 +02:00
|
|
|
out = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
2003-07-22 05:17:52 +02:00
|
|
|
if( out )
|
|
|
|
{
|
2004-03-25 06:29:47 +01:00
|
|
|
lstrcpyW( in, username );
|
|
|
|
lstrcatW( in, szColon );
|
|
|
|
lstrcatW( in, password );
|
|
|
|
lstrcpyW( out, szBasic );
|
|
|
|
HTTP_Base64( in, &out[strlenW(out)] );
|
2003-07-22 05:17:52 +02:00
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, in );
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_InsertProxyAuthorization
|
|
|
|
*
|
|
|
|
* Insert the basic authorization field in the request header
|
|
|
|
*/
|
2005-10-26 12:07:58 +02:00
|
|
|
static BOOL HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr,
|
2004-03-25 06:29:47 +01:00
|
|
|
LPCWSTR username, LPCWSTR password )
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
2005-11-28 11:17:06 +01:00
|
|
|
WCHAR *authorization = HTTP_EncodeBasicAuth( username, password );
|
2005-12-13 17:07:41 +01:00
|
|
|
BOOL ret = TRUE;
|
2005-11-28 11:17:06 +01:00
|
|
|
|
|
|
|
if (!authorization)
|
2003-07-22 05:17:52 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2005-11-28 11:17:06 +01:00
|
|
|
TRACE( "Inserting authorization: %s\n", debugstr_w( authorization ) );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
HTTP_ProcessHeader(lpwhr, szProxy_Authorization, authorization,
|
|
|
|
HTTP_ADDHDR_FLAG_REPLACE);
|
2005-11-28 11:17:06 +01:00
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, authorization );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2005-11-28 11:17:06 +01:00
|
|
|
return ret;
|
2003-07-22 05:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_DealWithProxy
|
|
|
|
*/
|
2004-03-25 06:29:47 +01:00
|
|
|
static BOOL HTTP_DealWithProxy( LPWININETAPPINFOW hIC,
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs, LPWININETHTTPREQW lpwhr)
|
2003-07-22 05:17:52 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR buf[MAXHOSTNAME];
|
|
|
|
WCHAR proxy[MAXHOSTNAME + 15]; /* 15 == "http://" + sizeof(port#) + ":/\0" */
|
2004-04-20 04:14:00 +02:00
|
|
|
WCHAR* url;
|
2006-10-13 15:43:54 +02:00
|
|
|
static WCHAR szNul[] = { 0 };
|
2004-03-30 06:36:09 +02:00
|
|
|
URL_COMPONENTSW UrlComponents;
|
2004-04-20 04:14:00 +02:00
|
|
|
static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/',0 }, szSlash[] = { '/',0 } ;
|
2004-06-01 22:19:56 +02:00
|
|
|
static const WCHAR szFormat1[] = { 'h','t','t','p',':','/','/','%','s',0 };
|
2004-04-20 04:14:00 +02:00
|
|
|
static const WCHAR szFormat2[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
|
2004-03-30 06:36:09 +02:00
|
|
|
int len;
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
memset( &UrlComponents, 0, sizeof UrlComponents );
|
|
|
|
UrlComponents.dwStructSize = sizeof UrlComponents;
|
|
|
|
UrlComponents.lpszHostName = buf;
|
|
|
|
UrlComponents.dwHostNameLength = MAXHOSTNAME;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
if( CSTR_EQUAL != CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
|
2005-11-28 11:31:11 +01:00
|
|
|
hIC->lpszProxy,strlenW(szHttp),szHttp,strlenW(szHttp)) )
|
2004-03-30 06:36:09 +02:00
|
|
|
sprintfW(proxy, szFormat1, hIC->lpszProxy);
|
2003-12-15 20:47:31 +01:00
|
|
|
else
|
2005-11-28 11:31:11 +01:00
|
|
|
strcpyW(proxy, hIC->lpszProxy);
|
2004-03-30 06:36:09 +02:00
|
|
|
if( !InternetCrackUrlW(proxy, 0, 0, &UrlComponents) )
|
2003-07-22 05:17:52 +02:00
|
|
|
return FALSE;
|
|
|
|
if( UrlComponents.dwHostNameLength == 0 )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if( !lpwhr->lpszPath )
|
2006-10-13 15:43:54 +02:00
|
|
|
lpwhr->lpszPath = szNul;
|
2003-07-22 05:17:52 +02:00
|
|
|
TRACE("server='%s' path='%s'\n",
|
2005-11-28 10:40:42 +01:00
|
|
|
debugstr_w(lpwhs->lpszHostName), debugstr_w(lpwhr->lpszPath));
|
2003-07-22 05:17:52 +02:00
|
|
|
/* for constant 15 see above */
|
2005-11-28 10:40:42 +01:00
|
|
|
len = strlenW(lpwhs->lpszHostName) + strlenW(lpwhr->lpszPath) + 15;
|
2004-03-30 06:36:09 +02:00
|
|
|
url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
|
|
|
|
UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
|
2005-11-28 11:53:05 +01:00
|
|
|
sprintfW(url, szFormat2, lpwhs->lpszHostName, lpwhs->nHostPort);
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
if( lpwhr->lpszPath[0] != '/' )
|
2004-03-30 06:36:09 +02:00
|
|
|
strcatW( url, szSlash );
|
|
|
|
strcatW(url, lpwhr->lpszPath);
|
2003-07-22 05:17:52 +02:00
|
|
|
if(lpwhr->lpszPath != szNul)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
|
|
|
|
lpwhr->lpszPath = url;
|
2005-11-28 10:40:42 +01:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs->lpszServerName = WININET_strdupW(UrlComponents.lpszHostName);
|
2003-07-22 05:17:52 +02:00
|
|
|
lpwhs->nServerPort = UrlComponents.nPort;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
2004-07-19 23:49:39 +02:00
|
|
|
HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
|
2004-03-30 06:36:09 +02:00
|
|
|
LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
|
|
|
|
LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
|
2000-06-11 22:04:44 +02:00
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPREQW lpwhr;
|
|
|
|
LPWSTR lpszCookies;
|
|
|
|
LPWSTR lpszUrl = NULL;
|
2003-06-21 01:26:56 +02:00
|
|
|
DWORD nCookieSize;
|
2004-07-19 23:49:39 +02:00
|
|
|
HINTERNET handle = NULL;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szUrlForm[] = {'h','t','t','p',':','/','/','%','s',0};
|
2004-03-30 06:36:09 +02:00
|
|
|
DWORD len;
|
2005-12-13 17:07:41 +01:00
|
|
|
LPHTTPHEADERW Host;
|
2006-01-05 14:37:06 +01:00
|
|
|
char szaddr[32];
|
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
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
assert( lpwhs->hdr.htype == WH_HHTTPSESSION );
|
2004-03-25 06:29:47 +01:00
|
|
|
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPREQW));
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL == lpwhr)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2004-02-07 02:03:41 +01:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
lpwhr->hdr.htype = WH_HHTTPREQ;
|
|
|
|
lpwhr->hdr.lpwhparent = WININET_AddRef( &lpwhs->hdr );
|
|
|
|
lpwhr->hdr.dwFlags = dwFlags;
|
|
|
|
lpwhr->hdr.dwContext = dwContext;
|
|
|
|
lpwhr->hdr.dwRefCount = 1;
|
|
|
|
lpwhr->hdr.destroy = HTTP_CloseHTTPRequestHandle;
|
2004-09-20 21:10:31 +02:00
|
|
|
lpwhr->hdr.lpfnStatusCB = lpwhs->hdr.lpfnStatusCB;
|
2004-07-19 23:49:39 +02:00
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
handle = WININET_AllocHandle( &lpwhr->hdr );
|
|
|
|
if (NULL == handle)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2006-03-06 18:31:09 +01:00
|
|
|
if (!NETCON_init(&lpwhr->netConnection, dwFlags & INTERNET_FLAG_SECURE))
|
|
|
|
{
|
|
|
|
InternetCloseHandle( handle );
|
|
|
|
handle = NULL;
|
|
|
|
goto lend;
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
if (NULL != lpszObjectName && strlenW(lpszObjectName)) {
|
2002-06-22 01:59:49 +02:00
|
|
|
HRESULT rc;
|
2004-03-30 06:36:09 +02:00
|
|
|
|
|
|
|
len = 0;
|
|
|
|
rc = UrlEscapeW(lpszObjectName, NULL, &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;
|
|
|
|
lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
rc = UrlEscapeW(lpszObjectName, lpwhr->lpszPath, &len,
|
2001-01-21 22:09:00 +01:00
|
|
|
URL_ESCAPE_SPACES_ONLY);
|
2002-06-22 01:59:49 +02:00
|
|
|
if (rc)
|
|
|
|
{
|
2006-10-05 13:18:56 +02:00
|
|
|
ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(lpszObjectName),rc);
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(lpwhr->lpszPath,lpszObjectName);
|
2002-06-22 01:59:49 +02:00
|
|
|
}
|
2001-01-21 22:09:00 +01:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
if (NULL != lpszReferrer && strlenW(lpszReferrer))
|
2003-06-21 01:26:56 +02:00
|
|
|
HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpszReferrer, HTTP_ADDHDR_FLAG_COALESCE);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
if(lpszAcceptTypes!=NULL)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;lpszAcceptTypes[i]!=NULL;i++)
|
|
|
|
HTTP_ProcessHeader(lpwhr, HTTP_ACCEPT, lpszAcceptTypes[i], HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_REQ|HTTP_ADDHDR_FLAG_ADD_IF_NEW);
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
if (NULL == lpszVerb)
|
2004-03-30 06:36:09 +02:00
|
|
|
{
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szGet[] = {'G','E','T',0};
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhr->lpszVerb = WININET_strdupW(szGet);
|
|
|
|
}
|
|
|
|
else if (strlenW(lpszVerb))
|
|
|
|
lpwhr->lpszVerb = WININET_strdupW(lpszVerb);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
if (NULL != lpszReferrer && strlenW(lpszReferrer))
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR buf[MAXHOSTNAME];
|
|
|
|
URL_COMPONENTSW UrlComponents;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
memset( &UrlComponents, 0, sizeof UrlComponents );
|
|
|
|
UrlComponents.dwStructSize = sizeof UrlComponents;
|
2000-06-11 22:04:44 +02:00
|
|
|
UrlComponents.lpszHostName = buf;
|
|
|
|
UrlComponents.dwHostNameLength = MAXHOSTNAME;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
InternetCrackUrlW(lpszReferrer, 0, 0, &UrlComponents);
|
|
|
|
if (strlenW(UrlComponents.lpszHostName))
|
2005-12-13 17:07:41 +01:00
|
|
|
HTTP_ProcessHeader(lpwhr, szHost, UrlComponents.lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2004-09-13 21:33:17 +02:00
|
|
|
else
|
2005-12-13 17:07:41 +01:00
|
|
|
HTTP_ProcessHeader(lpwhr, szHost, lpwhs->lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
|
2004-09-13 21:33:17 +02:00
|
|
|
|
2005-10-19 21:07:08 +02:00
|
|
|
if (lpwhs->nServerPort == INTERNET_INVALID_PORT_NUMBER)
|
|
|
|
lpwhs->nServerPort = (dwFlags & INTERNET_FLAG_SECURE ?
|
|
|
|
INTERNET_DEFAULT_HTTPS_PORT :
|
|
|
|
INTERNET_DEFAULT_HTTP_PORT);
|
2005-11-28 11:53:05 +01:00
|
|
|
lpwhs->nHostPort = lpwhs->nServerPort;
|
2005-10-19 21:07:08 +02:00
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0)
|
|
|
|
HTTP_DealWithProxy( hIC, lpwhs, lpwhr );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (hIC->lpszAgent)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR *agent_header;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR user_agent[] = {'U','s','e','r','-','A','g','e','n','t',':',' ','%','s','\r','\n',0 };
|
2004-03-25 06:29:47 +01:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
len = strlenW(hIC->lpszAgent) + strlenW(user_agent);
|
|
|
|
agent_header = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
sprintfW(agent_header, user_agent, hIC->lpszAgent );
|
2004-03-25 06:29:47 +01:00
|
|
|
|
2004-06-14 19:57:26 +02:00
|
|
|
HTTP_HttpAddRequestHeadersW(lpwhr, agent_header, strlenW(agent_header),
|
2003-06-21 01:26:56 +02:00
|
|
|
HTTP_ADDREQ_FLAG_ADD);
|
|
|
|
HeapFree(GetProcessHeap(), 0, agent_header);
|
|
|
|
}
|
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
Host = HTTP_GetHeader(lpwhr,szHost);
|
|
|
|
|
|
|
|
len = lstrlenW(Host->lpszValue) + strlenW(szUrlForm);
|
2004-03-30 06:36:09 +02:00
|
|
|
lpszUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
2005-12-13 17:07:41 +01:00
|
|
|
sprintfW( lpszUrl, szUrlForm, Host->lpszValue );
|
2004-03-30 06:36:09 +02:00
|
|
|
|
2004-07-19 23:18:33 +02:00
|
|
|
if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) &&
|
|
|
|
InternetGetCookieW(lpszUrl, NULL, NULL, &nCookieSize))
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
|
|
|
int cnt = 0;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szCookie[] = {'C','o','o','k','i','e',':',' ',0};
|
|
|
|
static const WCHAR szcrlf[] = {'\r','\n',0};
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpszCookies = HeapAlloc(GetProcessHeap(), 0, (nCookieSize + 1 + 8)*sizeof(WCHAR));
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
cnt += sprintfW(lpszCookies, szCookie);
|
|
|
|
InternetGetCookieW(lpszUrl, NULL, lpszCookies + cnt, &nCookieSize);
|
|
|
|
strcatW(lpszCookies, szcrlf);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-06-14 19:57:26 +02:00
|
|
|
HTTP_HttpAddRequestHeadersW(lpwhr, lpszCookies, strlenW(lpszCookies),
|
2003-06-21 01:26:56 +02:00
|
|
|
HTTP_ADDREQ_FLAG_ADD);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpszCookies);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpszUrl);
|
|
|
|
|
|
|
|
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhs->hdr, dwContext,
|
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &handle,
|
|
|
|
sizeof(handle));
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
/*
|
|
|
|
* A STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on windows
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
/*
|
|
|
|
* According to my tests. The name is not resolved until a request is Opened
|
|
|
|
*/
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, dwContext,
|
|
|
|
INTERNET_STATUS_RESOLVING_NAME,
|
|
|
|
lpwhs->lpszServerName,
|
|
|
|
strlenW(lpwhs->lpszServerName)+1);
|
2005-06-21 22:02:34 +02:00
|
|
|
|
2005-10-19 21:07:08 +02:00
|
|
|
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
2005-11-15 19:16:55 +01:00
|
|
|
&lpwhs->socketAddress))
|
2002-06-22 01:59:49 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
2004-07-19 23:49:39 +02:00
|
|
|
InternetCloseHandle( handle );
|
|
|
|
handle = NULL;
|
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2006-01-05 14:37:06 +01:00
|
|
|
inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr,
|
|
|
|
szaddr, sizeof(szaddr));
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_NAME_RESOLVED,
|
2006-01-05 14:37:06 +01:00
|
|
|
szaddr, strlen(szaddr)+1);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
lend:
|
|
|
|
if( lpwhr )
|
|
|
|
WININET_Release( &lpwhr->hdr );
|
|
|
|
|
|
|
|
TRACE("<-- %p (%p)\n", handle, lpwhr);
|
2004-02-07 02:03:41 +01:00
|
|
|
return handle;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2005-12-13 17:07:41 +01: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 szAuthorization[] = { 'A','u','t','h','o','r','i','z','a','t','i','o','n',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 };
|
|
|
|
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 };
|
|
|
|
|
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 */
|
|
|
|
NULL, /* HTTP_QUERY_CONTENT_DISPOSITION = 47 */
|
|
|
|
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 */
|
|
|
|
szHost, /* HTTP_QUERY_HOST = 55 */
|
|
|
|
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
|
|
|
*/
|
2005-06-13 21:05:42 +02:00
|
|
|
static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD dwInfoLevel,
|
2000-06-11 22:04:44 +02:00
|
|
|
LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPHTTPHEADERW lphttpHdr = NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
2005-12-13 17:07:41 +01:00
|
|
|
BOOL request_only = dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS;
|
2006-03-30 11:01:48 +02:00
|
|
|
INT requested_index = lpdwIndex ? *lpdwIndex : 0;
|
|
|
|
INT level = (dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK);
|
|
|
|
INT index = -1;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
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:
|
|
|
|
index = HTTP_GetCustomHeaderIndex(lpwhr, lpBuffer, requested_index, request_only);
|
|
|
|
break;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2006-03-30 11:01:48 +02:00
|
|
|
case HTTP_QUERY_RAW_HEADERS_CRLF:
|
2004-07-19 22:09:20 +02:00
|
|
|
{
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD len = strlenW(lpwhr->lpszRawHeaders);
|
2004-07-19 22:09:20 +02:00
|
|
|
if (len + 1 > *lpdwBufferLength/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
*lpdwBufferLength = (len + 1) * sizeof(WCHAR);
|
|
|
|
INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
memcpy(lpBuffer, lpwhr->lpszRawHeaders, (len+1)*sizeof(WCHAR));
|
2004-07-21 23:17:03 +02:00
|
|
|
*lpdwBufferLength = len * sizeof(WCHAR);
|
|
|
|
|
|
|
|
TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len));
|
|
|
|
|
2004-07-19 22:09:20 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2006-03-30 11:01:48 +02:00
|
|
|
case HTTP_QUERY_RAW_HEADERS:
|
2004-07-19 22:09:20 +02:00
|
|
|
{
|
|
|
|
static const WCHAR szCrLf[] = {'\r','\n',0};
|
|
|
|
LPWSTR * ppszRawHeaderLines = HTTP_Tokenize(lpwhr->lpszRawHeaders, szCrLf);
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD i, size = 0;
|
2004-07-19 22:09:20 +02:00
|
|
|
LPWSTR pszString = (WCHAR*)lpBuffer;
|
|
|
|
|
|
|
|
for (i = 0; ppszRawHeaderLines[i]; i++)
|
|
|
|
size += strlenW(ppszRawHeaderLines[i]) + 1;
|
|
|
|
|
|
|
|
if (size + 1 > *lpdwBufferLength/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
HTTP_FreeTokens(ppszRawHeaderLines);
|
|
|
|
*lpdwBufferLength = (size + 1) * sizeof(WCHAR);
|
|
|
|
INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; ppszRawHeaderLines[i]; i++)
|
|
|
|
{
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD len = strlenW(ppszRawHeaderLines[i]);
|
2004-07-19 22:09:20 +02:00
|
|
|
memcpy(pszString, ppszRawHeaderLines[i], (len+1)*sizeof(WCHAR));
|
|
|
|
pszString += len+1;
|
|
|
|
}
|
|
|
|
*pszString = '\0';
|
|
|
|
|
|
|
|
TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, size));
|
|
|
|
|
2004-07-21 23:17:03 +02:00
|
|
|
*lpdwBufferLength = size * sizeof(WCHAR);
|
2004-07-19 22:09:20 +02:00
|
|
|
HTTP_FreeTokens(ppszRawHeaderLines);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-03-30 11:01:48 +02:00
|
|
|
case HTTP_QUERY_STATUS_TEXT:
|
2006-05-30 15:55:42 +02:00
|
|
|
if (lpwhr->lpszStatusText)
|
2005-12-13 17:07:41 +01:00
|
|
|
{
|
|
|
|
DWORD len = strlenW(lpwhr->lpszStatusText);
|
|
|
|
if (len + 1 > *lpdwBufferLength/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
*lpdwBufferLength = (len + 1) * sizeof(WCHAR);
|
|
|
|
INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
memcpy(lpBuffer, lpwhr->lpszStatusText, (len+1)*sizeof(WCHAR));
|
|
|
|
*lpdwBufferLength = len * sizeof(WCHAR);
|
|
|
|
|
|
|
|
TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-05-30 15:55:42 +02:00
|
|
|
break;
|
2006-03-30 11:01:48 +02:00
|
|
|
case HTTP_QUERY_VERSION:
|
2006-05-30 15:55:42 +02:00
|
|
|
if (lpwhr->lpszVersion)
|
2005-12-13 17:07:41 +01:00
|
|
|
{
|
|
|
|
DWORD len = strlenW(lpwhr->lpszVersion);
|
|
|
|
if (len + 1 > *lpdwBufferLength/sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
*lpdwBufferLength = (len + 1) * sizeof(WCHAR);
|
|
|
|
INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
memcpy(lpBuffer, lpwhr->lpszVersion, (len+1)*sizeof(WCHAR));
|
|
|
|
*lpdwBufferLength = len * sizeof(WCHAR);
|
|
|
|
|
|
|
|
TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-05-30 15:55:42 +02:00
|
|
|
break;
|
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));
|
|
|
|
|
|
|
|
if (level >= 0 && level < LAST_TABLE_HEADER && header_lookup[level])
|
|
|
|
index = HTTP_GetCustomHeaderIndex(lpwhr, header_lookup[level],
|
|
|
|
requested_index,request_only);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2006-03-30 11:01:48 +02:00
|
|
|
if (index >= 0)
|
|
|
|
lphttpHdr = &lpwhr->pCustHeaders[index];
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/* Ensure header satisifies 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
|
|
|
{
|
|
|
|
SetLastError(ERROR_HTTP_HEADER_NOT_FOUND);
|
2006-03-30 11:01:48 +02:00
|
|
|
return bSuccess;
|
2004-07-15 20:57:32 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-03-30 11:01:48 +02:00
|
|
|
if (lpdwIndex)
|
|
|
|
(*lpdwIndex)++;
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/* coalesce value to reuqested type */
|
|
|
|
if (dwInfoLevel & HTTP_QUERY_FLAG_NUMBER)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
*(int *)lpBuffer = atoiW(lphttpHdr->lpszValue);
|
2004-02-09 23:01:49 +01:00
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
TRACE(" returning number : %d\n", *(int *)lpBuffer);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
STHook = (SYSTEMTIME *) lpBuffer;
|
|
|
|
if(STHook==NULL)
|
2004-06-14 19:57:26 +02:00
|
|
|
return bSuccess;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-02-09 23:01:49 +01:00
|
|
|
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;
|
|
|
|
STHook->wYear = tmpTM.tm_year;
|
|
|
|
|
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
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;
|
2000-06-11 22:04:44 +02:00
|
|
|
INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
2004-06-14 19:57:26 +02:00
|
|
|
return bSuccess;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2004-03-31 22:09:54 +02:00
|
|
|
memcpy(lpBuffer, lphttpHdr->lpszValue, len);
|
|
|
|
*lpdwBufferLength = len - sizeof(WCHAR);
|
2002-06-01 01:06:46 +02:00
|
|
|
bSuccess = TRUE;
|
2004-02-09 23:01:49 +01:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE(" returning string : '%s'\n", debugstr_w(lpBuffer));
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2004-06-14 19:57:26 +02:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpQueryInfoW (WININET.@)
|
|
|
|
*
|
|
|
|
* Queries for information about an HTTP request
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel,
|
|
|
|
LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
|
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
LPWININETHTTPREQW lpwhr;
|
|
|
|
|
|
|
|
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
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("(%p, 0x%08x)--> %d\n", hHttpRequest, dwInfoLevel, dwInfoLevel);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest );
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2004-06-14 19:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bSuccess = HTTP_HttpQueryInfoW( lpwhr, dwInfoLevel,
|
|
|
|
lpBuffer, lpdwBufferLength, lpdwIndex);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
lend:
|
|
|
|
if( lpwhr )
|
|
|
|
WININET_Release( &lpwhr->hdr );
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
TRACE("%d <--\n", bSuccess);
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
|
|
|
len = (*lpdwBufferLength)*sizeof(WCHAR);
|
|
|
|
bufferW = HeapAlloc( GetProcessHeap(), 0, len );
|
2005-12-08 12:44:45 +01:00
|
|
|
/* buffer is in/out because of HTTP_QUERY_CUSTOM */
|
|
|
|
if ((dwInfoLevel & HTTP_QUERY_HEADER_MASK) == HTTP_QUERY_CUSTOM)
|
|
|
|
MultiByteToWideChar(CP_ACP,0,lpBuffer,-1,bufferW,len);
|
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
|
|
|
|
2004-03-30 22:37:49 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, bufferW );
|
|
|
|
|
2002-11-12 03:13:04 +01:00
|
|
|
return result;
|
|
|
|
}
|
2000-10-28 02:30:23 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* HttpSendRequestExA (WININET.@)
|
2000-10-28 02:30:23 +02:00
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server and allows chunked
|
2006-02-14 11:34:14 +01:00
|
|
|
* transfers.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE, call GetLastError() for more information.
|
2000-10-28 02:30:23 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSA lpBuffersIn,
|
|
|
|
LPINTERNET_BUFFERSA lpBuffersOut,
|
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
2005-11-29 11:42:23 +01:00
|
|
|
INTERNET_BUFFERSW BuffersInW;
|
2005-11-21 16:17:55 +01:00
|
|
|
BOOL rc = FALSE;
|
2005-11-29 11:42:23 +01:00
|
|
|
DWORD headerlen;
|
2006-10-13 15:43:54 +02:00
|
|
|
LPWSTR header = NULL;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("(%p, %p, %p, %08x, %08x): stub\n", hRequest, lpBuffersIn,
|
2005-11-21 16:17:55 +01:00
|
|
|
lpBuffersOut, dwFlags, dwContext);
|
|
|
|
|
2005-11-29 11:42:23 +01:00
|
|
|
if (lpBuffersIn)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2005-11-29 11:42:23 +01:00
|
|
|
BuffersInW.dwStructSize = sizeof(LPINTERNET_BUFFERSW);
|
|
|
|
if (lpBuffersIn->lpcszHeader)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2005-11-29 11:42:23 +01:00
|
|
|
headerlen = MultiByteToWideChar(CP_ACP,0,lpBuffersIn->lpcszHeader,
|
|
|
|
lpBuffersIn->dwHeadersLength,0,0);
|
2006-10-13 15:43:54 +02:00
|
|
|
header = HeapAlloc(GetProcessHeap(),0,headerlen*sizeof(WCHAR));
|
|
|
|
if (!(BuffersInW.lpcszHeader = header))
|
2005-11-29 11:42:23 +01:00
|
|
|
{
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
BuffersInW.dwHeadersLength = MultiByteToWideChar(CP_ACP, 0,
|
|
|
|
lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength,
|
2006-10-13 15:43:54 +02:00
|
|
|
header, headerlen);
|
2005-11-21 16:17:55 +01:00
|
|
|
}
|
2005-12-08 11:54:24 +01:00
|
|
|
else
|
|
|
|
BuffersInW.lpcszHeader = NULL;
|
2005-11-29 11:42:23 +01:00
|
|
|
BuffersInW.dwHeadersTotal = lpBuffersIn->dwHeadersTotal;
|
|
|
|
BuffersInW.lpvBuffer = lpBuffersIn->lpvBuffer;
|
|
|
|
BuffersInW.dwBufferLength = lpBuffersIn->dwBufferLength;
|
|
|
|
BuffersInW.dwBufferTotal = lpBuffersIn->dwBufferTotal;
|
|
|
|
BuffersInW.Next = NULL;
|
|
|
|
}
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2005-11-29 11:42:23 +01:00
|
|
|
rc = HttpSendRequestExW(hRequest, lpBuffersIn ? &BuffersInW : NULL, NULL, dwFlags, dwContext);
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2006-10-13 15:43:54 +02:00
|
|
|
HeapFree(GetProcessHeap(),0,header);
|
2005-11-21 16:17:55 +01:00
|
|
|
|
|
|
|
return rc;
|
- 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
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpSendRequestExW (WININET.@)
|
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server and allows chunked
|
|
|
|
* transfers
|
2006-02-14 11:34:14 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE, call GetLastError() for more information.
|
- 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
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestExW(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSW lpBuffersIn,
|
|
|
|
LPINTERNET_BUFFERSW lpBuffersOut,
|
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
2005-11-30 12:31:22 +01:00
|
|
|
BOOL ret;
|
2005-11-21 16:17:55 +01:00
|
|
|
LPWININETHTTPREQW lpwhr;
|
2005-11-30 12:31:22 +01:00
|
|
|
LPWININETHTTPSESSIONW lpwhs;
|
|
|
|
LPWININETAPPINFOW hIC;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("(%p, %p, %p, %08x, %08x)\n", hRequest, lpBuffersIn,
|
2005-11-21 16:17:55 +01:00
|
|
|
lpBuffersOut, dwFlags, dwContext);
|
|
|
|
|
|
|
|
lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hRequest );
|
|
|
|
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-30 12:31:22 +01:00
|
|
|
lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
|
|
|
|
assert(lpwhs->hdr.htype == WH_HHTTPSESSION);
|
|
|
|
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
|
|
|
assert(hIC->hdr.htype == WH_HINIT);
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2005-11-30 12:31:22 +01:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2005-11-21 16:17:55 +01:00
|
|
|
{
|
2005-11-30 12:31:22 +01:00
|
|
|
WORKREQUEST workRequest;
|
|
|
|
struct WORKREQ_HTTPSENDREQUESTW *req;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2005-11-30 12:31:22 +01:00
|
|
|
workRequest.asyncall = HTTPSENDREQUESTW;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwhr->hdr );
|
|
|
|
req = &workRequest.u.HttpSendRequestW;
|
2006-01-13 13:52:38 +01:00
|
|
|
if (lpBuffersIn)
|
|
|
|
{
|
|
|
|
if (lpBuffersIn->lpcszHeader)
|
|
|
|
/* FIXME: this should use dwHeadersLength or may not be necessary at all */
|
|
|
|
req->lpszHeader = WININET_strdupW(lpBuffersIn->lpcszHeader);
|
|
|
|
else
|
|
|
|
req->lpszHeader = NULL;
|
|
|
|
req->dwHeaderLength = lpBuffersIn->dwHeadersLength;
|
|
|
|
req->lpOptional = lpBuffersIn->lpvBuffer;
|
|
|
|
req->dwOptionalLength = lpBuffersIn->dwBufferLength;
|
|
|
|
req->dwContentLength = lpBuffersIn->dwBufferTotal;
|
|
|
|
}
|
2005-11-30 12:31:22 +01:00
|
|
|
else
|
2006-01-13 13:52:38 +01:00
|
|
|
{
|
2005-11-30 12:31:22 +01:00
|
|
|
req->lpszHeader = NULL;
|
2006-01-13 13:52:38 +01:00
|
|
|
req->dwHeaderLength = 0;
|
|
|
|
req->lpOptional = NULL;
|
|
|
|
req->dwOptionalLength = 0;
|
|
|
|
req->dwContentLength = 0;
|
|
|
|
}
|
|
|
|
|
2005-11-30 12:31:22 +01:00
|
|
|
req->bEndRequest = FALSE;
|
2005-11-21 16:17:55 +01:00
|
|
|
|
2005-11-30 12:31:22 +01:00
|
|
|
INTERNET_AsyncCall(&workRequest);
|
|
|
|
/*
|
|
|
|
* This is from windows.
|
|
|
|
*/
|
|
|
|
SetLastError(ERROR_IO_PENDING);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = HTTP_HttpSendRequestW(lpwhr, lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength,
|
|
|
|
lpBuffersIn->lpvBuffer, lpBuffersIn->dwBufferLength,
|
|
|
|
lpBuffersIn->dwBufferTotal, FALSE);
|
|
|
|
}
|
2005-11-21 16:17:55 +01:00
|
|
|
|
|
|
|
WININET_Release(&lpwhr->hdr);
|
|
|
|
TRACE("<---\n");
|
2005-11-30 12:31:22 +01:00
|
|
|
return ret;
|
2000-10-28 02:30:23 +02:00
|
|
|
}
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
2004-06-28 22:28:38 +02:00
|
|
|
* HttpSendRequestW (WININET.@)
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders,
|
2000-06-11 22:04:44 +02:00
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPREQW lpwhr;
|
|
|
|
LPWININETHTTPSESSIONW lpwhs = NULL;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("%p, %p (%s), %i, %p, %i)\n", hHttpRequest,
|
2004-03-30 06:36:09 +02:00
|
|
|
lpszHeaders, debugstr_w(lpszHeaders), dwHeaderLength, lpOptional, dwOptionalLength);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest );
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FALSE;
|
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FALSE;
|
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL == hIC || hIC->hdr.htype != WH_HINIT)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FALSE;
|
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-03-30 06:36:09 +02:00
|
|
|
struct WORKREQ_HTTPSENDREQUESTW *req;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
workRequest.asyncall = HTTPSENDREQUESTW;
|
2004-07-19 23:49:39 +02:00
|
|
|
workRequest.hdr = WININET_AddRef( &lpwhr->hdr );
|
2004-03-30 06:36:09 +02:00
|
|
|
req = &workRequest.u.HttpSendRequestW;
|
2002-06-22 01:59:49 +02:00
|
|
|
if (lpszHeaders)
|
2004-03-30 06:36:09 +02:00
|
|
|
req->lpszHeader = WININET_strdupW(lpszHeaders);
|
2002-06-22 01:59:49 +02:00
|
|
|
else
|
2003-09-25 22:25:22 +02:00
|
|
|
req->lpszHeader = 0;
|
|
|
|
req->dwHeaderLength = dwHeaderLength;
|
|
|
|
req->lpOptional = lpOptional;
|
|
|
|
req->dwOptionalLength = dwOptionalLength;
|
2005-11-30 12:31:22 +01:00
|
|
|
req->dwContentLength = dwOptionalLength;
|
|
|
|
req->bEndRequest = TRUE;
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
INTERNET_AsyncCall(&workRequest);
|
|
|
|
/*
|
2002-12-07 00:20:31 +01:00
|
|
|
* This is from windows.
|
2002-06-22 01:59:49 +02:00
|
|
|
*/
|
2002-12-07 00:20:31 +01:00
|
|
|
SetLastError(ERROR_IO_PENDING);
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FALSE;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
r = HTTP_HttpSendRequestW(lpwhr, lpszHeaders,
|
2005-11-30 12:31:22 +01:00
|
|
|
dwHeaderLength, lpOptional, dwOptionalLength,
|
|
|
|
dwOptionalLength, TRUE);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
lend:
|
|
|
|
if( lpwhr )
|
|
|
|
WININET_Release( &lpwhr->hdr );
|
|
|
|
return r;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2002-11-12 03:13:04 +01:00
|
|
|
/***********************************************************************
|
2004-06-28 22:28:38 +02:00
|
|
|
* HttpSendRequestA (WININET.@)
|
2002-11-12 03:13:04 +01:00
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL WINAPI HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders,
|
2002-11-12 03:13:04 +01:00
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
|
|
|
|
{
|
|
|
|
BOOL result;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR szHeaders=NULL;
|
2002-11-12 03:13:04 +01:00
|
|
|
DWORD nLen=dwHeaderLength;
|
|
|
|
if(lpszHeaders!=NULL)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
nLen=MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,NULL,0);
|
|
|
|
szHeaders=HeapAlloc(GetProcessHeap(),0,nLen*sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,szHeaders,nLen);
|
2002-11-12 03:13:04 +01:00
|
|
|
}
|
2004-03-30 06:36:09 +02:00
|
|
|
result=HttpSendRequestW(hHttpRequest, szHeaders, nLen, lpOptional, dwOptionalLength);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,szHeaders);
|
2002-11-12 03:13:04 +01:00
|
|
|
return result;
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_HandleRedirect (internal)
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl, LPCWSTR lpszHeaders,
|
2005-11-30 12:31:22 +01:00
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
|
|
|
|
DWORD dwContentLength)
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR path[2048];
|
2006-01-05 14:37:06 +01:00
|
|
|
char szaddr[32];
|
2004-02-07 02:03:41 +01:00
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
if(lpszUrl[0]=='/')
|
|
|
|
{
|
|
|
|
/* if it's an absolute path, keep the same session info */
|
2005-11-30 12:01:50 +01:00
|
|
|
lstrcpynW(path, lpszUrl, 2048);
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
2003-07-22 05:17:52 +02:00
|
|
|
else if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0)
|
|
|
|
{
|
|
|
|
TRACE("Redirect through proxy\n");
|
2005-11-30 12:01:50 +01:00
|
|
|
lstrcpynW(path, lpszUrl, 2048);
|
2003-07-22 05:17:52 +02:00
|
|
|
}
|
2002-12-07 00:20:31 +01:00
|
|
|
else
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
URL_COMPONENTSW urlComponents;
|
|
|
|
WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
|
2006-10-13 15:43:54 +02:00
|
|
|
static WCHAR szHttp[] = {'h','t','t','p',0};
|
|
|
|
static WCHAR szHttps[] = {'h','t','t','p','s',0};
|
2006-03-09 16:11:59 +01:00
|
|
|
DWORD url_length = 0;
|
|
|
|
LPWSTR orig_url;
|
|
|
|
LPWSTR combined_url;
|
|
|
|
|
|
|
|
urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
|
2006-10-13 15:43:54 +02:00
|
|
|
urlComponents.lpszScheme = (lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE) ? szHttps : szHttp;
|
2006-03-09 16:11:59 +01:00
|
|
|
urlComponents.dwSchemeLength = 0;
|
|
|
|
urlComponents.lpszHostName = lpwhs->lpszHostName;
|
|
|
|
urlComponents.dwHostNameLength = 0;
|
|
|
|
urlComponents.nPort = lpwhs->nHostPort;
|
|
|
|
urlComponents.lpszUserName = lpwhs->lpszUserName;
|
|
|
|
urlComponents.dwUserNameLength = 0;
|
|
|
|
urlComponents.lpszPassword = NULL;
|
|
|
|
urlComponents.dwPasswordLength = 0;
|
|
|
|
urlComponents.lpszUrlPath = lpwhr->lpszPath;
|
|
|
|
urlComponents.dwUrlPathLength = 0;
|
|
|
|
urlComponents.lpszExtraInfo = NULL;
|
|
|
|
urlComponents.dwExtraInfoLength = 0;
|
|
|
|
|
|
|
|
if (!InternetCreateUrlW(&urlComponents, 0, NULL, &url_length) &&
|
|
|
|
(GetLastError() != ERROR_INSUFFICIENT_BUFFER))
|
|
|
|
return FALSE;
|
|
|
|
|
2006-03-21 14:44:36 +01:00
|
|
|
orig_url = HeapAlloc(GetProcessHeap(), 0, url_length);
|
2006-03-09 16:11:59 +01:00
|
|
|
|
2006-03-21 14:44:36 +01:00
|
|
|
/* convert from bytes to characters */
|
|
|
|
url_length = url_length / sizeof(WCHAR) - 1;
|
2006-03-09 16:11:59 +01:00
|
|
|
if (!InternetCreateUrlW(&urlComponents, 0, orig_url, &url_length))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, orig_url);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
url_length = 0;
|
|
|
|
if (!InternetCombineUrlW(orig_url, lpszUrl, NULL, &url_length, ICU_ENCODE_SPACES_ONLY) &&
|
|
|
|
(GetLastError() != ERROR_INSUFFICIENT_BUFFER))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, orig_url);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
combined_url = HeapAlloc(GetProcessHeap(), 0, url_length * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (!InternetCombineUrlW(orig_url, lpszUrl, combined_url, &url_length, ICU_ENCODE_SPACES_ONLY))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, orig_url);
|
|
|
|
HeapFree(GetProcessHeap(), 0, combined_url);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, orig_url);
|
|
|
|
|
2005-11-28 17:31:02 +01:00
|
|
|
userName[0] = 0;
|
|
|
|
hostName[0] = 0;
|
|
|
|
protocol[0] = 0;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
|
2002-12-07 00:20:31 +01:00
|
|
|
urlComponents.lpszScheme = protocol;
|
|
|
|
urlComponents.dwSchemeLength = 32;
|
|
|
|
urlComponents.lpszHostName = hostName;
|
|
|
|
urlComponents.dwHostNameLength = MAXHOSTNAME;
|
|
|
|
urlComponents.lpszUserName = userName;
|
|
|
|
urlComponents.dwUserNameLength = 1024;
|
2005-11-30 12:01:50 +01:00
|
|
|
urlComponents.lpszPassword = NULL;
|
|
|
|
urlComponents.dwPasswordLength = 0;
|
2002-12-07 00:20:31 +01:00
|
|
|
urlComponents.lpszUrlPath = path;
|
|
|
|
urlComponents.dwUrlPathLength = 2048;
|
2005-11-30 12:01:50 +01:00
|
|
|
urlComponents.lpszExtraInfo = NULL;
|
|
|
|
urlComponents.dwExtraInfoLength = 0;
|
2006-03-09 16:11:59 +01:00
|
|
|
if(!InternetCrackUrlW(combined_url, strlenW(combined_url), 0, &urlComponents))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, combined_url);
|
2002-12-07 00:20:31 +01:00
|
|
|
return FALSE;
|
2006-03-09 16:11:59 +01:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, combined_url);
|
2005-11-29 11:25:31 +01:00
|
|
|
|
2005-11-30 12:01:50 +01:00
|
|
|
if (!strncmpW(szHttp, urlComponents.lpszScheme, strlenW(szHttp)) &&
|
2005-11-29 11:25:31 +01:00
|
|
|
(lpwhr->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 */
|
|
|
|
lpwhr->hdr.dwFlags &= ~INTERNET_FLAG_SECURE;
|
|
|
|
}
|
2005-11-30 12:01:50 +01:00
|
|
|
if (!strncmpW(szHttps, urlComponents.lpszScheme, strlenW(szHttps)) &&
|
2005-11-29 11:25:31 +01:00
|
|
|
!(lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE))
|
|
|
|
{
|
|
|
|
TRACE("redirect from non-secure page to secure page\n");
|
|
|
|
/* FIXME: notify about redirect to secure page */
|
|
|
|
lpwhr->hdr.dwFlags |= INTERNET_FLAG_SECURE;
|
|
|
|
}
|
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
if (urlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
|
2005-11-28 17:31:02 +01:00
|
|
|
{
|
|
|
|
if (lstrlenW(protocol)>4) /*https*/
|
|
|
|
urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
|
|
|
|
else /*http*/
|
|
|
|
urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
}
|
2002-12-07 00:20:31 +01:00
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* This upsets redirects to binary files on sourceforge.net
|
|
|
|
* and gives an html page instead of the target file
|
|
|
|
* Examination of the HTTP request sent by native wininet.dll
|
|
|
|
* reveals that it doesn't send a referrer in that case.
|
|
|
|
* Maybe there's a flag that enables this, or maybe a referrer
|
|
|
|
* shouldn't be added in case of a redirect.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* consider the current host as the referrer */
|
2004-03-30 06:36:09 +02:00
|
|
|
if (NULL != lpwhs->lpszServerName && strlenW(lpwhs->lpszServerName))
|
2003-07-22 05:17:52 +02:00
|
|
|
HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpwhs->lpszServerName,
|
|
|
|
HTTP_ADDHDR_FLAG_REQ|HTTP_ADDREQ_FLAG_REPLACE|
|
|
|
|
HTTP_ADDHDR_FLAG_ADD_IF_NEW);
|
|
|
|
#endif
|
2002-12-07 00:20:31 +01:00
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
|
2005-11-29 11:35:19 +01:00
|
|
|
lpwhs->lpszServerName = WININET_strdupW(hostName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszHostName);
|
2005-11-28 17:31:02 +01:00
|
|
|
if (urlComponents.nPort != INTERNET_DEFAULT_HTTP_PORT &&
|
|
|
|
urlComponents.nPort != INTERNET_DEFAULT_HTTPS_PORT)
|
|
|
|
{
|
|
|
|
int len;
|
2006-05-24 08:22:38 +02:00
|
|
|
static const WCHAR fmt[] = {'%','s',':','%','i',0};
|
2005-11-28 17:31:02 +01:00
|
|
|
len = lstrlenW(hostName);
|
2005-11-29 11:35:19 +01:00
|
|
|
len += 7; /* 5 for strlen("65535") + 1 for ":" + 1 for '\0' */
|
|
|
|
lpwhs->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
sprintfW(lpwhs->lpszHostName, fmt, hostName, urlComponents.nPort);
|
2005-11-28 17:31:02 +01:00
|
|
|
}
|
|
|
|
else
|
2005-11-29 11:35:19 +01:00
|
|
|
lpwhs->lpszHostName = WININET_strdupW(hostName);
|
2005-11-28 17:31:02 +01:00
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
HTTP_ProcessHeader(lpwhr, szHost, lpwhs->lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
|
2005-11-28 17:31:02 +01:00
|
|
|
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName);
|
2006-03-10 13:28:52 +01:00
|
|
|
lpwhs->lpszUserName = NULL;
|
|
|
|
if (userName[0])
|
|
|
|
lpwhs->lpszUserName = WININET_strdupW(userName);
|
2002-12-07 00:20:31 +01:00
|
|
|
lpwhs->nServerPort = urlComponents.nPort;
|
|
|
|
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RESOLVING_NAME,
|
|
|
|
lpwhs->lpszServerName,
|
|
|
|
strlenW(lpwhs->lpszServerName)+1);
|
2002-12-07 00:20:31 +01:00
|
|
|
|
|
|
|
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
2005-11-15 19:16:55 +01:00
|
|
|
&lpwhs->socketAddress))
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-05 14:37:06 +01:00
|
|
|
inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr,
|
|
|
|
szaddr, sizeof(szaddr));
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_NAME_RESOLVED,
|
2006-01-05 14:37:06 +01:00
|
|
|
szaddr, strlen(szaddr)+1);
|
2002-12-07 00:20:31 +01:00
|
|
|
|
2005-11-29 11:25:31 +01:00
|
|
|
NETCON_close(&lpwhr->netConnection);
|
2006-03-06 18:31:09 +01:00
|
|
|
|
|
|
|
if (!NETCON_init(&lpwhr->netConnection,lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE))
|
|
|
|
return FALSE;
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
|
2002-12-07 00:20:31 +01:00
|
|
|
lpwhr->lpszPath=NULL;
|
2004-03-30 06:36:09 +02:00
|
|
|
if (strlenW(path))
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
|
|
|
DWORD needed = 0;
|
|
|
|
HRESULT rc;
|
2004-03-30 06:36:09 +02:00
|
|
|
|
|
|
|
rc = UrlEscapeW(path, NULL, &needed, URL_ESCAPE_SPACES_ONLY);
|
2002-12-07 00:20:31 +01:00
|
|
|
if (rc != E_POINTER)
|
2004-03-30 06:36:09 +02:00
|
|
|
needed = strlenW(path)+1;
|
|
|
|
lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, needed*sizeof(WCHAR));
|
|
|
|
rc = UrlEscapeW(path, lpwhr->lpszPath, &needed,
|
2002-12-07 00:20:31 +01:00
|
|
|
URL_ESCAPE_SPACES_ONLY);
|
|
|
|
if (rc)
|
|
|
|
{
|
2006-10-05 13:18:56 +02:00
|
|
|
ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(path),rc);
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(lpwhr->lpszPath,path);
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-30 12:31:22 +01:00
|
|
|
return HTTP_HttpSendRequestW(lpwhr, lpszHeaders, dwHeaderLength, lpOptional,
|
|
|
|
dwOptionalLength, dwContentLength, TRUE);
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
|
|
|
|
2004-07-04 02:24:47 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_build_req (internal)
|
|
|
|
*
|
|
|
|
* concatenate all the strings in the request together
|
|
|
|
*/
|
|
|
|
static LPWSTR HTTP_build_req( LPCWSTR *list, int len )
|
|
|
|
{
|
|
|
|
LPCWSTR *t;
|
|
|
|
LPWSTR str;
|
|
|
|
|
|
|
|
for( t = list; *t ; t++ )
|
|
|
|
len += strlenW( *t );
|
|
|
|
len++;
|
|
|
|
|
|
|
|
str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
*str = 0;
|
|
|
|
|
|
|
|
for( t = list; *t ; t++ )
|
|
|
|
strcatW( str, *t );
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2005-11-28 11:55:16 +01:00
|
|
|
static BOOL HTTP_SecureProxyConnect(LPWININETHTTPREQW lpwhr)
|
|
|
|
{
|
|
|
|
LPWSTR lpszPath;
|
|
|
|
LPWSTR requestString;
|
|
|
|
INT len;
|
|
|
|
INT cnt;
|
|
|
|
INT responseLen;
|
|
|
|
char *ascii_req;
|
|
|
|
BOOL ret;
|
|
|
|
static const WCHAR szConnect[] = {'C','O','N','N','E','C','T',0};
|
|
|
|
static const WCHAR szFormat[] = {'%','s',':','%','d',0};
|
|
|
|
LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW)lpwhr->hdr.lpwhparent;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
lpszPath = HeapAlloc( GetProcessHeap(), 0, (lstrlenW( lpwhs->lpszHostName ) + 13)*sizeof(WCHAR) );
|
|
|
|
sprintfW( lpszPath, szFormat, lpwhs->lpszHostName, lpwhs->nHostPort );
|
|
|
|
requestString = HTTP_BuildHeaderRequestString( lpwhr, szConnect, lpszPath, FALSE );
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpszPath );
|
|
|
|
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, requestString, -1,
|
|
|
|
NULL, 0, NULL, NULL );
|
|
|
|
len--; /* the nul terminator isn't needed */
|
|
|
|
ascii_req = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, requestString, -1,
|
|
|
|
ascii_req, len, NULL, NULL );
|
|
|
|
HeapFree( GetProcessHeap(), 0, requestString );
|
|
|
|
|
|
|
|
TRACE("full request -> %s\n", debugstr_an( ascii_req, len ) );
|
|
|
|
|
|
|
|
ret = NETCON_send( &lpwhr->netConnection, ascii_req, len, 0, &cnt );
|
|
|
|
HeapFree( GetProcessHeap(), 0, ascii_req );
|
|
|
|
if (!ret || cnt < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
responseLen = HTTP_GetResponseHeaders( lpwhr );
|
|
|
|
if (!responseLen)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
2004-03-30 06:36:09 +02:00
|
|
|
* HTTP_HttpSendRequestW (internal)
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
|
2005-11-30 12:31:22 +01:00
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
|
|
|
|
DWORD dwContentLength, BOOL bEndRequest)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
INT cnt;
|
|
|
|
BOOL bSuccess = FALSE;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR requestString = NULL;
|
2002-06-22 01:59:49 +02:00
|
|
|
INT responseLen;
|
2003-06-21 01:26:56 +02:00
|
|
|
BOOL loop_next = FALSE;
|
2004-09-20 21:10:31 +02:00
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2005-12-13 17:07:41 +01:00
|
|
|
LPHTTPHEADERW Host;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
TRACE("--> %p\n", lpwhr);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
assert(lpwhr->hdr.htype == WH_HHTTPREQ);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
2005-11-21 16:17:55 +01:00
|
|
|
HTTP_FixVerb(lpwhr);
|
|
|
|
|
2003-08-05 20:31:02 +02:00
|
|
|
/* if we are using optional stuff, we must add the fixed header of that option length */
|
2005-11-30 12:31:22 +01:00
|
|
|
if (dwContentLength > 0)
|
2003-08-05 20:31:02 +02:00
|
|
|
{
|
2004-06-14 19:57:26 +02:00
|
|
|
static const WCHAR szContentLength[] = {
|
|
|
|
'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','l','i','\r','\n',0};
|
|
|
|
WCHAR contentLengthStr[sizeof szContentLength/2 /* includes \n\r */ + 20 /* int */ ];
|
2005-11-30 12:31:22 +01:00
|
|
|
sprintfW(contentLengthStr, szContentLength, dwContentLength);
|
2006-10-20 15:39:00 +02:00
|
|
|
HTTP_HttpAddRequestHeadersW(lpwhr, contentLengthStr, -1L,
|
|
|
|
HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE);
|
2003-08-05 20:31:02 +02:00
|
|
|
}
|
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
Host = HTTP_GetHeader(lpwhr,szHost);
|
2003-06-21 01:26:56 +02:00
|
|
|
do
|
2001-10-04 20:12:41 +02:00
|
|
|
{
|
2005-11-21 16:17:55 +01:00
|
|
|
DWORD len;
|
2004-07-04 02:24:47 +02:00
|
|
|
char *ascii_req;
|
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
TRACE("Going to url %s %s\n", debugstr_w(Host->lpszValue), debugstr_w(lpwhr->lpszPath));
|
2003-06-21 01:26:56 +02:00
|
|
|
loop_next = FALSE;
|
2001-10-04 20:12:41 +02:00
|
|
|
|
2005-11-21 16:17:55 +01:00
|
|
|
HTTP_FixURL(lpwhr);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-21 21:36:34 +02:00
|
|
|
/* add the headers the caller supplied */
|
2004-08-11 01:41:35 +02:00
|
|
|
if( lpszHeaders && dwHeaderLength )
|
2004-07-21 21:36:34 +02:00
|
|
|
{
|
2004-08-11 01:41:35 +02:00
|
|
|
HTTP_HttpAddRequestHeadersW(lpwhr, lpszHeaders, dwHeaderLength,
|
|
|
|
HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE);
|
2004-07-21 21:36:34 +02:00
|
|
|
}
|
|
|
|
|
2005-11-21 16:17:55 +01:00
|
|
|
/* if there's a proxy username and password, add it to the headers */
|
|
|
|
HTTP_AddProxyInfo(lpwhr);
|
2004-12-06 12:40:57 +01:00
|
|
|
|
2005-11-28 11:55:16 +01:00
|
|
|
requestString = HTTP_BuildHeaderRequestString(lpwhr, lpwhr->lpszVerb, lpwhr->lpszPath, FALSE);
|
2004-07-04 02:24:47 +02:00
|
|
|
|
|
|
|
TRACE("Request header -> %s\n", debugstr_w(requestString) );
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Send the request and store the results */
|
|
|
|
if (!HTTP_OpenConnection(lpwhr))
|
|
|
|
goto lend;
|
|
|
|
|
2004-07-04 02:24:47 +02:00
|
|
|
/* send the request as ASCII, tack on the optional data */
|
|
|
|
if( !lpOptional )
|
|
|
|
dwOptionalLength = 0;
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, requestString, -1,
|
|
|
|
NULL, 0, NULL, NULL );
|
|
|
|
ascii_req = HeapAlloc( GetProcessHeap(), 0, len + dwOptionalLength );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, requestString, -1,
|
|
|
|
ascii_req, len, NULL, NULL );
|
|
|
|
if( lpOptional )
|
2004-07-21 21:36:34 +02:00
|
|
|
memcpy( &ascii_req[len-1], lpOptional, dwOptionalLength );
|
|
|
|
len = (len + dwOptionalLength - 1);
|
|
|
|
ascii_req[len] = 0;
|
2005-10-19 20:28:35 +02:00
|
|
|
TRACE("full request -> %s\n", debugstr_a(ascii_req) );
|
2004-07-21 21:36:34 +02:00
|
|
|
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
|
2004-07-21 21:36:34 +02:00
|
|
|
|
2004-07-04 02:24:47 +02:00
|
|
|
NETCON_send(&lpwhr->netConnection, ascii_req, len, 0, &cnt);
|
|
|
|
HeapFree( GetProcessHeap(), 0, ascii_req );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_REQUEST_SENT,
|
|
|
|
&len, sizeof(DWORD));
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2005-11-30 12:31:22 +01:00
|
|
|
if (bEndRequest)
|
|
|
|
{
|
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
|
|
|
|
|
|
|
|
if (cnt < 0)
|
|
|
|
goto lend;
|
|
|
|
|
|
|
|
responseLen = HTTP_GetResponseHeaders(lpwhr);
|
|
|
|
if (responseLen)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen,
|
|
|
|
sizeof(DWORD));
|
|
|
|
|
|
|
|
HTTP_ProcessHeaders(lpwhr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bSuccess = TRUE;
|
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:
|
|
|
|
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, requestString);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
/* TODO: send notification for P3P header */
|
|
|
|
|
2005-11-30 12:31:22 +01:00
|
|
|
if(!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT) && bSuccess && bEndRequest)
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
|
|
|
DWORD dwCode,dwCodeLength=sizeof(DWORD),dwIndex=0;
|
2004-06-14 19:57:26 +02:00
|
|
|
if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,&dwCode,&dwCodeLength,&dwIndex) &&
|
2002-12-07 00:20:31 +01:00
|
|
|
(dwCode==302 || dwCode==301))
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR szNewLocation[2048];
|
2002-12-07 00:20:31 +01:00
|
|
|
DWORD dwBufferSize=2048;
|
|
|
|
dwIndex=0;
|
2004-06-14 19:57:26 +02:00
|
|
|
if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,&dwIndex))
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_REDIRECT, szNewLocation,
|
|
|
|
dwBufferSize);
|
2002-12-07 00:20:31 +01:00
|
|
|
return HTTP_HandleRedirect(lpwhr, szNewLocation, lpszHeaders,
|
2005-11-30 12:31:22 +01:00
|
|
|
dwHeaderLength, lpOptional, dwOptionalLength,
|
|
|
|
dwContentLength);
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_REQUEST_COMPLETE, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
TRACE("<--\n");
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_Connect (internal)
|
|
|
|
*
|
|
|
|
* Create http session handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a session handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-07-19 23:49:39 +02:00
|
|
|
HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
|
2004-03-30 06:36:09 +02:00
|
|
|
INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
|
2004-05-13 07:17:25 +02:00
|
|
|
LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
|
|
|
|
DWORD dwInternalFlags)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs = NULL;
|
2004-02-07 02:03:41 +01:00
|
|
|
HINTERNET handle = 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
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
assert( hIC->hdr.htype == WH_HINIT );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
hIC->hdr.dwContext = dwContext;
|
2003-04-14 23:32:36 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPSESSIONW));
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL == lpwhs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto lerror;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
lpwhs->hdr.htype = WH_HHTTPSESSION;
|
2004-07-19 23:49:39 +02:00
|
|
|
lpwhs->hdr.lpwhparent = WININET_AddRef( &hIC->hdr );
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhs->hdr.dwFlags = dwFlags;
|
|
|
|
lpwhs->hdr.dwContext = dwContext;
|
2004-05-13 07:17:25 +02:00
|
|
|
lpwhs->hdr.dwInternalFlags = dwInternalFlags;
|
2004-07-19 23:49:39 +02:00
|
|
|
lpwhs->hdr.dwRefCount = 1;
|
|
|
|
lpwhs->hdr.destroy = HTTP_CloseHTTPSessionHandle;
|
2004-09-20 21:10:31 +02:00
|
|
|
lpwhs->hdr.lpfnStatusCB = hIC->hdr.lpfnStatusCB;
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
handle = WININET_AllocHandle( &lpwhs->hdr );
|
|
|
|
if (NULL == handle)
|
|
|
|
{
|
|
|
|
ERR("Failed to alloc handle\n");
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto lerror;
|
|
|
|
}
|
|
|
|
|
2003-04-14 23:32:36 +02:00
|
|
|
if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
|
2004-03-25 06:29:47 +01:00
|
|
|
if(strchrW(hIC->lpszProxy, ' '))
|
2003-04-14 23:32:36 +02:00
|
|
|
FIXME("Several proxies not implemented.\n");
|
|
|
|
if(hIC->lpszProxyBypass)
|
|
|
|
FIXME("Proxy bypass is ignored.\n");
|
|
|
|
}
|
2006-03-10 13:28:52 +01:00
|
|
|
if (lpszServerName && lpszServerName[0])
|
2005-11-28 10:40:42 +01:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs->lpszServerName = WININET_strdupW(lpszServerName);
|
2005-11-28 10:40:42 +01:00
|
|
|
lpwhs->lpszHostName = WININET_strdupW(lpszServerName);
|
|
|
|
}
|
2006-03-10 13:28:52 +01:00
|
|
|
if (lpszUserName && lpszUserName[0])
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs->lpszUserName = WININET_strdupW(lpszUserName);
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhs->nServerPort = nServerPort;
|
2005-11-28 11:53:05 +01:00
|
|
|
lpwhs->nHostPort = nServerPort;
|
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 */
|
2004-09-20 21:10:31 +02:00
|
|
|
if (!(lpwhs->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,
|
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &handle,
|
|
|
|
sizeof(handle));
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
lerror:
|
2004-07-19 23:49:39 +02:00
|
|
|
if( lpwhs )
|
|
|
|
WININET_Release( &lpwhs->hdr );
|
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
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
TRACE("%p --> %p (%p)\n", hIC, handle, lpwhs);
|
2004-02-07 02:03:41 +01:00
|
|
|
return handle;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_OpenConnection (internal)
|
|
|
|
*
|
|
|
|
* Connect to a web server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*/
|
2005-10-26 12:07:58 +02:00
|
|
|
static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2006-01-05 14:37:06 +01:00
|
|
|
char szaddr[32];
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
TRACE("-->\n");
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs = (LPWININETHTTPSESSIONW)lpwhr->hdr.lpwhparent;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
2006-01-05 14:37:06 +01:00
|
|
|
inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr,
|
|
|
|
szaddr, sizeof(szaddr));
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTING_TO_SERVER,
|
2006-01-05 14:37:06 +01:00
|
|
|
szaddr,
|
|
|
|
strlen(szaddr)+1);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2005-11-15 19:16:55 +01:00
|
|
|
if (!NETCON_create(&lpwhr->netConnection, lpwhs->socketAddress.sin_family,
|
2003-06-21 01:26:56 +02:00
|
|
|
SOCK_STREAM, 0))
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
WARN("Socket creation failed\n");
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (!NETCON_connect(&lpwhr->netConnection, (struct sockaddr *)&lpwhs->socketAddress,
|
|
|
|
sizeof(lpwhs->socketAddress)))
|
2000-06-11 22:04:44 +02:00
|
|
|
goto lend;
|
|
|
|
|
2005-11-28 11:54:31 +01:00
|
|
|
if (lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE)
|
|
|
|
{
|
2005-11-28 11:55:16 +01:00
|
|
|
/* Note: we differ from Microsoft's WinINet here. they seem to have
|
|
|
|
* a bug that causes no status callbacks to be sent when starting
|
|
|
|
* a tunnel to a proxy server using the CONNECT verb. i believe our
|
|
|
|
* behaviour to be more correct and to not cause any incompatibilities
|
|
|
|
* because using a secure connection through a proxy server is a rare
|
|
|
|
* case that would be hard for anyone to depend on */
|
|
|
|
if (hIC->lpszProxy && !HTTP_SecureProxyConnect(lpwhr))
|
|
|
|
goto lend;
|
|
|
|
|
2005-11-28 11:54:31 +01:00
|
|
|
if (!NETCON_secure_connect(&lpwhr->netConnection, lpwhs->lpszHostName))
|
|
|
|
{
|
|
|
|
WARN("Couldn't connect securely to host\n");
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTED_TO_SERVER,
|
2006-01-05 14:37:06 +01:00
|
|
|
szaddr, strlen(szaddr)+1);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
lend:
|
2002-06-22 01:59:49 +02:00
|
|
|
TRACE("%d <--\n", bSuccess);
|
2000-06-11 22:04:44 +02:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-15 20:57:32 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_clear_response_headers (internal)
|
|
|
|
*
|
|
|
|
* clear out any old response headers
|
|
|
|
*/
|
|
|
|
static void HTTP_clear_response_headers( LPWININETHTTPREQW lpwhr )
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for( i=0; i<lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if( !lpwhr->pCustHeaders[i].lpszField )
|
|
|
|
continue;
|
|
|
|
if( !lpwhr->pCustHeaders[i].lpszValue )
|
|
|
|
continue;
|
|
|
|
if ( lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST )
|
|
|
|
continue;
|
2005-03-10 12:14:24 +01:00
|
|
|
HTTP_DeleteCustomHeader( lpwhr, i );
|
|
|
|
i--;
|
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
|
|
|
|
*/
|
2005-11-28 11:55:16 +01:00
|
|
|
static INT HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr)
|
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;
|
|
|
|
BOOL bSuccess = FALSE;
|
2002-06-22 01:59:49 +02:00
|
|
|
INT rc = 0;
|
2004-07-19 22:09:20 +02:00
|
|
|
static const WCHAR szCrLf[] = {'\r','\n',0};
|
2004-03-30 06:36:09 +02:00
|
|
|
char bufferA[MAX_REPLY_LEN];
|
2004-07-15 20:57:32 +02:00
|
|
|
LPWSTR status_code, status_text;
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD cchMaxRawHeaders = 1024;
|
2004-07-19 22:09:20 +02:00
|
|
|
LPWSTR lpszRawHeaders = HeapAlloc(GetProcessHeap(), 0, (cchMaxRawHeaders+1)*sizeof(WCHAR));
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD cchRawHeaders = 0;
|
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
|
|
|
|
2004-07-15 20:57:32 +02:00
|
|
|
/* clear old response headers (eg. from a redirect response) */
|
|
|
|
HTTP_clear_response_headers( lpwhr );
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (!NETCON_connected(&lpwhr->netConnection))
|
2000-06-11 22:04:44 +02:00
|
|
|
goto lend;
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
/*
|
|
|
|
* HACK peek at the buffer
|
|
|
|
*/
|
2003-06-21 01:26:56 +02:00
|
|
|
NETCON_recv(&lpwhr->netConnection, buffer, buflen, MSG_PEEK, &rc);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2004-07-15 20:57:32 +02:00
|
|
|
* We should first receive 'HTTP/1.x nnn OK' where nnn is the status code.
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2002-06-22 01:59:49 +02:00
|
|
|
buflen = MAX_REPLY_LEN;
|
2003-06-21 01:26:56 +02:00
|
|
|
memset(buffer, 0, MAX_REPLY_LEN);
|
2004-03-30 06:36:09 +02:00
|
|
|
if (!NETCON_getNextLine(&lpwhr->netConnection, bufferA, &buflen))
|
2000-06-11 22:04:44 +02:00
|
|
|
goto lend;
|
2004-03-30 06:36:09 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-07-19 22:09:20 +02:00
|
|
|
/* regenerate raw headers */
|
|
|
|
while (cchRawHeaders + buflen + strlenW(szCrLf) > cchMaxRawHeaders)
|
|
|
|
{
|
|
|
|
cchMaxRawHeaders *= 2;
|
|
|
|
lpszRawHeaders = HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders, (cchMaxRawHeaders+1)*sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
memcpy(lpszRawHeaders+cchRawHeaders, buffer, (buflen-1)*sizeof(WCHAR));
|
|
|
|
cchRawHeaders += (buflen-1);
|
|
|
|
memcpy(lpszRawHeaders+cchRawHeaders, szCrLf, sizeof(szCrLf));
|
|
|
|
cchRawHeaders += sizeof(szCrLf)/sizeof(szCrLf[0])-1;
|
|
|
|
lpszRawHeaders[cchRawHeaders] = '\0';
|
|
|
|
|
2004-07-15 20:57:32 +02:00
|
|
|
/* split the version from the status code */
|
|
|
|
status_code = strchrW( buffer, ' ' );
|
|
|
|
if( !status_code )
|
|
|
|
goto lend;
|
|
|
|
*status_code++=0;
|
|
|
|
|
|
|
|
/* split the status code from the status text */
|
|
|
|
status_text = strchrW( status_code, ' ' );
|
|
|
|
if( !status_text )
|
|
|
|
goto lend;
|
|
|
|
*status_text++=0;
|
|
|
|
|
|
|
|
TRACE("version [%s] status code [%s] status text [%s]\n",
|
|
|
|
debugstr_w(buffer), debugstr_w(status_code), debugstr_w(status_text) );
|
2005-12-13 17:07:41 +01:00
|
|
|
|
|
|
|
HTTP_ProcessHeader(lpwhr, szStatus, status_code,
|
|
|
|
HTTP_ADDHDR_FLAG_REPLACE);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,lpwhr->lpszVersion);
|
|
|
|
HeapFree(GetProcessHeap(),0,lpwhr->lpszStatusText);
|
|
|
|
|
|
|
|
lpwhr->lpszVersion= WININET_strdupW(buffer);
|
|
|
|
lpwhr->lpszStatusText = WININET_strdupW(status_text);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
/* Parse each response line */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
buflen = MAX_REPLY_LEN;
|
2004-03-30 06:36:09 +02:00
|
|
|
if (NETCON_getNextLine(&lpwhr->netConnection, bufferA, &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));
|
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
|
|
|
|
|
|
|
while (cchRawHeaders + buflen + strlenW(szCrLf) > cchMaxRawHeaders)
|
|
|
|
{
|
|
|
|
cchMaxRawHeaders *= 2;
|
|
|
|
lpszRawHeaders = HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders, (cchMaxRawHeaders+1)*sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
memcpy(lpszRawHeaders+cchRawHeaders, buffer, (buflen-1)*sizeof(WCHAR));
|
|
|
|
cchRawHeaders += (buflen-1);
|
|
|
|
memcpy(lpszRawHeaders+cchRawHeaders, szCrLf, sizeof(szCrLf));
|
|
|
|
cchRawHeaders += sizeof(szCrLf)/sizeof(szCrLf[0])-1;
|
|
|
|
lpszRawHeaders[cchRawHeaders] = '\0';
|
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
pFieldAndValue = HTTP_InterpretHttpHeader(buffer);
|
|
|
|
if (!pFieldAndValue)
|
2000-06-11 22:04:44 +02:00
|
|
|
break;
|
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
HTTP_ProcessHeader(lpwhr, pFieldAndValue[0], pFieldAndValue[1],
|
2005-12-13 17:07:41 +01:00
|
|
|
HTTP_ADDREQ_FLAG_ADD );
|
2004-09-24 00:53:50 +02:00
|
|
|
|
|
|
|
HTTP_FreeTokens(pFieldAndValue);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cbreaks++;
|
|
|
|
if (cbreaks >= 2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}while(1);
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders);
|
2004-07-19 22:09:20 +02:00
|
|
|
lpwhr->lpszRawHeaders = lpszRawHeaders;
|
|
|
|
TRACE("raw headers: %s\n", debugstr_w(lpszRawHeaders));
|
2000-06-11 22:04:44 +02:00
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
lend:
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
TRACE("<--\n");
|
|
|
|
if (bSuccess)
|
|
|
|
return rc;
|
|
|
|
else
|
2005-11-28 11:55:16 +01:00
|
|
|
return 0;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
static void strip_spaces(LPWSTR start)
|
|
|
|
{
|
|
|
|
LPWSTR str = start;
|
|
|
|
LPWSTR end;
|
|
|
|
|
|
|
|
while (*str == ' ' && *str != '\0')
|
|
|
|
str++;
|
|
|
|
|
|
|
|
if (str != start)
|
|
|
|
memmove(start, str, sizeof(WCHAR) * (strlenW(str) + 1));
|
|
|
|
|
|
|
|
end = start + strlenW(start) - 1;
|
|
|
|
while (end >= start && *end == ' ')
|
|
|
|
{
|
|
|
|
*end = '\0';
|
|
|
|
end--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
pTokenPair = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 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
|
|
|
}
|
|
|
|
|
2004-09-24 00:53:50 +02:00
|
|
|
pTokenPair[0] = HeapAlloc(GetProcessHeap(), 0, (pszColon - buffer + 1) * sizeof(WCHAR));
|
|
|
|
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);
|
|
|
|
pTokenPair[1] = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
|
|
|
|
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>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COALESCEFLASG (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
|
|
|
|
|
2005-10-26 12:07:58 +02:00
|
|
|
static BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, 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;
|
2000-06-11 22:04:44 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
2005-12-13 17:07:41 +01:00
|
|
|
INT index = -1;
|
|
|
|
static const WCHAR szConnection[] = { 'C','o','n','n','e','c','t','i','o','n',0 };
|
|
|
|
BOOL request_only = dwModifier & HTTP_ADDHDR_FLAG_REQ;
|
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
|
|
|
|
2004-09-14 21:38:59 +02:00
|
|
|
/* Don't let applications add Connection header to request */
|
2005-12-13 17:07:41 +01:00
|
|
|
if (strcmpW(szConnection,field)==0 && (dwModifier & HTTP_ADDHDR_FLAG_REQ))
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
return FALSE;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
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
|
|
|
|
index = HTTP_GetCustomHeaderIndex(lpwhr, field, 0, request_only);
|
|
|
|
|
|
|
|
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)
|
2002-06-22 01:59:49 +02:00
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
return FALSE;
|
2002-06-22 01:59:49 +02:00
|
|
|
}
|
2005-12-13 17:07:41 +01:00
|
|
|
lphttpHdr = &lpwhr->pCustHeaders[index];
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
return HTTP_InsertCustomHeader(lpwhr, &hdr);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
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
|
|
|
{
|
2005-12-13 17:07:41 +01:00
|
|
|
HTTP_DeleteCustomHeader( lpwhr, index );
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
if (value)
|
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;
|
|
|
|
|
|
|
|
return HTTP_InsertCustomHeader(lpwhr, &hdr);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (dwModifier & COALESCEFLASG)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2005-12-13 17:07:41 +01:00
|
|
|
lpsztmp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR));
|
|
|
|
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';
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("HeapReAlloc (%d bytes) failed\n",len+1);
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
}
|
2002-12-07 00:20:31 +01:00
|
|
|
TRACE("<-- %d\n",bSuccess);
|
2000-06-11 22:04:44 +02:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_CloseConnection (internal)
|
|
|
|
*
|
|
|
|
* Close socket connection
|
|
|
|
*
|
|
|
|
*/
|
2005-10-26 12:07:58 +02:00
|
|
|
static VOID HTTP_CloseConnection(LPWININETHTTPREQW lpwhr)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs = NULL;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
TRACE("%p\n",lpwhr);
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
|
2004-03-25 06:29:47 +01:00
|
|
|
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CLOSING_CONNECTION, 0, 0);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (NETCON_connected(&lpwhr->netConnection))
|
|
|
|
{
|
|
|
|
NETCON_close(&lpwhr->netConnection);
|
|
|
|
}
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2005-11-29 10:44:05 +01:00
|
|
|
INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTION_CLOSED, 0, 0);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_CloseHTTPRequestHandle (internal)
|
|
|
|
*
|
|
|
|
* Deallocate request handle
|
|
|
|
*
|
|
|
|
*/
|
2004-07-19 23:49:39 +02:00
|
|
|
static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD i;
|
2004-07-19 23:49:39 +02:00
|
|
|
LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) hdr;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (NETCON_connected(&lpwhr->netConnection))
|
2000-06-11 22:04:44 +02:00
|
|
|
HTTP_CloseConnection(lpwhr);
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders);
|
2005-12-13 17:07:41 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszVersion);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszStatusText);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
2005-01-03 15:56:42 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszField);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszValue);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_CloseHTTPSessionHandle (internal)
|
|
|
|
*
|
|
|
|
* Deallocate session handle
|
|
|
|
*
|
|
|
|
*/
|
2005-10-26 12:07:58 +02:00
|
|
|
static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) hdr;
|
2004-02-07 02:03:41 +01:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
TRACE("%p\n", lpwhs);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2005-11-28 10:40:42 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszHostName);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName);
|
2000-06-11 22:04:44 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetCustomHeaderIndex (internal)
|
|
|
|
*
|
|
|
|
* Return index of custom header from header array
|
|
|
|
*
|
|
|
|
*/
|
2006-03-30 11:20:04 +02:00
|
|
|
static INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField,
|
|
|
|
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
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("%s\n", debugstr_w(lpszField));
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
for (index = 0; index < lpwhr->nCustHeaders; index++)
|
|
|
|
{
|
2006-03-30 11:20:04 +02:00
|
|
|
if (strcmpiW(lpwhr->pCustHeaders[index].lpszField, lpszField))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (request_only && !(lpwhr->pCustHeaders[index].wFlags & HDR_ISREQUEST))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!request_only && (lpwhr->pCustHeaders[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
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= lpwhr->nCustHeaders)
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
2005-10-26 12:07:58 +02:00
|
|
|
static BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
INT count;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPHTTPHEADERW lph = NULL;
|
2003-07-22 05:17:52 +02:00
|
|
|
BOOL r = FALSE;
|
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));
|
2000-06-11 22:04:44 +02:00
|
|
|
count = lpwhr->nCustHeaders + 1;
|
|
|
|
if (count > 1)
|
2004-03-30 06:36:09 +02:00
|
|
|
lph = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpwhr->pCustHeaders, sizeof(HTTPHEADERW) * count);
|
2000-06-11 22:04:44 +02:00
|
|
|
else
|
2004-03-30 06:36:09 +02:00
|
|
|
lph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HTTPHEADERW) * count);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
if (NULL != lph)
|
|
|
|
{
|
|
|
|
lpwhr->pCustHeaders = lph;
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhr->pCustHeaders[count-1].lpszField = WININET_strdupW(lpHdr->lpszField);
|
|
|
|
lpwhr->pCustHeaders[count-1].lpszValue = WININET_strdupW(lpHdr->lpszValue);
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhr->pCustHeaders[count-1].wFlags = lpHdr->wFlags;
|
|
|
|
lpwhr->pCustHeaders[count-1].wCount= lpHdr->wCount;
|
|
|
|
lpwhr->nCustHeaders++;
|
2003-07-22 05:17:52 +02:00
|
|
|
r = TRUE;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
return r;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_DeleteCustomHeader (internal)
|
|
|
|
*
|
|
|
|
* Delete header from array
|
2003-07-22 05:17:52 +02:00
|
|
|
* If this function is called, the indexs may change.
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
2005-10-26 12:07:58 +02:00
|
|
|
static BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, DWORD index)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2003-07-22 05:17:52 +02:00
|
|
|
if( lpwhr->nCustHeaders <= 0 )
|
|
|
|
return FALSE;
|
2005-03-10 12:14:24 +01:00
|
|
|
if( index >= lpwhr->nCustHeaders )
|
2003-07-22 05:17:52 +02:00
|
|
|
return FALSE;
|
|
|
|
lpwhr->nCustHeaders--;
|
|
|
|
|
|
|
|
memmove( &lpwhr->pCustHeaders[index], &lpwhr->pCustHeaders[index+1],
|
2004-03-30 06:36:09 +02:00
|
|
|
(lpwhr->nCustHeaders - index)* sizeof(HTTPHEADERW) );
|
|
|
|
memset( &lpwhr->pCustHeaders[lpwhr->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
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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;
|
|
|
|
}
|