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
9 * Copyright 2006 Robert Shearman for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #include <sys/types.h>
33 #ifdef HAVE_SYS_SOCKET_H
34 # include <sys/socket.h>
36 #ifdef HAVE_ARPA_INET_H
37 # include <arpa/inet.h>
52 #define NO_SHLWAPI_STREAM
53 #define NO_SHLWAPI_REG
54 #define NO_SHLWAPI_STRFCNS
55 #define NO_SHLWAPI_GDI
60 #include "wine/debug.h"
61 #include "wine/unicode.h"
63 #include "inet_ntop.c"
65 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
67 static const WCHAR g_szHttp1_0
[] = {' ','H','T','T','P','/','1','.','0',0 };
68 static const WCHAR g_szHttp1_1
[] = {' ','H','T','T','P','/','1','.','1',0 };
69 static const WCHAR g_szReferer
[] = {'R','e','f','e','r','e','r',0};
70 static const WCHAR g_szAccept
[] = {'A','c','c','e','p','t',0};
71 static const WCHAR g_szUserAgent
[] = {'U','s','e','r','-','A','g','e','n','t',0};
72 static const WCHAR szHost
[] = { 'H','o','s','t',0 };
73 static const WCHAR szAuthorization
[] = { 'A','u','t','h','o','r','i','z','a','t','i','o','n',0 };
74 static const WCHAR szProxy_Authorization
[] = { 'P','r','o','x','y','-','A','u','t','h','o','r','i','z','a','t','i','o','n',0 };
75 static const WCHAR szStatus
[] = { 'S','t','a','t','u','s',0 };
76 static const WCHAR szKeepAlive
[] = {'K','e','e','p','-','A','l','i','v','e',0};
78 #define MAXHOSTNAME 100
79 #define MAX_FIELD_VALUE_LEN 256
80 #define MAX_FIELD_LEN 256
82 #define HTTP_REFERER g_szReferer
83 #define HTTP_ACCEPT g_szAccept
84 #define HTTP_USERAGENT g_szUserAgent
86 #define HTTP_ADDHDR_FLAG_ADD 0x20000000
87 #define HTTP_ADDHDR_FLAG_ADD_IF_NEW 0x10000000
88 #define HTTP_ADDHDR_FLAG_COALESCE 0x40000000
89 #define HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA 0x40000000
90 #define HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON 0x01000000
91 #define HTTP_ADDHDR_FLAG_REPLACE 0x80000000
92 #define HTTP_ADDHDR_FLAG_REQ 0x02000000
94 #define ARRAYSIZE(array) (sizeof(array)/sizeof((array)[0]))
104 unsigned int auth_data_len
;
105 BOOL finished
; /* finished authenticating */
108 static void HTTP_CloseConnection(LPWININETHANDLEHEADER hdr
);
109 static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr
);
110 static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr
);
111 static BOOL
HTTP_OpenConnection(LPWININETHTTPREQW lpwhr
);
112 static BOOL
HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr
);
113 static BOOL
HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr
, LPCWSTR field
, LPCWSTR value
, DWORD dwModifier
);
114 static LPWSTR
* HTTP_InterpretHttpHeader(LPCWSTR buffer
);
115 static BOOL
HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr
, LPHTTPHEADERW lpHdr
);
116 static INT
HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszField
, INT index
, BOOL Request
);
117 static BOOL
HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr
, DWORD index
);
118 static LPWSTR
HTTP_build_req( LPCWSTR
*list
, int len
);
119 static BOOL WINAPI
HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr
, DWORD
120 dwInfoLevel
, LPVOID lpBuffer
, LPDWORD lpdwBufferLength
, LPDWORD
122 static BOOL
HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszUrl
);
123 static UINT
HTTP_DecodeBase64(LPCWSTR base64
, LPSTR bin
);
124 static BOOL
HTTP_VerifyValidHeader(LPWININETHTTPREQW lpwhr
, LPCWSTR field
);
127 LPHTTPHEADERW
HTTP_GetHeader(LPWININETHTTPREQW req
, LPCWSTR head
)
130 HeaderIndex
= HTTP_GetCustomHeaderIndex(req
, head
, 0, TRUE
);
131 if (HeaderIndex
== -1)
134 return &req
->pCustHeaders
[HeaderIndex
];
137 /***********************************************************************
138 * HTTP_Tokenize (internal)
140 * Tokenize a string, allocating memory for the tokens.
142 static LPWSTR
* HTTP_Tokenize(LPCWSTR string
, LPCWSTR token_string
)
144 LPWSTR
* token_array
;
149 /* empty string has no tokens */
153 for (i
= 0; string
[i
]; i
++)
154 if (!strncmpW(string
+i
, token_string
, strlenW(token_string
)))
158 /* we want to skip over separators, but not the null terminator */
159 for (j
= 0; j
< strlenW(token_string
) - 1; j
++)
165 /* add 1 for terminating NULL */
166 token_array
= HeapAlloc(GetProcessHeap(), 0, (tokens
+1) * sizeof(*token_array
));
167 token_array
[tokens
] = NULL
;
170 for (i
= 0; i
< tokens
; i
++)
173 next_token
= strstrW(string
, token_string
);
174 if (!next_token
) next_token
= string
+strlenW(string
);
175 len
= next_token
- string
;
176 token_array
[i
] = HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
177 memcpy(token_array
[i
], string
, len
*sizeof(WCHAR
));
178 token_array
[i
][len
] = '\0';
179 string
= next_token
+strlenW(token_string
);
184 /***********************************************************************
185 * HTTP_FreeTokens (internal)
187 * Frees memory returned from HTTP_Tokenize.
189 static void HTTP_FreeTokens(LPWSTR
* token_array
)
192 for (i
= 0; token_array
[i
]; i
++)
193 HeapFree(GetProcessHeap(), 0, token_array
[i
]);
194 HeapFree(GetProcessHeap(), 0, token_array
);
197 /* **********************************************************************
199 * Helper functions for the HttpSendRequest(Ex) functions
202 static void AsyncHttpSendRequestProc(WORKREQUEST
*workRequest
)
204 struct WORKREQ_HTTPSENDREQUESTW
const *req
= &workRequest
->u
.HttpSendRequestW
;
205 LPWININETHTTPREQW lpwhr
= (LPWININETHTTPREQW
) workRequest
->hdr
;
207 TRACE("%p\n", lpwhr
);
209 HTTP_HttpSendRequestW(lpwhr
, req
->lpszHeader
,
210 req
->dwHeaderLength
, req
->lpOptional
, req
->dwOptionalLength
,
211 req
->dwContentLength
, req
->bEndRequest
);
213 HeapFree(GetProcessHeap(), 0, req
->lpszHeader
);
216 static void HTTP_FixVerb( LPWININETHTTPREQW lpwhr
)
218 /* if the verb is NULL default to GET */
219 if (NULL
== lpwhr
->lpszVerb
)
221 static const WCHAR szGET
[] = { 'G','E','T', 0 };
222 lpwhr
->lpszVerb
= WININET_strdupW(szGET
);
226 static void HTTP_FixURL( LPWININETHTTPREQW lpwhr
)
228 static const WCHAR szSlash
[] = { '/',0 };
229 static const WCHAR szHttp
[] = { 'h','t','t','p',':','/','/', 0 };
231 /* If we don't have a path we set it to root */
232 if (NULL
== lpwhr
->lpszPath
)
233 lpwhr
->lpszPath
= WININET_strdupW(szSlash
);
234 else /* remove \r and \n*/
236 int nLen
= strlenW(lpwhr
->lpszPath
);
237 while ((nLen
>0 ) && ((lpwhr
->lpszPath
[nLen
-1] == '\r')||(lpwhr
->lpszPath
[nLen
-1] == '\n')))
240 lpwhr
->lpszPath
[nLen
]='\0';
242 /* Replace '\' with '/' */
245 if (lpwhr
->lpszPath
[nLen
] == '\\') lpwhr
->lpszPath
[nLen
]='/';
249 if(CSTR_EQUAL
!= CompareStringW( LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
,
250 lpwhr
->lpszPath
, strlenW(lpwhr
->lpszPath
), szHttp
, strlenW(szHttp
) )
251 && lpwhr
->lpszPath
[0] != '/') /* not an absolute path ?? --> fix it !! */
253 WCHAR
*fixurl
= HeapAlloc(GetProcessHeap(), 0,
254 (strlenW(lpwhr
->lpszPath
) + 2)*sizeof(WCHAR
));
256 strcpyW(fixurl
+ 1, lpwhr
->lpszPath
);
257 HeapFree( GetProcessHeap(), 0, lpwhr
->lpszPath
);
258 lpwhr
->lpszPath
= fixurl
;
262 static LPWSTR
HTTP_BuildHeaderRequestString( LPWININETHTTPREQW lpwhr
, LPCWSTR verb
, LPCWSTR path
, BOOL http1_1
)
264 LPWSTR requestString
;
270 static const WCHAR szSpace
[] = { ' ',0 };
271 static const WCHAR szcrlf
[] = {'\r','\n', 0};
272 static const WCHAR szColon
[] = { ':',' ',0 };
273 static const WCHAR sztwocrlf
[] = {'\r','\n','\r','\n', 0};
275 /* allocate space for an array of all the string pointers to be added */
276 len
= (lpwhr
->nCustHeaders
)*4 + 9;
277 req
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(LPCWSTR
) );
279 /* add the verb, path and HTTP version string */
284 req
[n
++] = http1_1
? g_szHttp1_1
: g_szHttp1_0
;
286 /* Append custom request heades */
287 for (i
= 0; i
< lpwhr
->nCustHeaders
; i
++)
289 if (lpwhr
->pCustHeaders
[i
].wFlags
& HDR_ISREQUEST
)
292 req
[n
++] = lpwhr
->pCustHeaders
[i
].lpszField
;
294 req
[n
++] = lpwhr
->pCustHeaders
[i
].lpszValue
;
296 TRACE("Adding custom header %s (%s)\n",
297 debugstr_w(lpwhr
->pCustHeaders
[i
].lpszField
),
298 debugstr_w(lpwhr
->pCustHeaders
[i
].lpszValue
));
303 ERR("oops. buffer overrun\n");
306 requestString
= HTTP_build_req( req
, 4 );
307 HeapFree( GetProcessHeap(), 0, req
);
310 * Set (header) termination string for request
311 * Make sure there's exactly two new lines at the end of the request
313 p
= &requestString
[strlenW(requestString
)-1];
314 while ( (*p
== '\n') || (*p
== '\r') )
316 strcpyW( p
+1, sztwocrlf
);
318 return requestString
;
321 static void HTTP_ProcessHeaders( LPWININETHTTPREQW lpwhr
)
323 static const WCHAR szSet_Cookie
[] = { 'S','e','t','-','C','o','o','k','i','e',0 };
325 LPHTTPHEADERW setCookieHeader
;
327 HeaderIndex
= HTTP_GetCustomHeaderIndex(lpwhr
, szSet_Cookie
, 0, FALSE
);
328 if (HeaderIndex
== -1)
330 setCookieHeader
= &lpwhr
->pCustHeaders
[HeaderIndex
];
332 if (!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_COOKIES
) && setCookieHeader
->lpszValue
)
334 int nPosStart
= 0, nPosEnd
= 0, len
;
335 static const WCHAR szFmt
[] = { 'h','t','t','p',':','/','/','%','s','/',0};
337 while (setCookieHeader
->lpszValue
[nPosEnd
] != '\0')
339 LPWSTR buf_cookie
, cookie_name
, cookie_data
;
341 LPWSTR domain
= NULL
;
345 while (setCookieHeader
->lpszValue
[nPosEnd
] != ';' && setCookieHeader
->lpszValue
[nPosEnd
] != ',' &&
346 setCookieHeader
->lpszValue
[nPosEnd
] != '\0')
350 if (setCookieHeader
->lpszValue
[nPosEnd
] == ';')
352 /* fixme: not case sensitive, strcasestr is gnu only */
353 int nDomainPosEnd
= 0;
354 int nDomainPosStart
= 0, nDomainLength
= 0;
355 static const WCHAR szDomain
[] = {'d','o','m','a','i','n','=',0};
356 LPWSTR lpszDomain
= strstrW(&setCookieHeader
->lpszValue
[nPosEnd
], szDomain
);
358 { /* they have specified their own domain, lets use it */
359 while (lpszDomain
[nDomainPosEnd
] != ';' && lpszDomain
[nDomainPosEnd
] != ',' &&
360 lpszDomain
[nDomainPosEnd
] != '\0')
364 nDomainPosStart
= strlenW(szDomain
);
365 nDomainLength
= (nDomainPosEnd
- nDomainPosStart
) + 1;
366 domain
= HeapAlloc(GetProcessHeap(), 0, (nDomainLength
+ 1)*sizeof(WCHAR
));
367 lstrcpynW(domain
, &lpszDomain
[nDomainPosStart
], nDomainLength
+ 1);
370 if (setCookieHeader
->lpszValue
[nPosEnd
] == '\0') break;
371 buf_cookie
= HeapAlloc(GetProcessHeap(), 0, ((nPosEnd
- nPosStart
) + 1)*sizeof(WCHAR
));
372 lstrcpynW(buf_cookie
, &setCookieHeader
->lpszValue
[nPosStart
], (nPosEnd
- nPosStart
) + 1);
373 TRACE("%s\n", debugstr_w(buf_cookie
));
374 while (buf_cookie
[nEqualPos
] != '=' && buf_cookie
[nEqualPos
] != '\0')
378 if (buf_cookie
[nEqualPos
] == '\0' || buf_cookie
[nEqualPos
+ 1] == '\0')
380 HeapFree(GetProcessHeap(), 0, buf_cookie
);
384 cookie_name
= HeapAlloc(GetProcessHeap(), 0, (nEqualPos
+ 1)*sizeof(WCHAR
));
385 lstrcpynW(cookie_name
, buf_cookie
, nEqualPos
+ 1);
386 cookie_data
= &buf_cookie
[nEqualPos
+ 1];
388 Host
= HTTP_GetHeader(lpwhr
,szHost
);
389 len
= lstrlenW((domain
? domain
: (Host
?Host
->lpszValue
:NULL
))) +
390 strlenW(lpwhr
->lpszPath
) + 9;
391 buf_url
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
392 sprintfW(buf_url
, szFmt
, (domain
? domain
: (Host
?Host
->lpszValue
:NULL
))); /* FIXME PATH!!! */
393 InternetSetCookieW(buf_url
, cookie_name
, cookie_data
);
395 HeapFree(GetProcessHeap(), 0, buf_url
);
396 HeapFree(GetProcessHeap(), 0, buf_cookie
);
397 HeapFree(GetProcessHeap(), 0, cookie_name
);
398 HeapFree(GetProcessHeap(), 0, domain
);
404 static inline BOOL
is_basic_auth_value( LPCWSTR pszAuthValue
)
406 static const WCHAR szBasic
[] = {'B','a','s','i','c'}; /* Note: not nul-terminated */
407 return !strncmpiW(pszAuthValue
, szBasic
, ARRAYSIZE(szBasic
)) &&
408 ((pszAuthValue
[ARRAYSIZE(szBasic
)] != ' ') || !pszAuthValue
[ARRAYSIZE(szBasic
)]);
411 static BOOL
HTTP_DoAuthorization( LPWININETHTTPREQW lpwhr
, LPCWSTR pszAuthValue
,
412 struct HttpAuthInfo
**ppAuthInfo
,
413 LPWSTR domain_and_username
, LPWSTR password
)
415 SECURITY_STATUS sec_status
;
416 struct HttpAuthInfo
*pAuthInfo
= *ppAuthInfo
;
419 TRACE("%s\n", debugstr_w(pszAuthValue
));
421 if (!domain_and_username
) return FALSE
;
428 pAuthInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(*pAuthInfo
));
432 SecInvalidateHandle(&pAuthInfo
->cred
);
433 SecInvalidateHandle(&pAuthInfo
->ctx
);
434 memset(&pAuthInfo
->exp
, 0, sizeof(pAuthInfo
->exp
));
436 pAuthInfo
->auth_data
= NULL
;
437 pAuthInfo
->auth_data_len
= 0;
438 pAuthInfo
->finished
= FALSE
;
440 if (is_basic_auth_value(pszAuthValue
))
442 static const WCHAR szBasic
[] = {'B','a','s','i','c',0};
443 pAuthInfo
->scheme
= WININET_strdupW(szBasic
);
444 if (!pAuthInfo
->scheme
)
446 HeapFree(GetProcessHeap(), 0, pAuthInfo
);
452 SEC_WINNT_AUTH_IDENTITY_W nt_auth_identity
;
453 WCHAR
*user
= strchrW(domain_and_username
, '\\');
454 WCHAR
*domain
= domain_and_username
;
456 pAuthInfo
->scheme
= WININET_strdupW(pszAuthValue
);
457 if (!pAuthInfo
->scheme
)
459 HeapFree(GetProcessHeap(), 0, pAuthInfo
);
466 user
= domain_and_username
;
469 nt_auth_identity
.Flags
= SEC_WINNT_AUTH_IDENTITY_UNICODE
;
470 nt_auth_identity
.User
= user
;
471 nt_auth_identity
.UserLength
= strlenW(nt_auth_identity
.User
);
472 nt_auth_identity
.Domain
= domain
;
473 nt_auth_identity
.DomainLength
= domain
? user
- domain
- 1 : 0;
474 nt_auth_identity
.Password
= password
;
475 nt_auth_identity
.PasswordLength
= strlenW(nt_auth_identity
.Password
);
477 /* FIXME: make sure scheme accepts SEC_WINNT_AUTH_IDENTITY before calling AcquireCredentialsHandle */
479 sec_status
= AcquireCredentialsHandleW(NULL
, pAuthInfo
->scheme
,
480 SECPKG_CRED_OUTBOUND
, NULL
,
481 &nt_auth_identity
, NULL
,
482 NULL
, &pAuthInfo
->cred
,
484 if (sec_status
!= SEC_E_OK
)
486 WARN("AcquireCredentialsHandleW for scheme %s failed with error 0x%08x\n",
487 debugstr_w(pAuthInfo
->scheme
), sec_status
);
488 HeapFree(GetProcessHeap(), 0, pAuthInfo
->scheme
);
489 HeapFree(GetProcessHeap(), 0, pAuthInfo
);
493 *ppAuthInfo
= pAuthInfo
;
495 else if (pAuthInfo
->finished
)
498 if ((strlenW(pszAuthValue
) < strlenW(pAuthInfo
->scheme
)) ||
499 strncmpiW(pszAuthValue
, pAuthInfo
->scheme
, strlenW(pAuthInfo
->scheme
)))
501 ERR("authentication scheme changed from %s to %s\n",
502 debugstr_w(pAuthInfo
->scheme
), debugstr_w(pszAuthValue
));
506 if (is_basic_auth_value(pszAuthValue
))
508 int userlen
= WideCharToMultiByte(CP_UTF8
, 0, domain_and_username
, lstrlenW(domain_and_username
), NULL
, 0, NULL
, NULL
);
509 int passlen
= WideCharToMultiByte(CP_UTF8
, 0, password
, lstrlenW(password
), NULL
, 0, NULL
, NULL
);
512 TRACE("basic authentication\n");
514 /* length includes a nul terminator, which will be re-used for the ':' */
515 auth_data
= HeapAlloc(GetProcessHeap(), 0, userlen
+ 1 + passlen
);
519 WideCharToMultiByte(CP_UTF8
, 0, domain_and_username
, -1, auth_data
, userlen
, NULL
, NULL
);
520 auth_data
[userlen
] = ':';
521 WideCharToMultiByte(CP_UTF8
, 0, password
, -1, &auth_data
[userlen
+1], passlen
, NULL
, NULL
);
523 pAuthInfo
->auth_data
= auth_data
;
524 pAuthInfo
->auth_data_len
= userlen
+ 1 + passlen
;
525 pAuthInfo
->finished
= TRUE
;
532 SecBufferDesc out_desc
, in_desc
;
534 unsigned char *buffer
;
535 ULONG context_req
= ISC_REQ_CONNECTION
| ISC_REQ_USE_DCE_STYLE
|
536 ISC_REQ_MUTUAL_AUTH
| ISC_REQ_DELEGATE
;
538 in
.BufferType
= SECBUFFER_TOKEN
;
542 in_desc
.ulVersion
= 0;
543 in_desc
.cBuffers
= 1;
544 in_desc
.pBuffers
= &in
;
546 pszAuthData
= pszAuthValue
+ strlenW(pAuthInfo
->scheme
);
547 if (*pszAuthData
== ' ')
550 in
.cbBuffer
= HTTP_DecodeBase64(pszAuthData
, NULL
);
551 in
.pvBuffer
= HeapAlloc(GetProcessHeap(), 0, in
.cbBuffer
);
552 HTTP_DecodeBase64(pszAuthData
, in
.pvBuffer
);
555 buffer
= HeapAlloc(GetProcessHeap(), 0, 0x100);
557 out
.BufferType
= SECBUFFER_TOKEN
;
558 out
.cbBuffer
= 0x100;
559 out
.pvBuffer
= buffer
;
561 out_desc
.ulVersion
= 0;
562 out_desc
.cBuffers
= 1;
563 out_desc
.pBuffers
= &out
;
565 sec_status
= InitializeSecurityContextW(first
? &pAuthInfo
->cred
: NULL
,
566 first
? NULL
: &pAuthInfo
->ctx
, NULL
,
567 context_req
, 0, SECURITY_NETWORK_DREP
,
568 in
.pvBuffer
? &in_desc
: NULL
,
569 0, &pAuthInfo
->ctx
, &out_desc
,
570 &pAuthInfo
->attr
, &pAuthInfo
->exp
);
571 if (sec_status
== SEC_E_OK
)
573 pAuthInfo
->finished
= TRUE
;
574 pAuthInfo
->auth_data
= out
.pvBuffer
;
575 pAuthInfo
->auth_data_len
= out
.cbBuffer
;
576 TRACE("sending last auth packet\n");
578 else if (sec_status
== SEC_I_CONTINUE_NEEDED
)
580 pAuthInfo
->auth_data
= out
.pvBuffer
;
581 pAuthInfo
->auth_data_len
= out
.cbBuffer
;
582 TRACE("sending next auth packet\n");
586 ERR("InitializeSecurityContextW returned error 0x%08x\n", sec_status
);
587 HeapFree(GetProcessHeap(), 0, out
.pvBuffer
);
595 /***********************************************************************
596 * HTTP_HttpAddRequestHeadersW (internal)
598 static BOOL WINAPI
HTTP_HttpAddRequestHeadersW(LPWININETHTTPREQW lpwhr
,
599 LPCWSTR lpszHeader
, DWORD dwHeaderLength
, DWORD dwModifier
)
604 BOOL bSuccess
= FALSE
;
607 TRACE("copying header: %s\n", debugstr_w(lpszHeader
));
609 if( dwHeaderLength
== ~0U )
610 len
= strlenW(lpszHeader
);
612 len
= dwHeaderLength
;
613 buffer
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1) );
614 lstrcpynW( buffer
, lpszHeader
, len
+ 1);
620 LPWSTR
* pFieldAndValue
;
624 while (*lpszEnd
!= '\0')
626 if (*lpszEnd
== '\r' && *(lpszEnd
+ 1) == '\n')
631 if (*lpszStart
== '\0')
634 if (*lpszEnd
== '\r')
637 lpszEnd
+= 2; /* Jump over \r\n */
639 TRACE("interpreting header %s\n", debugstr_w(lpszStart
));
640 pFieldAndValue
= HTTP_InterpretHttpHeader(lpszStart
);
643 bSuccess
= HTTP_VerifyValidHeader(lpwhr
, pFieldAndValue
[0]);
645 bSuccess
= HTTP_ProcessHeader(lpwhr
, pFieldAndValue
[0],
646 pFieldAndValue
[1], dwModifier
| HTTP_ADDHDR_FLAG_REQ
);
647 HTTP_FreeTokens(pFieldAndValue
);
653 HeapFree(GetProcessHeap(), 0, buffer
);
658 /***********************************************************************
659 * HttpAddRequestHeadersW (WININET.@)
661 * Adds one or more HTTP header to the request handler
668 BOOL WINAPI
HttpAddRequestHeadersW(HINTERNET hHttpRequest
,
669 LPCWSTR lpszHeader
, DWORD dwHeaderLength
, DWORD dwModifier
)
671 BOOL bSuccess
= FALSE
;
672 LPWININETHTTPREQW lpwhr
;
674 TRACE("%p, %s, %i, %i\n", hHttpRequest
, debugstr_w(lpszHeader
), dwHeaderLength
,
680 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hHttpRequest
);
681 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
683 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
686 bSuccess
= HTTP_HttpAddRequestHeadersW( lpwhr
, lpszHeader
, dwHeaderLength
, dwModifier
);
689 WININET_Release( &lpwhr
->hdr
);
694 /***********************************************************************
695 * HttpAddRequestHeadersA (WININET.@)
697 * Adds one or more HTTP header to the request handler
704 BOOL WINAPI
HttpAddRequestHeadersA(HINTERNET hHttpRequest
,
705 LPCSTR lpszHeader
, DWORD dwHeaderLength
, DWORD dwModifier
)
711 TRACE("%p, %s, %i, %i\n", hHttpRequest
, debugstr_a(lpszHeader
), dwHeaderLength
,
714 len
= MultiByteToWideChar( CP_ACP
, 0, lpszHeader
, dwHeaderLength
, NULL
, 0 );
715 hdr
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
716 MultiByteToWideChar( CP_ACP
, 0, lpszHeader
, dwHeaderLength
, hdr
, len
);
717 if( dwHeaderLength
!= ~0U )
718 dwHeaderLength
= len
;
720 r
= HttpAddRequestHeadersW( hHttpRequest
, hdr
, dwHeaderLength
, dwModifier
);
722 HeapFree( GetProcessHeap(), 0, hdr
);
727 /* read any content returned by the server so that the connection can be
729 static void HTTP_DrainContent(LPWININETHTTPREQW lpwhr
)
733 if (!NETCON_connected(&lpwhr
->netConnection
)) return;
735 if (lpwhr
->dwContentLength
== -1)
736 NETCON_close(&lpwhr
->netConnection
);
741 if (!INTERNET_ReadFile(&lpwhr
->hdr
, buffer
, sizeof(buffer
), &bytes_read
,
744 } while (bytes_read
);
747 /***********************************************************************
748 * HttpEndRequestA (WININET.@)
750 * Ends an HTTP request that was started by HttpSendRequestEx
757 BOOL WINAPI
HttpEndRequestA(HINTERNET hRequest
,
758 LPINTERNET_BUFFERSA lpBuffersOut
, DWORD dwFlags
, DWORD_PTR dwContext
)
760 LPINTERNET_BUFFERSA ptr
;
761 LPINTERNET_BUFFERSW lpBuffersOutW
,ptrW
;
764 TRACE("(%p, %p, %08x, %08lx): stub\n", hRequest
, lpBuffersOut
, dwFlags
,
769 lpBuffersOutW
= (LPINTERNET_BUFFERSW
)HeapAlloc(GetProcessHeap(),
770 HEAP_ZERO_MEMORY
, sizeof(INTERNET_BUFFERSW
));
772 lpBuffersOutW
= NULL
;
774 ptrW
= lpBuffersOutW
;
777 if (ptr
->lpvBuffer
&& ptr
->dwBufferLength
)
778 ptrW
->lpvBuffer
= HeapAlloc(GetProcessHeap(),0,ptr
->dwBufferLength
);
779 ptrW
->dwBufferLength
= ptr
->dwBufferLength
;
780 ptrW
->dwBufferTotal
= ptr
->dwBufferTotal
;
783 ptrW
->Next
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,
784 sizeof(INTERNET_BUFFERSW
));
790 rc
= HttpEndRequestW(hRequest
, lpBuffersOutW
, dwFlags
, dwContext
);
794 ptrW
= lpBuffersOutW
;
797 LPINTERNET_BUFFERSW ptrW2
;
799 FIXME("Do we need to translate info out of these buffer?\n");
801 HeapFree(GetProcessHeap(),0,(LPVOID
)ptrW
->lpvBuffer
);
803 HeapFree(GetProcessHeap(),0,ptrW
);
811 /***********************************************************************
812 * HttpEndRequestW (WININET.@)
814 * Ends an HTTP request that was started by HttpSendRequestEx
821 BOOL WINAPI
HttpEndRequestW(HINTERNET hRequest
,
822 LPINTERNET_BUFFERSW lpBuffersOut
, DWORD dwFlags
, DWORD_PTR dwContext
)
825 LPWININETHTTPREQW lpwhr
;
830 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hRequest
);
832 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
834 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
836 WININET_Release( &lpwhr
->hdr
);
840 lpwhr
->hdr
.dwFlags
|= dwFlags
;
841 lpwhr
->hdr
.dwContext
= dwContext
;
843 /* We appear to do nothing with lpBuffersOut.. is that correct? */
845 SendAsyncCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
846 INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
848 responseLen
= HTTP_GetResponseHeaders(lpwhr
);
852 SendAsyncCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
853 INTERNET_STATUS_RESPONSE_RECEIVED
, &responseLen
, sizeof(DWORD
));
855 /* process headers here. Is this right? */
856 HTTP_ProcessHeaders(lpwhr
);
858 dwBufferSize
= sizeof(lpwhr
->dwContentLength
);
859 if (!HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
,
860 &lpwhr
->dwContentLength
,&dwBufferSize
,NULL
))
861 lpwhr
->dwContentLength
= -1;
863 if (lpwhr
->dwContentLength
== 0)
864 HTTP_FinishedReading(lpwhr
);
866 if(!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_AUTO_REDIRECT
))
868 DWORD dwCode
,dwCodeLength
=sizeof(DWORD
);
869 if(HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_STATUS_CODE
,&dwCode
,&dwCodeLength
,NULL
) &&
870 (dwCode
==302 || dwCode
==301))
872 WCHAR szNewLocation
[2048];
873 dwBufferSize
=sizeof(szNewLocation
);
874 if(HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_LOCATION
,szNewLocation
,&dwBufferSize
,NULL
))
876 static const WCHAR szGET
[] = { 'G','E','T', 0 };
877 /* redirects are always GETs */
878 HeapFree(GetProcessHeap(),0,lpwhr
->lpszVerb
);
879 lpwhr
->lpszVerb
= WININET_strdupW(szGET
);
880 HTTP_DrainContent(lpwhr
);
881 rc
= HTTP_HandleRedirect(lpwhr
, szNewLocation
);
883 rc
= HTTP_HttpSendRequestW(lpwhr
, NULL
, 0, NULL
, 0, 0, TRUE
);
888 WININET_Release( &lpwhr
->hdr
);
889 TRACE("%i <--\n",rc
);
893 /***********************************************************************
894 * HttpOpenRequestW (WININET.@)
896 * Open a HTTP request handle
899 * HINTERNET a HTTP request handle on success
903 HINTERNET WINAPI
HttpOpenRequestW(HINTERNET hHttpSession
,
904 LPCWSTR lpszVerb
, LPCWSTR lpszObjectName
, LPCWSTR lpszVersion
,
905 LPCWSTR lpszReferrer
, LPCWSTR
*lpszAcceptTypes
,
906 DWORD dwFlags
, DWORD_PTR dwContext
)
908 LPWININETHTTPSESSIONW lpwhs
;
909 HINTERNET handle
= NULL
;
911 TRACE("(%p, %s, %s, %s, %s, %p, %08x, %08lx)\n", hHttpSession
,
912 debugstr_w(lpszVerb
), debugstr_w(lpszObjectName
),
913 debugstr_w(lpszVersion
), debugstr_w(lpszReferrer
), lpszAcceptTypes
,
915 if(lpszAcceptTypes
!=NULL
)
918 for(i
=0;lpszAcceptTypes
[i
]!=NULL
;i
++)
919 TRACE("\taccept type: %s\n",debugstr_w(lpszAcceptTypes
[i
]));
922 lpwhs
= (LPWININETHTTPSESSIONW
) WININET_GetObject( hHttpSession
);
923 if (NULL
== lpwhs
|| lpwhs
->hdr
.htype
!= WH_HHTTPSESSION
)
925 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
930 * My tests seem to show that the windows version does not
931 * become asynchronous until after this point. And anyhow
932 * if this call was asynchronous then how would you get the
933 * necessary HINTERNET pointer returned by this function.
936 handle
= HTTP_HttpOpenRequestW(lpwhs
, lpszVerb
, lpszObjectName
,
937 lpszVersion
, lpszReferrer
, lpszAcceptTypes
,
941 WININET_Release( &lpwhs
->hdr
);
942 TRACE("returning %p\n", handle
);
947 /***********************************************************************
948 * HttpOpenRequestA (WININET.@)
950 * Open a HTTP request handle
953 * HINTERNET a HTTP request handle on success
957 HINTERNET WINAPI
HttpOpenRequestA(HINTERNET hHttpSession
,
958 LPCSTR lpszVerb
, LPCSTR lpszObjectName
, LPCSTR lpszVersion
,
959 LPCSTR lpszReferrer
, LPCSTR
*lpszAcceptTypes
,
960 DWORD dwFlags
, DWORD_PTR dwContext
)
962 LPWSTR szVerb
= NULL
, szObjectName
= NULL
;
963 LPWSTR szVersion
= NULL
, szReferrer
= NULL
, *szAcceptTypes
= NULL
;
965 INT acceptTypesCount
;
966 HINTERNET rc
= FALSE
;
967 TRACE("(%p, %s, %s, %s, %s, %p, %08x, %08lx)\n", hHttpSession
,
968 debugstr_a(lpszVerb
), debugstr_a(lpszObjectName
),
969 debugstr_a(lpszVersion
), debugstr_a(lpszReferrer
), lpszAcceptTypes
,
974 len
= MultiByteToWideChar(CP_ACP
, 0, lpszVerb
, -1, NULL
, 0 );
975 szVerb
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
978 MultiByteToWideChar(CP_ACP
, 0, lpszVerb
, -1, szVerb
, len
);
983 len
= MultiByteToWideChar(CP_ACP
, 0, lpszObjectName
, -1, NULL
, 0 );
984 szObjectName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
987 MultiByteToWideChar(CP_ACP
, 0, lpszObjectName
, -1, szObjectName
, len
);
992 len
= MultiByteToWideChar(CP_ACP
, 0, lpszVersion
, -1, NULL
, 0 );
993 szVersion
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
996 MultiByteToWideChar(CP_ACP
, 0, lpszVersion
, -1, szVersion
, len
);
1001 len
= MultiByteToWideChar(CP_ACP
, 0, lpszReferrer
, -1, NULL
, 0 );
1002 szReferrer
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1005 MultiByteToWideChar(CP_ACP
, 0, lpszReferrer
, -1, szReferrer
, len
);
1008 acceptTypesCount
= 0;
1009 if (lpszAcceptTypes
)
1011 /* find out how many there are */
1012 while (lpszAcceptTypes
[acceptTypesCount
] && *lpszAcceptTypes
[acceptTypesCount
])
1014 szAcceptTypes
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
*) * (acceptTypesCount
+1));
1015 acceptTypesCount
= 0;
1016 while (lpszAcceptTypes
[acceptTypesCount
] && *lpszAcceptTypes
[acceptTypesCount
])
1018 len
= MultiByteToWideChar(CP_ACP
, 0, lpszAcceptTypes
[acceptTypesCount
],
1020 szAcceptTypes
[acceptTypesCount
] = HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1021 if (!szAcceptTypes
[acceptTypesCount
] )
1023 MultiByteToWideChar(CP_ACP
, 0, lpszAcceptTypes
[acceptTypesCount
],
1024 -1, szAcceptTypes
[acceptTypesCount
], len
);
1027 szAcceptTypes
[acceptTypesCount
] = NULL
;
1029 else szAcceptTypes
= 0;
1031 rc
= HttpOpenRequestW(hHttpSession
, szVerb
, szObjectName
,
1032 szVersion
, szReferrer
,
1033 (LPCWSTR
*)szAcceptTypes
, dwFlags
, dwContext
);
1038 acceptTypesCount
= 0;
1039 while (szAcceptTypes
[acceptTypesCount
])
1041 HeapFree(GetProcessHeap(), 0, szAcceptTypes
[acceptTypesCount
]);
1044 HeapFree(GetProcessHeap(), 0, szAcceptTypes
);
1046 HeapFree(GetProcessHeap(), 0, szReferrer
);
1047 HeapFree(GetProcessHeap(), 0, szVersion
);
1048 HeapFree(GetProcessHeap(), 0, szObjectName
);
1049 HeapFree(GetProcessHeap(), 0, szVerb
);
1054 /***********************************************************************
1057 static UINT
HTTP_EncodeBase64( LPCSTR bin
, unsigned int len
, LPWSTR base64
)
1060 static const CHAR HTTP_Base64Enc
[] =
1061 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1065 /* first 6 bits, all from bin[0] */
1066 base64
[n
++] = HTTP_Base64Enc
[(bin
[0] & 0xfc) >> 2];
1067 x
= (bin
[0] & 3) << 4;
1069 /* next 6 bits, 2 from bin[0] and 4 from bin[1] */
1072 base64
[n
++] = HTTP_Base64Enc
[x
];
1077 base64
[n
++] = HTTP_Base64Enc
[ x
| ( (bin
[1]&0xf0) >> 4 ) ];
1078 x
= ( bin
[1] & 0x0f ) << 2;
1080 /* next 6 bits 4 from bin[1] and 2 from bin[2] */
1083 base64
[n
++] = HTTP_Base64Enc
[x
];
1087 base64
[n
++] = HTTP_Base64Enc
[ x
| ( (bin
[2]&0xc0 ) >> 6 ) ];
1089 /* last 6 bits, all from bin [2] */
1090 base64
[n
++] = HTTP_Base64Enc
[ bin
[2] & 0x3f ];
1098 #define CH(x) (((x) >= 'A' && (x) <= 'Z') ? (x) - 'A' : \
1099 ((x) >= 'a' && (x) <= 'z') ? (x) - 'a' + 26 : \
1100 ((x) >= '0' && (x) <= '9') ? (x) - '0' + 52 : \
1101 ((x) == '+') ? 62 : ((x) == '/') ? 63 : -1)
1102 static const signed char HTTP_Base64Dec
[256] =
1104 CH( 0),CH( 1),CH( 2),CH( 3),CH( 4),CH( 5),CH( 6),CH( 7),CH( 8),CH( 9),
1105 CH(10),CH(11),CH(12),CH(13),CH(14),CH(15),CH(16),CH(17),CH(18),CH(19),
1106 CH(20),CH(21),CH(22),CH(23),CH(24),CH(25),CH(26),CH(27),CH(28),CH(29),
1107 CH(30),CH(31),CH(32),CH(33),CH(34),CH(35),CH(36),CH(37),CH(38),CH(39),
1108 CH(40),CH(41),CH(42),CH(43),CH(44),CH(45),CH(46),CH(47),CH(48),CH(49),
1109 CH(50),CH(51),CH(52),CH(53),CH(54),CH(55),CH(56),CH(57),CH(58),CH(59),
1110 CH(60),CH(61),CH(62),CH(63),CH(64),CH(65),CH(66),CH(67),CH(68),CH(69),
1111 CH(70),CH(71),CH(72),CH(73),CH(74),CH(75),CH(76),CH(77),CH(78),CH(79),
1112 CH(80),CH(81),CH(82),CH(83),CH(84),CH(85),CH(86),CH(87),CH(88),CH(89),
1113 CH(90),CH(91),CH(92),CH(93),CH(94),CH(95),CH(96),CH(97),CH(98),CH(99),
1114 CH(100),CH(101),CH(102),CH(103),CH(104),CH(105),CH(106),CH(107),CH(108),CH(109),
1115 CH(110),CH(111),CH(112),CH(113),CH(114),CH(115),CH(116),CH(117),CH(118),CH(119),
1116 CH(120),CH(121),CH(122),CH(123),CH(124),CH(125),CH(126),CH(127),CH(128),CH(129),
1117 CH(130),CH(131),CH(132),CH(133),CH(134),CH(135),CH(136),CH(137),CH(138),CH(139),
1118 CH(140),CH(141),CH(142),CH(143),CH(144),CH(145),CH(146),CH(147),CH(148),CH(149),
1119 CH(150),CH(151),CH(152),CH(153),CH(154),CH(155),CH(156),CH(157),CH(158),CH(159),
1120 CH(160),CH(161),CH(162),CH(163),CH(164),CH(165),CH(166),CH(167),CH(168),CH(169),
1121 CH(170),CH(171),CH(172),CH(173),CH(174),CH(175),CH(176),CH(177),CH(178),CH(179),
1122 CH(180),CH(181),CH(182),CH(183),CH(184),CH(185),CH(186),CH(187),CH(188),CH(189),
1123 CH(190),CH(191),CH(192),CH(193),CH(194),CH(195),CH(196),CH(197),CH(198),CH(199),
1124 CH(200),CH(201),CH(202),CH(203),CH(204),CH(205),CH(206),CH(207),CH(208),CH(209),
1125 CH(210),CH(211),CH(212),CH(213),CH(214),CH(215),CH(216),CH(217),CH(218),CH(219),
1126 CH(220),CH(221),CH(222),CH(223),CH(224),CH(225),CH(226),CH(227),CH(228),CH(229),
1127 CH(230),CH(231),CH(232),CH(233),CH(234),CH(235),CH(236),CH(237),CH(238),CH(239),
1128 CH(240),CH(241),CH(242),CH(243),CH(244),CH(245),CH(246),CH(247),CH(248), CH(249),
1129 CH(250),CH(251),CH(252),CH(253),CH(254),CH(255),
1133 /***********************************************************************
1136 static UINT
HTTP_DecodeBase64( LPCWSTR base64
, LPSTR bin
)
1144 if (base64
[0] > ARRAYSIZE(HTTP_Base64Dec
) ||
1145 ((in
[0] = HTTP_Base64Dec
[base64
[0]]) == -1) ||
1146 base64
[1] > ARRAYSIZE(HTTP_Base64Dec
) ||
1147 ((in
[1] = HTTP_Base64Dec
[base64
[1]]) == -1))
1149 WARN("invalid base64: %s\n", debugstr_w(base64
));
1153 bin
[n
] = (unsigned char) (in
[0] << 2 | in
[1] >> 4);
1156 if ((base64
[2] == '=') && (base64
[3] == '='))
1158 if (base64
[2] > ARRAYSIZE(HTTP_Base64Dec
) ||
1159 ((in
[2] = HTTP_Base64Dec
[base64
[2]]) == -1))
1161 WARN("invalid base64: %s\n", debugstr_w(&base64
[2]));
1165 bin
[n
] = (unsigned char) (in
[1] << 4 | in
[2] >> 2);
1168 if (base64
[3] == '=')
1170 if (base64
[3] > ARRAYSIZE(HTTP_Base64Dec
) ||
1171 ((in
[3] = HTTP_Base64Dec
[base64
[3]]) == -1))
1173 WARN("invalid base64: %s\n", debugstr_w(&base64
[3]));
1177 bin
[n
] = (unsigned char) (((in
[2] << 6) & 0xc0) | in
[3]);
1186 /***********************************************************************
1187 * HTTP_InsertAuthorizationForHeader
1189 * Insert or delete the authorization field in the request header.
1191 static BOOL
HTTP_InsertAuthorizationForHeader( LPWININETHTTPREQW lpwhr
, struct HttpAuthInfo
*pAuthInfo
, LPCWSTR header
)
1193 WCHAR
*authorization
= NULL
;
1195 if (pAuthInfo
&& pAuthInfo
->auth_data_len
)
1197 static const WCHAR wszSpace
[] = {' ',0};
1198 static const WCHAR wszBasic
[] = {'B','a','s','i','c',0};
1201 /* scheme + space + base64 encoded data (3/2/1 bytes data -> 4 bytes of characters) */
1202 len
= strlenW(pAuthInfo
->scheme
)+1+((pAuthInfo
->auth_data_len
+2)*4)/3;
1203 authorization
= HeapAlloc(GetProcessHeap(), 0, (len
+1)*sizeof(WCHAR
));
1207 strcpyW(authorization
, pAuthInfo
->scheme
);
1208 strcatW(authorization
, wszSpace
);
1209 HTTP_EncodeBase64(pAuthInfo
->auth_data
,
1210 pAuthInfo
->auth_data_len
,
1211 authorization
+strlenW(authorization
));
1213 /* clear the data as it isn't valid now that it has been sent to the
1214 * server, unless it's Basic authentication which doesn't do
1215 * connection tracking */
1216 if (strcmpiW(pAuthInfo
->scheme
, wszBasic
))
1218 HeapFree(GetProcessHeap(), 0, pAuthInfo
->auth_data
);
1219 pAuthInfo
->auth_data
= NULL
;
1220 pAuthInfo
->auth_data_len
= 0;
1224 TRACE("Inserting authorization: %s\n", debugstr_w(authorization
));
1226 HTTP_ProcessHeader(lpwhr
, header
, authorization
,
1227 HTTP_ADDHDR_FLAG_REPLACE
| HTTP_ADDHDR_FLAG_REQ
);
1229 HeapFree(GetProcessHeap(), 0, authorization
);
1234 /***********************************************************************
1235 * HTTP_InsertAuthorization
1237 * Insert the authorization field in the request header
1239 static BOOL
HTTP_InsertAuthorization( LPWININETHTTPREQW lpwhr
)
1241 return HTTP_InsertAuthorizationForHeader(lpwhr
, lpwhr
->pAuthInfo
, szAuthorization
);
1244 /***********************************************************************
1245 * HTTP_InsertProxyAuthorization
1247 * Insert the proxy authorization field in the request header
1249 static BOOL
HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr
)
1251 return HTTP_InsertAuthorizationForHeader(lpwhr
, lpwhr
->pProxyAuthInfo
, szProxy_Authorization
);
1254 /***********************************************************************
1255 * HTTP_DealWithProxy
1257 static BOOL
HTTP_DealWithProxy( LPWININETAPPINFOW hIC
,
1258 LPWININETHTTPSESSIONW lpwhs
, LPWININETHTTPREQW lpwhr
)
1260 WCHAR buf
[MAXHOSTNAME
];
1261 WCHAR proxy
[MAXHOSTNAME
+ 15]; /* 15 == "http://" + sizeof(port#) + ":/\0" */
1263 static WCHAR szNul
[] = { 0 };
1264 URL_COMPONENTSW UrlComponents
;
1265 static const WCHAR szHttp
[] = { 'h','t','t','p',':','/','/',0 }, szSlash
[] = { '/',0 } ;
1266 static const WCHAR szFormat1
[] = { 'h','t','t','p',':','/','/','%','s',0 };
1267 static const WCHAR szFormat2
[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 };
1270 memset( &UrlComponents
, 0, sizeof UrlComponents
);
1271 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
1272 UrlComponents
.lpszHostName
= buf
;
1273 UrlComponents
.dwHostNameLength
= MAXHOSTNAME
;
1275 if( CSTR_EQUAL
!= CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
,
1276 hIC
->lpszProxy
,strlenW(szHttp
),szHttp
,strlenW(szHttp
)) )
1277 sprintfW(proxy
, szFormat1
, hIC
->lpszProxy
);
1279 strcpyW(proxy
, hIC
->lpszProxy
);
1280 if( !InternetCrackUrlW(proxy
, 0, 0, &UrlComponents
) )
1282 if( UrlComponents
.dwHostNameLength
== 0 )
1285 if( !lpwhr
->lpszPath
)
1286 lpwhr
->lpszPath
= szNul
;
1287 TRACE("server=%s path=%s\n",
1288 debugstr_w(lpwhs
->lpszHostName
), debugstr_w(lpwhr
->lpszPath
));
1289 /* for constant 15 see above */
1290 len
= strlenW(lpwhs
->lpszHostName
) + strlenW(lpwhr
->lpszPath
) + 15;
1291 url
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1293 if(UrlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
1294 UrlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
1296 sprintfW(url
, szFormat2
, lpwhs
->lpszHostName
, lpwhs
->nHostPort
);
1298 if( lpwhr
->lpszPath
[0] != '/' )
1299 strcatW( url
, szSlash
);
1300 strcatW(url
, lpwhr
->lpszPath
);
1301 if(lpwhr
->lpszPath
!= szNul
)
1302 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszPath
);
1303 lpwhr
->lpszPath
= url
;
1305 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszServerName
);
1306 lpwhs
->lpszServerName
= WININET_strdupW(UrlComponents
.lpszHostName
);
1307 lpwhs
->nServerPort
= UrlComponents
.nPort
;
1312 static BOOL
HTTP_ResolveName(LPWININETHTTPREQW lpwhr
)
1315 LPWININETHTTPSESSIONW lpwhs
= lpwhr
->lpHttpSession
;
1317 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
1318 INTERNET_STATUS_RESOLVING_NAME
,
1319 lpwhs
->lpszServerName
,
1320 strlenW(lpwhs
->lpszServerName
)+1);
1322 if (!GetAddress(lpwhs
->lpszServerName
, lpwhs
->nServerPort
,
1323 &lpwhs
->socketAddress
))
1325 INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED
);
1329 inet_ntop(lpwhs
->socketAddress
.sin_family
, &lpwhs
->socketAddress
.sin_addr
,
1330 szaddr
, sizeof(szaddr
));
1331 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
1332 INTERNET_STATUS_NAME_RESOLVED
,
1333 szaddr
, strlen(szaddr
)+1);
1337 /***********************************************************************
1338 * HTTP_HttpOpenRequestW (internal)
1340 * Open a HTTP request handle
1343 * HINTERNET a HTTP request handle on success
1347 HINTERNET WINAPI
HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs
,
1348 LPCWSTR lpszVerb
, LPCWSTR lpszObjectName
, LPCWSTR lpszVersion
,
1349 LPCWSTR lpszReferrer
, LPCWSTR
*lpszAcceptTypes
,
1350 DWORD dwFlags
, DWORD_PTR dwContext
)
1352 LPWININETAPPINFOW hIC
= NULL
;
1353 LPWININETHTTPREQW lpwhr
;
1355 LPWSTR lpszUrl
= NULL
;
1357 HINTERNET handle
= NULL
;
1358 static const WCHAR szUrlForm
[] = {'h','t','t','p',':','/','/','%','s',0};
1364 assert( lpwhs
->hdr
.htype
== WH_HHTTPSESSION
);
1365 hIC
= lpwhs
->lpAppInfo
;
1367 lpwhr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETHTTPREQW
));
1370 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1373 lpwhr
->hdr
.htype
= WH_HHTTPREQ
;
1374 lpwhr
->hdr
.dwFlags
= dwFlags
;
1375 lpwhr
->hdr
.dwContext
= dwContext
;
1376 lpwhr
->hdr
.dwRefCount
= 1;
1377 lpwhr
->hdr
.close_connection
= HTTP_CloseConnection
;
1378 lpwhr
->hdr
.destroy
= HTTP_CloseHTTPRequestHandle
;
1379 lpwhr
->hdr
.lpfnStatusCB
= lpwhs
->hdr
.lpfnStatusCB
;
1380 lpwhr
->hdr
.dwInternalFlags
= lpwhs
->hdr
.dwInternalFlags
& INET_CALLBACKW
;
1382 WININET_AddRef( &lpwhs
->hdr
);
1383 lpwhr
->lpHttpSession
= lpwhs
;
1384 list_add_head( &lpwhs
->hdr
.children
, &lpwhr
->hdr
.entry
);
1386 handle
= WININET_AllocHandle( &lpwhr
->hdr
);
1389 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
1393 if (!NETCON_init(&lpwhr
->netConnection
, dwFlags
& INTERNET_FLAG_SECURE
))
1395 InternetCloseHandle( handle
);
1400 if (NULL
!= lpszObjectName
&& strlenW(lpszObjectName
)) {
1404 rc
= UrlEscapeW(lpszObjectName
, NULL
, &len
, URL_ESCAPE_SPACES_ONLY
);
1405 if (rc
!= E_POINTER
)
1406 len
= strlenW(lpszObjectName
)+1;
1407 lpwhr
->lpszPath
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1408 rc
= UrlEscapeW(lpszObjectName
, lpwhr
->lpszPath
, &len
,
1409 URL_ESCAPE_SPACES_ONLY
);
1412 ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(lpszObjectName
),rc
);
1413 strcpyW(lpwhr
->lpszPath
,lpszObjectName
);
1417 if (NULL
!= lpszReferrer
&& strlenW(lpszReferrer
))
1418 HTTP_ProcessHeader(lpwhr
, HTTP_REFERER
, lpszReferrer
, HTTP_ADDHDR_FLAG_COALESCE
);
1420 if (lpszAcceptTypes
)
1423 for (i
= 0; lpszAcceptTypes
[i
]; i
++)
1425 if (!*lpszAcceptTypes
[i
]) continue;
1426 HTTP_ProcessHeader(lpwhr
, HTTP_ACCEPT
, lpszAcceptTypes
[i
],
1427 HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA
|
1428 HTTP_ADDHDR_FLAG_REQ
|
1429 (i
== 0 ? HTTP_ADDHDR_FLAG_REPLACE
: 0));
1433 if (NULL
== lpszVerb
)
1435 static const WCHAR szGet
[] = {'G','E','T',0};
1436 lpwhr
->lpszVerb
= WININET_strdupW(szGet
);
1438 else if (strlenW(lpszVerb
))
1439 lpwhr
->lpszVerb
= WININET_strdupW(lpszVerb
);
1441 if (NULL
!= lpszReferrer
&& strlenW(lpszReferrer
))
1443 WCHAR buf
[MAXHOSTNAME
];
1444 URL_COMPONENTSW UrlComponents
;
1446 memset( &UrlComponents
, 0, sizeof UrlComponents
);
1447 UrlComponents
.dwStructSize
= sizeof UrlComponents
;
1448 UrlComponents
.lpszHostName
= buf
;
1449 UrlComponents
.dwHostNameLength
= MAXHOSTNAME
;
1451 InternetCrackUrlW(lpszReferrer
, 0, 0, &UrlComponents
);
1452 if (strlenW(UrlComponents
.lpszHostName
))
1453 HTTP_ProcessHeader(lpwhr
, szHost
, UrlComponents
.lpszHostName
, HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDHDR_FLAG_REQ
);
1456 HTTP_ProcessHeader(lpwhr
, szHost
, lpwhs
->lpszHostName
, HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDHDR_FLAG_REQ
);
1458 if (lpwhs
->nServerPort
== INTERNET_INVALID_PORT_NUMBER
)
1459 lpwhs
->nServerPort
= (dwFlags
& INTERNET_FLAG_SECURE
?
1460 INTERNET_DEFAULT_HTTPS_PORT
:
1461 INTERNET_DEFAULT_HTTP_PORT
);
1462 lpwhs
->nHostPort
= lpwhs
->nServerPort
;
1464 if (NULL
!= hIC
->lpszProxy
&& hIC
->lpszProxy
[0] != 0)
1465 HTTP_DealWithProxy( hIC
, lpwhs
, lpwhr
);
1469 WCHAR
*agent_header
;
1470 static const WCHAR user_agent
[] = {'U','s','e','r','-','A','g','e','n','t',':',' ','%','s','\r','\n',0 };
1472 len
= strlenW(hIC
->lpszAgent
) + strlenW(user_agent
);
1473 agent_header
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
1474 sprintfW(agent_header
, user_agent
, hIC
->lpszAgent
);
1476 HTTP_HttpAddRequestHeadersW(lpwhr
, agent_header
, strlenW(agent_header
),
1477 HTTP_ADDREQ_FLAG_ADD
);
1478 HeapFree(GetProcessHeap(), 0, agent_header
);
1481 Host
= HTTP_GetHeader(lpwhr
,szHost
);
1483 len
= lstrlenW(Host
->lpszValue
) + strlenW(szUrlForm
);
1484 lpszUrl
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1485 sprintfW( lpszUrl
, szUrlForm
, Host
->lpszValue
);
1487 if (!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_COOKIES
) &&
1488 InternetGetCookieW(lpszUrl
, NULL
, NULL
, &nCookieSize
))
1491 static const WCHAR szCookie
[] = {'C','o','o','k','i','e',':',' ',0};
1492 static const WCHAR szcrlf
[] = {'\r','\n',0};
1494 lpszCookies
= HeapAlloc(GetProcessHeap(), 0, (nCookieSize
+ 1 + 8)*sizeof(WCHAR
));
1496 cnt
+= sprintfW(lpszCookies
, szCookie
);
1497 InternetGetCookieW(lpszUrl
, NULL
, lpszCookies
+ cnt
, &nCookieSize
);
1498 strcatW(lpszCookies
, szcrlf
);
1500 HTTP_HttpAddRequestHeadersW(lpwhr
, lpszCookies
, strlenW(lpszCookies
),
1501 HTTP_ADDREQ_FLAG_ADD
);
1502 HeapFree(GetProcessHeap(), 0, lpszCookies
);
1504 HeapFree(GetProcessHeap(), 0, lpszUrl
);
1507 INTERNET_SendCallback(&lpwhs
->hdr
, dwContext
,
1508 INTERNET_STATUS_HANDLE_CREATED
, &handle
,
1512 * A STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on windows
1515 if (!HTTP_ResolveName(lpwhr
))
1517 InternetCloseHandle( handle
);
1523 WININET_Release( &lpwhr
->hdr
);
1525 TRACE("<-- %p (%p)\n", handle
, lpwhr
);
1529 static const WCHAR szAccept
[] = { 'A','c','c','e','p','t',0 };
1530 static const WCHAR szAccept_Charset
[] = { 'A','c','c','e','p','t','-','C','h','a','r','s','e','t', 0 };
1531 static const WCHAR szAccept_Encoding
[] = { 'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',0 };
1532 static const WCHAR szAccept_Language
[] = { 'A','c','c','e','p','t','-','L','a','n','g','u','a','g','e',0 };
1533 static const WCHAR szAccept_Ranges
[] = { 'A','c','c','e','p','t','-','R','a','n','g','e','s',0 };
1534 static const WCHAR szAge
[] = { 'A','g','e',0 };
1535 static const WCHAR szAllow
[] = { 'A','l','l','o','w',0 };
1536 static const WCHAR szCache_Control
[] = { 'C','a','c','h','e','-','C','o','n','t','r','o','l',0 };
1537 static const WCHAR szConnection
[] = { 'C','o','n','n','e','c','t','i','o','n',0 };
1538 static const WCHAR szContent_Base
[] = { 'C','o','n','t','e','n','t','-','B','a','s','e',0 };
1539 static const WCHAR szContent_Encoding
[] = { 'C','o','n','t','e','n','t','-','E','n','c','o','d','i','n','g',0 };
1540 static const WCHAR szContent_ID
[] = { 'C','o','n','t','e','n','t','-','I','D',0 };
1541 static const WCHAR szContent_Language
[] = { 'C','o','n','t','e','n','t','-','L','a','n','g','u','a','g','e',0 };
1542 static const WCHAR szContent_Length
[] = { 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0 };
1543 static const WCHAR szContent_Location
[] = { 'C','o','n','t','e','n','t','-','L','o','c','a','t','i','o','n',0 };
1544 static const WCHAR szContent_MD5
[] = { 'C','o','n','t','e','n','t','-','M','D','5',0 };
1545 static const WCHAR szContent_Range
[] = { 'C','o','n','t','e','n','t','-','R','a','n','g','e',0 };
1546 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 };
1547 static const WCHAR szContent_Type
[] = { 'C','o','n','t','e','n','t','-','T','y','p','e',0 };
1548 static const WCHAR szCookie
[] = { 'C','o','o','k','i','e',0 };
1549 static const WCHAR szDate
[] = { 'D','a','t','e',0 };
1550 static const WCHAR szFrom
[] = { 'F','r','o','m',0 };
1551 static const WCHAR szETag
[] = { 'E','T','a','g',0 };
1552 static const WCHAR szExpect
[] = { 'E','x','p','e','c','t',0 };
1553 static const WCHAR szExpires
[] = { 'E','x','p','i','r','e','s',0 };
1554 static const WCHAR szIf_Match
[] = { 'I','f','-','M','a','t','c','h',0 };
1555 static const WCHAR szIf_Modified_Since
[] = { 'I','f','-','M','o','d','i','f','i','e','d','-','S','i','n','c','e',0 };
1556 static const WCHAR szIf_None_Match
[] = { 'I','f','-','N','o','n','e','-','M','a','t','c','h',0 };
1557 static const WCHAR szIf_Range
[] = { 'I','f','-','R','a','n','g','e',0 };
1558 static const WCHAR szIf_Unmodified_Since
[] = { 'I','f','-','U','n','m','o','d','i','f','i','e','d','-','S','i','n','c','e',0 };
1559 static const WCHAR szLast_Modified
[] = { 'L','a','s','t','-','M','o','d','i','f','i','e','d',0 };
1560 static const WCHAR szLocation
[] = { 'L','o','c','a','t','i','o','n',0 };
1561 static const WCHAR szMax_Forwards
[] = { 'M','a','x','-','F','o','r','w','a','r','d','s',0 };
1562 static const WCHAR szMime_Version
[] = { 'M','i','m','e','-','V','e','r','s','i','o','n',0 };
1563 static const WCHAR szPragma
[] = { 'P','r','a','g','m','a',0 };
1564 static const WCHAR szProxy_Authenticate
[] = { 'P','r','o','x','y','-','A','u','t','h','e','n','t','i','c','a','t','e',0 };
1565 static const WCHAR szProxy_Connection
[] = { 'P','r','o','x','y','-','C','o','n','n','e','c','t','i','o','n',0 };
1566 static const WCHAR szPublic
[] = { 'P','u','b','l','i','c',0 };
1567 static const WCHAR szRange
[] = { 'R','a','n','g','e',0 };
1568 static const WCHAR szReferer
[] = { 'R','e','f','e','r','e','r',0 };
1569 static const WCHAR szRetry_After
[] = { 'R','e','t','r','y','-','A','f','t','e','r',0 };
1570 static const WCHAR szServer
[] = { 'S','e','r','v','e','r',0 };
1571 static const WCHAR szSet_Cookie
[] = { 'S','e','t','-','C','o','o','k','i','e',0 };
1572 static const WCHAR szTransfer_Encoding
[] = { 'T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0 };
1573 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 };
1574 static const WCHAR szUpgrade
[] = { 'U','p','g','r','a','d','e',0 };
1575 static const WCHAR szURI
[] = { 'U','R','I',0 };
1576 static const WCHAR szUser_Agent
[] = { 'U','s','e','r','-','A','g','e','n','t',0 };
1577 static const WCHAR szVary
[] = { 'V','a','r','y',0 };
1578 static const WCHAR szVia
[] = { 'V','i','a',0 };
1579 static const WCHAR szWarning
[] = { 'W','a','r','n','i','n','g',0 };
1580 static const WCHAR szWWW_Authenticate
[] = { 'W','W','W','-','A','u','t','h','e','n','t','i','c','a','t','e',0 };
1582 static const LPCWSTR header_lookup
[] = {
1583 szMime_Version
, /* HTTP_QUERY_MIME_VERSION = 0 */
1584 szContent_Type
, /* HTTP_QUERY_CONTENT_TYPE = 1 */
1585 szContent_Transfer_Encoding
,/* HTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2 */
1586 szContent_ID
, /* HTTP_QUERY_CONTENT_ID = 3 */
1587 NULL
, /* HTTP_QUERY_CONTENT_DESCRIPTION = 4 */
1588 szContent_Length
, /* HTTP_QUERY_CONTENT_LENGTH = 5 */
1589 szContent_Language
, /* HTTP_QUERY_CONTENT_LANGUAGE = 6 */
1590 szAllow
, /* HTTP_QUERY_ALLOW = 7 */
1591 szPublic
, /* HTTP_QUERY_PUBLIC = 8 */
1592 szDate
, /* HTTP_QUERY_DATE = 9 */
1593 szExpires
, /* HTTP_QUERY_EXPIRES = 10 */
1594 szLast_Modified
, /* HTTP_QUERY_LAST_MODIFIED = 11 */
1595 NULL
, /* HTTP_QUERY_MESSAGE_ID = 12 */
1596 szURI
, /* HTTP_QUERY_URI = 13 */
1597 szFrom
, /* HTTP_QUERY_DERIVED_FROM = 14 */
1598 NULL
, /* HTTP_QUERY_COST = 15 */
1599 NULL
, /* HTTP_QUERY_LINK = 16 */
1600 szPragma
, /* HTTP_QUERY_PRAGMA = 17 */
1601 NULL
, /* HTTP_QUERY_VERSION = 18 */
1602 szStatus
, /* HTTP_QUERY_STATUS_CODE = 19 */
1603 NULL
, /* HTTP_QUERY_STATUS_TEXT = 20 */
1604 NULL
, /* HTTP_QUERY_RAW_HEADERS = 21 */
1605 NULL
, /* HTTP_QUERY_RAW_HEADERS_CRLF = 22 */
1606 szConnection
, /* HTTP_QUERY_CONNECTION = 23 */
1607 szAccept
, /* HTTP_QUERY_ACCEPT = 24 */
1608 szAccept_Charset
, /* HTTP_QUERY_ACCEPT_CHARSET = 25 */
1609 szAccept_Encoding
, /* HTTP_QUERY_ACCEPT_ENCODING = 26 */
1610 szAccept_Language
, /* HTTP_QUERY_ACCEPT_LANGUAGE = 27 */
1611 szAuthorization
, /* HTTP_QUERY_AUTHORIZATION = 28 */
1612 szContent_Encoding
, /* HTTP_QUERY_CONTENT_ENCODING = 29 */
1613 NULL
, /* HTTP_QUERY_FORWARDED = 30 */
1614 NULL
, /* HTTP_QUERY_FROM = 31 */
1615 szIf_Modified_Since
, /* HTTP_QUERY_IF_MODIFIED_SINCE = 32 */
1616 szLocation
, /* HTTP_QUERY_LOCATION = 33 */
1617 NULL
, /* HTTP_QUERY_ORIG_URI = 34 */
1618 szReferer
, /* HTTP_QUERY_REFERER = 35 */
1619 szRetry_After
, /* HTTP_QUERY_RETRY_AFTER = 36 */
1620 szServer
, /* HTTP_QUERY_SERVER = 37 */
1621 NULL
, /* HTTP_TITLE = 38 */
1622 szUser_Agent
, /* HTTP_QUERY_USER_AGENT = 39 */
1623 szWWW_Authenticate
, /* HTTP_QUERY_WWW_AUTHENTICATE = 40 */
1624 szProxy_Authenticate
, /* HTTP_QUERY_PROXY_AUTHENTICATE = 41 */
1625 szAccept_Ranges
, /* HTTP_QUERY_ACCEPT_RANGES = 42 */
1626 szSet_Cookie
, /* HTTP_QUERY_SET_COOKIE = 43 */
1627 szCookie
, /* HTTP_QUERY_COOKIE = 44 */
1628 NULL
, /* HTTP_QUERY_REQUEST_METHOD = 45 */
1629 NULL
, /* HTTP_QUERY_REFRESH = 46 */
1630 NULL
, /* HTTP_QUERY_CONTENT_DISPOSITION = 47 */
1631 szAge
, /* HTTP_QUERY_AGE = 48 */
1632 szCache_Control
, /* HTTP_QUERY_CACHE_CONTROL = 49 */
1633 szContent_Base
, /* HTTP_QUERY_CONTENT_BASE = 50 */
1634 szContent_Location
, /* HTTP_QUERY_CONTENT_LOCATION = 51 */
1635 szContent_MD5
, /* HTTP_QUERY_CONTENT_MD5 = 52 */
1636 szContent_Range
, /* HTTP_QUERY_CONTENT_RANGE = 53 */
1637 szETag
, /* HTTP_QUERY_ETAG = 54 */
1638 szHost
, /* HTTP_QUERY_HOST = 55 */
1639 szIf_Match
, /* HTTP_QUERY_IF_MATCH = 56 */
1640 szIf_None_Match
, /* HTTP_QUERY_IF_NONE_MATCH = 57 */
1641 szIf_Range
, /* HTTP_QUERY_IF_RANGE = 58 */
1642 szIf_Unmodified_Since
, /* HTTP_QUERY_IF_UNMODIFIED_SINCE = 59 */
1643 szMax_Forwards
, /* HTTP_QUERY_MAX_FORWARDS = 60 */
1644 szProxy_Authorization
, /* HTTP_QUERY_PROXY_AUTHORIZATION = 61 */
1645 szRange
, /* HTTP_QUERY_RANGE = 62 */
1646 szTransfer_Encoding
, /* HTTP_QUERY_TRANSFER_ENCODING = 63 */
1647 szUpgrade
, /* HTTP_QUERY_UPGRADE = 64 */
1648 szVary
, /* HTTP_QUERY_VARY = 65 */
1649 szVia
, /* HTTP_QUERY_VIA = 66 */
1650 szWarning
, /* HTTP_QUERY_WARNING = 67 */
1651 szExpect
, /* HTTP_QUERY_EXPECT = 68 */
1652 szProxy_Connection
, /* HTTP_QUERY_PROXY_CONNECTION = 69 */
1653 szUnless_Modified_Since
, /* HTTP_QUERY_UNLESS_MODIFIED_SINCE = 70 */
1656 #define LAST_TABLE_HEADER (sizeof(header_lookup)/sizeof(header_lookup[0]))
1658 /***********************************************************************
1659 * HTTP_HttpQueryInfoW (internal)
1661 static BOOL WINAPI
HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr
, DWORD dwInfoLevel
,
1662 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
, LPDWORD lpdwIndex
)
1664 LPHTTPHEADERW lphttpHdr
= NULL
;
1665 BOOL bSuccess
= FALSE
;
1666 BOOL request_only
= dwInfoLevel
& HTTP_QUERY_FLAG_REQUEST_HEADERS
;
1667 INT requested_index
= lpdwIndex
? *lpdwIndex
: 0;
1668 INT level
= (dwInfoLevel
& ~HTTP_QUERY_MODIFIER_FLAGS_MASK
);
1671 /* Find requested header structure */
1674 case HTTP_QUERY_CUSTOM
:
1675 index
= HTTP_GetCustomHeaderIndex(lpwhr
, lpBuffer
, requested_index
, request_only
);
1678 case HTTP_QUERY_RAW_HEADERS_CRLF
:
1685 headers
= HTTP_BuildHeaderRequestString(lpwhr
, lpwhr
->lpszVerb
, lpwhr
->lpszPath
, FALSE
);
1687 headers
= lpwhr
->lpszRawHeaders
;
1689 len
= strlenW(headers
);
1690 if (len
+ 1 > *lpdwBufferLength
/sizeof(WCHAR
))
1692 *lpdwBufferLength
= (len
+ 1) * sizeof(WCHAR
);
1693 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1697 memcpy(lpBuffer
, headers
, (len
+1)*sizeof(WCHAR
));
1698 *lpdwBufferLength
= len
* sizeof(WCHAR
);
1700 TRACE("returning data: %s\n", debugstr_wn((WCHAR
*)lpBuffer
, len
));
1705 HeapFree(GetProcessHeap(), 0, headers
);
1708 case HTTP_QUERY_RAW_HEADERS
:
1710 static const WCHAR szCrLf
[] = {'\r','\n',0};
1711 LPWSTR
* ppszRawHeaderLines
= HTTP_Tokenize(lpwhr
->lpszRawHeaders
, szCrLf
);
1713 LPWSTR pszString
= (WCHAR
*)lpBuffer
;
1715 for (i
= 0; ppszRawHeaderLines
[i
]; i
++)
1716 size
+= strlenW(ppszRawHeaderLines
[i
]) + 1;
1718 if (size
+ 1 > *lpdwBufferLength
/sizeof(WCHAR
))
1720 HTTP_FreeTokens(ppszRawHeaderLines
);
1721 *lpdwBufferLength
= (size
+ 1) * sizeof(WCHAR
);
1722 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1726 for (i
= 0; ppszRawHeaderLines
[i
]; i
++)
1728 DWORD len
= strlenW(ppszRawHeaderLines
[i
]);
1729 memcpy(pszString
, ppszRawHeaderLines
[i
], (len
+1)*sizeof(WCHAR
));
1734 TRACE("returning data: %s\n", debugstr_wn((WCHAR
*)lpBuffer
, size
));
1736 *lpdwBufferLength
= size
* sizeof(WCHAR
);
1737 HTTP_FreeTokens(ppszRawHeaderLines
);
1741 case HTTP_QUERY_STATUS_TEXT
:
1742 if (lpwhr
->lpszStatusText
)
1744 DWORD len
= strlenW(lpwhr
->lpszStatusText
);
1745 if (len
+ 1 > *lpdwBufferLength
/sizeof(WCHAR
))
1747 *lpdwBufferLength
= (len
+ 1) * sizeof(WCHAR
);
1748 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1751 memcpy(lpBuffer
, lpwhr
->lpszStatusText
, (len
+1)*sizeof(WCHAR
));
1752 *lpdwBufferLength
= len
* sizeof(WCHAR
);
1754 TRACE("returning data: %s\n", debugstr_wn((WCHAR
*)lpBuffer
, len
));
1759 case HTTP_QUERY_VERSION
:
1760 if (lpwhr
->lpszVersion
)
1762 DWORD len
= strlenW(lpwhr
->lpszVersion
);
1763 if (len
+ 1 > *lpdwBufferLength
/sizeof(WCHAR
))
1765 *lpdwBufferLength
= (len
+ 1) * sizeof(WCHAR
);
1766 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1769 memcpy(lpBuffer
, lpwhr
->lpszVersion
, (len
+1)*sizeof(WCHAR
));
1770 *lpdwBufferLength
= len
* sizeof(WCHAR
);
1772 TRACE("returning data: %s\n", debugstr_wn((WCHAR
*)lpBuffer
, len
));
1778 assert (LAST_TABLE_HEADER
== (HTTP_QUERY_UNLESS_MODIFIED_SINCE
+ 1));
1780 if (level
>= 0 && level
< LAST_TABLE_HEADER
&& header_lookup
[level
])
1781 index
= HTTP_GetCustomHeaderIndex(lpwhr
, header_lookup
[level
],
1782 requested_index
,request_only
);
1786 lphttpHdr
= &lpwhr
->pCustHeaders
[index
];
1788 /* Ensure header satisifies requested attributes */
1790 ((dwInfoLevel
& HTTP_QUERY_FLAG_REQUEST_HEADERS
) &&
1791 (~lphttpHdr
->wFlags
& HDR_ISREQUEST
)))
1793 INTERNET_SetLastError(ERROR_HTTP_HEADER_NOT_FOUND
);
1800 /* coalesce value to reuqested type */
1801 if (dwInfoLevel
& HTTP_QUERY_FLAG_NUMBER
)
1803 *(int *)lpBuffer
= atoiW(lphttpHdr
->lpszValue
);
1806 TRACE(" returning number : %d\n", *(int *)lpBuffer
);
1808 else if (dwInfoLevel
& HTTP_QUERY_FLAG_SYSTEMTIME
)
1814 tmpTime
= ConvertTimeString(lphttpHdr
->lpszValue
);
1816 tmpTM
= *gmtime(&tmpTime
);
1817 STHook
= (SYSTEMTIME
*) lpBuffer
;
1821 STHook
->wDay
= tmpTM
.tm_mday
;
1822 STHook
->wHour
= tmpTM
.tm_hour
;
1823 STHook
->wMilliseconds
= 0;
1824 STHook
->wMinute
= tmpTM
.tm_min
;
1825 STHook
->wDayOfWeek
= tmpTM
.tm_wday
;
1826 STHook
->wMonth
= tmpTM
.tm_mon
+ 1;
1827 STHook
->wSecond
= tmpTM
.tm_sec
;
1828 STHook
->wYear
= tmpTM
.tm_year
;
1832 TRACE(" returning time : %04d/%02d/%02d - %d - %02d:%02d:%02d.%02d\n",
1833 STHook
->wYear
, STHook
->wMonth
, STHook
->wDay
, STHook
->wDayOfWeek
,
1834 STHook
->wHour
, STHook
->wMinute
, STHook
->wSecond
, STHook
->wMilliseconds
);
1836 else if (lphttpHdr
->lpszValue
)
1838 DWORD len
= (strlenW(lphttpHdr
->lpszValue
) + 1) * sizeof(WCHAR
);
1840 if (len
> *lpdwBufferLength
)
1842 *lpdwBufferLength
= len
;
1843 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1847 memcpy(lpBuffer
, lphttpHdr
->lpszValue
, len
);
1848 *lpdwBufferLength
= len
- sizeof(WCHAR
);
1851 TRACE(" returning string : %s\n", debugstr_w(lpBuffer
));
1856 /***********************************************************************
1857 * HttpQueryInfoW (WININET.@)
1859 * Queries for information about an HTTP request
1866 BOOL WINAPI
HttpQueryInfoW(HINTERNET hHttpRequest
, DWORD dwInfoLevel
,
1867 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
, LPDWORD lpdwIndex
)
1869 BOOL bSuccess
= FALSE
;
1870 LPWININETHTTPREQW lpwhr
;
1872 if (TRACE_ON(wininet
)) {
1873 #define FE(x) { x, #x }
1874 static const wininet_flag_info query_flags
[] = {
1875 FE(HTTP_QUERY_MIME_VERSION
),
1876 FE(HTTP_QUERY_CONTENT_TYPE
),
1877 FE(HTTP_QUERY_CONTENT_TRANSFER_ENCODING
),
1878 FE(HTTP_QUERY_CONTENT_ID
),
1879 FE(HTTP_QUERY_CONTENT_DESCRIPTION
),
1880 FE(HTTP_QUERY_CONTENT_LENGTH
),
1881 FE(HTTP_QUERY_CONTENT_LANGUAGE
),
1882 FE(HTTP_QUERY_ALLOW
),
1883 FE(HTTP_QUERY_PUBLIC
),
1884 FE(HTTP_QUERY_DATE
),
1885 FE(HTTP_QUERY_EXPIRES
),
1886 FE(HTTP_QUERY_LAST_MODIFIED
),
1887 FE(HTTP_QUERY_MESSAGE_ID
),
1889 FE(HTTP_QUERY_DERIVED_FROM
),
1890 FE(HTTP_QUERY_COST
),
1891 FE(HTTP_QUERY_LINK
),
1892 FE(HTTP_QUERY_PRAGMA
),
1893 FE(HTTP_QUERY_VERSION
),
1894 FE(HTTP_QUERY_STATUS_CODE
),
1895 FE(HTTP_QUERY_STATUS_TEXT
),
1896 FE(HTTP_QUERY_RAW_HEADERS
),
1897 FE(HTTP_QUERY_RAW_HEADERS_CRLF
),
1898 FE(HTTP_QUERY_CONNECTION
),
1899 FE(HTTP_QUERY_ACCEPT
),
1900 FE(HTTP_QUERY_ACCEPT_CHARSET
),
1901 FE(HTTP_QUERY_ACCEPT_ENCODING
),
1902 FE(HTTP_QUERY_ACCEPT_LANGUAGE
),
1903 FE(HTTP_QUERY_AUTHORIZATION
),
1904 FE(HTTP_QUERY_CONTENT_ENCODING
),
1905 FE(HTTP_QUERY_FORWARDED
),
1906 FE(HTTP_QUERY_FROM
),
1907 FE(HTTP_QUERY_IF_MODIFIED_SINCE
),
1908 FE(HTTP_QUERY_LOCATION
),
1909 FE(HTTP_QUERY_ORIG_URI
),
1910 FE(HTTP_QUERY_REFERER
),
1911 FE(HTTP_QUERY_RETRY_AFTER
),
1912 FE(HTTP_QUERY_SERVER
),
1913 FE(HTTP_QUERY_TITLE
),
1914 FE(HTTP_QUERY_USER_AGENT
),
1915 FE(HTTP_QUERY_WWW_AUTHENTICATE
),
1916 FE(HTTP_QUERY_PROXY_AUTHENTICATE
),
1917 FE(HTTP_QUERY_ACCEPT_RANGES
),
1918 FE(HTTP_QUERY_SET_COOKIE
),
1919 FE(HTTP_QUERY_COOKIE
),
1920 FE(HTTP_QUERY_REQUEST_METHOD
),
1921 FE(HTTP_QUERY_REFRESH
),
1922 FE(HTTP_QUERY_CONTENT_DISPOSITION
),
1924 FE(HTTP_QUERY_CACHE_CONTROL
),
1925 FE(HTTP_QUERY_CONTENT_BASE
),
1926 FE(HTTP_QUERY_CONTENT_LOCATION
),
1927 FE(HTTP_QUERY_CONTENT_MD5
),
1928 FE(HTTP_QUERY_CONTENT_RANGE
),
1929 FE(HTTP_QUERY_ETAG
),
1930 FE(HTTP_QUERY_HOST
),
1931 FE(HTTP_QUERY_IF_MATCH
),
1932 FE(HTTP_QUERY_IF_NONE_MATCH
),
1933 FE(HTTP_QUERY_IF_RANGE
),
1934 FE(HTTP_QUERY_IF_UNMODIFIED_SINCE
),
1935 FE(HTTP_QUERY_MAX_FORWARDS
),
1936 FE(HTTP_QUERY_PROXY_AUTHORIZATION
),
1937 FE(HTTP_QUERY_RANGE
),
1938 FE(HTTP_QUERY_TRANSFER_ENCODING
),
1939 FE(HTTP_QUERY_UPGRADE
),
1940 FE(HTTP_QUERY_VARY
),
1942 FE(HTTP_QUERY_WARNING
),
1943 FE(HTTP_QUERY_CUSTOM
)
1945 static const wininet_flag_info modifier_flags
[] = {
1946 FE(HTTP_QUERY_FLAG_REQUEST_HEADERS
),
1947 FE(HTTP_QUERY_FLAG_SYSTEMTIME
),
1948 FE(HTTP_QUERY_FLAG_NUMBER
),
1949 FE(HTTP_QUERY_FLAG_COALESCE
)
1952 DWORD info_mod
= dwInfoLevel
& HTTP_QUERY_MODIFIER_FLAGS_MASK
;
1953 DWORD info
= dwInfoLevel
& HTTP_QUERY_HEADER_MASK
;
1956 TRACE("(%p, 0x%08x)--> %d\n", hHttpRequest
, dwInfoLevel
, dwInfoLevel
);
1957 TRACE(" Attribute:");
1958 for (i
= 0; i
< (sizeof(query_flags
) / sizeof(query_flags
[0])); i
++) {
1959 if (query_flags
[i
].val
== info
) {
1960 TRACE(" %s", query_flags
[i
].name
);
1964 if (i
== (sizeof(query_flags
) / sizeof(query_flags
[0]))) {
1965 TRACE(" Unknown (%08x)", info
);
1968 TRACE(" Modifier:");
1969 for (i
= 0; i
< (sizeof(modifier_flags
) / sizeof(modifier_flags
[0])); i
++) {
1970 if (modifier_flags
[i
].val
& info_mod
) {
1971 TRACE(" %s", modifier_flags
[i
].name
);
1972 info_mod
&= ~ modifier_flags
[i
].val
;
1977 TRACE(" Unknown (%08x)", info_mod
);
1982 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hHttpRequest
);
1983 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
1985 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1989 if (lpBuffer
== NULL
)
1990 *lpdwBufferLength
= 0;
1991 bSuccess
= HTTP_HttpQueryInfoW( lpwhr
, dwInfoLevel
,
1992 lpBuffer
, lpdwBufferLength
, lpdwIndex
);
1996 WININET_Release( &lpwhr
->hdr
);
1998 TRACE("%d <--\n", bSuccess
);
2002 /***********************************************************************
2003 * HttpQueryInfoA (WININET.@)
2005 * Queries for information about an HTTP request
2012 BOOL WINAPI
HttpQueryInfoA(HINTERNET hHttpRequest
, DWORD dwInfoLevel
,
2013 LPVOID lpBuffer
, LPDWORD lpdwBufferLength
, LPDWORD lpdwIndex
)
2019 if((dwInfoLevel
& HTTP_QUERY_FLAG_NUMBER
) ||
2020 (dwInfoLevel
& HTTP_QUERY_FLAG_SYSTEMTIME
))
2022 return HttpQueryInfoW( hHttpRequest
, dwInfoLevel
, lpBuffer
,
2023 lpdwBufferLength
, lpdwIndex
);
2028 len
= (*lpdwBufferLength
)*sizeof(WCHAR
);
2029 bufferW
= HeapAlloc( GetProcessHeap(), 0, len
);
2030 /* buffer is in/out because of HTTP_QUERY_CUSTOM */
2031 if ((dwInfoLevel
& HTTP_QUERY_HEADER_MASK
) == HTTP_QUERY_CUSTOM
)
2032 MultiByteToWideChar(CP_ACP
,0,lpBuffer
,-1,bufferW
,len
);
2039 result
= HttpQueryInfoW( hHttpRequest
, dwInfoLevel
, bufferW
,
2043 len
= WideCharToMultiByte( CP_ACP
,0, bufferW
, len
/ sizeof(WCHAR
) + 1,
2044 lpBuffer
, *lpdwBufferLength
, NULL
, NULL
);
2045 *lpdwBufferLength
= len
- 1;
2047 TRACE("lpBuffer: %s\n", debugstr_a(lpBuffer
));
2050 /* since the strings being returned from HttpQueryInfoW should be
2051 * only ASCII characters, it is reasonable to assume that all of
2052 * the Unicode characters can be reduced to a single byte */
2053 *lpdwBufferLength
= len
/ sizeof(WCHAR
);
2055 HeapFree(GetProcessHeap(), 0, bufferW
);
2060 /***********************************************************************
2061 * HttpSendRequestExA (WININET.@)
2063 * Sends the specified request to the HTTP server and allows chunked
2068 * Failure: FALSE, call GetLastError() for more information.
2070 BOOL WINAPI
HttpSendRequestExA(HINTERNET hRequest
,
2071 LPINTERNET_BUFFERSA lpBuffersIn
,
2072 LPINTERNET_BUFFERSA lpBuffersOut
,
2073 DWORD dwFlags
, DWORD_PTR dwContext
)
2075 INTERNET_BUFFERSW BuffersInW
;
2078 LPWSTR header
= NULL
;
2080 TRACE("(%p, %p, %p, %08x, %08lx): stub\n", hRequest
, lpBuffersIn
,
2081 lpBuffersOut
, dwFlags
, dwContext
);
2085 BuffersInW
.dwStructSize
= sizeof(LPINTERNET_BUFFERSW
);
2086 if (lpBuffersIn
->lpcszHeader
)
2088 headerlen
= MultiByteToWideChar(CP_ACP
,0,lpBuffersIn
->lpcszHeader
,
2089 lpBuffersIn
->dwHeadersLength
,0,0);
2090 header
= HeapAlloc(GetProcessHeap(),0,headerlen
*sizeof(WCHAR
));
2091 if (!(BuffersInW
.lpcszHeader
= header
))
2093 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2096 BuffersInW
.dwHeadersLength
= MultiByteToWideChar(CP_ACP
, 0,
2097 lpBuffersIn
->lpcszHeader
, lpBuffersIn
->dwHeadersLength
,
2101 BuffersInW
.lpcszHeader
= NULL
;
2102 BuffersInW
.dwHeadersTotal
= lpBuffersIn
->dwHeadersTotal
;
2103 BuffersInW
.lpvBuffer
= lpBuffersIn
->lpvBuffer
;
2104 BuffersInW
.dwBufferLength
= lpBuffersIn
->dwBufferLength
;
2105 BuffersInW
.dwBufferTotal
= lpBuffersIn
->dwBufferTotal
;
2106 BuffersInW
.Next
= NULL
;
2109 rc
= HttpSendRequestExW(hRequest
, lpBuffersIn
? &BuffersInW
: NULL
, NULL
, dwFlags
, dwContext
);
2111 HeapFree(GetProcessHeap(),0,header
);
2116 /***********************************************************************
2117 * HttpSendRequestExW (WININET.@)
2119 * Sends the specified request to the HTTP server and allows chunked
2124 * Failure: FALSE, call GetLastError() for more information.
2126 BOOL WINAPI
HttpSendRequestExW(HINTERNET hRequest
,
2127 LPINTERNET_BUFFERSW lpBuffersIn
,
2128 LPINTERNET_BUFFERSW lpBuffersOut
,
2129 DWORD dwFlags
, DWORD_PTR dwContext
)
2132 LPWININETHTTPREQW lpwhr
;
2133 LPWININETHTTPSESSIONW lpwhs
;
2134 LPWININETAPPINFOW hIC
;
2136 TRACE("(%p, %p, %p, %08x, %08lx)\n", hRequest
, lpBuffersIn
,
2137 lpBuffersOut
, dwFlags
, dwContext
);
2139 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hRequest
);
2141 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
2143 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2147 lpwhs
= lpwhr
->lpHttpSession
;
2148 assert(lpwhs
->hdr
.htype
== WH_HHTTPSESSION
);
2149 hIC
= lpwhs
->lpAppInfo
;
2150 assert(hIC
->hdr
.htype
== WH_HINIT
);
2152 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
2154 WORKREQUEST workRequest
;
2155 struct WORKREQ_HTTPSENDREQUESTW
*req
;
2157 workRequest
.asyncproc
= AsyncHttpSendRequestProc
;
2158 workRequest
.hdr
= WININET_AddRef( &lpwhr
->hdr
);
2159 req
= &workRequest
.u
.HttpSendRequestW
;
2162 if (lpBuffersIn
->lpcszHeader
)
2163 /* FIXME: this should use dwHeadersLength or may not be necessary at all */
2164 req
->lpszHeader
= WININET_strdupW(lpBuffersIn
->lpcszHeader
);
2166 req
->lpszHeader
= NULL
;
2167 req
->dwHeaderLength
= lpBuffersIn
->dwHeadersLength
;
2168 req
->lpOptional
= lpBuffersIn
->lpvBuffer
;
2169 req
->dwOptionalLength
= lpBuffersIn
->dwBufferLength
;
2170 req
->dwContentLength
= lpBuffersIn
->dwBufferTotal
;
2174 req
->lpszHeader
= NULL
;
2175 req
->dwHeaderLength
= 0;
2176 req
->lpOptional
= NULL
;
2177 req
->dwOptionalLength
= 0;
2178 req
->dwContentLength
= 0;
2181 req
->bEndRequest
= FALSE
;
2183 INTERNET_AsyncCall(&workRequest
);
2185 * This is from windows.
2187 INTERNET_SetLastError(ERROR_IO_PENDING
);
2192 ret
= HTTP_HttpSendRequestW(lpwhr
, lpBuffersIn
->lpcszHeader
, lpBuffersIn
->dwHeadersLength
,
2193 lpBuffersIn
->lpvBuffer
, lpBuffersIn
->dwBufferLength
,
2194 lpBuffersIn
->dwBufferTotal
, FALSE
);
2196 ret
= HTTP_HttpSendRequestW(lpwhr
, NULL
, 0, NULL
, 0, 0, FALSE
);
2201 WININET_Release( &lpwhr
->hdr
);
2207 /***********************************************************************
2208 * HttpSendRequestW (WININET.@)
2210 * Sends the specified request to the HTTP server
2217 BOOL WINAPI
HttpSendRequestW(HINTERNET hHttpRequest
, LPCWSTR lpszHeaders
,
2218 DWORD dwHeaderLength
, LPVOID lpOptional
,DWORD dwOptionalLength
)
2220 LPWININETHTTPREQW lpwhr
;
2221 LPWININETHTTPSESSIONW lpwhs
= NULL
;
2222 LPWININETAPPINFOW hIC
= NULL
;
2225 TRACE("%p, %s, %i, %p, %i)\n", hHttpRequest
,
2226 debugstr_wn(lpszHeaders
, dwHeaderLength
), dwHeaderLength
, lpOptional
, dwOptionalLength
);
2228 lpwhr
= (LPWININETHTTPREQW
) WININET_GetObject( hHttpRequest
);
2229 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
2231 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2236 lpwhs
= lpwhr
->lpHttpSession
;
2237 if (NULL
== lpwhs
|| lpwhs
->hdr
.htype
!= WH_HHTTPSESSION
)
2239 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2244 hIC
= lpwhs
->lpAppInfo
;
2245 if (NULL
== hIC
|| hIC
->hdr
.htype
!= WH_HINIT
)
2247 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2252 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
2254 WORKREQUEST workRequest
;
2255 struct WORKREQ_HTTPSENDREQUESTW
*req
;
2257 workRequest
.asyncproc
= AsyncHttpSendRequestProc
;
2258 workRequest
.hdr
= WININET_AddRef( &lpwhr
->hdr
);
2259 req
= &workRequest
.u
.HttpSendRequestW
;
2262 req
->lpszHeader
= HeapAlloc(GetProcessHeap(), 0, dwHeaderLength
* sizeof(WCHAR
));
2263 memcpy(req
->lpszHeader
, lpszHeaders
, dwHeaderLength
* sizeof(WCHAR
));
2266 req
->lpszHeader
= 0;
2267 req
->dwHeaderLength
= dwHeaderLength
;
2268 req
->lpOptional
= lpOptional
;
2269 req
->dwOptionalLength
= dwOptionalLength
;
2270 req
->dwContentLength
= dwOptionalLength
;
2271 req
->bEndRequest
= TRUE
;
2273 INTERNET_AsyncCall(&workRequest
);
2275 * This is from windows.
2277 INTERNET_SetLastError(ERROR_IO_PENDING
);
2282 r
= HTTP_HttpSendRequestW(lpwhr
, lpszHeaders
,
2283 dwHeaderLength
, lpOptional
, dwOptionalLength
,
2284 dwOptionalLength
, TRUE
);
2288 WININET_Release( &lpwhr
->hdr
);
2292 /***********************************************************************
2293 * HttpSendRequestA (WININET.@)
2295 * Sends the specified request to the HTTP server
2302 BOOL WINAPI
HttpSendRequestA(HINTERNET hHttpRequest
, LPCSTR lpszHeaders
,
2303 DWORD dwHeaderLength
, LPVOID lpOptional
,DWORD dwOptionalLength
)
2306 LPWSTR szHeaders
=NULL
;
2307 DWORD nLen
=dwHeaderLength
;
2308 if(lpszHeaders
!=NULL
)
2310 nLen
=MultiByteToWideChar(CP_ACP
,0,lpszHeaders
,dwHeaderLength
,NULL
,0);
2311 szHeaders
=HeapAlloc(GetProcessHeap(),0,nLen
*sizeof(WCHAR
));
2312 MultiByteToWideChar(CP_ACP
,0,lpszHeaders
,dwHeaderLength
,szHeaders
,nLen
);
2314 result
=HttpSendRequestW(hHttpRequest
, szHeaders
, nLen
, lpOptional
, dwOptionalLength
);
2315 HeapFree(GetProcessHeap(),0,szHeaders
);
2319 /***********************************************************************
2320 * HTTP_HandleRedirect (internal)
2322 static BOOL
HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszUrl
)
2324 LPWININETHTTPSESSIONW lpwhs
= lpwhr
->lpHttpSession
;
2325 LPWININETAPPINFOW hIC
= lpwhs
->lpAppInfo
;
2330 /* if it's an absolute path, keep the same session info */
2331 lstrcpynW(path
, lpszUrl
, 2048);
2333 else if (NULL
!= hIC
->lpszProxy
&& hIC
->lpszProxy
[0] != 0)
2335 TRACE("Redirect through proxy\n");
2336 lstrcpynW(path
, lpszUrl
, 2048);
2340 URL_COMPONENTSW urlComponents
;
2341 WCHAR protocol
[32], hostName
[MAXHOSTNAME
], userName
[1024];
2342 static WCHAR szHttp
[] = {'h','t','t','p',0};
2343 static WCHAR szHttps
[] = {'h','t','t','p','s',0};
2344 DWORD url_length
= 0;
2346 LPWSTR combined_url
;
2348 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2349 urlComponents
.lpszScheme
= (lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
) ? szHttps
: szHttp
;
2350 urlComponents
.dwSchemeLength
= 0;
2351 urlComponents
.lpszHostName
= lpwhs
->lpszHostName
;
2352 urlComponents
.dwHostNameLength
= 0;
2353 urlComponents
.nPort
= lpwhs
->nHostPort
;
2354 urlComponents
.lpszUserName
= lpwhs
->lpszUserName
;
2355 urlComponents
.dwUserNameLength
= 0;
2356 urlComponents
.lpszPassword
= NULL
;
2357 urlComponents
.dwPasswordLength
= 0;
2358 urlComponents
.lpszUrlPath
= lpwhr
->lpszPath
;
2359 urlComponents
.dwUrlPathLength
= 0;
2360 urlComponents
.lpszExtraInfo
= NULL
;
2361 urlComponents
.dwExtraInfoLength
= 0;
2363 if (!InternetCreateUrlW(&urlComponents
, 0, NULL
, &url_length
) &&
2364 (GetLastError() != ERROR_INSUFFICIENT_BUFFER
))
2367 orig_url
= HeapAlloc(GetProcessHeap(), 0, url_length
);
2369 /* convert from bytes to characters */
2370 url_length
= url_length
/ sizeof(WCHAR
) - 1;
2371 if (!InternetCreateUrlW(&urlComponents
, 0, orig_url
, &url_length
))
2373 HeapFree(GetProcessHeap(), 0, orig_url
);
2378 if (!InternetCombineUrlW(orig_url
, lpszUrl
, NULL
, &url_length
, ICU_ENCODE_SPACES_ONLY
) &&
2379 (GetLastError() != ERROR_INSUFFICIENT_BUFFER
))
2381 HeapFree(GetProcessHeap(), 0, orig_url
);
2384 combined_url
= HeapAlloc(GetProcessHeap(), 0, url_length
* sizeof(WCHAR
));
2386 if (!InternetCombineUrlW(orig_url
, lpszUrl
, combined_url
, &url_length
, ICU_ENCODE_SPACES_ONLY
))
2388 HeapFree(GetProcessHeap(), 0, orig_url
);
2389 HeapFree(GetProcessHeap(), 0, combined_url
);
2392 HeapFree(GetProcessHeap(), 0, orig_url
);
2398 urlComponents
.dwStructSize
= sizeof(URL_COMPONENTSW
);
2399 urlComponents
.lpszScheme
= protocol
;
2400 urlComponents
.dwSchemeLength
= 32;
2401 urlComponents
.lpszHostName
= hostName
;
2402 urlComponents
.dwHostNameLength
= MAXHOSTNAME
;
2403 urlComponents
.lpszUserName
= userName
;
2404 urlComponents
.dwUserNameLength
= 1024;
2405 urlComponents
.lpszPassword
= NULL
;
2406 urlComponents
.dwPasswordLength
= 0;
2407 urlComponents
.lpszUrlPath
= path
;
2408 urlComponents
.dwUrlPathLength
= 2048;
2409 urlComponents
.lpszExtraInfo
= NULL
;
2410 urlComponents
.dwExtraInfoLength
= 0;
2411 if(!InternetCrackUrlW(combined_url
, strlenW(combined_url
), 0, &urlComponents
))
2413 HeapFree(GetProcessHeap(), 0, combined_url
);
2416 HeapFree(GetProcessHeap(), 0, combined_url
);
2418 if (!strncmpW(szHttp
, urlComponents
.lpszScheme
, strlenW(szHttp
)) &&
2419 (lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
))
2421 TRACE("redirect from secure page to non-secure page\n");
2422 /* FIXME: warn about from secure redirect to non-secure page */
2423 lpwhr
->hdr
.dwFlags
&= ~INTERNET_FLAG_SECURE
;
2425 if (!strncmpW(szHttps
, urlComponents
.lpszScheme
, strlenW(szHttps
)) &&
2426 !(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
))
2428 TRACE("redirect from non-secure page to secure page\n");
2429 /* FIXME: notify about redirect to secure page */
2430 lpwhr
->hdr
.dwFlags
|= INTERNET_FLAG_SECURE
;
2433 if (urlComponents
.nPort
== INTERNET_INVALID_PORT_NUMBER
)
2435 if (lstrlenW(protocol
)>4) /*https*/
2436 urlComponents
.nPort
= INTERNET_DEFAULT_HTTPS_PORT
;
2438 urlComponents
.nPort
= INTERNET_DEFAULT_HTTP_PORT
;
2443 * This upsets redirects to binary files on sourceforge.net
2444 * and gives an html page instead of the target file
2445 * Examination of the HTTP request sent by native wininet.dll
2446 * reveals that it doesn't send a referrer in that case.
2447 * Maybe there's a flag that enables this, or maybe a referrer
2448 * shouldn't be added in case of a redirect.
2451 /* consider the current host as the referrer */
2452 if (NULL
!= lpwhs
->lpszServerName
&& strlenW(lpwhs
->lpszServerName
))
2453 HTTP_ProcessHeader(lpwhr
, HTTP_REFERER
, lpwhs
->lpszServerName
,
2454 HTTP_ADDHDR_FLAG_REQ
|HTTP_ADDREQ_FLAG_REPLACE
|
2455 HTTP_ADDHDR_FLAG_ADD_IF_NEW
);
2458 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszServerName
);
2459 lpwhs
->lpszServerName
= WININET_strdupW(hostName
);
2460 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszHostName
);
2461 if (urlComponents
.nPort
!= INTERNET_DEFAULT_HTTP_PORT
&&
2462 urlComponents
.nPort
!= INTERNET_DEFAULT_HTTPS_PORT
)
2465 static const WCHAR fmt
[] = {'%','s',':','%','i',0};
2466 len
= lstrlenW(hostName
);
2467 len
+= 7; /* 5 for strlen("65535") + 1 for ":" + 1 for '\0' */
2468 lpwhs
->lpszHostName
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
2469 sprintfW(lpwhs
->lpszHostName
, fmt
, hostName
, urlComponents
.nPort
);
2472 lpwhs
->lpszHostName
= WININET_strdupW(hostName
);
2474 HTTP_ProcessHeader(lpwhr
, szHost
, lpwhs
->lpszHostName
, HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDHDR_FLAG_REQ
);
2477 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszUserName
);
2478 lpwhs
->lpszUserName
= NULL
;
2480 lpwhs
->lpszUserName
= WININET_strdupW(userName
);
2481 lpwhs
->nServerPort
= urlComponents
.nPort
;
2483 if (!HTTP_ResolveName(lpwhr
))
2486 NETCON_close(&lpwhr
->netConnection
);
2488 if (!NETCON_init(&lpwhr
->netConnection
,lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
))
2492 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszPath
);
2493 lpwhr
->lpszPath
=NULL
;
2499 rc
= UrlEscapeW(path
, NULL
, &needed
, URL_ESCAPE_SPACES_ONLY
);
2500 if (rc
!= E_POINTER
)
2501 needed
= strlenW(path
)+1;
2502 lpwhr
->lpszPath
= HeapAlloc(GetProcessHeap(), 0, needed
*sizeof(WCHAR
));
2503 rc
= UrlEscapeW(path
, lpwhr
->lpszPath
, &needed
,
2504 URL_ESCAPE_SPACES_ONLY
);
2507 ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(path
),rc
);
2508 strcpyW(lpwhr
->lpszPath
,path
);
2515 /***********************************************************************
2516 * HTTP_build_req (internal)
2518 * concatenate all the strings in the request together
2520 static LPWSTR
HTTP_build_req( LPCWSTR
*list
, int len
)
2525 for( t
= list
; *t
; t
++ )
2526 len
+= strlenW( *t
);
2529 str
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2532 for( t
= list
; *t
; t
++ )
2538 static BOOL
HTTP_SecureProxyConnect(LPWININETHTTPREQW lpwhr
)
2541 LPWSTR requestString
;
2547 static const WCHAR szConnect
[] = {'C','O','N','N','E','C','T',0};
2548 static const WCHAR szFormat
[] = {'%','s',':','%','d',0};
2549 LPWININETHTTPSESSIONW lpwhs
= lpwhr
->lpHttpSession
;
2553 lpszPath
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW( lpwhs
->lpszHostName
) + 13)*sizeof(WCHAR
) );
2554 sprintfW( lpszPath
, szFormat
, lpwhs
->lpszHostName
, lpwhs
->nHostPort
);
2555 requestString
= HTTP_BuildHeaderRequestString( lpwhr
, szConnect
, lpszPath
, FALSE
);
2556 HeapFree( GetProcessHeap(), 0, lpszPath
);
2558 len
= WideCharToMultiByte( CP_ACP
, 0, requestString
, -1,
2559 NULL
, 0, NULL
, NULL
);
2560 len
--; /* the nul terminator isn't needed */
2561 ascii_req
= HeapAlloc( GetProcessHeap(), 0, len
);
2562 WideCharToMultiByte( CP_ACP
, 0, requestString
, -1,
2563 ascii_req
, len
, NULL
, NULL
);
2564 HeapFree( GetProcessHeap(), 0, requestString
);
2566 TRACE("full request -> %s\n", debugstr_an( ascii_req
, len
) );
2568 ret
= NETCON_send( &lpwhr
->netConnection
, ascii_req
, len
, 0, &cnt
);
2569 HeapFree( GetProcessHeap(), 0, ascii_req
);
2570 if (!ret
|| cnt
< 0)
2573 responseLen
= HTTP_GetResponseHeaders( lpwhr
);
2580 /***********************************************************************
2581 * HTTP_HttpSendRequestW (internal)
2583 * Sends the specified request to the HTTP server
2590 BOOL WINAPI
HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszHeaders
,
2591 DWORD dwHeaderLength
, LPVOID lpOptional
, DWORD dwOptionalLength
,
2592 DWORD dwContentLength
, BOOL bEndRequest
)
2595 BOOL bSuccess
= FALSE
;
2596 LPWSTR requestString
= NULL
;
2599 INTERNET_ASYNC_RESULT iar
;
2600 static const WCHAR szClose
[] = { 'C','l','o','s','e',0 };
2601 static const WCHAR szContentLength
[] =
2602 { 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','l','i','\r','\n',0 };
2603 WCHAR contentLengthStr
[sizeof szContentLength
/2 /* includes \r\n */ + 20 /* int */ ];
2605 TRACE("--> %p\n", lpwhr
);
2607 assert(lpwhr
->hdr
.htype
== WH_HHTTPREQ
);
2609 /* Clear any error information */
2610 INTERNET_SetLastError(0);
2612 HTTP_FixVerb(lpwhr
);
2614 sprintfW(contentLengthStr
, szContentLength
, dwContentLength
);
2615 HTTP_HttpAddRequestHeadersW(lpwhr
, contentLengthStr
, -1L, HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDHDR_FLAG_REPLACE
);
2624 /* like native, just in case the caller forgot to call InternetReadFile
2625 * for all the data */
2626 HTTP_DrainContent(lpwhr
);
2627 lpwhr
->dwContentRead
= 0;
2629 if (TRACE_ON(wininet
))
2631 LPHTTPHEADERW Host
= HTTP_GetHeader(lpwhr
,szHost
);
2632 TRACE("Going to url %s %s\n", debugstr_w(Host
->lpszValue
), debugstr_w(lpwhr
->lpszPath
));
2636 HTTP_ProcessHeader(lpwhr
, szConnection
,
2637 lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_KEEP_CONNECTION
? szKeepAlive
: szClose
,
2638 HTTP_ADDHDR_FLAG_REQ
| HTTP_ADDHDR_FLAG_REPLACE
);
2640 HTTP_InsertAuthorization(lpwhr
);
2641 HTTP_InsertProxyAuthorization(lpwhr
);
2643 /* add the headers the caller supplied */
2644 if( lpszHeaders
&& dwHeaderLength
)
2646 HTTP_HttpAddRequestHeadersW(lpwhr
, lpszHeaders
, dwHeaderLength
,
2647 HTTP_ADDREQ_FLAG_ADD
| HTTP_ADDHDR_FLAG_REPLACE
);
2650 requestString
= HTTP_BuildHeaderRequestString(lpwhr
, lpwhr
->lpszVerb
, lpwhr
->lpszPath
, FALSE
);
2652 TRACE("Request header -> %s\n", debugstr_w(requestString
) );
2654 /* Send the request and store the results */
2655 if (!HTTP_OpenConnection(lpwhr
))
2658 /* send the request as ASCII, tack on the optional data */
2660 dwOptionalLength
= 0;
2661 len
= WideCharToMultiByte( CP_ACP
, 0, requestString
, -1,
2662 NULL
, 0, NULL
, NULL
);
2663 ascii_req
= HeapAlloc( GetProcessHeap(), 0, len
+ dwOptionalLength
);
2664 WideCharToMultiByte( CP_ACP
, 0, requestString
, -1,
2665 ascii_req
, len
, NULL
, NULL
);
2667 memcpy( &ascii_req
[len
-1], lpOptional
, dwOptionalLength
);
2668 len
= (len
+ dwOptionalLength
- 1);
2670 TRACE("full request -> %s\n", debugstr_a(ascii_req
) );
2672 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2673 INTERNET_STATUS_SENDING_REQUEST
, NULL
, 0);
2675 NETCON_send(&lpwhr
->netConnection
, ascii_req
, len
, 0, &cnt
);
2676 HeapFree( GetProcessHeap(), 0, ascii_req
);
2678 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2679 INTERNET_STATUS_REQUEST_SENT
,
2680 &len
, sizeof(DWORD
));
2687 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2688 INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
2693 responseLen
= HTTP_GetResponseHeaders(lpwhr
);
2697 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2698 INTERNET_STATUS_RESPONSE_RECEIVED
, &responseLen
,
2701 HTTP_ProcessHeaders(lpwhr
);
2703 dwBufferSize
= sizeof(lpwhr
->dwContentLength
);
2704 if (!HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
,
2705 &lpwhr
->dwContentLength
,&dwBufferSize
,NULL
))
2706 lpwhr
->dwContentLength
= -1;
2708 if (lpwhr
->dwContentLength
== 0)
2709 HTTP_FinishedReading(lpwhr
);
2711 dwBufferSize
= sizeof(dwStatusCode
);
2712 if (!HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_STATUS_CODE
,
2713 &dwStatusCode
,&dwBufferSize
,NULL
))
2716 if (!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_AUTO_REDIRECT
) && bSuccess
)
2718 WCHAR szNewLocation
[2048];
2719 dwBufferSize
=sizeof(szNewLocation
);
2720 if ((dwStatusCode
==HTTP_STATUS_REDIRECT
|| dwStatusCode
==HTTP_STATUS_MOVED
) &&
2721 HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_LOCATION
,szNewLocation
,&dwBufferSize
,NULL
))
2723 HTTP_DrainContent(lpwhr
);
2724 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2725 INTERNET_STATUS_REDIRECT
, szNewLocation
,
2727 bSuccess
= HTTP_HandleRedirect(lpwhr
, szNewLocation
);
2730 HeapFree(GetProcessHeap(), 0, requestString
);
2735 if (!(lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_NO_AUTH
) && bSuccess
)
2737 WCHAR szAuthValue
[2048];
2739 if (dwStatusCode
== HTTP_STATUS_DENIED
)
2742 while (HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_WWW_AUTHENTICATE
,szAuthValue
,&dwBufferSize
,&dwIndex
))
2744 if (HTTP_DoAuthorization(lpwhr
, szAuthValue
,
2746 lpwhr
->lpHttpSession
->lpszUserName
,
2747 lpwhr
->lpHttpSession
->lpszPassword
))
2754 if (dwStatusCode
== HTTP_STATUS_PROXY_AUTH_REQ
)
2757 while (HTTP_HttpQueryInfoW(lpwhr
,HTTP_QUERY_PROXY_AUTHENTICATE
,szAuthValue
,&dwBufferSize
,&dwIndex
))
2759 if (HTTP_DoAuthorization(lpwhr
, szAuthValue
,
2760 &lpwhr
->pProxyAuthInfo
,
2761 lpwhr
->lpHttpSession
->lpAppInfo
->lpszProxyUsername
,
2762 lpwhr
->lpHttpSession
->lpAppInfo
->lpszProxyPassword
))
2778 HeapFree(GetProcessHeap(), 0, requestString
);
2780 /* TODO: send notification for P3P header */
2782 iar
.dwResult
= (DWORD
)bSuccess
;
2783 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: INTERNET_GetLastError();
2785 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2786 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
2787 sizeof(INTERNET_ASYNC_RESULT
));
2793 /***********************************************************************
2794 * HTTP_Connect (internal)
2796 * Create http session handle
2799 * HINTERNET a session handle on success
2803 HINTERNET
HTTP_Connect(LPWININETAPPINFOW hIC
, LPCWSTR lpszServerName
,
2804 INTERNET_PORT nServerPort
, LPCWSTR lpszUserName
,
2805 LPCWSTR lpszPassword
, DWORD dwFlags
, DWORD_PTR dwContext
,
2806 DWORD dwInternalFlags
)
2808 BOOL bSuccess
= FALSE
;
2809 LPWININETHTTPSESSIONW lpwhs
= NULL
;
2810 HINTERNET handle
= NULL
;
2814 assert( hIC
->hdr
.htype
== WH_HINIT
);
2816 lpwhs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WININETHTTPSESSIONW
));
2819 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2824 * According to my tests. The name is not resolved until a request is sent
2827 lpwhs
->hdr
.htype
= WH_HHTTPSESSION
;
2828 lpwhs
->hdr
.dwFlags
= dwFlags
;
2829 lpwhs
->hdr
.dwContext
= dwContext
;
2830 lpwhs
->hdr
.dwInternalFlags
= dwInternalFlags
| (hIC
->hdr
.dwInternalFlags
& INET_CALLBACKW
);
2831 lpwhs
->hdr
.dwRefCount
= 1;
2832 lpwhs
->hdr
.close_connection
= NULL
;
2833 lpwhs
->hdr
.destroy
= HTTP_CloseHTTPSessionHandle
;
2834 lpwhs
->hdr
.lpfnStatusCB
= hIC
->hdr
.lpfnStatusCB
;
2836 WININET_AddRef( &hIC
->hdr
);
2837 lpwhs
->lpAppInfo
= hIC
;
2838 list_add_head( &hIC
->hdr
.children
, &lpwhs
->hdr
.entry
);
2840 handle
= WININET_AllocHandle( &lpwhs
->hdr
);
2843 ERR("Failed to alloc handle\n");
2844 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2848 if(hIC
->lpszProxy
&& hIC
->dwAccessType
== INTERNET_OPEN_TYPE_PROXY
) {
2849 if(strchrW(hIC
->lpszProxy
, ' '))
2850 FIXME("Several proxies not implemented.\n");
2851 if(hIC
->lpszProxyBypass
)
2852 FIXME("Proxy bypass is ignored.\n");
2854 if (lpszServerName
&& lpszServerName
[0])
2856 lpwhs
->lpszServerName
= WININET_strdupW(lpszServerName
);
2857 lpwhs
->lpszHostName
= WININET_strdupW(lpszServerName
);
2859 if (lpszUserName
&& lpszUserName
[0])
2860 lpwhs
->lpszUserName
= WININET_strdupW(lpszUserName
);
2861 if (lpszPassword
&& lpszPassword
[0])
2862 lpwhs
->lpszPassword
= WININET_strdupW(lpszPassword
);
2863 lpwhs
->nServerPort
= nServerPort
;
2864 lpwhs
->nHostPort
= nServerPort
;
2866 /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
2867 if (!(lpwhs
->hdr
.dwInternalFlags
& INET_OPENURL
))
2869 INTERNET_SendCallback(&hIC
->hdr
, dwContext
,
2870 INTERNET_STATUS_HANDLE_CREATED
, &handle
,
2878 WININET_Release( &lpwhs
->hdr
);
2881 * an INTERNET_STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on
2885 TRACE("%p --> %p (%p)\n", hIC
, handle
, lpwhs
);
2890 /***********************************************************************
2891 * HTTP_OpenConnection (internal)
2893 * Connect to a web server
2900 static BOOL
HTTP_OpenConnection(LPWININETHTTPREQW lpwhr
)
2902 BOOL bSuccess
= FALSE
;
2903 LPWININETHTTPSESSIONW lpwhs
;
2904 LPWININETAPPINFOW hIC
= NULL
;
2910 if (NULL
== lpwhr
|| lpwhr
->hdr
.htype
!= WH_HHTTPREQ
)
2912 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2916 if (NETCON_connected(&lpwhr
->netConnection
))
2922 lpwhs
= lpwhr
->lpHttpSession
;
2924 hIC
= lpwhs
->lpAppInfo
;
2925 inet_ntop(lpwhs
->socketAddress
.sin_family
, &lpwhs
->socketAddress
.sin_addr
,
2926 szaddr
, sizeof(szaddr
));
2927 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2928 INTERNET_STATUS_CONNECTING_TO_SERVER
,
2932 if (!NETCON_create(&lpwhr
->netConnection
, lpwhs
->socketAddress
.sin_family
,
2935 WARN("Socket creation failed\n");
2939 if (!NETCON_connect(&lpwhr
->netConnection
, (struct sockaddr
*)&lpwhs
->socketAddress
,
2940 sizeof(lpwhs
->socketAddress
)))
2943 if (lpwhr
->hdr
.dwFlags
& INTERNET_FLAG_SECURE
)
2945 /* Note: we differ from Microsoft's WinINet here. they seem to have
2946 * a bug that causes no status callbacks to be sent when starting
2947 * a tunnel to a proxy server using the CONNECT verb. i believe our
2948 * behaviour to be more correct and to not cause any incompatibilities
2949 * because using a secure connection through a proxy server is a rare
2950 * case that would be hard for anyone to depend on */
2951 if (hIC
->lpszProxy
&& !HTTP_SecureProxyConnect(lpwhr
))
2954 if (!NETCON_secure_connect(&lpwhr
->netConnection
, lpwhs
->lpszHostName
))
2956 WARN("Couldn't connect securely to host\n");
2961 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
2962 INTERNET_STATUS_CONNECTED_TO_SERVER
,
2963 szaddr
, strlen(szaddr
)+1);
2968 TRACE("%d <--\n", bSuccess
);
2973 /***********************************************************************
2974 * HTTP_clear_response_headers (internal)
2976 * clear out any old response headers
2978 static void HTTP_clear_response_headers( LPWININETHTTPREQW lpwhr
)
2982 for( i
=0; i
<lpwhr
->nCustHeaders
; i
++)
2984 if( !lpwhr
->pCustHeaders
[i
].lpszField
)
2986 if( !lpwhr
->pCustHeaders
[i
].lpszValue
)
2988 if ( lpwhr
->pCustHeaders
[i
].wFlags
& HDR_ISREQUEST
)
2990 HTTP_DeleteCustomHeader( lpwhr
, i
);
2995 /***********************************************************************
2996 * HTTP_GetResponseHeaders (internal)
2998 * Read server response
3005 static INT
HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr
)
3008 WCHAR buffer
[MAX_REPLY_LEN
];
3009 DWORD buflen
= MAX_REPLY_LEN
;
3010 BOOL bSuccess
= FALSE
;
3012 static const WCHAR szCrLf
[] = {'\r','\n',0};
3013 char bufferA
[MAX_REPLY_LEN
];
3014 LPWSTR status_code
, status_text
;
3015 DWORD cchMaxRawHeaders
= 1024;
3016 LPWSTR lpszRawHeaders
= HeapAlloc(GetProcessHeap(), 0, (cchMaxRawHeaders
+1)*sizeof(WCHAR
));
3017 DWORD cchRawHeaders
= 0;
3021 /* clear old response headers (eg. from a redirect response) */
3022 HTTP_clear_response_headers( lpwhr
);
3024 if (!NETCON_connected(&lpwhr
->netConnection
))
3028 * HACK peek at the buffer
3031 /* This is Wine code, we don't support MSG_PEEK yet so we have to do it
3033 NETCON_recv(&lpwhr
->netConnection
, buffer
, buflen
, MSG_PEEK
, &rc
);
3036 * We should first receive 'HTTP/1.x nnn OK' where nnn is the status code.
3038 buflen
= MAX_REPLY_LEN
;
3039 memset(buffer
, 0, MAX_REPLY_LEN
);
3040 if (!NETCON_getNextLine(&lpwhr
->netConnection
, bufferA
, &buflen
))
3045 MultiByteToWideChar( CP_ACP
, 0, bufferA
, buflen
, buffer
, MAX_REPLY_LEN
);
3047 /* regenerate raw headers */
3048 while (cchRawHeaders
+ buflen
+ strlenW(szCrLf
) > cchMaxRawHeaders
)
3050 cchMaxRawHeaders
*= 2;
3051 lpszRawHeaders
= HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders
, (cchMaxRawHeaders
+1)*sizeof(WCHAR
));
3053 memcpy(lpszRawHeaders
+cchRawHeaders
, buffer
, (buflen
-1)*sizeof(WCHAR
));
3054 cchRawHeaders
+= (buflen
-1);
3055 memcpy(lpszRawHeaders
+cchRawHeaders
, szCrLf
, sizeof(szCrLf
));
3056 cchRawHeaders
+= sizeof(szCrLf
)/sizeof(szCrLf
[0])-1;
3057 lpszRawHeaders
[cchRawHeaders
] = '\0';
3059 /* split the version from the status code */
3060 status_code
= strchrW( buffer
, ' ' );
3065 /* split the status code from the status text */
3066 status_text
= strchrW( status_code
, ' ' );
3071 TRACE("version [%s] status code [%s] status text [%s]\n",
3072 debugstr_w(buffer
), debugstr_w(status_code
), debugstr_w(status_text
) );
3074 HTTP_ProcessHeader(lpwhr
, szStatus
, status_code
,
3075 HTTP_ADDHDR_FLAG_REPLACE
);
3077 HeapFree(GetProcessHeap(),0,lpwhr
->lpszVersion
);
3078 HeapFree(GetProcessHeap(),0,lpwhr
->lpszStatusText
);
3080 lpwhr
->lpszVersion
= WININET_strdupW(buffer
);
3081 lpwhr
->lpszStatusText
= WININET_strdupW(status_text
);
3083 /* Parse each response line */
3086 buflen
= MAX_REPLY_LEN
;
3087 if (NETCON_getNextLine(&lpwhr
->netConnection
, bufferA
, &buflen
))
3089 LPWSTR
* pFieldAndValue
;
3091 TRACE("got line %s, now interpreting\n", debugstr_a(bufferA
));
3092 MultiByteToWideChar( CP_ACP
, 0, bufferA
, buflen
, buffer
, MAX_REPLY_LEN
);
3094 while (cchRawHeaders
+ buflen
+ strlenW(szCrLf
) > cchMaxRawHeaders
)
3096 cchMaxRawHeaders
*= 2;
3097 lpszRawHeaders
= HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders
, (cchMaxRawHeaders
+1)*sizeof(WCHAR
));
3099 memcpy(lpszRawHeaders
+cchRawHeaders
, buffer
, (buflen
-1)*sizeof(WCHAR
));
3100 cchRawHeaders
+= (buflen
-1);
3101 memcpy(lpszRawHeaders
+cchRawHeaders
, szCrLf
, sizeof(szCrLf
));
3102 cchRawHeaders
+= sizeof(szCrLf
)/sizeof(szCrLf
[0])-1;
3103 lpszRawHeaders
[cchRawHeaders
] = '\0';
3105 pFieldAndValue
= HTTP_InterpretHttpHeader(buffer
);
3106 if (!pFieldAndValue
)
3109 HTTP_ProcessHeader(lpwhr
, pFieldAndValue
[0], pFieldAndValue
[1],
3110 HTTP_ADDREQ_FLAG_ADD
);
3112 HTTP_FreeTokens(pFieldAndValue
);
3122 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszRawHeaders
);
3123 lpwhr
->lpszRawHeaders
= lpszRawHeaders
;
3124 TRACE("raw headers: %s\n", debugstr_w(lpszRawHeaders
));
3137 static void strip_spaces(LPWSTR start
)
3142 while (*str
== ' ' && *str
!= '\0')
3146 memmove(start
, str
, sizeof(WCHAR
) * (strlenW(str
) + 1));
3148 end
= start
+ strlenW(start
) - 1;
3149 while (end
>= start
&& *end
== ' ')
3157 /***********************************************************************
3158 * HTTP_InterpretHttpHeader (internal)
3160 * Parse server response
3164 * Pointer to array of field, value, NULL on success.
3167 static LPWSTR
* HTTP_InterpretHttpHeader(LPCWSTR buffer
)
3169 LPWSTR
* pTokenPair
;
3173 pTokenPair
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*pTokenPair
)*3);
3175 pszColon
= strchrW(buffer
, ':');
3176 /* must have two tokens */
3179 HTTP_FreeTokens(pTokenPair
);
3181 TRACE("No ':' in line: %s\n", debugstr_w(buffer
));
3185 pTokenPair
[0] = HeapAlloc(GetProcessHeap(), 0, (pszColon
- buffer
+ 1) * sizeof(WCHAR
));
3188 HTTP_FreeTokens(pTokenPair
);
3191 memcpy(pTokenPair
[0], buffer
, (pszColon
- buffer
) * sizeof(WCHAR
));
3192 pTokenPair
[0][pszColon
- buffer
] = '\0';
3196 len
= strlenW(pszColon
);
3197 pTokenPair
[1] = HeapAlloc(GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
));
3200 HTTP_FreeTokens(pTokenPair
);
3203 memcpy(pTokenPair
[1], pszColon
, (len
+ 1) * sizeof(WCHAR
));
3205 strip_spaces(pTokenPair
[0]);
3206 strip_spaces(pTokenPair
[1]);
3208 TRACE("field(%s) Value(%s)\n", debugstr_w(pTokenPair
[0]), debugstr_w(pTokenPair
[1]));
3212 /***********************************************************************
3213 * HTTP_ProcessHeader (internal)
3215 * Stuff header into header tables according to <dwModifier>
3219 #define COALESCEFLAGS (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON)
3221 static BOOL
HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr
, LPCWSTR field
, LPCWSTR value
, DWORD dwModifier
)
3223 LPHTTPHEADERW lphttpHdr
= NULL
;
3224 BOOL bSuccess
= FALSE
;
3226 BOOL request_only
= dwModifier
& HTTP_ADDHDR_FLAG_REQ
;
3228 TRACE("--> %s: %s - 0x%08x\n", debugstr_w(field
), debugstr_w(value
), dwModifier
);
3230 /* REPLACE wins out over ADD */
3231 if (dwModifier
& HTTP_ADDHDR_FLAG_REPLACE
)
3232 dwModifier
&= ~HTTP_ADDHDR_FLAG_ADD
;
3234 if (dwModifier
& HTTP_ADDHDR_FLAG_ADD
)
3237 index
= HTTP_GetCustomHeaderIndex(lpwhr
, field
, 0, request_only
);
3241 if (dwModifier
& HTTP_ADDHDR_FLAG_ADD_IF_NEW
)
3245 lphttpHdr
= &lpwhr
->pCustHeaders
[index
];
3251 hdr
.lpszField
= (LPWSTR
)field
;
3252 hdr
.lpszValue
= (LPWSTR
)value
;
3253 hdr
.wFlags
= hdr
.wCount
= 0;
3255 if (dwModifier
& HTTP_ADDHDR_FLAG_REQ
)
3256 hdr
.wFlags
|= HDR_ISREQUEST
;
3258 return HTTP_InsertCustomHeader(lpwhr
, &hdr
);
3260 /* no value to delete */
3263 if (dwModifier
& HTTP_ADDHDR_FLAG_REQ
)
3264 lphttpHdr
->wFlags
|= HDR_ISREQUEST
;
3266 lphttpHdr
->wFlags
&= ~HDR_ISREQUEST
;
3268 if (dwModifier
& HTTP_ADDHDR_FLAG_REPLACE
)
3270 HTTP_DeleteCustomHeader( lpwhr
, index
);
3276 hdr
.lpszField
= (LPWSTR
)field
;
3277 hdr
.lpszValue
= (LPWSTR
)value
;
3278 hdr
.wFlags
= hdr
.wCount
= 0;
3280 if (dwModifier
& HTTP_ADDHDR_FLAG_REQ
)
3281 hdr
.wFlags
|= HDR_ISREQUEST
;
3283 return HTTP_InsertCustomHeader(lpwhr
, &hdr
);
3288 else if (dwModifier
& COALESCEFLAGS
)
3293 INT origlen
= strlenW(lphttpHdr
->lpszValue
);
3294 INT valuelen
= strlenW(value
);
3296 if (dwModifier
& HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA
)
3299 lphttpHdr
->wFlags
|= HDR_COMMADELIMITED
;
3301 else if (dwModifier
& HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON
)
3304 lphttpHdr
->wFlags
|= HDR_COMMADELIMITED
;
3307 len
= origlen
+ valuelen
+ ((ch
> 0) ? 2 : 0);
3309 lpsztmp
= HeapReAlloc(GetProcessHeap(), 0, lphttpHdr
->lpszValue
, (len
+1)*sizeof(WCHAR
));
3312 lphttpHdr
->lpszValue
= lpsztmp
;
3313 /* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */
3316 lphttpHdr
->lpszValue
[origlen
] = ch
;
3318 lphttpHdr
->lpszValue
[origlen
] = ' ';
3322 memcpy(&lphttpHdr
->lpszValue
[origlen
], value
, valuelen
*sizeof(WCHAR
));
3323 lphttpHdr
->lpszValue
[len
] = '\0';
3328 WARN("HeapReAlloc (%d bytes) failed\n",len
+1);
3329 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
3332 TRACE("<-- %d\n",bSuccess
);
3337 /***********************************************************************
3338 * HTTP_CloseConnection (internal)
3340 * Close socket connection
3343 static void HTTP_CloseConnection(LPWININETHANDLEHEADER hdr
)
3345 LPWININETHTTPREQW lpwhr
= (LPWININETHTTPREQW
) hdr
;
3346 LPWININETHTTPSESSIONW lpwhs
= NULL
;
3347 LPWININETAPPINFOW hIC
= NULL
;
3349 TRACE("%p\n",lpwhr
);
3351 if (!NETCON_connected(&lpwhr
->netConnection
))
3354 if (lpwhr
->pAuthInfo
)
3356 DeleteSecurityContext(&lpwhr
->pAuthInfo
->ctx
);
3357 FreeCredentialsHandle(&lpwhr
->pAuthInfo
->cred
);
3359 HeapFree(GetProcessHeap(), 0, lpwhr
->pAuthInfo
->auth_data
);
3360 HeapFree(GetProcessHeap(), 0, lpwhr
->pAuthInfo
->scheme
);
3361 HeapFree(GetProcessHeap(), 0, lpwhr
->pAuthInfo
);
3362 lpwhr
->pAuthInfo
= NULL
;
3364 if (lpwhr
->pProxyAuthInfo
)
3366 DeleteSecurityContext(&lpwhr
->pProxyAuthInfo
->ctx
);
3367 FreeCredentialsHandle(&lpwhr
->pProxyAuthInfo
->cred
);
3369 HeapFree(GetProcessHeap(), 0, lpwhr
->pProxyAuthInfo
->auth_data
);
3370 HeapFree(GetProcessHeap(), 0, lpwhr
->pProxyAuthInfo
->scheme
);
3371 HeapFree(GetProcessHeap(), 0, lpwhr
->pProxyAuthInfo
);
3372 lpwhr
->pProxyAuthInfo
= NULL
;
3375 lpwhs
= lpwhr
->lpHttpSession
;
3376 hIC
= lpwhs
->lpAppInfo
;
3378 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
3379 INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0);
3381 NETCON_close(&lpwhr
->netConnection
);
3383 INTERNET_SendCallback(&lpwhr
->hdr
, lpwhr
->hdr
.dwContext
,
3384 INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0);
3388 /***********************************************************************
3389 * HTTP_FinishedReading (internal)
3391 * Called when all content from server has been read by client.
3394 BOOL
HTTP_FinishedReading(LPWININETHTTPREQW lpwhr
)
3396 WCHAR szConnectionResponse
[20];
3397 DWORD dwBufferSize
= sizeof(szConnectionResponse
);
3401 if (!HTTP_HttpQueryInfoW(lpwhr
, HTTP_QUERY_CONNECTION
, szConnectionResponse
,
3402 &dwBufferSize
, NULL
) ||
3403 strcmpiW(szConnectionResponse
, szKeepAlive
))
3405 HTTP_CloseConnection(&lpwhr
->hdr
);
3408 /* FIXME: store data in the URL cache here */
3413 /***********************************************************************
3414 * HTTP_CloseHTTPRequestHandle (internal)
3416 * Deallocate request handle
3419 static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr
)
3422 LPWININETHTTPREQW lpwhr
= (LPWININETHTTPREQW
) hdr
;
3426 WININET_Release(&lpwhr
->lpHttpSession
->hdr
);
3428 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszPath
);
3429 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszVerb
);
3430 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszRawHeaders
);
3431 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszVersion
);
3432 HeapFree(GetProcessHeap(), 0, lpwhr
->lpszStatusText
);
3434 for (i
= 0; i
< lpwhr
->nCustHeaders
; i
++)
3436 HeapFree(GetProcessHeap(), 0, lpwhr
->pCustHeaders
[i
].lpszField
);
3437 HeapFree(GetProcessHeap(), 0, lpwhr
->pCustHeaders
[i
].lpszValue
);
3440 HeapFree(GetProcessHeap(), 0, lpwhr
->pCustHeaders
);
3441 HeapFree(GetProcessHeap(), 0, lpwhr
);
3445 /***********************************************************************
3446 * HTTP_CloseHTTPSessionHandle (internal)
3448 * Deallocate session handle
3451 static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr
)
3453 LPWININETHTTPSESSIONW lpwhs
= (LPWININETHTTPSESSIONW
) hdr
;
3455 TRACE("%p\n", lpwhs
);
3457 WININET_Release(&lpwhs
->lpAppInfo
->hdr
);
3459 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszHostName
);
3460 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszServerName
);
3461 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszPassword
);
3462 HeapFree(GetProcessHeap(), 0, lpwhs
->lpszUserName
);
3463 HeapFree(GetProcessHeap(), 0, lpwhs
);
3467 /***********************************************************************
3468 * HTTP_GetCustomHeaderIndex (internal)
3470 * Return index of custom header from header array
3473 static INT
HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr
, LPCWSTR lpszField
,
3474 int requested_index
, BOOL request_only
)
3478 TRACE("%s\n", debugstr_w(lpszField
));
3480 for (index
= 0; index
< lpwhr
->nCustHeaders
; index
++)
3482 if (strcmpiW(lpwhr
->pCustHeaders
[index
].lpszField
, lpszField
))
3485 if (request_only
&& !(lpwhr
->pCustHeaders
[index
].wFlags
& HDR_ISREQUEST
))
3488 if (!request_only
&& (lpwhr
->pCustHeaders
[index
].wFlags
& HDR_ISREQUEST
))
3491 if (requested_index
== 0)
3496 if (index
>= lpwhr
->nCustHeaders
)
3499 TRACE("Return: %d\n", index
);
3504 /***********************************************************************
3505 * HTTP_InsertCustomHeader (internal)
3507 * Insert header into array
3510 static BOOL
HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr
, LPHTTPHEADERW lpHdr
)
3513 LPHTTPHEADERW lph
= NULL
;
3516 TRACE("--> %s: %s\n", debugstr_w(lpHdr
->lpszField
), debugstr_w(lpHdr
->lpszValue
));
3517 count
= lpwhr
->nCustHeaders
+ 1;
3519 lph
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, lpwhr
->pCustHeaders
, sizeof(HTTPHEADERW
) * count
);
3521 lph
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HTTPHEADERW
) * count
);
3525 lpwhr
->pCustHeaders
= lph
;
3526 lpwhr
->pCustHeaders
[count
-1].lpszField
= WININET_strdupW(lpHdr
->lpszField
);
3527 lpwhr
->pCustHeaders
[count
-1].lpszValue
= WININET_strdupW(lpHdr
->lpszValue
);
3528 lpwhr
->pCustHeaders
[count
-1].wFlags
= lpHdr
->wFlags
;
3529 lpwhr
->pCustHeaders
[count
-1].wCount
= lpHdr
->wCount
;
3530 lpwhr
->nCustHeaders
++;
3535 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
3542 /***********************************************************************
3543 * HTTP_DeleteCustomHeader (internal)
3545 * Delete header from array
3546 * If this function is called, the indexs may change.
3548 static BOOL
HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr
, DWORD index
)
3550 if( lpwhr
->nCustHeaders
<= 0 )
3552 if( index
>= lpwhr
->nCustHeaders
)
3554 lpwhr
->nCustHeaders
--;
3556 memmove( &lpwhr
->pCustHeaders
[index
], &lpwhr
->pCustHeaders
[index
+1],
3557 (lpwhr
->nCustHeaders
- index
)* sizeof(HTTPHEADERW
) );
3558 memset( &lpwhr
->pCustHeaders
[lpwhr
->nCustHeaders
], 0, sizeof(HTTPHEADERW
) );
3564 /***********************************************************************
3565 * HTTP_VerifyValidHeader (internal)
3567 * Verify the given header is not invalid for the given http request
3570 static BOOL
HTTP_VerifyValidHeader(LPWININETHTTPREQW lpwhr
, LPCWSTR field
)
3574 /* Accept-Encoding is stripped from HTTP/1.0 requests. It is invalid */
3575 if (strcmpiW(field
,szAccept_Encoding
)==0)
3581 /***********************************************************************
3582 * IsHostInProxyBypassList (@)
3587 BOOL WINAPI
IsHostInProxyBypassList(DWORD flags
, LPCSTR szHost
, DWORD length
)
3589 FIXME("STUB: flags=%d host=%s length=%d\n",flags
,szHost
,length
);