2002-05-31 23:06:46 +00:00
|
|
|
/*
|
2000-06-11 20:04:44 +00:00
|
|
|
* Wininet - Http Implementation
|
|
|
|
*
|
|
|
|
* Copyright 1999 Corel Corporation
|
2002-06-21 23:59:49 +00:00
|
|
|
* Copyright 2002 CodeWeavers Inc.
|
2000-06-11 20:04:44 +00:00
|
|
|
*
|
|
|
|
* Ulrich Czekalla
|
2002-06-21 23:59:49 +00:00
|
|
|
* Aric Stewart
|
2000-06-11 20:04:44 +00:00
|
|
|
*
|
2002-03-09 23:29:33 +00: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 20:04:44 +00:00
|
|
|
*/
|
|
|
|
|
2000-06-23 15:47:14 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
#include <sys/types.h>
|
2000-06-23 15:47:14 +00:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
2000-06-11 20:04:44 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-17 00:43:16 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2000-06-11 20:04:44 +00:00
|
|
|
#include <errno.h>
|
2001-01-22 02:17:29 +00:00
|
|
|
#include <string.h>
|
2001-02-15 21:24:07 +00:00
|
|
|
#include <time.h>
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2001-11-06 22:31:19 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wininet.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winerror.h"
|
2001-12-11 00:30:17 +00:00
|
|
|
#define NO_SHLWAPI_STREAM
|
2001-11-06 22:31:19 +00:00
|
|
|
#include "shlwapi.h"
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
#include "internet.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
2002-11-12 02:13:04 +00:00
|
|
|
#include "wine/unicode.h"
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
#define HTTPHEADER " HTTP/1.0"
|
|
|
|
#define HTTPHOSTHEADER "\r\nHost: "
|
|
|
|
#define MAXHOSTNAME 100
|
|
|
|
#define MAX_FIELD_VALUE_LEN 256
|
|
|
|
#define MAX_FIELD_LEN 256
|
|
|
|
|
|
|
|
|
2002-12-06 23:20:31 +00:00
|
|
|
#define HTTP_REFERER "Referer"
|
|
|
|
#define HTTP_ACCEPT "Accept"
|
|
|
|
#define HTTP_USERAGENT "User-Agent"
|
2000-06-11 20:04:44 +00: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
|
|
|
|
|
|
|
|
|
|
|
|
BOOL HTTP_OpenConnection(LPWININETHTTPREQA lpwhr);
|
2002-05-31 23:06:46 +00:00
|
|
|
int HTTP_WriteDataToStream(LPWININETHTTPREQA lpwhr,
|
2000-06-11 20:04:44 +00:00
|
|
|
void *Buffer, int BytesToWrite);
|
2002-05-31 23:06:46 +00:00
|
|
|
int HTTP_ReadDataFromStream(LPWININETHTTPREQA lpwhr,
|
2000-06-11 20:04:44 +00:00
|
|
|
void *Buffer, int BytesToRead);
|
|
|
|
BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQA lpwhr);
|
|
|
|
BOOL HTTP_ProcessHeader(LPWININETHTTPREQA lpwhr, LPCSTR field, LPCSTR value, DWORD dwModifier);
|
|
|
|
void HTTP_CloseConnection(LPWININETHTTPREQA lpwhr);
|
|
|
|
BOOL HTTP_InterpretHttpHeader(LPSTR buffer, LPSTR field, INT fieldlen, LPSTR value, INT valuelen);
|
|
|
|
INT HTTP_GetStdHeaderIndex(LPCSTR lpszField);
|
|
|
|
INT HTTP_InsertCustomHeader(LPWININETHTTPREQA lpwhr, LPHTTPHEADERA lpHdr);
|
|
|
|
INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQA lpwhr, LPCSTR lpszField);
|
|
|
|
|
2000-11-16 00:28:52 +00:00
|
|
|
inline static LPSTR HTTP_strdup( LPCSTR str )
|
|
|
|
{
|
|
|
|
LPSTR ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 );
|
|
|
|
if (ret) strcpy( ret, str );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
/***********************************************************************
|
2001-06-19 18:20:47 +00:00
|
|
|
* HttpAddRequestHeadersA (WININET.@)
|
2000-06-11 20:04:44 +00:00
|
|
|
*
|
|
|
|
* Adds one or more HTTP header to the request handler
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2002-05-31 23:06:46 +00:00
|
|
|
BOOL WINAPI HttpAddRequestHeadersA(HINTERNET hHttpRequest,
|
2000-06-11 20:04:44 +00:00
|
|
|
LPCSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
|
|
|
|
{
|
|
|
|
LPSTR lpszStart;
|
|
|
|
LPSTR lpszEnd;
|
|
|
|
LPSTR buffer;
|
|
|
|
CHAR value[MAX_FIELD_VALUE_LEN], field[MAX_FIELD_LEN];
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
LPWININETHTTPREQA lpwhr = (LPWININETHTTPREQA) hHttpRequest;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-25 03:57:59 +00:00
|
|
|
if (!lpszHeader)
|
|
|
|
return TRUE;
|
2000-11-16 00:28:52 +00:00
|
|
|
buffer = HTTP_strdup(lpszHeader);
|
2000-06-11 20:04:44 +00:00
|
|
|
lpszStart = buffer;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
lpszEnd = lpszStart;
|
|
|
|
|
|
|
|
while (*lpszEnd != '\0')
|
|
|
|
{
|
|
|
|
if (*lpszEnd == '\r' && *(lpszEnd + 1) == '\n')
|
|
|
|
break;
|
|
|
|
lpszEnd++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*lpszEnd == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
*lpszEnd = '\0';
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-09-27 22:05:23 +00: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 20:04:44 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 18:20:47 +00:00
|
|
|
* HttpOpenRequestA (WININET.@)
|
2000-06-11 20:04:44 +00:00
|
|
|
*
|
|
|
|
* Open a HTTP request handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a HTTP request handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2001-09-11 00:32:32 +00:00
|
|
|
HINTERNET WINAPI HttpOpenRequestA(HINTERNET hHttpSession,
|
2000-06-11 20:04:44 +00:00
|
|
|
LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion,
|
2002-05-31 23:06:46 +00:00
|
|
|
LPCSTR lpszReferrer , LPCSTR *lpszAcceptTypes,
|
2000-06-11 20:04:44 +00:00
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
|
|
|
LPWININETHTTPSESSIONA lpwhs = (LPWININETHTTPSESSIONA) hHttpSession;
|
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
|
|
|
|
2002-12-06 23:20:31 +00:00
|
|
|
TRACE("(%s, %s, %s, %s, %ld, %ld)\n", lpszVerb, lpszObjectName, lpszVersion, lpszReferrer, dwFlags, dwContext);
|
|
|
|
if(lpszAcceptTypes!=NULL)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;lpszAcceptTypes[i]!=NULL;i++)
|
|
|
|
TRACE("\taccept type: %s\n",lpszAcceptTypes[i]);
|
|
|
|
}
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
|
2002-06-21 23:59:49 +00: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 20:04:44 +00:00
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
|
|
|
|
|
|
|
workRequest.asyncall = HTTPOPENREQUESTA;
|
|
|
|
workRequest.HFTPSESSION = (DWORD)hHttpSession;
|
2000-11-16 00:28:52 +00:00
|
|
|
workRequest.LPSZVERB = (DWORD)HTTP_strdup(lpszVerb);
|
|
|
|
workRequest.LPSZOBJECTNAME = (DWORD)HTTP_strdup(lpszObjectName);
|
2002-06-21 23:59:49 +00:00
|
|
|
if (lpszVersion)
|
|
|
|
workRequest.LPSZVERSION = (DWORD)HTTP_strdup(lpszVersion);
|
|
|
|
else
|
|
|
|
workRequest.LPSZVERSION = 0;
|
|
|
|
if (lpszReferrer)
|
|
|
|
workRequest.LPSZREFERRER = (DWORD)HTTP_strdup(lpszReferrer);
|
|
|
|
else
|
|
|
|
workRequest.LPSZREFERRER = 0;
|
2000-06-11 20:04:44 +00:00
|
|
|
workRequest.LPSZACCEPTTYPES = (DWORD)lpszAcceptTypes;
|
|
|
|
workRequest.DWFLAGS = dwFlags;
|
|
|
|
workRequest.DWCONTEXT = dwContext;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
INTERNET_AsyncCall(&workRequest);
|
|
|
|
return NULL;
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
return HTTP_HttpOpenRequestA(hHttpSession, lpszVerb, lpszObjectName,
|
2000-06-11 20:04:44 +00:00
|
|
|
lpszVersion, lpszReferrer, lpszAcceptTypes, dwFlags, dwContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-12 02:13:04 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* HttpOpenRequestW (WININET.@)
|
|
|
|
*
|
|
|
|
* Open a HTTP request handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a HTTP request handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HINTERNET WINAPI HttpOpenRequestW(HINTERNET hHttpSession,
|
|
|
|
LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
|
|
|
|
LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
|
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
|
|
|
char szVerb[20],
|
|
|
|
szObjectName[INTERNET_MAX_PATH_LENGTH];
|
2002-12-06 23:20:31 +00:00
|
|
|
TRACE("(%s, %s, %s, %s, %ld, %ld)\n", debugstr_w(lpszVerb), debugstr_w(lpszObjectName), debugstr_w(lpszVersion), debugstr_w(lpszReferrer), dwFlags, dwContext);
|
|
|
|
|
2002-11-12 02:13:04 +00:00
|
|
|
if(lpszVerb!=NULL)
|
|
|
|
WideCharToMultiByte(CP_ACP,0,lpszVerb,-1,szVerb,20,NULL,NULL);
|
|
|
|
else
|
|
|
|
szVerb[0]=0;
|
|
|
|
if(lpszObjectName!=NULL)
|
|
|
|
WideCharToMultiByte(CP_ACP,0,lpszObjectName,-1,szObjectName,INTERNET_MAX_PATH_LENGTH,NULL,NULL);
|
|
|
|
else
|
|
|
|
szObjectName[0]=0;
|
|
|
|
TRACE("object name=%s\n",szObjectName);
|
|
|
|
FIXME("lpszVersion, lpszReferrer and lpszAcceptTypes ignored\n");
|
2002-12-06 23:20:31 +00:00
|
|
|
return HttpOpenRequestA(hHttpSession, szVerb[0]?szVerb:NULL, szObjectName, NULL, NULL, NULL, dwFlags, dwContext);
|
2002-11-12 02:13:04 +00:00
|
|
|
}
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_HttpOpenRequestA (internal)
|
|
|
|
*
|
|
|
|
* Open a HTTP request handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a HTTP request handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2001-09-11 00:32:32 +00:00
|
|
|
HINTERNET WINAPI HTTP_HttpOpenRequestA(HINTERNET hHttpSession,
|
2000-06-11 20:04:44 +00:00
|
|
|
LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion,
|
2002-05-31 23:06:46 +00:00
|
|
|
LPCSTR lpszReferrer , LPCSTR *lpszAcceptTypes,
|
2000-06-11 20:04:44 +00:00
|
|
|
DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
|
|
|
LPWININETHTTPSESSIONA lpwhs = (LPWININETHTTPSESSIONA) hHttpSession;
|
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
|
|
|
LPWININETHTTPREQA lpwhr;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
TRACE("--> \n");
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
|
|
|
|
lpwhr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPREQA));
|
|
|
|
if (NULL == lpwhr)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return (HINTERNET) NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpwhr->hdr.htype = WH_HHTTPREQ;
|
|
|
|
lpwhr->hdr.lpwhparent = hHttpSession;
|
|
|
|
lpwhr->hdr.dwFlags = dwFlags;
|
|
|
|
lpwhr->hdr.dwContext = dwContext;
|
2001-08-24 19:13:36 +00:00
|
|
|
lpwhr->nSocketFD = -1;
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2001-01-21 21:09:00 +00:00
|
|
|
if (NULL != lpszObjectName && strlen(lpszObjectName)) {
|
|
|
|
DWORD needed = 0;
|
2002-06-21 23:59:49 +00:00
|
|
|
HRESULT rc;
|
|
|
|
rc = UrlEscapeA(lpszObjectName, NULL, &needed, URL_ESCAPE_SPACES_ONLY);
|
|
|
|
if (rc != E_POINTER)
|
|
|
|
needed = strlen(lpszObjectName)+1;
|
2001-01-21 21:09:00 +00:00
|
|
|
lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, needed);
|
2002-06-21 23:59:49 +00:00
|
|
|
rc = UrlEscapeA(lpszObjectName, lpwhr->lpszPath, &needed,
|
2001-01-21 21:09:00 +00:00
|
|
|
URL_ESCAPE_SPACES_ONLY);
|
2002-06-21 23:59:49 +00:00
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
ERR("Unable to escape string!(%s) (%ld)\n",lpszObjectName,rc);
|
|
|
|
strcpy(lpwhr->lpszPath,lpszObjectName);
|
|
|
|
}
|
2001-01-21 21:09:00 +00:00
|
|
|
}
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2002-12-06 23:20:31 +00:00
|
|
|
if (NULL != hIC->lpszAgent && strlen(hIC->lpszAgent))
|
|
|
|
HTTP_ProcessHeader(lpwhr, HTTP_USERAGENT, hIC->lpszAgent, HTTP_ADDHDR_FLAG_REQ|HTTP_ADDREQ_FLAG_REPLACE|HTTP_ADDHDR_FLAG_ADD_IF_NEW);
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
if (NULL != lpszReferrer && strlen(lpszReferrer))
|
2002-12-06 23:20:31 +00:00
|
|
|
HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpszReferrer, HTTP_ADDHDR_FLAG_REQ|HTTP_ADDREQ_FLAG_REPLACE|HTTP_ADDHDR_FLAG_ADD_IF_NEW);
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2002-12-06 23:20:31 +00: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 20:04:44 +00:00
|
|
|
|
|
|
|
if (NULL == lpszVerb)
|
2000-11-16 00:28:52 +00:00
|
|
|
lpwhr->lpszVerb = HTTP_strdup("GET");
|
2000-06-11 20:04:44 +00:00
|
|
|
else if (strlen(lpszVerb))
|
2000-11-16 00:28:52 +00:00
|
|
|
lpwhr->lpszVerb = HTTP_strdup(lpszVerb);
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
if (NULL != lpszReferrer)
|
|
|
|
{
|
|
|
|
char buf[MAXHOSTNAME];
|
|
|
|
URL_COMPONENTSA UrlComponents;
|
|
|
|
|
|
|
|
UrlComponents.lpszExtraInfo = NULL;
|
|
|
|
UrlComponents.lpszPassword = NULL;
|
|
|
|
UrlComponents.lpszScheme = NULL;
|
|
|
|
UrlComponents.lpszUrlPath = NULL;
|
|
|
|
UrlComponents.lpszUserName = NULL;
|
|
|
|
UrlComponents.lpszHostName = buf;
|
|
|
|
UrlComponents.dwHostNameLength = MAXHOSTNAME;
|
|
|
|
|
|
|
|
InternetCrackUrlA(lpszReferrer, 0, 0, &UrlComponents);
|
|
|
|
if (strlen(UrlComponents.lpszHostName))
|
2000-11-16 00:28:52 +00:00
|
|
|
lpwhr->lpszHostName = HTTP_strdup(UrlComponents.lpszHostName);
|
2003-04-14 21:32:36 +00:00
|
|
|
} else if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0) {
|
|
|
|
char buf[MAXHOSTNAME];
|
|
|
|
char proxy[MAXHOSTNAME + 13]; /* 13 == "http://" + sizeof(port#) + ":/\0" */
|
|
|
|
URL_COMPONENTSA UrlComponents;
|
|
|
|
|
|
|
|
UrlComponents.lpszExtraInfo = NULL;
|
|
|
|
UrlComponents.lpszPassword = NULL;
|
|
|
|
UrlComponents.lpszScheme = NULL;
|
|
|
|
UrlComponents.lpszUrlPath = NULL;
|
|
|
|
UrlComponents.lpszUserName = NULL;
|
|
|
|
UrlComponents.lpszHostName = buf;
|
|
|
|
UrlComponents.dwHostNameLength = MAXHOSTNAME;
|
|
|
|
|
|
|
|
sprintf(proxy, "http://%s/", hIC->lpszProxy);
|
|
|
|
InternetCrackUrlA(proxy, 0, 0, &UrlComponents);
|
|
|
|
if (strlen(UrlComponents.lpszHostName)) {
|
|
|
|
/* for constant 13 see above */
|
2003-05-16 20:12:03 +00:00
|
|
|
char* url = HeapAlloc(GetProcessHeap(), 0, strlen(lpwhs->lpszServerName) + strlen(lpwhr->lpszPath) + 13);
|
2003-04-14 21:32:36 +00:00
|
|
|
|
|
|
|
if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
|
|
|
|
UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
|
|
|
|
if(lpwhr->lpszHostName != 0) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszHostName);
|
|
|
|
lpwhr->lpszHostName = 0;
|
|
|
|
}
|
|
|
|
sprintf(url, "http://%s:%d/%s", lpwhs->lpszServerName, lpwhs->nServerPort, lpwhr->lpszPath);
|
|
|
|
if(lpwhr->lpszPath)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
|
|
|
|
lpwhr->lpszPath = url;
|
|
|
|
/* FIXME: Do I have to free lpwhs->lpszServerName here ? */
|
|
|
|
lpwhs->lpszServerName = HTTP_strdup(UrlComponents.lpszHostName);
|
|
|
|
lpwhs->nServerPort = UrlComponents.nPort;
|
|
|
|
}
|
2000-08-26 20:31:48 +00:00
|
|
|
} else {
|
2000-11-16 00:28:52 +00:00
|
|
|
lpwhr->lpszHostName = HTTP_strdup(lpwhs->lpszServerName);
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hIC->lpfnStatusCB)
|
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
|
|
|
|
|
|
|
iar.dwResult = (DWORD)lpwhr;
|
|
|
|
iar.dwError = ERROR_SUCCESS;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
SendAsyncCallback(hIC, hHttpSession, dwContext,
|
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
/*
|
|
|
|
* A STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on windows
|
|
|
|
*/
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2002-06-21 23:59:49 +00: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,
|
|
|
|
strlen(lpwhs->lpszServerName)+1);
|
|
|
|
|
|
|
|
if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
|
|
|
|
&lpwhs->phostent, &lpwhs->socketAddress))
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
|
|
|
return FALSE;
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
SendAsyncCallback(hIC, hHttpSession, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_NAME_RESOLVED,
|
|
|
|
&(lpwhs->socketAddress),
|
|
|
|
sizeof(struct sockaddr_in));
|
|
|
|
|
|
|
|
TRACE("<--\n");
|
2000-06-11 20:04:44 +00:00
|
|
|
return (HINTERNET) lpwhr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 18:20:47 +00:00
|
|
|
* HttpQueryInfoA (WININET.@)
|
2000-06-11 20:04:44 +00:00
|
|
|
*
|
|
|
|
* Queries for information about an HTTP request
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpQueryInfoA(HINTERNET hHttpRequest, DWORD dwInfoLevel,
|
|
|
|
LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
LPHTTPHEADERA lphttpHdr = NULL;
|
2000-06-11 20:04:44 +00:00
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
LPWININETHTTPREQA lpwhr = (LPWININETHTTPREQA) hHttpRequest;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
TRACE("(0x%08lx)--> %ld\n", dwInfoLevel, dwInfoLevel);
|
|
|
|
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find requested header structure */
|
|
|
|
if ((dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK) == HTTP_QUERY_CUSTOM)
|
|
|
|
{
|
|
|
|
INT index = HTTP_GetCustomHeaderIndex(lpwhr, (LPSTR)lpBuffer);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
size += strlen(lpwhr->pCustHeaders[i].lpszField) +
|
2000-06-11 20:04:44 +00:00
|
|
|
strlen(lpwhr->pCustHeaders[i].lpszValue) + delim + 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the length of stadard request headers */
|
|
|
|
for (i = 0; i <= HTTP_QUERY_MAX; i++)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
if ((~lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST) && lpwhr->StdHeaders[i].lpszField &&
|
2000-06-11 20:04:44 +00:00
|
|
|
lpwhr->StdHeaders[i].lpszValue)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
size += strlen(lpwhr->StdHeaders[i].lpszField) +
|
2000-06-11 20:04:44 +00:00
|
|
|
strlen(lpwhr->StdHeaders[i].lpszValue) + delim + 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size += delim;
|
|
|
|
|
|
|
|
if (size + 1 > *lpdwBufferLength)
|
|
|
|
{
|
|
|
|
*lpdwBufferLength = size + 1;
|
|
|
|
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)
|
|
|
|
{
|
2002-07-03 21:10:43 +00:00
|
|
|
cnt += sprintf((char*)lpBuffer + cnt, "%s: %s%s", lpwhr->StdHeaders[i].lpszField, lpwhr->StdHeaders[i].lpszValue,
|
2000-06-11 20:04:44 +00:00
|
|
|
index == HTTP_QUERY_RAW_HEADERS_CRLF ? "\r\n" : "\0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2002-07-03 21:10:43 +00:00
|
|
|
cnt += sprintf((char*)lpBuffer + cnt, "%s: %s%s",
|
2000-06-11 20:04:44 +00:00
|
|
|
lpwhr->pCustHeaders[i].lpszField, lpwhr->pCustHeaders[i].lpszValue,
|
|
|
|
index == HTTP_QUERY_RAW_HEADERS_CRLF ? "\r\n" : "\0");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-03 21:10:43 +00:00
|
|
|
strcpy((char*)lpBuffer + cnt, index == HTTP_QUERY_RAW_HEADERS_CRLF ? "\r\n" : "");
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
*lpdwBufferLength = cnt + delim;
|
|
|
|
bSuccess = TRUE;
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
else if (index >= 0 && index <= HTTP_QUERY_MAX && lpwhr->StdHeaders[index].lpszValue)
|
2002-05-31 23:06:46 +00:00
|
|
|
{
|
2000-06-11 20:04:44 +00:00
|
|
|
lphttpHdr = &lpwhr->StdHeaders[index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure header satisifies requested attributes */
|
2002-05-31 23:06:46 +00:00
|
|
|
if ((dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS) &&
|
2000-06-11 20:04:44 +00:00
|
|
|
(~lphttpHdr->wFlags & HDR_ISREQUEST))
|
|
|
|
goto lend;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
/* coalesce value to reuqested type */
|
|
|
|
if (dwInfoLevel & HTTP_QUERY_FLAG_NUMBER)
|
|
|
|
{
|
|
|
|
*(int *)lpBuffer = atoi(lphttpHdr->lpszValue);
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME)
|
|
|
|
{
|
|
|
|
time_t tmpTime;
|
|
|
|
struct tm tmpTM;
|
|
|
|
SYSTEMTIME *STHook;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
tmpTime = ConvertTimeString(lphttpHdr->lpszValue);
|
|
|
|
|
|
|
|
tmpTM = *gmtime(&tmpTime);
|
|
|
|
STHook = (SYSTEMTIME *) lpBuffer;
|
|
|
|
if(STHook==NULL)
|
|
|
|
goto lend;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else if (dwInfoLevel & HTTP_QUERY_FLAG_COALESCE)
|
|
|
|
{
|
|
|
|
if (*lpdwIndex >= lphttpHdr->wCount)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_HTTP_HEADER_NOT_FOUND);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-29 18:48:56 +00:00
|
|
|
/* Copy strncpy(lpBuffer, lphttpHdr[*lpdwIndex], len); */
|
2000-06-11 20:04:44 +00:00
|
|
|
(*lpdwIndex)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INT len = strlen(lphttpHdr->lpszValue);
|
|
|
|
|
|
|
|
if (len + 1 > *lpdwBufferLength)
|
|
|
|
{
|
|
|
|
*lpdwBufferLength = len + 1;
|
|
|
|
INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(lpBuffer, lphttpHdr->lpszValue, len);
|
2002-06-21 23:59:49 +00:00
|
|
|
((char*)lpBuffer)[len]=0;
|
2000-06-11 20:04:44 +00:00
|
|
|
*lpdwBufferLength = len;
|
2002-05-31 23:06:46 +00:00
|
|
|
bSuccess = TRUE;
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
TRACE("%d <--\n", bSuccess);
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2002-11-12 02:13:04 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* HttpQueryInfoW (WININET.@)
|
|
|
|
*
|
|
|
|
* Queries for information about an HTTP request
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel,
|
|
|
|
LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
DWORD charLen=*lpdwBufferLength;
|
|
|
|
char* tempBuffer=HeapAlloc(GetProcessHeap(), 0, charLen);
|
|
|
|
result=HttpQueryInfoA(hHttpRequest, dwInfoLevel, tempBuffer, &charLen, lpdwIndex);
|
|
|
|
if((dwInfoLevel & HTTP_QUERY_FLAG_NUMBER) ||
|
|
|
|
(dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME))
|
|
|
|
{
|
|
|
|
memcpy(lpBuffer,tempBuffer,charLen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int nChars=MultiByteToWideChar(CP_ACP,0, tempBuffer,charLen,lpBuffer,*lpdwBufferLength);
|
|
|
|
*lpdwBufferLength=nChars;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, tempBuffer);
|
|
|
|
return result;
|
|
|
|
}
|
2000-10-28 00:30:23 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* HttpSendRequestExA (WININET.@)
|
2000-10-28 00:30:23 +00: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 20:04:44 +00:00
|
|
|
/***********************************************************************
|
2001-06-19 18:20:47 +00:00
|
|
|
* HttpSendRequestA (WININET.@)
|
2000-06-11 20:04:44 +00:00
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders,
|
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
|
2002-05-31 23:06:46 +00:00
|
|
|
{
|
2000-06-11 20:04:44 +00:00
|
|
|
LPWININETHTTPREQA lpwhr = (LPWININETHTTPREQA) hHttpRequest;
|
|
|
|
LPWININETHTTPSESSIONA lpwhs = NULL;
|
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
|
|
|
|
|
|
|
TRACE("0x%08lx\n", (unsigned long)hHttpRequest);
|
|
|
|
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpwhs = (LPWININETHTTPSESSIONA) lpwhr->hdr.lpwhparent;
|
|
|
|
if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
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;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
workRequest.asyncall = HTTPSENDREQUESTA;
|
|
|
|
workRequest.HFTPSESSION = (DWORD)hHttpRequest;
|
|
|
|
if (lpszHeaders)
|
|
|
|
workRequest.LPSZHEADER = (DWORD)HTTP_strdup(lpszHeaders);
|
|
|
|
else
|
|
|
|
workRequest.LPSZHEADER = 0;
|
|
|
|
workRequest.DWHEADERLENGTH = dwHeaderLength;
|
|
|
|
workRequest.LPOPTIONAL = (DWORD)lpOptional;
|
|
|
|
workRequest.DWOPTIONALLENGTH = dwOptionalLength;
|
|
|
|
|
|
|
|
INTERNET_AsyncCall(&workRequest);
|
|
|
|
/*
|
2002-12-06 23:20:31 +00:00
|
|
|
* This is from windows.
|
2002-06-21 23:59:49 +00:00
|
|
|
*/
|
2002-12-06 23:20:31 +00:00
|
|
|
SetLastError(ERROR_IO_PENDING);
|
2002-06-21 23:59:49 +00:00
|
|
|
return 0;
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
return HTTP_HttpSendRequestA(hHttpRequest, lpszHeaders,
|
2000-06-11 20:04:44 +00:00
|
|
|
dwHeaderLength, lpOptional, dwOptionalLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-12 02:13:04 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* HttpSendRequestW (WININET.@)
|
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders,
|
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
|
|
|
|
{
|
|
|
|
BOOL result;
|
|
|
|
char* szHeaders=NULL;
|
|
|
|
DWORD nLen=dwHeaderLength;
|
|
|
|
if(lpszHeaders!=NULL)
|
|
|
|
{
|
|
|
|
if(nLen==-1)
|
|
|
|
nLen=strlenW(lpszHeaders);
|
|
|
|
szHeaders=(char*)malloc(nLen+1);
|
|
|
|
WideCharToMultiByte(CP_ACP,0,lpszHeaders,nLen,szHeaders,nLen,NULL,NULL);
|
|
|
|
}
|
|
|
|
result=HttpSendRequestA(hHttpRequest, szHeaders, dwHeaderLength, lpOptional, dwOptionalLength);
|
|
|
|
if(szHeaders!=NULL)
|
|
|
|
free(szHeaders);
|
|
|
|
return result;
|
|
|
|
}
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2002-12-06 23:20:31 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_HandleRedirect (internal)
|
|
|
|
*/
|
|
|
|
static BOOL HTTP_HandleRedirect(LPWININETHTTPREQA lpwhr, LPCSTR lpszUrl, LPCSTR lpszHeaders,
|
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength)
|
|
|
|
{
|
|
|
|
LPWININETHTTPSESSIONA lpwhs = (LPWININETHTTPSESSIONA) lpwhr->hdr.lpwhparent;
|
|
|
|
LPWININETAPPINFOA hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
char path[2048];
|
|
|
|
if(lpszUrl[0]=='/')
|
|
|
|
{
|
|
|
|
/* if it's an absolute path, keep the same session info */
|
|
|
|
strcpy(path,lpszUrl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
URL_COMPONENTSA urlComponents;
|
|
|
|
char protocol[32], hostName[MAXHOSTNAME], userName[1024];
|
|
|
|
char password[1024], extra[1024];
|
|
|
|
urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
|
|
|
|
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;
|
|
|
|
if(!InternetCrackUrlA(lpszUrl, strlen(lpszUrl), 0, &urlComponents))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (urlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
|
|
|
|
urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
|
|
|
|
/* consider the current host as the referef */
|
|
|
|
if (NULL != lpwhs->lpszServerName && strlen(lpwhs->lpszServerName))
|
|
|
|
HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpwhs->lpszServerName, HTTP_ADDHDR_FLAG_REQ|HTTP_ADDREQ_FLAG_REPLACE|HTTP_ADDHDR_FLAG_ADD_IF_NEW);
|
|
|
|
|
|
|
|
if (NULL != lpwhs->lpszServerName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
|
|
|
|
lpwhs->lpszServerName = HTTP_strdup(hostName);
|
|
|
|
if (NULL != lpwhs->lpszUserName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName);
|
|
|
|
lpwhs->lpszUserName = HTTP_strdup(userName);
|
|
|
|
lpwhs->nServerPort = urlComponents.nPort;
|
|
|
|
|
|
|
|
if (NULL != lpwhr->lpszHostName)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhr->lpszHostName);
|
|
|
|
lpwhr->lpszHostName=HTTP_strdup(hostName);
|
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhs, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RESOLVING_NAME,
|
|
|
|
lpwhs->lpszServerName,
|
|
|
|
strlen(lpwhs->lpszServerName)+1);
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (strlen(path))
|
|
|
|
{
|
|
|
|
DWORD needed = 0;
|
|
|
|
HRESULT rc;
|
|
|
|
rc = UrlEscapeA(path, NULL, &needed, URL_ESCAPE_SPACES_ONLY);
|
|
|
|
if (rc != E_POINTER)
|
|
|
|
needed = strlen(path)+1;
|
|
|
|
lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, needed);
|
|
|
|
rc = UrlEscapeA(path, lpwhr->lpszPath, &needed,
|
|
|
|
URL_ESCAPE_SPACES_ONLY);
|
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
ERR("Unable to escape string!(%s) (%ld)\n",path,rc);
|
|
|
|
strcpy(lpwhr->lpszPath,path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return HttpSendRequestA((HINTERNET)lpwhr, lpszHeaders, dwHeaderLength, lpOptional, dwOptionalLength);
|
|
|
|
}
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_HttpSendRequestA (internal)
|
|
|
|
*
|
|
|
|
* Sends the specified request to the HTTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI HTTP_HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders,
|
|
|
|
DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
|
|
|
|
{
|
|
|
|
INT cnt;
|
|
|
|
INT i;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
LPSTR requestString = NULL;
|
|
|
|
INT requestStringLen;
|
2002-06-21 23:59:49 +00:00
|
|
|
INT responseLen;
|
2000-06-11 20:04:44 +00:00
|
|
|
INT headerLength = 0;
|
|
|
|
LPWININETHTTPREQA lpwhr = (LPWININETHTTPREQA) hHttpRequest;
|
|
|
|
LPWININETHTTPSESSIONA lpwhs = NULL;
|
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
TRACE("--> 0x%08lx\n", (ULONG)hHttpRequest);
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
/* Verify our tree of internet handles */
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpwhs = (LPWININETHTTPSESSIONA) lpwhr->hdr.lpwhparent;
|
|
|
|
if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
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-21 23:59:49 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
/* We must have a verb */
|
|
|
|
if (NULL == lpwhr->lpszVerb)
|
|
|
|
{
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we don't have a path we set it to root */
|
|
|
|
if (NULL == lpwhr->lpszPath)
|
2000-11-16 00:28:52 +00:00
|
|
|
lpwhr->lpszPath = HTTP_strdup("/");
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2003-04-14 21:32:36 +00:00
|
|
|
if(strncmp(lpwhr->lpszPath, "http://", sizeof("http://") -1) != 0
|
|
|
|
&& lpwhr->lpszPath[0] != '/') /* not an absolute path ?? --> fix it !! */
|
2001-10-04 18:12:41 +00:00
|
|
|
{
|
|
|
|
char *fixurl = HeapAlloc(GetProcessHeap(), 0, strlen(lpwhr->lpszPath) + 2);
|
|
|
|
*fixurl = '/';
|
|
|
|
strcpy(fixurl + 1, lpwhr->lpszPath);
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpwhr->lpszPath );
|
|
|
|
lpwhr->lpszPath = fixurl;
|
|
|
|
}
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
/* Calculate length of request string */
|
2002-05-31 23:06:46 +00:00
|
|
|
requestStringLen =
|
2000-06-11 20:04:44 +00:00
|
|
|
strlen(lpwhr->lpszVerb) +
|
|
|
|
strlen(lpwhr->lpszPath) +
|
|
|
|
(lpwhr->lpszHostName ? (strlen(HTTPHOSTHEADER) + strlen(lpwhr->lpszHostName)) : 0) +
|
|
|
|
strlen(HTTPHEADER) +
|
|
|
|
5; /* " \r\n\r\n" */
|
|
|
|
|
|
|
|
/* Add length of passed headers */
|
|
|
|
if (lpszHeaders)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
headerLength = -1 == dwHeaderLength ? strlen(lpszHeaders) : dwHeaderLength;
|
2000-06-11 20:04:44 +00:00
|
|
|
requestStringLen += headerLength + 2; /* \r\n */
|
|
|
|
}
|
|
|
|
|
2000-07-23 13:34:43 +00:00
|
|
|
/* Calculate length of custom request headers */
|
2000-06-11 20:04:44 +00:00
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
requestStringLen += strlen(lpwhr->pCustHeaders[i].lpszField) +
|
2000-06-11 20:04:44 +00:00
|
|
|
strlen(lpwhr->pCustHeaders[i].lpszValue) + 4; /*: \r\n */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-23 13:34:43 +00:00
|
|
|
/* Calculate the length of standard request headers */
|
2000-06-11 20:04:44 +00:00
|
|
|
for (i = 0; i <= HTTP_QUERY_MAX; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
requestStringLen += strlen(lpwhr->StdHeaders[i].lpszField) +
|
2000-06-11 20:04:44 +00:00
|
|
|
strlen(lpwhr->StdHeaders[i].lpszValue) + 4; /*: \r\n */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate string to hold entire request */
|
|
|
|
requestString = HeapAlloc(GetProcessHeap(), 0, requestStringLen + 1);
|
|
|
|
if (NULL == requestString)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build request string */
|
|
|
|
cnt = sprintf(requestString, "%s %s%s%s",
|
|
|
|
lpwhr->lpszVerb,
|
|
|
|
lpwhr->lpszPath,
|
|
|
|
lpwhr->lpszHostName ? (HTTPHEADER HTTPHOSTHEADER) : HTTPHEADER,
|
|
|
|
lpwhr->lpszHostName ? lpwhr->lpszHostName : "");
|
|
|
|
|
2000-07-23 13:34:43 +00:00
|
|
|
/* Append standard request headers */
|
2000-06-11 20:04:44 +00:00
|
|
|
for (i = 0; i <= HTTP_QUERY_MAX; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
cnt += sprintf(requestString + cnt, "\r\n%s: %s",
|
2000-06-11 20:04:44 +00:00
|
|
|
lpwhr->StdHeaders[i].lpszField, lpwhr->StdHeaders[i].lpszValue);
|
2002-12-06 23:20:31 +00:00
|
|
|
TRACE("Adding header %s (%s)\n",lpwhr->StdHeaders[i].lpszField,lpwhr->StdHeaders[i].lpszValue);
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append custom request heades */
|
|
|
|
for (i = 0; i < lpwhr->nCustHeaders; i++)
|
|
|
|
{
|
|
|
|
if (lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
cnt += sprintf(requestString + cnt, "\r\n%s: %s",
|
2000-06-11 20:04:44 +00:00
|
|
|
lpwhr->pCustHeaders[i].lpszField, lpwhr->pCustHeaders[i].lpszValue);
|
2002-12-06 23:20:31 +00:00
|
|
|
TRACE("Adding custom header %s (%s)\n",lpwhr->pCustHeaders[i].lpszField,lpwhr->pCustHeaders[i].lpszValue);
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append passed request headers */
|
|
|
|
if (lpszHeaders)
|
|
|
|
{
|
|
|
|
strcpy(requestString + cnt, "\r\n");
|
|
|
|
cnt += 2;
|
|
|
|
strcpy(requestString + cnt, lpszHeaders);
|
|
|
|
cnt += headerLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set termination string for request */
|
|
|
|
strcpy(requestString + cnt, "\r\n\r\n");
|
|
|
|
|
|
|
|
TRACE("(%s) len(%d)\n", requestString, requestStringLen);
|
|
|
|
/* Send the request and store the results */
|
|
|
|
if (!HTTP_OpenConnection(lpwhr))
|
|
|
|
goto lend;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
|
|
|
|
|
|
|
|
cnt = send(lpwhr->nSocketFD, requestString, requestStringLen, 0);
|
|
|
|
|
|
|
|
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);
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
if (cnt < 0)
|
|
|
|
goto lend;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
responseLen = HTTP_GetResponseHeaders(lpwhr);
|
|
|
|
if (responseLen)
|
2000-06-11 20:04:44 +00:00
|
|
|
bSuccess = TRUE;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen,
|
|
|
|
sizeof(DWORD));
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
lend:
|
|
|
|
|
|
|
|
if (requestString)
|
|
|
|
HeapFree(GetProcessHeap(), 0, requestString);
|
|
|
|
|
2002-12-06 23:20:31 +00:00
|
|
|
/* TODO: send notification for P3P header */
|
|
|
|
|
|
|
|
if(!(hIC->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT) && bSuccess)
|
|
|
|
{
|
|
|
|
DWORD dwCode,dwCodeLength=sizeof(DWORD),dwIndex=0;
|
|
|
|
if(HttpQueryInfoA(hHttpRequest,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,&dwCode,&dwCodeLength,&dwIndex) &&
|
|
|
|
(dwCode==302 || dwCode==301))
|
|
|
|
{
|
|
|
|
char szNewLocation[2048];
|
|
|
|
DWORD dwBufferSize=2048;
|
|
|
|
dwIndex=0;
|
|
|
|
if(HttpQueryInfoA(hHttpRequest,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,&dwIndex))
|
|
|
|
{
|
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_REDIRECT, szNewLocation,
|
|
|
|
dwBufferSize);
|
|
|
|
return HTTP_HandleRedirect(lpwhr, szNewLocation, lpszHeaders,
|
|
|
|
dwHeaderLength, lpOptional, dwOptionalLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-21 23:59:49 +00:00
|
|
|
|
|
|
|
if (hIC->lpfnStatusCB)
|
2000-06-11 20:04:44 +00:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2002-06-21 23:59:49 +00:00
|
|
|
|
|
|
|
SendAsyncCallback(hIC, hHttpRequest, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_REQUEST_COMPLETE, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("<--\n");
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_Connect (internal)
|
|
|
|
*
|
|
|
|
* Create http session handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a session handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2002-05-31 23:06:46 +00:00
|
|
|
HINTERNET HTTP_Connect(HINTERNET hInternet, LPCSTR lpszServerName,
|
2000-06-11 20:04:44 +00:00
|
|
|
INTERNET_PORT nServerPort, LPCSTR lpszUserName,
|
|
|
|
LPCSTR lpszPassword, DWORD dwFlags, DWORD dwContext)
|
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
|
|
|
LPWININETHTTPSESSIONA lpwhs = NULL;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
TRACE("-->\n");
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
if (((LPWININETHANDLEHEADER)hInternet)->htype != WH_HINIT)
|
|
|
|
goto lerror;
|
|
|
|
|
|
|
|
hIC = (LPWININETAPPINFOA) hInternet;
|
2002-06-21 23:59:49 +00:00
|
|
|
hIC->hdr.dwContext = dwContext;
|
2003-04-14 21:32:36 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
lpwhs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPSESSIONA));
|
|
|
|
if (NULL == lpwhs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto lerror;
|
|
|
|
}
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
/*
|
|
|
|
* According to my tests. The name is not resolved until a request is sent
|
|
|
|
*/
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
if (nServerPort == INTERNET_INVALID_PORT_NUMBER)
|
|
|
|
nServerPort = INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
|
|
|
|
lpwhs->hdr.htype = WH_HHTTPSESSION;
|
|
|
|
lpwhs->hdr.lpwhparent = (LPWININETHANDLEHEADER)hInternet;
|
|
|
|
lpwhs->hdr.dwFlags = dwFlags;
|
|
|
|
lpwhs->hdr.dwContext = dwContext;
|
2003-04-14 21:32:36 +00:00
|
|
|
if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
|
|
|
|
if(strchr(hIC->lpszProxy, ' '))
|
|
|
|
FIXME("Several proxies not implemented.\n");
|
|
|
|
if(hIC->lpszProxyBypass)
|
|
|
|
FIXME("Proxy bypass is ignored.\n");
|
|
|
|
}
|
2000-06-11 20:04:44 +00:00
|
|
|
if (NULL != lpszServerName)
|
2000-11-16 00:28:52 +00:00
|
|
|
lpwhs->lpszServerName = HTTP_strdup(lpszServerName);
|
2000-06-11 20:04:44 +00:00
|
|
|
if (NULL != lpszUserName)
|
2000-11-16 00:28:52 +00:00
|
|
|
lpwhs->lpszUserName = HTTP_strdup(lpszUserName);
|
2000-06-11 20:04:44 +00:00
|
|
|
lpwhs->nServerPort = nServerPort;
|
|
|
|
|
|
|
|
if (hIC->lpfnStatusCB)
|
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
|
|
|
|
|
|
|
iar.dwResult = (DWORD)lpwhs;
|
|
|
|
iar.dwError = ERROR_SUCCESS;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
SendAsyncCallback(hIC, hInternet, dwContext,
|
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
lerror:
|
|
|
|
if (!bSuccess && lpwhs)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwhs);
|
|
|
|
lpwhs = NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
/*
|
|
|
|
* a INTERNET_STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on
|
|
|
|
* windows
|
|
|
|
*/
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
TRACE("<--\n");
|
|
|
|
return (HINTERNET)lpwhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_OpenConnection (internal)
|
|
|
|
*
|
|
|
|
* Connect to a web server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*/
|
|
|
|
BOOL HTTP_OpenConnection(LPWININETHTTPREQA lpwhr)
|
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
INT result;
|
|
|
|
LPWININETHTTPSESSIONA lpwhs;
|
2002-06-21 23:59:49 +00:00
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
|
|
|
|
|
|
|
TRACE("-->\n");
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpwhs = (LPWININETHTTPSESSIONA)lpwhr->hdr.lpwhparent;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTING_TO_SERVER,
|
|
|
|
&(lpwhs->socketAddress),
|
|
|
|
sizeof(struct sockaddr_in));
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
lpwhr->nSocketFD = socket(lpwhs->phostent->h_addrtype,SOCK_STREAM,0);
|
2001-08-24 19:13:36 +00:00
|
|
|
if (lpwhr->nSocketFD == -1)
|
2000-06-11 20:04:44 +00:00
|
|
|
{
|
|
|
|
WARN("Socket creation failed\n");
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = connect(lpwhr->nSocketFD, (struct sockaddr *)&lpwhs->socketAddress,
|
|
|
|
sizeof(lpwhs->socketAddress));
|
|
|
|
|
2001-08-24 19:13:36 +00:00
|
|
|
if (result == -1)
|
2000-06-11 20:04:44 +00:00
|
|
|
{
|
2000-08-26 20:31:48 +00:00
|
|
|
WARN("Unable to connect to host (%s)\n", strerror(errno));
|
2000-06-11 20:04:44 +00:00
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTED_TO_SERVER,
|
|
|
|
&(lpwhs->socketAddress),
|
|
|
|
sizeof(struct sockaddr_in));
|
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
lend:
|
2002-06-21 23:59:49 +00:00
|
|
|
TRACE("%d <--\n", bSuccess);
|
2000-06-11 20:04:44 +00:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetResponseHeaders (internal)
|
|
|
|
*
|
|
|
|
* Read server response
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on error
|
|
|
|
*/
|
|
|
|
BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQA lpwhr)
|
|
|
|
{
|
|
|
|
INT cbreaks = 0;
|
|
|
|
CHAR buffer[MAX_REPLY_LEN];
|
|
|
|
DWORD buflen = MAX_REPLY_LEN;
|
|
|
|
BOOL bSuccess = FALSE;
|
2002-06-21 23:59:49 +00:00
|
|
|
INT rc = 0;
|
2000-06-11 20:04:44 +00:00
|
|
|
CHAR value[MAX_FIELD_VALUE_LEN], field[MAX_FIELD_LEN];
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
TRACE("-->\n");
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2001-08-24 19:13:36 +00:00
|
|
|
if (lpwhr->nSocketFD == -1)
|
2000-06-11 20:04:44 +00:00
|
|
|
goto lend;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
/*
|
|
|
|
* HACK peek at the buffer
|
|
|
|
*/
|
|
|
|
rc = recv(lpwhr->nSocketFD,buffer,buflen,MSG_PEEK);
|
|
|
|
|
2002-05-31 23:06:46 +00:00
|
|
|
/*
|
2000-06-11 20:04:44 +00:00
|
|
|
* We should first receive 'HTTP/1.x nnn' where nnn is the status code.
|
|
|
|
*/
|
2002-06-21 23:59:49 +00:00
|
|
|
buflen = MAX_REPLY_LEN;
|
2000-06-11 20:04:44 +00:00
|
|
|
if (!INTERNET_GetNextLine(lpwhr->nSocketFD, buffer, &buflen))
|
|
|
|
goto lend;
|
|
|
|
|
|
|
|
if (strncmp(buffer, "HTTP", 4) != 0)
|
|
|
|
goto lend;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
buffer[12]='\0';
|
|
|
|
HTTP_ProcessHeader(lpwhr, "Status", buffer+9, (HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE));
|
|
|
|
|
|
|
|
/* Parse each response line */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
buflen = MAX_REPLY_LEN;
|
|
|
|
if (INTERNET_GetNextLine(lpwhr->nSocketFD, buffer, &buflen))
|
|
|
|
{
|
|
|
|
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-21 23:59:49 +00:00
|
|
|
TRACE("<--\n");
|
|
|
|
if (bSuccess)
|
|
|
|
return rc;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_InterpretHttpHeader (internal)
|
|
|
|
*
|
|
|
|
* Parse server response
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on error
|
|
|
|
*/
|
|
|
|
INT stripSpaces(LPCSTR lpszSrc, LPSTR lpszStart, INT *len)
|
|
|
|
{
|
|
|
|
LPCSTR lpsztmp;
|
|
|
|
INT srclen;
|
|
|
|
|
|
|
|
srclen = 0;
|
|
|
|
|
|
|
|
while (*lpszSrc == ' ' && *lpszSrc != '\0')
|
|
|
|
lpszSrc++;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
lpsztmp = lpszSrc;
|
|
|
|
while(*lpsztmp != '\0')
|
|
|
|
{
|
|
|
|
if (*lpsztmp != ' ')
|
|
|
|
srclen = lpsztmp - lpszSrc + 1;
|
|
|
|
|
|
|
|
lpsztmp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = min(*len, srclen);
|
|
|
|
strncpy(lpszStart, lpszSrc, *len);
|
|
|
|
lpszStart[*len] = '\0';
|
|
|
|
|
|
|
|
return *len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL HTTP_InterpretHttpHeader(LPSTR buffer, LPSTR field, INT fieldlen, LPSTR value, INT valuelen)
|
|
|
|
{
|
|
|
|
CHAR *pd;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
*field = '\0';
|
|
|
|
*value = '\0';
|
|
|
|
|
|
|
|
pd = strchr(buffer, ':');
|
|
|
|
if (pd)
|
|
|
|
{
|
|
|
|
*pd = '\0';
|
|
|
|
if (stripSpaces(buffer, field, &fieldlen) > 0)
|
|
|
|
{
|
|
|
|
if (stripSpaces(pd+1, value, &valuelen) > 0)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%d: field(%s) Value(%s)\n", bSuccess, field, value);
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_GetStdHeaderIndex (internal)
|
|
|
|
*
|
2000-07-23 13:34:43 +00:00
|
|
|
* Lookup field index in standard http header array
|
2000-06-11 20:04:44 +00:00
|
|
|
*
|
|
|
|
* FIXME: This should be stuffed into a hash table
|
|
|
|
*/
|
|
|
|
INT HTTP_GetStdHeaderIndex(LPCSTR lpszField)
|
|
|
|
{
|
|
|
|
INT index = -1;
|
|
|
|
|
2000-08-09 22:35:05 +00:00
|
|
|
if (!strcasecmp(lpszField, "Content-Length"))
|
2000-06-11 20:04:44 +00:00
|
|
|
index = HTTP_QUERY_CONTENT_LENGTH;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Status"))
|
2000-06-11 20:04:44 +00:00
|
|
|
index = HTTP_QUERY_STATUS_CODE;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Content-Type"))
|
2000-06-11 20:04:44 +00:00
|
|
|
index = HTTP_QUERY_CONTENT_TYPE;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Last-Modified"))
|
2000-06-11 20:04:44 +00:00
|
|
|
index = HTTP_QUERY_LAST_MODIFIED;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Location"))
|
2000-06-11 20:04:44 +00:00
|
|
|
index = HTTP_QUERY_LOCATION;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Accept"))
|
2000-06-11 20:04:44 +00:00
|
|
|
index = HTTP_QUERY_ACCEPT;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Referer"))
|
2000-06-11 20:04:44 +00:00
|
|
|
index = HTTP_QUERY_REFERER;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Content-Transfer-Encoding"))
|
2000-06-11 20:04:44 +00:00
|
|
|
index = HTTP_QUERY_CONTENT_TRANSFER_ENCODING;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Date"))
|
2000-07-23 13:34:43 +00:00
|
|
|
index = HTTP_QUERY_DATE;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Server"))
|
2000-07-23 13:34:43 +00:00
|
|
|
index = HTTP_QUERY_SERVER;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Connection"))
|
2000-07-23 13:34:43 +00:00
|
|
|
index = HTTP_QUERY_CONNECTION;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"ETag"))
|
2000-07-23 13:34:43 +00:00
|
|
|
index = HTTP_QUERY_ETAG;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Accept-Ranges"))
|
2000-07-23 13:34:43 +00:00
|
|
|
index = HTTP_QUERY_ACCEPT_RANGES;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Expires"))
|
2000-07-23 13:34:43 +00:00
|
|
|
index = HTTP_QUERY_EXPIRES;
|
2000-08-09 22:35:05 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Mime-Version"))
|
2000-08-03 22:16:39 +00:00
|
|
|
index = HTTP_QUERY_MIME_VERSION;
|
2001-12-17 20:50:53 +00:00
|
|
|
else if (!strcasecmp(lpszField,"Pragma"))
|
|
|
|
index = HTTP_QUERY_PRAGMA;
|
|
|
|
else if (!strcasecmp(lpszField,"Cache-Control"))
|
|
|
|
index = HTTP_QUERY_CACHE_CONTROL;
|
|
|
|
else if (!strcasecmp(lpszField,"Content-Length"))
|
|
|
|
index = HTTP_QUERY_CONTENT_LENGTH;
|
|
|
|
else if (!strcasecmp(lpszField,"User-Agent"))
|
|
|
|
index = HTTP_QUERY_USER_AGENT;
|
2000-06-11 20:04:44 +00:00
|
|
|
else
|
|
|
|
{
|
2002-06-21 23:59:49 +00:00
|
|
|
TRACE("Couldn't find %s in standard header table\n", lpszField);
|
2000-06-11 20:04:44 +00: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)
|
|
|
|
|
|
|
|
BOOL HTTP_ProcessHeader(LPWININETHTTPREQA lpwhr, LPCSTR field, LPCSTR value, DWORD dwModifier)
|
|
|
|
{
|
|
|
|
LPHTTPHEADERA lphttpHdr = NULL;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
INT index;
|
|
|
|
|
2002-12-06 23:20:31 +00:00
|
|
|
TRACE("--> %s: %s - 0x%08x\n", field, value, (unsigned int)dwModifier);
|
2000-06-11 20:04:44 +00: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-21 23:59:49 +00:00
|
|
|
index = HTTP_GetCustomHeaderIndex(lpwhr, field);
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_ADD_IF_NEW)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
lphttpHdr = &lpwhr->pCustHeaders[index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HTTPHEADERA hdr;
|
2000-06-11 20:04:44 +00:00
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
hdr.lpszField = (LPSTR)field;
|
|
|
|
hdr.lpszValue = (LPSTR)value;
|
|
|
|
hdr.wFlags = hdr.wCount = 0;
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
hdr.wFlags |= HDR_ISREQUEST;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
index = HTTP_InsertCustomHeader(lpwhr, &hdr);
|
|
|
|
return index >= 0;
|
|
|
|
}
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
lphttpHdr->wFlags |= HDR_ISREQUEST;
|
|
|
|
else
|
|
|
|
lphttpHdr->wFlags &= ~HDR_ISREQUEST;
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-06-11 20:04:44 +00:00
|
|
|
if (!lphttpHdr->lpszValue && (dwModifier & (HTTP_ADDHDR_FLAG_ADD|HTTP_ADDHDR_FLAG_ADD_IF_NEW)))
|
|
|
|
{
|
|
|
|
INT slen;
|
|
|
|
|
|
|
|
if (!lpwhr->StdHeaders[index].lpszField)
|
|
|
|
{
|
2000-11-16 00:28:52 +00:00
|
|
|
lphttpHdr->lpszField = HTTP_strdup(field);
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
|
|
|
|
lphttpHdr->wFlags |= HDR_ISREQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
slen = strlen(value) + 1;
|
|
|
|
lphttpHdr->lpszValue = HeapAlloc(GetProcessHeap(), 0, slen);
|
|
|
|
if (lphttpHdr->lpszValue)
|
|
|
|
{
|
|
|
|
memcpy(lphttpHdr->lpszValue, value, slen);
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
}
|
2002-05-31 23:06:46 +00:00
|
|
|
else if (lphttpHdr->lpszValue)
|
2000-06-11 20:04:44 +00:00
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE)
|
2000-06-11 20:04:44 +00:00
|
|
|
{
|
|
|
|
LPSTR lpsztmp;
|
|
|
|
INT len;
|
|
|
|
|
|
|
|
len = strlen(value);
|
|
|
|
|
|
|
|
if (len <= 0)
|
|
|
|
{
|
2002-04-29 18:48:56 +00:00
|
|
|
/* if custom header delete from array */
|
2000-06-11 20:04:44 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, lphttpHdr->lpszValue);
|
|
|
|
lphttpHdr->lpszValue = NULL;
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lpsztmp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lphttpHdr->lpszValue, len+1);
|
|
|
|
if (lpsztmp)
|
|
|
|
{
|
|
|
|
lphttpHdr->lpszValue = lpsztmp;
|
|
|
|
strcpy(lpsztmp, value);
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-06 23:20:31 +00:00
|
|
|
WARN("HeapReAlloc (%d bytes) failed\n",len+1);
|
2000-06-11 20:04:44 +00:00
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dwModifier & COALESCEFLASG)
|
|
|
|
{
|
|
|
|
LPSTR lpsztmp;
|
|
|
|
CHAR ch = 0;
|
|
|
|
INT len = 0;
|
|
|
|
INT origlen = strlen(lphttpHdr->lpszValue);
|
|
|
|
INT valuelen = strlen(value);
|
|
|
|
|
|
|
|
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-06 23:20:31 +00:00
|
|
|
len = origlen + valuelen + ((ch > 0) ? 1 : 0);
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
lpsztmp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lphttpHdr->lpszValue, len+1);
|
|
|
|
if (lpsztmp)
|
|
|
|
{
|
2002-05-31 23:06:46 +00:00
|
|
|
/* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */
|
2000-06-11 20:04:44 +00:00
|
|
|
if (ch > 0)
|
|
|
|
{
|
|
|
|
lphttpHdr->lpszValue[origlen] = ch;
|
|
|
|
origlen++;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen);
|
|
|
|
lphttpHdr->lpszValue[len] = '\0';
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-06 23:20:31 +00:00
|
|
|
WARN("HeapReAlloc (%d bytes) failed\n",len+1);
|
2000-06-11 20:04:44 +00:00
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-06 23:20:31 +00:00
|
|
|
TRACE("<-- %d\n",bSuccess);
|
2000-06-11 20:04:44 +00:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_CloseConnection (internal)
|
|
|
|
*
|
|
|
|
* Close socket connection
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
VOID HTTP_CloseConnection(LPWININETHTTPREQA lpwhr)
|
|
|
|
{
|
2002-06-21 23:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
LPWININETHTTPSESSIONA lpwhs = NULL;
|
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
|
|
|
|
|
|
|
TRACE("%p\n",lpwhr);
|
|
|
|
|
|
|
|
lpwhs = (LPWININETHTTPSESSIONA) lpwhr->hdr.lpwhparent;
|
|
|
|
hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CLOSING_CONNECTION, 0, 0);
|
|
|
|
|
2001-08-24 19:13:36 +00:00
|
|
|
if (lpwhr->nSocketFD != -1)
|
2000-06-11 20:04:44 +00:00
|
|
|
{
|
|
|
|
close(lpwhr->nSocketFD);
|
2001-08-24 19:13:36 +00:00
|
|
|
lpwhr->nSocketFD = -1;
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
2002-06-21 23:59:49 +00:00
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTION_CLOSED, 0, 0);
|
2000-06-11 20:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_CloseHTTPRequestHandle (internal)
|
|
|
|
*
|
|
|
|
* Deallocate request handle
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void HTTP_CloseHTTPRequestHandle(LPWININETHTTPREQA lpwhr)
|
|
|
|
{
|
|
|
|
int i;
|
2002-06-21 23:59:49 +00:00
|
|
|
LPWININETHTTPSESSIONA lpwhs = NULL;
|
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
2000-06-11 20:04:44 +00:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2001-08-24 19:13:36 +00:00
|
|
|
if (lpwhr->nSocketFD != -1)
|
2000-06-11 20:04:44 +00:00
|
|
|
HTTP_CloseConnection(lpwhr);
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
lpwhs = (LPWININETHTTPSESSIONA) lpwhr->hdr.lpwhparent;
|
|
|
|
hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhr, lpwhr->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_HANDLE_CLOSING, lpwhr,
|
|
|
|
sizeof(HINTERNET));
|
|
|
|
|
2000-06-11 20:04:44 +00: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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void HTTP_CloseHTTPSessionHandle(LPWININETHTTPSESSIONA lpwhs)
|
|
|
|
{
|
2002-06-21 23:59:49 +00:00
|
|
|
LPWININETAPPINFOA hIC = NULL;
|
2000-06-11 20:04:44 +00:00
|
|
|
TRACE("\n");
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
hIC = (LPWININETAPPINFOA) lpwhs->hdr.lpwhparent;
|
|
|
|
|
|
|
|
SendAsyncCallback(hIC, lpwhs, lpwhs->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_HANDLE_CLOSING, lpwhs,
|
|
|
|
sizeof(HINTERNET));
|
|
|
|
|
2000-06-11 20:04:44 +00: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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQA lpwhr, LPCSTR lpszField)
|
|
|
|
{
|
|
|
|
INT index;
|
|
|
|
|
|
|
|
TRACE("%s\n", lpszField);
|
|
|
|
|
|
|
|
for (index = 0; index < lpwhr->nCustHeaders; index++)
|
|
|
|
{
|
2000-08-09 22:35:05 +00:00
|
|
|
if (!strcasecmp(lpwhr->pCustHeaders[index].lpszField, lpszField))
|
2000-06-11 20:04:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= lpwhr->nCustHeaders)
|
|
|
|
index = -1;
|
|
|
|
|
|
|
|
TRACE("Return: %d\n", index);
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_InsertCustomHeader (internal)
|
|
|
|
*
|
|
|
|
* Insert header into array
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
INT HTTP_InsertCustomHeader(LPWININETHTTPREQA lpwhr, LPHTTPHEADERA lpHdr)
|
|
|
|
{
|
|
|
|
INT count;
|
|
|
|
LPHTTPHEADERA lph = NULL;
|
|
|
|
|
2002-06-21 23:59:49 +00:00
|
|
|
TRACE("--> %s: %s\n", lpHdr->lpszField, lpHdr->lpszValue);
|
2000-06-11 20:04:44 +00:00
|
|
|
count = lpwhr->nCustHeaders + 1;
|
|
|
|
if (count > 1)
|
|
|
|
lph = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpwhr->pCustHeaders, sizeof(HTTPHEADERA) * count);
|
|
|
|
else
|
|
|
|
lph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HTTPHEADERA) * count);
|
|
|
|
|
|
|
|
if (NULL != lph)
|
|
|
|
{
|
|
|
|
lpwhr->pCustHeaders = lph;
|
2000-11-16 00:28:52 +00:00
|
|
|
lpwhr->pCustHeaders[count-1].lpszField = HTTP_strdup(lpHdr->lpszField);
|
|
|
|
lpwhr->pCustHeaders[count-1].lpszValue = HTTP_strdup(lpHdr->lpszValue);
|
2000-06-11 20:04:44 +00:00
|
|
|
lpwhr->pCustHeaders[count-1].wFlags = lpHdr->wFlags;
|
|
|
|
lpwhr->pCustHeaders[count-1].wCount= lpHdr->wCount;
|
|
|
|
lpwhr->nCustHeaders++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("%d <--\n", count-1);
|
|
|
|
return count - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* HTTP_DeleteCustomHeader (internal)
|
|
|
|
*
|
|
|
|
* Delete header from array
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL HTTP_DeleteCustomHeader(INT index)
|
|
|
|
{
|
2002-06-21 23:59:49 +00:00
|
|
|
FIXME("STUB\n");
|
2000-06-11 20:04:44 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2002-11-13 04:08:26 +00: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;
|
|
|
|
}
|