2 * Wininet - Http Implementation
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 TransGaming Technologies Inc.
7 * Copyright 2004 Mike McCormack for CodeWeavers
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/port.h"
31 #include <sys/types.h>
32 #ifdef HAVE_SYS_SOCKET_H
33 # include <sys/socket.h>
51 #define NO_SHLWAPI_STREAM
55 #include "wine/debug.h"
56 #include "wine/unicode.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
60 static const WCHAR g_szHttp[] = {' ','H','T','T','P','/','1','.','0',0 };
61 static const WCHAR g_szReferer[] = {'R','e','f','e','r','e','r',0};
62 static const WCHAR g_szAccept[] = {'A','c','c','e','p','t',0};
63 static const WCHAR g_szUserAgent[] = {'U','s','e','r','-','A','g','e','n','t',0};
64 static const WCHAR g_szHost[] = {'H','o','s','t',0};
67 #define HTTPHEADER g_szHttp
68 #define MAXHOSTNAME 100
69 #define MAX_FIELD_VALUE_LEN 256
70 #define MAX_FIELD_LEN 256
72 #define HTTP_REFERER g_szReferer
73 #define HTTP_ACCEPT g_szAccept
74 #define HTTP_USERAGENT g_szUserAgent
76 #define HTTP_ADDHDR_FLAG_ADD 0x20000000
77 #define HTTP_ADDHDR_FLAG_ADD_IF_NEW 0x10000000
78 #define HTTP_ADDHDR_FLAG_COALESCE 0x40000000
79 #define HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA 0x40000000
80 #define HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON 0x01000000
81 #define HTTP_ADDHDR_FLAG_REPLACE 0x80000000
82 #define HTTP_ADDHDR_FLAG_REQ 0x02000000
85 static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr);
86 static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr);
87 BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr);
88 int HTTP_WriteDataToStream(LPWININETHTTPREQW lpwhr,
89 void *Buffer, int BytesToWrite);
90 int HTTP_ReadDataFromStream(LPWININETHTTPREQW lpwhr,
91 void *Buffer, int BytesToRead);
92 BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr);
93 BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier);
94 BOOL HTTP_ReplaceHeaderValue( LPHTTPHEADERW lphttpHdr, LPCWSTR lpsztmp );
95 void HTTP_CloseConnection(LPWININETHTTPREQW lpwhr);
96 LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer);
97 INT HTTP_GetStdHeaderIndex(LPCWSTR lpszField);
98 BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr);
99 INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField);
100 BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, DWORD index);
102 /***********************************************************************
103 * HTTP_Tokenize (internal)
105 * Tokenize a string, allocating memory for the tokens.
107 static LPWSTR * HTTP_Tokenize(LPCWSTR string, LPCWSTR token_string)
109 LPWSTR * token_array;
114 /* empty string has no tokens */
118 for (i = 0; string[i]; i++)
119 if (!strncmpW(string+i, token_string, strlenW(token_string)))
123 /* we want to skip over separators, but not the null terminator */
124 for (j = 0; j < strlenW(token_string) - 1; j++)
130 /* add 1 for terminating NULL */
131 token_array = HeapAlloc(GetProcessHeap(), 0, (tokens+1) * sizeof(*token_array));
132 token_array[tokens] = NULL;
135 for (i = 0; i < tokens; i++)
138 next_token = strstrW(string, token_string);
139 if (!next_token) next_token = string+strlenW(string);
140 len = next_token - string;
141 token_array[i] = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR));
142 memcpy(token_array[i], string, len*sizeof(WCHAR));
143 token_array[i][len] = '\0';
144 string = next_token+strlenW(token_string);
149 /***********************************************************************
150 * HTTP_FreeTokens (internal)
152 * Frees memory returned from HTTP_Tokenize.
154 static void HTTP_FreeTokens(LPWSTR * token_array)
157 for (i = 0; token_array[i]; i++)
158 HeapFree(GetProcessHeap(), 0, token_array[i]);
159 HeapFree(GetProcessHeap(), 0, token_array);
162 /***********************************************************************
163 * HTTP_HttpAddRequestHeadersW (internal)
165 static BOOL WINAPI HTTP_HttpAddRequestHeadersW(LPWININETHTTPREQW lpwhr,
166 LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
171 BOOL bSuccess = FALSE;
174 TRACE("copying header: %s\n", debugstr_w(lpszHeader));
176 if( dwHeaderLength == ~0UL )
177 len = strlenW(lpszHeader);
179 len = dwHeaderLength;
180 buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*(len+1) );
181 lstrcpynW( buffer, lpszHeader, len + 1);
187 LPWSTR * pFieldAndValue;
191 while (*lpszEnd != '\0')
193 if (*lpszEnd == '\r' && *(lpszEnd + 1) == '\n')
198 if (*lpszStart == '\0')
201 if (*lpszEnd == '\r')
204 lpszEnd += 2; /* Jump over \r\n */
206 TRACE("interpreting header %s\n", debugstr_w(lpszStart));
207 pFieldAndValue = HTTP_InterpretHttpHeader(lpszStart);
210 bSuccess = HTTP_ProcessHeader(lpwhr, pFieldAndValue[0],
211 pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ);
212 HTTP_FreeTokens(pFieldAndValue);
218 HeapFree(GetProcessHeap(), 0, buffer);
223 /***********************************************************************
224 * HttpAddRequestHeadersW (WININET.@)
226 * Adds one or more HTTP header to the request handler
233 BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
234 LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
236 BOOL bSuccess = FALSE;
237 LPWININETHTTPREQW lpwhr;
239 TRACE("%p, %s, %li, %li\n", hHttpRequest, debugstr_w(lpszHeader), dwHeaderLength,
245 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest );
246 if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
248 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
251 bSuccess = HTTP_HttpAddRequestHeadersW( lpwhr, lpszHeader, dwHeaderLength, dwModifier );
254 WININET_Release( &lpwhr->hdr );
259 /***********************************************************************
260 * HttpAddRequestHeadersA (WININET.@)
262 * Adds one or more HTTP header to the request handler
269 BOOL WINAPI HttpAddRequestHeadersA(HINTERNET hHttpRequest,
270 LPCSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
276 TRACE("%p, %s, %li, %li\n", hHttpRequest, debugstr_a(lpszHeader), dwHeaderLength,
279 len = MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, NULL, 0 );
280 hdr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
281 MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, hdr, len );
282 if( dwHeaderLength != ~0UL )
283 dwHeaderLength = len;
285 r = HttpAddRequestHeadersW( hHttpRequest, hdr, dwHeaderLength, dwModifier );
287 HeapFree( GetProcessHeap(), 0, hdr );
292 /***********************************************************************
293 * HttpEndRequestA (WININET.@)
295 * Ends an HTTP request that was started by HttpSendRequestEx
302 BOOL WINAPI HttpEndRequestA(HINTERNET hRequest, LPINTERNET_BUFFERSA lpBuffersOut,
303 DWORD dwFlags, DWORD dwContext)
309 /***********************************************************************
310 * HttpEndRequestW (WININET.@)
312 * Ends an HTTP request that was started by HttpSendRequestEx
319 BOOL WINAPI HttpEndRequestW(HINTERNET hRequest, LPINTERNET_BUFFERSW lpBuffersOut,
320 DWORD dwFlags, DWORD dwContext)
326 /***********************************************************************
327 * HttpOpenRequestW (WININET.@)
329 * Open a HTTP request handle
332 * HINTERNET a HTTP request handle on success
336 HINTERNET WINAPI HttpOpenRequestW(HINTERNET hHttpSession,
337 LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
338 LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
339 DWORD dwFlags, DWORD dwContext)
341 LPWININETHTTPSESSIONW lpwhs;
342 HINTERNET handle = NULL;
344 TRACE("(%p, %s, %s, %s, %s, %p, %08lx, %08lx)\n", hHttpSession,
345 debugstr_w(lpszVerb), debugstr_w(lpszObjectName),
346 debugstr_w(lpszVersion), debugstr_w(lpszReferrer), lpszAcceptTypes,
348 if(lpszAcceptTypes!=NULL)
351 for(i=0;lpszAcceptTypes[i]!=NULL;i++)
352 TRACE("\taccept type: %s\n",debugstr_w(lpszAcceptTypes[i]));
355 lpwhs = (LPWININETHTTPSESSIONW) WININET_GetObject( hHttpSession );
356 if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
358 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
363 * My tests seem to show that the windows version does not
364 * become asynchronous until after this point. And anyhow
365 * if this call was asynchronous then how would you get the
366 * necessary HINTERNET pointer returned by this function.
369 handle = HTTP_HttpOpenRequestW(lpwhs, lpszVerb, lpszObjectName,
370 lpszVersion, lpszReferrer, lpszAcceptTypes,
374 WININET_Release( &lpwhs->hdr );
375 TRACE("returning %p\n", handle);
380 /***********************************************************************
381 * HttpOpenRequestA (WININET.@)
383 * Open a HTTP request handle
386 * HINTERNET a HTTP request handle on success
390 HINTERNET WINAPI HttpOpenRequestA(HINTERNET hHttpSession,
391 LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion,
392 LPCSTR lpszReferrer , LPCSTR *lpszAcceptTypes,
393 DWORD dwFlags, DWORD dwContext)
395 LPWSTR szVerb = NULL, szObjectName = NULL;
396 LPWSTR szVersion = NULL, szReferrer = NULL, *szAcceptTypes = NULL;
398 INT acceptTypesCount;
399 HINTERNET rc = FALSE;
400 TRACE("(%p, %s, %s, %s, %s, %p, %08lx, %08lx)\n", hHttpSession,
401 debugstr_a(lpszVerb), debugstr_a(lpszObjectName),
402 debugstr_a(lpszVersion), debugstr_a(lpszReferrer), lpszAcceptTypes,
407 len = MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, NULL, 0 );
408 szVerb = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) );
411 MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, szVerb, len);
416 len = MultiByteToWideChar(CP_ACP, 0, lpszObjectName, -1, NULL, 0 );
417 szObjectName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) );
420 MultiByteToWideChar(CP_ACP, 0, lpszObjectName, -1, szObjectName, len );
425 len = MultiByteToWideChar(CP_ACP, 0, lpszVersion, -1, NULL, 0 );
426 szVersion = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
429 MultiByteToWideChar(CP_ACP, 0, lpszVersion, -1, szVersion, len );
434 len = MultiByteToWideChar(CP_ACP, 0, lpszReferrer, -1, NULL, 0 );
435 szReferrer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
438 MultiByteToWideChar(CP_ACP, 0, lpszReferrer, -1, szReferrer, len );
441 acceptTypesCount = 0;
444 /* find out how many there are */
445 while (lpszAcceptTypes[acceptTypesCount])
447 szAcceptTypes = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR *) * (acceptTypesCount+1));
448 acceptTypesCount = 0;
449 while (lpszAcceptTypes[acceptTypesCount])
451 len = MultiByteToWideChar(CP_ACP, 0, lpszAcceptTypes[acceptTypesCount],
453 szAcceptTypes[acceptTypesCount] = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
454 if (!szAcceptTypes[acceptTypesCount] )
456 MultiByteToWideChar(CP_ACP, 0, lpszAcceptTypes[acceptTypesCount],
457 -1, szAcceptTypes[acceptTypesCount], len );
460 szAcceptTypes[acceptTypesCount] = NULL;
462 else szAcceptTypes = 0;
464 rc = HttpOpenRequestW(hHttpSession, szVerb, szObjectName,
465 szVersion, szReferrer,
466 (LPCWSTR*)szAcceptTypes, dwFlags, dwContext);
471 acceptTypesCount = 0;
472 while (szAcceptTypes[acceptTypesCount])
474 HeapFree(GetProcessHeap(), 0, szAcceptTypes[acceptTypesCount]);
477 HeapFree(GetProcessHeap(), 0, szAcceptTypes);
479 HeapFree(GetProcessHeap(), 0, szReferrer);
480 HeapFree(GetProcessHeap(), 0, szVersion);
481 HeapFree(GetProcessHeap(), 0, szObjectName);
482 HeapFree(GetProcessHeap(), 0, szVerb);
487 /***********************************************************************
490 static UINT HTTP_Base64( LPCWSTR bin, LPWSTR base64 )
493 static LPCSTR HTTP_Base64Enc =
494 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
498 /* first 6 bits, all from bin[0] */
499 base64[n++] = HTTP_Base64Enc[(bin[0] & 0xfc) >> 2];
500 x = (bin[0] & 3) << 4;
502 /* next 6 bits, 2 from bin[0] and 4 from bin[1] */
505 base64[n++] = HTTP_Base64Enc[x];
510 base64[n++] = HTTP_Base64Enc[ x | ( (bin[1]&0xf0) >> 4 ) ];
511 x = ( bin[1] & 0x0f ) << 2;
513 /* next 6 bits 4 from bin[1] and 2 from bin[2] */
516 base64[n++] = HTTP_Base64Enc[x];
520 base64[n++] = HTTP_Base64Enc[ x | ( (bin[2]&0xc0 ) >> 6 ) ];
522 /* last 6 bits, all from bin [2] */
523 base64[n++] = HTTP_Base64Enc[ bin[2] & 0x3f ];
530 /***********************************************************************
531 * HTTP_EncodeBasicAuth
533 * Encode the basic authentication string for HTTP 1.1
535 static LPWSTR HTTP_EncodeBasicAuth( LPCWSTR username, LPCWSTR password)
539 static const WCHAR szBasic[] = {'B','a','s','i','c',' ',0};
540 static const WCHAR szColon[] = {':',0};
542 len = lstrlenW( username ) + 1 + lstrlenW ( password ) + 1;
543 in = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
547 len = lstrlenW(szBasic) +
548 (lstrlenW( username ) + 1 + lstrlenW ( password ))*2 + 1 + 1;
549 out = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
552 lstrcpyW( in, username );
553 lstrcatW( in, szColon );
554 lstrcatW( in, password );
555 lstrcpyW( out, szBasic );
556 HTTP_Base64( in, &out[strlenW(out)] );
558 HeapFree( GetProcessHeap(), 0, in );
563 /***********************************************************************
564 * HTTP_InsertProxyAuthorization
566 * Insert the basic authorization field in the request header
568 BOOL HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr,
569 LPCWSTR username, LPCWSTR password )
573 static const WCHAR szProxyAuthorization[] = {
574 'P','r','o','x','y','-','A','u','t','h','o','r','i','z','a','t','i','o','n',0 };
576 hdr.lpszValue = HTTP_EncodeBasicAuth( username, password );
577 hdr.lpszField = (WCHAR *)szProxyAuthorization;
578 hdr.wFlags = HDR_ISREQUEST;
583 TRACE("Inserting %s = %s\n",
584 debugstr_w( hdr.lpszField ), debugstr_w( hdr.lpszValue ) );
586 /* remove the old proxy authorization header */
587 index = HTTP_GetCustomHeaderIndex( lpwhr, hdr.lpszField );
589 HTTP_DeleteCustomHeader( lpwhr, index );
591 HTTP_InsertCustomHeader(lpwhr, &hdr);
592 HeapFree( GetProcessHeap(), 0, hdr.lpszValue );
597 /***********************************************************************
600 static BOOL HTTP_DealWithProxy( LPWININETAPPINFOW hIC,
601 LPWININETHTTPSESSIONW lpwhs, LPWININETHTTPREQW lpwhr)
603 WCHAR buf[MAXHOSTNAME];
604 WCHAR proxy[MAXHOSTNAME + 15]; /* 15 == "http://" + sizeof(port#) + ":/\0" */
606 static const WCHAR szNul[] = { 0 };
607 URL_COMPONENTSW UrlComponents;
608 static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/',0 }, szSlash[] = { '/',0 } ;
609 static const WCHAR szFormat1[] = { 'h','t','t','p',':','/','/','%','s',0 };
610 static const WCHAR szFormat2[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
613 memset( &UrlComponents, 0, sizeof UrlComponents );
614 UrlComponents.dwStructSize = sizeof UrlComponents;
615 UrlComponents.lpszHostName = buf;
616 UrlComponents.dwHostNameLength = MAXHOSTNAME;
618 if( CSTR_EQUAL != CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
619 buf,strlenW(szHttp),szHttp,strlenW(szHttp)) )
620 sprintfW(proxy, szFormat1, hIC->lpszProxy);
623 if( !InternetCrackUrlW(proxy, 0, 0, &UrlComponents) )
625 if( UrlComponents.dwHostNameLength == 0 )
628 if( !lpwhr->lpszPath )
629 lpwhr->lpszPath = (LPWSTR)szNul;
630 TRACE("server='%s' path='%s'\n",
631 debugstr_w(lpwhs->lpszServerName), debugstr_w(lpwhr->lpszPath));
632 /* for constant 15 see above */
633 len = strlenW(lpwhs->lpszServerName) + strlenW(lpwhr->lpszPath) + 15;
634 url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
636 if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
637 UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
639 sprintfW(url, szFormat2, lpwhs->lpszServerName, lpwhs->nServerPort);
641 if( lpwhr->lpszPath[0] != '/' )
642 strcatW( url, szSlash );
643 strcatW(url, lpwhr->lpszPath);
644 if(lpwhr->lpszPath != szNul)
645 HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
646 lpwhr->lpszPath = url;
647 /* FIXME: Do I have to free lpwhs->lpszServerName here ? */
648 lpwhs->lpszServerName = WININET_strdupW(UrlComponents.lpszHostName);
649 lpwhs->nServerPort = UrlComponents.nPort;
654 /***********************************************************************
655 * HTTP_HttpOpenRequestW (internal)
657 * Open a HTTP request handle
660 * HINTERNET a HTTP request handle on success
664 HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
665 LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion,
666 LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes,
667 DWORD dwFlags, DWORD dwContext)
669 LPWININETAPPINFOW hIC = NULL;
670 LPWININETHTTPREQW lpwhr;
672 LPWSTR lpszUrl = NULL;
674 HINTERNET handle = NULL;
675 static const WCHAR szUrlForm[] = {'h','t','t','p',':','/','/','%','s',0};
677 INTERNET_ASYNC_RESULT iar;
681 assert( lpwhs->hdr.htype == WH_HHTTPSESSION );
682 hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
684 lpwhr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPREQW));
687 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
690 lpwhr->hdr.htype = WH_HHTTPREQ;
691 lpwhr->hdr.lpwhparent = WININET_AddRef( &lpwhs->hdr );
692 lpwhr->hdr.dwFlags = dwFlags;
693 lpwhr->hdr.dwContext = dwContext;
694 lpwhr->hdr.dwRefCount = 1;
695 lpwhr->hdr.destroy = HTTP_CloseHTTPRequestHandle;
696 lpwhr->hdr.lpfnStatusCB = lpwhs->hdr.lpfnStatusCB;
698 handle = WININET_AllocHandle( &lpwhr->hdr );
701 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
705 NETCON_init(&lpwhr->netConnection, dwFlags & INTERNET_FLAG_SECURE);
707 if (NULL != lpszObjectName && strlenW(lpszObjectName)) {
711 rc = UrlEscapeW(lpszObjectName, NULL, &len, URL_ESCAPE_SPACES_ONLY);
713 len = strlenW(lpszObjectName)+1;
714 lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
715 rc = UrlEscapeW(lpszObjectName, lpwhr->lpszPath, &len,
716 URL_ESCAPE_SPACES_ONLY);
719 ERR("Unable to escape string!(%s) (%ld)\n",debugstr_w(lpszObjectName),rc);
720 strcpyW(lpwhr->lpszPath,lpszObjectName);
724 if (NULL != lpszReferrer && strlenW(lpszReferrer))
725 HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpszReferrer, HTTP_ADDHDR_FLAG_COALESCE);
727 if(lpszAcceptTypes!=NULL)
730 for(i=0;lpszAcceptTypes[i]!=NULL;i++)
731 HTTP_ProcessHeader(lpwhr, HTTP_ACCEPT, lpszAcceptTypes[i], HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_REQ|HTTP_ADDHDR_FLAG_ADD_IF_NEW);
734 if (NULL == lpszVerb)
736 static const WCHAR szGet[] = {'G','E','T',0};
737 lpwhr->lpszVerb = WININET_strdupW(szGet);
739 else if (strlenW(lpszVerb))
740 lpwhr->lpszVerb = WININET_strdupW(lpszVerb);
742 if (NULL != lpszReferrer && strlenW(lpszReferrer))
744 WCHAR buf[MAXHOSTNAME];
745 URL_COMPONENTSW UrlComponents;
747 memset( &UrlComponents, 0, sizeof UrlComponents );
748 UrlComponents.dwStructSize = sizeof UrlComponents;
749 UrlComponents.lpszHostName = buf;
750 UrlComponents.dwHostNameLength = MAXHOSTNAME;
752 InternetCrackUrlW(lpszReferrer, 0, 0, &UrlComponents);
753 if (strlenW(UrlComponents.lpszHostName))
754 HTTP_ProcessHeader(lpwhr, g_szHost, UrlComponents.lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
757 HTTP_ProcessHeader(lpwhr, g_szHost, lpwhs->lpszServerName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
759 if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0)
760 HTTP_DealWithProxy( hIC, lpwhs, lpwhr );
765 static const WCHAR user_agent[] = {'U','s','e','r','-','A','g','e','n','t',':',' ','%','s','\r','\n',0 };
767 len = strlenW(hIC->lpszAgent) + strlenW(user_agent);
768 agent_header = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
769 sprintfW(agent_header, user_agent, hIC->lpszAgent );
771 HTTP_HttpAddRequestHeadersW(lpwhr, agent_header, strlenW(agent_header),
772 HTTP_ADDREQ_FLAG_ADD);
773 HeapFree(GetProcessHeap(), 0, agent_header);
776 len = strlenW(lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue) + strlenW(szUrlForm);
777 lpszUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
778 sprintfW( lpszUrl, szUrlForm, lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue );
780 if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) &&
781 InternetGetCookieW(lpszUrl, NULL, NULL, &nCookieSize))
784 static const WCHAR szCookie[] = {'C','o','o','k','i','e',':',' ',0};
785 static const WCHAR szcrlf[] = {'\r','\n',0};
787 lpszCookies = HeapAlloc(GetProcessHeap(), 0, (nCookieSize + 1 + 8)*sizeof(WCHAR));
789 cnt += sprintfW(lpszCookies, szCookie);
790 InternetGetCookieW(lpszUrl, NULL, lpszCookies + cnt, &nCookieSize);
791 strcatW(lpszCookies, szcrlf);
793 HTTP_HttpAddRequestHeadersW(lpwhr, lpszCookies, strlenW(lpszCookies),
794 HTTP_ADDREQ_FLAG_ADD);
795 HeapFree(GetProcessHeap(), 0, lpszCookies);
797 HeapFree(GetProcessHeap(), 0, lpszUrl);
800 iar.dwResult = (DWORD_PTR)handle;
801 iar.dwError = ERROR_SUCCESS;
803 SendAsyncCallback(&lpwhs->hdr, dwContext,
804 INTERNET_STATUS_HANDLE_CREATED, &iar,
805 sizeof(INTERNET_ASYNC_RESULT));
808 * A STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on windows
812 * According to my tests. The name is not resolved until a request is Opened
814 SendAsyncCallback(&lpwhr->hdr, dwContext,
815 INTERNET_STATUS_RESOLVING_NAME,
816 lpwhs->lpszServerName,
817 strlenW(lpwhs->lpszServerName)+1);
818 if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
819 &lpwhs->phostent, &lpwhs->socketAddress))
821 INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
822 InternetCloseHandle( handle );
827 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
828 INTERNET_STATUS_NAME_RESOLVED,
829 &(lpwhs->socketAddress),
830 sizeof(struct sockaddr_in));
834 WININET_Release( &lpwhr->hdr );
836 TRACE("<-- %p (%p)\n", handle, lpwhr);
840 /***********************************************************************
841 * HTTP_HttpQueryInfoW (internal)
843 static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD dwInfoLevel,
844 LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
846 LPHTTPHEADERW lphttpHdr = NULL;
847 BOOL bSuccess = FALSE;
849 /* Find requested header structure */
850 if ((dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK) == HTTP_QUERY_CUSTOM)
852 INT index = HTTP_GetCustomHeaderIndex(lpwhr, (LPWSTR)lpBuffer);
857 lphttpHdr = &lpwhr->pCustHeaders[index];
861 INT index = dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK;
863 if (index == HTTP_QUERY_RAW_HEADERS_CRLF)
865 DWORD len = strlenW(lpwhr->lpszRawHeaders);
866 if (len + 1 > *lpdwBufferLength/sizeof(WCHAR))
868 *lpdwBufferLength = (len + 1) * sizeof(WCHAR);
869 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
872 memcpy(lpBuffer, lpwhr->lpszRawHeaders, (len+1)*sizeof(WCHAR));
873 *lpdwBufferLength = len * sizeof(WCHAR);
875 TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len));
879 else if (index == HTTP_QUERY_RAW_HEADERS)
881 static const WCHAR szCrLf[] = {'\r','\n',0};
882 LPWSTR * ppszRawHeaderLines = HTTP_Tokenize(lpwhr->lpszRawHeaders, szCrLf);
884 LPWSTR pszString = (WCHAR*)lpBuffer;
886 for (i = 0; ppszRawHeaderLines[i]; i++)
887 size += strlenW(ppszRawHeaderLines[i]) + 1;
889 if (size + 1 > *lpdwBufferLength/sizeof(WCHAR))
891 HTTP_FreeTokens(ppszRawHeaderLines);
892 *lpdwBufferLength = (size + 1) * sizeof(WCHAR);
893 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
897 for (i = 0; ppszRawHeaderLines[i]; i++)
899 DWORD len = strlenW(ppszRawHeaderLines[i]);
900 memcpy(pszString, ppszRawHeaderLines[i], (len+1)*sizeof(WCHAR));
905 TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, size));
907 *lpdwBufferLength = size * sizeof(WCHAR);
908 HTTP_FreeTokens(ppszRawHeaderLines);
912 else if (index >= 0 && index <= HTTP_QUERY_MAX && lpwhr->StdHeaders[index].lpszValue)
914 lphttpHdr = &lpwhr->StdHeaders[index];
918 SetLastError(ERROR_HTTP_HEADER_NOT_FOUND);
923 /* Ensure header satisifies requested attributes */
924 if ((dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS) &&
925 (~lphttpHdr->wFlags & HDR_ISREQUEST))
927 SetLastError(ERROR_HTTP_HEADER_NOT_FOUND);
931 /* coalesce value to reuqested type */
932 if (dwInfoLevel & HTTP_QUERY_FLAG_NUMBER)
934 *(int *)lpBuffer = atoiW(lphttpHdr->lpszValue);
937 TRACE(" returning number : %d\n", *(int *)lpBuffer);
939 else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME)
945 tmpTime = ConvertTimeString(lphttpHdr->lpszValue);
947 tmpTM = *gmtime(&tmpTime);
948 STHook = (SYSTEMTIME *) lpBuffer;
952 STHook->wDay = tmpTM.tm_mday;
953 STHook->wHour = tmpTM.tm_hour;
954 STHook->wMilliseconds = 0;
955 STHook->wMinute = tmpTM.tm_min;
956 STHook->wDayOfWeek = tmpTM.tm_wday;
957 STHook->wMonth = tmpTM.tm_mon + 1;
958 STHook->wSecond = tmpTM.tm_sec;
959 STHook->wYear = tmpTM.tm_year;
963 TRACE(" returning time : %04d/%02d/%02d - %d - %02d:%02d:%02d.%02d\n",
964 STHook->wYear, STHook->wMonth, STHook->wDay, STHook->wDayOfWeek,
965 STHook->wHour, STHook->wMinute, STHook->wSecond, STHook->wMilliseconds);
967 else if (dwInfoLevel & HTTP_QUERY_FLAG_COALESCE)
969 if (*lpdwIndex >= lphttpHdr->wCount)
971 INTERNET_SetLastError(ERROR_HTTP_HEADER_NOT_FOUND);
975 /* Copy strncpyW(lpBuffer, lphttpHdr[*lpdwIndex], len); */
981 DWORD len = (strlenW(lphttpHdr->lpszValue) + 1) * sizeof(WCHAR);
983 if (len > *lpdwBufferLength)
985 *lpdwBufferLength = len;
986 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
990 memcpy(lpBuffer, lphttpHdr->lpszValue, len);
991 *lpdwBufferLength = len - sizeof(WCHAR);
994 TRACE(" returning string : '%s'\n", debugstr_w(lpBuffer));
999 /***********************************************************************
1000 * HttpQueryInfoW (WININET.@)
1002 * Queries for information about an HTTP request
1009 BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel,
1010 LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
1012 BOOL bSuccess = FALSE;
1013 LPWININETHTTPREQW lpwhr;
1015 if (TRACE_ON(wininet)) {
1016 #define FE(x) { x, #x }
1017 static const wininet_flag_info query_flags[] = {
1018 FE(HTTP_QUERY_MIME_VERSION),
1019 FE(HTTP_QUERY_CONTENT_TYPE),
1020 FE(HTTP_QUERY_CONTENT_TRANSFER_ENCODING),
1021 FE(HTTP_QUERY_CONTENT_ID),
1022 FE(HTTP_QUERY_CONTENT_DESCRIPTION),
1023 FE(HTTP_QUERY_CONTENT_LENGTH),
1024 FE(HTTP_QUERY_CONTENT_LANGUAGE),
1025 FE(HTTP_QUERY_ALLOW),
1026 FE(HTTP_QUERY_PUBLIC),
1027 FE(HTTP_QUERY_DATE),
1028 FE(HTTP_QUERY_EXPIRES),
1029 FE(HTTP_QUERY_LAST_MODIFIED),
1030 FE(HTTP_QUERY_MESSAGE_ID),
1032 FE(HTTP_QUERY_DERIVED_FROM),
1033 FE(HTTP_QUERY_COST),
1034 FE(HTTP_QUERY_LINK),
1035 FE(HTTP_QUERY_PRAGMA),
1036 FE(HTTP_QUERY_VERSION),
1037 FE(HTTP_QUERY_STATUS_CODE),
1038 FE(HTTP_QUERY_STATUS_TEXT),
1039 FE(HTTP_QUERY_RAW_HEADERS),
1040 FE(HTTP_QUERY_RAW_HEADERS_CRLF),
1041 FE(HTTP_QUERY_CONNECTION),
1042 FE(HTTP_QUERY_ACCEPT),
1043 FE(HTTP_QUERY_ACCEPT_CHARSET),
1044 FE(HTTP_QUERY_ACCEPT_ENCODING),
1045 FE(HTTP_QUERY_ACCEPT_LANGUAGE),
1046 FE(HTTP_QUERY_AUTHORIZATION),
1047 FE(HTTP_QUERY_CONTENT_ENCODING),
1048 FE(HTTP_QUERY_FORWARDED),
1049 FE(HTTP_QUERY_FROM),
1050 FE(HTTP_QUERY_IF_MODIFIED_SINCE),
1051 FE(HTTP_QUERY_LOCATION),
1052 FE(HTTP_QUERY_ORIG_URI),
1053 FE(HTTP_QUERY_REFERER),
1054 FE(HTTP_QUERY_RETRY_AFTER),
1055 FE(HTTP_QUERY_SERVER),
1056 FE(HTTP_QUERY_TITLE),
1057 FE(HTTP_QUERY_USER_AGENT),
1058 FE(HTTP_QUERY_WWW_AUTHENTICATE),
1059 FE(HTTP_QUERY_PROXY_AUTHENTICATE),
1060 FE(HTTP_QUERY_ACCEPT_RANGES),
1061 FE(HTTP_QUERY_SET_COOKIE),
1062 FE(HTTP_QUERY_COOKIE),
1063 FE(HTTP_QUERY_REQUEST_METHOD),
1064 FE(HTTP_QUERY_REFRESH),
1065 FE(HTTP_QUERY_CONTENT_DISPOSITION),
1067 FE(HTTP_QUERY_CACHE_CONTROL),
1068 FE(HTTP_QUERY_CONTENT_BASE),
1069 FE(HTTP_QUERY_CONTENT_LOCATION),
1070 FE(HTTP_QUERY_CONTENT_MD5),
1071 FE(HTTP_QUERY_CONTENT_RANGE),
1072 FE(HTTP_QUERY_ETAG),
1073 FE(HTTP_QUERY_HOST),
1074 FE(HTTP_QUERY_IF_MATCH),
1075 FE(HTTP_QUERY_IF_NONE_MATCH),
1076 FE(HTTP_QUERY_IF_RANGE),
1077 FE(HTTP_QUERY_IF_UNMODIFIED_SINCE),
1078 FE(HTTP_QUERY_MAX_FORWARDS),
1079 FE(HTTP_QUERY_PROXY_AUTHORIZATION),
1080 FE(HTTP_QUERY_RANGE),
1081 FE(HTTP_QUERY_TRANSFER_ENCODING),
1082 FE(HTTP_QUERY_UPGRADE),
1083 FE(HTTP_QUERY_VARY),
1085 FE(HTTP_QUERY_WARNING),
1086 FE(HTTP_QUERY_CUSTOM)
1088 static const wininet_flag_info modifier_flags[] = {
1089 FE(HTTP_QUERY_FLAG_REQUEST_HEADERS),
1090 FE(HTTP_QUERY_FLAG_SYSTEMTIME),
1091 FE(HTTP_QUERY_FLAG_NUMBER),
1092 FE(HTTP_QUERY_FLAG_COALESCE)
1095 DWORD info_mod = dwInfoLevel & HTTP_QUERY_MODIFIER_FLAGS_MASK;
1096 DWORD info = dwInfoLevel & HTTP_QUERY_HEADER_MASK;
1099 TRACE("(%p, 0x%08lx)--> %ld\n", hHttpRequest, dwInfoLevel, dwInfoLevel);
1100 TRACE(" Attribute:");
1101 for (i = 0; i < (sizeof(query_flags) / sizeof(query_flags[0])); i++) {
1102 if (query_flags[i].val == info) {
1103 TRACE(" %s", query_flags[i].name);
1107 if (i == (sizeof(query_flags) / sizeof(query_flags[0]))) {
1108 TRACE(" Unknown (%08lx)", info);
1111 TRACE(" Modifier:");
1112 for (i = 0; i < (sizeof(modifier_flags) / sizeof(modifier_flags[0])); i++) {
1113 if (modifier_flags[i].val & info_mod) {
1114 TRACE(" %s", modifier_flags[i].name);
1115 info_mod &= ~ modifier_flags[i].val;
1120 TRACE(" Unknown (%08lx)", info_mod);
1125 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest );
1126 if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
1128 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1132 bSuccess = HTTP_HttpQueryInfoW( lpwhr, dwInfoLevel,
1133 lpBuffer, lpdwBufferLength, lpdwIndex);
1137 WININET_Release( &lpwhr->hdr );
1139 TRACE("%d <--\n", bSuccess);
1143 /***********************************************************************
1144 * HttpQueryInfoA (WININET.@)
1146 * Queries for information about an HTTP request
1153 BOOL WINAPI HttpQueryInfoA(HINTERNET hHttpRequest, DWORD dwInfoLevel,
1154 LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex)
1160 if((dwInfoLevel & HTTP_QUERY_FLAG_NUMBER) ||
1161 (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME))
1163 return HttpQueryInfoW( hHttpRequest, dwInfoLevel, lpBuffer,
1164 lpdwBufferLength, lpdwIndex );
1167 len = (*lpdwBufferLength)*sizeof(WCHAR);
1168 bufferW = HeapAlloc( GetProcessHeap(), 0, len );
1169 result = HttpQueryInfoW( hHttpRequest, dwInfoLevel, bufferW,
1173 len = WideCharToMultiByte( CP_ACP,0, bufferW, len / sizeof(WCHAR) + 1,
1174 lpBuffer, *lpdwBufferLength, NULL, NULL );
1175 *lpdwBufferLength = len - 1;
1177 TRACE("lpBuffer: %s\n", debugstr_a(lpBuffer));
1180 /* since the strings being returned from HttpQueryInfoW should be
1181 * only ASCII characters, it is reasonable to assume that all of
1182 * the Unicode characters can be reduced to a single byte */
1183 *lpdwBufferLength = len / sizeof(WCHAR);
1185 HeapFree(GetProcessHeap(), 0, bufferW );
1190 /***********************************************************************
1191 * HttpSendRequestExA (WININET.@)
1193 * Sends the specified request to the HTTP server and allows chunked
1196 BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest,
1197 LPINTERNET_BUFFERSA lpBuffersIn,
1198 LPINTERNET_BUFFERSA lpBuffersOut,
1199 DWORD dwFlags, DWORD dwContext)
1201 FIXME("(%p, %p, %p, %08lx, %08lx): stub\n", hRequest, lpBuffersIn,
1202 lpBuffersOut, dwFlags, dwContext);
1206 /***********************************************************************
1207 * HttpSendRequestExW (WININET.@)
1209 * Sends the specified request to the HTTP server and allows chunked
1212 BOOL WINAPI HttpSendRequestExW(HINTERNET hRequest,
1213 LPINTERNET_BUFFERSW lpBuffersIn,
1214 LPINTERNET_BUFFERSW lpBuffersOut,
1215 DWORD dwFlags, DWORD dwContext)
1217 FIXME("(%p, %p, %p, %08lx, %08lx): stub\n", hRequest, lpBuffersIn,
1218 lpBuffersOut, dwFlags, dwContext);
1222 /***********************************************************************
1223 * HttpSendRequestW (WININET.@)
1225 * Sends the specified request to the HTTP server
1232 BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders,
1233 DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
1235 LPWININETHTTPREQW lpwhr;
1236 LPWININETHTTPSESSIONW lpwhs = NULL;
1237 LPWININETAPPINFOW hIC = NULL;
1240 TRACE("%p, %p (%s), %li, %p, %li)\n", hHttpRequest,
1241 lpszHeaders, debugstr_w(lpszHeaders), dwHeaderLength, lpOptional, dwOptionalLength);
1243 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest );
1244 if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
1246 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1251 lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
1252 if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
1254 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1259 hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
1260 if (NULL == hIC || hIC->hdr.htype != WH_HINIT)
1262 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1267 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1269 WORKREQUEST workRequest;
1270 struct WORKREQ_HTTPSENDREQUESTW *req;
1272 workRequest.asyncall = HTTPSENDREQUESTW;
1273 workRequest.hdr = WININET_AddRef( &lpwhr->hdr );
1274 req = &workRequest.u.HttpSendRequestW;
1276 req->lpszHeader = WININET_strdupW(lpszHeaders);
1278 req->lpszHeader = 0;
1279 req->dwHeaderLength = dwHeaderLength;
1280 req->lpOptional = lpOptional;
1281 req->dwOptionalLength = dwOptionalLength;
1283 INTERNET_AsyncCall(&workRequest);
1285 * This is from windows.
1287 SetLastError(ERROR_IO_PENDING);
1292 r = HTTP_HttpSendRequestW(lpwhr, lpszHeaders,
1293 dwHeaderLength, lpOptional, dwOptionalLength);
1297 WININET_Release( &lpwhr->hdr );
1301 /***********************************************************************
1302 * HttpSendRequestA (WININET.@)
1304 * Sends the specified request to the HTTP server
1311 BOOL WINAPI HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders,
1312 DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
1315 LPWSTR szHeaders=NULL;
1316 DWORD nLen=dwHeaderLength;
1317 if(lpszHeaders!=NULL)
1319 nLen=MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,NULL,0);
1320 szHeaders=HeapAlloc(GetProcessHeap(),0,nLen*sizeof(WCHAR));
1321 MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,szHeaders,nLen);
1323 result=HttpSendRequestW(hHttpRequest, szHeaders, nLen, lpOptional, dwOptionalLength);
1324 HeapFree(GetProcessHeap(),0,szHeaders);
1328 /***********************************************************************
1329 * HTTP_HandleRedirect (internal)
1331 static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl, LPCWSTR lpszHeaders,
1332 DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength)
1334 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
1335 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
1340 /* if it's an absolute path, keep the same session info */
1341 strcpyW(path,lpszUrl);
1343 else if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0)
1345 TRACE("Redirect through proxy\n");
1346 strcpyW(path,lpszUrl);
1350 URL_COMPONENTSW urlComponents;
1351 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
1352 WCHAR password[1024], extra[1024];
1353 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
1354 urlComponents.lpszScheme = protocol;
1355 urlComponents.dwSchemeLength = 32;
1356 urlComponents.lpszHostName = hostName;
1357 urlComponents.dwHostNameLength = MAXHOSTNAME;
1358 urlComponents.lpszUserName = userName;
1359 urlComponents.dwUserNameLength = 1024;
1360 urlComponents.lpszPassword = password;
1361 urlComponents.dwPasswordLength = 1024;
1362 urlComponents.lpszUrlPath = path;
1363 urlComponents.dwUrlPathLength = 2048;
1364 urlComponents.lpszExtraInfo = extra;
1365 urlComponents.dwExtraInfoLength = 1024;
1366 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
1369 if (urlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
1370 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
1374 * This upsets redirects to binary files on sourceforge.net
1375 * and gives an html page instead of the target file
1376 * Examination of the HTTP request sent by native wininet.dll
1377 * reveals that it doesn't send a referrer in that case.
1378 * Maybe there's a flag that enables this, or maybe a referrer
1379 * shouldn't be added in case of a redirect.
1382 /* consider the current host as the referrer */
1383 if (NULL != lpwhs->lpszServerName && strlenW(lpwhs->lpszServerName))
1384 HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpwhs->lpszServerName,
1385 HTTP_ADDHDR_FLAG_REQ|HTTP_ADDREQ_FLAG_REPLACE|
1386 HTTP_ADDHDR_FLAG_ADD_IF_NEW);
1389 HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
1390 lpwhs->lpszServerName = WININET_strdupW(hostName);
1391 HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName);
1392 lpwhs->lpszUserName = WININET_strdupW(userName);
1393 lpwhs->nServerPort = urlComponents.nPort;
1395 HTTP_ProcessHeader(lpwhr, g_szHost, hostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
1397 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1398 INTERNET_STATUS_RESOLVING_NAME,
1399 lpwhs->lpszServerName,
1400 strlenW(lpwhs->lpszServerName)+1);
1402 if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort,
1403 &lpwhs->phostent, &lpwhs->socketAddress))
1405 INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
1409 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1410 INTERNET_STATUS_NAME_RESOLVED,
1411 &(lpwhs->socketAddress),
1412 sizeof(struct sockaddr_in));
1416 HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
1417 lpwhr->lpszPath=NULL;
1423 rc = UrlEscapeW(path, NULL, &needed, URL_ESCAPE_SPACES_ONLY);
1424 if (rc != E_POINTER)
1425 needed = strlenW(path)+1;
1426 lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, needed*sizeof(WCHAR));
1427 rc = UrlEscapeW(path, lpwhr->lpszPath, &needed,
1428 URL_ESCAPE_SPACES_ONLY);
1431 ERR("Unable to escape string!(%s) (%ld)\n",debugstr_w(path),rc);
1432 strcpyW(lpwhr->lpszPath,path);
1436 return HTTP_HttpSendRequestW(lpwhr, lpszHeaders, dwHeaderLength, lpOptional, dwOptionalLength);
1439 /***********************************************************************
1440 * HTTP_build_req (internal)
1442 * concatenate all the strings in the request together
1444 static LPWSTR HTTP_build_req( LPCWSTR *list, int len )
1449 for( t = list; *t ; t++ )
1450 len += strlenW( *t );
1453 str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1456 for( t = list; *t ; t++ )
1462 /***********************************************************************
1463 * HTTP_HttpSendRequestW (internal)
1465 * Sends the specified request to the HTTP server
1472 BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
1473 DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength)
1477 BOOL bSuccess = FALSE;
1478 LPWSTR requestString = NULL;
1480 LPWININETHTTPSESSIONW lpwhs = NULL;
1481 LPWININETAPPINFOW hIC = NULL;
1482 BOOL loop_next = FALSE;
1483 int CustHeaderIndex;
1484 INTERNET_ASYNC_RESULT iar;
1486 TRACE("--> %p\n", lpwhr);
1488 assert(lpwhr->hdr.htype == WH_HHTTPREQ);
1490 lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
1491 if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
1493 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1497 hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
1498 if (NULL == hIC || hIC->hdr.htype != WH_HINIT)
1500 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1504 /* Clear any error information */
1505 INTERNET_SetLastError(0);
1508 /* if the verb is NULL default to GET */
1509 if (NULL == lpwhr->lpszVerb)
1511 static const WCHAR szGET[] = { 'G','E','T', 0 };
1512 lpwhr->lpszVerb = WININET_strdupW(szGET);
1515 /* if we are using optional stuff, we must add the fixed header of that option length */
1516 if (lpOptional && dwOptionalLength)
1518 static const WCHAR szContentLength[] = {
1519 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','l','i','\r','\n',0};
1520 WCHAR contentLengthStr[sizeof szContentLength/2 /* includes \n\r */ + 20 /* int */ ];
1521 sprintfW(contentLengthStr, szContentLength, dwOptionalLength);
1522 HTTP_HttpAddRequestHeadersW(lpwhr, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD);
1527 static const WCHAR szSlash[] = { '/',0 };
1528 static const WCHAR szSpace[] = { ' ',0 };
1529 static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/', 0 };
1530 static const WCHAR szcrlf[] = {'\r','\n', 0};
1531 static const WCHAR sztwocrlf[] = {'\r','\n','\r','\n', 0};
1532 static const WCHAR szSetCookie[] = {'S','e','t','-','C','o','o','k','i','e',0 };
1533 static const WCHAR szColon[] = { ':',' ',0 };
1539 TRACE("Going to url %s %s\n", debugstr_w(lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue), debugstr_w(lpwhr->lpszPath));
1542 /* If we don't have a path we set it to root */
1543 if (NULL == lpwhr->lpszPath)
1544 lpwhr->lpszPath = WININET_strdupW(szSlash);
1545 else /* remove \r and \n*/
1547 int nLen = strlenW(lpwhr->lpszPath);
1548 while ((nLen >0 ) && ((lpwhr->lpszPath[nLen-1] == '\r')||(lpwhr->lpszPath[nLen-1] == '\n')))
1551 lpwhr->lpszPath[nLen]='\0';
1553 /* Replace '\' with '/' */
1556 if (lpwhr->lpszPath[nLen] == '\\') lpwhr->lpszPath[nLen]='/';
1560 if(CSTR_EQUAL != CompareStringW( LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE,
1561 lpwhr->lpszPath, strlenW(szHttp), szHttp, strlenW(szHttp) )
1562 && lpwhr->lpszPath[0] != '/') /* not an absolute path ?? --> fix it !! */
1564 WCHAR *fixurl = HeapAlloc(GetProcessHeap(), 0,
1565 (strlenW(lpwhr->lpszPath) + 2)*sizeof(WCHAR));
1567 strcpyW(fixurl + 1, lpwhr->lpszPath);
1568 HeapFree( GetProcessHeap(), 0, lpwhr->lpszPath );
1569 lpwhr->lpszPath = fixurl;
1572 /* add the headers the caller supplied */
1573 if( lpszHeaders && dwHeaderLength )
1575 HTTP_HttpAddRequestHeadersW(lpwhr, lpszHeaders, dwHeaderLength,
1576 HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE);
1579 /* if there's a proxy username and password, add it to the headers */
1580 if (hIC && (hIC->lpszProxyUsername || hIC->lpszProxyPassword ))
1581 HTTP_InsertProxyAuthorization(lpwhr, hIC->lpszProxyUsername, hIC->lpszProxyPassword);
1583 /* allocate space for an array of all the string pointers to be added */
1584 len = (HTTP_QUERY_MAX + lpwhr->nCustHeaders)*4 + 9;
1585 req = HeapAlloc( GetProcessHeap(), 0, len*sizeof(LPCWSTR) );
1587 /* add the verb, path and HTTP/1.0 */
1589 req[n++] = lpwhr->lpszVerb;
1591 req[n++] = lpwhr->lpszPath;
1592 req[n++] = HTTPHEADER;
1594 /* Append standard request headers */
1595 for (i = 0; i <= HTTP_QUERY_MAX; i++)
1597 if (lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST)
1600 req[n++] = lpwhr->StdHeaders[i].lpszField;
1602 req[n++] = lpwhr->StdHeaders[i].lpszValue;
1604 TRACE("Adding header %s (%s)\n",
1605 debugstr_w(lpwhr->StdHeaders[i].lpszField),
1606 debugstr_w(lpwhr->StdHeaders[i].lpszValue));
1610 /* Append custom request heades */
1611 for (i = 0; i < lpwhr->nCustHeaders; i++)
1613 if (lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST)
1616 req[n++] = lpwhr->pCustHeaders[i].lpszField;
1618 req[n++] = lpwhr->pCustHeaders[i].lpszValue;
1620 TRACE("Adding custom header %s (%s)\n",
1621 debugstr_w(lpwhr->pCustHeaders[i].lpszField),
1622 debugstr_w(lpwhr->pCustHeaders[i].lpszValue));
1627 ERR("oops. buffer overrun\n");
1630 requestString = HTTP_build_req( req, 4 );
1631 HeapFree( GetProcessHeap(), 0, req );
1634 * Set (header) termination string for request
1635 * Make sure there's exactly two new lines at the end of the request
1637 p = &requestString[strlenW(requestString)-1];
1638 while ( (*p == '\n') || (*p == '\r') )
1640 strcpyW( p+1, sztwocrlf );
1642 TRACE("Request header -> %s\n", debugstr_w(requestString) );
1644 /* Send the request and store the results */
1645 if (!HTTP_OpenConnection(lpwhr))
1648 /* send the request as ASCII, tack on the optional data */
1650 dwOptionalLength = 0;
1651 len = WideCharToMultiByte( CP_ACP, 0, requestString, -1,
1652 NULL, 0, NULL, NULL );
1653 ascii_req = HeapAlloc( GetProcessHeap(), 0, len + dwOptionalLength );
1654 WideCharToMultiByte( CP_ACP, 0, requestString, -1,
1655 ascii_req, len, NULL, NULL );
1657 memcpy( &ascii_req[len-1], lpOptional, dwOptionalLength );
1658 len = (len + dwOptionalLength - 1);
1660 TRACE("full request -> %s\n", ascii_req );
1662 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1663 INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
1665 NETCON_send(&lpwhr->netConnection, ascii_req, len, 0, &cnt);
1666 HeapFree( GetProcessHeap(), 0, ascii_req );
1668 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1669 INTERNET_STATUS_REQUEST_SENT,
1670 &len,sizeof(DWORD));
1672 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1673 INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
1678 responseLen = HTTP_GetResponseHeaders(lpwhr);
1682 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1683 INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen,
1686 /* process headers here. Is this right? */
1687 CustHeaderIndex = HTTP_GetCustomHeaderIndex(lpwhr, szSetCookie);
1688 if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) && (CustHeaderIndex >= 0))
1690 LPHTTPHEADERW setCookieHeader;
1691 int nPosStart = 0, nPosEnd = 0, len;
1692 static const WCHAR szFmt[] = { 'h','t','t','p',':','/','/','%','s','/',0};
1694 setCookieHeader = &lpwhr->pCustHeaders[CustHeaderIndex];
1696 while (setCookieHeader->lpszValue[nPosEnd] != '\0')
1698 LPWSTR buf_cookie, cookie_name, cookie_data;
1700 LPWSTR domain = NULL;
1702 while (setCookieHeader->lpszValue[nPosEnd] != ';' && setCookieHeader->lpszValue[nPosEnd] != ',' &&
1703 setCookieHeader->lpszValue[nPosEnd] != '\0')
1707 if (setCookieHeader->lpszValue[nPosEnd] == ';')
1709 /* fixme: not case sensitive, strcasestr is gnu only */
1710 int nDomainPosEnd = 0;
1711 int nDomainPosStart = 0, nDomainLength = 0;
1712 static const WCHAR szDomain[] = {'d','o','m','a','i','n','=',0};
1713 LPWSTR lpszDomain = strstrW(&setCookieHeader->lpszValue[nPosEnd], szDomain);
1715 { /* they have specified their own domain, lets use it */
1716 while (lpszDomain[nDomainPosEnd] != ';' && lpszDomain[nDomainPosEnd] != ',' &&
1717 lpszDomain[nDomainPosEnd] != '\0')
1721 nDomainPosStart = strlenW(szDomain);
1722 nDomainLength = (nDomainPosEnd - nDomainPosStart) + 1;
1723 domain = HeapAlloc(GetProcessHeap(), 0, (nDomainLength + 1)*sizeof(WCHAR));
1724 lstrcpynW(domain, &lpszDomain[nDomainPosStart], nDomainLength + 1);
1727 if (setCookieHeader->lpszValue[nPosEnd] == '\0') break;
1728 buf_cookie = HeapAlloc(GetProcessHeap(), 0, ((nPosEnd - nPosStart) + 1)*sizeof(WCHAR));
1729 lstrcpynW(buf_cookie, &setCookieHeader->lpszValue[nPosStart], (nPosEnd - nPosStart) + 1);
1730 TRACE("%s\n", debugstr_w(buf_cookie));
1731 while (buf_cookie[nEqualPos] != '=' && buf_cookie[nEqualPos] != '\0')
1735 if (buf_cookie[nEqualPos] == '\0' || buf_cookie[nEqualPos + 1] == '\0')
1737 HeapFree(GetProcessHeap(), 0, buf_cookie);
1741 cookie_name = HeapAlloc(GetProcessHeap(), 0, (nEqualPos + 1)*sizeof(WCHAR));
1742 lstrcpynW(cookie_name, buf_cookie, nEqualPos + 1);
1743 cookie_data = &buf_cookie[nEqualPos + 1];
1746 len = strlenW((domain ? domain : lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue)) +
1747 strlenW(lpwhr->lpszPath) + 9;
1748 buf_url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
1749 sprintfW(buf_url, szFmt, (domain ? domain : lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue)); /* FIXME PATH!!! */
1750 InternetSetCookieW(buf_url, cookie_name, cookie_data);
1752 HeapFree(GetProcessHeap(), 0, buf_url);
1753 HeapFree(GetProcessHeap(), 0, buf_cookie);
1754 HeapFree(GetProcessHeap(), 0, cookie_name);
1755 HeapFree(GetProcessHeap(), 0, domain);
1756 nPosStart = nPosEnd;
1764 HeapFree(GetProcessHeap(), 0, requestString);
1766 /* TODO: send notification for P3P header */
1768 if(!(hIC->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT) && bSuccess)
1770 DWORD dwCode,dwCodeLength=sizeof(DWORD),dwIndex=0;
1771 if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,&dwCode,&dwCodeLength,&dwIndex) &&
1772 (dwCode==302 || dwCode==301))
1774 WCHAR szNewLocation[2048];
1775 DWORD dwBufferSize=2048;
1777 if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,&dwIndex))
1779 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1780 INTERNET_STATUS_REDIRECT, szNewLocation,
1782 return HTTP_HandleRedirect(lpwhr, szNewLocation, lpszHeaders,
1783 dwHeaderLength, lpOptional, dwOptionalLength);
1789 iar.dwResult = (DWORD)bSuccess;
1790 iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
1792 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1793 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1794 sizeof(INTERNET_ASYNC_RESULT));
1801 /***********************************************************************
1802 * HTTP_Connect (internal)
1804 * Create http session handle
1807 * HINTERNET a session handle on success
1811 HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName,
1812 INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
1813 LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
1814 DWORD dwInternalFlags)
1816 BOOL bSuccess = FALSE;
1817 LPWININETHTTPSESSIONW lpwhs = NULL;
1818 HINTERNET handle = NULL;
1822 assert( hIC->hdr.htype == WH_HINIT );
1824 hIC->hdr.dwContext = dwContext;
1826 lpwhs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPSESSIONW));
1829 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1834 * According to my tests. The name is not resolved until a request is sent
1837 if (nServerPort == INTERNET_INVALID_PORT_NUMBER)
1838 nServerPort = INTERNET_DEFAULT_HTTP_PORT;
1840 lpwhs->hdr.htype = WH_HHTTPSESSION;
1841 lpwhs->hdr.lpwhparent = WININET_AddRef( &hIC->hdr );
1842 lpwhs->hdr.dwFlags = dwFlags;
1843 lpwhs->hdr.dwContext = dwContext;
1844 lpwhs->hdr.dwInternalFlags = dwInternalFlags;
1845 lpwhs->hdr.dwRefCount = 1;
1846 lpwhs->hdr.destroy = HTTP_CloseHTTPSessionHandle;
1847 lpwhs->hdr.lpfnStatusCB = hIC->hdr.lpfnStatusCB;
1849 handle = WININET_AllocHandle( &lpwhs->hdr );
1852 ERR("Failed to alloc handle\n");
1853 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1857 if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1858 if(strchrW(hIC->lpszProxy, ' '))
1859 FIXME("Several proxies not implemented.\n");
1860 if(hIC->lpszProxyBypass)
1861 FIXME("Proxy bypass is ignored.\n");
1863 if (NULL != lpszServerName)
1864 lpwhs->lpszServerName = WININET_strdupW(lpszServerName);
1865 if (NULL != lpszUserName)
1866 lpwhs->lpszUserName = WININET_strdupW(lpszUserName);
1867 lpwhs->nServerPort = nServerPort;
1869 /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
1870 if (!(lpwhs->hdr.dwInternalFlags & INET_OPENURL))
1872 INTERNET_ASYNC_RESULT iar;
1874 iar.dwResult = (DWORD_PTR)handle;
1875 iar.dwError = ERROR_SUCCESS;
1877 SendAsyncCallback(&lpwhs->hdr, dwContext,
1878 INTERNET_STATUS_HANDLE_CREATED, &iar,
1879 sizeof(INTERNET_ASYNC_RESULT));
1886 WININET_Release( &lpwhs->hdr );
1889 * an INTERNET_STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on
1893 TRACE("%p --> %p (%p)\n", hIC, handle, lpwhs);
1898 /***********************************************************************
1899 * HTTP_OpenConnection (internal)
1901 * Connect to a web server
1908 BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr)
1910 BOOL bSuccess = FALSE;
1911 LPWININETHTTPSESSIONW lpwhs;
1912 LPWININETAPPINFOW hIC = NULL;
1917 if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
1919 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1923 lpwhs = (LPWININETHTTPSESSIONW)lpwhr->hdr.lpwhparent;
1925 hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
1926 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1927 INTERNET_STATUS_CONNECTING_TO_SERVER,
1928 &(lpwhs->socketAddress),
1929 sizeof(struct sockaddr_in));
1931 if (!NETCON_create(&lpwhr->netConnection, lpwhs->phostent->h_addrtype,
1934 WARN("Socket creation failed\n");
1938 if (!NETCON_connect(&lpwhr->netConnection, (struct sockaddr *)&lpwhs->socketAddress,
1939 sizeof(lpwhs->socketAddress)))
1941 WARN("Unable to connect to host (%s)\n", strerror(errno));
1945 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
1946 INTERNET_STATUS_CONNECTED_TO_SERVER,
1947 &(lpwhs->socketAddress),
1948 sizeof(struct sockaddr_in));
1953 TRACE("%d <--\n", bSuccess);
1958 /***********************************************************************
1959 * HTTP_clear_response_headers (internal)
1961 * clear out any old response headers
1963 static void HTTP_clear_response_headers( LPWININETHTTPREQW lpwhr )
1967 for( i=0; i<=HTTP_QUERY_MAX; i++ )
1969 if( !lpwhr->StdHeaders[i].lpszField )
1971 if( !lpwhr->StdHeaders[i].lpszValue )
1973 if ( lpwhr->StdHeaders[i].wFlags & HDR_ISREQUEST )
1975 HTTP_ReplaceHeaderValue( &lpwhr->StdHeaders[i], NULL );
1976 HeapFree( GetProcessHeap(), 0, lpwhr->StdHeaders[i].lpszField );
1977 lpwhr->StdHeaders[i].lpszField = NULL;
1979 for( i=0; i<lpwhr->nCustHeaders; i++)
1981 if( !lpwhr->pCustHeaders[i].lpszField )
1983 if( !lpwhr->pCustHeaders[i].lpszValue )
1985 if ( lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST )
1987 HTTP_DeleteCustomHeader( lpwhr, i );
1992 /***********************************************************************
1993 * HTTP_GetResponseHeaders (internal)
1995 * Read server response
2002 BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr)
2005 WCHAR buffer[MAX_REPLY_LEN];
2006 DWORD buflen = MAX_REPLY_LEN;
2007 BOOL bSuccess = FALSE;
2009 static const WCHAR szCrLf[] = {'\r','\n',0};
2010 char bufferA[MAX_REPLY_LEN];
2011 LPWSTR status_code, status_text;
2012 DWORD cchMaxRawHeaders = 1024;
2013 LPWSTR lpszRawHeaders = HeapAlloc(GetProcessHeap(), 0, (cchMaxRawHeaders+1)*sizeof(WCHAR));
2014 DWORD cchRawHeaders = 0;
2018 /* clear old response headers (eg. from a redirect response) */
2019 HTTP_clear_response_headers( lpwhr );
2021 if (!NETCON_connected(&lpwhr->netConnection))
2025 * HACK peek at the buffer
2027 NETCON_recv(&lpwhr->netConnection, buffer, buflen, MSG_PEEK, &rc);
2030 * We should first receive 'HTTP/1.x nnn OK' where nnn is the status code.
2032 buflen = MAX_REPLY_LEN;
2033 memset(buffer, 0, MAX_REPLY_LEN);
2034 if (!NETCON_getNextLine(&lpwhr->netConnection, bufferA, &buflen))
2036 MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
2038 /* regenerate raw headers */
2039 while (cchRawHeaders + buflen + strlenW(szCrLf) > cchMaxRawHeaders)
2041 cchMaxRawHeaders *= 2;
2042 lpszRawHeaders = HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders, (cchMaxRawHeaders+1)*sizeof(WCHAR));
2044 memcpy(lpszRawHeaders+cchRawHeaders, buffer, (buflen-1)*sizeof(WCHAR));
2045 cchRawHeaders += (buflen-1);
2046 memcpy(lpszRawHeaders+cchRawHeaders, szCrLf, sizeof(szCrLf));
2047 cchRawHeaders += sizeof(szCrLf)/sizeof(szCrLf[0])-1;
2048 lpszRawHeaders[cchRawHeaders] = '\0';
2050 /* split the version from the status code */
2051 status_code = strchrW( buffer, ' ' );
2056 /* split the status code from the status text */
2057 status_text = strchrW( status_code, ' ' );
2062 TRACE("version [%s] status code [%s] status text [%s]\n",
2063 debugstr_w(buffer), debugstr_w(status_code), debugstr_w(status_text) );
2064 HTTP_ReplaceHeaderValue( &lpwhr->StdHeaders[HTTP_QUERY_VERSION], buffer );
2065 HTTP_ReplaceHeaderValue( &lpwhr->StdHeaders[HTTP_QUERY_STATUS_CODE], status_code );
2066 HTTP_ReplaceHeaderValue( &lpwhr->StdHeaders[HTTP_QUERY_STATUS_TEXT], status_text );
2068 /* Parse each response line */
2071 buflen = MAX_REPLY_LEN;
2072 if (NETCON_getNextLine(&lpwhr->netConnection, bufferA, &buflen))
2074 LPWSTR * pFieldAndValue;
2076 TRACE("got line %s, now interpreting\n", debugstr_a(bufferA));
2077 MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN );
2079 while (cchRawHeaders + buflen + strlenW(szCrLf) > cchMaxRawHeaders)
2081 cchMaxRawHeaders *= 2;
2082 lpszRawHeaders = HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders, (cchMaxRawHeaders+1)*sizeof(WCHAR));
2084 memcpy(lpszRawHeaders+cchRawHeaders, buffer, (buflen-1)*sizeof(WCHAR));
2085 cchRawHeaders += (buflen-1);
2086 memcpy(lpszRawHeaders+cchRawHeaders, szCrLf, sizeof(szCrLf));
2087 cchRawHeaders += sizeof(szCrLf)/sizeof(szCrLf[0])-1;
2088 lpszRawHeaders[cchRawHeaders] = '\0';
2090 pFieldAndValue = HTTP_InterpretHttpHeader(buffer);
2091 if (!pFieldAndValue)
2094 HTTP_ProcessHeader(lpwhr, pFieldAndValue[0], pFieldAndValue[1],
2095 HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
2097 HTTP_FreeTokens(pFieldAndValue);
2107 HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders);
2108 lpwhr->lpszRawHeaders = lpszRawHeaders;
2109 TRACE("raw headers: %s\n", debugstr_w(lpszRawHeaders));
2122 static void strip_spaces(LPWSTR start)
2127 while (*str == ' ' && *str != '\0')
2131 memmove(start, str, sizeof(WCHAR) * (strlenW(str) + 1));
2133 end = start + strlenW(start) - 1;
2134 while (end >= start && *end == ' ')
2142 /***********************************************************************
2143 * HTTP_InterpretHttpHeader (internal)
2145 * Parse server response
2149 * Pointer to array of field, value, NULL on success.
2152 LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer)
2154 LPWSTR * pTokenPair;
2158 pTokenPair = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pTokenPair)*3);
2160 pszColon = strchrW(buffer, ':');
2161 /* must have two tokens */
2164 HTTP_FreeTokens(pTokenPair);
2166 TRACE("No ':' in line: %s\n", debugstr_w(buffer));
2170 pTokenPair[0] = HeapAlloc(GetProcessHeap(), 0, (pszColon - buffer + 1) * sizeof(WCHAR));
2173 HTTP_FreeTokens(pTokenPair);
2176 memcpy(pTokenPair[0], buffer, (pszColon - buffer) * sizeof(WCHAR));
2177 pTokenPair[0][pszColon - buffer] = '\0';
2181 len = strlenW(pszColon);
2182 pTokenPair[1] = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
2185 HTTP_FreeTokens(pTokenPair);
2188 memcpy(pTokenPair[1], pszColon, (len + 1) * sizeof(WCHAR));
2190 strip_spaces(pTokenPair[0]);
2191 strip_spaces(pTokenPair[1]);
2193 TRACE("field(%s) Value(%s)\n", debugstr_w(pTokenPair[0]), debugstr_w(pTokenPair[1]));
2198 /***********************************************************************
2199 * HTTP_GetStdHeaderIndex (internal)
2201 * Lookup field index in standard http header array
2203 * FIXME: This should be stuffed into a hash table
2205 INT HTTP_GetStdHeaderIndex(LPCWSTR lpszField)
2208 static const WCHAR szContentLength[] = {
2209 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0};
2210 static const WCHAR szQueryRange[] = {
2211 'R','a','n','g','e',0};
2212 static const WCHAR szContentRange[] = {
2213 'C','o','n','t','e','n','t','-','R','a','n','g','e',0};
2214 static const WCHAR szContentType[] = {
2215 'C','o','n','t','e','n','t','-','T','y','p','e',0};
2216 static const WCHAR szLastModified[] = {
2217 'L','a','s','t','-','M','o','d','i','f','i','e','d',0};
2218 static const WCHAR szLocation[] = {'L','o','c','a','t','i','o','n',0};
2219 static const WCHAR szAccept[] = {'A','c','c','e','p','t',0};
2220 static const WCHAR szReferer[] = { 'R','e','f','e','r','e','r',0};
2221 static const WCHAR szContentTrans[] = { 'C','o','n','t','e','n','t','-',
2222 'T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0};
2223 static const WCHAR szDate[] = { 'D','a','t','e',0};
2224 static const WCHAR szServer[] = { 'S','e','r','v','e','r',0};
2225 static const WCHAR szConnection[] = { 'C','o','n','n','e','c','t','i','o','n',0};
2226 static const WCHAR szETag[] = { 'E','T','a','g',0};
2227 static const WCHAR szAcceptRanges[] = {
2228 'A','c','c','e','p','t','-','R','a','n','g','e','s',0 };
2229 static const WCHAR szExpires[] = { 'E','x','p','i','r','e','s',0 };
2230 static const WCHAR szMimeVersion[] = {
2231 'M','i','m','e','-','V','e','r','s','i','o','n', 0};
2232 static const WCHAR szPragma[] = { 'P','r','a','g','m','a', 0};
2233 static const WCHAR szCacheControl[] = {
2234 'C','a','c','h','e','-','C','o','n','t','r','o','l',0};
2235 static const WCHAR szUserAgent[] = { 'U','s','e','r','-','A','g','e','n','t',0};
2236 static const WCHAR szProxyAuth[] = {
2237 'P','r','o','x','y','-',
2238 'A','u','t','h','e','n','t','i','c','a','t','e', 0};
2239 static const WCHAR szContentEncoding[] = {
2240 'C','o','n','t','e','n','t','-','E','n','c','o','d','i','n','g',0};
2241 static const WCHAR szCookie[] = {'C','o','o','k','i','e',0};
2242 static const WCHAR szVary[] = {'V','a','r','y',0};
2243 static const WCHAR szVia[] = {'V','i','a',0};
2245 if (!strcmpiW(lpszField, szContentLength))
2246 index = HTTP_QUERY_CONTENT_LENGTH;
2247 else if (!strcmpiW(lpszField,szQueryRange))
2248 index = HTTP_QUERY_RANGE;
2249 else if (!strcmpiW(lpszField,szContentRange))
2250 index = HTTP_QUERY_CONTENT_RANGE;
2251 else if (!strcmpiW(lpszField,szContentType))
2252 index = HTTP_QUERY_CONTENT_TYPE;
2253 else if (!strcmpiW(lpszField,szLastModified))
2254 index = HTTP_QUERY_LAST_MODIFIED;
2255 else if (!strcmpiW(lpszField,szLocation))
2256 index = HTTP_QUERY_LOCATION;
2257 else if (!strcmpiW(lpszField,szAccept))
2258 index = HTTP_QUERY_ACCEPT;
2259 else if (!strcmpiW(lpszField,szReferer))
2260 index = HTTP_QUERY_REFERER;
2261 else if (!strcmpiW(lpszField,szContentTrans))
2262 index = HTTP_QUERY_CONTENT_TRANSFER_ENCODING;
2263 else if (!strcmpiW(lpszField,szDate))
2264 index = HTTP_QUERY_DATE;
2265 else if (!strcmpiW(lpszField,szServer))
2266 index = HTTP_QUERY_SERVER;
2267 else if (!strcmpiW(lpszField,szConnection))
2268 index = HTTP_QUERY_CONNECTION;
2269 else if (!strcmpiW(lpszField,szETag))
2270 index = HTTP_QUERY_ETAG;
2271 else if (!strcmpiW(lpszField,szAcceptRanges))
2272 index = HTTP_QUERY_ACCEPT_RANGES;
2273 else if (!strcmpiW(lpszField,szExpires))
2274 index = HTTP_QUERY_EXPIRES;
2275 else if (!strcmpiW(lpszField,szMimeVersion))
2276 index = HTTP_QUERY_MIME_VERSION;
2277 else if (!strcmpiW(lpszField,szPragma))
2278 index = HTTP_QUERY_PRAGMA;
2279 else if (!strcmpiW(lpszField,szCacheControl))
2280 index = HTTP_QUERY_CACHE_CONTROL;
2281 else if (!strcmpiW(lpszField,szUserAgent))
2282 index = HTTP_QUERY_USER_AGENT;
2283 else if (!strcmpiW(lpszField,szProxyAuth))
2284 index = HTTP_QUERY_PROXY_AUTHENTICATE;
2285 else if (!strcmpiW(lpszField,szContentEncoding))
2286 index = HTTP_QUERY_CONTENT_ENCODING;
2287 else if (!strcmpiW(lpszField,szCookie))
2288 index = HTTP_QUERY_COOKIE;
2289 else if (!strcmpiW(lpszField,szVary))
2290 index = HTTP_QUERY_VARY;
2291 else if (!strcmpiW(lpszField,szVia))
2292 index = HTTP_QUERY_VIA;
2293 else if (!strcmpiW(lpszField,g_szHost))
2294 index = HTTP_QUERY_HOST;
2297 TRACE("Couldn't find %s in standard header table\n", debugstr_w(lpszField));
2303 /***********************************************************************
2304 * HTTP_ReplaceHeaderValue (internal)
2306 BOOL HTTP_ReplaceHeaderValue( LPHTTPHEADERW lphttpHdr, LPCWSTR value )
2310 HeapFree( GetProcessHeap(), 0, lphttpHdr->lpszValue );
2311 lphttpHdr->lpszValue = NULL;
2314 len = strlenW(value);
2317 lphttpHdr->lpszValue = HeapAlloc(GetProcessHeap(), 0,
2318 (len+1)*sizeof(WCHAR));
2319 strcpyW(lphttpHdr->lpszValue, value);
2324 /***********************************************************************
2325 * HTTP_ProcessHeader (internal)
2327 * Stuff header into header tables according to <dwModifier>
2331 #define COALESCEFLASG (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
2333 BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier)
2335 LPHTTPHEADERW lphttpHdr = NULL;
2336 BOOL bSuccess = FALSE;
2339 TRACE("--> %s: %s - 0x%08lx\n", debugstr_w(field), debugstr_w(value), dwModifier);
2341 /* Adjust modifier flags */
2342 if (dwModifier & COALESCEFLASG)
2343 dwModifier |= HTTP_ADDHDR_FLAG_ADD;
2345 /* Try to get index into standard header array */
2346 index = HTTP_GetStdHeaderIndex(field);
2347 /* Don't let applications add Connection header to request */
2348 if ((index == HTTP_QUERY_CONNECTION) && (dwModifier & HTTP_ADDHDR_FLAG_REQ))
2350 else if (index >= 0)
2352 lphttpHdr = &lpwhr->StdHeaders[index];
2354 else /* Find or create new custom header */
2356 index = HTTP_GetCustomHeaderIndex(lpwhr, field);
2359 if (dwModifier & HTTP_ADDHDR_FLAG_ADD_IF_NEW)
2363 lphttpHdr = &lpwhr->pCustHeaders[index];
2369 hdr.lpszField = (LPWSTR)field;
2370 hdr.lpszValue = (LPWSTR)value;
2371 hdr.wFlags = hdr.wCount = 0;
2373 if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
2374 hdr.wFlags |= HDR_ISREQUEST;
2376 return HTTP_InsertCustomHeader(lpwhr, &hdr);
2380 if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
2381 lphttpHdr->wFlags |= HDR_ISREQUEST;
2383 lphttpHdr->wFlags &= ~HDR_ISREQUEST;
2385 if (!lphttpHdr->lpszValue && (dwModifier & (HTTP_ADDHDR_FLAG_ADD|HTTP_ADDHDR_FLAG_ADD_IF_NEW)))
2389 if (!lpwhr->StdHeaders[index].lpszField)
2391 lphttpHdr->lpszField = WININET_strdupW(field);
2393 if (dwModifier & HTTP_ADDHDR_FLAG_REQ)
2394 lphttpHdr->wFlags |= HDR_ISREQUEST;
2397 slen = strlenW(value) + 1;
2398 lphttpHdr->lpszValue = HeapAlloc(GetProcessHeap(), 0, slen*sizeof(WCHAR));
2399 if (lphttpHdr->lpszValue)
2401 strcpyW(lphttpHdr->lpszValue, value);
2406 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
2409 else if (lphttpHdr->lpszValue)
2411 if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE)
2412 bSuccess = HTTP_ReplaceHeaderValue( lphttpHdr, value );
2413 else if (dwModifier & COALESCEFLASG)
2418 INT origlen = strlenW(lphttpHdr->lpszValue);
2419 INT valuelen = strlenW(value);
2421 if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA)
2424 lphttpHdr->wFlags |= HDR_COMMADELIMITED;
2426 else if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
2429 lphttpHdr->wFlags |= HDR_COMMADELIMITED;
2432 len = origlen + valuelen + ((ch > 0) ? 1 : 0);
2434 lpsztmp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR));
2437 /* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */
2440 lphttpHdr->lpszValue[origlen] = ch;
2444 memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR));
2445 lphttpHdr->lpszValue[len] = '\0';
2450 WARN("HeapReAlloc (%d bytes) failed\n",len+1);
2451 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
2455 TRACE("<-- %d\n",bSuccess);
2460 /***********************************************************************
2461 * HTTP_CloseConnection (internal)
2463 * Close socket connection
2466 VOID HTTP_CloseConnection(LPWININETHTTPREQW lpwhr)
2468 LPWININETHTTPSESSIONW lpwhs = NULL;
2469 LPWININETAPPINFOW hIC = NULL;
2471 TRACE("%p\n",lpwhr);
2473 lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent;
2474 hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
2476 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
2477 INTERNET_STATUS_CLOSING_CONNECTION, 0, 0);
2479 if (NETCON_connected(&lpwhr->netConnection))
2481 NETCON_close(&lpwhr->netConnection);
2484 SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
2485 INTERNET_STATUS_CONNECTION_CLOSED, 0, 0);
2489 /***********************************************************************
2490 * HTTP_CloseHTTPRequestHandle (internal)
2492 * Deallocate request handle
2495 static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr)
2498 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) hdr;
2502 if (NETCON_connected(&lpwhr->netConnection))
2503 HTTP_CloseConnection(lpwhr);
2505 HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
2506 HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb);
2507 HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders);
2509 for (i = 0; i <= HTTP_QUERY_MAX; i++)
2511 HeapFree(GetProcessHeap(), 0, lpwhr->StdHeaders[i].lpszField);
2512 HeapFree(GetProcessHeap(), 0, lpwhr->StdHeaders[i].lpszValue);
2515 for (i = 0; i < lpwhr->nCustHeaders; i++)
2517 HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszField);
2518 HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszValue);
2521 HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders);
2522 HeapFree(GetProcessHeap(), 0, lpwhr);
2526 /***********************************************************************
2527 * HTTP_CloseHTTPSessionHandle (internal)
2529 * Deallocate session handle
2532 void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr)
2534 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) hdr;
2536 TRACE("%p\n", lpwhs);
2538 HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
2539 HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName);
2540 HeapFree(GetProcessHeap(), 0, lpwhs);
2544 /***********************************************************************
2545 * HTTP_GetCustomHeaderIndex (internal)
2547 * Return index of custom header from header array
2550 INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField)
2554 TRACE("%s\n", debugstr_w(lpszField));
2556 for (index = 0; index < lpwhr->nCustHeaders; index++)
2558 if (!strcmpiW(lpwhr->pCustHeaders[index].lpszField, lpszField))
2563 if (index >= lpwhr->nCustHeaders)
2566 TRACE("Return: %ld\n", index);
2571 /***********************************************************************
2572 * HTTP_InsertCustomHeader (internal)
2574 * Insert header into array
2577 BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr)
2580 LPHTTPHEADERW lph = NULL;
2583 TRACE("--> %s: %s\n", debugstr_w(lpHdr->lpszField), debugstr_w(lpHdr->lpszValue));
2584 count = lpwhr->nCustHeaders + 1;
2586 lph = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpwhr->pCustHeaders, sizeof(HTTPHEADERW) * count);
2588 lph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HTTPHEADERW) * count);
2592 lpwhr->pCustHeaders = lph;
2593 lpwhr->pCustHeaders[count-1].lpszField = WININET_strdupW(lpHdr->lpszField);
2594 lpwhr->pCustHeaders[count-1].lpszValue = WININET_strdupW(lpHdr->lpszValue);
2595 lpwhr->pCustHeaders[count-1].wFlags = lpHdr->wFlags;
2596 lpwhr->pCustHeaders[count-1].wCount= lpHdr->wCount;
2597 lpwhr->nCustHeaders++;
2602 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
2609 /***********************************************************************
2610 * HTTP_DeleteCustomHeader (internal)
2612 * Delete header from array
2613 * If this function is called, the indexs may change.
2615 BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, DWORD index)
2617 if( lpwhr->nCustHeaders <= 0 )
2619 if( index >= lpwhr->nCustHeaders )
2621 lpwhr->nCustHeaders--;
2623 memmove( &lpwhr->pCustHeaders[index], &lpwhr->pCustHeaders[index+1],
2624 (lpwhr->nCustHeaders - index)* sizeof(HTTPHEADERW) );
2625 memset( &lpwhr->pCustHeaders[lpwhr->nCustHeaders], 0, sizeof(HTTPHEADERW) );
2630 /***********************************************************************
2631 * IsHostInProxyBypassList (@)
2636 BOOL WINAPI IsHostInProxyBypassList(DWORD flags, LPCSTR szHost, DWORD length)
2638 FIXME("STUB: flags=%ld host=%s length=%ld\n",flags,szHost,length);