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
8 * Copyright 2005 Aric Stewart 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>
49 #define NO_SHLWAPI_STREAM
50 #define NO_SHLWAPI_REG
51 #define NO_SHLWAPI_STRFCNS
52 #define NO_SHLWAPI_GDI
56 #include "wine/debug.h"
57 #include "wine/unicode.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
61 static const WCHAR g_szHttp1_0
[] = {' ','H','T','T','P','/','1','.','0',0 };
62 static const WCHAR g_szHttp1_1
[] = {' ','H','T','T','P','/','1','.','1',0 };
63 static const WCHAR g_szReferer
[] = {'R','e','f','e','r','e','r',0};
64 static const WCHAR g_szAccept
[] = {'A','c','c','e','p','t',0};
65 static const WCHAR g_szUserAgent
[] = {'U','s','e','r','-','A','g','e','n','t',0};
66 static const WCHAR szHost
[] = { 'H','o','s','t',0 };
67 static const WCHAR szProxy_Authorization
[] = { 'P','r','o','x','y','-','A','u','t','h','o','r','i','z','a','t','i','o','n',0 };
68 static const WCHAR szStatus
[] = { 'S','t','a','t','u','s',0 };
70 #define MAXHOSTNAME 100
71 #define MAX_FIELD_VALUE_LEN 256
72 #define MAX_FIELD_LEN 256
74 #define HTTP_REFERER g_szReferer
75 #define HTTP_ACCEPT g_szAccept
76 #define HTTP_USERAGENT g_szUserAgent
78 #define HTTP_ADDHDR_FLAG_ADD 0x20000000
79 #define HTTP_ADDHDR_FLAG_ADD_IF_NEW 0x10000000
80 #define HTTP_ADDHDR_FLAG_COALESCE 0x40000000
81 #define HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA 0x40000000
82 #define HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON 0x01000000
83 #define HTTP_ADDHDR_FLAG_REPLACE 0x80000000
84 #define HTTP_ADDHDR_FLAG_REQ 0x02000000
87 static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr
);
88 static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr
);
89 static BOOL
HTTP_OpenConnection(LPWININETHTTPREQW lpwhr
);
90 static BOOL
HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr
);
91 static BOOL
HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr
, LPCWSTR field
, LPCWSTR value
, DWORD dwModifier
);
92 static LPWSTR
* HTTP_InterpretHttpHeader(LPCWSTR buffer
);
93 static BOOL
HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr
, LPHTTPHEADERW lpHdr
);
94 static INT
HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszField
, INT index
, BOOL Request
);
95 static BOOL
HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr
, DWORD index
);
96 static LPWSTR
HTTP_build_req( LPCWSTR
*list
, int len
);
97 static BOOL
HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr
,
98 LPCWSTR username
, LPCWSTR password
);
99 static BOOL WINAPI
HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr
, DWORD
100 dwInfoLevel
, LPVOID lpBuffer
, LPDWORD lpdwBufferLength
, LPDWORD
102 static BOOL
HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszUrl
,
103 LPCWSTR lpszHeaders
, DWORD dwHeaderLength
, LPVOID lpOptional
, DWORD
104 dwOptionalLength
, DWORD dwContentLength
);
107 LPHTTPHEADERW
HTTP_GetHeader(LPWININETHTTPREQW req
, LPCWSTR head
)
110 HeaderIndex
= HTTP_GetCustomHeaderIndex(req
, head
, 0, TRUE
);
111 if (HeaderIndex
== -1)
114 return &req
->pCustHeaders
[HeaderIndex
];
117 /***********************************************************************
118 * HTTP_Tokenize (internal)
120 * Tokenize a string, allocating memory for the tokens.
122 static LPWSTR
* HTTP_Tokenize(LPCWSTR string
, LPCWSTR token_string
)
124 LPWSTR
* token_array
;
129 /* empty string has no tokens */
133 for (i
= 0; string
[i
]; i
++)
134 if (!strncmpW(string
+i
, token_string
, strlenW(token_string
)))
138 /* we want to skip over separators, but not the null terminator */
139 for (j
= 0; j
< strlenW(token_string
) - 1; j
++)
145 /* add 1 for terminating NULL */
146 token_array
= HeapAlloc(GetProcessHeap(), 0, (tokens
+1) * sizeof(*token_array
));
147 token_array
[tokens
] = NULL
;
150 for (i
= 0; i
< tokens
; i
++)
153 next_token
= strstrW(string
, token_string
);
154 if (!next_token
) next_token
= string
+strlenW(string
);
155 len
= next_token
- string
;
156 token_array
[i
] = HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
157 memcpy(token_array
[i
], string
, len
*sizeof(WCHAR
));
158 token_array
[i
][len
] = '\0';
159 string
= next_token
+strlenW(token_string
);
164 /***********************************************************************
165 * HTTP_FreeTokens (internal)
167 * Frees memory returned from HTTP_Tokenize.
169 static void HTTP_FreeTokens(LPWSTR
* token_array
)
172 for (i
= 0; token_array
[i
]; i
++)
173 HeapFree(GetProcessHeap(), 0, token_array
[i
]);
174 HeapFree(GetProcessHeap(), 0, token_array
);
177 /* **********************************************************************
179 * Helper functions for the HttpSendRequest(Ex) functions
182 static void HTTP_FixVerb( LPWININETHTTPREQW lpwhr
)
184 /* if the verb is NULL default to GET */
185 if (NULL
== lpwhr
->lpszVerb
)
187 static const WCHAR szGET
[] = { 'G','E','T', 0 };
188 lpwhr
->lpszVerb
= WININET_strdupW(szGET
);
192 static void HTTP_FixURL( LPWININETHTTPREQW lpwhr
)
194 static const WCHAR szSlash
[] = { '/',0 };
195 static const WCHAR szHttp
[] = { 'h','t','t','p',':','/','/', 0 };
197 /* If we don't have a path we set it to root */
198 if (NULL
== lpwhr
->lpszPath
)
199 lpwhr
->lpszPath
= WININET_strdupW(szSlash
);
200 else /* remove \r and \n*/
202 int nLen
= strlenW(lpwhr
->lpszPath
);
203 while ((nLen
>0 ) && ((lpwhr
->lpszPath
[nLen
-1] == '\r')||(lpwhr
->lpszPath
[nLen
-1] == '\n')))
206 lpwhr
->lpszPath
[nLen
]='\0';
208 /* Replace '\' with '/' */
211 if (lpwhr
->lpszPath
[nLen
] == '\\') lpwhr
->lpszPath
[nLen
]='/';
215 if(CSTR_EQUAL
!= CompareStringW( LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
,
216 lpwhr
->lpszPath
, strlenW(szHttp
), szHttp
, strlenW(szHttp
) )
217 && lpwhr
->lpszPath
[0] != '/') /* not an absolute path ?? --> fix it !! */
219 WCHAR
*fixurl
= HeapAlloc(GetProcessHeap(), 0,
220 (strlenW(lpwhr
->lpszPath
) + 2)*sizeof(WCHAR
));
222 strcpyW(fixurl
+ 1, lpwhr
->lpszPath
);
223 HeapFree( GetProcessHeap(), 0, lpwhr
->lpszPath
);
224 lpwhr
->lpszPath
= fixurl
;
228 static LPWSTR
HTTP_BuildHeaderRequestString( LPWININETHTTPREQW lpwhr
, LPCWSTR verb
, LPCWSTR path
, BOOL http1_1
)
230 LPWSTR requestString
;
236 static const WCHAR szSpace
[] = { ' ',0 };
237 static const WCHAR szcrlf
[] = {'\r','\n', 0};
238 static const WCHAR szColon
[] = { ':',' ',0 };
239 static const WCHAR sztwocrlf
[] = {'\r','\n','\r','\n', 0};
241 /* allocate space for an array of all the string pointers to be added */
242 len
= (lpwhr
->nCustHeaders
)*4 + 9;
243 req
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(LPCWSTR
) );
245 /* add the verb, path and HTTP version string */
250 req
[n
++] = http1_1
? g_szHttp1_1
: g_szHttp1_0
;
252 /* Append custom request heades */
253 for (i
= 0; i
< lpwhr
->nCustHeaders
; i
++)
255 if (lpwhr
->pCustHeaders
[i
].wFlags
& HDR_ISREQUEST
)
258 req
[n
++] = lpwhr
->pCustHeaders
[i
].lpszField
;
260 req
[n
++] = lpwhr
->pCustHeaders
[i
].lpszValue
;
262 TRACE("Adding custom header %s (%s)\n",
263 debugstr_w(lpwhr
->pCustHeaders
[i
].lpszField
),
264 debugstr_w(lpwhr
->pCustHeaders
[i
].lpszValue
));
269 ERR("oops. buffer overrun\n");
272 requestString
= HTTP_build_req( req
, 4 );
273 HeapFree( GetProcessHeap(), 0, req
);
276 * Set (header) termination string for request
277 * Make sure there's exactly two new lines at the end of the request
279 p
= &requestString
[strlenW(requestString
)-1];
280 while ( (*p
== '\n') || (*p
== '\r') )
282 strcpyW( p
+1, sztwocrlf
);
284 return requestString
;
287 static void HTTP_ProcessHeaders( LPWININETHTTPREQW lpwhr
)
289 static const WCHAR szSet_Cookie
[] = { 'S','e','t','-','C','o','o','k','i','e',0 };
291 LPHTTPHEADERW setCookieHeader
;
293 HeaderIndex
= HTTP_GetCustomHeaderIndex(lpwhr
, szSet_Cookie
, 0, FALSE
);
294 if (HeaderIndex
== -1)
296 setCookieHeader
= &lpwhr
->pCustHeaders
[HeaderIndex
];
298 if (!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_COOKIES
) && setCookieHeader
->lpszValue
)
300 int nPosStart
= 0, nPosEnd
= 0, len
;
301 static const WCHAR szFmt
[] = { 'h','t','t','p',':','/','/','%','s','/',0};
303 while (setCookieHeader
->lpszValue
[nPosEnd
] != '\0')
305 LPWSTR buf_cookie
, cookie_name
, cookie_data
;
307 LPWSTR domain
= NULL
;
311 while (setCookieHeader
->lpszValue
[nPosEnd
] != ';' && setCookieHeader
->lpszValue
[nPosEnd
] != ',' &&
312 setCookieHeader
->lpszValue
[nPosEnd
] != '\0')
316 if (setCookieHeader
->lpszValue
[nPosEnd
] == ';')
318 /* fixme: not case sensitive, strcasestr is gnu only */
319 int nDomainPosEnd
= 0;
320 int nDomainPosStart
= 0, nDomainLength
= 0;
321 static const WCHAR szDomain
[] = {'d','o','m','a','i','n','=',0};
322 LPWSTR lpszDomain
= strstrW(&setCookieHeader
->lpszValue
[nPosEnd
], szDomain
);
324 { /* they have specified their own domain, lets use it */
325 while (lpszDomain
[nDomainPosEnd
] != ';' && lpszDomain
[nDomainPosEnd
] != ',' &&
326 lpszDomain
[nDomainPosEnd
] != '\0')
330 nDomainPosStart
= strlenW(szDomain
);
331 nDomainLength
= (nDomainPosEnd
- nDomainPosStart
) + 1;
332 domain
= HeapAlloc(GetProcessHeap(), 0, (nDomainLength
+ 1)*sizeof(WCHAR
));
333 lstrcpynW(domain
, &lpszDomain
[nDomainPosStart
], nDomainLength
+ 1);
336 if (setCookieHeader
->lpszValue
[nPosEnd
] == '\0') break;
337 buf_cookie
= HeapAlloc(GetProcessHeap(), 0, ((nPosEnd
- nPosStart
) + 1)*sizeof(WCHAR
));
338 lstrcpynW(buf_cookie
, &setCookieHeader
->lpszValue
[nPosStart
], (nPosEnd
- nPosStart
) + 1);
339 TRACE("%s\n", debugstr_w(buf_cookie
));
340 while (buf_cookie
[nEqualPos
] != '=' && buf_cookie
[nEqualPos
] != '\0')
344 if (buf_cookie
[nEqualPos
] == '\0' || buf_cookie
[nEqualPos
+ 1] == '\0')
346 HeapFree(GetProcessHeap(), 0, buf_cookie
);
350 cookie_name
= HeapAlloc(GetProcessHeap(), 0, (nEqualPos
+ 1)*sizeof(WCHAR
));
351 lstrcpynW(cookie_name
, buf_cookie
, nEqualPos
+ 1);
352 cookie_data
= &buf_cookie
[nEqualPos
+ 1];
354 Host
= HTTP_GetHeader(lpwhr
,szHost
);
355 len
= lstrlenW((domain
? domain
: (Host
?Host
->lpszValue
:NULL
))) +
356 strlenW(lpwhr
->lpszPath
) + 9;
357 buf_url
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
358 sprintfW(buf_url
, szFmt
, (domain
? domain
: (Host
?Host
->lpszValue
:NULL
))); /* FIXME PATH!!! */
359 InternetSetCookieW(buf_url
, cookie_name
, cookie_data
);
361 HeapFree(GetProcessHeap(), 0, buf_url
);
362 HeapFree(GetProcessHeap(), 0, buf_cookie
);
363 HeapFree(GetProcessHeap(), 0, cookie_name
);
364 HeapFree(GetProcessHeap(), 0, domain
);
370 static void HTTP_AddProxyInfo( LPWININETHTTPREQW lpwhr
)
372 LPWININETHTTPSESSIONW lpwhs
= (LPWININETHTTPSESSIONW
)lpwhr
->hdr
.lpwhparent
;
373 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
)lpwhs
->hdr
.lpwhparent
;
375 assert(lpwhs
->hdr
.htype
== WH_HHTTPSESSION
);
376 assert(hIC
->hdr
.htype
== WH_HINIT
);
378 if (hIC
&& (hIC
->lpszProxyUsername
|| hIC
->lpszProxyPassword
))
379 HTTP_InsertProxyAuthorization(lpwhr
, hIC
->lpszProxyUsername
,
380 hIC
->lpszProxyPassword
);
383 /***********************************************************************
384 * HTTP_HttpAddRequestHeadersW (internal)
386 static BOOL WINAPI
HTTP_HttpAddRequestHeadersW(LPWININETHTTPREQW lpwhr
,
387 LPCWSTR lpszHeader
, DWORD dwHeaderLength
, DWORD dwModifier
)
392 BOOL bSuccess
= FALSE
;
395 TRACE("copying header: %s\n", debugstr_w(lpszHeader
));
397 if( dwHeaderLength
== ~0U )
398 len
= strlenW(lpszHeader
);
400 len
= dwHeaderLength
;
401 buffer
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1) );
402 lstrcpynW( buffer
, lpszHeader
, len
+ 1);
408 LPWSTR
* pFieldAndValue
;
412 while (*lpszEnd
!= '\0')
414 if (*lpszEnd
== '\r' && *(lpszEnd
+ 1) == '\n')
419 if (*lpszStart
== '\0')
422 if (*lpszEnd
== '\r')
425 lpszEnd
+= 2; /* Jump over \r\n */
427 TRACE("interpreting header %s\n", debugstr_w(lpszStart
));
428 pFieldAndValue
= HTTP_InterpretHttpHeader(lpszStart
);
431 bSuccess
= HTTP_ProcessHeader(lpwhr
, pFieldAndValue
[0],
432 pFieldAndValue
[1], dwModifier
| HTTP_ADDHDR_FLAG_REQ
);
433 HTTP_FreeTokens(pFieldAndValue
);
439 HeapFree(GetProcessHeap(), 0, buffer
);
444 /***********************************************************************
445 * HttpAddRequestHeadersW (WININET.@)
447 * Adds one or more HTTP header to the request handler
454 BOOL WINAPI
HttpAddRequestHeadersW(HINTERNET hHttpRequest
,
455 LPCWSTR lpszHeader
, DWORD dwHeaderLength
, DWORD dwModifier
)
457 BOOL bSuccess
= FALSE
;
458 LPWININETHTTPREQW lpwhr
;
460 TRACE("%p, %s, %li, %li\n", hHttpRequest
, debugstr_w(lpszHeader
), dwHeaderLength
,
466 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hHttpRequest
);
467 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
469 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
472 bSuccess
= HTTP_HttpAddRequestHeadersW( lpwhr
, lpszHeader
, dwHeaderLength
, dwModifier
);
475 WININET_Release( &lpwhr
->hdr
);
480 /***********************************************************************
481 * HttpAddRequestHeadersA (WININET.@)
483 * Adds one or more HTTP header to the request handler
490 BOOL WINAPI
HttpAddRequestHeadersA(HINTERNET hHttpRequest
,
491 LPCSTR lpszHeader
, DWORD dwHeaderLength
, DWORD dwModifier
)
497 TRACE("%p, %s, %li, %li\n", hHttpRequest
, debugstr_a(lpszHeader
), dwHeaderLength
,
500 len
= MultiByteToWideChar( CP_ACP
, 0, lpszHeader
, dwHeaderLength
, NULL
, 0 );
501 hdr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
502 MultiByteToWideChar( CP_ACP
, 0, lpszHeader
, dwHeaderLength
, hdr
, len
);
503 if( dwHeaderLength
!= ~0U )
504 dwHeaderLength
= len
;
506 r
= HttpAddRequestHeadersW( hHttpRequest
, hdr
, dwHeaderLength
, dwModifier
);
508 HeapFree( GetProcessHeap(), 0, hdr
);
513 /***********************************************************************
514 * HttpEndRequestA (WININET.@)
516 * Ends an HTTP request that was started by HttpSendRequestEx
523 BOOL WINAPI
HttpEndRequestA(HINTERNET hRequest
,
524 LPINTERNET_BUFFERSA lpBuffersOut
, DWORD dwFlags
, DWORD dwContext
)
526 LPINTERNET_BUFFERSA ptr
;
527 LPINTERNET_BUFFERSW lpBuffersOutW
,ptrW
;
530 TRACE("(%p, %p, %08lx, %08lx): stub\n", hRequest
, lpBuffersOut
, dwFlags
,
535 lpBuffersOutW
= (LPINTERNET_BUFFERSW
)HeapAlloc(GetProcessHeap(),
536 HEAP_ZERO_MEMORY
, sizeof(INTERNET_BUFFERSW
));
538 lpBuffersOutW
= NULL
;
540 ptrW
= lpBuffersOutW
;
543 if (ptr
->lpvBuffer
&& ptr
->dwBufferLength
)
544 ptrW
->lpvBuffer
= HeapAlloc(GetProcessHeap(),0,ptr
->dwBufferLength
);
545 ptrW
->dwBufferLength
= ptr
->dwBufferLength
;
546 ptrW
->dwBufferTotal
= ptr
->dwBufferTotal
;
549 ptrW
->Next
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,
550 sizeof(INTERNET_BUFFERSW
));
556 rc
= HttpEndRequestW(hRequest
, lpBuffersOutW
, dwFlags
, dwContext
);
560 ptrW
= lpBuffersOutW
;
563 LPINTERNET_BUFFERSW ptrW2
;
565 FIXME("Do we need to translate info out of these buffer?\n");
567 HeapFree(GetProcessHeap(),0,(LPVOID
)ptrW
->lpvBuffer
);
569 HeapFree(GetProcessHeap(),0,ptrW
);
577 /***********************************************************************
578 * HttpEndRequestW (WININET.@)
580 * Ends an HTTP request that was started by HttpSendRequestEx
587 BOOL WINAPI
HttpEndRequestW(HINTERNET hRequest
,
588 LPINTERNET_BUFFERSW lpBuffersOut
, DWORD dwFlags
, DWORD dwContext
)
591 LPWININETHTTPREQW lpwhr
;
595 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hRequest
);
597 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
599 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
603 lpwhr
->hdr
.dwFlags
|= dwFlags
;
604 lpwhr
->hdr
.dwContext
= dwContext
;
606 SendAsyncCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
607 INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
609 responseLen
= HTTP_GetResponseHeaders(lpwhr
);
613 SendAsyncCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
614 INTERNET_STATUS_RESPONSE_RECEIVED
, &responseLen
, sizeof(DWORD
));
616 /* process headers here. Is this right? */
617 HTTP_ProcessHeaders(lpwhr
);
619 /* We appear to do nothing with the buffer.. is that correct? */
621 if(!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_AUTO_REDIRECT
))
623 DWORD dwCode
,dwCodeLength
=sizeof(DWORD
),dwIndex
=0;
624 if(HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_STATUS_CODE
,&dwCode
,&dwCodeLength
,&dwIndex
) &&
625 (dwCode
==302 || dwCode
==301))
627 WCHAR szNewLocation
[2048];
628 DWORD dwBufferSize
=2048;
630 if(HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_LOCATION
,szNewLocation
,&dwBufferSize
,&dwIndex
))
632 static const WCHAR szGET
[] = { 'G','E','T', 0 };
633 /* redirects are always GETs */
634 HeapFree(GetProcessHeap(),0,lpwhr
->lpszVerb
);
635 lpwhr
->lpszVerb
= WININET_strdupW(szGET
);
636 return HTTP_HandleRedirect(lpwhr
, szNewLocation
, NULL
, 0, NULL
, 0, 0);
641 TRACE("%i <--\n",rc
);
645 /***********************************************************************
646 * HttpOpenRequestW (WININET.@)
648 * Open a HTTP request handle
651 * HINTERNET a HTTP request handle on success
655 HINTERNET WINAPI
HttpOpenRequestW(HINTERNET hHttpSession
,
656 LPCWSTR lpszVerb
, LPCWSTR lpszObjectName
, LPCWSTR lpszVersion
,
657 LPCWSTR lpszReferrer
, LPCWSTR
*lpszAcceptTypes
,
658 DWORD dwFlags
, DWORD dwContext
)
660 LPWININETHTTPSESSIONW lpwhs
;
661 HINTERNET handle
= NULL
;
663 TRACE("(%p, %s, %s, %s, %s, %p, %08lx, %08lx)\n", hHttpSession
,
664 debugstr_w(lpszVerb
), debugstr_w(lpszObjectName
),
665 debugstr_w(lpszVersion
), debugstr_w(lpszReferrer
), lpszAcceptTypes
,
667 if(lpszAcceptTypes
!=NULL
)
670 for(i
=0;lpszAcceptTypes
[i
]!=NULL
;i
++)
671 TRACE("\taccept type: %s\n",debugstr_w(lpszAcceptTypes
[i
]));
674 lpwhs
= (LPWININETHTTPSESSIONW
) WININET_GetObject( hHttpSession
);
675 if (NULL
== lpwhs
|| lpwhs
->hdr
.htype
!= WH_HHTTPSESSION
)
677 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
682 * My tests seem to show that the windows version does not
683 * become asynchronous until after this point. And anyhow
684 * if this call was asynchronous then how would you get the
685 * necessary HINTERNET pointer returned by this function.
688 handle
= HTTP_HttpOpenRequestW(lpwhs
, lpszVerb
, lpszObjectName
,
689 lpszVersion
, lpszReferrer
, lpszAcceptTypes
,
693 WININET_Release( &lpwhs
->hdr
);
694 TRACE("returning %p\n", handle
);
699 /***********************************************************************
700 * HttpOpenRequestA (WININET.@)
702 * Open a HTTP request handle
705 * HINTERNET a HTTP request handle on success
709 HINTERNET WINAPI
HttpOpenRequestA(HINTERNET hHttpSession
,
710 LPCSTR lpszVerb
, LPCSTR lpszObjectName
, LPCSTR lpszVersion
,
711 LPCSTR lpszReferrer
, LPCSTR
*lpszAcceptTypes
,
712 DWORD dwFlags
, DWORD dwContext
)
714 LPWSTR szVerb
= NULL
, szObjectName
= NULL
;
715 LPWSTR szVersion
= NULL
, szReferrer
= NULL
, *szAcceptTypes
= NULL
;
717 INT acceptTypesCount
;
718 HINTERNET rc
= FALSE
;
719 TRACE("(%p, %s, %s, %s, %s, %p, %08lx, %08lx)\n", hHttpSession
,
720 debugstr_a(lpszVerb
), debugstr_a(lpszObjectName
),
721 debugstr_a(lpszVersion
), debugstr_a(lpszReferrer
), lpszAcceptTypes
,
726 len
= MultiByteToWideChar(CP_ACP
, 0, lpszVerb
, -1, NULL
, 0 );
727 szVerb
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
730 MultiByteToWideChar(CP_ACP
, 0, lpszVerb
, -1, szVerb
, len
);
735 len
= MultiByteToWideChar(CP_ACP
, 0, lpszObjectName
, -1, NULL
, 0 );
736 szObjectName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
739 MultiByteToWideChar(CP_ACP
, 0, lpszObjectName
, -1, szObjectName
, len
);
744 len
= MultiByteToWideChar(CP_ACP
, 0, lpszVersion
, -1, NULL
, 0 );
745 szVersion
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
748 MultiByteToWideChar(CP_ACP
, 0, lpszVersion
, -1, szVersion
, len
);
753 len
= MultiByteToWideChar(CP_ACP
, 0, lpszReferrer
, -1, NULL
, 0 );
754 szReferrer
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
757 MultiByteToWideChar(CP_ACP
, 0, lpszReferrer
, -1, szReferrer
, len
);
760 acceptTypesCount
= 0;
763 /* find out how many there are */
764 while (lpszAcceptTypes
[acceptTypesCount
])
766 szAcceptTypes
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
*) * (acceptTypesCount
+1));
767 acceptTypesCount
= 0;
768 while (lpszAcceptTypes
[acceptTypesCount
])
770 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAcceptTypes
[acceptTypesCount
],
772 szAcceptTypes
[acceptTypesCount
] = HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
773 if (!szAcceptTypes
[acceptTypesCount
] )
775 MultiByteToWideChar(CP_ACP
, 0, lpszAcceptTypes
[acceptTypesCount
],
776 -1, szAcceptTypes
[acceptTypesCount
], len
);
779 szAcceptTypes
[acceptTypesCount
] = NULL
;
781 else szAcceptTypes
= 0;
783 rc
= HttpOpenRequestW(hHttpSession
, szVerb
, szObjectName
,
784 szVersion
, szReferrer
,
785 (LPCWSTR
*)szAcceptTypes
, dwFlags
, dwContext
);
790 acceptTypesCount
= 0;
791 while (szAcceptTypes
[acceptTypesCount
])
793 HeapFree(GetProcessHeap(), 0, szAcceptTypes
[acceptTypesCount
]);
796 HeapFree(GetProcessHeap(), 0, szAcceptTypes
);
798 HeapFree(GetProcessHeap(), 0, szReferrer
);
799 HeapFree(GetProcessHeap(), 0, szVersion
);
800 HeapFree(GetProcessHeap(), 0, szObjectName
);
801 HeapFree(GetProcessHeap(), 0, szVerb
);
806 /***********************************************************************
809 static UINT
HTTP_Base64( LPCWSTR bin
, LPWSTR base64
)
812 static LPCSTR HTTP_Base64Enc
=
813 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
817 /* first 6 bits, all from bin[0] */
818 base64
[n
++] = HTTP_Base64Enc
[(bin
[0] & 0xfc) >> 2];
819 x
= (bin
[0] & 3) << 4;
821 /* next 6 bits, 2 from bin[0] and 4 from bin[1] */
824 base64
[n
++] = HTTP_Base64Enc
[x
];
829 base64
[n
++] = HTTP_Base64Enc
[ x
| ( (bin
[1]&0xf0) >> 4 ) ];
830 x
= ( bin
[1] & 0x0f ) << 2;
832 /* next 6 bits 4 from bin[1] and 2 from bin[2] */
835 base64
[n
++] = HTTP_Base64Enc
[x
];
839 base64
[n
++] = HTTP_Base64Enc
[ x
| ( (bin
[2]&0xc0 ) >> 6 ) ];
841 /* last 6 bits, all from bin [2] */
842 base64
[n
++] = HTTP_Base64Enc
[ bin
[2] & 0x3f ];
849 /***********************************************************************
850 * HTTP_EncodeBasicAuth
852 * Encode the basic authentication string for HTTP 1.1
854 static LPWSTR
HTTP_EncodeBasicAuth( LPCWSTR username
, LPCWSTR password
)
858 static const WCHAR szBasic
[] = {'B','a','s','i','c',' ',0};
859 static const WCHAR szColon
[] = {':',0};
861 len
= lstrlenW( username
) + 1 + lstrlenW ( password
) + 1;
862 in
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
866 len
= lstrlenW(szBasic
) +
867 (lstrlenW( username
) + 1 + lstrlenW ( password
))*2 + 1 + 1;
868 out
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
871 lstrcpyW( in
, username
);
872 lstrcatW( in
, szColon
);
873 lstrcatW( in
, password
);
874 lstrcpyW( out
, szBasic
);
875 HTTP_Base64( in
, &out
[strlenW(out
)] );
877 HeapFree( GetProcessHeap(), 0, in
);
882 /***********************************************************************
883 * HTTP_InsertProxyAuthorization
885 * Insert the basic authorization field in the request header
887 static BOOL
HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr
,
888 LPCWSTR username
, LPCWSTR password
)
890 WCHAR
*authorization
= HTTP_EncodeBasicAuth( username
, password
);
896 TRACE( "Inserting authorization: %s\n", debugstr_w( authorization
) );
898 HTTP_ProcessHeader(lpwhr
, szProxy_Authorization
, authorization
,
899 HTTP_ADDHDR_FLAG_REPLACE
);
901 HeapFree( GetProcessHeap(), 0, authorization
);
906 /***********************************************************************
909 static BOOL
HTTP_DealWithProxy( LPWININETAPPINFOW hIC
,
910 LPWININETHTTPSESSIONW lpwhs
, LPWININETHTTPREQW lpwhr
)
912 WCHAR buf
[MAXHOSTNAME
];
913 WCHAR proxy
[MAXHOSTNAME
+ 15]; /* 15 == "http://" + sizeof(port#) + ":/\0" */
915 static const WCHAR szNul
[] = { 0 };
916 URL_COMPONENTSW UrlComponents
;
917 static const WCHAR szHttp
[] = { 'h','t','t','p',':','/','/',0 }, szSlash
[] = { '/',0 } ;
918 static const WCHAR szFormat1
[] = { 'h','t','t','p',':','/','/','%','s',0 };
919 static const WCHAR szFormat2
[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
922 memset( &UrlComponents
, 0, sizeof UrlComponents
);
923 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
924 UrlComponents
.lpszHostName
= buf
;
925 UrlComponents
.dwHostNameLength
= MAXHOSTNAME
;
927 if( CSTR_EQUAL
!= CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
,
928 hIC
->lpszProxy
,strlenW(szHttp
),szHttp
,strlenW(szHttp
)) )
929 sprintfW(proxy
, szFormat1
, hIC
->lpszProxy
);
931 strcpyW(proxy
, hIC
->lpszProxy
);
932 if( !InternetCrackUrlW(proxy
, 0, 0, &UrlComponents
) )
934 if( UrlComponents
.dwHostNameLength
== 0 )
937 if( !lpwhr
->lpszPath
)
938 lpwhr
->lpszPath
= (LPWSTR
)szNul
;
939 TRACE("server='%s' path='%s'\n",
940 debugstr_w(lpwhs
->lpszHostName
), debugstr_w(lpwhr
->lpszPath
));
941 /* for constant 15 see above */
942 len
= strlenW(lpwhs
->lpszHostName
) + strlenW(lpwhr
->lpszPath
) + 15;
943 url
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
945 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
946 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
948 sprintfW(url
, szFormat2
, lpwhs
->lpszHostName
, lpwhs
->nHostPort
);
950 if( lpwhr
->lpszPath
[0] != '/' )
951 strcatW( url
, szSlash
);
952 strcatW(url
, lpwhr
->lpszPath
);
953 if(lpwhr
->lpszPath
!= szNul
)
954 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszPath
);
955 lpwhr
->lpszPath
= url
;
957 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszServerName
);
958 lpwhs
->lpszServerName
= WININET_strdupW(UrlComponents
.lpszHostName
);
959 lpwhs
->nServerPort
= UrlComponents
.nPort
;
964 /***********************************************************************
965 * HTTP_HttpOpenRequestW (internal)
967 * Open a HTTP request handle
970 * HINTERNET a HTTP request handle on success
974 HINTERNET WINAPI
HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs
,
975 LPCWSTR lpszVerb
, LPCWSTR lpszObjectName
, LPCWSTR lpszVersion
,
976 LPCWSTR lpszReferrer
, LPCWSTR
*lpszAcceptTypes
,
977 DWORD dwFlags
, DWORD dwContext
)
979 LPWININETAPPINFOW hIC
= NULL
;
980 LPWININETHTTPREQW lpwhr
;
982 LPWSTR lpszUrl
= NULL
;
984 HINTERNET handle
= NULL
;
985 static const WCHAR szUrlForm
[] = {'h','t','t','p',':','/','/','%','s',0};
991 assert( lpwhs
->hdr
.htype
== WH_HHTTPSESSION
);
992 hIC
= (LPWININETAPPINFOW
) lpwhs
->hdr
.lpwhparent
;
994 lpwhr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETHTTPREQW
));
997 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1000 lpwhr
->hdr
.htype
= WH_HHTTPREQ
;
1001 lpwhr
->hdr
.lpwhparent
= WININET_AddRef( &lpwhs
->hdr
);
1002 lpwhr
->hdr
.dwFlags
= dwFlags
;
1003 lpwhr
->hdr
.dwContext
= dwContext
;
1004 lpwhr
->hdr
.dwRefCount
= 1;
1005 lpwhr
->hdr
.destroy
= HTTP_CloseHTTPRequestHandle
;
1006 lpwhr
->hdr
.lpfnStatusCB
= lpwhs
->hdr
.lpfnStatusCB
;
1008 handle
= WININET_AllocHandle( &lpwhr
->hdr
);
1011 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1015 NETCON_init(&lpwhr
->netConnection
, dwFlags
& INTERNET_FLAG_SECURE
);
1017 if (NULL
!= lpszObjectName
&& strlenW(lpszObjectName
)) {
1021 rc
= UrlEscapeW(lpszObjectName
, NULL
, &len
, URL_ESCAPE_SPACES_ONLY
);
1022 if (rc
!= E_POINTER
)
1023 len
= strlenW(lpszObjectName
)+1;
1024 lpwhr
->lpszPath
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1025 rc
= UrlEscapeW(lpszObjectName
, lpwhr
->lpszPath
, &len
,
1026 URL_ESCAPE_SPACES_ONLY
);
1029 ERR("Unable to escape string!(%s) (%ld)\n",debugstr_w(lpszObjectName
),rc
);
1030 strcpyW(lpwhr
->lpszPath
,lpszObjectName
);
1034 if (NULL
!= lpszReferrer
&& strlenW(lpszReferrer
))
1035 HTTP_ProcessHeader(lpwhr
, HTTP_REFERER
, lpszReferrer
, HTTP_ADDHDR_FLAG_COALESCE
);
1037 if(lpszAcceptTypes
!=NULL
)
1040 for(i
=0;lpszAcceptTypes
[i
]!=NULL
;i
++)
1041 HTTP_ProcessHeader(lpwhr
, HTTP_ACCEPT
, lpszAcceptTypes
[i
], HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA
|HTTP_ADDHDR_FLAG_REQ
|HTTP_ADDHDR_FLAG_ADD_IF_NEW
);
1044 if (NULL
== lpszVerb
)
1046 static const WCHAR szGet
[] = {'G','E','T',0};
1047 lpwhr
->lpszVerb
= WININET_strdupW(szGet
);
1049 else if (strlenW(lpszVerb
))
1050 lpwhr
->lpszVerb
= WININET_strdupW(lpszVerb
);
1052 if (NULL
!= lpszReferrer
&& strlenW(lpszReferrer
))
1054 WCHAR buf
[MAXHOSTNAME
];
1055 URL_COMPONENTSW UrlComponents
;
1057 memset( &UrlComponents
, 0, sizeof UrlComponents
);
1058 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
1059 UrlComponents
.lpszHostName
= buf
;
1060 UrlComponents
.dwHostNameLength
= MAXHOSTNAME
;
1062 InternetCrackUrlW(lpszReferrer
, 0, 0, &UrlComponents
);
1063 if (strlenW(UrlComponents
.lpszHostName
))
1064 HTTP_ProcessHeader(lpwhr
, szHost
, UrlComponents
.lpszHostName
, HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDHDR_FLAG_REQ
);
1067 HTTP_ProcessHeader(lpwhr
, szHost
, lpwhs
->lpszHostName
, HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDHDR_FLAG_REQ
);
1069 if (lpwhs
->nServerPort
== INTERNET_INVALID_PORT_NUMBER
)
1070 lpwhs
->nServerPort
= (dwFlags
& INTERNET_FLAG_SECURE
?
1071 INTERNET_DEFAULT_HTTPS_PORT
:
1072 INTERNET_DEFAULT_HTTP_PORT
);
1073 lpwhs
->nHostPort
= lpwhs
->nServerPort
;
1075 if (NULL
!= hIC
->lpszProxy
&& hIC
->lpszProxy
[0] != 0)
1076 HTTP_DealWithProxy( hIC
, lpwhs
, lpwhr
);
1080 WCHAR
*agent_header
;
1081 static const WCHAR user_agent
[] = {'U','s','e','r','-','A','g','e','n','t',':',' ','%','s','\r','\n',0 };
1083 len
= strlenW(hIC
->lpszAgent
) + strlenW(user_agent
);
1084 agent_header
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1085 sprintfW(agent_header
, user_agent
, hIC
->lpszAgent
);
1087 HTTP_HttpAddRequestHeadersW(lpwhr
, agent_header
, strlenW(agent_header
),
1088 HTTP_ADDREQ_FLAG_ADD
);
1089 HeapFree(GetProcessHeap(), 0, agent_header
);
1092 Host
= HTTP_GetHeader(lpwhr
,szHost
);
1094 len
= lstrlenW(Host
->lpszValue
) + strlenW(szUrlForm
);
1095 lpszUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1096 sprintfW( lpszUrl
, szUrlForm
, Host
->lpszValue
);
1098 if (!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_COOKIES
) &&
1099 InternetGetCookieW(lpszUrl
, NULL
, NULL
, &nCookieSize
))
1102 static const WCHAR szCookie
[] = {'C','o','o','k','i','e',':',' ',0};
1103 static const WCHAR szcrlf
[] = {'\r','\n',0};
1105 lpszCookies
= HeapAlloc(GetProcessHeap(), 0, (nCookieSize
+ 1 + 8)*sizeof(WCHAR
));
1107 cnt
+= sprintfW(lpszCookies
, szCookie
);
1108 InternetGetCookieW(lpszUrl
, NULL
, lpszCookies
+ cnt
, &nCookieSize
);
1109 strcatW(lpszCookies
, szcrlf
);
1111 HTTP_HttpAddRequestHeadersW(lpwhr
, lpszCookies
, strlenW(lpszCookies
),
1112 HTTP_ADDREQ_FLAG_ADD
);
1113 HeapFree(GetProcessHeap(), 0, lpszCookies
);
1115 HeapFree(GetProcessHeap(), 0, lpszUrl
);
1118 INTERNET_SendCallback(&lpwhs
->hdr
, dwContext
,
1119 INTERNET_STATUS_HANDLE_CREATED
, &handle
,
1123 * A STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on windows
1127 * According to my tests. The name is not resolved until a request is Opened
1129 INTERNET_SendCallback(&lpwhr
->hdr
, dwContext
,
1130 INTERNET_STATUS_RESOLVING_NAME
,
1131 lpwhs
->lpszServerName
,
1132 strlenW(lpwhs
->lpszServerName
)+1);
1134 if (!GetAddress(lpwhs
->lpszServerName
, lpwhs
->nServerPort
,
1135 &lpwhs
->socketAddress
))
1137 INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED
);
1138 InternetCloseHandle( handle
);
1143 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
1144 INTERNET_STATUS_NAME_RESOLVED
,
1145 &(lpwhs
->socketAddress
),
1146 sizeof(struct sockaddr_in
));
1150 WININET_Release( &lpwhr
->hdr
);
1152 TRACE("<-- %p (%p)\n", handle
, lpwhr
);
1156 typedef struct std_hdr_data
1158 const WCHAR
* hdrStr
;
1162 static const WCHAR szAccept
[] = { 'A','c','c','e','p','t',0 };
1163 static const WCHAR szAccept_Charset
[] = { 'A','c','c','e','p','t','-','C','h','a','r','s','e','t', 0 };
1164 static const WCHAR szAccept_Encoding
[] = { 'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',0 };
1165 static const WCHAR szAccept_Language
[] = { 'A','c','c','e','p','t','-','L','a','n','g','u','a','g','e',0 };
1166 static const WCHAR szAccept_Ranges
[] = { 'A','c','c','e','p','t','-','R','a','n','g','e','s',0 };
1167 static const WCHAR szAge
[] = { 'A','g','e',0 };
1168 static const WCHAR szAllow
[] = { 'A','l','l','o','w',0 };
1169 static const WCHAR szAuthorization
[] = { 'A','u','t','h','o','r','i','z','a','t','i','o','n',0 };
1170 static const WCHAR szCache_Control
[] = { 'C','a','c','h','e','-','C','o','n','t','r','o','l',0 };
1171 static const WCHAR szConnection
[] = { 'C','o','n','n','e','c','t','i','o','n',0 };
1172 static const WCHAR szContent_Base
[] = { 'C','o','n','t','e','n','t','-','B','a','s','e',0 };
1173 static const WCHAR szContent_Encoding
[] = { 'C','o','n','t','e','n','t','-','E','n','c','o','d','i','n','g',0 };
1174 static const WCHAR szContent_ID
[] = { 'C','o','n','t','e','n','t','-','I','D',0 };
1175 static const WCHAR szContent_Language
[] = { 'C','o','n','t','e','n','t','-','L','a','n','g','u','a','g','e',0 };
1176 static const WCHAR szContent_Length
[] = { 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0 };
1177 static const WCHAR szContent_Location
[] = { 'C','o','n','t','e','n','t','-','L','o','c','a','t','i','o','n',0 };
1178 static const WCHAR szContent_MD5
[] = { 'C','o','n','t','e','n','t','-','M','D','5',0 };
1179 static const WCHAR szContent_Range
[] = { 'C','o','n','t','e','n','t','-','R','a','n','g','e',0 };
1180 static const WCHAR szContent_Transfer_Encoding
[] = { 'C','o','n','t','e','n','t','-','T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0 };
1181 static const WCHAR szContent_Type
[] = { 'C','o','n','t','e','n','t','-','T','y','p','e',0 };
1182 static const WCHAR szCookie
[] = { 'C','o','o','k','i','e',0 };
1183 static const WCHAR szDate
[] = { 'D','a','t','e',0 };
1184 static const WCHAR szFrom
[] = { 'F','r','o','m',0 };
1185 static const WCHAR szETag
[] = { 'E','T','a','g',0 };
1186 static const WCHAR szExpect
[] = { 'E','x','p','e','c','t',0 };
1187 static const WCHAR szExpires
[] = { 'E','x','p','i','r','e','s',0 };
1188 static const WCHAR szIf_Match
[] = { 'I','f','-','M','a','t','c','h',0 };
1189 static const WCHAR szIf_Modified_Since
[] = { 'I','f','-','M','o','d','i','f','i','e','d','-','S','i','n','c','e',0 };
1190 static const WCHAR szIf_None_Match
[] = { 'I','f','-','N','o','n','e','-','M','a','t','c','h',0 };
1191 static const WCHAR szIf_Range
[] = { 'I','f','-','R','a','n','g','e',0 };
1192 static const WCHAR szIf_Unmodified_Since
[] = { 'I','f','-','U','n','m','o','d','i','f','i','e','d','-','S','i','n','c','e',0 };
1193 static const WCHAR szLast_Modified
[] = { 'L','a','s','t','-','M','o','d','i','f','i','e','d',0 };
1194 static const WCHAR szLocation
[] = { 'L','o','c','a','t','i','o','n',0 };
1195 static const WCHAR szMax_Forwards
[] = { 'M','a','x','-','F','o','r','w','a','r','d','s',0 };
1196 static const WCHAR szMime_Version
[] = { 'M','i','m','e','-','V','e','r','s','i','o','n',0 };
1197 static const WCHAR szPragma
[] = { 'P','r','a','g','m','a',0 };
1198 static const WCHAR szProxy_Authenticate
[] = { 'P','r','o','x','y','-','A','u','t','h','e','n','t','i','c','a','t','e',0 };
1199 static const WCHAR szProxy_Connection
[] = { 'P','r','o','x','y','-','C','o','n','n','e','c','t','i','o','n',0 };
1200 static const WCHAR szPublic
[] = { 'P','u','b','l','i','c',0 };
1201 static const WCHAR szRange
[] = { 'R','a','n','g','e',0 };
1202 static const WCHAR szReferer
[] = { 'R','e','f','e','r','e','r',0 };
1203 static const WCHAR szRetry_After
[] = { 'R','e','t','r','y','-','A','f','t','e','r',0 };
1204 static const WCHAR szServer
[] = { 'S','e','r','v','e','r',0 };
1205 static const WCHAR szSet_Cookie
[] = { 'S','e','t','-','C','o','o','k','i','e',0 };
1206 static const WCHAR szTransfer_Encoding
[] = { 'T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0 };
1207 static const WCHAR szUnless_Modified_Since
[] = { 'U','n','l','e','s','s','-','M','o','d','i','f','i','e','d','-','S','i','n','c','e',0 };
1208 static const WCHAR szUpgrade
[] = { 'U','p','g','r','a','d','e',0 };
1209 static const WCHAR szURI
[] = { 'U','R','I',0 };
1210 static const WCHAR szUser_Agent
[] = { 'U','s','e','r','-','A','g','e','n','t',0 };
1211 static const WCHAR szVary
[] = { 'V','a','r','y',0 };
1212 static const WCHAR szVia
[] = { 'V','i','a',0 };
1213 static const WCHAR szWarning
[] = { 'W','a','r','n','i','n','g',0 };
1214 static const WCHAR szWWW_Authenticate
[] = { 'W','W','W','-','A','u','t','h','e','n','t','i','c','a','t','e',0 };
1216 static const std_hdr_data SORTED_STANDARD_HEADERS
[] = {
1217 {szAccept
, HTTP_QUERY_ACCEPT
,},
1218 {szAccept_Charset
, HTTP_QUERY_ACCEPT_CHARSET
,},
1219 {szAccept_Encoding
, HTTP_QUERY_ACCEPT_ENCODING
,},
1220 {szAccept_Language
, HTTP_QUERY_ACCEPT_LANGUAGE
,},
1221 {szAccept_Ranges
, HTTP_QUERY_ACCEPT_RANGES
,},
1222 {szAge
, HTTP_QUERY_AGE
,},
1223 {szAllow
, HTTP_QUERY_ALLOW
,},
1224 {szAuthorization
, HTTP_QUERY_AUTHORIZATION
,},
1225 {szCache_Control
, HTTP_QUERY_CACHE_CONTROL
,},
1226 {szConnection
, HTTP_QUERY_CONNECTION
,},
1227 {szContent_Base
, HTTP_QUERY_CONTENT_BASE
,},
1228 {szContent_Encoding
, HTTP_QUERY_CONTENT_ENCODING
,},
1229 {szContent_ID
, HTTP_QUERY_CONTENT_ID
,},
1230 {szContent_Language
, HTTP_QUERY_CONTENT_LANGUAGE
,},
1231 {szContent_Length
, HTTP_QUERY_CONTENT_LENGTH
,},
1232 {szContent_Location
, HTTP_QUERY_CONTENT_LOCATION
,},
1233 {szContent_MD5
, HTTP_QUERY_CONTENT_MD5
,},
1234 {szContent_Range
, HTTP_QUERY_CONTENT_RANGE
,},
1235 {szContent_Transfer_Encoding
,HTTP_QUERY_CONTENT_TRANSFER_ENCODING
,},
1236 {szContent_Type
, HTTP_QUERY_CONTENT_TYPE
,},
1237 {szCookie
, HTTP_QUERY_COOKIE
,},
1238 {szDate
, HTTP_QUERY_DATE
,},
1239 {szETag
, HTTP_QUERY_ETAG
,},
1240 {szExpect
, HTTP_QUERY_EXPECT
,},
1241 {szExpires
, HTTP_QUERY_EXPIRES
,},
1242 {szFrom
, HTTP_QUERY_DERIVED_FROM
,},
1243 {szHost
, HTTP_QUERY_HOST
,},
1244 {szIf_Match
, HTTP_QUERY_IF_MATCH
,},
1245 {szIf_Modified_Since
, HTTP_QUERY_IF_MODIFIED_SINCE
,},
1246 {szIf_None_Match
, HTTP_QUERY_IF_NONE_MATCH
,},
1247 {szIf_Range
, HTTP_QUERY_IF_RANGE
,},
1248 {szIf_Unmodified_Since
, HTTP_QUERY_IF_UNMODIFIED_SINCE
,},
1249 {szLast_Modified
, HTTP_QUERY_LAST_MODIFIED
,},
1250 {szLocation
, HTTP_QUERY_LOCATION
,},
1251 {szMax_Forwards
, HTTP_QUERY_MAX_FORWARDS
,},
1252 {szMime_Version
, HTTP_QUERY_MIME_VERSION
,},
1253 {szPragma
, HTTP_QUERY_PRAGMA
,},
1254 {szProxy_Authenticate
, HTTP_QUERY_PROXY_AUTHENTICATE
,},
1255 {szProxy_Authorization
, HTTP_QUERY_PROXY_AUTHORIZATION
,},
1256 {szProxy_Connection
, HTTP_QUERY_PROXY_CONNECTION
,},
1257 {szPublic
, HTTP_QUERY_PUBLIC
,},
1258 {szRange
, HTTP_QUERY_RANGE
,},
1259 {szReferer
, HTTP_QUERY_REFERER
,},
1260 {szRetry_After
, HTTP_QUERY_RETRY_AFTER
,},
1261 {szServer
, HTTP_QUERY_SERVER
,},
1262 {szSet_Cookie
, HTTP_QUERY_SET_COOKIE
,},
1263 {szStatus
, HTTP_QUERY_STATUS_CODE
,},
1264 {szTransfer_Encoding
, HTTP_QUERY_TRANSFER_ENCODING
,},
1265 {szUnless_Modified_Since
, HTTP_QUERY_UNLESS_MODIFIED_SINCE
,},
1266 {szUpgrade
, HTTP_QUERY_UPGRADE
,},
1267 {szURI
, HTTP_QUERY_URI
,},
1268 {szUser_Agent
, HTTP_QUERY_USER_AGENT
,},
1269 {szVary
, HTTP_QUERY_VARY
,},
1270 {szVia
, HTTP_QUERY_VIA
,},
1271 {szWarning
, HTTP_QUERY_WARNING
,},
1272 {szWWW_Authenticate
, HTTP_QUERY_WWW_AUTHENTICATE
,},
1275 /***********************************************************************
1276 * HTTP_HttpQueryInfoW (internal)
1278 static BOOL WINAPI
HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr
, DWORD dwInfoLevel
,
1279 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
, LPDWORD lpdwIndex
)
1281 LPHTTPHEADERW lphttpHdr
= NULL
;
1282 BOOL bSuccess
= FALSE
;
1283 BOOL request_only
= dwInfoLevel
& HTTP_QUERY_FLAG_REQUEST_HEADERS
;
1286 /* Find requested header structure */
1287 if ((dwInfoLevel
& ~HTTP_QUERY_MODIFIER_FLAGS_MASK
) == HTTP_QUERY_CUSTOM
)
1289 INT requested_index
= (lpdwIndex
)?(*lpdwIndex
):0;
1290 INT index
= HTTP_GetCustomHeaderIndex(lpwhr
, (LPWSTR
)lpBuffer
,
1291 requested_index
,request_only
);
1296 lphttpHdr
= &lpwhr
->pCustHeaders
[index
];
1303 INT index
= dwInfoLevel
& ~HTTP_QUERY_MODIFIER_FLAGS_MASK
;
1305 if (index
== HTTP_QUERY_RAW_HEADERS_CRLF
)
1307 DWORD len
= strlenW(lpwhr
->lpszRawHeaders
);
1308 if (len
+ 1 > *lpdwBufferLength
/sizeof(WCHAR
))
1310 *lpdwBufferLength
= (len
+ 1) * sizeof(WCHAR
);
1311 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1314 memcpy(lpBuffer
, lpwhr
->lpszRawHeaders
, (len
+1)*sizeof(WCHAR
));
1315 *lpdwBufferLength
= len
* sizeof(WCHAR
);
1317 TRACE("returning data: %s\n", debugstr_wn((WCHAR
*)lpBuffer
, len
));
1321 else if (index
== HTTP_QUERY_RAW_HEADERS
)
1323 static const WCHAR szCrLf
[] = {'\r','\n',0};
1324 LPWSTR
* ppszRawHeaderLines
= HTTP_Tokenize(lpwhr
->lpszRawHeaders
, szCrLf
);
1326 LPWSTR pszString
= (WCHAR
*)lpBuffer
;
1328 for (i
= 0; ppszRawHeaderLines
[i
]; i
++)
1329 size
+= strlenW(ppszRawHeaderLines
[i
]) + 1;
1331 if (size
+ 1 > *lpdwBufferLength
/sizeof(WCHAR
))
1333 HTTP_FreeTokens(ppszRawHeaderLines
);
1334 *lpdwBufferLength
= (size
+ 1) * sizeof(WCHAR
);
1335 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1339 for (i
= 0; ppszRawHeaderLines
[i
]; i
++)
1341 DWORD len
= strlenW(ppszRawHeaderLines
[i
]);
1342 memcpy(pszString
, ppszRawHeaderLines
[i
], (len
+1)*sizeof(WCHAR
));
1347 TRACE("returning data: %s\n", debugstr_wn((WCHAR
*)lpBuffer
, size
));
1349 *lpdwBufferLength
= size
* sizeof(WCHAR
);
1350 HTTP_FreeTokens(ppszRawHeaderLines
);
1354 else if (index
== HTTP_QUERY_STATUS_TEXT
)
1356 DWORD len
= strlenW(lpwhr
->lpszStatusText
);
1357 if (len
+ 1 > *lpdwBufferLength
/sizeof(WCHAR
))
1359 *lpdwBufferLength
= (len
+ 1) * sizeof(WCHAR
);
1360 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1363 memcpy(lpBuffer
, lpwhr
->lpszStatusText
, (len
+1)*sizeof(WCHAR
));
1364 *lpdwBufferLength
= len
* sizeof(WCHAR
);
1366 TRACE("returning data: %s\n", debugstr_wn((WCHAR
*)lpBuffer
, len
));
1370 else if (index
== HTTP_QUERY_VERSION
)
1372 DWORD len
= strlenW(lpwhr
->lpszVersion
);
1373 if (len
+ 1 > *lpdwBufferLength
/sizeof(WCHAR
))
1375 *lpdwBufferLength
= (len
+ 1) * sizeof(WCHAR
);
1376 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1379 memcpy(lpBuffer
, lpwhr
->lpszVersion
, (len
+1)*sizeof(WCHAR
));
1380 *lpdwBufferLength
= len
* sizeof(WCHAR
);
1382 TRACE("returning data: %s\n", debugstr_wn((WCHAR
*)lpBuffer
, len
));
1386 else if (index
>= 0 && index
<= HTTP_QUERY_MAX
)
1389 for (i
= 0; i
< sizeof(SORTED_STANDARD_HEADERS
)/sizeof(std_hdr_data
) ; i
++)
1391 if (SORTED_STANDARD_HEADERS
[i
].hdrIndex
== index
)
1393 INT requested_index
= (lpdwIndex
)?(*lpdwIndex
):0;
1394 INT index
= HTTP_GetCustomHeaderIndex(lpwhr
,
1395 (LPWSTR
)SORTED_STANDARD_HEADERS
[i
].hdrStr
,
1396 requested_index
,request_only
);
1401 lphttpHdr
= &lpwhr
->pCustHeaders
[index
];
1412 SetLastError(ERROR_HTTP_HEADER_NOT_FOUND
);
1418 SetLastError(ERROR_HTTP_HEADER_NOT_FOUND
);
1423 /* Ensure header satisifies requested attributes */
1424 if ((dwInfoLevel
& HTTP_QUERY_FLAG_REQUEST_HEADERS
) &&
1425 (~lphttpHdr
->wFlags
& HDR_ISREQUEST
))
1427 SetLastError(ERROR_HTTP_HEADER_NOT_FOUND
);
1431 /* coalesce value to reuqested type */
1432 if (dwInfoLevel
& HTTP_QUERY_FLAG_NUMBER
)
1434 *(int *)lpBuffer
= atoiW(lphttpHdr
->lpszValue
);
1437 TRACE(" returning number : %d\n", *(int *)lpBuffer
);
1439 else if (dwInfoLevel
& HTTP_QUERY_FLAG_SYSTEMTIME
)
1445 tmpTime
= ConvertTimeString(lphttpHdr
->lpszValue
);
1447 tmpTM
= *gmtime(&tmpTime
);
1448 STHook
= (SYSTEMTIME
*) lpBuffer
;
1452 STHook
->wDay
= tmpTM
.tm_mday
;
1453 STHook
->wHour
= tmpTM
.tm_hour
;
1454 STHook
->wMilliseconds
= 0;
1455 STHook
->wMinute
= tmpTM
.tm_min
;
1456 STHook
->wDayOfWeek
= tmpTM
.tm_wday
;
1457 STHook
->wMonth
= tmpTM
.tm_mon
+ 1;
1458 STHook
->wSecond
= tmpTM
.tm_sec
;
1459 STHook
->wYear
= tmpTM
.tm_year
;
1463 TRACE(" returning time : %04d/%02d/%02d - %d - %02d:%02d:%02d.%02d\n",
1464 STHook
->wYear
, STHook
->wMonth
, STHook
->wDay
, STHook
->wDayOfWeek
,
1465 STHook
->wHour
, STHook
->wMinute
, STHook
->wSecond
, STHook
->wMilliseconds
);
1467 else if (dwInfoLevel
& HTTP_QUERY_FLAG_COALESCE
)
1469 if (*lpdwIndex
>= lphttpHdr
->wCount
)
1471 INTERNET_SetLastError(ERROR_HTTP_HEADER_NOT_FOUND
);
1475 /* Copy strncpyW(lpBuffer, lphttpHdr[*lpdwIndex], len); */
1479 else if (lphttpHdr
->lpszValue
)
1481 DWORD len
= (strlenW(lphttpHdr
->lpszValue
) + 1) * sizeof(WCHAR
);
1483 if (len
> *lpdwBufferLength
)
1485 *lpdwBufferLength
= len
;
1486 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1490 memcpy(lpBuffer
, lphttpHdr
->lpszValue
, len
);
1491 *lpdwBufferLength
= len
- sizeof(WCHAR
);
1494 TRACE(" returning string : '%s'\n", debugstr_w(lpBuffer
));
1499 /***********************************************************************
1500 * HttpQueryInfoW (WININET.@)
1502 * Queries for information about an HTTP request
1509 BOOL WINAPI
HttpQueryInfoW(HINTERNET hHttpRequest
, DWORD dwInfoLevel
,
1510 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
, LPDWORD lpdwIndex
)
1512 BOOL bSuccess
= FALSE
;
1513 LPWININETHTTPREQW lpwhr
;
1515 if (TRACE_ON(wininet
)) {
1516 #define FE(x) { x, #x }
1517 static const wininet_flag_info query_flags
[] = {
1518 FE(HTTP_QUERY_MIME_VERSION
),
1519 FE(HTTP_QUERY_CONTENT_TYPE
),
1520 FE(HTTP_QUERY_CONTENT_TRANSFER_ENCODING
),
1521 FE(HTTP_QUERY_CONTENT_ID
),
1522 FE(HTTP_QUERY_CONTENT_DESCRIPTION
),
1523 FE(HTTP_QUERY_CONTENT_LENGTH
),
1524 FE(HTTP_QUERY_CONTENT_LANGUAGE
),
1525 FE(HTTP_QUERY_ALLOW
),
1526 FE(HTTP_QUERY_PUBLIC
),
1527 FE(HTTP_QUERY_DATE
),
1528 FE(HTTP_QUERY_EXPIRES
),
1529 FE(HTTP_QUERY_LAST_MODIFIED
),
1530 FE(HTTP_QUERY_MESSAGE_ID
),
1532 FE(HTTP_QUERY_DERIVED_FROM
),
1533 FE(HTTP_QUERY_COST
),
1534 FE(HTTP_QUERY_LINK
),
1535 FE(HTTP_QUERY_PRAGMA
),
1536 FE(HTTP_QUERY_VERSION
),
1537 FE(HTTP_QUERY_STATUS_CODE
),
1538 FE(HTTP_QUERY_STATUS_TEXT
),
1539 FE(HTTP_QUERY_RAW_HEADERS
),
1540 FE(HTTP_QUERY_RAW_HEADERS_CRLF
),
1541 FE(HTTP_QUERY_CONNECTION
),
1542 FE(HTTP_QUERY_ACCEPT
),
1543 FE(HTTP_QUERY_ACCEPT_CHARSET
),
1544 FE(HTTP_QUERY_ACCEPT_ENCODING
),
1545 FE(HTTP_QUERY_ACCEPT_LANGUAGE
),
1546 FE(HTTP_QUERY_AUTHORIZATION
),
1547 FE(HTTP_QUERY_CONTENT_ENCODING
),
1548 FE(HTTP_QUERY_FORWARDED
),
1549 FE(HTTP_QUERY_FROM
),
1550 FE(HTTP_QUERY_IF_MODIFIED_SINCE
),
1551 FE(HTTP_QUERY_LOCATION
),
1552 FE(HTTP_QUERY_ORIG_URI
),
1553 FE(HTTP_QUERY_REFERER
),
1554 FE(HTTP_QUERY_RETRY_AFTER
),
1555 FE(HTTP_QUERY_SERVER
),
1556 FE(HTTP_QUERY_TITLE
),
1557 FE(HTTP_QUERY_USER_AGENT
),
1558 FE(HTTP_QUERY_WWW_AUTHENTICATE
),
1559 FE(HTTP_QUERY_PROXY_AUTHENTICATE
),
1560 FE(HTTP_QUERY_ACCEPT_RANGES
),
1561 FE(HTTP_QUERY_SET_COOKIE
),
1562 FE(HTTP_QUERY_COOKIE
),
1563 FE(HTTP_QUERY_REQUEST_METHOD
),
1564 FE(HTTP_QUERY_REFRESH
),
1565 FE(HTTP_QUERY_CONTENT_DISPOSITION
),
1567 FE(HTTP_QUERY_CACHE_CONTROL
),
1568 FE(HTTP_QUERY_CONTENT_BASE
),
1569 FE(HTTP_QUERY_CONTENT_LOCATION
),
1570 FE(HTTP_QUERY_CONTENT_MD5
),
1571 FE(HTTP_QUERY_CONTENT_RANGE
),
1572 FE(HTTP_QUERY_ETAG
),
1573 FE(HTTP_QUERY_HOST
),
1574 FE(HTTP_QUERY_IF_MATCH
),
1575 FE(HTTP_QUERY_IF_NONE_MATCH
),
1576 FE(HTTP_QUERY_IF_RANGE
),
1577 FE(HTTP_QUERY_IF_UNMODIFIED_SINCE
),
1578 FE(HTTP_QUERY_MAX_FORWARDS
),
1579 FE(HTTP_QUERY_PROXY_AUTHORIZATION
),
1580 FE(HTTP_QUERY_RANGE
),
1581 FE(HTTP_QUERY_TRANSFER_ENCODING
),
1582 FE(HTTP_QUERY_UPGRADE
),
1583 FE(HTTP_QUERY_VARY
),
1585 FE(HTTP_QUERY_WARNING
),
1586 FE(HTTP_QUERY_CUSTOM
)
1588 static const wininet_flag_info modifier_flags
[] = {
1589 FE(HTTP_QUERY_FLAG_REQUEST_HEADERS
),
1590 FE(HTTP_QUERY_FLAG_SYSTEMTIME
),
1591 FE(HTTP_QUERY_FLAG_NUMBER
),
1592 FE(HTTP_QUERY_FLAG_COALESCE
)
1595 DWORD info_mod
= dwInfoLevel
& HTTP_QUERY_MODIFIER_FLAGS_MASK
;
1596 DWORD info
= dwInfoLevel
& HTTP_QUERY_HEADER_MASK
;
1599 TRACE("(%p, 0x%08lx)--> %ld\n", hHttpRequest
, dwInfoLevel
, dwInfoLevel
);
1600 TRACE(" Attribute:");
1601 for (i
= 0; i
< (sizeof(query_flags
) / sizeof(query_flags
[0])); i
++) {
1602 if (query_flags
[i
].val
== info
) {
1603 TRACE(" %s", query_flags
[i
].name
);
1607 if (i
== (sizeof(query_flags
) / sizeof(query_flags
[0]))) {
1608 TRACE(" Unknown (%08lx)", info
);
1611 TRACE(" Modifier:");
1612 for (i
= 0; i
< (sizeof(modifier_flags
) / sizeof(modifier_flags
[0])); i
++) {
1613 if (modifier_flags
[i
].val
& info_mod
) {
1614 TRACE(" %s", modifier_flags
[i
].name
);
1615 info_mod
&= ~ modifier_flags
[i
].val
;
1620 TRACE(" Unknown (%08lx)", info_mod
);
1625 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hHttpRequest
);
1626 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
1628 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1632 bSuccess
= HTTP_HttpQueryInfoW( lpwhr
, dwInfoLevel
,
1633 lpBuffer
, lpdwBufferLength
, lpdwIndex
);
1637 WININET_Release( &lpwhr
->hdr
);
1639 TRACE("%d <--\n", bSuccess
);
1643 /***********************************************************************
1644 * HttpQueryInfoA (WININET.@)
1646 * Queries for information about an HTTP request
1653 BOOL WINAPI
HttpQueryInfoA(HINTERNET hHttpRequest
, DWORD dwInfoLevel
,
1654 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
, LPDWORD lpdwIndex
)
1660 if((dwInfoLevel
& HTTP_QUERY_FLAG_NUMBER
) ||
1661 (dwInfoLevel
& HTTP_QUERY_FLAG_SYSTEMTIME
))
1663 return HttpQueryInfoW( hHttpRequest
, dwInfoLevel
, lpBuffer
,
1664 lpdwBufferLength
, lpdwIndex
);
1667 len
= (*lpdwBufferLength
)*sizeof(WCHAR
);
1668 bufferW
= HeapAlloc( GetProcessHeap(), 0, len
);
1669 /* buffer is in/out because of HTTP_QUERY_CUSTOM */
1670 if ((dwInfoLevel
& HTTP_QUERY_HEADER_MASK
) == HTTP_QUERY_CUSTOM
)
1671 MultiByteToWideChar(CP_ACP
,0,lpBuffer
,-1,bufferW
,len
);
1672 result
= HttpQueryInfoW( hHttpRequest
, dwInfoLevel
, bufferW
,
1676 len
= WideCharToMultiByte( CP_ACP
,0, bufferW
, len
/ sizeof(WCHAR
) + 1,
1677 lpBuffer
, *lpdwBufferLength
, NULL
, NULL
);
1678 *lpdwBufferLength
= len
- 1;
1680 TRACE("lpBuffer: %s\n", debugstr_a(lpBuffer
));
1683 /* since the strings being returned from HttpQueryInfoW should be
1684 * only ASCII characters, it is reasonable to assume that all of
1685 * the Unicode characters can be reduced to a single byte */
1686 *lpdwBufferLength
= len
/ sizeof(WCHAR
);
1688 HeapFree(GetProcessHeap(), 0, bufferW
);
1693 /***********************************************************************
1694 * HttpSendRequestExA (WININET.@)
1696 * Sends the specified request to the HTTP server and allows chunked
1699 BOOL WINAPI
HttpSendRequestExA(HINTERNET hRequest
,
1700 LPINTERNET_BUFFERSA lpBuffersIn
,
1701 LPINTERNET_BUFFERSA lpBuffersOut
,
1702 DWORD dwFlags
, DWORD dwContext
)
1704 INTERNET_BUFFERSW BuffersInW
;
1708 TRACE("(%p, %p, %p, %08lx, %08lx): stub\n", hRequest
, lpBuffersIn
,
1709 lpBuffersOut
, dwFlags
, dwContext
);
1713 BuffersInW
.dwStructSize
= sizeof(LPINTERNET_BUFFERSW
);
1714 if (lpBuffersIn
->lpcszHeader
)
1716 headerlen
= MultiByteToWideChar(CP_ACP
,0,lpBuffersIn
->lpcszHeader
,
1717 lpBuffersIn
->dwHeadersLength
,0,0);
1718 BuffersInW
.lpcszHeader
= HeapAlloc(GetProcessHeap(),0,headerlen
*
1720 if (!BuffersInW
.lpcszHeader
)
1722 SetLastError(ERROR_OUTOFMEMORY
);
1725 BuffersInW
.dwHeadersLength
= MultiByteToWideChar(CP_ACP
, 0,
1726 lpBuffersIn
->lpcszHeader
, lpBuffersIn
->dwHeadersLength
,
1727 (LPWSTR
)BuffersInW
.lpcszHeader
, headerlen
);
1730 BuffersInW
.lpcszHeader
= NULL
;
1731 BuffersInW
.dwHeadersTotal
= lpBuffersIn
->dwHeadersTotal
;
1732 BuffersInW
.lpvBuffer
= lpBuffersIn
->lpvBuffer
;
1733 BuffersInW
.dwBufferLength
= lpBuffersIn
->dwBufferLength
;
1734 BuffersInW
.dwBufferTotal
= lpBuffersIn
->dwBufferTotal
;
1735 BuffersInW
.Next
= NULL
;
1738 rc
= HttpSendRequestExW(hRequest
, lpBuffersIn
? &BuffersInW
: NULL
, NULL
, dwFlags
, dwContext
);
1741 HeapFree(GetProcessHeap(),0,(LPVOID
)BuffersInW
.lpcszHeader
);
1746 /***********************************************************************
1747 * HttpSendRequestExW (WININET.@)
1749 * Sends the specified request to the HTTP server and allows chunked
1752 BOOL WINAPI
HttpSendRequestExW(HINTERNET hRequest
,
1753 LPINTERNET_BUFFERSW lpBuffersIn
,
1754 LPINTERNET_BUFFERSW lpBuffersOut
,
1755 DWORD dwFlags
, DWORD dwContext
)
1758 LPWININETHTTPREQW lpwhr
;
1759 LPWININETHTTPSESSIONW lpwhs
;
1760 LPWININETAPPINFOW hIC
;
1762 TRACE("(%p, %p, %p, %08lx, %08lx)\n", hRequest
, lpBuffersIn
,
1763 lpBuffersOut
, dwFlags
, dwContext
);
1765 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hRequest
);
1767 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
1769 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1773 lpwhs
= (LPWININETHTTPSESSIONW
) lpwhr
->hdr
.lpwhparent
;
1774 assert(lpwhs
->hdr
.htype
== WH_HHTTPSESSION
);
1775 hIC
= (LPWININETAPPINFOW
) lpwhs
->hdr
.lpwhparent
;
1776 assert(hIC
->hdr
.htype
== WH_HINIT
);
1778 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1780 WORKREQUEST workRequest
;
1781 struct WORKREQ_HTTPSENDREQUESTW
*req
;
1783 workRequest
.asyncall
= HTTPSENDREQUESTW
;
1784 workRequest
.hdr
= WININET_AddRef( &lpwhr
->hdr
);
1785 req
= &workRequest
.u
.HttpSendRequestW
;
1786 if (lpBuffersIn
->lpcszHeader
)
1787 /* FIXME: this should use dwHeadersLength or may not be necessary at all */
1788 req
->lpszHeader
= WININET_strdupW(lpBuffersIn
->lpcszHeader
);
1790 req
->lpszHeader
= NULL
;
1791 req
->dwHeaderLength
= lpBuffersIn
->dwHeadersLength
;
1792 req
->lpOptional
= lpBuffersIn
->lpvBuffer
;
1793 req
->dwOptionalLength
= lpBuffersIn
->dwBufferLength
;
1794 req
->dwContentLength
= lpBuffersIn
->dwBufferTotal
;
1795 req
->bEndRequest
= FALSE
;
1797 INTERNET_AsyncCall(&workRequest
);
1799 * This is from windows.
1801 SetLastError(ERROR_IO_PENDING
);
1806 ret
= HTTP_HttpSendRequestW(lpwhr
, lpBuffersIn
->lpcszHeader
, lpBuffersIn
->dwHeadersLength
,
1807 lpBuffersIn
->lpvBuffer
, lpBuffersIn
->dwBufferLength
,
1808 lpBuffersIn
->dwBufferTotal
, FALSE
);
1811 WININET_Release(&lpwhr
->hdr
);
1816 /***********************************************************************
1817 * HttpSendRequestW (WININET.@)
1819 * Sends the specified request to the HTTP server
1826 BOOL WINAPI
HttpSendRequestW(HINTERNET hHttpRequest
, LPCWSTR lpszHeaders
,
1827 DWORD dwHeaderLength
, LPVOID lpOptional
,DWORD dwOptionalLength
)
1829 LPWININETHTTPREQW lpwhr
;
1830 LPWININETHTTPSESSIONW lpwhs
= NULL
;
1831 LPWININETAPPINFOW hIC
= NULL
;
1834 TRACE("%p, %p (%s), %li, %p, %li)\n", hHttpRequest
,
1835 lpszHeaders
, debugstr_w(lpszHeaders
), dwHeaderLength
, lpOptional
, dwOptionalLength
);
1837 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hHttpRequest
);
1838 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
1840 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1845 lpwhs
= (LPWININETHTTPSESSIONW
) lpwhr
->hdr
.lpwhparent
;
1846 if (NULL
== lpwhs
|| lpwhs
->hdr
.htype
!= WH_HHTTPSESSION
)
1848 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1853 hIC
= (LPWININETAPPINFOW
) lpwhs
->hdr
.lpwhparent
;
1854 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
)
1856 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1861 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1863 WORKREQUEST workRequest
;
1864 struct WORKREQ_HTTPSENDREQUESTW
*req
;
1866 workRequest
.asyncall
= HTTPSENDREQUESTW
;
1867 workRequest
.hdr
= WININET_AddRef( &lpwhr
->hdr
);
1868 req
= &workRequest
.u
.HttpSendRequestW
;
1870 req
->lpszHeader
= WININET_strdupW(lpszHeaders
);
1872 req
->lpszHeader
= 0;
1873 req
->dwHeaderLength
= dwHeaderLength
;
1874 req
->lpOptional
= lpOptional
;
1875 req
->dwOptionalLength
= dwOptionalLength
;
1876 req
->dwContentLength
= dwOptionalLength
;
1877 req
->bEndRequest
= TRUE
;
1879 INTERNET_AsyncCall(&workRequest
);
1881 * This is from windows.
1883 SetLastError(ERROR_IO_PENDING
);
1888 r
= HTTP_HttpSendRequestW(lpwhr
, lpszHeaders
,
1889 dwHeaderLength
, lpOptional
, dwOptionalLength
,
1890 dwOptionalLength
, TRUE
);
1894 WININET_Release( &lpwhr
->hdr
);
1898 /***********************************************************************
1899 * HttpSendRequestA (WININET.@)
1901 * Sends the specified request to the HTTP server
1908 BOOL WINAPI
HttpSendRequestA(HINTERNET hHttpRequest
, LPCSTR lpszHeaders
,
1909 DWORD dwHeaderLength
, LPVOID lpOptional
,DWORD dwOptionalLength
)
1912 LPWSTR szHeaders
=NULL
;
1913 DWORD nLen
=dwHeaderLength
;
1914 if(lpszHeaders
!=NULL
)
1916 nLen
=MultiByteToWideChar(CP_ACP
,0,lpszHeaders
,dwHeaderLength
,NULL
,0);
1917 szHeaders
=HeapAlloc(GetProcessHeap(),0,nLen
*sizeof(WCHAR
));
1918 MultiByteToWideChar(CP_ACP
,0,lpszHeaders
,dwHeaderLength
,szHeaders
,nLen
);
1920 result
=HttpSendRequestW(hHttpRequest
, szHeaders
, nLen
, lpOptional
, dwOptionalLength
);
1921 HeapFree(GetProcessHeap(),0,szHeaders
);
1925 /***********************************************************************
1926 * HTTP_HandleRedirect (internal)
1928 static BOOL
HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszUrl
, LPCWSTR lpszHeaders
,
1929 DWORD dwHeaderLength
, LPVOID lpOptional
, DWORD dwOptionalLength
,
1930 DWORD dwContentLength
)
1932 LPWININETHTTPSESSIONW lpwhs
= (LPWININETHTTPSESSIONW
) lpwhr
->hdr
.lpwhparent
;
1933 LPWININETAPPINFOW hIC
= (LPWININETAPPINFOW
) lpwhs
->hdr
.lpwhparent
;
1938 /* if it's an absolute path, keep the same session info */
1939 lstrcpynW(path
, lpszUrl
, 2048);
1941 else if (NULL
!= hIC
->lpszProxy
&& hIC
->lpszProxy
[0] != 0)
1943 TRACE("Redirect through proxy\n");
1944 lstrcpynW(path
, lpszUrl
, 2048);
1948 URL_COMPONENTSW urlComponents
;
1949 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
1950 static const WCHAR szHttp
[] = {'h','t','t','p',0};
1951 static const WCHAR szHttps
[] = {'h','t','t','p','s',0};
1956 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
1957 urlComponents
.lpszScheme
= protocol
;
1958 urlComponents
.dwSchemeLength
= 32;
1959 urlComponents
.lpszHostName
= hostName
;
1960 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
1961 urlComponents
.lpszUserName
= userName
;
1962 urlComponents
.dwUserNameLength
= 1024;
1963 urlComponents
.lpszPassword
= NULL
;
1964 urlComponents
.dwPasswordLength
= 0;
1965 urlComponents
.lpszUrlPath
= path
;
1966 urlComponents
.dwUrlPathLength
= 2048;
1967 urlComponents
.lpszExtraInfo
= NULL
;
1968 urlComponents
.dwExtraInfoLength
= 0;
1969 if(!InternetCrackUrlW(lpszUrl
, strlenW(lpszUrl
), 0, &urlComponents
))
1972 if (!strncmpW(szHttp
, urlComponents
.lpszScheme
, strlenW(szHttp
)) &&
1973 (lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
))
1975 TRACE("redirect from secure page to non-secure page\n");
1976 /* FIXME: warn about from secure redirect to non-secure page */
1977 lpwhr
->hdr
.dwFlags
&= ~INTERNET_FLAG_SECURE
;
1979 if (!strncmpW(szHttps
, urlComponents
.lpszScheme
, strlenW(szHttps
)) &&
1980 !(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
))
1982 TRACE("redirect from non-secure page to secure page\n");
1983 /* FIXME: notify about redirect to secure page */
1984 lpwhr
->hdr
.dwFlags
|= INTERNET_FLAG_SECURE
;
1987 if (urlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
1989 if (lstrlenW(protocol
)>4) /*https*/
1990 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
1992 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1997 * This upsets redirects to binary files on sourceforge.net
1998 * and gives an html page instead of the target file
1999 * Examination of the HTTP request sent by native wininet.dll
2000 * reveals that it doesn't send a referrer in that case.
2001 * Maybe there's a flag that enables this, or maybe a referrer
2002 * shouldn't be added in case of a redirect.
2005 /* consider the current host as the referrer */
2006 if (NULL
!= lpwhs
->lpszServerName
&& strlenW(lpwhs
->lpszServerName
))
2007 HTTP_ProcessHeader(lpwhr
, HTTP_REFERER
, lpwhs
->lpszServerName
,
2008 HTTP_ADDHDR_FLAG_REQ
|HTTP_ADDREQ_FLAG_REPLACE
|
2009 HTTP_ADDHDR_FLAG_ADD_IF_NEW
);
2012 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszServerName
);
2013 lpwhs
->lpszServerName
= WININET_strdupW(hostName
);
2014 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszHostName
);
2015 if (urlComponents
.nPort
!= INTERNET_DEFAULT_HTTP_PORT
&&
2016 urlComponents
.nPort
!= INTERNET_DEFAULT_HTTPS_PORT
)
2019 static WCHAR fmt
[] = {'%','s',':','%','i',0};
2020 len
= lstrlenW(hostName
);
2021 len
+= 7; /* 5 for strlen("65535") + 1 for ":" + 1 for '\0' */
2022 lpwhs
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
2023 sprintfW(lpwhs
->lpszHostName
, fmt
, hostName
, urlComponents
.nPort
);
2026 lpwhs
->lpszHostName
= WININET_strdupW(hostName
);
2028 HTTP_ProcessHeader(lpwhr
, szHost
, lpwhs
->lpszHostName
, HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDHDR_FLAG_REQ
);
2031 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszUserName
);
2032 lpwhs
->lpszUserName
= WININET_strdupW(userName
);
2033 lpwhs
->nServerPort
= urlComponents
.nPort
;
2035 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2036 INTERNET_STATUS_RESOLVING_NAME
,
2037 lpwhs
->lpszServerName
,
2038 strlenW(lpwhs
->lpszServerName
)+1);
2040 if (!GetAddress(lpwhs
->lpszServerName
, lpwhs
->nServerPort
,
2041 &lpwhs
->socketAddress
))
2043 INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED
);
2047 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2048 INTERNET_STATUS_NAME_RESOLVED
,
2049 &(lpwhs
->socketAddress
),
2050 sizeof(struct sockaddr_in
));
2052 NETCON_close(&lpwhr
->netConnection
);
2053 NETCON_init(&lpwhr
->netConnection
,lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
);
2056 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszPath
);
2057 lpwhr
->lpszPath
=NULL
;
2063 rc
= UrlEscapeW(path
, NULL
, &needed
, URL_ESCAPE_SPACES_ONLY
);
2064 if (rc
!= E_POINTER
)
2065 needed
= strlenW(path
)+1;
2066 lpwhr
->lpszPath
= HeapAlloc(GetProcessHeap(), 0, needed
*sizeof(WCHAR
));
2067 rc
= UrlEscapeW(path
, lpwhr
->lpszPath
, &needed
,
2068 URL_ESCAPE_SPACES_ONLY
);
2071 ERR("Unable to escape string!(%s) (%ld)\n",debugstr_w(path
),rc
);
2072 strcpyW(lpwhr
->lpszPath
,path
);
2076 return HTTP_HttpSendRequestW(lpwhr
, lpszHeaders
, dwHeaderLength
, lpOptional
,
2077 dwOptionalLength
, dwContentLength
, TRUE
);
2080 /***********************************************************************
2081 * HTTP_build_req (internal)
2083 * concatenate all the strings in the request together
2085 static LPWSTR
HTTP_build_req( LPCWSTR
*list
, int len
)
2090 for( t
= list
; *t
; t
++ )
2091 len
+= strlenW( *t
);
2094 str
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2097 for( t
= list
; *t
; t
++ )
2103 static BOOL
HTTP_SecureProxyConnect(LPWININETHTTPREQW lpwhr
)
2106 LPWSTR requestString
;
2112 static const WCHAR szConnect
[] = {'C','O','N','N','E','C','T',0};
2113 static const WCHAR szFormat
[] = {'%','s',':','%','d',0};
2114 LPWININETHTTPSESSIONW lpwhs
= (LPWININETHTTPSESSIONW
)lpwhr
->hdr
.lpwhparent
;
2118 lpszPath
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW( lpwhs
->lpszHostName
) + 13)*sizeof(WCHAR
) );
2119 sprintfW( lpszPath
, szFormat
, lpwhs
->lpszHostName
, lpwhs
->nHostPort
);
2120 requestString
= HTTP_BuildHeaderRequestString( lpwhr
, szConnect
, lpszPath
, FALSE
);
2121 HeapFree( GetProcessHeap(), 0, lpszPath
);
2123 len
= WideCharToMultiByte( CP_ACP
, 0, requestString
, -1,
2124 NULL
, 0, NULL
, NULL
);
2125 len
--; /* the nul terminator isn't needed */
2126 ascii_req
= HeapAlloc( GetProcessHeap(), 0, len
);
2127 WideCharToMultiByte( CP_ACP
, 0, requestString
, -1,
2128 ascii_req
, len
, NULL
, NULL
);
2129 HeapFree( GetProcessHeap(), 0, requestString
);
2131 TRACE("full request -> %s\n", debugstr_an( ascii_req
, len
) );
2133 ret
= NETCON_send( &lpwhr
->netConnection
, ascii_req
, len
, 0, &cnt
);
2134 HeapFree( GetProcessHeap(), 0, ascii_req
);
2135 if (!ret
|| cnt
< 0)
2138 responseLen
= HTTP_GetResponseHeaders( lpwhr
);
2145 /***********************************************************************
2146 * HTTP_HttpSendRequestW (internal)
2148 * Sends the specified request to the HTTP server
2155 BOOL WINAPI
HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszHeaders
,
2156 DWORD dwHeaderLength
, LPVOID lpOptional
, DWORD dwOptionalLength
,
2157 DWORD dwContentLength
, BOOL bEndRequest
)
2160 BOOL bSuccess
= FALSE
;
2161 LPWSTR requestString
= NULL
;
2163 BOOL loop_next
= FALSE
;
2164 INTERNET_ASYNC_RESULT iar
;
2167 TRACE("--> %p\n", lpwhr
);
2169 assert(lpwhr
->hdr
.htype
== WH_HHTTPREQ
);
2171 /* Clear any error information */
2172 INTERNET_SetLastError(0);
2174 HTTP_FixVerb(lpwhr
);
2176 /* if we are using optional stuff, we must add the fixed header of that option length */
2177 if (dwContentLength
> 0)
2179 static const WCHAR szContentLength
[] = {
2180 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','l','i','\r','\n',0};
2181 WCHAR contentLengthStr
[sizeof szContentLength
/2 /* includes \n\r */ + 20 /* int */ ];
2182 sprintfW(contentLengthStr
, szContentLength
, dwContentLength
);
2183 HTTP_HttpAddRequestHeadersW(lpwhr
, contentLengthStr
, -1L, HTTP_ADDREQ_FLAG_ADD
);
2186 Host
= HTTP_GetHeader(lpwhr
,szHost
);
2192 TRACE("Going to url %s %s\n", debugstr_w(Host
->lpszValue
), debugstr_w(lpwhr
->lpszPath
));
2197 /* add the headers the caller supplied */
2198 if( lpszHeaders
&& dwHeaderLength
)
2200 HTTP_HttpAddRequestHeadersW(lpwhr
, lpszHeaders
, dwHeaderLength
,
2201 HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDHDR_FLAG_REPLACE
);
2204 /* if there's a proxy username and password, add it to the headers */
2205 HTTP_AddProxyInfo(lpwhr
);
2207 requestString
= HTTP_BuildHeaderRequestString(lpwhr
, lpwhr
->lpszVerb
, lpwhr
->lpszPath
, FALSE
);
2209 TRACE("Request header -> %s\n", debugstr_w(requestString
) );
2211 /* Send the request and store the results */
2212 if (!HTTP_OpenConnection(lpwhr
))
2215 /* send the request as ASCII, tack on the optional data */
2217 dwOptionalLength
= 0;
2218 len
= WideCharToMultiByte( CP_ACP
, 0, requestString
, -1,
2219 NULL
, 0, NULL
, NULL
);
2220 ascii_req
= HeapAlloc( GetProcessHeap(), 0, len
+ dwOptionalLength
);
2221 WideCharToMultiByte( CP_ACP
, 0, requestString
, -1,
2222 ascii_req
, len
, NULL
, NULL
);
2224 memcpy( &ascii_req
[len
-1], lpOptional
, dwOptionalLength
);
2225 len
= (len
+ dwOptionalLength
- 1);
2227 TRACE("full request -> %s\n", debugstr_a(ascii_req
) );
2229 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2230 INTERNET_STATUS_SENDING_REQUEST
, NULL
, 0);
2232 NETCON_send(&lpwhr
->netConnection
, ascii_req
, len
, 0, &cnt
);
2233 HeapFree( GetProcessHeap(), 0, ascii_req
);
2235 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2236 INTERNET_STATUS_REQUEST_SENT
,
2237 &len
, sizeof(DWORD
));
2241 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2242 INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
2247 responseLen
= HTTP_GetResponseHeaders(lpwhr
);
2251 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2252 INTERNET_STATUS_RESPONSE_RECEIVED
, &responseLen
,
2255 HTTP_ProcessHeaders(lpwhr
);
2264 HeapFree(GetProcessHeap(), 0, requestString
);
2266 /* TODO: send notification for P3P header */
2268 if(!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_AUTO_REDIRECT
) && bSuccess
&& bEndRequest
)
2270 DWORD dwCode
,dwCodeLength
=sizeof(DWORD
),dwIndex
=0;
2271 if(HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_STATUS_CODE
,&dwCode
,&dwCodeLength
,&dwIndex
) &&
2272 (dwCode
==302 || dwCode
==301))
2274 WCHAR szNewLocation
[2048];
2275 DWORD dwBufferSize
=2048;
2277 if(HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_LOCATION
,szNewLocation
,&dwBufferSize
,&dwIndex
))
2279 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2280 INTERNET_STATUS_REDIRECT
, szNewLocation
,
2282 return HTTP_HandleRedirect(lpwhr
, szNewLocation
, lpszHeaders
,
2283 dwHeaderLength
, lpOptional
, dwOptionalLength
,
2290 iar
.dwResult
= (DWORD
)bSuccess
;
2291 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: INTERNET_GetLastError();
2293 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2294 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
2295 sizeof(INTERNET_ASYNC_RESULT
));
2302 /***********************************************************************
2303 * HTTP_Connect (internal)
2305 * Create http session handle
2308 * HINTERNET a session handle on success
2312 HINTERNET
HTTP_Connect(LPWININETAPPINFOW hIC
, LPCWSTR lpszServerName
,
2313 INTERNET_PORT nServerPort
, LPCWSTR lpszUserName
,
2314 LPCWSTR lpszPassword
, DWORD dwFlags
, DWORD dwContext
,
2315 DWORD dwInternalFlags
)
2317 BOOL bSuccess
= FALSE
;
2318 LPWININETHTTPSESSIONW lpwhs
= NULL
;
2319 HINTERNET handle
= NULL
;
2323 assert( hIC
->hdr
.htype
== WH_HINIT
);
2325 hIC
->hdr
.dwContext
= dwContext
;
2327 lpwhs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETHTTPSESSIONW
));
2330 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2335 * According to my tests. The name is not resolved until a request is sent
2338 lpwhs
->hdr
.htype
= WH_HHTTPSESSION
;
2339 lpwhs
->hdr
.lpwhparent
= WININET_AddRef( &hIC
->hdr
);
2340 lpwhs
->hdr
.dwFlags
= dwFlags
;
2341 lpwhs
->hdr
.dwContext
= dwContext
;
2342 lpwhs
->hdr
.dwInternalFlags
= dwInternalFlags
;
2343 lpwhs
->hdr
.dwRefCount
= 1;
2344 lpwhs
->hdr
.destroy
= HTTP_CloseHTTPSessionHandle
;
2345 lpwhs
->hdr
.lpfnStatusCB
= hIC
->hdr
.lpfnStatusCB
;
2347 handle
= WININET_AllocHandle( &lpwhs
->hdr
);
2350 ERR("Failed to alloc handle\n");
2351 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2355 if(hIC
->lpszProxy
&& hIC
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
2356 if(strchrW(hIC
->lpszProxy
, ' '))
2357 FIXME("Several proxies not implemented.\n");
2358 if(hIC
->lpszProxyBypass
)
2359 FIXME("Proxy bypass is ignored.\n");
2361 if (NULL
!= lpszServerName
)
2363 lpwhs
->lpszServerName
= WININET_strdupW(lpszServerName
);
2364 lpwhs
->lpszHostName
= WININET_strdupW(lpszServerName
);
2366 if (NULL
!= lpszUserName
)
2367 lpwhs
->lpszUserName
= WININET_strdupW(lpszUserName
);
2368 lpwhs
->nServerPort
= nServerPort
;
2369 lpwhs
->nHostPort
= nServerPort
;
2371 /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
2372 if (!(lpwhs
->hdr
.dwInternalFlags
& INET_OPENURL
))
2374 INTERNET_SendCallback(&hIC
->hdr
, dwContext
,
2375 INTERNET_STATUS_HANDLE_CREATED
, &handle
,
2383 WININET_Release( &lpwhs
->hdr
);
2386 * an INTERNET_STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on
2390 TRACE("%p --> %p (%p)\n", hIC
, handle
, lpwhs
);
2395 /***********************************************************************
2396 * HTTP_OpenConnection (internal)
2398 * Connect to a web server
2405 static BOOL
HTTP_OpenConnection(LPWININETHTTPREQW lpwhr
)
2407 BOOL bSuccess
= FALSE
;
2408 LPWININETHTTPSESSIONW lpwhs
;
2409 LPWININETAPPINFOW hIC
= NULL
;
2414 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
2416 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2420 lpwhs
= (LPWININETHTTPSESSIONW
)lpwhr
->hdr
.lpwhparent
;
2422 hIC
= (LPWININETAPPINFOW
) lpwhs
->hdr
.lpwhparent
;
2423 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2424 INTERNET_STATUS_CONNECTING_TO_SERVER
,
2425 &(lpwhs
->socketAddress
),
2426 sizeof(struct sockaddr_in
));
2428 if (!NETCON_create(&lpwhr
->netConnection
, lpwhs
->socketAddress
.sin_family
,
2431 WARN("Socket creation failed\n");
2435 if (!NETCON_connect(&lpwhr
->netConnection
, (struct sockaddr
*)&lpwhs
->socketAddress
,
2436 sizeof(lpwhs
->socketAddress
)))
2439 if (lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
)
2441 /* Note: we differ from Microsoft's WinINet here. they seem to have
2442 * a bug that causes no status callbacks to be sent when starting
2443 * a tunnel to a proxy server using the CONNECT verb. i believe our
2444 * behaviour to be more correct and to not cause any incompatibilities
2445 * because using a secure connection through a proxy server is a rare
2446 * case that would be hard for anyone to depend on */
2447 if (hIC
->lpszProxy
&& !HTTP_SecureProxyConnect(lpwhr
))
2450 if (!NETCON_secure_connect(&lpwhr
->netConnection
, lpwhs
->lpszHostName
))
2452 WARN("Couldn't connect securely to host\n");
2457 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2458 INTERNET_STATUS_CONNECTED_TO_SERVER
,
2459 &(lpwhs
->socketAddress
),
2460 sizeof(struct sockaddr_in
));
2465 TRACE("%d <--\n", bSuccess
);
2470 /***********************************************************************
2471 * HTTP_clear_response_headers (internal)
2473 * clear out any old response headers
2475 static void HTTP_clear_response_headers( LPWININETHTTPREQW lpwhr
)
2479 for( i
=0; i
<lpwhr
->nCustHeaders
; i
++)
2481 if( !lpwhr
->pCustHeaders
[i
].lpszField
)
2483 if( !lpwhr
->pCustHeaders
[i
].lpszValue
)
2485 if ( lpwhr
->pCustHeaders
[i
].wFlags
& HDR_ISREQUEST
)
2487 HTTP_DeleteCustomHeader( lpwhr
, i
);
2492 /***********************************************************************
2493 * HTTP_GetResponseHeaders (internal)
2495 * Read server response
2502 static INT
HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr
)
2505 WCHAR buffer
[MAX_REPLY_LEN
];
2506 DWORD buflen
= MAX_REPLY_LEN
;
2507 BOOL bSuccess
= FALSE
;
2509 static const WCHAR szCrLf
[] = {'\r','\n',0};
2510 char bufferA
[MAX_REPLY_LEN
];
2511 LPWSTR status_code
, status_text
;
2512 DWORD cchMaxRawHeaders
= 1024;
2513 LPWSTR lpszRawHeaders
= HeapAlloc(GetProcessHeap(), 0, (cchMaxRawHeaders
+1)*sizeof(WCHAR
));
2514 DWORD cchRawHeaders
= 0;
2518 /* clear old response headers (eg. from a redirect response) */
2519 HTTP_clear_response_headers( lpwhr
);
2521 if (!NETCON_connected(&lpwhr
->netConnection
))
2525 * HACK peek at the buffer
2528 /* This is Wine code, we don't support MSG_PEEK yet so we have to do it
2530 NETCON_recv(&lpwhr
->netConnection
, buffer
, buflen
, MSG_PEEK
, &rc
);
2534 * We should first receive 'HTTP/1.x nnn OK' where nnn is the status code.
2536 buflen
= MAX_REPLY_LEN
;
2537 memset(buffer
, 0, MAX_REPLY_LEN
);
2538 if (!NETCON_getNextLine(&lpwhr
->netConnection
, bufferA
, &buflen
))
2543 MultiByteToWideChar( CP_ACP
, 0, bufferA
, buflen
, buffer
, MAX_REPLY_LEN
);
2545 /* regenerate raw headers */
2546 while (cchRawHeaders
+ buflen
+ strlenW(szCrLf
) > cchMaxRawHeaders
)
2548 cchMaxRawHeaders
*= 2;
2549 lpszRawHeaders
= HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders
, (cchMaxRawHeaders
+1)*sizeof(WCHAR
));
2551 memcpy(lpszRawHeaders
+cchRawHeaders
, buffer
, (buflen
-1)*sizeof(WCHAR
));
2552 cchRawHeaders
+= (buflen
-1);
2553 memcpy(lpszRawHeaders
+cchRawHeaders
, szCrLf
, sizeof(szCrLf
));
2554 cchRawHeaders
+= sizeof(szCrLf
)/sizeof(szCrLf
[0])-1;
2555 lpszRawHeaders
[cchRawHeaders
] = '\0';
2557 /* split the version from the status code */
2558 status_code
= strchrW( buffer
, ' ' );
2563 /* split the status code from the status text */
2564 status_text
= strchrW( status_code
, ' ' );
2569 TRACE("version [%s] status code [%s] status text [%s]\n",
2570 debugstr_w(buffer
), debugstr_w(status_code
), debugstr_w(status_text
) );
2572 HTTP_ProcessHeader(lpwhr
, szStatus
, status_code
,
2573 HTTP_ADDHDR_FLAG_REPLACE
);
2575 HeapFree(GetProcessHeap(),0,lpwhr
->lpszVersion
);
2576 HeapFree(GetProcessHeap(),0,lpwhr
->lpszStatusText
);
2578 lpwhr
->lpszVersion
= WININET_strdupW(buffer
);
2579 lpwhr
->lpszStatusText
= WININET_strdupW(status_text
);
2581 /* Parse each response line */
2584 buflen
= MAX_REPLY_LEN
;
2585 if (NETCON_getNextLine(&lpwhr
->netConnection
, bufferA
, &buflen
))
2587 LPWSTR
* pFieldAndValue
;
2592 TRACE("got line %s, now interpreting\n", debugstr_a(bufferA
));
2593 MultiByteToWideChar( CP_ACP
, 0, bufferA
, buflen
, buffer
, MAX_REPLY_LEN
);
2595 while (cchRawHeaders
+ buflen
+ strlenW(szCrLf
) > cchMaxRawHeaders
)
2597 cchMaxRawHeaders
*= 2;
2598 lpszRawHeaders
= HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders
, (cchMaxRawHeaders
+1)*sizeof(WCHAR
));
2600 memcpy(lpszRawHeaders
+cchRawHeaders
, buffer
, (buflen
-1)*sizeof(WCHAR
));
2601 cchRawHeaders
+= (buflen
-1);
2602 memcpy(lpszRawHeaders
+cchRawHeaders
, szCrLf
, sizeof(szCrLf
));
2603 cchRawHeaders
+= sizeof(szCrLf
)/sizeof(szCrLf
[0])-1;
2604 lpszRawHeaders
[cchRawHeaders
] = '\0';
2606 pFieldAndValue
= HTTP_InterpretHttpHeader(buffer
);
2607 if (!pFieldAndValue
)
2610 HTTP_ProcessHeader(lpwhr
, pFieldAndValue
[0], pFieldAndValue
[1],
2611 HTTP_ADDREQ_FLAG_ADD
);
2613 HTTP_FreeTokens(pFieldAndValue
);
2623 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszRawHeaders
);
2624 lpwhr
->lpszRawHeaders
= lpszRawHeaders
;
2625 TRACE("raw headers: %s\n", debugstr_w(lpszRawHeaders
));
2638 static void strip_spaces(LPWSTR start
)
2643 while (*str
== ' ' && *str
!= '\0')
2647 memmove(start
, str
, sizeof(WCHAR
) * (strlenW(str
) + 1));
2649 end
= start
+ strlenW(start
) - 1;
2650 while (end
>= start
&& *end
== ' ')
2658 /***********************************************************************
2659 * HTTP_InterpretHttpHeader (internal)
2661 * Parse server response
2665 * Pointer to array of field, value, NULL on success.
2668 static LPWSTR
* HTTP_InterpretHttpHeader(LPCWSTR buffer
)
2670 LPWSTR
* pTokenPair
;
2674 pTokenPair
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*pTokenPair
)*3);
2676 pszColon
= strchrW(buffer
, ':');
2677 /* must have two tokens */
2680 HTTP_FreeTokens(pTokenPair
);
2682 TRACE("No ':' in line: %s\n", debugstr_w(buffer
));
2686 pTokenPair
[0] = HeapAlloc(GetProcessHeap(), 0, (pszColon
- buffer
+ 1) * sizeof(WCHAR
));
2689 HTTP_FreeTokens(pTokenPair
);
2692 memcpy(pTokenPair
[0], buffer
, (pszColon
- buffer
) * sizeof(WCHAR
));
2693 pTokenPair
[0][pszColon
- buffer
] = '\0';
2697 len
= strlenW(pszColon
);
2698 pTokenPair
[1] = HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
2701 HTTP_FreeTokens(pTokenPair
);
2704 memcpy(pTokenPair
[1], pszColon
, (len
+ 1) * sizeof(WCHAR
));
2706 strip_spaces(pTokenPair
[0]);
2707 strip_spaces(pTokenPair
[1]);
2709 TRACE("field(%s) Value(%s)\n", debugstr_w(pTokenPair
[0]), debugstr_w(pTokenPair
[1]));
2713 /***********************************************************************
2714 * HTTP_ProcessHeader (internal)
2716 * Stuff header into header tables according to <dwModifier>
2720 #define COALESCEFLASG (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
2722 static BOOL
HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr
, LPCWSTR field
, LPCWSTR value
, DWORD dwModifier
)
2724 LPHTTPHEADERW lphttpHdr
= NULL
;
2725 BOOL bSuccess
= FALSE
;
2727 static const WCHAR szConnection
[] = { 'C','o','n','n','e','c','t','i','o','n',0 };
2728 BOOL request_only
= dwModifier
& HTTP_ADDHDR_FLAG_REQ
;
2730 TRACE("--> %s: %s - 0x%08lx\n", debugstr_w(field
), debugstr_w(value
), dwModifier
);
2732 /* Don't let applications add Connection header to request */
2733 if (strcmpW(szConnection
,field
)==0 && (dwModifier
& HTTP_ADDHDR_FLAG_REQ
))
2738 /* REPLACE wins out over ADD */
2739 if (dwModifier
& HTTP_ADDHDR_FLAG_REPLACE
)
2740 dwModifier
&= ~HTTP_ADDHDR_FLAG_ADD
;
2742 if (dwModifier
& HTTP_ADDHDR_FLAG_ADD
)
2745 index
= HTTP_GetCustomHeaderIndex(lpwhr
, field
, 0, request_only
);
2749 if (dwModifier
& HTTP_ADDHDR_FLAG_ADD_IF_NEW
)
2753 lphttpHdr
= &lpwhr
->pCustHeaders
[index
];
2759 hdr
.lpszField
= (LPWSTR
)field
;
2760 hdr
.lpszValue
= (LPWSTR
)value
;
2761 hdr
.wFlags
= hdr
.wCount
= 0;
2763 if (dwModifier
& HTTP_ADDHDR_FLAG_REQ
)
2764 hdr
.wFlags
|= HDR_ISREQUEST
;
2766 return HTTP_InsertCustomHeader(lpwhr
, &hdr
);
2769 if (dwModifier
& HTTP_ADDHDR_FLAG_REQ
)
2770 lphttpHdr
->wFlags
|= HDR_ISREQUEST
;
2772 lphttpHdr
->wFlags
&= ~HDR_ISREQUEST
;
2774 if (dwModifier
& HTTP_ADDHDR_FLAG_REPLACE
)
2776 HTTP_DeleteCustomHeader( lpwhr
, index
);
2782 hdr
.lpszField
= (LPWSTR
)field
;
2783 hdr
.lpszValue
= (LPWSTR
)value
;
2784 hdr
.wFlags
= hdr
.wCount
= 0;
2786 if (dwModifier
& HTTP_ADDHDR_FLAG_REQ
)
2787 hdr
.wFlags
|= HDR_ISREQUEST
;
2789 return HTTP_InsertCustomHeader(lpwhr
, &hdr
);
2794 else if (dwModifier
& COALESCEFLASG
)
2799 INT origlen
= strlenW(lphttpHdr
->lpszValue
);
2800 INT valuelen
= strlenW(value
);
2802 if (dwModifier
& HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA
)
2805 lphttpHdr
->wFlags
|= HDR_COMMADELIMITED
;
2807 else if (dwModifier
& HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON
)
2810 lphttpHdr
->wFlags
|= HDR_COMMADELIMITED
;
2813 len
= origlen
+ valuelen
+ ((ch
> 0) ? 2 : 0);
2815 lpsztmp
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, lphttpHdr
->lpszValue
, (len
+1)*sizeof(WCHAR
));
2818 lphttpHdr
->lpszValue
= lpsztmp
;
2819 /* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */
2822 lphttpHdr
->lpszValue
[origlen
] = ch
;
2824 lphttpHdr
->lpszValue
[origlen
] = ' ';
2828 memcpy(&lphttpHdr
->lpszValue
[origlen
], value
, valuelen
*sizeof(WCHAR
));
2829 lphttpHdr
->lpszValue
[len
] = '\0';
2834 WARN("HeapReAlloc (%d bytes) failed\n",len
+1);
2835 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2838 TRACE("<-- %d\n",bSuccess
);
2843 /***********************************************************************
2844 * HTTP_CloseConnection (internal)
2846 * Close socket connection
2849 static VOID
HTTP_CloseConnection(LPWININETHTTPREQW lpwhr
)
2851 LPWININETHTTPSESSIONW lpwhs
= NULL
;
2852 LPWININETAPPINFOW hIC
= NULL
;
2854 TRACE("%p\n",lpwhr
);
2856 lpwhs
= (LPWININETHTTPSESSIONW
) lpwhr
->hdr
.lpwhparent
;
2857 hIC
= (LPWININETAPPINFOW
) lpwhs
->hdr
.lpwhparent
;
2859 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2860 INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0);
2862 if (NETCON_connected(&lpwhr
->netConnection
))
2864 NETCON_close(&lpwhr
->netConnection
);
2867 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2868 INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0);
2872 /***********************************************************************
2873 * HTTP_CloseHTTPRequestHandle (internal)
2875 * Deallocate request handle
2878 static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr
)
2881 LPWININETHTTPREQW lpwhr
= (LPWININETHTTPREQW
) hdr
;
2885 if (NETCON_connected(&lpwhr
->netConnection
))
2886 HTTP_CloseConnection(lpwhr
);
2888 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszPath
);
2889 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszVerb
);
2890 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszRawHeaders
);
2891 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszVersion
);
2892 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszStatusText
);
2894 for (i
= 0; i
< lpwhr
->nCustHeaders
; i
++)
2896 HeapFree(GetProcessHeap(), 0, lpwhr
->pCustHeaders
[i
].lpszField
);
2897 HeapFree(GetProcessHeap(), 0, lpwhr
->pCustHeaders
[i
].lpszValue
);
2900 HeapFree(GetProcessHeap(), 0, lpwhr
->pCustHeaders
);
2901 HeapFree(GetProcessHeap(), 0, lpwhr
);
2905 /***********************************************************************
2906 * HTTP_CloseHTTPSessionHandle (internal)
2908 * Deallocate session handle
2911 static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr
)
2913 LPWININETHTTPSESSIONW lpwhs
= (LPWININETHTTPSESSIONW
) hdr
;
2915 TRACE("%p\n", lpwhs
);
2917 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszHostName
);
2918 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszServerName
);
2919 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszUserName
);
2920 HeapFree(GetProcessHeap(), 0, lpwhs
);
2924 /***********************************************************************
2925 * HTTP_GetCustomHeaderIndex (internal)
2927 * Return index of custom header from header array
2930 static INT
HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszField
,int requested_index
, BOOL request_only
)
2934 TRACE("%s\n", debugstr_w(lpszField
));
2936 for (index
= 0; index
< lpwhr
->nCustHeaders
; index
++)
2938 if (!strcmpiW(lpwhr
->pCustHeaders
[index
].lpszField
, lpszField
))
2940 if ((request_only
&&
2941 !(lpwhr
->pCustHeaders
[index
].wFlags
& HDR_ISREQUEST
))||
2943 (lpwhr
->pCustHeaders
[index
].wFlags
& HDR_ISREQUEST
)))
2946 if (requested_index
== 0)
2953 if (index
>= lpwhr
->nCustHeaders
)
2956 TRACE("Return: %ld\n", index
);
2961 /***********************************************************************
2962 * HTTP_InsertCustomHeader (internal)
2964 * Insert header into array
2967 static BOOL
HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr
, LPHTTPHEADERW lpHdr
)
2970 LPHTTPHEADERW lph
= NULL
;
2973 TRACE("--> %s: %s\n", debugstr_w(lpHdr
->lpszField
), debugstr_w(lpHdr
->lpszValue
));
2974 count
= lpwhr
->nCustHeaders
+ 1;
2976 lph
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, lpwhr
->pCustHeaders
, sizeof(HTTPHEADERW
) * count
);
2978 lph
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HTTPHEADERW
) * count
);
2982 lpwhr
->pCustHeaders
= lph
;
2983 lpwhr
->pCustHeaders
[count
-1].lpszField
= WININET_strdupW(lpHdr
->lpszField
);
2984 lpwhr
->pCustHeaders
[count
-1].lpszValue
= WININET_strdupW(lpHdr
->lpszValue
);
2985 lpwhr
->pCustHeaders
[count
-1].wFlags
= lpHdr
->wFlags
;
2986 lpwhr
->pCustHeaders
[count
-1].wCount
= lpHdr
->wCount
;
2987 lpwhr
->nCustHeaders
++;
2992 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2999 /***********************************************************************
3000 * HTTP_DeleteCustomHeader (internal)
3002 * Delete header from array
3003 * If this function is called, the indexs may change.
3005 static BOOL
HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr
, DWORD index
)
3007 if( lpwhr
->nCustHeaders
<= 0 )
3009 if( index
>= lpwhr
->nCustHeaders
)
3011 lpwhr
->nCustHeaders
--;
3013 memmove( &lpwhr
->pCustHeaders
[index
], &lpwhr
->pCustHeaders
[index
+1],
3014 (lpwhr
->nCustHeaders
- index
)* sizeof(HTTPHEADERW
) );
3015 memset( &lpwhr
->pCustHeaders
[lpwhr
->nCustHeaders
], 0, sizeof(HTTPHEADERW
) );
3020 /***********************************************************************
3021 * IsHostInProxyBypassList (@)
3026 BOOL WINAPI
IsHostInProxyBypassList(DWORD flags
, LPCSTR szHost
, DWORD length
)
3028 FIXME("STUB: flags=%ld host=%s length=%ld\n",flags
,szHost
,length
);