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
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
|
|
|
* Ulrich Czekalla
|
2002-06-22 01:59:49 +02:00
|
|
|
* Aric Stewart
|
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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-06-11 22:04:44 +02:00
|
|
|
*/
|
|
|
|
|
2000-06-23 17:47:14 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
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
|
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
|
2000-06-11 22:04:44 +02:00
|
|
|
#include <errno.h>
|
2001-01-22 03:17:29 +01:00
|
|
|
#include <string.h>
|
2001-02-15 22:24:07 +01:00
|
|
|
#include <time.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
|
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
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
const WCHAR g_szHttp[] = {' ','H','T','T','P','/','1','.','0',0 };
|
|
|
|
const WCHAR g_szHost[] = {'\r','\n','H','o','s','t',':',' ',0 };
|
|
|
|
const WCHAR g_szReferer[] = {'R','e','f','e','r','e','r',0};
|
|
|
|
const WCHAR g_szAccept[] = {'A','c','c','e','p','t',0};
|
|
|
|
const WCHAR g_szUserAgent[] = {'U','s','e','r','-','A','g','e','n','t',0};
|
|
|
|
|
|
|
|
|
|
|
|
#define HTTPHEADER g_szHttp
|
|
|
|
#define HTTPHOSTHEADER g_szHost
|
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-03-30 06:36:09 +02:00
|
|
|
BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr);
|
|
|
|
int HTTP_WriteDataToStream(LPWININETHTTPREQW lpwhr,
|
2000-06-11 22:04:44 +02:00
|
|
|
void *Buffer, int BytesToWrite);
|
2004-03-30 06:36:09 +02:00
|
|
|
int HTTP_ReadDataFromStream(LPWININETHTTPREQW lpwhr,
|
2000-06-11 22:04:44 +02:00
|
|
|
void *Buffer, int BytesToRead);
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr);
|
|
|
|
BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier);
|
|
|
|
void HTTP_CloseConnection(LPWININETHTTPREQW lpwhr);
|
|
|
|
BOOL HTTP_InterpretHttpHeader(LPWSTR buffer, LPWSTR field, INT fieldlen, LPWSTR value, INT valuelen);
|
|
|
|
INT HTTP_GetStdHeaderIndex(LPCWSTR lpszField);
|
|
|
|
BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr);
|
|
|
|
INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField);
|
|
|
|
BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, INT index);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2004-03-30 06:36:09 +02:00
|
|
|
* HttpAddRequestHeadersW (WININET.@)
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
|
|
|
* Adds one or more HTTP header to the request handler
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
|
|
|
|
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;
|
|
|
|
WCHAR value[MAX_FIELD_VALUE_LEN], field[MAX_FIELD_LEN];
|
2000-06-11 22:04:44 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPREQW lpwhr;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("%p, %s, %li, %li\n", hHttpRequest, debugstr_w(lpszHeader), dwHeaderLength,
|
2003-06-21 01:26:56 +02:00
|
|
|
dwModifier);
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest );
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-25 04:57:59 +01:00
|
|
|
if (!lpszHeader)
|
|
|
|
return TRUE;
|
2003-06-21 01:26:56 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("copying header: %s\n", debugstr_w(lpszHeader));
|
|
|
|
buffer = WININET_strdupW(lpszHeader);
|
2000-06-11 22:04:44 +02:00
|
|
|
lpszStart = buffer;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
lpszEnd = lpszStart;
|
|
|
|
|
|
|
|
while (*lpszEnd != '\0')
|
|
|
|
{
|
|
|
|
if (*lpszEnd == '\r' && *(lpszEnd + 1) == '\n')
|
|
|
|
break;
|
|
|
|
lpszEnd++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*lpszEnd == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
*lpszEnd = '\0';
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("interpreting header %s\n", debugstr_w(lpszStart));
|
2000-06-11 22:04:44 +02:00
|
|
|
if (HTTP_InterpretHttpHeader(lpszStart, field, MAX_FIELD_LEN, value, MAX_FIELD_VALUE_LEN))
|
|
|
|
bSuccess = HTTP_ProcessHeader(lpwhr, field, value, dwModifier | HTTP_ADDHDR_FLAG_REQ);
|
|
|
|
|
|
|
|
lpszStart = lpszEnd + 2; /* Jump over \0\n */
|
|
|
|
|
|
|
|
} while (bSuccess);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
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;
|
|
|
|
|
|
|
|
TRACE("%p, %s, %li, %li\n", hHttpRequest, debugstr_a(lpszHeader), dwHeaderLength,
|
|
|
|
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 );
|
|
|
|
if( dwHeaderLength != -1 )
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpEndRequestA(HINTERNET hRequest, LPINTERNET_BUFFERSA lpBuffersOut,
|
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HttpEndRequestW (WININET.@)
|
|
|
|
*
|
|
|
|
* Ends an HTTP request that was started by HttpSendRequestEx
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if successful
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpEndRequestW(HINTERNET hRequest, LPINTERNET_BUFFERSW lpBuffersOut,
|
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
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-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2004-02-07 02:03:41 +01:00
|
|
|
HINTERNET handle = NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
TRACE("(%p, %s, %s, %s, %s, %p, %08lx, %08lx)\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-02-07 02:03:41 +01:00
|
|
|
return NULL;
|
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
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* I am leaving this here just in case I am wrong
|
|
|
|
*
|
|
|
|
* if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
*/
|
|
|
|
if (0)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-03-30 06:36:09 +02:00
|
|
|
struct WORKREQ_HTTPOPENREQUESTW *req;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
workRequest.asyncall = HTTPOPENREQUESTW;
|
2003-09-25 22:25:22 +02:00
|
|
|
workRequest.handle = hHttpSession;
|
2004-03-30 06:36:09 +02:00
|
|
|
req = &workRequest.u.HttpOpenRequestW;
|
|
|
|
req->lpszVerb = WININET_strdupW(lpszVerb);
|
|
|
|
req->lpszObjectName = WININET_strdupW(lpszObjectName);
|
2002-06-22 01:59:49 +02:00
|
|
|
if (lpszVersion)
|
2004-03-30 06:36:09 +02:00
|
|
|
req->lpszVersion = WININET_strdupW(lpszVersion);
|
2002-06-22 01:59:49 +02:00
|
|
|
else
|
2003-09-25 22:25:22 +02:00
|
|
|
req->lpszVersion = 0;
|
2002-06-22 01:59:49 +02:00
|
|
|
if (lpszReferrer)
|
2004-03-30 06:36:09 +02:00
|
|
|
req->lpszReferrer = WININET_strdupW(lpszReferrer);
|
2002-06-22 01:59:49 +02:00
|
|
|
else
|
2003-09-25 22:25:22 +02:00
|
|
|
req->lpszReferrer = 0;
|
|
|
|
req->lpszAcceptTypes = lpszAcceptTypes;
|
|
|
|
req->dwFlags = dwFlags;
|
|
|
|
req->dwContext = dwContext;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
INTERNET_AsyncCall(&workRequest);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
handle = HTTP_HttpOpenRequestW(hHttpSession, lpszVerb, lpszObjectName,
|
2003-06-21 01:26:56 +02:00
|
|
|
lpszVersion, lpszReferrer, lpszAcceptTypes,
|
|
|
|
dwFlags, dwContext);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
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;
|
|
|
|
TRACE("(%p, %s, %s, %s, %s, %p, %08lx, %08lx)\n", hHttpSession,
|
2004-03-30 06:36:09 +02:00
|
|
|
debugstr_a(lpszVerb), debugstr_a(lpszObjectName),
|
|
|
|
debugstr_a(lpszVersion), debugstr_a(lpszReferrer), lpszAcceptTypes,
|
2003-06-21 01:26:56 +02:00
|
|
|
dwFlags, dwContext);
|
|
|
|
|
|
|
|
if (lpszVerb)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
if (szReferrer) HeapFree(GetProcessHeap(), 0, szReferrer);
|
|
|
|
if (szVersion) HeapFree(GetProcessHeap(), 0, szVersion);
|
|
|
|
if (szObjectName) HeapFree(GetProcessHeap(), 0, szObjectName);
|
|
|
|
if (szVerb) HeapFree(GetProcessHeap(), 0, szVerb);
|
|
|
|
|
|
|
|
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;
|
|
|
|
static LPSTR HTTP_Base64Enc =
|
|
|
|
"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;
|
|
|
|
WCHAR szBasic[] = {'B','a','s','i','c',' ',0};
|
|
|
|
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
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
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
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
HTTPHEADERW hdr;
|
|
|
|
INT index;
|
|
|
|
WCHAR szProxyAuthorization[] = {
|
|
|
|
'P','r','o','x','y','-','A','u','t','h','o','r','i','z','a','t','i','o','n',0 };
|
2003-07-22 05:17:52 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
hdr.lpszValue = HTTP_EncodeBasicAuth( username, password );
|
|
|
|
hdr.lpszField = szProxyAuthorization;
|
2003-07-22 05:17:52 +02:00
|
|
|
hdr.wFlags = HDR_ISREQUEST;
|
|
|
|
hdr.wCount = 0;
|
|
|
|
if( !hdr.lpszValue )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
TRACE("Inserting %s = %s\n",
|
2004-03-30 06:36:09 +02:00
|
|
|
debugstr_w( hdr.lpszField ), debugstr_w( hdr.lpszValue ) );
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
/* remove the old proxy authorization header */
|
|
|
|
index = HTTP_GetCustomHeaderIndex( lpwhr, hdr.lpszField );
|
|
|
|
if( index >=0 )
|
|
|
|
HTTP_DeleteCustomHeader( lpwhr, index );
|
|
|
|
|
|
|
|
HTTP_InsertCustomHeader(lpwhr, &hdr);
|
|
|
|
HeapFree( GetProcessHeap(), 0, hdr.lpszValue );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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" */
|
|
|
|
WCHAR* url, szNul[] = { 0 };
|
|
|
|
URL_COMPONENTSW UrlComponents;
|
|
|
|
WCHAR szHttp[] = { 'h','t','t','p',':','/','/',0 }, szSlash[] = { '/',0 } ;
|
|
|
|
/*WCHAR szColon[] = { ':',0 }; */
|
|
|
|
WCHAR szFormat1[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
|
|
|
|
WCHAR szFormat2[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
|
|
|
|
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,
|
|
|
|
buf,strlenW(szHttp),szHttp,strlenW(szHttp)) )
|
|
|
|
sprintfW(proxy, szFormat1, hIC->lpszProxy);
|
2003-12-15 20:47:31 +01:00
|
|
|
else
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(proxy,buf);
|
|
|
|
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 )
|
|
|
|
lpwhr->lpszPath = szNul;
|
|
|
|
TRACE("server='%s' path='%s'\n",
|
2004-03-30 06:36:09 +02:00
|
|
|
debugstr_w(lpwhs->lpszServerName), debugstr_w(lpwhr->lpszPath));
|
2003-07-22 05:17:52 +02:00
|
|
|
/* for constant 15 see above */
|
2004-03-30 06:36:09 +02:00
|
|
|
len = strlenW(lpwhs->lpszServerName) + strlenW(lpwhr->lpszPath) + 15;
|
|
|
|
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;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
sprintfW(url, szFormat2, lpwhs->lpszServerName, lpwhs->nServerPort);
|
|
|
|
|
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;
|
|
|
|
/* FIXME: Do I have to free lpwhs->lpszServerName here ? */
|
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-03-30 06:36:09 +02:00
|
|
|
HINTERNET WINAPI HTTP_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-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-02-07 02:03:41 +01:00
|
|
|
HINTERNET handle;
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR szUrlForm[] = {'h','t','t','p',':','/','/','%','s',0};
|
|
|
|
DWORD len;
|
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-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-02-07 02:03:41 +01:00
|
|
|
return NULL;
|
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
|
|
|
|
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-02-07 02:03:41 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
handle = WININET_AllocHandle( &lpwhr->hdr );
|
|
|
|
if (NULL == handle)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpwhr );
|
|
|
|
return NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lpwhr->hdr.htype = WH_HHTTPREQ;
|
2004-02-07 02:03:41 +01:00
|
|
|
lpwhr->hdr.lpwhparent = &lpwhs->hdr;
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhr->hdr.dwFlags = dwFlags;
|
|
|
|
lpwhr->hdr.dwContext = dwContext;
|
2003-06-21 01:26:56 +02:00
|
|
|
NETCON_init(&lpwhr->netConnection, dwFlags & INTERNET_FLAG_SECURE);
|
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)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
ERR("Unable to escape string!(%s) (%ld)\n",debugstr_w(lpszObjectName),rc);
|
|
|
|
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
|
|
|
{
|
|
|
|
WCHAR szGet[] = {'G','E','T',0};
|
|
|
|
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))
|
|
|
|
lpwhr->lpszHostName = WININET_strdupW(UrlComponents.lpszHostName);
|
2000-08-26 22:31:48 +02:00
|
|
|
} else {
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhr->lpszHostName = WININET_strdupW(lpwhs->lpszServerName);
|
2000-06-11 22:04:44 +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;
|
|
|
|
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-03-30 06:36:09 +02:00
|
|
|
HttpAddRequestHeadersW(handle, agent_header, strlenW(agent_header),
|
2003-06-21 01:26:56 +02:00
|
|
|
HTTP_ADDREQ_FLAG_ADD);
|
|
|
|
HeapFree(GetProcessHeap(), 0, agent_header);
|
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
len = strlenW(lpwhr->lpszHostName) + strlenW(szUrlForm);
|
|
|
|
lpszUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
sprintfW( lpszUrl, szUrlForm, lpwhr->lpszHostName );
|
|
|
|
|
|
|
|
if (InternetGetCookieW(lpszUrl, NULL, NULL, &nCookieSize))
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
|
|
|
int cnt = 0;
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR szCookie[] = {'C','o','o','k','i','e',':',' ',0};
|
|
|
|
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-03-30 06:36:09 +02:00
|
|
|
HttpAddRequestHeadersW(handle, lpszCookies, strlenW(lpszCookies),
|
2003-06-21 01:26:56 +02:00
|
|
|
HTTP_ADDREQ_FLAG_ADD);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpszCookies);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpszUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
if (hIC->lpfnStatusCB)
|
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
|
|
|
|
2004-02-09 21:55:58 +01:00
|
|
|
iar.dwResult = (DWORD)handle;
|
2000-06-11 22:04:44 +02:00
|
|
|
iar.dwError = ERROR_SUCCESS;
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
SendAsyncCallback(hIC, hHttpSession, dwContext,
|
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
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
|
|
|
|
*/
|
|
|
|
SendAsyncCallback(hIC, hHttpSession, dwContext,
|
|
|
|
INTERNET_STATUS_RESOLVING_NAME,
|
|
|
|
lpwhs->lpszServerName,
|
2004-03-30 06:36:09 +02:00
|
|
|
strlenW(lpwhs->lpszServerName)+1);
|
2002-06-22 01:59:49 +02:00
|
|
|
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
|
|
|
&lpwhs->phostent, &lpwhs->socketAddress))
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
2004-02-07 02:03:41 +01:00
|
|
|
return NULL;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
SendAsyncCallback(hIC, hHttpSession, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_NAME_RESOLVED,
|
|
|
|
&(lpwhs->socketAddress),
|
|
|
|
sizeof(struct sockaddr_in));
|
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
TRACE("<-- %p\n", handle);
|
|
|
|
return handle;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-03-30 22:37:49 +02:00
|
|
|
* HttpQueryInfoW (WININET.@)
|
2000-06-11 22:04:44 +02: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 HttpQueryInfoW(HINTERNET hHttpRequest, 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;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPREQW lpwhr;
|
|
|
|
WCHAR szFmt[] = { '%','s',':',' ','%','s','%','s',0 };
|
|
|
|
WCHAR szcrlf[] = { '\r','\n',0 };
|
|
|
|
WCHAR sznul[] = { 0 };
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-02-09 23:01:49 +01:00
|
|
|
if (TRACE_ON(wininet)) {
|
|
|
|
#define FE(x) { x, #x }
|
|
|
|
static const wininet_flag_info query_flags[] = {
|
|
|
|
FE(HTTP_QUERY_MIME_VERSION),
|
|
|
|
FE(HTTP_QUERY_CONTENT_TYPE),
|
|
|
|
FE(HTTP_QUERY_CONTENT_TRANSFER_ENCODING),
|
|
|
|
FE(HTTP_QUERY_CONTENT_ID),
|
|
|
|
FE(HTTP_QUERY_CONTENT_DESCRIPTION),
|
|
|
|
FE(HTTP_QUERY_CONTENT_LENGTH),
|
|
|
|
FE(HTTP_QUERY_CONTENT_LANGUAGE),
|
|
|
|
FE(HTTP_QUERY_ALLOW),
|
|
|
|
FE(HTTP_QUERY_PUBLIC),
|
|
|
|
FE(HTTP_QUERY_DATE),
|
|
|
|
FE(HTTP_QUERY_EXPIRES),
|
|
|
|
FE(HTTP_QUERY_LAST_MODIFIED),
|
|
|
|
FE(HTTP_QUERY_MESSAGE_ID),
|
|
|
|
FE(HTTP_QUERY_URI),
|
|
|
|
FE(HTTP_QUERY_DERIVED_FROM),
|
|
|
|
FE(HTTP_QUERY_COST),
|
|
|
|
FE(HTTP_QUERY_LINK),
|
|
|
|
FE(HTTP_QUERY_PRAGMA),
|
|
|
|
FE(HTTP_QUERY_VERSION),
|
|
|
|
FE(HTTP_QUERY_STATUS_CODE),
|
|
|
|
FE(HTTP_QUERY_STATUS_TEXT),
|
|
|
|
FE(HTTP_QUERY_RAW_HEADERS),
|
|
|
|
FE(HTTP_QUERY_RAW_HEADERS_CRLF),
|
|
|
|
FE(HTTP_QUERY_CONNECTION),
|
|
|
|
FE(HTTP_QUERY_ACCEPT),
|
|
|
|
FE(HTTP_QUERY_ACCEPT_CHARSET),
|
|
|
|
FE(HTTP_QUERY_ACCEPT_ENCODING),
|
|
|
|
FE(HTTP_QUERY_ACCEPT_LANGUAGE),
|
|
|
|
FE(HTTP_QUERY_AUTHORIZATION),
|
|
|
|
FE(HTTP_QUERY_CONTENT_ENCODING),
|
|
|
|
FE(HTTP_QUERY_FORWARDED),
|
|
|
|
FE(HTTP_QUERY_FROM),
|
|
|
|
FE(HTTP_QUERY_IF_MODIFIED_SINCE),
|
|
|
|
FE(HTTP_QUERY_LOCATION),
|
|
|
|
FE(HTTP_QUERY_ORIG_URI),
|
|
|
|
FE(HTTP_QUERY_REFERER),
|
|
|
|
FE(HTTP_QUERY_RETRY_AFTER),
|
|
|
|
FE(HTTP_QUERY_SERVER),
|
|
|
|
FE(HTTP_QUERY_TITLE),
|
|
|
|
FE(HTTP_QUERY_USER_AGENT),
|
|
|
|
FE(HTTP_QUERY_WWW_AUTHENTICATE),
|
|
|
|
FE(HTTP_QUERY_PROXY_AUTHENTICATE),
|
|
|
|
FE(HTTP_QUERY_ACCEPT_RANGES),
|
|
|
|
FE(HTTP_QUERY_SET_COOKIE),
|
|
|
|
FE(HTTP_QUERY_COOKIE),
|
|
|
|
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;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
TRACE("(%p, 0x%08lx)--> %ld\n", hHttpRequest, dwInfoLevel, dwInfoLevel);
|
|
|
|
TRACE(" Attribute:");
|
|
|
|
for (i = 0; i < (sizeof(query_flags) / sizeof(query_flags[0])); i++) {
|
|
|
|
if (query_flags[i].val == info) {
|
|
|
|
DPRINTF(" %s", query_flags[i].name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == (sizeof(query_flags) / sizeof(query_flags[0]))) {
|
|
|
|
DPRINTF(" Unknown (%08lx)", info);
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-02-09 23:01:49 +01:00
|
|
|
DPRINTF(" Modifier:");
|
|
|
|
for (i = 0; i < (sizeof(modifier_flags) / sizeof(modifier_flags[0])); i++) {
|
|
|
|
if (modifier_flags[i].val & info_mod) {
|
|
|
|
DPRINTF(" %s", modifier_flags[i].name);
|
|
|
|
info_mod &= ~ modifier_flags[i].val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info_mod) {
|
|
|
|
DPRINTF(" Unknown (%08lx)", info_mod);
|
|
|
|
}
|
|
|
|
DPRINTF("\n");
|
|
|
|
}
|
|
|
|
|
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-02-09 23:01:49 +01:00
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find requested header structure */
|
|
|
|
if ((dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK) == HTTP_QUERY_CUSTOM)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
INT index = HTTP_GetCustomHeaderIndex(lpwhr, (LPWSTR)lpBuffer);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
goto lend;
|
|
|
|
|
|
|
|
lphttpHdr = &lpwhr->pCustHeaders[index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INT index = dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK;
|
|
|
|
|
|
|
|
if (index == HTTP_QUERY_RAW_HEADERS_CRLF || index == HTTP_QUERY_RAW_HEADERS)
|
|
|
|
{
|
|
|
|
INT i, delim, size = 0, cnt = 0;
|
|
|
|
|
|
|
|
delim = index == HTTP_QUERY_RAW_HEADERS_CRLF ? 2 : 1;
|
|
|
|
|
|
|
|
/* Calculate length of custom reuqest headers */
|
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if ((~lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST) && lpwhr->pCustHeaders[i].lpszField &&
|
|
|
|
lpwhr->pCustHeaders[i].lpszValue)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
size += strlenW(lpwhr->pCustHeaders[i].lpszField) +
|
|
|
|
strlenW(lpwhr->pCustHeaders[i].lpszValue) + delim + 2;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the length of stadard request headers */
|
|
|
|
for (i = 0; i <= HTTP_QUERY_MAX; i++)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if ((~lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST) && lpwhr->StdHeaders[i].lpszField &&
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhr->StdHeaders[i].lpszValue)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
size += strlenW(lpwhr->StdHeaders[i].lpszField) +
|
|
|
|
strlenW(lpwhr->StdHeaders[i].lpszValue) + delim + 2;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
size += delim;
|
|
|
|
|
2004-03-31 22:09:54 +02:00
|
|
|
if (size + 1 > *lpdwBufferLength/sizeof(WCHAR))
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-31 22:09:54 +02:00
|
|
|
*lpdwBufferLength = (size + 1) * sizeof(WCHAR);
|
2000-06-11 22:04:44 +02:00
|
|
|
INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append standard request heades */
|
|
|
|
for (i = 0; i <= HTTP_QUERY_MAX; i++)
|
|
|
|
{
|
|
|
|
if ((~lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST) &&
|
|
|
|
lpwhr->StdHeaders[i].lpszField &&
|
|
|
|
lpwhr->StdHeaders[i].lpszValue)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
cnt += sprintfW((WCHAR*)lpBuffer + cnt, szFmt,
|
|
|
|
lpwhr->StdHeaders[i].lpszField, lpwhr->StdHeaders[i].lpszValue,
|
|
|
|
index == HTTP_QUERY_RAW_HEADERS_CRLF ? szcrlf : sznul );
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append custom request heades */
|
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if ((~lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST) &&
|
|
|
|
lpwhr->pCustHeaders[i].lpszField &&
|
|
|
|
lpwhr->pCustHeaders[i].lpszValue)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
cnt += sprintfW((WCHAR*)lpBuffer + cnt, szFmt,
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhr->pCustHeaders[i].lpszField, lpwhr->pCustHeaders[i].lpszValue,
|
2004-03-30 06:36:09 +02:00
|
|
|
index == HTTP_QUERY_RAW_HEADERS_CRLF ? szcrlf : sznul);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW((WCHAR*)lpBuffer + cnt, index == HTTP_QUERY_RAW_HEADERS_CRLF ? szcrlf : sznul);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-31 22:09:54 +02:00
|
|
|
*lpdwBufferLength = (cnt + delim) * sizeof(WCHAR);
|
|
|
|
bSuccess = TRUE;
|
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
else if (index >= 0 && index <= HTTP_QUERY_MAX && lpwhr->StdHeaders[index].lpszValue)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2000-06-11 22:04:44 +02:00
|
|
|
lphttpHdr = &lpwhr->StdHeaders[index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure header satisifies requested attributes */
|
2002-06-01 01:06:46 +02:00
|
|
|
if ((dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS) &&
|
2000-06-11 22:04:44 +02:00
|
|
|
(~lphttpHdr->wFlags & HDR_ISREQUEST))
|
|
|
|
goto lend;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
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)
|
|
|
|
goto lend;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
else if (dwInfoLevel & HTTP_QUERY_FLAG_COALESCE)
|
|
|
|
{
|
|
|
|
if (*lpdwIndex >= lphttpHdr->wCount)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_HTTP_HEADER_NOT_FOUND);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
/* Copy strncpyW(lpBuffer, lphttpHdr[*lpdwIndex], len); */
|
2000-06-11 22:04:44 +02:00
|
|
|
(*lpdwIndex)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-31 22:09:54 +02:00
|
|
|
INT 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);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
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 );
|
|
|
|
result = HttpQueryInfoW( hHttpRequest, dwInfoLevel, bufferW,
|
|
|
|
&len, lpdwIndex );
|
|
|
|
if( result )
|
2002-11-12 03:13:04 +01:00
|
|
|
{
|
2004-03-30 22:37:49 +02:00
|
|
|
len = WideCharToMultiByte( CP_ACP,0, bufferW, len / sizeof(WCHAR),
|
|
|
|
lpBuffer, *lpdwBufferLength, NULL, NULL );
|
|
|
|
*lpdwBufferLength = len * sizeof(WCHAR);
|
2002-11-12 03:13:04 +01: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
|
|
|
|
* transfers
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest,
|
|
|
|
LPINTERNET_BUFFERSA lpBuffersIn,
|
|
|
|
LPINTERNET_BUFFERSA lpBuffersOut,
|
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p, %p, %08lx, %08lx): stub\n", hRequest, lpBuffersIn,
|
|
|
|
lpBuffersOut, dwFlags, dwContext);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* HttpSendRequestA (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;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
TRACE("%p, %p (%s), %li, %p, %li)\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);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2003-09-25 22:25:22 +02:00
|
|
|
workRequest.handle = hHttpRequest;
|
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;
|
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);
|
2002-06-22 01:59:49 +02:00
|
|
|
return 0;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
return HTTP_HttpSendRequestW(hHttpRequest, lpszHeaders,
|
2000-06-11 22:04:44 +02:00
|
|
|
dwHeaderLength, lpOptional, dwOptionalLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-12 03:13:04 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* HttpSendRequestW (WININET.@)
|
|
|
|
*
|
|
|
|
* 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);
|
2002-11-12 03:13:04 +01:00
|
|
|
if(szHeaders!=NULL)
|
2003-08-15 05:47:30 +02: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,
|
2002-12-07 00:20:31 +01:00
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength)
|
|
|
|
{
|
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];
|
2004-02-07 02:03:41 +01:00
|
|
|
HINTERNET handle;
|
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
if(lpszUrl[0]=='/')
|
|
|
|
{
|
|
|
|
/* if it's an absolute path, keep the same session info */
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(path,lpszUrl);
|
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");
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(path,lpszUrl);
|
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];
|
|
|
|
WCHAR password[1024], extra[1024];
|
|
|
|
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;
|
|
|
|
urlComponents.lpszPassword = password;
|
|
|
|
urlComponents.dwPasswordLength = 1024;
|
|
|
|
urlComponents.lpszUrlPath = path;
|
|
|
|
urlComponents.dwUrlPathLength = 2048;
|
|
|
|
urlComponents.lpszExtraInfo = extra;
|
|
|
|
urlComponents.dwExtraInfoLength = 1024;
|
2004-03-30 06:36:09 +02:00
|
|
|
if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
|
2002-12-07 00:20:31 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (urlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
|
|
|
|
urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
|
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
|
|
|
|
|
|
|
if (NULL != lpwhs->lpszServerName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs->lpszServerName = WININET_strdupW(hostName);
|
2002-12-07 00:20:31 +01:00
|
|
|
if (NULL != lpwhs->lpszUserName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName);
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs->lpszUserName = WININET_strdupW(userName);
|
2002-12-07 00:20:31 +01:00
|
|
|
lpwhs->nServerPort = urlComponents.nPort;
|
|
|
|
|
|
|
|
if (NULL != lpwhr->lpszHostName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszHostName);
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhr->lpszHostName=WININET_strdupW(hostName);
|
2002-12-07 00:20:31 +01:00
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhs, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RESOLVING_NAME,
|
|
|
|
lpwhs->lpszServerName,
|
2004-03-30 06:36:09 +02:00
|
|
|
strlenW(lpwhs->lpszServerName)+1);
|
2002-12-07 00:20:31 +01:00
|
|
|
|
|
|
|
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
|
|
|
&lpwhs->phostent, &lpwhs->socketAddress))
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhs, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_NAME_RESOLVED,
|
|
|
|
&(lpwhs->socketAddress),
|
|
|
|
sizeof(struct sockaddr_in));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lpwhr->lpszPath)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
|
|
|
|
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)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
ERR("Unable to escape string!(%s) (%ld)\n",debugstr_w(path),rc);
|
|
|
|
strcpyW(lpwhr->lpszPath,path);
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
handle = WININET_FindHandle( &lpwhr->hdr );
|
2004-03-30 06:36:09 +02:00
|
|
|
return HttpSendRequestW(handle, lpszHeaders, dwHeaderLength, lpOptional, dwOptionalLength);
|
2002-12-07 00:20:31 +01:00
|
|
|
}
|
|
|
|
|
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-03-30 06:36:09 +02:00
|
|
|
BOOL WINAPI HTTP_HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders,
|
2000-06-11 22:04:44 +02:00
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
|
|
|
|
{
|
|
|
|
INT cnt;
|
|
|
|
INT i;
|
|
|
|
BOOL bSuccess = FALSE;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR requestString = NULL;
|
|
|
|
LPWSTR lpszHeaders_r_n = NULL; /* lpszHeaders with atleast one pair of \r\n at the end */
|
2000-06-11 22:04:44 +02:00
|
|
|
INT requestStringLen;
|
2002-06-22 01:59:49 +02:00
|
|
|
INT responseLen;
|
2000-06-11 22:04:44 +02:00
|
|
|
INT headerLength = 0;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPREQW lpwhr;
|
|
|
|
LPWININETHTTPSESSIONW lpwhs = NULL;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2003-06-21 01:26:56 +02:00
|
|
|
BOOL loop_next = FALSE;
|
|
|
|
int CustHeaderIndex;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
TRACE("--> 0x%08lx\n", (ULONG)hHttpRequest);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
/* Verify our tree of internet handles */
|
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);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
/* We must have a verb */
|
|
|
|
if (NULL == lpwhr->lpszVerb)
|
|
|
|
{
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2003-08-05 20:31:02 +02:00
|
|
|
/* if we are using optional stuff, we must add the fixed header of that option length */
|
|
|
|
if (lpOptional && dwOptionalLength)
|
|
|
|
{
|
|
|
|
char contentLengthStr[sizeof("Content-Length: ") + 20 /* int */ + 2 /* \n\r */];
|
|
|
|
sprintf(contentLengthStr, "Content-Length: %li\r\n", dwOptionalLength);
|
|
|
|
HttpAddRequestHeadersA(hHttpRequest, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD);
|
|
|
|
}
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
do
|
2001-10-04 20:12:41 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR szSlash[] = { '/',0 };
|
|
|
|
WCHAR szSpace[] = { ' ',0 };
|
|
|
|
WCHAR szHttp[] = { 'h','t','t','p',':','/','/', 0 };
|
|
|
|
WCHAR szcrlf[] = {'\r','\n', 0};
|
|
|
|
WCHAR sztwocrlf[] = {'\r','\n','\r','\n', 0};
|
|
|
|
WCHAR szSetCookie[] = {'S','e','t','-','C','o','o','k','i','e',0 };
|
|
|
|
|
|
|
|
TRACE("Going to url %s %s\n", debugstr_w(lpwhr->lpszHostName), debugstr_w(lpwhr->lpszPath));
|
2003-06-21 01:26:56 +02:00
|
|
|
loop_next = FALSE;
|
2001-10-04 20:12:41 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* If we don't have a path we set it to root */
|
|
|
|
if (NULL == lpwhr->lpszPath)
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhr->lpszPath = WININET_strdupW(szSlash);
|
|
|
|
|
|
|
|
if(CSTR_EQUAL != CompareStringW( LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
|
|
|
|
lpwhr->lpszPath, strlenW(szHttp), szHttp, strlenW(szHttp) )
|
2003-06-21 01:26:56 +02:00
|
|
|
&& lpwhr->lpszPath[0] != '/') /* not an absolute path ?? --> fix it !! */
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR *fixurl = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
(strlenW(lpwhr->lpszPath) + 2)*sizeof(WCHAR));
|
2003-06-21 01:26:56 +02:00
|
|
|
*fixurl = '/';
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(fixurl + 1, lpwhr->lpszPath);
|
2003-06-21 01:26:56 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, lpwhr->lpszPath );
|
|
|
|
lpwhr->lpszPath = fixurl;
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Calculate length of request string */
|
|
|
|
requestStringLen =
|
2004-03-30 06:36:09 +02:00
|
|
|
strlenW(lpwhr->lpszVerb) +
|
|
|
|
strlenW(lpwhr->lpszPath) +
|
|
|
|
strlenW(HTTPHEADER) +
|
2003-06-21 01:26:56 +02:00
|
|
|
5; /* " \r\n\r\n" */
|
|
|
|
|
2003-12-11 05:25:41 +01:00
|
|
|
/* add "\r\n" to end of lpszHeaders if needed */
|
|
|
|
if (lpszHeaders)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
int len = strlenW(lpszHeaders);
|
2003-12-11 05:25:41 +01:00
|
|
|
|
|
|
|
/* Check if the string is terminated with \r\n, but not if
|
|
|
|
* the string is less that 2 characters long, because then
|
|
|
|
* we would be looking at memory before the beginning of
|
|
|
|
* the string. Besides, if it is less than 2 characters
|
|
|
|
* long, then clearly, its not terminated with \r\n.
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
if ((len > 2) && (memcmp(lpszHeaders + (len - 2), szcrlf, sizeof szcrlf) == 0))
|
2003-12-11 05:25:41 +01:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
lpszHeaders_r_n = WININET_strdupW(lpszHeaders);
|
2003-12-11 05:25:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Adding \r\n to lpszHeaders.\n");
|
2004-03-30 06:36:09 +02:00
|
|
|
lpszHeaders_r_n = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
(len + 3)*sizeof(WCHAR) );
|
|
|
|
strcpyW( lpszHeaders_r_n, lpszHeaders );
|
|
|
|
strcatW( lpszHeaders_r_n, szcrlf );
|
2003-12-11 05:25:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Add length of passed headers */
|
|
|
|
if (lpszHeaders)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
headerLength = -1 == dwHeaderLength ? strlenW(lpszHeaders_r_n) : dwHeaderLength;
|
2003-06-21 01:26:56 +02:00
|
|
|
requestStringLen += headerLength + 2; /* \r\n */
|
|
|
|
}
|
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
|
|
|
|
/* if there isa proxy username and password, add it to the headers */
|
|
|
|
if( hIC && (hIC->lpszProxyUsername || hIC->lpszProxyPassword ) )
|
|
|
|
{
|
|
|
|
HTTP_InsertProxyAuthorization( lpwhr, hIC->lpszProxyUsername, hIC->lpszProxyPassword );
|
|
|
|
}
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Calculate length of custom request headers */
|
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
2000-06-11 22:04:44 +02:00
|
|
|
if (lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
requestStringLen += strlenW(lpwhr->pCustHeaders[i].lpszField) +
|
|
|
|
strlenW(lpwhr->pCustHeaders[i].lpszValue) + 4; /*: \r\n */
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Calculate the length of standard request headers */
|
|
|
|
for (i = 0; i <= HTTP_QUERY_MAX; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
requestStringLen += strlenW(lpwhr->StdHeaders[i].lpszField) +
|
|
|
|
strlenW(lpwhr->StdHeaders[i].lpszValue) + 4; /*: \r\n */
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (lpwhr->lpszHostName)
|
2004-03-30 06:36:09 +02:00
|
|
|
requestStringLen += (strlenW(HTTPHOSTHEADER) + strlenW(lpwhr->lpszHostName));
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-08-05 20:31:02 +02:00
|
|
|
/* if there is optional data to send, add the length */
|
|
|
|
if (lpOptional)
|
|
|
|
{
|
|
|
|
requestStringLen += dwOptionalLength;
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Allocate string to hold entire request */
|
2004-03-30 06:36:09 +02:00
|
|
|
requestString = HeapAlloc(GetProcessHeap(), 0, (requestStringLen + 1)*sizeof(WCHAR));
|
2003-06-21 01:26:56 +02:00
|
|
|
if (NULL == requestString)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto lend;
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Build request string */
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(requestString, lpwhr->lpszVerb);
|
|
|
|
strcatW(requestString, szSpace);
|
|
|
|
strcatW(requestString, lpwhr->lpszPath);
|
|
|
|
strcatW(requestString, HTTPHEADER );
|
|
|
|
cnt = strlenW(requestString);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Append standard request headers */
|
|
|
|
for (i = 0; i <= HTTP_QUERY_MAX; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR szFmt[] = { '\r','\n','%','s',':',' ','%','s', 0};
|
|
|
|
cnt += sprintfW(requestString + cnt, szFmt,
|
2003-06-21 01:26:56 +02:00
|
|
|
lpwhr->StdHeaders[i].lpszField, lpwhr->StdHeaders[i].lpszValue);
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("Adding header %s (%s)\n",
|
|
|
|
debugstr_w(lpwhr->StdHeaders[i].lpszField),
|
|
|
|
debugstr_w(lpwhr->StdHeaders[i].lpszValue));
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append custom request heades */
|
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR szFmt[] = { '\r','\n','%','s',':',' ','%','s', 0};
|
|
|
|
cnt += sprintfW(requestString + cnt, szFmt,
|
2003-06-21 01:26:56 +02:00
|
|
|
lpwhr->pCustHeaders[i].lpszField, lpwhr->pCustHeaders[i].lpszValue);
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("Adding custom header %s (%s)\n",
|
|
|
|
debugstr_w(lpwhr->pCustHeaders[i].lpszField),
|
|
|
|
debugstr_w(lpwhr->pCustHeaders[i].lpszValue));
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (lpwhr->lpszHostName)
|
2004-03-30 06:36:09 +02:00
|
|
|
{
|
|
|
|
WCHAR szFmt[] = { '%','s','%','s',0 };
|
|
|
|
cnt += sprintfW(requestString + cnt, szFmt, HTTPHOSTHEADER, lpwhr->lpszHostName);
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Append passed request headers */
|
2003-12-11 05:25:41 +01:00
|
|
|
if (lpszHeaders_r_n)
|
2003-06-21 01:26:56 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(requestString + cnt, szcrlf);
|
2003-06-21 01:26:56 +02:00
|
|
|
cnt += 2;
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(requestString + cnt, lpszHeaders_r_n);
|
2003-06-21 01:26:56 +02:00
|
|
|
cnt += headerLength;
|
2003-12-11 05:25:41 +01:00
|
|
|
/* only add \r\n if not already present */
|
2004-03-30 06:36:09 +02:00
|
|
|
if (memcmp((requestString + cnt) - 2, szcrlf, sizeof szcrlf) != 0)
|
2003-12-11 05:25:41 +01:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(requestString + cnt, szcrlf);
|
2003-12-11 05:25:41 +01:00
|
|
|
cnt += 2;
|
|
|
|
}
|
2003-06-21 01:26:56 +02:00
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-08-05 20:31:02 +02:00
|
|
|
/* Set (header) termination string for request */
|
2004-03-30 06:36:09 +02:00
|
|
|
if (memcmp((requestString + cnt) - 4, sztwocrlf, sizeof sztwocrlf) != 0)
|
2003-08-05 20:31:02 +02:00
|
|
|
{ /* only add it if the request string doesn't already
|
|
|
|
have the thing.. (could happen if the custom header
|
|
|
|
added it */
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(requestString + cnt, szcrlf);
|
2003-08-05 20:31:02 +02:00
|
|
|
cnt += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
requestStringLen -= 2;
|
|
|
|
|
|
|
|
/* if optional data, append it */
|
|
|
|
if (lpOptional)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
memcpy(requestString + cnt, lpOptional, dwOptionalLength*sizeof(WCHAR));
|
2003-08-05 20:31:02 +02:00
|
|
|
cnt += dwOptionalLength;
|
|
|
|
/* we also have to decrease the expected string length by two,
|
|
|
|
* since we won't be adding on those following \r\n's */
|
2003-12-11 05:25:41 +01:00
|
|
|
requestStringLen -= 2;
|
2003-08-05 20:31:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* if there is no optional data, add on another \r\n just to be safe */
|
|
|
|
/* termination for request */
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(requestString + cnt, szcrlf);
|
2003-08-05 20:31:02 +02:00
|
|
|
cnt += 2;
|
|
|
|
}
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("(%s) len(%d)\n", debugstr_w(requestString), requestStringLen);
|
2003-06-21 01:26:56 +02:00
|
|
|
/* Send the request and store the results */
|
|
|
|
if (!HTTP_OpenConnection(lpwhr))
|
|
|
|
goto lend;
|
|
|
|
|
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
/* send the request as ASCII */
|
|
|
|
{
|
|
|
|
int ascii_len;
|
|
|
|
char *ascii_req;
|
|
|
|
|
|
|
|
ascii_len = WideCharToMultiByte( CP_ACP, 0, requestString,
|
|
|
|
requestStringLen, NULL, 0, NULL, NULL );
|
|
|
|
ascii_req = HeapAlloc( GetProcessHeap(), 0, ascii_len );
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, requestString, requestStringLen,
|
|
|
|
ascii_req, ascii_len, NULL, NULL );
|
|
|
|
NETCON_send(&lpwhr->netConnection, ascii_req, ascii_len, 0, &cnt);
|
|
|
|
HeapFree( GetProcessHeap(), 0, ascii_req );
|
|
|
|
}
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_REQUEST_SENT,
|
|
|
|
&requestStringLen,sizeof(DWORD));
|
|
|
|
|
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
|
|
|
|
|
|
|
|
if (cnt < 0)
|
|
|
|
goto lend;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
responseLen = HTTP_GetResponseHeaders(lpwhr);
|
|
|
|
if (responseLen)
|
2000-06-11 22:04:44 +02:00
|
|
|
bSuccess = TRUE;
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen,
|
|
|
|
sizeof(DWORD));
|
|
|
|
|
|
|
|
/* process headers here. Is this right? */
|
2004-03-30 06:36:09 +02:00
|
|
|
CustHeaderIndex = HTTP_GetCustomHeaderIndex(lpwhr, szSetCookie);
|
2003-06-21 01:26:56 +02:00
|
|
|
if (CustHeaderIndex >= 0)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPHTTPHEADERW setCookieHeader;
|
|
|
|
int nPosStart = 0, nPosEnd = 0, len;
|
|
|
|
WCHAR szFmt[] = { 'h','t','t','p',':','/','/','%','s','/',0};
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
setCookieHeader = &lpwhr->pCustHeaders[CustHeaderIndex];
|
|
|
|
|
|
|
|
while (setCookieHeader->lpszValue[nPosEnd] != '\0')
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR buf_cookie, cookie_name, cookie_data;
|
|
|
|
LPWSTR buf_url;
|
|
|
|
LPWSTR domain = NULL;
|
2003-06-21 01:26:56 +02: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;
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR szDomain[] = {'d','o','m','a','i','n','=',0};
|
|
|
|
LPWSTR lpszDomain = strstrW(&setCookieHeader->lpszValue[nPosEnd], szDomain);
|
2003-06-21 01:26:56 +02:00
|
|
|
if (lpszDomain)
|
|
|
|
{ /* they have specified their own domain, lets use it */
|
|
|
|
while (lpszDomain[nDomainPosEnd] != ';' && lpszDomain[nDomainPosEnd] != ',' &&
|
|
|
|
lpszDomain[nDomainPosEnd] != '\0')
|
|
|
|
{
|
|
|
|
nDomainPosEnd++;
|
|
|
|
}
|
2004-03-30 06:36:09 +02:00
|
|
|
nDomainPosStart = strlenW(szDomain);
|
2003-06-21 01:26:56 +02:00
|
|
|
nDomainLength = (nDomainPosEnd - nDomainPosStart) + 1;
|
2004-03-30 06:36:09 +02:00
|
|
|
domain = HeapAlloc(GetProcessHeap(), 0, (nDomainLength + 1)*sizeof(WCHAR));
|
|
|
|
strncpyW(domain, &lpszDomain[nDomainPosStart], nDomainLength);
|
2003-06-21 01:26:56 +02:00
|
|
|
domain[nDomainLength] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (setCookieHeader->lpszValue[nPosEnd] == '\0') break;
|
2004-03-30 06:36:09 +02:00
|
|
|
buf_cookie = HeapAlloc(GetProcessHeap(), 0, ((nPosEnd - nPosStart) + 1)*sizeof(WCHAR));
|
|
|
|
strncpyW(buf_cookie, &setCookieHeader->lpszValue[nPosStart], (nPosEnd - nPosStart));
|
2003-06-21 01:26:56 +02:00
|
|
|
buf_cookie[(nPosEnd - nPosStart)] = '\0';
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("%s\n", debugstr_w(buf_cookie));
|
2003-06-21 01:26:56 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
cookie_name = HeapAlloc(GetProcessHeap(), 0, (nEqualPos + 1)*sizeof(WCHAR));
|
|
|
|
strncpyW(cookie_name, buf_cookie, nEqualPos);
|
2003-06-21 01:26:56 +02:00
|
|
|
cookie_name[nEqualPos] = '\0';
|
|
|
|
cookie_data = &buf_cookie[nEqualPos + 1];
|
|
|
|
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
len = strlenW((domain ? domain : lpwhr->lpszHostName)) + strlenW(lpwhr->lpszPath) + 9;
|
|
|
|
buf_url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
sprintfW(buf_url, szFmt, (domain ? domain : lpwhr->lpszHostName)); /* FIXME PATH!!! */
|
|
|
|
InternetSetCookieW(buf_url, cookie_name, cookie_data);
|
2003-06-21 01:26:56 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf_url);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf_cookie);
|
|
|
|
HeapFree(GetProcessHeap(), 0, cookie_name);
|
|
|
|
if (domain) HeapFree(GetProcessHeap(), 0, domain);
|
|
|
|
nPosStart = nPosEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (loop_next);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
lend:
|
|
|
|
|
|
|
|
if (requestString)
|
|
|
|
HeapFree(GetProcessHeap(), 0, requestString);
|
|
|
|
|
2003-12-11 05:25:41 +01:00
|
|
|
if (lpszHeaders)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpszHeaders_r_n);
|
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
/* TODO: send notification for P3P header */
|
|
|
|
|
|
|
|
if(!(hIC->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT) && bSuccess)
|
|
|
|
{
|
|
|
|
DWORD dwCode,dwCodeLength=sizeof(DWORD),dwIndex=0;
|
2004-03-30 06:36:09 +02:00
|
|
|
if(HttpQueryInfoW(hHttpRequest,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-03-30 06:36:09 +02:00
|
|
|
if(HttpQueryInfoW(hHttpRequest,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,&dwIndex))
|
2002-12-07 00:20:31 +01:00
|
|
|
{
|
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_REDIRECT, szNewLocation,
|
|
|
|
dwBufferSize);
|
|
|
|
return HTTP_HandleRedirect(lpwhr, szNewLocation, lpszHeaders,
|
|
|
|
dwHeaderLength, lpOptional, dwOptionalLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
if (hIC->lpfnStatusCB)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
SendAsyncCallback(hIC, hHttpRequest, 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-03-30 06:36:09 +02:00
|
|
|
HINTERNET HTTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName,
|
|
|
|
INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
|
|
|
|
LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
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-03-25 06:29:47 +01:00
|
|
|
hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
|
2004-02-07 02:03:41 +01:00
|
|
|
if( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
|
2000-06-11 22:04:44 +02:00
|
|
|
goto lerror;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
handle = WININET_AllocHandle( &lpwhs->hdr );
|
|
|
|
if (NULL == handle)
|
|
|
|
{
|
|
|
|
ERR("Failed to alloc handle\n");
|
|
|
|
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
|
|
|
|
|
|
|
if (nServerPort == INTERNET_INVALID_PORT_NUMBER)
|
|
|
|
nServerPort = INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
|
|
|
|
lpwhs->hdr.htype = WH_HHTTPSESSION;
|
2004-02-07 02:03:41 +01:00
|
|
|
lpwhs->hdr.lpwhparent = &hIC->hdr;
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhs->hdr.dwFlags = dwFlags;
|
|
|
|
lpwhs->hdr.dwContext = dwContext;
|
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");
|
|
|
|
}
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL != lpszServerName)
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs->lpszServerName = WININET_strdupW(lpszServerName);
|
2000-06-11 22:04:44 +02:00
|
|
|
if (NULL != lpszUserName)
|
2004-03-30 06:36:09 +02:00
|
|
|
lpwhs->lpszUserName = WININET_strdupW(lpszUserName);
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhs->nServerPort = nServerPort;
|
|
|
|
|
|
|
|
if (hIC->lpfnStatusCB)
|
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
|
|
|
|
2004-02-09 21:55:58 +01:00
|
|
|
iar.dwResult = (DWORD)handle;
|
2000-06-11 22:04:44 +02:00
|
|
|
iar.dwError = ERROR_SUCCESS;
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
SendAsyncCallback(hIC, hInternet, dwContext,
|
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
lerror:
|
|
|
|
if (!bSuccess && lpwhs)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs);
|
2004-02-07 02:03:41 +01:00
|
|
|
WININET_FreeHandle( handle );
|
2000-06-11 22:04:44 +02:00
|
|
|
lpwhs = NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
/*
|
|
|
|
* a INTERNET_STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on
|
|
|
|
* windows
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
TRACE("%p --> %p\n", hInternet, handle);
|
|
|
|
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
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
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;
|
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;
|
2002-06-22 01:59:49 +02:00
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTING_TO_SERVER,
|
|
|
|
&(lpwhs->socketAddress),
|
|
|
|
sizeof(struct sockaddr_in));
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
if (!NETCON_create(&lpwhr->netConnection, lpwhs->phostent->h_addrtype,
|
|
|
|
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
|
|
|
{
|
2000-08-26 22:31:48 +02:00
|
|
|
WARN("Unable to connect to host (%s)\n", strerror(errno));
|
2000-06-11 22:04:44 +02:00
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTED_TO_SERVER,
|
|
|
|
&(lpwhs->socketAddress),
|
|
|
|
sizeof(struct sockaddr_in));
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetResponseHeaders (internal)
|
|
|
|
*
|
|
|
|
* Read server response
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on error
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL 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-03-30 06:36:09 +02:00
|
|
|
WCHAR value[MAX_FIELD_VALUE_LEN], field[MAX_FIELD_LEN];
|
|
|
|
WCHAR szStatus[] = {'S','t','a','t','u','s',0};
|
|
|
|
WCHAR szHttp[] = { 'H','T','T','P',0 };
|
|
|
|
char bufferA[MAX_REPLY_LEN];
|
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
|
|
|
|
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
|
|
|
/*
|
2000-06-11 22:04:44 +02:00
|
|
|
* We should first receive 'HTTP/1.x nnn' where nnn is the status code.
|
|
|
|
*/
|
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-03-30 06:36:09 +02:00
|
|
|
if (strncmpW(buffer, szHttp, 4) != 0)
|
2000-06-11 22:04:44 +02:00
|
|
|
goto lend;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
buffer[12]='\0';
|
2004-03-30 06:36:09 +02:00
|
|
|
HTTP_ProcessHeader(lpwhr, szStatus, buffer+9, (HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE));
|
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))
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("got line %s, now interpretting\n", debugstr_a(bufferA));
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
|
2000-06-11 22:04:44 +02:00
|
|
|
if (!HTTP_InterpretHttpHeader(buffer, field, MAX_FIELD_LEN, value, MAX_FIELD_VALUE_LEN))
|
|
|
|
break;
|
|
|
|
|
|
|
|
HTTP_ProcessHeader(lpwhr, field, value, (HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cbreaks++;
|
|
|
|
if (cbreaks >= 2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}while(1);
|
|
|
|
|
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
lend:
|
|
|
|
|
2002-06-22 01:59:49 +02:00
|
|
|
TRACE("<--\n");
|
|
|
|
if (bSuccess)
|
|
|
|
return rc;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_InterpretHttpHeader (internal)
|
|
|
|
*
|
|
|
|
* Parse server response
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on error
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
INT stripSpaces(LPCWSTR lpszSrc, LPWSTR lpszStart, INT *len)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPCWSTR lpsztmp;
|
2000-06-11 22:04:44 +02:00
|
|
|
INT srclen;
|
|
|
|
|
|
|
|
srclen = 0;
|
|
|
|
|
|
|
|
while (*lpszSrc == ' ' && *lpszSrc != '\0')
|
|
|
|
lpszSrc++;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
lpsztmp = lpszSrc;
|
|
|
|
while(*lpsztmp != '\0')
|
|
|
|
{
|
|
|
|
if (*lpsztmp != ' ')
|
|
|
|
srclen = lpsztmp - lpszSrc + 1;
|
|
|
|
|
|
|
|
lpsztmp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = min(*len, srclen);
|
2004-03-30 06:36:09 +02:00
|
|
|
strncpyW(lpszStart, lpszSrc, *len);
|
2000-06-11 22:04:44 +02:00
|
|
|
lpszStart[*len] = '\0';
|
|
|
|
|
|
|
|
return *len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL HTTP_InterpretHttpHeader(LPWSTR buffer, LPWSTR field, INT fieldlen, LPWSTR value, INT valuelen)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR *pd;
|
2000-06-11 22:04:44 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
*field = '\0';
|
|
|
|
*value = '\0';
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
pd = strchrW(buffer, ':');
|
2000-06-11 22:04:44 +02:00
|
|
|
if (pd)
|
|
|
|
{
|
|
|
|
*pd = '\0';
|
|
|
|
if (stripSpaces(buffer, field, &fieldlen) > 0)
|
|
|
|
{
|
|
|
|
if (stripSpaces(pd+1, value, &valuelen) > 0)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("%d: field(%s) Value(%s)\n", bSuccess, debugstr_w(field), debugstr_w(value));
|
2000-06-11 22:04:44 +02:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetStdHeaderIndex (internal)
|
|
|
|
*
|
2000-07-23 15:34:43 +02:00
|
|
|
* Lookup field index in standard http header array
|
2000-06-11 22:04:44 +02:00
|
|
|
*
|
|
|
|
* FIXME: This should be stuffed into a hash table
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
INT HTTP_GetStdHeaderIndex(LPCWSTR lpszField)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
INT index = -1;
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR szContentLength[] = {
|
|
|
|
'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0};
|
|
|
|
WCHAR szStatus[] = {'S','t','a','t','u','s',0};
|
|
|
|
WCHAR szContentType[] = {
|
|
|
|
'C','o','n','t','e','n','t','-','T','y','p','e',0};
|
|
|
|
WCHAR szLastModified[] = {
|
|
|
|
'L','a','s','t','-','M','o','d','i','f','i','e','d',0};
|
|
|
|
WCHAR szLocation[] = {'L','o','c','a','t','i','o','n',0};
|
|
|
|
WCHAR szAccept[] = {'A','c','c','e','p','t',0};
|
|
|
|
WCHAR szReferer[] = { 'R','e','f','e','r','e','r',0};
|
|
|
|
WCHAR szContentTrans[] = { 'C','o','n','t','e','n','t','-',
|
|
|
|
'T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0};
|
|
|
|
WCHAR szDate[] = { 'D','a','t','e',0};
|
|
|
|
WCHAR szServer[] = { 'S','e','r','v','e','r',0};
|
|
|
|
WCHAR szConnection[] = { 'C','o','n','n','e','c','t','i','o','n',0};
|
|
|
|
WCHAR szETag[] = { 'E','T','a','g',0};
|
|
|
|
WCHAR szAcceptRanges[] = {
|
|
|
|
'A','c','c','e','p','t','-','R','a','n','g','e','s',0 };
|
|
|
|
WCHAR szExpires[] = { 'E','x','p','i','r','e','s',0 };
|
|
|
|
WCHAR szMimeVersion[] = {
|
|
|
|
'M','i','m','e','-','V','e','r','s','i','o','n', 0};
|
|
|
|
WCHAR szPragma[] = { 'P','r','a','g','m','a', 0};
|
|
|
|
WCHAR szCacheControl[] = {
|
|
|
|
'C','a','c','h','e','-','C','o','n','t','r','o','l',0};
|
|
|
|
WCHAR szUserAgent[] = { 'U','s','e','r','-','A','g','e','n','t',0};
|
|
|
|
WCHAR szProxyAuth[] = {
|
|
|
|
'P','r','o','x','y','-',
|
|
|
|
'A','u','t','h','e','n','t','i','c','a','t','e', 0};
|
|
|
|
|
|
|
|
if (!strcmpiW(lpszField, szContentLength))
|
2000-06-11 22:04:44 +02:00
|
|
|
index = HTTP_QUERY_CONTENT_LENGTH;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szStatus))
|
2000-06-11 22:04:44 +02:00
|
|
|
index = HTTP_QUERY_STATUS_CODE;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szContentType))
|
2000-06-11 22:04:44 +02:00
|
|
|
index = HTTP_QUERY_CONTENT_TYPE;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szLastModified))
|
2000-06-11 22:04:44 +02:00
|
|
|
index = HTTP_QUERY_LAST_MODIFIED;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szLocation))
|
2000-06-11 22:04:44 +02:00
|
|
|
index = HTTP_QUERY_LOCATION;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szAccept))
|
2000-06-11 22:04:44 +02:00
|
|
|
index = HTTP_QUERY_ACCEPT;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szReferer))
|
2000-06-11 22:04:44 +02:00
|
|
|
index = HTTP_QUERY_REFERER;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szContentTrans))
|
2000-06-11 22:04:44 +02:00
|
|
|
index = HTTP_QUERY_CONTENT_TRANSFER_ENCODING;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szDate))
|
2000-07-23 15:34:43 +02:00
|
|
|
index = HTTP_QUERY_DATE;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szServer))
|
2000-07-23 15:34:43 +02:00
|
|
|
index = HTTP_QUERY_SERVER;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szConnection))
|
2000-07-23 15:34:43 +02:00
|
|
|
index = HTTP_QUERY_CONNECTION;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szETag))
|
2000-07-23 15:34:43 +02:00
|
|
|
index = HTTP_QUERY_ETAG;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szAcceptRanges))
|
2000-07-23 15:34:43 +02:00
|
|
|
index = HTTP_QUERY_ACCEPT_RANGES;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szExpires))
|
2000-07-23 15:34:43 +02:00
|
|
|
index = HTTP_QUERY_EXPIRES;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szMimeVersion))
|
2000-08-04 00:16:39 +02:00
|
|
|
index = HTTP_QUERY_MIME_VERSION;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szPragma))
|
2001-12-17 21:50:53 +01:00
|
|
|
index = HTTP_QUERY_PRAGMA;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szCacheControl))
|
2001-12-17 21:50:53 +01:00
|
|
|
index = HTTP_QUERY_CACHE_CONTROL;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szUserAgent))
|
2001-12-17 21:50:53 +01:00
|
|
|
index = HTTP_QUERY_USER_AGENT;
|
2004-03-30 06:36:09 +02:00
|
|
|
else if (!strcmpiW(lpszField,szProxyAuth))
|
2003-07-22 05:17:52 +02:00
|
|
|
index = HTTP_QUERY_PROXY_AUTHENTICATE;
|
2000-06-11 22:04:44 +02:00
|
|
|
else
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("Couldn't find %s in standard header table\n", debugstr_w(lpszField));
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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)
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
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;
|
|
|
|
INT index;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("--> %s: %s - 0x%08x\n", debugstr_w(field), debugstr_w(value), (unsigned int)dwModifier);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
/* Adjust modifier flags */
|
|
|
|
if (dwModifier & COALESCEFLASG)
|
|
|
|
dwModifier |= HTTP_ADDHDR_FLAG_ADD;
|
|
|
|
|
|
|
|
/* Try to get index into standard header array */
|
|
|
|
index = HTTP_GetStdHeaderIndex(field);
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
lphttpHdr = &lpwhr->StdHeaders[index];
|
|
|
|
}
|
|
|
|
else /* Find or create new custom header */
|
|
|
|
{
|
2002-06-22 01:59:49 +02:00
|
|
|
index = HTTP_GetCustomHeaderIndex(lpwhr, field);
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_ADD_IF_NEW)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
lphttpHdr = &lpwhr->pCustHeaders[index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
HTTPHEADERW hdr;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
hdr.lpszField = (LPWSTR)field;
|
|
|
|
hdr.lpszValue = (LPWSTR)value;
|
2002-06-22 01:59:49 +02:00
|
|
|
hdr.wFlags = hdr.wCount = 0;
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
hdr.wFlags |= HDR_ISREQUEST;
|
|
|
|
|
2003-07-22 05:17:52 +02:00
|
|
|
return HTTP_InsertCustomHeader(lpwhr, &hdr);
|
2002-06-22 01:59:49 +02:00
|
|
|
}
|
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)
|
|
|
|
lphttpHdr->wFlags |= HDR_ISREQUEST;
|
|
|
|
else
|
|
|
|
lphttpHdr->wFlags &= ~HDR_ISREQUEST;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
if (!lphttpHdr->lpszValue && (dwModifier & (HTTP_ADDHDR_FLAG_ADD|HTTP_ADDHDR_FLAG_ADD_IF_NEW)))
|
|
|
|
{
|
|
|
|
INT slen;
|
|
|
|
|
|
|
|
if (!lpwhr->StdHeaders[index].lpszField)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
lphttpHdr->lpszField = WININET_strdupW(field);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
lphttpHdr->wFlags |= HDR_ISREQUEST;
|
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
slen = strlenW(value) + 1;
|
|
|
|
lphttpHdr->lpszValue = HeapAlloc(GetProcessHeap(), 0, slen*sizeof(WCHAR));
|
2000-06-11 22:04:44 +02:00
|
|
|
if (lphttpHdr->lpszValue)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(lphttpHdr->lpszValue, value);
|
2000-06-11 22:04:44 +02:00
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else if (lphttpHdr->lpszValue)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR lpsztmp;
|
2000-06-11 22:04:44 +02:00
|
|
|
INT len;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
len = strlenW(value);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
{
|
2002-04-29 20:48:56 +02:00
|
|
|
/* if custom header delete from array */
|
2000-06-11 22:04:44 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lphttpHdr->lpszValue);
|
|
|
|
lphttpHdr->lpszValue = NULL;
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
lpsztmp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR));
|
2000-06-11 22:04:44 +02:00
|
|
|
if (lpsztmp)
|
|
|
|
{
|
|
|
|
lphttpHdr->lpszValue = lpsztmp;
|
2004-03-30 06:36:09 +02:00
|
|
|
strcpyW(lpsztmp, value);
|
2000-06-11 22:04:44 +02:00
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-07 00:20:31 +01:00
|
|
|
WARN("HeapReAlloc (%d bytes) failed\n",len+1);
|
2000-06-11 22:04:44 +02:00
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dwModifier & COALESCEFLASG)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWSTR lpsztmp;
|
|
|
|
WCHAR ch = 0;
|
2000-06-11 22:04:44 +02:00
|
|
|
INT len = 0;
|
2004-03-30 06:36:09 +02:00
|
|
|
INT origlen = strlenW(lphttpHdr->lpszValue);
|
|
|
|
INT valuelen = strlenW(value);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA)
|
|
|
|
{
|
|
|
|
ch = ',';
|
|
|
|
lphttpHdr->wFlags |= HDR_COMMADELIMITED;
|
|
|
|
}
|
|
|
|
else if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
|
|
|
|
{
|
|
|
|
ch = ';';
|
|
|
|
lphttpHdr->wFlags |= HDR_COMMADELIMITED;
|
|
|
|
}
|
|
|
|
|
2002-12-07 00:20:31 +01:00
|
|
|
len = origlen + valuelen + ((ch > 0) ? 1 : 0);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
lpsztmp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR));
|
2000-06-11 22:04:44 +02:00
|
|
|
if (lpsztmp)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
/* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */
|
2000-06-11 22:04:44 +02:00
|
|
|
if (ch > 0)
|
|
|
|
{
|
|
|
|
lphttpHdr->lpszValue[origlen] = ch;
|
|
|
|
origlen++;
|
|
|
|
}
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR));
|
2000-06-11 22:04:44 +02:00
|
|
|
lphttpHdr->lpszValue[len] = '\0';
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-07 00:20:31 +01:00
|
|
|
WARN("HeapReAlloc (%d bytes) failed\n",len+1);
|
2000-06-11 22:04:44 +02:00
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
VOID HTTP_CloseConnection(LPWININETHTTPREQW lpwhr)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs = NULL;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2004-02-07 02:03:41 +01:00
|
|
|
HINTERNET handle;
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
TRACE("%p\n",lpwhr);
|
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
handle = WININET_FindHandle( &lpwhr->hdr );
|
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
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CLOSING_CONNECTION, 0, 0);
|
|
|
|
|
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
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTION_CLOSED, 0, 0);
|
2000-06-11 22:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_CloseHTTPRequestHandle (internal)
|
|
|
|
*
|
|
|
|
* Deallocate request handle
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
void HTTP_CloseHTTPRequestHandle(LPWININETHTTPREQW lpwhr)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
int i;
|
2004-03-30 06:36:09 +02:00
|
|
|
LPWININETHTTPSESSIONW lpwhs = NULL;
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2004-02-07 02:03:41 +01:00
|
|
|
HINTERNET handle;
|
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-02-07 02:03:41 +01:00
|
|
|
handle = WININET_FindHandle( &lpwhr->hdr );
|
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
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
SendAsyncCallback(hIC, handle, lpwhr->hdr.dwContext,
|
2002-06-22 01:59:49 +02:00
|
|
|
INTERNET_STATUS_HANDLE_CLOSING, lpwhr,
|
|
|
|
sizeof(HINTERNET));
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
if (lpwhr->lpszPath)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
|
|
|
|
if (lpwhr->lpszVerb)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb);
|
|
|
|
if (lpwhr->lpszHostName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszHostName);
|
|
|
|
|
|
|
|
for (i = 0; i <= HTTP_QUERY_MAX; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->StdHeaders[i].lpszField)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->StdHeaders[i].lpszField);
|
|
|
|
if (lpwhr->StdHeaders[i].lpszValue)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->StdHeaders[i].lpszValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->pCustHeaders[i].lpszField)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszField);
|
|
|
|
if (lpwhr->pCustHeaders[i].lpszValue)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_CloseHTTPSessionHandle (internal)
|
|
|
|
*
|
|
|
|
* Deallocate session handle
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
void HTTP_CloseHTTPSessionHandle(LPWININETHTTPSESSIONW lpwhs)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2004-03-25 06:29:47 +01:00
|
|
|
LPWININETAPPINFOW hIC = NULL;
|
2004-02-07 02:03:41 +01:00
|
|
|
HINTERNET handle;
|
|
|
|
|
2003-06-21 01:26:56 +02:00
|
|
|
TRACE("%p\n", lpwhs);
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2004-03-25 06:29:47 +01:00
|
|
|
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
handle = WININET_FindHandle( &lpwhs->hdr );
|
|
|
|
SendAsyncCallback(hIC, handle, lpwhs->hdr.dwContext,
|
2002-06-22 01:59:49 +02:00
|
|
|
INTERNET_STATUS_HANDLE_CLOSING, lpwhs,
|
|
|
|
sizeof(HINTERNET));
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
if (lpwhs->lpszServerName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
|
|
|
|
if (lpwhs->lpszUserName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetCustomHeaderIndex (internal)
|
|
|
|
*
|
|
|
|
* Return index of custom header from header array
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
|
|
|
INT index;
|
|
|
|
|
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++)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
if (!strcmpiW(lpwhr->pCustHeaders[index].lpszField, lpszField))
|
2000-06-11 22:04:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= lpwhr->nCustHeaders)
|
|
|
|
index = -1;
|
|
|
|
|
|
|
|
TRACE("Return: %d\n", index);
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_InsertCustomHeader (internal)
|
|
|
|
*
|
|
|
|
* Insert header into array
|
|
|
|
*
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
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
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, INT index)
|
2000-06-11 22:04:44 +02:00
|
|
|
{
|
2003-07-22 05:17:52 +02:00
|
|
|
if( lpwhr->nCustHeaders <= 0 )
|
|
|
|
return FALSE;
|
|
|
|
if( lpwhr->nCustHeaders >= index )
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
FIXME("STUB: flags=%ld host=%s length=%ld\n",flags,szHost,length);
|
|
|
|
return FALSE;
|
|
|
|
}
|