Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1 | /* |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2 | * Wininet - Http Implementation |
| 3 | * |
| 4 | * Copyright 1999 Corel Corporation |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 5 | * Copyright 2002 CodeWeavers Inc. |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 6 | * Copyright 2002 TransGaming Technologies Inc. |
Francois Gouget | ad5ff7c | 2004-02-09 22:07:42 +0000 | [diff] [blame] | 7 | * Copyright 2004 Mike McCormack for CodeWeavers |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 8 | * Copyright 2005 Aric Stewart for CodeWeavers |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 9 | * Copyright 2006 Robert Shearman for CodeWeavers |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 10 | * |
| 11 | * Ulrich Czekalla |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 12 | * David Hammerton |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 13 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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. |
| 18 | * |
| 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. |
| 23 | * |
| 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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 27 | */ |
| 28 | |
Patrik Stridvall | 4710be2 | 2000-06-23 15:47:14 +0000 | [diff] [blame] | 29 | #include "config.h" |
Alexandre Julliard | 754e7aa | 2004-09-03 18:30:28 +0000 | [diff] [blame] | 30 | #include "wine/port.h" |
Patrik Stridvall | 4710be2 | 2000-06-23 15:47:14 +0000 | [diff] [blame] | 31 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 32 | #include <sys/types.h> |
Patrik Stridvall | 4710be2 | 2000-06-23 15:47:14 +0000 | [diff] [blame] | 33 | #ifdef HAVE_SYS_SOCKET_H |
| 34 | # include <sys/socket.h> |
| 35 | #endif |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 36 | #ifdef HAVE_ARPA_INET_H |
| 37 | # include <arpa/inet.h> |
| 38 | #endif |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 39 | #include <stdarg.h> |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 40 | #include <stdio.h> |
| 41 | #include <stdlib.h> |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 42 | #ifdef HAVE_UNISTD_H |
| 43 | # include <unistd.h> |
| 44 | #endif |
Chris Morgan | b9807b4 | 2001-02-15 21:24:07 +0000 | [diff] [blame] | 45 | #include <time.h> |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 46 | #include <assert.h> |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 47 | |
Guy Albertelli | aafec98 | 2001-11-06 22:31:19 +0000 | [diff] [blame] | 48 | #include "windef.h" |
| 49 | #include "winbase.h" |
| 50 | #include "wininet.h" |
Guy Albertelli | aafec98 | 2001-11-06 22:31:19 +0000 | [diff] [blame] | 51 | #include "winerror.h" |
Jon Griffiths | 603f20f | 2001-12-11 00:30:17 +0000 | [diff] [blame] | 52 | #define NO_SHLWAPI_STREAM |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 53 | #define NO_SHLWAPI_REG |
| 54 | #define NO_SHLWAPI_STRFCNS |
| 55 | #define NO_SHLWAPI_GDI |
Guy Albertelli | aafec98 | 2001-11-06 22:31:19 +0000 | [diff] [blame] | 56 | #include "shlwapi.h" |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 57 | #include "sspi.h" |
Jacek Caban | 7e63f95 | 2008-03-12 02:24:23 +0100 | [diff] [blame] | 58 | #include "wincrypt.h" |
Guy Albertelli | aafec98 | 2001-11-06 22:31:19 +0000 | [diff] [blame] | 59 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 60 | #include "internet.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 61 | #include "wine/debug.h" |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 62 | #include "wine/unicode.h" |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 63 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 64 | WINE_DEFAULT_DEBUG_CHANNEL(wininet); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 65 | |
Hans Leidekker | 3a57711 | 2008-03-24 21:31:53 +0100 | [diff] [blame] | 66 | static const WCHAR g_szHttp1_0[] = {'H','T','T','P','/','1','.','0',0}; |
Hans Leidekker | d0033db | 2008-02-17 20:41:42 +0100 | [diff] [blame] | 67 | static const WCHAR g_szHttp1_1[] = {'H','T','T','P','/','1','.','1',0}; |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 68 | static const WCHAR g_szReferer[] = {'R','e','f','e','r','e','r',0}; |
| 69 | static const WCHAR g_szAccept[] = {'A','c','c','e','p','t',0}; |
| 70 | static const WCHAR g_szUserAgent[] = {'U','s','e','r','-','A','g','e','n','t',0}; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 71 | static const WCHAR szHost[] = { 'H','o','s','t',0 }; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 72 | static const WCHAR szAuthorization[] = { 'A','u','t','h','o','r','i','z','a','t','i','o','n',0 }; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 73 | static const WCHAR szProxy_Authorization[] = { 'P','r','o','x','y','-','A','u','t','h','o','r','i','z','a','t','i','o','n',0 }; |
| 74 | static const WCHAR szStatus[] = { 'S','t','a','t','u','s',0 }; |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 75 | static const WCHAR szKeepAlive[] = {'K','e','e','p','-','A','l','i','v','e',0}; |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 76 | static const WCHAR szGET[] = { 'G','E','T', 0 }; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 77 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 78 | #define MAXHOSTNAME 100 |
| 79 | #define MAX_FIELD_VALUE_LEN 256 |
| 80 | #define MAX_FIELD_LEN 256 |
| 81 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 82 | #define HTTP_REFERER g_szReferer |
| 83 | #define HTTP_ACCEPT g_szAccept |
| 84 | #define HTTP_USERAGENT g_szUserAgent |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 85 | |
| 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 |
| 93 | |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 94 | #define ARRAYSIZE(array) (sizeof(array)/sizeof((array)[0])) |
| 95 | |
| 96 | struct HttpAuthInfo |
| 97 | { |
| 98 | LPWSTR scheme; |
| 99 | CredHandle cred; |
| 100 | CtxtHandle ctx; |
| 101 | TimeStamp exp; |
| 102 | ULONG attr; |
Rob Shearman | 0be05ab | 2008-03-10 16:41:44 +0000 | [diff] [blame] | 103 | ULONG max_token; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 104 | void *auth_data; |
| 105 | unsigned int auth_data_len; |
| 106 | BOOL finished; /* finished authenticating */ |
| 107 | }; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 108 | |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 109 | static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr); |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 110 | static BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr, BOOL clear); |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 111 | static BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier); |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 112 | static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer); |
| 113 | static BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 114 | static INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField, INT index, BOOL Request); |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 115 | static BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, DWORD index); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 116 | static LPWSTR HTTP_build_req( LPCWSTR *list, int len ); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 117 | static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD |
| 118 | dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD |
| 119 | lpdwIndex); |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 120 | static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl); |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 121 | static UINT HTTP_DecodeBase64(LPCWSTR base64, LPSTR bin); |
Aric Stewart | c8dfc02 | 2007-07-26 08:59:00 -0500 | [diff] [blame] | 122 | static BOOL HTTP_VerifyValidHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field); |
Jacek Caban | ca39a55 | 2008-03-02 19:55:04 +0100 | [diff] [blame] | 123 | static void HTTP_DrainContent(WININETHTTPREQW *req); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 124 | |
| 125 | LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW req, LPCWSTR head) |
| 126 | { |
| 127 | int HeaderIndex = 0; |
| 128 | HeaderIndex = HTTP_GetCustomHeaderIndex(req, head, 0, TRUE); |
| 129 | if (HeaderIndex == -1) |
| 130 | return NULL; |
| 131 | else |
| 132 | return &req->pCustHeaders[HeaderIndex]; |
| 133 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 134 | |
| 135 | /*********************************************************************** |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 136 | * HTTP_Tokenize (internal) |
| 137 | * |
| 138 | * Tokenize a string, allocating memory for the tokens. |
| 139 | */ |
| 140 | static LPWSTR * HTTP_Tokenize(LPCWSTR string, LPCWSTR token_string) |
| 141 | { |
| 142 | LPWSTR * token_array; |
| 143 | int tokens = 0; |
| 144 | int i; |
| 145 | LPCWSTR next_token; |
| 146 | |
| 147 | /* empty string has no tokens */ |
| 148 | if (*string) |
| 149 | tokens++; |
| 150 | /* count tokens */ |
| 151 | for (i = 0; string[i]; i++) |
| 152 | if (!strncmpW(string+i, token_string, strlenW(token_string))) |
| 153 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 154 | DWORD j; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 155 | tokens++; |
| 156 | /* we want to skip over separators, but not the null terminator */ |
| 157 | for (j = 0; j < strlenW(token_string) - 1; j++) |
| 158 | if (!string[i+j]) |
| 159 | break; |
| 160 | i += j; |
| 161 | } |
| 162 | |
| 163 | /* add 1 for terminating NULL */ |
| 164 | token_array = HeapAlloc(GetProcessHeap(), 0, (tokens+1) * sizeof(*token_array)); |
| 165 | token_array[tokens] = NULL; |
| 166 | if (!tokens) |
| 167 | return token_array; |
| 168 | for (i = 0; i < tokens; i++) |
| 169 | { |
| 170 | int len; |
| 171 | next_token = strstrW(string, token_string); |
| 172 | if (!next_token) next_token = string+strlenW(string); |
| 173 | len = next_token - string; |
| 174 | token_array[i] = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR)); |
| 175 | memcpy(token_array[i], string, len*sizeof(WCHAR)); |
| 176 | token_array[i][len] = '\0'; |
| 177 | string = next_token+strlenW(token_string); |
| 178 | } |
| 179 | return token_array; |
| 180 | } |
| 181 | |
| 182 | /*********************************************************************** |
| 183 | * HTTP_FreeTokens (internal) |
| 184 | * |
| 185 | * Frees memory returned from HTTP_Tokenize. |
| 186 | */ |
| 187 | static void HTTP_FreeTokens(LPWSTR * token_array) |
| 188 | { |
| 189 | int i; |
| 190 | for (i = 0; token_array[i]; i++) |
| 191 | HeapFree(GetProcessHeap(), 0, token_array[i]); |
| 192 | HeapFree(GetProcessHeap(), 0, token_array); |
| 193 | } |
| 194 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 195 | /* ********************************************************************** |
| 196 | * |
| 197 | * Helper functions for the HttpSendRequest(Ex) functions |
| 198 | * |
| 199 | */ |
Jacek Caban | c156845 | 2006-12-25 21:33:36 +0100 | [diff] [blame] | 200 | static void AsyncHttpSendRequestProc(WORKREQUEST *workRequest) |
| 201 | { |
| 202 | struct WORKREQ_HTTPSENDREQUESTW const *req = &workRequest->u.HttpSendRequestW; |
| 203 | LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest->hdr; |
| 204 | |
| 205 | TRACE("%p\n", lpwhr); |
| 206 | |
| 207 | HTTP_HttpSendRequestW(lpwhr, req->lpszHeader, |
| 208 | req->dwHeaderLength, req->lpOptional, req->dwOptionalLength, |
| 209 | req->dwContentLength, req->bEndRequest); |
| 210 | |
| 211 | HeapFree(GetProcessHeap(), 0, req->lpszHeader); |
| 212 | } |
| 213 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 214 | static void HTTP_FixURL( LPWININETHTTPREQW lpwhr) |
| 215 | { |
| 216 | static const WCHAR szSlash[] = { '/',0 }; |
| 217 | static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/', 0 }; |
| 218 | |
| 219 | /* If we don't have a path we set it to root */ |
| 220 | if (NULL == lpwhr->lpszPath) |
| 221 | lpwhr->lpszPath = WININET_strdupW(szSlash); |
| 222 | else /* remove \r and \n*/ |
| 223 | { |
| 224 | int nLen = strlenW(lpwhr->lpszPath); |
| 225 | while ((nLen >0 ) && ((lpwhr->lpszPath[nLen-1] == '\r')||(lpwhr->lpszPath[nLen-1] == '\n'))) |
| 226 | { |
| 227 | nLen--; |
| 228 | lpwhr->lpszPath[nLen]='\0'; |
| 229 | } |
| 230 | /* Replace '\' with '/' */ |
| 231 | while (nLen>0) { |
| 232 | nLen--; |
| 233 | if (lpwhr->lpszPath[nLen] == '\\') lpwhr->lpszPath[nLen]='/'; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | if(CSTR_EQUAL != CompareStringW( LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, |
Juan Lang | b210e3a | 2007-11-07 14:34:49 -0800 | [diff] [blame] | 238 | lpwhr->lpszPath, strlenW(lpwhr->lpszPath), szHttp, strlenW(szHttp) ) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 239 | && lpwhr->lpszPath[0] != '/') /* not an absolute path ?? --> fix it !! */ |
| 240 | { |
| 241 | WCHAR *fixurl = HeapAlloc(GetProcessHeap(), 0, |
| 242 | (strlenW(lpwhr->lpszPath) + 2)*sizeof(WCHAR)); |
| 243 | *fixurl = '/'; |
| 244 | strcpyW(fixurl + 1, lpwhr->lpszPath); |
| 245 | HeapFree( GetProcessHeap(), 0, lpwhr->lpszPath ); |
| 246 | lpwhr->lpszPath = fixurl; |
| 247 | } |
| 248 | } |
| 249 | |
Hans Leidekker | d0033db | 2008-02-17 20:41:42 +0100 | [diff] [blame] | 250 | static LPWSTR HTTP_BuildHeaderRequestString( LPWININETHTTPREQW lpwhr, LPCWSTR verb, LPCWSTR path, LPCWSTR version ) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 251 | { |
| 252 | LPWSTR requestString; |
| 253 | DWORD len, n; |
| 254 | LPCWSTR *req; |
Gerald Pfeifer | 3f1a20b | 2008-01-12 20:14:04 +0100 | [diff] [blame] | 255 | UINT i; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 256 | LPWSTR p; |
| 257 | |
| 258 | static const WCHAR szSpace[] = { ' ',0 }; |
| 259 | static const WCHAR szcrlf[] = {'\r','\n', 0}; |
| 260 | static const WCHAR szColon[] = { ':',' ',0 }; |
| 261 | static const WCHAR sztwocrlf[] = {'\r','\n','\r','\n', 0}; |
| 262 | |
| 263 | /* allocate space for an array of all the string pointers to be added */ |
Hans Leidekker | d0033db | 2008-02-17 20:41:42 +0100 | [diff] [blame] | 264 | len = (lpwhr->nCustHeaders)*4 + 10; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 265 | req = HeapAlloc( GetProcessHeap(), 0, len*sizeof(LPCWSTR) ); |
| 266 | |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 267 | /* add the verb, path and HTTP version string */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 268 | n = 0; |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 269 | req[n++] = verb; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 270 | req[n++] = szSpace; |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 271 | req[n++] = path; |
Hans Leidekker | d0033db | 2008-02-17 20:41:42 +0100 | [diff] [blame] | 272 | req[n++] = szSpace; |
| 273 | req[n++] = version; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 274 | |
Austin English | 0e4adae | 2008-01-04 13:37:14 -0600 | [diff] [blame] | 275 | /* Append custom request headers */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 276 | for (i = 0; i < lpwhr->nCustHeaders; i++) |
| 277 | { |
| 278 | if (lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST) |
| 279 | { |
| 280 | req[n++] = szcrlf; |
| 281 | req[n++] = lpwhr->pCustHeaders[i].lpszField; |
| 282 | req[n++] = szColon; |
| 283 | req[n++] = lpwhr->pCustHeaders[i].lpszValue; |
| 284 | |
| 285 | TRACE("Adding custom header %s (%s)\n", |
| 286 | debugstr_w(lpwhr->pCustHeaders[i].lpszField), |
| 287 | debugstr_w(lpwhr->pCustHeaders[i].lpszValue)); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | if( n >= len ) |
| 292 | ERR("oops. buffer overrun\n"); |
| 293 | |
| 294 | req[n] = NULL; |
| 295 | requestString = HTTP_build_req( req, 4 ); |
| 296 | HeapFree( GetProcessHeap(), 0, req ); |
| 297 | |
| 298 | /* |
| 299 | * Set (header) termination string for request |
| 300 | * Make sure there's exactly two new lines at the end of the request |
| 301 | */ |
| 302 | p = &requestString[strlenW(requestString)-1]; |
| 303 | while ( (*p == '\n') || (*p == '\r') ) |
| 304 | p--; |
| 305 | strcpyW( p+1, sztwocrlf ); |
| 306 | |
| 307 | return requestString; |
| 308 | } |
| 309 | |
Hans Leidekker | 9717113 | 2008-02-17 21:29:45 +0100 | [diff] [blame] | 310 | static void HTTP_ProcessCookies( LPWININETHTTPREQW lpwhr ) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 311 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 312 | static const WCHAR szSet_Cookie[] = { 'S','e','t','-','C','o','o','k','i','e',0 }; |
| 313 | int HeaderIndex; |
| 314 | LPHTTPHEADERW setCookieHeader; |
| 315 | |
| 316 | HeaderIndex = HTTP_GetCustomHeaderIndex(lpwhr, szSet_Cookie, 0, FALSE); |
| 317 | if (HeaderIndex == -1) |
| 318 | return; |
| 319 | setCookieHeader = &lpwhr->pCustHeaders[HeaderIndex]; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 320 | |
Robert Shearman | 225a9fa | 2005-11-28 11:24:41 +0100 | [diff] [blame] | 321 | if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) && setCookieHeader->lpszValue) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 322 | { |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 323 | int nPosStart = 0, nPosEnd = 0, len; |
| 324 | static const WCHAR szFmt[] = { 'h','t','t','p',':','/','/','%','s','/',0}; |
| 325 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 326 | while (setCookieHeader->lpszValue[nPosEnd] != '\0') |
| 327 | { |
| 328 | LPWSTR buf_cookie, cookie_name, cookie_data; |
| 329 | LPWSTR buf_url; |
| 330 | LPWSTR domain = NULL; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 331 | LPHTTPHEADERW Host; |
| 332 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 333 | int nEqualPos = 0; |
| 334 | while (setCookieHeader->lpszValue[nPosEnd] != ';' && setCookieHeader->lpszValue[nPosEnd] != ',' && |
| 335 | setCookieHeader->lpszValue[nPosEnd] != '\0') |
| 336 | { |
| 337 | nPosEnd++; |
| 338 | } |
| 339 | if (setCookieHeader->lpszValue[nPosEnd] == ';') |
| 340 | { |
| 341 | /* fixme: not case sensitive, strcasestr is gnu only */ |
| 342 | int nDomainPosEnd = 0; |
| 343 | int nDomainPosStart = 0, nDomainLength = 0; |
| 344 | static const WCHAR szDomain[] = {'d','o','m','a','i','n','=',0}; |
| 345 | LPWSTR lpszDomain = strstrW(&setCookieHeader->lpszValue[nPosEnd], szDomain); |
| 346 | if (lpszDomain) |
| 347 | { /* they have specified their own domain, lets use it */ |
| 348 | while (lpszDomain[nDomainPosEnd] != ';' && lpszDomain[nDomainPosEnd] != ',' && |
| 349 | lpszDomain[nDomainPosEnd] != '\0') |
| 350 | { |
| 351 | nDomainPosEnd++; |
| 352 | } |
| 353 | nDomainPosStart = strlenW(szDomain); |
| 354 | nDomainLength = (nDomainPosEnd - nDomainPosStart) + 1; |
| 355 | domain = HeapAlloc(GetProcessHeap(), 0, (nDomainLength + 1)*sizeof(WCHAR)); |
| 356 | lstrcpynW(domain, &lpszDomain[nDomainPosStart], nDomainLength + 1); |
| 357 | } |
| 358 | } |
| 359 | if (setCookieHeader->lpszValue[nPosEnd] == '\0') break; |
| 360 | buf_cookie = HeapAlloc(GetProcessHeap(), 0, ((nPosEnd - nPosStart) + 1)*sizeof(WCHAR)); |
| 361 | lstrcpynW(buf_cookie, &setCookieHeader->lpszValue[nPosStart], (nPosEnd - nPosStart) + 1); |
| 362 | TRACE("%s\n", debugstr_w(buf_cookie)); |
| 363 | while (buf_cookie[nEqualPos] != '=' && buf_cookie[nEqualPos] != '\0') |
| 364 | { |
| 365 | nEqualPos++; |
| 366 | } |
| 367 | if (buf_cookie[nEqualPos] == '\0' || buf_cookie[nEqualPos + 1] == '\0') |
| 368 | { |
| 369 | HeapFree(GetProcessHeap(), 0, buf_cookie); |
| 370 | break; |
| 371 | } |
| 372 | |
| 373 | cookie_name = HeapAlloc(GetProcessHeap(), 0, (nEqualPos + 1)*sizeof(WCHAR)); |
| 374 | lstrcpynW(cookie_name, buf_cookie, nEqualPos + 1); |
| 375 | cookie_data = &buf_cookie[nEqualPos + 1]; |
| 376 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 377 | Host = HTTP_GetHeader(lpwhr,szHost); |
| 378 | len = lstrlenW((domain ? domain : (Host?Host->lpszValue:NULL))) + |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 379 | strlenW(lpwhr->lpszPath) + 9; |
| 380 | buf_url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 381 | sprintfW(buf_url, szFmt, (domain ? domain : (Host?Host->lpszValue:NULL))); /* FIXME PATH!!! */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 382 | InternetSetCookieW(buf_url, cookie_name, cookie_data); |
| 383 | |
| 384 | HeapFree(GetProcessHeap(), 0, buf_url); |
| 385 | HeapFree(GetProcessHeap(), 0, buf_cookie); |
| 386 | HeapFree(GetProcessHeap(), 0, cookie_name); |
| 387 | HeapFree(GetProcessHeap(), 0, domain); |
| 388 | nPosStart = nPosEnd; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 393 | static inline BOOL is_basic_auth_value( LPCWSTR pszAuthValue ) |
| 394 | { |
| 395 | static const WCHAR szBasic[] = {'B','a','s','i','c'}; /* Note: not nul-terminated */ |
| 396 | return !strncmpiW(pszAuthValue, szBasic, ARRAYSIZE(szBasic)) && |
| 397 | ((pszAuthValue[ARRAYSIZE(szBasic)] != ' ') || !pszAuthValue[ARRAYSIZE(szBasic)]); |
| 398 | } |
| 399 | |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 400 | static BOOL HTTP_DoAuthorization( LPWININETHTTPREQW lpwhr, LPCWSTR pszAuthValue, |
| 401 | struct HttpAuthInfo **ppAuthInfo, |
| 402 | LPWSTR domain_and_username, LPWSTR password ) |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 403 | { |
| 404 | SECURITY_STATUS sec_status; |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 405 | struct HttpAuthInfo *pAuthInfo = *ppAuthInfo; |
Rob Shearman | 7b94871 | 2007-05-26 08:49:12 +0100 | [diff] [blame] | 406 | BOOL first = FALSE; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 407 | |
| 408 | TRACE("%s\n", debugstr_w(pszAuthValue)); |
| 409 | |
| 410 | if (!pAuthInfo) |
| 411 | { |
| 412 | TimeStamp exp; |
| 413 | |
Rob Shearman | 7b94871 | 2007-05-26 08:49:12 +0100 | [diff] [blame] | 414 | first = TRUE; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 415 | pAuthInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*pAuthInfo)); |
| 416 | if (!pAuthInfo) |
| 417 | return FALSE; |
| 418 | |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 419 | SecInvalidateHandle(&pAuthInfo->cred); |
| 420 | SecInvalidateHandle(&pAuthInfo->ctx); |
| 421 | memset(&pAuthInfo->exp, 0, sizeof(pAuthInfo->exp)); |
| 422 | pAuthInfo->attr = 0; |
| 423 | pAuthInfo->auth_data = NULL; |
| 424 | pAuthInfo->auth_data_len = 0; |
| 425 | pAuthInfo->finished = FALSE; |
| 426 | |
Rob Shearman | 4d1b8b1 | 2007-05-25 12:06:11 +0100 | [diff] [blame] | 427 | if (is_basic_auth_value(pszAuthValue)) |
| 428 | { |
| 429 | static const WCHAR szBasic[] = {'B','a','s','i','c',0}; |
| 430 | pAuthInfo->scheme = WININET_strdupW(szBasic); |
| 431 | if (!pAuthInfo->scheme) |
| 432 | { |
| 433 | HeapFree(GetProcessHeap(), 0, pAuthInfo); |
| 434 | return FALSE; |
| 435 | } |
| 436 | } |
| 437 | else |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 438 | { |
Rob Shearman | 7631bdf | 2008-03-10 16:40:23 +0000 | [diff] [blame] | 439 | PVOID pAuthData; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 440 | SEC_WINNT_AUTH_IDENTITY_W nt_auth_identity; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 441 | |
Rob Shearman | 4d1b8b1 | 2007-05-25 12:06:11 +0100 | [diff] [blame] | 442 | pAuthInfo->scheme = WININET_strdupW(pszAuthValue); |
| 443 | if (!pAuthInfo->scheme) |
| 444 | { |
| 445 | HeapFree(GetProcessHeap(), 0, pAuthInfo); |
| 446 | return FALSE; |
| 447 | } |
| 448 | |
Rob Shearman | 7631bdf | 2008-03-10 16:40:23 +0000 | [diff] [blame] | 449 | if (domain_and_username) |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 450 | { |
Rob Shearman | 7631bdf | 2008-03-10 16:40:23 +0000 | [diff] [blame] | 451 | WCHAR *user = strchrW(domain_and_username, '\\'); |
| 452 | WCHAR *domain = domain_and_username; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 453 | |
Rob Shearman | 7631bdf | 2008-03-10 16:40:23 +0000 | [diff] [blame] | 454 | /* FIXME: make sure scheme accepts SEC_WINNT_AUTH_IDENTITY before calling AcquireCredentialsHandle */ |
| 455 | |
| 456 | pAuthData = &nt_auth_identity; |
| 457 | |
| 458 | if (user) user++; |
| 459 | else |
| 460 | { |
| 461 | user = domain_and_username; |
| 462 | domain = NULL; |
| 463 | } |
| 464 | |
| 465 | nt_auth_identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; |
| 466 | nt_auth_identity.User = user; |
| 467 | nt_auth_identity.UserLength = strlenW(nt_auth_identity.User); |
| 468 | nt_auth_identity.Domain = domain; |
| 469 | nt_auth_identity.DomainLength = domain ? user - domain - 1 : 0; |
| 470 | nt_auth_identity.Password = password; |
| 471 | nt_auth_identity.PasswordLength = strlenW(nt_auth_identity.Password); |
| 472 | } |
| 473 | else |
| 474 | /* use default credentials */ |
| 475 | pAuthData = NULL; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 476 | |
| 477 | sec_status = AcquireCredentialsHandleW(NULL, pAuthInfo->scheme, |
| 478 | SECPKG_CRED_OUTBOUND, NULL, |
Rob Shearman | 7631bdf | 2008-03-10 16:40:23 +0000 | [diff] [blame] | 479 | pAuthData, NULL, |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 480 | NULL, &pAuthInfo->cred, |
| 481 | &exp); |
Rob Shearman | 0be05ab | 2008-03-10 16:41:44 +0000 | [diff] [blame] | 482 | if (sec_status == SEC_E_OK) |
| 483 | { |
| 484 | PSecPkgInfoW sec_pkg_info; |
| 485 | sec_status = QuerySecurityPackageInfoW(pAuthInfo->scheme, &sec_pkg_info); |
| 486 | if (sec_status == SEC_E_OK) |
| 487 | { |
| 488 | pAuthInfo->max_token = sec_pkg_info->cbMaxToken; |
| 489 | FreeContextBuffer(sec_pkg_info); |
| 490 | } |
| 491 | } |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 492 | if (sec_status != SEC_E_OK) |
| 493 | { |
| 494 | WARN("AcquireCredentialsHandleW for scheme %s failed with error 0x%08x\n", |
| 495 | debugstr_w(pAuthInfo->scheme), sec_status); |
| 496 | HeapFree(GetProcessHeap(), 0, pAuthInfo->scheme); |
| 497 | HeapFree(GetProcessHeap(), 0, pAuthInfo); |
| 498 | return FALSE; |
| 499 | } |
| 500 | } |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 501 | *ppAuthInfo = pAuthInfo; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 502 | } |
| 503 | else if (pAuthInfo->finished) |
| 504 | return FALSE; |
| 505 | |
| 506 | if ((strlenW(pszAuthValue) < strlenW(pAuthInfo->scheme)) || |
| 507 | strncmpiW(pszAuthValue, pAuthInfo->scheme, strlenW(pAuthInfo->scheme))) |
| 508 | { |
| 509 | ERR("authentication scheme changed from %s to %s\n", |
| 510 | debugstr_w(pAuthInfo->scheme), debugstr_w(pszAuthValue)); |
| 511 | return FALSE; |
| 512 | } |
| 513 | |
| 514 | if (is_basic_auth_value(pszAuthValue)) |
| 515 | { |
Rob Shearman | 7631bdf | 2008-03-10 16:40:23 +0000 | [diff] [blame] | 516 | int userlen; |
| 517 | int passlen; |
Rob Shearman | 847cc51 | 2007-05-21 14:28:02 +0100 | [diff] [blame] | 518 | char *auth_data; |
| 519 | |
| 520 | TRACE("basic authentication\n"); |
| 521 | |
Rob Shearman | 7631bdf | 2008-03-10 16:40:23 +0000 | [diff] [blame] | 522 | /* we don't cache credentials for basic authentication, so we can't |
| 523 | * retrieve them if the application didn't pass us any credentials */ |
| 524 | if (!domain_and_username) return FALSE; |
| 525 | |
| 526 | userlen = WideCharToMultiByte(CP_UTF8, 0, domain_and_username, lstrlenW(domain_and_username), NULL, 0, NULL, NULL); |
| 527 | passlen = WideCharToMultiByte(CP_UTF8, 0, password, lstrlenW(password), NULL, 0, NULL, NULL); |
| 528 | |
Rob Shearman | 847cc51 | 2007-05-21 14:28:02 +0100 | [diff] [blame] | 529 | /* length includes a nul terminator, which will be re-used for the ':' */ |
| 530 | auth_data = HeapAlloc(GetProcessHeap(), 0, userlen + 1 + passlen); |
| 531 | if (!auth_data) |
| 532 | return FALSE; |
| 533 | |
| 534 | WideCharToMultiByte(CP_UTF8, 0, domain_and_username, -1, auth_data, userlen, NULL, NULL); |
| 535 | auth_data[userlen] = ':'; |
| 536 | WideCharToMultiByte(CP_UTF8, 0, password, -1, &auth_data[userlen+1], passlen, NULL, NULL); |
| 537 | |
| 538 | pAuthInfo->auth_data = auth_data; |
| 539 | pAuthInfo->auth_data_len = userlen + 1 + passlen; |
| 540 | pAuthInfo->finished = TRUE; |
| 541 | |
| 542 | return TRUE; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 543 | } |
| 544 | else |
| 545 | { |
| 546 | LPCWSTR pszAuthData; |
| 547 | SecBufferDesc out_desc, in_desc; |
| 548 | SecBuffer out, in; |
| 549 | unsigned char *buffer; |
| 550 | ULONG context_req = ISC_REQ_CONNECTION | ISC_REQ_USE_DCE_STYLE | |
| 551 | ISC_REQ_MUTUAL_AUTH | ISC_REQ_DELEGATE; |
| 552 | |
| 553 | in.BufferType = SECBUFFER_TOKEN; |
| 554 | in.cbBuffer = 0; |
| 555 | in.pvBuffer = NULL; |
| 556 | |
| 557 | in_desc.ulVersion = 0; |
| 558 | in_desc.cBuffers = 1; |
| 559 | in_desc.pBuffers = ∈ |
| 560 | |
| 561 | pszAuthData = pszAuthValue + strlenW(pAuthInfo->scheme); |
| 562 | if (*pszAuthData == ' ') |
| 563 | { |
| 564 | pszAuthData++; |
| 565 | in.cbBuffer = HTTP_DecodeBase64(pszAuthData, NULL); |
| 566 | in.pvBuffer = HeapAlloc(GetProcessHeap(), 0, in.cbBuffer); |
| 567 | HTTP_DecodeBase64(pszAuthData, in.pvBuffer); |
| 568 | } |
| 569 | |
Rob Shearman | 0be05ab | 2008-03-10 16:41:44 +0000 | [diff] [blame] | 570 | buffer = HeapAlloc(GetProcessHeap(), 0, pAuthInfo->max_token); |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 571 | |
| 572 | out.BufferType = SECBUFFER_TOKEN; |
Rob Shearman | 0be05ab | 2008-03-10 16:41:44 +0000 | [diff] [blame] | 573 | out.cbBuffer = pAuthInfo->max_token; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 574 | out.pvBuffer = buffer; |
| 575 | |
| 576 | out_desc.ulVersion = 0; |
| 577 | out_desc.cBuffers = 1; |
| 578 | out_desc.pBuffers = &out; |
| 579 | |
Rob Shearman | 7b94871 | 2007-05-26 08:49:12 +0100 | [diff] [blame] | 580 | sec_status = InitializeSecurityContextW(first ? &pAuthInfo->cred : NULL, |
Rob Shearman | 5edcf3a | 2008-01-24 19:30:11 +0000 | [diff] [blame] | 581 | first ? NULL : &pAuthInfo->ctx, |
| 582 | first ? lpwhr->lpHttpSession->lpszServerName : NULL, |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 583 | context_req, 0, SECURITY_NETWORK_DREP, |
| 584 | in.pvBuffer ? &in_desc : NULL, |
| 585 | 0, &pAuthInfo->ctx, &out_desc, |
| 586 | &pAuthInfo->attr, &pAuthInfo->exp); |
| 587 | if (sec_status == SEC_E_OK) |
| 588 | { |
| 589 | pAuthInfo->finished = TRUE; |
| 590 | pAuthInfo->auth_data = out.pvBuffer; |
| 591 | pAuthInfo->auth_data_len = out.cbBuffer; |
| 592 | TRACE("sending last auth packet\n"); |
| 593 | } |
| 594 | else if (sec_status == SEC_I_CONTINUE_NEEDED) |
| 595 | { |
| 596 | pAuthInfo->auth_data = out.pvBuffer; |
| 597 | pAuthInfo->auth_data_len = out.cbBuffer; |
| 598 | TRACE("sending next auth packet\n"); |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | ERR("InitializeSecurityContextW returned error 0x%08x\n", sec_status); |
Rob Shearman | db5745c | 2008-03-14 18:09:20 +0000 | [diff] [blame] | 603 | pAuthInfo->finished = TRUE; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 604 | HeapFree(GetProcessHeap(), 0, out.pvBuffer); |
| 605 | return FALSE; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | return TRUE; |
| 610 | } |
| 611 | |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 612 | /*********************************************************************** |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 613 | * HTTP_HttpAddRequestHeadersW (internal) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 614 | */ |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 615 | static BOOL WINAPI HTTP_HttpAddRequestHeadersW(LPWININETHTTPREQW lpwhr, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 616 | LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 617 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 618 | LPWSTR lpszStart; |
| 619 | LPWSTR lpszEnd; |
| 620 | LPWSTR buffer; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 621 | BOOL bSuccess = FALSE; |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 622 | DWORD len; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 623 | |
Francois Gouget | abfa73b | 2008-02-19 00:18:02 +0100 | [diff] [blame] | 624 | TRACE("copying header: %s\n", debugstr_wn(lpszHeader, dwHeaderLength)); |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 625 | |
Alexandre Julliard | 7c1925a0 | 2005-09-13 15:00:32 +0000 | [diff] [blame] | 626 | if( dwHeaderLength == ~0U ) |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 627 | len = strlenW(lpszHeader); |
| 628 | else |
| 629 | len = dwHeaderLength; |
| 630 | buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*(len+1) ); |
Peter Berg Larsen | e732fc0 | 2005-03-28 14:17:51 +0000 | [diff] [blame] | 631 | lstrcpynW( buffer, lpszHeader, len + 1); |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 632 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 633 | lpszStart = buffer; |
| 634 | |
| 635 | do |
| 636 | { |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 637 | LPWSTR * pFieldAndValue; |
| 638 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 639 | lpszEnd = lpszStart; |
| 640 | |
| 641 | while (*lpszEnd != '\0') |
| 642 | { |
| 643 | if (*lpszEnd == '\r' && *(lpszEnd + 1) == '\n') |
| 644 | break; |
| 645 | lpszEnd++; |
| 646 | } |
| 647 | |
Robert Shearman | 4cd38b4 | 2004-07-13 23:34:28 +0000 | [diff] [blame] | 648 | if (*lpszStart == '\0') |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 649 | break; |
| 650 | |
Robert Shearman | 4cd38b4 | 2004-07-13 23:34:28 +0000 | [diff] [blame] | 651 | if (*lpszEnd == '\r') |
| 652 | { |
| 653 | *lpszEnd = '\0'; |
| 654 | lpszEnd += 2; /* Jump over \r\n */ |
| 655 | } |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 656 | TRACE("interpreting header %s\n", debugstr_w(lpszStart)); |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 657 | pFieldAndValue = HTTP_InterpretHttpHeader(lpszStart); |
| 658 | if (pFieldAndValue) |
| 659 | { |
Aric Stewart | c8dfc02 | 2007-07-26 08:59:00 -0500 | [diff] [blame] | 660 | bSuccess = HTTP_VerifyValidHeader(lpwhr, pFieldAndValue[0]); |
| 661 | if (bSuccess) |
| 662 | bSuccess = HTTP_ProcessHeader(lpwhr, pFieldAndValue[0], |
| 663 | pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ); |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 664 | HTTP_FreeTokens(pFieldAndValue); |
| 665 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 666 | |
Robert Shearman | 4cd38b4 | 2004-07-13 23:34:28 +0000 | [diff] [blame] | 667 | lpszStart = lpszEnd; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 668 | } while (bSuccess); |
| 669 | |
| 670 | HeapFree(GetProcessHeap(), 0, buffer); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 671 | |
| 672 | return bSuccess; |
| 673 | } |
| 674 | |
| 675 | /*********************************************************************** |
| 676 | * HttpAddRequestHeadersW (WININET.@) |
| 677 | * |
| 678 | * Adds one or more HTTP header to the request handler |
| 679 | * |
Francois Gouget | abfa73b | 2008-02-19 00:18:02 +0100 | [diff] [blame] | 680 | * NOTE |
| 681 | * On Windows if dwHeaderLength includes the trailing '\0', then |
| 682 | * HttpAddRequestHeadersW() adds it too. However this results in an |
| 683 | * invalid Http header which is rejected by some servers so we probably |
| 684 | * don't need to match Windows on that point. |
| 685 | * |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 686 | * RETURNS |
| 687 | * TRUE on success |
| 688 | * FALSE on failure |
| 689 | * |
| 690 | */ |
| 691 | BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest, |
| 692 | LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) |
| 693 | { |
| 694 | BOOL bSuccess = FALSE; |
| 695 | LPWININETHTTPREQW lpwhr; |
| 696 | |
Francois Gouget | abfa73b | 2008-02-19 00:18:02 +0100 | [diff] [blame] | 697 | TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_wn(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 698 | |
| 699 | if (!lpszHeader) |
| 700 | return TRUE; |
| 701 | |
| 702 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest ); |
| 703 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 704 | { |
| 705 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 706 | goto lend; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 707 | } |
| 708 | bSuccess = HTTP_HttpAddRequestHeadersW( lpwhr, lpszHeader, dwHeaderLength, dwModifier ); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 709 | lend: |
| 710 | if( lpwhr ) |
| 711 | WININET_Release( &lpwhr->hdr ); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 712 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 713 | return bSuccess; |
| 714 | } |
| 715 | |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 716 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 717 | * HttpAddRequestHeadersA (WININET.@) |
| 718 | * |
| 719 | * Adds one or more HTTP header to the request handler |
| 720 | * |
| 721 | * RETURNS |
| 722 | * TRUE on success |
| 723 | * FALSE on failure |
| 724 | * |
| 725 | */ |
| 726 | BOOL WINAPI HttpAddRequestHeadersA(HINTERNET hHttpRequest, |
| 727 | LPCSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) |
| 728 | { |
| 729 | DWORD len; |
| 730 | LPWSTR hdr; |
| 731 | BOOL r; |
| 732 | |
Francois Gouget | abfa73b | 2008-02-19 00:18:02 +0100 | [diff] [blame] | 733 | TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_an(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 734 | |
| 735 | len = MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, NULL, 0 ); |
| 736 | hdr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); |
| 737 | MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, hdr, len ); |
Alexandre Julliard | 7c1925a0 | 2005-09-13 15:00:32 +0000 | [diff] [blame] | 738 | if( dwHeaderLength != ~0U ) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 739 | dwHeaderLength = len; |
| 740 | |
| 741 | r = HttpAddRequestHeadersW( hHttpRequest, hdr, dwHeaderLength, dwModifier ); |
| 742 | |
| 743 | HeapFree( GetProcessHeap(), 0, hdr ); |
| 744 | |
| 745 | return r; |
| 746 | } |
| 747 | |
| 748 | /*********************************************************************** |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 749 | * HttpEndRequestA (WININET.@) |
| 750 | * |
| 751 | * Ends an HTTP request that was started by HttpSendRequestEx |
| 752 | * |
| 753 | * RETURNS |
| 754 | * TRUE if successful |
| 755 | * FALSE on failure |
| 756 | * |
| 757 | */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 758 | BOOL WINAPI HttpEndRequestA(HINTERNET hRequest, |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 759 | LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext) |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 760 | { |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 761 | LPINTERNET_BUFFERSA ptr; |
| 762 | LPINTERNET_BUFFERSW lpBuffersOutW,ptrW; |
| 763 | BOOL rc = FALSE; |
| 764 | |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 765 | TRACE("(%p, %p, %08x, %08lx): stub\n", hRequest, lpBuffersOut, dwFlags, |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 766 | dwContext); |
| 767 | |
| 768 | ptr = lpBuffersOut; |
| 769 | if (ptr) |
| 770 | lpBuffersOutW = (LPINTERNET_BUFFERSW)HeapAlloc(GetProcessHeap(), |
| 771 | HEAP_ZERO_MEMORY, sizeof(INTERNET_BUFFERSW)); |
| 772 | else |
| 773 | lpBuffersOutW = NULL; |
| 774 | |
| 775 | ptrW = lpBuffersOutW; |
| 776 | while (ptr) |
| 777 | { |
| 778 | if (ptr->lpvBuffer && ptr->dwBufferLength) |
| 779 | ptrW->lpvBuffer = HeapAlloc(GetProcessHeap(),0,ptr->dwBufferLength); |
| 780 | ptrW->dwBufferLength = ptr->dwBufferLength; |
| 781 | ptrW->dwBufferTotal= ptr->dwBufferTotal; |
| 782 | |
| 783 | if (ptr->Next) |
| 784 | ptrW->Next = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, |
| 785 | sizeof(INTERNET_BUFFERSW)); |
| 786 | |
| 787 | ptr = ptr->Next; |
| 788 | ptrW = ptrW->Next; |
| 789 | } |
| 790 | |
| 791 | rc = HttpEndRequestW(hRequest, lpBuffersOutW, dwFlags, dwContext); |
| 792 | |
| 793 | if (lpBuffersOutW) |
| 794 | { |
| 795 | ptrW = lpBuffersOutW; |
| 796 | while (ptrW) |
| 797 | { |
| 798 | LPINTERNET_BUFFERSW ptrW2; |
| 799 | |
| 800 | FIXME("Do we need to translate info out of these buffer?\n"); |
| 801 | |
Andrew Talbot | 45481db | 2008-02-04 22:07:57 +0000 | [diff] [blame] | 802 | HeapFree(GetProcessHeap(),0,ptrW->lpvBuffer); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 803 | ptrW2 = ptrW->Next; |
| 804 | HeapFree(GetProcessHeap(),0,ptrW); |
| 805 | ptrW = ptrW2; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | return rc; |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /*********************************************************************** |
| 813 | * HttpEndRequestW (WININET.@) |
| 814 | * |
| 815 | * Ends an HTTP request that was started by HttpSendRequestEx |
| 816 | * |
| 817 | * RETURNS |
| 818 | * TRUE if successful |
| 819 | * FALSE on failure |
| 820 | * |
| 821 | */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 822 | BOOL WINAPI HttpEndRequestW(HINTERNET hRequest, |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 823 | LPINTERNET_BUFFERSW lpBuffersOut, DWORD dwFlags, DWORD_PTR dwContext) |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 824 | { |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 825 | BOOL rc = FALSE; |
| 826 | LPWININETHTTPREQW lpwhr; |
| 827 | INT responseLen; |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 828 | DWORD dwBufferSize; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 829 | |
| 830 | TRACE("-->\n"); |
| 831 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hRequest ); |
| 832 | |
| 833 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 834 | { |
| 835 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Nigel Liang | 7d2ac20 | 2007-10-17 17:07:41 -0700 | [diff] [blame] | 836 | if (lpwhr) |
| 837 | WININET_Release( &lpwhr->hdr ); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 838 | return FALSE; |
| 839 | } |
| 840 | |
| 841 | lpwhr->hdr.dwFlags |= dwFlags; |
| 842 | lpwhr->hdr.dwContext = dwContext; |
| 843 | |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 844 | /* We appear to do nothing with lpBuffersOut.. is that correct? */ |
| 845 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 846 | SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 847 | INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0); |
| 848 | |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 849 | responseLen = HTTP_GetResponseHeaders(lpwhr, TRUE); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 850 | if (responseLen) |
| 851 | rc = TRUE; |
| 852 | |
| 853 | SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 854 | INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen, sizeof(DWORD)); |
| 855 | |
Hans Leidekker | 9717113 | 2008-02-17 21:29:45 +0100 | [diff] [blame] | 856 | /* process cookies here. Is this right? */ |
| 857 | HTTP_ProcessCookies(lpwhr); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 858 | |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 859 | dwBufferSize = sizeof(lpwhr->dwContentLength); |
| 860 | if (!HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, |
| 861 | &lpwhr->dwContentLength,&dwBufferSize,NULL)) |
| 862 | lpwhr->dwContentLength = -1; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 863 | |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 864 | if (lpwhr->dwContentLength == 0) |
| 865 | HTTP_FinishedReading(lpwhr); |
| 866 | |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 867 | if(!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT)) |
| 868 | { |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 869 | DWORD dwCode,dwCodeLength=sizeof(DWORD); |
| 870 | if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,&dwCode,&dwCodeLength,NULL) && |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 871 | (dwCode==302 || dwCode==301)) |
| 872 | { |
Hans Leidekker | 612f3c1 | 2008-03-31 20:26:16 +0200 | [diff] [blame^] | 873 | WCHAR szNewLocation[INTERNET_MAX_URL_LENGTH]; |
Rob Shearman | 9efe083 | 2007-01-12 19:19:18 -0600 | [diff] [blame] | 874 | dwBufferSize=sizeof(szNewLocation); |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 875 | if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,NULL)) |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 876 | { |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 877 | /* redirects are always GETs */ |
| 878 | HeapFree(GetProcessHeap(),0,lpwhr->lpszVerb); |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 879 | lpwhr->lpszVerb = WININET_strdupW(szGET); |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 880 | HTTP_DrainContent(lpwhr); |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 881 | rc = HTTP_HandleRedirect(lpwhr, szNewLocation); |
| 882 | if (rc) |
| 883 | rc = HTTP_HttpSendRequestW(lpwhr, NULL, 0, NULL, 0, 0, TRUE); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
Nigel Liang | 7d2ac20 | 2007-10-17 17:07:41 -0700 | [diff] [blame] | 888 | WININET_Release( &lpwhr->hdr ); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 889 | TRACE("%i <--\n",rc); |
| 890 | return rc; |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 891 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 892 | |
| 893 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 894 | * HttpOpenRequestW (WININET.@) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 895 | * |
| 896 | * Open a HTTP request handle |
| 897 | * |
| 898 | * RETURNS |
| 899 | * HINTERNET a HTTP request handle on success |
| 900 | * NULL on failure |
| 901 | * |
| 902 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 903 | HINTERNET WINAPI HttpOpenRequestW(HINTERNET hHttpSession, |
| 904 | LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, |
| 905 | LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes, |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 906 | DWORD dwFlags, DWORD_PTR dwContext) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 907 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 908 | LPWININETHTTPSESSIONW lpwhs; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 909 | HINTERNET handle = NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 910 | |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 911 | TRACE("(%p, %s, %s, %s, %s, %p, %08x, %08lx)\n", hHttpSession, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 912 | debugstr_w(lpszVerb), debugstr_w(lpszObjectName), |
| 913 | debugstr_w(lpszVersion), debugstr_w(lpszReferrer), lpszAcceptTypes, |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 914 | dwFlags, dwContext); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 915 | if(lpszAcceptTypes!=NULL) |
| 916 | { |
| 917 | int i; |
| 918 | for(i=0;lpszAcceptTypes[i]!=NULL;i++) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 919 | TRACE("\taccept type: %s\n",debugstr_w(lpszAcceptTypes[i])); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 920 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 921 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 922 | lpwhs = (LPWININETHTTPSESSIONW) WININET_GetObject( hHttpSession ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 923 | if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION) |
| 924 | { |
| 925 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 926 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 927 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 928 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 929 | /* |
| 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. |
| 934 | * |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 935 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 936 | handle = HTTP_HttpOpenRequestW(lpwhs, lpszVerb, lpszObjectName, |
| 937 | lpszVersion, lpszReferrer, lpszAcceptTypes, |
| 938 | dwFlags, dwContext); |
| 939 | lend: |
| 940 | if( lpwhs ) |
| 941 | WININET_Release( &lpwhs->hdr ); |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 942 | TRACE("returning %p\n", handle); |
| 943 | return handle; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 944 | } |
| 945 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 946 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 947 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 948 | * HttpOpenRequestA (WININET.@) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 949 | * |
| 950 | * Open a HTTP request handle |
| 951 | * |
| 952 | * RETURNS |
| 953 | * HINTERNET a HTTP request handle on success |
| 954 | * NULL on failure |
| 955 | * |
| 956 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 957 | HINTERNET WINAPI HttpOpenRequestA(HINTERNET hHttpSession, |
| 958 | LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion, |
| 959 | LPCSTR lpszReferrer , LPCSTR *lpszAcceptTypes, |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 960 | DWORD dwFlags, DWORD_PTR dwContext) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 961 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 962 | LPWSTR szVerb = NULL, szObjectName = NULL; |
| 963 | LPWSTR szVersion = NULL, szReferrer = NULL, *szAcceptTypes = NULL; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 964 | INT len; |
| 965 | INT acceptTypesCount; |
| 966 | HINTERNET rc = FALSE; |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 967 | TRACE("(%p, %s, %s, %s, %s, %p, %08x, %08lx)\n", hHttpSession, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 968 | debugstr_a(lpszVerb), debugstr_a(lpszObjectName), |
| 969 | debugstr_a(lpszVersion), debugstr_a(lpszReferrer), lpszAcceptTypes, |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 970 | dwFlags, dwContext); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 971 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 972 | if (lpszVerb) |
| 973 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 974 | len = MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, NULL, 0 ); |
| 975 | szVerb = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) ); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 976 | if ( !szVerb ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 977 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 978 | MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, szVerb, len); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | if (lpszObjectName) |
| 982 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 983 | len = MultiByteToWideChar(CP_ACP, 0, lpszObjectName, -1, NULL, 0 ); |
| 984 | szObjectName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) ); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 985 | if ( !szObjectName ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 986 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 987 | MultiByteToWideChar(CP_ACP, 0, lpszObjectName, -1, szObjectName, len ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | if (lpszVersion) |
| 991 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 992 | len = MultiByteToWideChar(CP_ACP, 0, lpszVersion, -1, NULL, 0 ); |
| 993 | szVersion = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 994 | if ( !szVersion ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 995 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 996 | MultiByteToWideChar(CP_ACP, 0, lpszVersion, -1, szVersion, len ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | if (lpszReferrer) |
| 1000 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1001 | len = MultiByteToWideChar(CP_ACP, 0, lpszReferrer, -1, NULL, 0 ); |
| 1002 | szReferrer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 1003 | if ( !szReferrer ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1004 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1005 | MultiByteToWideChar(CP_ACP, 0, lpszReferrer, -1, szReferrer, len ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | acceptTypesCount = 0; |
| 1009 | if (lpszAcceptTypes) |
| 1010 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1011 | /* find out how many there are */ |
Hans Leidekker | 2024f68 | 2007-02-12 15:19:17 +0100 | [diff] [blame] | 1012 | while (lpszAcceptTypes[acceptTypesCount] && *lpszAcceptTypes[acceptTypesCount]) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1013 | acceptTypesCount++; |
| 1014 | szAcceptTypes = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR *) * (acceptTypesCount+1)); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1015 | acceptTypesCount = 0; |
Hans Leidekker | 2024f68 | 2007-02-12 15:19:17 +0100 | [diff] [blame] | 1016 | while (lpszAcceptTypes[acceptTypesCount] && *lpszAcceptTypes[acceptTypesCount]) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1017 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1018 | len = MultiByteToWideChar(CP_ACP, 0, lpszAcceptTypes[acceptTypesCount], |
| 1019 | -1, NULL, 0 ); |
| 1020 | szAcceptTypes[acceptTypesCount] = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 1021 | if (!szAcceptTypes[acceptTypesCount] ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1022 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1023 | MultiByteToWideChar(CP_ACP, 0, lpszAcceptTypes[acceptTypesCount], |
| 1024 | -1, szAcceptTypes[acceptTypesCount], len ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1025 | acceptTypesCount++; |
| 1026 | } |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1027 | szAcceptTypes[acceptTypesCount] = NULL; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1028 | } |
| 1029 | else szAcceptTypes = 0; |
| 1030 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1031 | rc = HttpOpenRequestW(hHttpSession, szVerb, szObjectName, |
| 1032 | szVersion, szReferrer, |
| 1033 | (LPCWSTR*)szAcceptTypes, dwFlags, dwContext); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1034 | |
| 1035 | end: |
| 1036 | if (szAcceptTypes) |
| 1037 | { |
| 1038 | acceptTypesCount = 0; |
| 1039 | while (szAcceptTypes[acceptTypesCount]) |
| 1040 | { |
| 1041 | HeapFree(GetProcessHeap(), 0, szAcceptTypes[acceptTypesCount]); |
| 1042 | acceptTypesCount++; |
| 1043 | } |
| 1044 | HeapFree(GetProcessHeap(), 0, szAcceptTypes); |
| 1045 | } |
Michael Stefaniuc | 7cb43c9 | 2004-12-21 14:42:35 +0000 | [diff] [blame] | 1046 | HeapFree(GetProcessHeap(), 0, szReferrer); |
| 1047 | HeapFree(GetProcessHeap(), 0, szVersion); |
| 1048 | HeapFree(GetProcessHeap(), 0, szObjectName); |
| 1049 | HeapFree(GetProcessHeap(), 0, szVerb); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1050 | |
| 1051 | return rc; |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1052 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1053 | |
| 1054 | /*********************************************************************** |
Rob Shearman | a9ebc70 | 2007-01-12 19:17:20 -0600 | [diff] [blame] | 1055 | * HTTP_EncodeBase64 |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1056 | */ |
Rob Shearman | a9ebc70 | 2007-01-12 19:17:20 -0600 | [diff] [blame] | 1057 | static UINT HTTP_EncodeBase64( LPCSTR bin, unsigned int len, LPWSTR base64 ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1058 | { |
| 1059 | UINT n = 0, x; |
Andrew Talbot | 46fc9c2 | 2007-02-24 21:55:12 +0000 | [diff] [blame] | 1060 | static const CHAR HTTP_Base64Enc[] = |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1061 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 1062 | |
Rob Shearman | a9ebc70 | 2007-01-12 19:17:20 -0600 | [diff] [blame] | 1063 | while( len > 0 ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1064 | { |
| 1065 | /* first 6 bits, all from bin[0] */ |
| 1066 | base64[n++] = HTTP_Base64Enc[(bin[0] & 0xfc) >> 2]; |
| 1067 | x = (bin[0] & 3) << 4; |
| 1068 | |
| 1069 | /* next 6 bits, 2 from bin[0] and 4 from bin[1] */ |
Rob Shearman | a9ebc70 | 2007-01-12 19:17:20 -0600 | [diff] [blame] | 1070 | if( len == 1 ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1071 | { |
| 1072 | base64[n++] = HTTP_Base64Enc[x]; |
| 1073 | base64[n++] = '='; |
| 1074 | base64[n++] = '='; |
| 1075 | break; |
| 1076 | } |
| 1077 | base64[n++] = HTTP_Base64Enc[ x | ( (bin[1]&0xf0) >> 4 ) ]; |
| 1078 | x = ( bin[1] & 0x0f ) << 2; |
| 1079 | |
| 1080 | /* next 6 bits 4 from bin[1] and 2 from bin[2] */ |
Rob Shearman | a9ebc70 | 2007-01-12 19:17:20 -0600 | [diff] [blame] | 1081 | if( len == 2 ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1082 | { |
| 1083 | base64[n++] = HTTP_Base64Enc[x]; |
| 1084 | base64[n++] = '='; |
| 1085 | break; |
| 1086 | } |
| 1087 | base64[n++] = HTTP_Base64Enc[ x | ( (bin[2]&0xc0 ) >> 6 ) ]; |
| 1088 | |
| 1089 | /* last 6 bits, all from bin [2] */ |
| 1090 | base64[n++] = HTTP_Base64Enc[ bin[2] & 0x3f ]; |
| 1091 | bin += 3; |
Rob Shearman | a9ebc70 | 2007-01-12 19:17:20 -0600 | [diff] [blame] | 1092 | len -= 3; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1093 | } |
| 1094 | base64[n] = 0; |
| 1095 | return n; |
| 1096 | } |
| 1097 | |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 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] = |
| 1103 | { |
| 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), |
| 1130 | }; |
| 1131 | #undef CH |
| 1132 | |
| 1133 | /*********************************************************************** |
| 1134 | * HTTP_DecodeBase64 |
| 1135 | */ |
| 1136 | static UINT HTTP_DecodeBase64( LPCWSTR base64, LPSTR bin ) |
| 1137 | { |
| 1138 | unsigned int n = 0; |
| 1139 | |
| 1140 | while(*base64) |
| 1141 | { |
| 1142 | signed char in[4]; |
| 1143 | |
Rob Shearman | f8f9dbb | 2008-02-15 10:06:32 +0000 | [diff] [blame] | 1144 | if (base64[0] >= ARRAYSIZE(HTTP_Base64Dec) || |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1145 | ((in[0] = HTTP_Base64Dec[base64[0]]) == -1) || |
Rob Shearman | f8f9dbb | 2008-02-15 10:06:32 +0000 | [diff] [blame] | 1146 | base64[1] >= ARRAYSIZE(HTTP_Base64Dec) || |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1147 | ((in[1] = HTTP_Base64Dec[base64[1]]) == -1)) |
| 1148 | { |
| 1149 | WARN("invalid base64: %s\n", debugstr_w(base64)); |
| 1150 | return 0; |
| 1151 | } |
| 1152 | if (bin) |
| 1153 | bin[n] = (unsigned char) (in[0] << 2 | in[1] >> 4); |
| 1154 | n++; |
| 1155 | |
| 1156 | if ((base64[2] == '=') && (base64[3] == '=')) |
| 1157 | break; |
| 1158 | if (base64[2] > ARRAYSIZE(HTTP_Base64Dec) || |
| 1159 | ((in[2] = HTTP_Base64Dec[base64[2]]) == -1)) |
| 1160 | { |
| 1161 | WARN("invalid base64: %s\n", debugstr_w(&base64[2])); |
| 1162 | return 0; |
| 1163 | } |
| 1164 | if (bin) |
| 1165 | bin[n] = (unsigned char) (in[1] << 4 | in[2] >> 2); |
| 1166 | n++; |
| 1167 | |
| 1168 | if (base64[3] == '=') |
| 1169 | break; |
| 1170 | if (base64[3] > ARRAYSIZE(HTTP_Base64Dec) || |
| 1171 | ((in[3] = HTTP_Base64Dec[base64[3]]) == -1)) |
| 1172 | { |
| 1173 | WARN("invalid base64: %s\n", debugstr_w(&base64[3])); |
| 1174 | return 0; |
| 1175 | } |
| 1176 | if (bin) |
| 1177 | bin[n] = (unsigned char) (((in[2] << 6) & 0xc0) | in[3]); |
| 1178 | n++; |
| 1179 | |
| 1180 | base64 += 4; |
| 1181 | } |
| 1182 | |
| 1183 | return n; |
| 1184 | } |
| 1185 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1186 | /*********************************************************************** |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 1187 | * HTTP_InsertAuthorizationForHeader |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1188 | * |
| 1189 | * Insert or delete the authorization field in the request header. |
| 1190 | */ |
Rob Shearman | ebaa4d9 | 2008-03-12 13:27:46 +0000 | [diff] [blame] | 1191 | static BOOL HTTP_InsertAuthorization( LPWININETHTTPREQW lpwhr, struct HttpAuthInfo *pAuthInfo, LPCWSTR header ) |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1192 | { |
Rob Shearman | ebaa4d9 | 2008-03-12 13:27:46 +0000 | [diff] [blame] | 1193 | if (pAuthInfo) |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1194 | { |
| 1195 | static const WCHAR wszSpace[] = {' ',0}; |
Rob Shearman | 01826e0 | 2007-11-27 14:19:50 +0000 | [diff] [blame] | 1196 | static const WCHAR wszBasic[] = {'B','a','s','i','c',0}; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1197 | unsigned int len; |
Rob Shearman | ebaa4d9 | 2008-03-12 13:27:46 +0000 | [diff] [blame] | 1198 | WCHAR *authorization = NULL; |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1199 | |
Rob Shearman | ebaa4d9 | 2008-03-12 13:27:46 +0000 | [diff] [blame] | 1200 | if (pAuthInfo->auth_data_len) |
Rob Shearman | 01826e0 | 2007-11-27 14:19:50 +0000 | [diff] [blame] | 1201 | { |
Rob Shearman | ebaa4d9 | 2008-03-12 13:27:46 +0000 | [diff] [blame] | 1202 | /* scheme + space + base64 encoded data (3/2/1 bytes data -> 4 bytes of characters) */ |
| 1203 | len = strlenW(pAuthInfo->scheme)+1+((pAuthInfo->auth_data_len+2)*4)/3; |
| 1204 | authorization = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR)); |
| 1205 | if (!authorization) |
| 1206 | return FALSE; |
| 1207 | |
| 1208 | strcpyW(authorization, pAuthInfo->scheme); |
| 1209 | strcatW(authorization, wszSpace); |
| 1210 | HTTP_EncodeBase64(pAuthInfo->auth_data, |
| 1211 | pAuthInfo->auth_data_len, |
| 1212 | authorization+strlenW(authorization)); |
| 1213 | |
| 1214 | /* clear the data as it isn't valid now that it has been sent to the |
| 1215 | * server, unless it's Basic authentication which doesn't do |
| 1216 | * connection tracking */ |
| 1217 | if (strcmpiW(pAuthInfo->scheme, wszBasic)) |
| 1218 | { |
| 1219 | HeapFree(GetProcessHeap(), 0, pAuthInfo->auth_data); |
| 1220 | pAuthInfo->auth_data = NULL; |
| 1221 | pAuthInfo->auth_data_len = 0; |
| 1222 | } |
Rob Shearman | 01826e0 | 2007-11-27 14:19:50 +0000 | [diff] [blame] | 1223 | } |
Rob Shearman | ebaa4d9 | 2008-03-12 13:27:46 +0000 | [diff] [blame] | 1224 | |
| 1225 | TRACE("Inserting authorization: %s\n", debugstr_w(authorization)); |
| 1226 | |
| 1227 | HTTP_ProcessHeader(lpwhr, header, authorization, HTTP_ADDHDR_FLAG_REQ | HTTP_ADDHDR_FLAG_REPLACE); |
| 1228 | |
| 1229 | HeapFree(GetProcessHeap(), 0, authorization); |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1230 | } |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1231 | return TRUE; |
| 1232 | } |
| 1233 | |
Hans Leidekker | 0ffe9f5 | 2008-03-30 19:16:52 +0100 | [diff] [blame] | 1234 | static WCHAR *HTTP_BuildProxyRequestUrl(WININETHTTPREQW *req) |
| 1235 | { |
Hans Leidekker | 612f3c1 | 2008-03-31 20:26:16 +0200 | [diff] [blame^] | 1236 | WCHAR new_location[INTERNET_MAX_URL_LENGTH], *url; |
Hans Leidekker | 0ffe9f5 | 2008-03-30 19:16:52 +0100 | [diff] [blame] | 1237 | DWORD size; |
| 1238 | |
| 1239 | size = sizeof(new_location); |
| 1240 | if (HTTP_HttpQueryInfoW(req, HTTP_QUERY_LOCATION, new_location, &size, NULL)) |
| 1241 | { |
| 1242 | if (!(url = HeapAlloc( GetProcessHeap(), 0, size + sizeof(WCHAR) ))) return NULL; |
| 1243 | strcpyW( url, new_location ); |
| 1244 | } |
| 1245 | else |
| 1246 | { |
| 1247 | static const WCHAR slash[] = { '/',0 }; |
| 1248 | static const WCHAR format[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 }; |
| 1249 | WININETHTTPSESSIONW *session = req->lpHttpSession; |
| 1250 | |
| 1251 | size = 15; /* "http://" + sizeof(port#) + ":/\0" */ |
| 1252 | size += strlenW( session->lpszHostName ) + strlenW( req->lpszPath ); |
| 1253 | |
| 1254 | if (!(url = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE; |
| 1255 | |
| 1256 | sprintfW( url, format, session->lpszHostName, session->nHostPort ); |
| 1257 | if (req->lpszPath[0] != '/') strcatW( url, slash ); |
| 1258 | strcatW( url, req->lpszPath ); |
| 1259 | } |
| 1260 | TRACE("url=%s\n", debugstr_w(url)); |
| 1261 | return url; |
| 1262 | } |
| 1263 | |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 1264 | /*********************************************************************** |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1265 | * HTTP_DealWithProxy |
| 1266 | */ |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 1267 | static BOOL HTTP_DealWithProxy( LPWININETAPPINFOW hIC, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1268 | LPWININETHTTPSESSIONW lpwhs, LPWININETHTTPREQW lpwhr) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1269 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1270 | WCHAR buf[MAXHOSTNAME]; |
| 1271 | WCHAR proxy[MAXHOSTNAME + 15]; /* 15 == "http://" + sizeof(port#) + ":/\0" */ |
Hans Leidekker | 781f3f7 | 2006-10-13 15:43:54 +0200 | [diff] [blame] | 1272 | static WCHAR szNul[] = { 0 }; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1273 | URL_COMPONENTSW UrlComponents; |
Hans Leidekker | 0ffe9f5 | 2008-03-30 19:16:52 +0100 | [diff] [blame] | 1274 | static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/',0 }; |
| 1275 | static const WCHAR szFormat[] = { 'h','t','t','p',':','/','/','%','s',0 }; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1276 | |
| 1277 | memset( &UrlComponents, 0, sizeof UrlComponents ); |
| 1278 | UrlComponents.dwStructSize = sizeof UrlComponents; |
| 1279 | UrlComponents.lpszHostName = buf; |
| 1280 | UrlComponents.dwHostNameLength = MAXHOSTNAME; |
| 1281 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1282 | if( CSTR_EQUAL != CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, |
Robert Shearman | cc44f3a | 2005-11-28 11:31:11 +0100 | [diff] [blame] | 1283 | hIC->lpszProxy,strlenW(szHttp),szHttp,strlenW(szHttp)) ) |
Hans Leidekker | 0ffe9f5 | 2008-03-30 19:16:52 +0100 | [diff] [blame] | 1284 | sprintfW(proxy, szFormat, hIC->lpszProxy); |
Uwe Bonnes | 599c452 | 2003-12-15 19:47:31 +0000 | [diff] [blame] | 1285 | else |
Robert Shearman | cc44f3a | 2005-11-28 11:31:11 +0100 | [diff] [blame] | 1286 | strcpyW(proxy, hIC->lpszProxy); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1287 | if( !InternetCrackUrlW(proxy, 0, 0, &UrlComponents) ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1288 | return FALSE; |
| 1289 | if( UrlComponents.dwHostNameLength == 0 ) |
| 1290 | return FALSE; |
| 1291 | |
| 1292 | if( !lpwhr->lpszPath ) |
Hans Leidekker | 781f3f7 | 2006-10-13 15:43:54 +0200 | [diff] [blame] | 1293 | lpwhr->lpszPath = szNul; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1294 | |
| 1295 | if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER) |
| 1296 | UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT; |
| 1297 | |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 1298 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1299 | lpwhs->lpszServerName = WININET_strdupW(UrlComponents.lpszHostName); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1300 | lpwhs->nServerPort = UrlComponents.nPort; |
| 1301 | |
Hans Leidekker | 729631d | 2008-03-31 20:25:40 +0200 | [diff] [blame] | 1302 | TRACE("proxy server=%s port=%d\n", debugstr_w(lpwhs->lpszServerName), lpwhs->nServerPort); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1303 | return TRUE; |
| 1304 | } |
| 1305 | |
Rob Shearman | 72575a0 | 2006-12-07 00:52:50 +0000 | [diff] [blame] | 1306 | static BOOL HTTP_ResolveName(LPWININETHTTPREQW lpwhr) |
| 1307 | { |
| 1308 | char szaddr[32]; |
| 1309 | LPWININETHTTPSESSIONW lpwhs = lpwhr->lpHttpSession; |
| 1310 | |
| 1311 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 1312 | INTERNET_STATUS_RESOLVING_NAME, |
| 1313 | lpwhs->lpszServerName, |
| 1314 | strlenW(lpwhs->lpszServerName)+1); |
| 1315 | |
| 1316 | if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort, |
| 1317 | &lpwhs->socketAddress)) |
| 1318 | { |
| 1319 | INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED); |
| 1320 | return FALSE; |
| 1321 | } |
| 1322 | |
| 1323 | inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr, |
| 1324 | szaddr, sizeof(szaddr)); |
| 1325 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 1326 | INTERNET_STATUS_NAME_RESOLVED, |
| 1327 | szaddr, strlen(szaddr)+1); |
| 1328 | return TRUE; |
| 1329 | } |
| 1330 | |
Jacek Caban | 5a535d6 | 2008-02-26 20:20:41 +0100 | [diff] [blame] | 1331 | |
| 1332 | /*********************************************************************** |
| 1333 | * HTTPREQ_Destroy (internal) |
| 1334 | * |
| 1335 | * Deallocate request handle |
| 1336 | * |
| 1337 | */ |
| 1338 | static void HTTPREQ_Destroy(WININETHANDLEHEADER *hdr) |
| 1339 | { |
| 1340 | LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) hdr; |
| 1341 | DWORD i; |
| 1342 | |
| 1343 | TRACE("\n"); |
| 1344 | |
| 1345 | if(lpwhr->hCacheFile) |
| 1346 | CloseHandle(lpwhr->hCacheFile); |
| 1347 | |
| 1348 | if(lpwhr->lpszCacheFile) { |
| 1349 | DeleteFileW(lpwhr->lpszCacheFile); /* FIXME */ |
| 1350 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszCacheFile); |
| 1351 | } |
| 1352 | |
| 1353 | WININET_Release(&lpwhr->lpHttpSession->hdr); |
| 1354 | |
| 1355 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath); |
| 1356 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb); |
| 1357 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders); |
| 1358 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszVersion); |
| 1359 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszStatusText); |
| 1360 | |
| 1361 | for (i = 0; i < lpwhr->nCustHeaders; i++) |
| 1362 | { |
| 1363 | HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszField); |
| 1364 | HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszValue); |
| 1365 | } |
| 1366 | |
| 1367 | HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders); |
| 1368 | HeapFree(GetProcessHeap(), 0, lpwhr); |
| 1369 | } |
| 1370 | |
Jacek Caban | 7dc9bf6 | 2008-02-26 20:21:00 +0100 | [diff] [blame] | 1371 | static void HTTPREQ_CloseConnection(WININETHANDLEHEADER *hdr) |
| 1372 | { |
| 1373 | LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) hdr; |
| 1374 | LPWININETHTTPSESSIONW lpwhs = NULL; |
| 1375 | LPWININETAPPINFOW hIC = NULL; |
| 1376 | |
| 1377 | TRACE("%p\n",lpwhr); |
| 1378 | |
| 1379 | if (!NETCON_connected(&lpwhr->netConnection)) |
| 1380 | return; |
| 1381 | |
| 1382 | if (lpwhr->pAuthInfo) |
| 1383 | { |
Rob Shearman | 8c6ac00 | 2008-03-10 16:39:40 +0000 | [diff] [blame] | 1384 | if (SecIsValidHandle(&lpwhr->pAuthInfo->ctx)) |
| 1385 | DeleteSecurityContext(&lpwhr->pAuthInfo->ctx); |
| 1386 | if (SecIsValidHandle(&lpwhr->pAuthInfo->cred)) |
| 1387 | FreeCredentialsHandle(&lpwhr->pAuthInfo->cred); |
Jacek Caban | 7dc9bf6 | 2008-02-26 20:21:00 +0100 | [diff] [blame] | 1388 | |
| 1389 | HeapFree(GetProcessHeap(), 0, lpwhr->pAuthInfo->auth_data); |
| 1390 | HeapFree(GetProcessHeap(), 0, lpwhr->pAuthInfo->scheme); |
| 1391 | HeapFree(GetProcessHeap(), 0, lpwhr->pAuthInfo); |
| 1392 | lpwhr->pAuthInfo = NULL; |
| 1393 | } |
| 1394 | if (lpwhr->pProxyAuthInfo) |
| 1395 | { |
Rob Shearman | 8c6ac00 | 2008-03-10 16:39:40 +0000 | [diff] [blame] | 1396 | if (SecIsValidHandle(&lpwhr->pProxyAuthInfo->ctx)) |
| 1397 | DeleteSecurityContext(&lpwhr->pProxyAuthInfo->ctx); |
| 1398 | if (SecIsValidHandle(&lpwhr->pProxyAuthInfo->cred)) |
| 1399 | FreeCredentialsHandle(&lpwhr->pProxyAuthInfo->cred); |
Jacek Caban | 7dc9bf6 | 2008-02-26 20:21:00 +0100 | [diff] [blame] | 1400 | |
| 1401 | HeapFree(GetProcessHeap(), 0, lpwhr->pProxyAuthInfo->auth_data); |
| 1402 | HeapFree(GetProcessHeap(), 0, lpwhr->pProxyAuthInfo->scheme); |
| 1403 | HeapFree(GetProcessHeap(), 0, lpwhr->pProxyAuthInfo); |
| 1404 | lpwhr->pProxyAuthInfo = NULL; |
| 1405 | } |
| 1406 | |
| 1407 | lpwhs = lpwhr->lpHttpSession; |
| 1408 | hIC = lpwhs->lpAppInfo; |
| 1409 | |
| 1410 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 1411 | INTERNET_STATUS_CLOSING_CONNECTION, 0, 0); |
| 1412 | |
| 1413 | NETCON_close(&lpwhr->netConnection); |
| 1414 | |
| 1415 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 1416 | INTERNET_STATUS_CONNECTION_CLOSED, 0, 0); |
| 1417 | } |
| 1418 | |
Jacek Caban | e2933c2 | 2008-03-12 02:23:20 +0100 | [diff] [blame] | 1419 | static DWORD HTTPREQ_QueryOption(WININETHANDLEHEADER *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode) |
| 1420 | { |
Jacek Caban | 0e010d8 | 2008-03-12 02:23:48 +0100 | [diff] [blame] | 1421 | WININETHTTPREQW *req = (WININETHTTPREQW*)hdr; |
| 1422 | |
Jacek Caban | e2933c2 | 2008-03-12 02:23:20 +0100 | [diff] [blame] | 1423 | switch(option) { |
| 1424 | case INTERNET_OPTION_HANDLE_TYPE: |
| 1425 | TRACE("INTERNET_OPTION_HANDLE_TYPE\n"); |
| 1426 | |
| 1427 | if (*size < sizeof(ULONG)) |
| 1428 | return ERROR_INSUFFICIENT_BUFFER; |
| 1429 | |
| 1430 | *size = sizeof(DWORD); |
| 1431 | *(DWORD*)buffer = INTERNET_HANDLE_TYPE_HTTP_REQUEST; |
| 1432 | return ERROR_SUCCESS; |
Jacek Caban | 0e010d8 | 2008-03-12 02:23:48 +0100 | [diff] [blame] | 1433 | |
| 1434 | case INTERNET_OPTION_URL: { |
| 1435 | WCHAR url[INTERNET_MAX_URL_LENGTH]; |
| 1436 | HTTPHEADERW *host; |
| 1437 | DWORD len; |
| 1438 | |
| 1439 | static const WCHAR formatW[] = {'h','t','t','p',':','/','/','%','s','%','s',0}; |
| 1440 | static const WCHAR hostW[] = {'H','o','s','t',0}; |
| 1441 | |
| 1442 | TRACE("INTERNET_OPTION_URL\n"); |
| 1443 | |
| 1444 | host = HTTP_GetHeader(req, hostW); |
| 1445 | sprintfW(url, formatW, host->lpszValue, req->lpszPath); |
| 1446 | TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url)); |
| 1447 | |
| 1448 | if(unicode) { |
| 1449 | len = (strlenW(url)+1) * sizeof(WCHAR); |
| 1450 | if(*size < len) |
| 1451 | return ERROR_INSUFFICIENT_BUFFER; |
| 1452 | |
| 1453 | *size = len; |
| 1454 | strcpyW(buffer, url); |
| 1455 | return ERROR_SUCCESS; |
| 1456 | }else { |
| 1457 | len = WideCharToMultiByte(CP_ACP, 0, url, -1, buffer, *size, NULL, NULL); |
| 1458 | if(len > *size) |
| 1459 | return ERROR_INSUFFICIENT_BUFFER; |
| 1460 | |
| 1461 | *size = len; |
| 1462 | return ERROR_SUCCESS; |
| 1463 | } |
| 1464 | } |
Jacek Caban | ce6a228 | 2008-03-12 02:24:06 +0100 | [diff] [blame] | 1465 | |
| 1466 | case INTERNET_OPTION_DATAFILE_NAME: { |
| 1467 | DWORD req_size; |
| 1468 | |
| 1469 | TRACE("INTERNET_OPTION_DATAFILE_NAME\n"); |
| 1470 | |
| 1471 | if(!req->lpszCacheFile) { |
| 1472 | *size = 0; |
| 1473 | return ERROR_INTERNET_ITEM_NOT_FOUND; |
| 1474 | } |
| 1475 | |
| 1476 | if(unicode) { |
| 1477 | req_size = (lstrlenW(req->lpszCacheFile)+1) * sizeof(WCHAR); |
| 1478 | if(*size < req_size) |
| 1479 | return ERROR_INSUFFICIENT_BUFFER; |
| 1480 | |
| 1481 | *size = req_size; |
| 1482 | memcpy(buffer, req->lpszCacheFile, *size); |
| 1483 | return ERROR_SUCCESS; |
| 1484 | }else { |
| 1485 | req_size = WideCharToMultiByte(CP_ACP, 0, req->lpszCacheFile, -1, NULL, 0, NULL, NULL); |
| 1486 | if (req_size > *size) |
| 1487 | return ERROR_INSUFFICIENT_BUFFER; |
| 1488 | |
| 1489 | *size = WideCharToMultiByte(CP_ACP, 0, req->lpszCacheFile, |
| 1490 | -1, buffer, *size, NULL, NULL); |
| 1491 | return ERROR_SUCCESS; |
| 1492 | } |
| 1493 | } |
Jacek Caban | 7e63f95 | 2008-03-12 02:24:23 +0100 | [diff] [blame] | 1494 | |
| 1495 | case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT: { |
| 1496 | PCCERT_CONTEXT context; |
| 1497 | |
| 1498 | if(*size < sizeof(INTERNET_CERTIFICATE_INFOW)) { |
| 1499 | *size = sizeof(INTERNET_CERTIFICATE_INFOW); |
| 1500 | return ERROR_INSUFFICIENT_BUFFER; |
| 1501 | } |
| 1502 | |
| 1503 | context = (PCCERT_CONTEXT)NETCON_GetCert(&(req->netConnection)); |
| 1504 | if(context) { |
| 1505 | INTERNET_CERTIFICATE_INFOW *info = (INTERNET_CERTIFICATE_INFOW*)buffer; |
| 1506 | DWORD len; |
| 1507 | |
| 1508 | memset(info, 0, sizeof(INTERNET_CERTIFICATE_INFOW)); |
| 1509 | info->ftExpiry = context->pCertInfo->NotAfter; |
| 1510 | info->ftStart = context->pCertInfo->NotBefore; |
| 1511 | if(unicode) { |
| 1512 | len = CertNameToStrW(context->dwCertEncodingType, |
| 1513 | &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR, NULL, 0); |
| 1514 | info->lpszSubjectInfo = LocalAlloc(0, len*sizeof(WCHAR)); |
| 1515 | if(info->lpszSubjectInfo) |
| 1516 | CertNameToStrW(context->dwCertEncodingType, |
| 1517 | &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR, |
| 1518 | info->lpszSubjectInfo, len); |
| 1519 | len = CertNameToStrW(context->dwCertEncodingType, |
| 1520 | &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR, NULL, 0); |
| 1521 | info->lpszIssuerInfo = LocalAlloc(0, len*sizeof(WCHAR)); |
| 1522 | if (info->lpszIssuerInfo) |
| 1523 | CertNameToStrW(context->dwCertEncodingType, |
| 1524 | &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR, |
| 1525 | info->lpszIssuerInfo, len); |
| 1526 | }else { |
| 1527 | INTERNET_CERTIFICATE_INFOA *infoA = (INTERNET_CERTIFICATE_INFOA*)info; |
| 1528 | |
| 1529 | len = CertNameToStrA(context->dwCertEncodingType, |
| 1530 | &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR, NULL, 0); |
| 1531 | infoA->lpszSubjectInfo = LocalAlloc(0, len); |
| 1532 | if(infoA->lpszSubjectInfo) |
| 1533 | CertNameToStrA(context->dwCertEncodingType, |
| 1534 | &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR, |
| 1535 | infoA->lpszSubjectInfo, len); |
| 1536 | len = CertNameToStrA(context->dwCertEncodingType, |
| 1537 | &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR, NULL, 0); |
| 1538 | infoA->lpszIssuerInfo = LocalAlloc(0, len); |
| 1539 | if(infoA->lpszIssuerInfo) |
| 1540 | CertNameToStrA(context->dwCertEncodingType, |
| 1541 | &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR, |
| 1542 | infoA->lpszIssuerInfo, len); |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | * Contrary to MSDN, these do not appear to be set. |
| 1547 | * lpszProtocolName |
| 1548 | * lpszSignatureAlgName |
| 1549 | * lpszEncryptionAlgName |
| 1550 | * dwKeySize |
| 1551 | */ |
| 1552 | CertFreeCertificateContext(context); |
| 1553 | return ERROR_SUCCESS; |
| 1554 | } |
| 1555 | } |
Jacek Caban | e2933c2 | 2008-03-12 02:23:20 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | FIXME("Not implemented option %d\n", option); |
| 1559 | return ERROR_INTERNET_INVALID_OPTION; |
| 1560 | } |
| 1561 | |
Jacek Caban | 0e33eee | 2008-02-26 20:22:02 +0100 | [diff] [blame] | 1562 | static DWORD HTTPREQ_SetOption(WININETHANDLEHEADER *hdr, DWORD option, void *buffer, DWORD size) |
| 1563 | { |
| 1564 | WININETHTTPREQW *req = (WININETHTTPREQW*)hdr; |
| 1565 | |
| 1566 | switch(option) { |
| 1567 | case INTERNET_OPTION_SEND_TIMEOUT: |
| 1568 | case INTERNET_OPTION_RECEIVE_TIMEOUT: |
| 1569 | TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n"); |
| 1570 | |
| 1571 | if (size != sizeof(DWORD)) |
| 1572 | return ERROR_INVALID_PARAMETER; |
| 1573 | |
| 1574 | return NETCON_set_timeout(&req->netConnection, option == INTERNET_OPTION_SEND_TIMEOUT, |
| 1575 | *(DWORD*)buffer); |
| 1576 | } |
| 1577 | |
| 1578 | return ERROR_INTERNET_INVALID_OPTION; |
| 1579 | } |
| 1580 | |
Hans Leidekker | 058761f | 2008-03-26 22:22:04 +0100 | [diff] [blame] | 1581 | static DWORD HTTP_Read(WININETHTTPREQW *req, void *buffer, DWORD size, DWORD *read, BOOL sync) |
Jacek Caban | 3b4ca69 | 2008-03-02 19:35:11 +0100 | [diff] [blame] | 1582 | { |
| 1583 | int bytes_read; |
| 1584 | |
| 1585 | if(!NETCON_recv(&req->netConnection, buffer, min(size, req->dwContentLength - req->dwContentRead), |
| 1586 | sync ? MSG_WAITALL : 0, &bytes_read)) { |
| 1587 | if(req->dwContentLength != -1 && req->dwContentRead != req->dwContentLength) |
| 1588 | ERR("not all data received %d/%d\n", req->dwContentRead, req->dwContentLength); |
| 1589 | |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 1590 | /* always return success, even if the network layer returns an error */ |
Jacek Caban | 3b4ca69 | 2008-03-02 19:35:11 +0100 | [diff] [blame] | 1591 | *read = 0; |
| 1592 | HTTP_FinishedReading(req); |
| 1593 | return ERROR_SUCCESS; |
| 1594 | } |
| 1595 | |
| 1596 | req->dwContentRead += bytes_read; |
| 1597 | *read = bytes_read; |
| 1598 | |
| 1599 | if(req->lpszCacheFile) { |
| 1600 | BOOL res; |
| 1601 | |
| 1602 | res = WriteFile(req->hCacheFile, buffer, bytes_read, NULL, NULL); |
| 1603 | if(!res) |
| 1604 | WARN("WriteFile failed: %u\n", GetLastError()); |
| 1605 | } |
| 1606 | |
| 1607 | if(!bytes_read && (req->dwContentRead == req->dwContentLength)) |
| 1608 | HTTP_FinishedReading(req); |
| 1609 | |
| 1610 | return ERROR_SUCCESS; |
| 1611 | } |
| 1612 | |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 1613 | static DWORD get_chunk_size(const char *buffer) |
| 1614 | { |
| 1615 | const char *p; |
| 1616 | DWORD size = 0; |
| 1617 | |
| 1618 | for (p = buffer; *p; p++) |
| 1619 | { |
| 1620 | if (*p >= '0' && *p <= '9') size = size * 16 + *p - '0'; |
| 1621 | else if (*p >= 'a' && *p <= 'f') size = size * 16 + *p - 'a' + 10; |
| 1622 | else if (*p >= 'A' && *p <= 'F') size = size * 16 + *p - 'A' + 10; |
| 1623 | else if (*p == ';') break; |
| 1624 | } |
| 1625 | return size; |
| 1626 | } |
| 1627 | |
Hans Leidekker | 058761f | 2008-03-26 22:22:04 +0100 | [diff] [blame] | 1628 | static DWORD HTTP_ReadChunked(WININETHTTPREQW *req, void *buffer, DWORD size, DWORD *read, BOOL sync) |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 1629 | { |
| 1630 | char reply[MAX_REPLY_LEN], *p = buffer; |
| 1631 | DWORD buflen, to_write = size; |
| 1632 | size_t to_read; |
| 1633 | int bytes_read; |
| 1634 | |
| 1635 | *read = 0; |
| 1636 | for (;;) |
| 1637 | { |
| 1638 | if (*read == size) break; |
| 1639 | |
| 1640 | if (req->dwContentLength == ~0UL) /* new chunk */ |
| 1641 | { |
| 1642 | buflen = sizeof(reply); |
| 1643 | if (!NETCON_getNextLine(&req->netConnection, reply, &buflen)) break; |
| 1644 | |
| 1645 | if (!(req->dwContentLength = get_chunk_size(reply))) |
| 1646 | { |
| 1647 | /* zero sized chunk marks end of transfer; read any trailing headers and return */ |
| 1648 | HTTP_GetResponseHeaders(req, FALSE); |
| 1649 | break; |
| 1650 | } |
| 1651 | } |
| 1652 | to_read = min(to_write, req->dwContentLength - req->dwContentRead); |
| 1653 | |
| 1654 | if (!NETCON_recv(&req->netConnection, p, to_read, sync ? MSG_WAITALL : 0, &bytes_read)) |
| 1655 | { |
| 1656 | if (bytes_read != to_read) |
| 1657 | ERR("Not all data received %d/%d\n", bytes_read, to_read); |
| 1658 | |
| 1659 | /* always return success, even if the network layer returns an error */ |
| 1660 | *read = 0; |
| 1661 | break; |
| 1662 | } |
| 1663 | if (!bytes_read) break; |
| 1664 | |
| 1665 | req->dwContentRead += bytes_read; |
| 1666 | to_write -= bytes_read; |
| 1667 | *read += bytes_read; |
| 1668 | |
| 1669 | if (req->lpszCacheFile) |
| 1670 | { |
| 1671 | if (!WriteFile(req->hCacheFile, p, bytes_read, NULL, NULL)) |
| 1672 | WARN("WriteFile failed: %u\n", GetLastError()); |
| 1673 | } |
| 1674 | p += bytes_read; |
| 1675 | |
| 1676 | if (req->dwContentRead == req->dwContentLength) /* chunk complete */ |
| 1677 | { |
| 1678 | req->dwContentRead = 0; |
| 1679 | req->dwContentLength = ~0UL; |
| 1680 | |
| 1681 | buflen = sizeof(reply); |
| 1682 | if (!NETCON_getNextLine(&req->netConnection, reply, &buflen)) |
| 1683 | { |
| 1684 | ERR("Malformed chunk\n"); |
| 1685 | *read = 0; |
| 1686 | break; |
| 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | if (!*read) HTTP_FinishedReading(req); |
| 1691 | return ERROR_SUCCESS; |
| 1692 | } |
| 1693 | |
Hans Leidekker | 058761f | 2008-03-26 22:22:04 +0100 | [diff] [blame] | 1694 | static DWORD HTTPREQ_Read(WININETHTTPREQW *req, void *buffer, DWORD size, DWORD *read, BOOL sync) |
Jacek Caban | 3b4ca69 | 2008-03-02 19:35:11 +0100 | [diff] [blame] | 1695 | { |
Hans Leidekker | 058761f | 2008-03-26 22:22:04 +0100 | [diff] [blame] | 1696 | WCHAR encoding[20]; |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 1697 | DWORD buflen = sizeof(encoding); |
| 1698 | static const WCHAR szChunked[] = {'c','h','u','n','k','e','d',0}; |
Jacek Caban | 3b4ca69 | 2008-03-02 19:35:11 +0100 | [diff] [blame] | 1699 | |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 1700 | if (HTTP_HttpQueryInfoW(req, HTTP_QUERY_TRANSFER_ENCODING, encoding, &buflen, NULL) && |
| 1701 | !strcmpiW(encoding, szChunked)) |
| 1702 | { |
Hans Leidekker | 058761f | 2008-03-26 22:22:04 +0100 | [diff] [blame] | 1703 | return HTTP_ReadChunked(req, buffer, size, read, sync); |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 1704 | } |
| 1705 | else |
Hans Leidekker | 058761f | 2008-03-26 22:22:04 +0100 | [diff] [blame] | 1706 | return HTTP_Read(req, buffer, size, read, sync); |
| 1707 | } |
| 1708 | |
| 1709 | static DWORD HTTPREQ_ReadFile(WININETHANDLEHEADER *hdr, void *buffer, DWORD size, DWORD *read) |
| 1710 | { |
| 1711 | WININETHTTPREQW *req = (WININETHTTPREQW*)hdr; |
| 1712 | return HTTPREQ_Read(req, buffer, size, read, TRUE); |
Jacek Caban | 3b4ca69 | 2008-03-02 19:35:11 +0100 | [diff] [blame] | 1713 | } |
| 1714 | |
Jacek Caban | d597fd1 | 2008-03-03 18:07:20 +0100 | [diff] [blame] | 1715 | static void HTTPREQ_AsyncReadFileExProc(WORKREQUEST *workRequest) |
| 1716 | { |
| 1717 | struct WORKREQ_INTERNETREADFILEEXA const *data = &workRequest->u.InternetReadFileExA; |
| 1718 | WININETHTTPREQW *req = (WININETHTTPREQW*)workRequest->hdr; |
| 1719 | INTERNET_ASYNC_RESULT iar; |
| 1720 | DWORD res; |
| 1721 | |
| 1722 | TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr); |
| 1723 | |
| 1724 | res = HTTPREQ_Read(req, data->lpBuffersOut->lpvBuffer, |
| 1725 | data->lpBuffersOut->dwBufferLength, &data->lpBuffersOut->dwBufferLength, TRUE); |
| 1726 | |
| 1727 | iar.dwResult = res == ERROR_SUCCESS; |
| 1728 | iar.dwError = res; |
| 1729 | |
| 1730 | INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, |
| 1731 | INTERNET_STATUS_REQUEST_COMPLETE, &iar, |
| 1732 | sizeof(INTERNET_ASYNC_RESULT)); |
| 1733 | } |
| 1734 | |
| 1735 | static DWORD HTTPREQ_ReadFileExA(WININETHANDLEHEADER *hdr, INTERNET_BUFFERSA *buffers, |
| 1736 | DWORD flags, DWORD_PTR context) |
| 1737 | { |
| 1738 | |
| 1739 | WININETHTTPREQW *req = (WININETHTTPREQW*)hdr; |
| 1740 | DWORD res; |
| 1741 | |
| 1742 | if (flags & ~(IRF_ASYNC|IRF_NO_WAIT)) |
| 1743 | FIXME("these dwFlags aren't implemented: 0x%x\n", flags & ~(IRF_ASYNC|IRF_NO_WAIT)); |
| 1744 | |
| 1745 | if (buffers->dwStructSize != sizeof(*buffers)) |
| 1746 | return ERROR_INVALID_PARAMETER; |
| 1747 | |
| 1748 | INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0); |
| 1749 | |
Dan Hipschman | 0929593 | 2008-03-27 13:52:24 -0700 | [diff] [blame] | 1750 | if (hdr->dwFlags & INTERNET_FLAG_ASYNC) { |
Jacek Caban | d597fd1 | 2008-03-03 18:07:20 +0100 | [diff] [blame] | 1751 | DWORD available = 0; |
| 1752 | |
| 1753 | NETCON_query_data_available(&req->netConnection, &available); |
| 1754 | if (!available) |
| 1755 | { |
| 1756 | WORKREQUEST workRequest; |
| 1757 | |
| 1758 | workRequest.asyncproc = HTTPREQ_AsyncReadFileExProc; |
| 1759 | workRequest.hdr = WININET_AddRef(&req->hdr); |
| 1760 | workRequest.u.InternetReadFileExA.lpBuffersOut = buffers; |
| 1761 | |
| 1762 | INTERNET_AsyncCall(&workRequest); |
| 1763 | |
| 1764 | return ERROR_IO_PENDING; |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | res = HTTPREQ_Read(req, buffers->lpvBuffer, buffers->dwBufferLength, &buffers->dwBufferLength, |
| 1769 | !(flags & IRF_NO_WAIT)); |
| 1770 | |
| 1771 | if (res == ERROR_SUCCESS) { |
| 1772 | DWORD size = buffers->dwBufferLength; |
| 1773 | INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_RESPONSE_RECEIVED, |
| 1774 | &size, sizeof(size)); |
| 1775 | } |
| 1776 | |
| 1777 | return res; |
| 1778 | } |
| 1779 | |
Jacek Caban | 1ffcfbc | 2008-02-26 20:21:34 +0100 | [diff] [blame] | 1780 | static BOOL HTTPREQ_WriteFile(WININETHANDLEHEADER *hdr, const void *buffer, DWORD size, DWORD *written) |
| 1781 | { |
| 1782 | LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW)hdr; |
| 1783 | |
| 1784 | return NETCON_send(&lpwhr->netConnection, buffer, size, 0, (LPINT)written); |
| 1785 | } |
| 1786 | |
Jacek Caban | 3314184 | 2008-02-29 12:57:57 +0100 | [diff] [blame] | 1787 | static void HTTPREQ_AsyncQueryDataAvailableProc(WORKREQUEST *workRequest) |
| 1788 | { |
| 1789 | WININETHTTPREQW *req = (WININETHTTPREQW*)workRequest->hdr; |
| 1790 | INTERNET_ASYNC_RESULT iar; |
| 1791 | char buffer[4048]; |
| 1792 | |
| 1793 | TRACE("%p\n", workRequest->hdr); |
| 1794 | |
| 1795 | iar.dwResult = NETCON_recv(&req->netConnection, buffer, |
| 1796 | min(sizeof(buffer), req->dwContentLength - req->dwContentRead), |
| 1797 | MSG_PEEK, (int *)&iar.dwError); |
| 1798 | |
| 1799 | INTERNET_SendCallback(&req->hdr, req->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE, &iar, |
| 1800 | sizeof(INTERNET_ASYNC_RESULT)); |
| 1801 | } |
| 1802 | |
| 1803 | static DWORD HTTPREQ_QueryDataAvailable(WININETHANDLEHEADER *hdr, DWORD *available, DWORD flags, DWORD_PTR ctx) |
| 1804 | { |
| 1805 | WININETHTTPREQW *req = (WININETHTTPREQW*)hdr; |
| 1806 | BYTE buffer[4048]; |
| 1807 | BOOL async; |
| 1808 | |
| 1809 | TRACE("(%p %p %x %lx)\n", req, available, flags, ctx); |
| 1810 | |
| 1811 | if(!NETCON_query_data_available(&req->netConnection, available) || *available) |
| 1812 | return ERROR_SUCCESS; |
| 1813 | |
| 1814 | /* Even if we are in async mode, we need to determine whether |
| 1815 | * there is actually more data available. We do this by trying |
| 1816 | * to peek only a single byte in async mode. */ |
| 1817 | async = (req->lpHttpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC) != 0; |
| 1818 | |
| 1819 | if (NETCON_recv(&req->netConnection, buffer, |
| 1820 | min(async ? 1 : sizeof(buffer), req->dwContentLength - req->dwContentRead), |
| 1821 | MSG_PEEK, (int *)available) && async && *available) |
| 1822 | { |
| 1823 | WORKREQUEST workRequest; |
| 1824 | |
| 1825 | *available = 0; |
| 1826 | workRequest.asyncproc = HTTPREQ_AsyncQueryDataAvailableProc; |
| 1827 | workRequest.hdr = WININET_AddRef( &req->hdr ); |
| 1828 | |
| 1829 | INTERNET_AsyncCall(&workRequest); |
| 1830 | |
| 1831 | return ERROR_IO_PENDING; |
| 1832 | } |
| 1833 | |
| 1834 | return ERROR_SUCCESS; |
| 1835 | } |
| 1836 | |
Jacek Caban | 5a535d6 | 2008-02-26 20:20:41 +0100 | [diff] [blame] | 1837 | static const HANDLEHEADERVtbl HTTPREQVtbl = { |
Jacek Caban | 7dc9bf6 | 2008-02-26 20:21:00 +0100 | [diff] [blame] | 1838 | HTTPREQ_Destroy, |
Jacek Caban | 1ffcfbc | 2008-02-26 20:21:34 +0100 | [diff] [blame] | 1839 | HTTPREQ_CloseConnection, |
Jacek Caban | e2933c2 | 2008-03-12 02:23:20 +0100 | [diff] [blame] | 1840 | HTTPREQ_QueryOption, |
Jacek Caban | 0e33eee | 2008-02-26 20:22:02 +0100 | [diff] [blame] | 1841 | HTTPREQ_SetOption, |
Jacek Caban | 3b4ca69 | 2008-03-02 19:35:11 +0100 | [diff] [blame] | 1842 | HTTPREQ_ReadFile, |
Jacek Caban | d597fd1 | 2008-03-03 18:07:20 +0100 | [diff] [blame] | 1843 | HTTPREQ_ReadFileExA, |
Jacek Caban | 8c45eec | 2008-02-27 18:55:09 +0100 | [diff] [blame] | 1844 | HTTPREQ_WriteFile, |
Jacek Caban | 3314184 | 2008-02-29 12:57:57 +0100 | [diff] [blame] | 1845 | HTTPREQ_QueryDataAvailable, |
Jacek Caban | 8c45eec | 2008-02-27 18:55:09 +0100 | [diff] [blame] | 1846 | NULL |
Jacek Caban | 5a535d6 | 2008-02-26 20:20:41 +0100 | [diff] [blame] | 1847 | }; |
| 1848 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1849 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1850 | * HTTP_HttpOpenRequestW (internal) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1851 | * |
| 1852 | * Open a HTTP request handle |
| 1853 | * |
| 1854 | * RETURNS |
| 1855 | * HINTERNET a HTTP request handle on success |
| 1856 | * NULL on failure |
| 1857 | * |
| 1858 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1859 | HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1860 | LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, |
| 1861 | LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes, |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 1862 | DWORD dwFlags, DWORD_PTR dwContext) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1863 | { |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 1864 | LPWININETAPPINFOW hIC = NULL; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1865 | LPWININETHTTPREQW lpwhr; |
| 1866 | LPWSTR lpszCookies; |
| 1867 | LPWSTR lpszUrl = NULL; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1868 | DWORD nCookieSize; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1869 | HINTERNET handle = NULL; |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 1870 | static const WCHAR szUrlForm[] = {'h','t','t','p',':','/','/','%','s',0}; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1871 | DWORD len; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1872 | LPHTTPHEADERW Host; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1873 | |
Francois Gouget | 0edbaf7 | 2005-11-10 12:14:56 +0000 | [diff] [blame] | 1874 | TRACE("-->\n"); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1875 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1876 | assert( lpwhs->hdr.htype == WH_HHTTPSESSION ); |
Jacek Caban | a541a44 | 2006-10-29 18:49:39 +0100 | [diff] [blame] | 1877 | hIC = lpwhs->lpAppInfo; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1878 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1879 | lpwhr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPREQW)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1880 | if (NULL == lpwhr) |
| 1881 | { |
| 1882 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1883 | goto lend; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 1884 | } |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1885 | lpwhr->hdr.htype = WH_HHTTPREQ; |
Jacek Caban | 5a535d6 | 2008-02-26 20:20:41 +0100 | [diff] [blame] | 1886 | lpwhr->hdr.vtbl = &HTTPREQVtbl; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1887 | lpwhr->hdr.dwFlags = dwFlags; |
| 1888 | lpwhr->hdr.dwContext = dwContext; |
Rob Shearman | bdc81d9 | 2008-03-10 16:39:15 +0000 | [diff] [blame] | 1889 | lpwhr->hdr.refs = 1; |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 1890 | lpwhr->hdr.lpfnStatusCB = lpwhs->hdr.lpfnStatusCB; |
Jacek Caban | 5c53baa | 2006-10-30 22:14:59 +0100 | [diff] [blame] | 1891 | lpwhr->hdr.dwInternalFlags = lpwhs->hdr.dwInternalFlags & INET_CALLBACKW; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1892 | |
Jacek Caban | a9bdc01 | 2006-10-29 18:50:25 +0100 | [diff] [blame] | 1893 | WININET_AddRef( &lpwhs->hdr ); |
| 1894 | lpwhr->lpHttpSession = lpwhs; |
Misha Koshelev | 728e5fa | 2007-09-20 20:59:40 -0500 | [diff] [blame] | 1895 | list_add_head( &lpwhs->hdr.children, &lpwhr->hdr.entry ); |
Jacek Caban | a9bdc01 | 2006-10-29 18:50:25 +0100 | [diff] [blame] | 1896 | |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 1897 | handle = WININET_AllocHandle( &lpwhr->hdr ); |
| 1898 | if (NULL == handle) |
| 1899 | { |
| 1900 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1901 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
Robert Shearman | 9981f33 | 2006-03-06 17:31:09 +0000 | [diff] [blame] | 1904 | if (!NETCON_init(&lpwhr->netConnection, dwFlags & INTERNET_FLAG_SECURE)) |
| 1905 | { |
| 1906 | InternetCloseHandle( handle ); |
| 1907 | handle = NULL; |
| 1908 | goto lend; |
| 1909 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1910 | |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 1911 | if (lpszObjectName && *lpszObjectName) { |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1912 | HRESULT rc; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1913 | |
| 1914 | len = 0; |
| 1915 | rc = UrlEscapeW(lpszObjectName, NULL, &len, URL_ESCAPE_SPACES_ONLY); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1916 | if (rc != E_POINTER) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1917 | len = strlenW(lpszObjectName)+1; |
| 1918 | lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
| 1919 | rc = UrlEscapeW(lpszObjectName, lpwhr->lpszPath, &len, |
Huw D M Davies | 0aebee9 | 2001-01-21 21:09:00 +0000 | [diff] [blame] | 1920 | URL_ESCAPE_SPACES_ONLY); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1921 | if (rc) |
| 1922 | { |
Hans Leidekker | cd2c458 | 2006-10-05 13:18:56 +0200 | [diff] [blame] | 1923 | ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(lpszObjectName),rc); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1924 | strcpyW(lpwhr->lpszPath,lpszObjectName); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1925 | } |
Huw D M Davies | 0aebee9 | 2001-01-21 21:09:00 +0000 | [diff] [blame] | 1926 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1927 | |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 1928 | if (lpszReferrer && *lpszReferrer) |
Hans Leidekker | 4d84eb2 | 2008-01-04 13:14:00 +0100 | [diff] [blame] | 1929 | HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpszReferrer, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1930 | |
Hans Leidekker | 2024f68 | 2007-02-12 15:19:17 +0100 | [diff] [blame] | 1931 | if (lpszAcceptTypes) |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1932 | { |
| 1933 | int i; |
Hans Leidekker | 2024f68 | 2007-02-12 15:19:17 +0100 | [diff] [blame] | 1934 | for (i = 0; lpszAcceptTypes[i]; i++) |
| 1935 | { |
| 1936 | if (!*lpszAcceptTypes[i]) continue; |
Rob Shearman | a9c2cfa | 2007-01-07 12:53:50 +0000 | [diff] [blame] | 1937 | HTTP_ProcessHeader(lpwhr, HTTP_ACCEPT, lpszAcceptTypes[i], |
Hans Leidekker | 2024f68 | 2007-02-12 15:19:17 +0100 | [diff] [blame] | 1938 | HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA | |
| 1939 | HTTP_ADDHDR_FLAG_REQ | |
| 1940 | (i == 0 ? HTTP_ADDHDR_FLAG_REPLACE : 0)); |
| 1941 | } |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1942 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1943 | |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 1944 | lpwhr->lpszVerb = WININET_strdupW(lpszVerb && *lpszVerb ? lpszVerb : szGET); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1945 | |
Hans Leidekker | d0033db | 2008-02-17 20:41:42 +0100 | [diff] [blame] | 1946 | if (lpszVersion) |
| 1947 | lpwhr->lpszVersion = WININET_strdupW(lpszVersion); |
| 1948 | else |
| 1949 | lpwhr->lpszVersion = WININET_strdupW(g_szHttp1_1); |
| 1950 | |
Hans Leidekker | 4d84eb2 | 2008-01-04 13:14:00 +0100 | [diff] [blame] | 1951 | HTTP_ProcessHeader(lpwhr, szHost, lpwhs->lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ); |
Robert Shearman | 37f2cc8 | 2004-09-13 19:33:17 +0000 | [diff] [blame] | 1952 | |
Mike McCormack | 403e58f | 2005-10-19 19:07:08 +0000 | [diff] [blame] | 1953 | if (lpwhs->nServerPort == INTERNET_INVALID_PORT_NUMBER) |
| 1954 | lpwhs->nServerPort = (dwFlags & INTERNET_FLAG_SECURE ? |
| 1955 | INTERNET_DEFAULT_HTTPS_PORT : |
| 1956 | INTERNET_DEFAULT_HTTP_PORT); |
Hans Leidekker | e4c59c2 | 2008-03-30 19:17:31 +0100 | [diff] [blame] | 1957 | |
| 1958 | if (lpwhs->nHostPort == INTERNET_INVALID_PORT_NUMBER) |
| 1959 | lpwhs->nHostPort = (dwFlags & INTERNET_FLAG_SECURE ? |
| 1960 | INTERNET_DEFAULT_HTTPS_PORT : |
| 1961 | INTERNET_DEFAULT_HTTP_PORT); |
Mike McCormack | 403e58f | 2005-10-19 19:07:08 +0000 | [diff] [blame] | 1962 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1963 | if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0) |
| 1964 | HTTP_DealWithProxy( hIC, lpwhs, lpwhr ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1965 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1966 | if (hIC->lpszAgent) |
| 1967 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1968 | WCHAR *agent_header; |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 1969 | static const WCHAR user_agent[] = {'U','s','e','r','-','A','g','e','n','t',':',' ','%','s','\r','\n',0 }; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 1970 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1971 | len = strlenW(hIC->lpszAgent) + strlenW(user_agent); |
| 1972 | agent_header = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); |
| 1973 | sprintfW(agent_header, user_agent, hIC->lpszAgent ); |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 1974 | |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1975 | HTTP_HttpAddRequestHeadersW(lpwhr, agent_header, strlenW(agent_header), |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1976 | HTTP_ADDREQ_FLAG_ADD); |
| 1977 | HeapFree(GetProcessHeap(), 0, agent_header); |
| 1978 | } |
| 1979 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1980 | Host = HTTP_GetHeader(lpwhr,szHost); |
| 1981 | |
| 1982 | len = lstrlenW(Host->lpszValue) + strlenW(szUrlForm); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1983 | lpszUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1984 | sprintfW( lpszUrl, szUrlForm, Host->lpszValue ); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1985 | |
Robert Shearman | d631592 | 2004-07-19 21:18:33 +0000 | [diff] [blame] | 1986 | if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) && |
| 1987 | InternetGetCookieW(lpszUrl, NULL, NULL, &nCookieSize)) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1988 | { |
| 1989 | int cnt = 0; |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 1990 | static const WCHAR szCookie[] = {'C','o','o','k','i','e',':',' ',0}; |
| 1991 | static const WCHAR szcrlf[] = {'\r','\n',0}; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1992 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1993 | lpszCookies = HeapAlloc(GetProcessHeap(), 0, (nCookieSize + 1 + 8)*sizeof(WCHAR)); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1994 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1995 | cnt += sprintfW(lpszCookies, szCookie); |
| 1996 | InternetGetCookieW(lpszUrl, NULL, lpszCookies + cnt, &nCookieSize); |
| 1997 | strcatW(lpszCookies, szcrlf); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1998 | |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1999 | HTTP_HttpAddRequestHeadersW(lpwhr, lpszCookies, strlenW(lpszCookies), |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2000 | HTTP_ADDREQ_FLAG_ADD); |
| 2001 | HeapFree(GetProcessHeap(), 0, lpszCookies); |
| 2002 | } |
| 2003 | HeapFree(GetProcessHeap(), 0, lpszUrl); |
| 2004 | |
| 2005 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2006 | INTERNET_SendCallback(&lpwhs->hdr, dwContext, |
| 2007 | INTERNET_STATUS_HANDLE_CREATED, &handle, |
| 2008 | sizeof(handle)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2009 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2010 | /* |
| 2011 | * A STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on windows |
| 2012 | */ |
| 2013 | |
Rob Shearman | 72575a0 | 2006-12-07 00:52:50 +0000 | [diff] [blame] | 2014 | if (!HTTP_ResolveName(lpwhr)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2015 | { |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2016 | InternetCloseHandle( handle ); |
| 2017 | handle = NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2020 | lend: |
| 2021 | if( lpwhr ) |
| 2022 | WININET_Release( &lpwhr->hdr ); |
| 2023 | |
| 2024 | TRACE("<-- %p (%p)\n", handle, lpwhr); |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 2025 | return handle; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
Jacek Caban | ca39a55 | 2008-03-02 19:55:04 +0100 | [diff] [blame] | 2028 | /* read any content returned by the server so that the connection can be |
| 2029 | * reused */ |
| 2030 | static void HTTP_DrainContent(WININETHTTPREQW *req) |
| 2031 | { |
| 2032 | DWORD bytes_read; |
| 2033 | |
| 2034 | if (!NETCON_connected(&req->netConnection)) return; |
| 2035 | |
| 2036 | if (req->dwContentLength == -1) |
| 2037 | NETCON_close(&req->netConnection); |
| 2038 | |
| 2039 | do |
| 2040 | { |
| 2041 | char buffer[2048]; |
Hans Leidekker | 058761f | 2008-03-26 22:22:04 +0100 | [diff] [blame] | 2042 | if (HTTP_Read(req, buffer, sizeof(buffer), &bytes_read, TRUE) != ERROR_SUCCESS) |
Jacek Caban | ca39a55 | 2008-03-02 19:55:04 +0100 | [diff] [blame] | 2043 | return; |
| 2044 | } while (bytes_read); |
| 2045 | } |
| 2046 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2047 | static const WCHAR szAccept[] = { 'A','c','c','e','p','t',0 }; |
| 2048 | static const WCHAR szAccept_Charset[] = { 'A','c','c','e','p','t','-','C','h','a','r','s','e','t', 0 }; |
| 2049 | static const WCHAR szAccept_Encoding[] = { 'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',0 }; |
| 2050 | static const WCHAR szAccept_Language[] = { 'A','c','c','e','p','t','-','L','a','n','g','u','a','g','e',0 }; |
| 2051 | static const WCHAR szAccept_Ranges[] = { 'A','c','c','e','p','t','-','R','a','n','g','e','s',0 }; |
| 2052 | static const WCHAR szAge[] = { 'A','g','e',0 }; |
| 2053 | static const WCHAR szAllow[] = { 'A','l','l','o','w',0 }; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2054 | static const WCHAR szCache_Control[] = { 'C','a','c','h','e','-','C','o','n','t','r','o','l',0 }; |
| 2055 | static const WCHAR szConnection[] = { 'C','o','n','n','e','c','t','i','o','n',0 }; |
| 2056 | static const WCHAR szContent_Base[] = { 'C','o','n','t','e','n','t','-','B','a','s','e',0 }; |
| 2057 | static const WCHAR szContent_Encoding[] = { 'C','o','n','t','e','n','t','-','E','n','c','o','d','i','n','g',0 }; |
| 2058 | static const WCHAR szContent_ID[] = { 'C','o','n','t','e','n','t','-','I','D',0 }; |
| 2059 | static const WCHAR szContent_Language[] = { 'C','o','n','t','e','n','t','-','L','a','n','g','u','a','g','e',0 }; |
| 2060 | static const WCHAR szContent_Length[] = { 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0 }; |
| 2061 | static const WCHAR szContent_Location[] = { 'C','o','n','t','e','n','t','-','L','o','c','a','t','i','o','n',0 }; |
| 2062 | static const WCHAR szContent_MD5[] = { 'C','o','n','t','e','n','t','-','M','D','5',0 }; |
| 2063 | static const WCHAR szContent_Range[] = { 'C','o','n','t','e','n','t','-','R','a','n','g','e',0 }; |
| 2064 | 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 }; |
| 2065 | static const WCHAR szContent_Type[] = { 'C','o','n','t','e','n','t','-','T','y','p','e',0 }; |
| 2066 | static const WCHAR szCookie[] = { 'C','o','o','k','i','e',0 }; |
| 2067 | static const WCHAR szDate[] = { 'D','a','t','e',0 }; |
| 2068 | static const WCHAR szFrom[] = { 'F','r','o','m',0 }; |
| 2069 | static const WCHAR szETag[] = { 'E','T','a','g',0 }; |
| 2070 | static const WCHAR szExpect[] = { 'E','x','p','e','c','t',0 }; |
| 2071 | static const WCHAR szExpires[] = { 'E','x','p','i','r','e','s',0 }; |
| 2072 | static const WCHAR szIf_Match[] = { 'I','f','-','M','a','t','c','h',0 }; |
| 2073 | static const WCHAR szIf_Modified_Since[] = { 'I','f','-','M','o','d','i','f','i','e','d','-','S','i','n','c','e',0 }; |
| 2074 | static const WCHAR szIf_None_Match[] = { 'I','f','-','N','o','n','e','-','M','a','t','c','h',0 }; |
| 2075 | static const WCHAR szIf_Range[] = { 'I','f','-','R','a','n','g','e',0 }; |
| 2076 | static const WCHAR szIf_Unmodified_Since[] = { 'I','f','-','U','n','m','o','d','i','f','i','e','d','-','S','i','n','c','e',0 }; |
| 2077 | static const WCHAR szLast_Modified[] = { 'L','a','s','t','-','M','o','d','i','f','i','e','d',0 }; |
| 2078 | static const WCHAR szLocation[] = { 'L','o','c','a','t','i','o','n',0 }; |
| 2079 | static const WCHAR szMax_Forwards[] = { 'M','a','x','-','F','o','r','w','a','r','d','s',0 }; |
| 2080 | static const WCHAR szMime_Version[] = { 'M','i','m','e','-','V','e','r','s','i','o','n',0 }; |
| 2081 | static const WCHAR szPragma[] = { 'P','r','a','g','m','a',0 }; |
| 2082 | static const WCHAR szProxy_Authenticate[] = { 'P','r','o','x','y','-','A','u','t','h','e','n','t','i','c','a','t','e',0 }; |
| 2083 | static const WCHAR szProxy_Connection[] = { 'P','r','o','x','y','-','C','o','n','n','e','c','t','i','o','n',0 }; |
| 2084 | static const WCHAR szPublic[] = { 'P','u','b','l','i','c',0 }; |
| 2085 | static const WCHAR szRange[] = { 'R','a','n','g','e',0 }; |
| 2086 | static const WCHAR szReferer[] = { 'R','e','f','e','r','e','r',0 }; |
| 2087 | static const WCHAR szRetry_After[] = { 'R','e','t','r','y','-','A','f','t','e','r',0 }; |
| 2088 | static const WCHAR szServer[] = { 'S','e','r','v','e','r',0 }; |
| 2089 | static const WCHAR szSet_Cookie[] = { 'S','e','t','-','C','o','o','k','i','e',0 }; |
| 2090 | static const WCHAR szTransfer_Encoding[] = { 'T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0 }; |
| 2091 | 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 }; |
| 2092 | static const WCHAR szUpgrade[] = { 'U','p','g','r','a','d','e',0 }; |
| 2093 | static const WCHAR szURI[] = { 'U','R','I',0 }; |
| 2094 | static const WCHAR szUser_Agent[] = { 'U','s','e','r','-','A','g','e','n','t',0 }; |
| 2095 | static const WCHAR szVary[] = { 'V','a','r','y',0 }; |
| 2096 | static const WCHAR szVia[] = { 'V','i','a',0 }; |
| 2097 | static const WCHAR szWarning[] = { 'W','a','r','n','i','n','g',0 }; |
| 2098 | static const WCHAR szWWW_Authenticate[] = { 'W','W','W','-','A','u','t','h','e','n','t','i','c','a','t','e',0 }; |
| 2099 | |
Mike McCormack | 7f5e273 | 2006-03-30 18:02:54 +0900 | [diff] [blame] | 2100 | static const LPCWSTR header_lookup[] = { |
| 2101 | szMime_Version, /* HTTP_QUERY_MIME_VERSION = 0 */ |
| 2102 | szContent_Type, /* HTTP_QUERY_CONTENT_TYPE = 1 */ |
| 2103 | szContent_Transfer_Encoding,/* HTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2 */ |
| 2104 | szContent_ID, /* HTTP_QUERY_CONTENT_ID = 3 */ |
| 2105 | NULL, /* HTTP_QUERY_CONTENT_DESCRIPTION = 4 */ |
| 2106 | szContent_Length, /* HTTP_QUERY_CONTENT_LENGTH = 5 */ |
| 2107 | szContent_Language, /* HTTP_QUERY_CONTENT_LANGUAGE = 6 */ |
| 2108 | szAllow, /* HTTP_QUERY_ALLOW = 7 */ |
| 2109 | szPublic, /* HTTP_QUERY_PUBLIC = 8 */ |
| 2110 | szDate, /* HTTP_QUERY_DATE = 9 */ |
| 2111 | szExpires, /* HTTP_QUERY_EXPIRES = 10 */ |
| 2112 | szLast_Modified, /* HTTP_QUERY_LAST_MODIFIED = 11 */ |
| 2113 | NULL, /* HTTP_QUERY_MESSAGE_ID = 12 */ |
| 2114 | szURI, /* HTTP_QUERY_URI = 13 */ |
| 2115 | szFrom, /* HTTP_QUERY_DERIVED_FROM = 14 */ |
| 2116 | NULL, /* HTTP_QUERY_COST = 15 */ |
| 2117 | NULL, /* HTTP_QUERY_LINK = 16 */ |
| 2118 | szPragma, /* HTTP_QUERY_PRAGMA = 17 */ |
| 2119 | NULL, /* HTTP_QUERY_VERSION = 18 */ |
| 2120 | szStatus, /* HTTP_QUERY_STATUS_CODE = 19 */ |
| 2121 | NULL, /* HTTP_QUERY_STATUS_TEXT = 20 */ |
| 2122 | NULL, /* HTTP_QUERY_RAW_HEADERS = 21 */ |
| 2123 | NULL, /* HTTP_QUERY_RAW_HEADERS_CRLF = 22 */ |
| 2124 | szConnection, /* HTTP_QUERY_CONNECTION = 23 */ |
| 2125 | szAccept, /* HTTP_QUERY_ACCEPT = 24 */ |
| 2126 | szAccept_Charset, /* HTTP_QUERY_ACCEPT_CHARSET = 25 */ |
| 2127 | szAccept_Encoding, /* HTTP_QUERY_ACCEPT_ENCODING = 26 */ |
| 2128 | szAccept_Language, /* HTTP_QUERY_ACCEPT_LANGUAGE = 27 */ |
| 2129 | szAuthorization, /* HTTP_QUERY_AUTHORIZATION = 28 */ |
| 2130 | szContent_Encoding, /* HTTP_QUERY_CONTENT_ENCODING = 29 */ |
| 2131 | NULL, /* HTTP_QUERY_FORWARDED = 30 */ |
| 2132 | NULL, /* HTTP_QUERY_FROM = 31 */ |
| 2133 | szIf_Modified_Since, /* HTTP_QUERY_IF_MODIFIED_SINCE = 32 */ |
| 2134 | szLocation, /* HTTP_QUERY_LOCATION = 33 */ |
| 2135 | NULL, /* HTTP_QUERY_ORIG_URI = 34 */ |
| 2136 | szReferer, /* HTTP_QUERY_REFERER = 35 */ |
| 2137 | szRetry_After, /* HTTP_QUERY_RETRY_AFTER = 36 */ |
| 2138 | szServer, /* HTTP_QUERY_SERVER = 37 */ |
| 2139 | NULL, /* HTTP_TITLE = 38 */ |
| 2140 | szUser_Agent, /* HTTP_QUERY_USER_AGENT = 39 */ |
| 2141 | szWWW_Authenticate, /* HTTP_QUERY_WWW_AUTHENTICATE = 40 */ |
| 2142 | szProxy_Authenticate, /* HTTP_QUERY_PROXY_AUTHENTICATE = 41 */ |
| 2143 | szAccept_Ranges, /* HTTP_QUERY_ACCEPT_RANGES = 42 */ |
| 2144 | szSet_Cookie, /* HTTP_QUERY_SET_COOKIE = 43 */ |
| 2145 | szCookie, /* HTTP_QUERY_COOKIE = 44 */ |
| 2146 | NULL, /* HTTP_QUERY_REQUEST_METHOD = 45 */ |
| 2147 | NULL, /* HTTP_QUERY_REFRESH = 46 */ |
| 2148 | NULL, /* HTTP_QUERY_CONTENT_DISPOSITION = 47 */ |
| 2149 | szAge, /* HTTP_QUERY_AGE = 48 */ |
| 2150 | szCache_Control, /* HTTP_QUERY_CACHE_CONTROL = 49 */ |
| 2151 | szContent_Base, /* HTTP_QUERY_CONTENT_BASE = 50 */ |
| 2152 | szContent_Location, /* HTTP_QUERY_CONTENT_LOCATION = 51 */ |
| 2153 | szContent_MD5, /* HTTP_QUERY_CONTENT_MD5 = 52 */ |
| 2154 | szContent_Range, /* HTTP_QUERY_CONTENT_RANGE = 53 */ |
| 2155 | szETag, /* HTTP_QUERY_ETAG = 54 */ |
| 2156 | szHost, /* HTTP_QUERY_HOST = 55 */ |
| 2157 | szIf_Match, /* HTTP_QUERY_IF_MATCH = 56 */ |
| 2158 | szIf_None_Match, /* HTTP_QUERY_IF_NONE_MATCH = 57 */ |
| 2159 | szIf_Range, /* HTTP_QUERY_IF_RANGE = 58 */ |
| 2160 | szIf_Unmodified_Since, /* HTTP_QUERY_IF_UNMODIFIED_SINCE = 59 */ |
| 2161 | szMax_Forwards, /* HTTP_QUERY_MAX_FORWARDS = 60 */ |
| 2162 | szProxy_Authorization, /* HTTP_QUERY_PROXY_AUTHORIZATION = 61 */ |
| 2163 | szRange, /* HTTP_QUERY_RANGE = 62 */ |
| 2164 | szTransfer_Encoding, /* HTTP_QUERY_TRANSFER_ENCODING = 63 */ |
| 2165 | szUpgrade, /* HTTP_QUERY_UPGRADE = 64 */ |
| 2166 | szVary, /* HTTP_QUERY_VARY = 65 */ |
| 2167 | szVia, /* HTTP_QUERY_VIA = 66 */ |
| 2168 | szWarning, /* HTTP_QUERY_WARNING = 67 */ |
| 2169 | szExpect, /* HTTP_QUERY_EXPECT = 68 */ |
| 2170 | szProxy_Connection, /* HTTP_QUERY_PROXY_CONNECTION = 69 */ |
| 2171 | szUnless_Modified_Since, /* HTTP_QUERY_UNLESS_MODIFIED_SINCE = 70 */ |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2172 | }; |
| 2173 | |
Mike McCormack | 7f5e273 | 2006-03-30 18:02:54 +0900 | [diff] [blame] | 2174 | #define LAST_TABLE_HEADER (sizeof(header_lookup)/sizeof(header_lookup[0])) |
| 2175 | |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2176 | /*********************************************************************** |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2177 | * HTTP_HttpQueryInfoW (internal) |
| 2178 | */ |
Mike McCormack | 9b95bb5 | 2005-06-13 19:05:42 +0000 | [diff] [blame] | 2179 | static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD dwInfoLevel, |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2180 | LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex) |
| 2181 | { |
| 2182 | LPHTTPHEADERW lphttpHdr = NULL; |
| 2183 | BOOL bSuccess = FALSE; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2184 | BOOL request_only = dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS; |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2185 | INT requested_index = lpdwIndex ? *lpdwIndex : 0; |
| 2186 | INT level = (dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK); |
| 2187 | INT index = -1; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2188 | |
| 2189 | /* Find requested header structure */ |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2190 | switch (level) |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2191 | { |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2192 | case HTTP_QUERY_CUSTOM: |
| 2193 | index = HTTP_GetCustomHeaderIndex(lpwhr, lpBuffer, requested_index, request_only); |
| 2194 | break; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2195 | |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2196 | case HTTP_QUERY_RAW_HEADERS_CRLF: |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2197 | { |
Mikołaj Zalewski | ab7d177 | 2007-08-15 16:29:58 -0700 | [diff] [blame] | 2198 | LPWSTR headers; |
| 2199 | DWORD len; |
| 2200 | BOOL ret; |
| 2201 | |
| 2202 | if (request_only) |
Hans Leidekker | d0033db | 2008-02-17 20:41:42 +0100 | [diff] [blame] | 2203 | headers = HTTP_BuildHeaderRequestString(lpwhr, lpwhr->lpszVerb, lpwhr->lpszPath, lpwhr->lpszVersion); |
Mikołaj Zalewski | ab7d177 | 2007-08-15 16:29:58 -0700 | [diff] [blame] | 2204 | else |
| 2205 | headers = lpwhr->lpszRawHeaders; |
| 2206 | |
| 2207 | len = strlenW(headers); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2208 | if (len + 1 > *lpdwBufferLength/sizeof(WCHAR)) |
| 2209 | { |
| 2210 | *lpdwBufferLength = (len + 1) * sizeof(WCHAR); |
| 2211 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
Mikołaj Zalewski | ab7d177 | 2007-08-15 16:29:58 -0700 | [diff] [blame] | 2212 | ret = FALSE; |
| 2213 | } else |
| 2214 | { |
| 2215 | memcpy(lpBuffer, headers, (len+1)*sizeof(WCHAR)); |
| 2216 | *lpdwBufferLength = len * sizeof(WCHAR); |
| 2217 | |
| 2218 | TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len)); |
| 2219 | ret = TRUE; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2220 | } |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 2221 | |
Mikołaj Zalewski | ab7d177 | 2007-08-15 16:29:58 -0700 | [diff] [blame] | 2222 | if (request_only) |
| 2223 | HeapFree(GetProcessHeap(), 0, headers); |
| 2224 | return ret; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2225 | } |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2226 | case HTTP_QUERY_RAW_HEADERS: |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2227 | { |
| 2228 | static const WCHAR szCrLf[] = {'\r','\n',0}; |
| 2229 | LPWSTR * ppszRawHeaderLines = HTTP_Tokenize(lpwhr->lpszRawHeaders, szCrLf); |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2230 | DWORD i, size = 0; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2231 | LPWSTR pszString = (WCHAR*)lpBuffer; |
| 2232 | |
| 2233 | for (i = 0; ppszRawHeaderLines[i]; i++) |
| 2234 | size += strlenW(ppszRawHeaderLines[i]) + 1; |
| 2235 | |
| 2236 | if (size + 1 > *lpdwBufferLength/sizeof(WCHAR)) |
| 2237 | { |
| 2238 | HTTP_FreeTokens(ppszRawHeaderLines); |
| 2239 | *lpdwBufferLength = (size + 1) * sizeof(WCHAR); |
| 2240 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 2241 | return FALSE; |
| 2242 | } |
| 2243 | |
| 2244 | for (i = 0; ppszRawHeaderLines[i]; i++) |
| 2245 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2246 | DWORD len = strlenW(ppszRawHeaderLines[i]); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2247 | memcpy(pszString, ppszRawHeaderLines[i], (len+1)*sizeof(WCHAR)); |
| 2248 | pszString += len+1; |
| 2249 | } |
| 2250 | *pszString = '\0'; |
| 2251 | |
| 2252 | TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, size)); |
| 2253 | |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 2254 | *lpdwBufferLength = size * sizeof(WCHAR); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2255 | HTTP_FreeTokens(ppszRawHeaderLines); |
| 2256 | |
| 2257 | return TRUE; |
| 2258 | } |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2259 | case HTTP_QUERY_STATUS_TEXT: |
Mike McCormack | 739cd1e | 2006-05-30 22:55:42 +0900 | [diff] [blame] | 2260 | if (lpwhr->lpszStatusText) |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2261 | { |
| 2262 | DWORD len = strlenW(lpwhr->lpszStatusText); |
| 2263 | if (len + 1 > *lpdwBufferLength/sizeof(WCHAR)) |
| 2264 | { |
| 2265 | *lpdwBufferLength = (len + 1) * sizeof(WCHAR); |
| 2266 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 2267 | return FALSE; |
| 2268 | } |
| 2269 | memcpy(lpBuffer, lpwhr->lpszStatusText, (len+1)*sizeof(WCHAR)); |
| 2270 | *lpdwBufferLength = len * sizeof(WCHAR); |
| 2271 | |
| 2272 | TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len)); |
| 2273 | |
| 2274 | return TRUE; |
| 2275 | } |
Mike McCormack | 739cd1e | 2006-05-30 22:55:42 +0900 | [diff] [blame] | 2276 | break; |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2277 | case HTTP_QUERY_VERSION: |
Mike McCormack | 739cd1e | 2006-05-30 22:55:42 +0900 | [diff] [blame] | 2278 | if (lpwhr->lpszVersion) |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2279 | { |
| 2280 | DWORD len = strlenW(lpwhr->lpszVersion); |
| 2281 | if (len + 1 > *lpdwBufferLength/sizeof(WCHAR)) |
| 2282 | { |
| 2283 | *lpdwBufferLength = (len + 1) * sizeof(WCHAR); |
| 2284 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 2285 | return FALSE; |
| 2286 | } |
| 2287 | memcpy(lpBuffer, lpwhr->lpszVersion, (len+1)*sizeof(WCHAR)); |
| 2288 | *lpdwBufferLength = len * sizeof(WCHAR); |
| 2289 | |
| 2290 | TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len)); |
| 2291 | |
| 2292 | return TRUE; |
| 2293 | } |
Mike McCormack | 739cd1e | 2006-05-30 22:55:42 +0900 | [diff] [blame] | 2294 | break; |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2295 | default: |
Mike McCormack | 7f5e273 | 2006-03-30 18:02:54 +0900 | [diff] [blame] | 2296 | assert (LAST_TABLE_HEADER == (HTTP_QUERY_UNLESS_MODIFIED_SINCE + 1)); |
| 2297 | |
| 2298 | if (level >= 0 && level < LAST_TABLE_HEADER && header_lookup[level]) |
| 2299 | index = HTTP_GetCustomHeaderIndex(lpwhr, header_lookup[level], |
| 2300 | requested_index,request_only); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2301 | } |
| 2302 | |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2303 | if (index >= 0) |
| 2304 | lphttpHdr = &lpwhr->pCustHeaders[index]; |
| 2305 | |
Austin English | 0e4adae | 2008-01-04 13:37:14 -0600 | [diff] [blame] | 2306 | /* Ensure header satisfies requested attributes */ |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2307 | if (!lphttpHdr || |
| 2308 | ((dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS) && |
| 2309 | (~lphttpHdr->wFlags & HDR_ISREQUEST))) |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2310 | { |
Francois Gouget | e66d1cd | 2007-01-09 12:30:45 +0100 | [diff] [blame] | 2311 | INTERNET_SetLastError(ERROR_HTTP_HEADER_NOT_FOUND); |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2312 | return bSuccess; |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2313 | } |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2314 | |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 2315 | if (lpdwIndex) |
| 2316 | (*lpdwIndex)++; |
| 2317 | |
Austin English | 0e4adae | 2008-01-04 13:37:14 -0600 | [diff] [blame] | 2318 | /* coalesce value to requested type */ |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2319 | if (dwInfoLevel & HTTP_QUERY_FLAG_NUMBER) |
| 2320 | { |
| 2321 | *(int *)lpBuffer = atoiW(lphttpHdr->lpszValue); |
| 2322 | bSuccess = TRUE; |
| 2323 | |
| 2324 | TRACE(" returning number : %d\n", *(int *)lpBuffer); |
| 2325 | } |
| 2326 | else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME) |
| 2327 | { |
| 2328 | time_t tmpTime; |
| 2329 | struct tm tmpTM; |
| 2330 | SYSTEMTIME *STHook; |
| 2331 | |
| 2332 | tmpTime = ConvertTimeString(lphttpHdr->lpszValue); |
| 2333 | |
| 2334 | tmpTM = *gmtime(&tmpTime); |
| 2335 | STHook = (SYSTEMTIME *) lpBuffer; |
| 2336 | if(STHook==NULL) |
| 2337 | return bSuccess; |
| 2338 | |
| 2339 | STHook->wDay = tmpTM.tm_mday; |
| 2340 | STHook->wHour = tmpTM.tm_hour; |
| 2341 | STHook->wMilliseconds = 0; |
| 2342 | STHook->wMinute = tmpTM.tm_min; |
| 2343 | STHook->wDayOfWeek = tmpTM.tm_wday; |
| 2344 | STHook->wMonth = tmpTM.tm_mon + 1; |
| 2345 | STHook->wSecond = tmpTM.tm_sec; |
| 2346 | STHook->wYear = tmpTM.tm_year; |
| 2347 | |
| 2348 | bSuccess = TRUE; |
| 2349 | |
| 2350 | TRACE(" returning time : %04d/%02d/%02d - %d - %02d:%02d:%02d.%02d\n", |
| 2351 | STHook->wYear, STHook->wMonth, STHook->wDay, STHook->wDayOfWeek, |
| 2352 | STHook->wHour, STHook->wMinute, STHook->wSecond, STHook->wMilliseconds); |
| 2353 | } |
Aric Stewart | 7bca41a | 2005-12-08 12:44:45 +0100 | [diff] [blame] | 2354 | else if (lphttpHdr->lpszValue) |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2355 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2356 | DWORD len = (strlenW(lphttpHdr->lpszValue) + 1) * sizeof(WCHAR); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2357 | |
| 2358 | if (len > *lpdwBufferLength) |
| 2359 | { |
| 2360 | *lpdwBufferLength = len; |
| 2361 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 2362 | return bSuccess; |
| 2363 | } |
| 2364 | |
| 2365 | memcpy(lpBuffer, lphttpHdr->lpszValue, len); |
| 2366 | *lpdwBufferLength = len - sizeof(WCHAR); |
| 2367 | bSuccess = TRUE; |
| 2368 | |
Francois Gouget | aab5e58 | 2007-01-18 11:40:15 +0100 | [diff] [blame] | 2369 | TRACE(" returning string : %s\n", debugstr_w(lpBuffer)); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2370 | } |
| 2371 | return bSuccess; |
| 2372 | } |
| 2373 | |
| 2374 | /*********************************************************************** |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 2375 | * HttpQueryInfoW (WININET.@) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2376 | * |
| 2377 | * Queries for information about an HTTP request |
| 2378 | * |
| 2379 | * RETURNS |
| 2380 | * TRUE on success |
| 2381 | * FALSE on failure |
| 2382 | * |
| 2383 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2384 | BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel, |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2385 | LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex) |
| 2386 | { |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2387 | BOOL bSuccess = FALSE; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2388 | LPWININETHTTPREQW lpwhr; |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 2389 | |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2390 | if (TRACE_ON(wininet)) { |
| 2391 | #define FE(x) { x, #x } |
| 2392 | static const wininet_flag_info query_flags[] = { |
| 2393 | FE(HTTP_QUERY_MIME_VERSION), |
| 2394 | FE(HTTP_QUERY_CONTENT_TYPE), |
| 2395 | FE(HTTP_QUERY_CONTENT_TRANSFER_ENCODING), |
| 2396 | FE(HTTP_QUERY_CONTENT_ID), |
| 2397 | FE(HTTP_QUERY_CONTENT_DESCRIPTION), |
| 2398 | FE(HTTP_QUERY_CONTENT_LENGTH), |
| 2399 | FE(HTTP_QUERY_CONTENT_LANGUAGE), |
| 2400 | FE(HTTP_QUERY_ALLOW), |
| 2401 | FE(HTTP_QUERY_PUBLIC), |
| 2402 | FE(HTTP_QUERY_DATE), |
| 2403 | FE(HTTP_QUERY_EXPIRES), |
| 2404 | FE(HTTP_QUERY_LAST_MODIFIED), |
| 2405 | FE(HTTP_QUERY_MESSAGE_ID), |
| 2406 | FE(HTTP_QUERY_URI), |
| 2407 | FE(HTTP_QUERY_DERIVED_FROM), |
| 2408 | FE(HTTP_QUERY_COST), |
| 2409 | FE(HTTP_QUERY_LINK), |
| 2410 | FE(HTTP_QUERY_PRAGMA), |
| 2411 | FE(HTTP_QUERY_VERSION), |
| 2412 | FE(HTTP_QUERY_STATUS_CODE), |
| 2413 | FE(HTTP_QUERY_STATUS_TEXT), |
| 2414 | FE(HTTP_QUERY_RAW_HEADERS), |
| 2415 | FE(HTTP_QUERY_RAW_HEADERS_CRLF), |
| 2416 | FE(HTTP_QUERY_CONNECTION), |
| 2417 | FE(HTTP_QUERY_ACCEPT), |
| 2418 | FE(HTTP_QUERY_ACCEPT_CHARSET), |
| 2419 | FE(HTTP_QUERY_ACCEPT_ENCODING), |
| 2420 | FE(HTTP_QUERY_ACCEPT_LANGUAGE), |
| 2421 | FE(HTTP_QUERY_AUTHORIZATION), |
| 2422 | FE(HTTP_QUERY_CONTENT_ENCODING), |
| 2423 | FE(HTTP_QUERY_FORWARDED), |
| 2424 | FE(HTTP_QUERY_FROM), |
| 2425 | FE(HTTP_QUERY_IF_MODIFIED_SINCE), |
| 2426 | FE(HTTP_QUERY_LOCATION), |
| 2427 | FE(HTTP_QUERY_ORIG_URI), |
| 2428 | FE(HTTP_QUERY_REFERER), |
| 2429 | FE(HTTP_QUERY_RETRY_AFTER), |
| 2430 | FE(HTTP_QUERY_SERVER), |
| 2431 | FE(HTTP_QUERY_TITLE), |
| 2432 | FE(HTTP_QUERY_USER_AGENT), |
| 2433 | FE(HTTP_QUERY_WWW_AUTHENTICATE), |
| 2434 | FE(HTTP_QUERY_PROXY_AUTHENTICATE), |
| 2435 | FE(HTTP_QUERY_ACCEPT_RANGES), |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2436 | FE(HTTP_QUERY_SET_COOKIE), |
| 2437 | FE(HTTP_QUERY_COOKIE), |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2438 | FE(HTTP_QUERY_REQUEST_METHOD), |
| 2439 | FE(HTTP_QUERY_REFRESH), |
| 2440 | FE(HTTP_QUERY_CONTENT_DISPOSITION), |
| 2441 | FE(HTTP_QUERY_AGE), |
| 2442 | FE(HTTP_QUERY_CACHE_CONTROL), |
| 2443 | FE(HTTP_QUERY_CONTENT_BASE), |
| 2444 | FE(HTTP_QUERY_CONTENT_LOCATION), |
| 2445 | FE(HTTP_QUERY_CONTENT_MD5), |
| 2446 | FE(HTTP_QUERY_CONTENT_RANGE), |
| 2447 | FE(HTTP_QUERY_ETAG), |
| 2448 | FE(HTTP_QUERY_HOST), |
| 2449 | FE(HTTP_QUERY_IF_MATCH), |
| 2450 | FE(HTTP_QUERY_IF_NONE_MATCH), |
| 2451 | FE(HTTP_QUERY_IF_RANGE), |
| 2452 | FE(HTTP_QUERY_IF_UNMODIFIED_SINCE), |
| 2453 | FE(HTTP_QUERY_MAX_FORWARDS), |
| 2454 | FE(HTTP_QUERY_PROXY_AUTHORIZATION), |
| 2455 | FE(HTTP_QUERY_RANGE), |
| 2456 | FE(HTTP_QUERY_TRANSFER_ENCODING), |
| 2457 | FE(HTTP_QUERY_UPGRADE), |
| 2458 | FE(HTTP_QUERY_VARY), |
| 2459 | FE(HTTP_QUERY_VIA), |
| 2460 | FE(HTTP_QUERY_WARNING), |
| 2461 | FE(HTTP_QUERY_CUSTOM) |
| 2462 | }; |
| 2463 | static const wininet_flag_info modifier_flags[] = { |
| 2464 | FE(HTTP_QUERY_FLAG_REQUEST_HEADERS), |
| 2465 | FE(HTTP_QUERY_FLAG_SYSTEMTIME), |
| 2466 | FE(HTTP_QUERY_FLAG_NUMBER), |
| 2467 | FE(HTTP_QUERY_FLAG_COALESCE) |
| 2468 | }; |
| 2469 | #undef FE |
| 2470 | DWORD info_mod = dwInfoLevel & HTTP_QUERY_MODIFIER_FLAGS_MASK; |
| 2471 | DWORD info = dwInfoLevel & HTTP_QUERY_HEADER_MASK; |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2472 | DWORD i; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2473 | |
Hans Leidekker | cd2c458 | 2006-10-05 13:18:56 +0200 | [diff] [blame] | 2474 | TRACE("(%p, 0x%08x)--> %d\n", hHttpRequest, dwInfoLevel, dwInfoLevel); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2475 | TRACE(" Attribute:"); |
| 2476 | for (i = 0; i < (sizeof(query_flags) / sizeof(query_flags[0])); i++) { |
| 2477 | if (query_flags[i].val == info) { |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 2478 | TRACE(" %s", query_flags[i].name); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2479 | break; |
| 2480 | } |
| 2481 | } |
| 2482 | if (i == (sizeof(query_flags) / sizeof(query_flags[0]))) { |
Hans Leidekker | cd2c458 | 2006-10-05 13:18:56 +0200 | [diff] [blame] | 2483 | TRACE(" Unknown (%08x)", info); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 2486 | TRACE(" Modifier:"); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2487 | for (i = 0; i < (sizeof(modifier_flags) / sizeof(modifier_flags[0])); i++) { |
| 2488 | if (modifier_flags[i].val & info_mod) { |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 2489 | TRACE(" %s", modifier_flags[i].name); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2490 | info_mod &= ~ modifier_flags[i].val; |
| 2491 | } |
| 2492 | } |
| 2493 | |
| 2494 | if (info_mod) { |
Hans Leidekker | cd2c458 | 2006-10-05 13:18:56 +0200 | [diff] [blame] | 2495 | TRACE(" Unknown (%08x)", info_mod); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2496 | } |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 2497 | TRACE("\n"); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2500 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2501 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 2502 | { |
| 2503 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2504 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2505 | } |
| 2506 | |
Mikołaj Zalewski | 3fa49f0 | 2007-08-15 16:55:15 -0700 | [diff] [blame] | 2507 | if (lpBuffer == NULL) |
| 2508 | *lpdwBufferLength = 0; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2509 | bSuccess = HTTP_HttpQueryInfoW( lpwhr, dwInfoLevel, |
| 2510 | lpBuffer, lpdwBufferLength, lpdwIndex); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2511 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2512 | lend: |
| 2513 | if( lpwhr ) |
| 2514 | WININET_Release( &lpwhr->hdr ); |
| 2515 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2516 | TRACE("%d <--\n", bSuccess); |
| 2517 | return bSuccess; |
| 2518 | } |
| 2519 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2520 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2521 | * HttpQueryInfoA (WININET.@) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2522 | * |
| 2523 | * Queries for information about an HTTP request |
| 2524 | * |
| 2525 | * RETURNS |
| 2526 | * TRUE on success |
| 2527 | * FALSE on failure |
| 2528 | * |
| 2529 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2530 | BOOL WINAPI HttpQueryInfoA(HINTERNET hHttpRequest, DWORD dwInfoLevel, |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2531 | LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex) |
| 2532 | { |
| 2533 | BOOL result; |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 2534 | DWORD len; |
| 2535 | WCHAR* bufferW; |
| 2536 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2537 | if((dwInfoLevel & HTTP_QUERY_FLAG_NUMBER) || |
| 2538 | (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME)) |
| 2539 | { |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 2540 | return HttpQueryInfoW( hHttpRequest, dwInfoLevel, lpBuffer, |
| 2541 | lpdwBufferLength, lpdwIndex ); |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2542 | } |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 2543 | |
Mikołaj Zalewski | 3fa49f0 | 2007-08-15 16:55:15 -0700 | [diff] [blame] | 2544 | if (lpBuffer) |
| 2545 | { |
Rob Shearman | 719cd82 | 2008-02-18 19:37:35 +0000 | [diff] [blame] | 2546 | DWORD alloclen; |
Mikołaj Zalewski | 3fa49f0 | 2007-08-15 16:55:15 -0700 | [diff] [blame] | 2547 | len = (*lpdwBufferLength)*sizeof(WCHAR); |
Rob Shearman | 719cd82 | 2008-02-18 19:37:35 +0000 | [diff] [blame] | 2548 | if ((dwInfoLevel & HTTP_QUERY_HEADER_MASK) == HTTP_QUERY_CUSTOM) |
| 2549 | { |
| 2550 | alloclen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 ) * sizeof(WCHAR); |
| 2551 | if (alloclen < len) |
| 2552 | alloclen = len; |
| 2553 | } |
| 2554 | else |
| 2555 | alloclen = len; |
| 2556 | bufferW = HeapAlloc( GetProcessHeap(), 0, alloclen ); |
Mikołaj Zalewski | 3fa49f0 | 2007-08-15 16:55:15 -0700 | [diff] [blame] | 2557 | /* buffer is in/out because of HTTP_QUERY_CUSTOM */ |
| 2558 | if ((dwInfoLevel & HTTP_QUERY_HEADER_MASK) == HTTP_QUERY_CUSTOM) |
Rob Shearman | 719cd82 | 2008-02-18 19:37:35 +0000 | [diff] [blame] | 2559 | MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, bufferW, alloclen / sizeof(WCHAR) ); |
Mikołaj Zalewski | 3fa49f0 | 2007-08-15 16:55:15 -0700 | [diff] [blame] | 2560 | } else |
| 2561 | { |
| 2562 | bufferW = NULL; |
| 2563 | len = 0; |
| 2564 | } |
| 2565 | |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 2566 | result = HttpQueryInfoW( hHttpRequest, dwInfoLevel, bufferW, |
| 2567 | &len, lpdwIndex ); |
| 2568 | if( result ) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2569 | { |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 2570 | len = WideCharToMultiByte( CP_ACP,0, bufferW, len / sizeof(WCHAR) + 1, |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 2571 | lpBuffer, *lpdwBufferLength, NULL, NULL ); |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 2572 | *lpdwBufferLength = len - 1; |
| 2573 | |
| 2574 | TRACE("lpBuffer: %s\n", debugstr_a(lpBuffer)); |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2575 | } |
Robert Shearman | 907ac44 | 2004-07-20 01:21:08 +0000 | [diff] [blame] | 2576 | else |
| 2577 | /* since the strings being returned from HttpQueryInfoW should be |
| 2578 | * only ASCII characters, it is reasonable to assume that all of |
| 2579 | * the Unicode characters can be reduced to a single byte */ |
| 2580 | *lpdwBufferLength = len / sizeof(WCHAR); |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 2581 | |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 2582 | HeapFree(GetProcessHeap(), 0, bufferW ); |
| 2583 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2584 | return result; |
| 2585 | } |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 2586 | |
| 2587 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 2588 | * HttpSendRequestExA (WININET.@) |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 2589 | * |
| 2590 | * Sends the specified request to the HTTP server and allows chunked |
Robert Shearman | 7a2357a | 2006-02-14 11:34:14 +0100 | [diff] [blame] | 2591 | * transfers. |
| 2592 | * |
| 2593 | * RETURNS |
| 2594 | * Success: TRUE |
| 2595 | * Failure: FALSE, call GetLastError() for more information. |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 2596 | */ |
| 2597 | BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest, |
| 2598 | LPINTERNET_BUFFERSA lpBuffersIn, |
| 2599 | LPINTERNET_BUFFERSA lpBuffersOut, |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 2600 | DWORD dwFlags, DWORD_PTR dwContext) |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 2601 | { |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2602 | INTERNET_BUFFERSW BuffersInW; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2603 | BOOL rc = FALSE; |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2604 | DWORD headerlen; |
Hans Leidekker | 781f3f7 | 2006-10-13 15:43:54 +0200 | [diff] [blame] | 2605 | LPWSTR header = NULL; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2606 | |
Dan Hipschman | aaecdf7 | 2008-03-27 13:51:13 -0700 | [diff] [blame] | 2607 | TRACE("(%p, %p, %p, %08x, %08lx)\n", hRequest, lpBuffersIn, |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2608 | lpBuffersOut, dwFlags, dwContext); |
| 2609 | |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2610 | if (lpBuffersIn) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2611 | { |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2612 | BuffersInW.dwStructSize = sizeof(LPINTERNET_BUFFERSW); |
| 2613 | if (lpBuffersIn->lpcszHeader) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2614 | { |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2615 | headerlen = MultiByteToWideChar(CP_ACP,0,lpBuffersIn->lpcszHeader, |
| 2616 | lpBuffersIn->dwHeadersLength,0,0); |
Hans Leidekker | 781f3f7 | 2006-10-13 15:43:54 +0200 | [diff] [blame] | 2617 | header = HeapAlloc(GetProcessHeap(),0,headerlen*sizeof(WCHAR)); |
| 2618 | if (!(BuffersInW.lpcszHeader = header)) |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2619 | { |
Francois Gouget | e66d1cd | 2007-01-09 12:30:45 +0100 | [diff] [blame] | 2620 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2621 | return FALSE; |
| 2622 | } |
| 2623 | BuffersInW.dwHeadersLength = MultiByteToWideChar(CP_ACP, 0, |
| 2624 | lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength, |
Hans Leidekker | 781f3f7 | 2006-10-13 15:43:54 +0200 | [diff] [blame] | 2625 | header, headerlen); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2626 | } |
Aric Stewart | d30cec7 | 2005-12-08 11:54:24 +0100 | [diff] [blame] | 2627 | else |
| 2628 | BuffersInW.lpcszHeader = NULL; |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2629 | BuffersInW.dwHeadersTotal = lpBuffersIn->dwHeadersTotal; |
| 2630 | BuffersInW.lpvBuffer = lpBuffersIn->lpvBuffer; |
| 2631 | BuffersInW.dwBufferLength = lpBuffersIn->dwBufferLength; |
| 2632 | BuffersInW.dwBufferTotal = lpBuffersIn->dwBufferTotal; |
| 2633 | BuffersInW.Next = NULL; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2636 | rc = HttpSendRequestExW(hRequest, lpBuffersIn ? &BuffersInW : NULL, NULL, dwFlags, dwContext); |
| 2637 | |
Hans Leidekker | 781f3f7 | 2006-10-13 15:43:54 +0200 | [diff] [blame] | 2638 | HeapFree(GetProcessHeap(),0,header); |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 2639 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2640 | return rc; |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2643 | /*********************************************************************** |
Hans Leidekker | 6a367db | 2005-02-01 18:50:53 +0000 | [diff] [blame] | 2644 | * HttpSendRequestExW (WININET.@) |
| 2645 | * |
| 2646 | * Sends the specified request to the HTTP server and allows chunked |
| 2647 | * transfers |
Robert Shearman | 7a2357a | 2006-02-14 11:34:14 +0100 | [diff] [blame] | 2648 | * |
| 2649 | * RETURNS |
| 2650 | * Success: TRUE |
| 2651 | * Failure: FALSE, call GetLastError() for more information. |
Hans Leidekker | 6a367db | 2005-02-01 18:50:53 +0000 | [diff] [blame] | 2652 | */ |
| 2653 | BOOL WINAPI HttpSendRequestExW(HINTERNET hRequest, |
| 2654 | LPINTERNET_BUFFERSW lpBuffersIn, |
| 2655 | LPINTERNET_BUFFERSW lpBuffersOut, |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 2656 | DWORD dwFlags, DWORD_PTR dwContext) |
Hans Leidekker | 6a367db | 2005-02-01 18:50:53 +0000 | [diff] [blame] | 2657 | { |
Nigel Liang | 6f44627 | 2007-11-03 18:24:49 -0700 | [diff] [blame] | 2658 | BOOL ret = FALSE; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2659 | LPWININETHTTPREQW lpwhr; |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2660 | LPWININETHTTPSESSIONW lpwhs; |
| 2661 | LPWININETAPPINFOW hIC; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2662 | |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 2663 | TRACE("(%p, %p, %p, %08x, %08lx)\n", hRequest, lpBuffersIn, |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2664 | lpBuffersOut, dwFlags, dwContext); |
| 2665 | |
| 2666 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hRequest ); |
| 2667 | |
| 2668 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 2669 | { |
| 2670 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Nigel Liang | 6f44627 | 2007-11-03 18:24:49 -0700 | [diff] [blame] | 2671 | goto lend; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
Jacek Caban | 61a1cef | 2006-10-29 18:51:15 +0100 | [diff] [blame] | 2674 | lpwhs = lpwhr->lpHttpSession; |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2675 | assert(lpwhs->hdr.htype == WH_HHTTPSESSION); |
Jacek Caban | a541a44 | 2006-10-29 18:49:39 +0100 | [diff] [blame] | 2676 | hIC = lpwhs->lpAppInfo; |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2677 | assert(hIC->hdr.htype == WH_HINIT); |
| 2678 | |
| 2679 | if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2680 | { |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2681 | WORKREQUEST workRequest; |
| 2682 | struct WORKREQ_HTTPSENDREQUESTW *req; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2683 | |
Jacek Caban | c156845 | 2006-12-25 21:33:36 +0100 | [diff] [blame] | 2684 | workRequest.asyncproc = AsyncHttpSendRequestProc; |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2685 | workRequest.hdr = WININET_AddRef( &lpwhr->hdr ); |
| 2686 | req = &workRequest.u.HttpSendRequestW; |
Aric Stewart | 21712d3 | 2006-01-13 13:52:38 +0100 | [diff] [blame] | 2687 | if (lpBuffersIn) |
| 2688 | { |
| 2689 | if (lpBuffersIn->lpcszHeader) |
| 2690 | /* FIXME: this should use dwHeadersLength or may not be necessary at all */ |
| 2691 | req->lpszHeader = WININET_strdupW(lpBuffersIn->lpcszHeader); |
| 2692 | else |
| 2693 | req->lpszHeader = NULL; |
| 2694 | req->dwHeaderLength = lpBuffersIn->dwHeadersLength; |
| 2695 | req->lpOptional = lpBuffersIn->lpvBuffer; |
| 2696 | req->dwOptionalLength = lpBuffersIn->dwBufferLength; |
| 2697 | req->dwContentLength = lpBuffersIn->dwBufferTotal; |
| 2698 | } |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2699 | else |
Aric Stewart | 21712d3 | 2006-01-13 13:52:38 +0100 | [diff] [blame] | 2700 | { |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2701 | req->lpszHeader = NULL; |
Aric Stewart | 21712d3 | 2006-01-13 13:52:38 +0100 | [diff] [blame] | 2702 | req->dwHeaderLength = 0; |
| 2703 | req->lpOptional = NULL; |
| 2704 | req->dwOptionalLength = 0; |
| 2705 | req->dwContentLength = 0; |
| 2706 | } |
| 2707 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2708 | req->bEndRequest = FALSE; |
| 2709 | |
| 2710 | INTERNET_AsyncCall(&workRequest); |
| 2711 | /* |
| 2712 | * This is from windows. |
| 2713 | */ |
Francois Gouget | e66d1cd | 2007-01-09 12:30:45 +0100 | [diff] [blame] | 2714 | INTERNET_SetLastError(ERROR_IO_PENDING); |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2715 | } |
| 2716 | else |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2717 | { |
Juan Lang | d857c04 | 2007-10-22 10:23:54 -0700 | [diff] [blame] | 2718 | if (lpBuffersIn) |
| 2719 | ret = HTTP_HttpSendRequestW(lpwhr, lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength, |
| 2720 | lpBuffersIn->lpvBuffer, lpBuffersIn->dwBufferLength, |
| 2721 | lpBuffersIn->dwBufferTotal, FALSE); |
| 2722 | else |
| 2723 | ret = HTTP_HttpSendRequestW(lpwhr, NULL, 0, NULL, 0, 0, FALSE); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2724 | } |
Nigel Liang | 6f44627 | 2007-11-03 18:24:49 -0700 | [diff] [blame] | 2725 | |
| 2726 | lend: |
| 2727 | if ( lpwhr ) |
| 2728 | WININET_Release( &lpwhr->hdr ); |
| 2729 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2730 | TRACE("<---\n"); |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2731 | return ret; |
Hans Leidekker | 6a367db | 2005-02-01 18:50:53 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | /*********************************************************************** |
Dimitrie O. Paun | f3b681a | 2004-06-28 20:28:38 +0000 | [diff] [blame] | 2735 | * HttpSendRequestW (WININET.@) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2736 | * |
| 2737 | * Sends the specified request to the HTTP server |
| 2738 | * |
| 2739 | * RETURNS |
| 2740 | * TRUE on success |
| 2741 | * FALSE on failure |
| 2742 | * |
| 2743 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2744 | BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders, |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2745 | DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength) |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 2746 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2747 | LPWININETHTTPREQW lpwhr; |
| 2748 | LPWININETHTTPSESSIONW lpwhs = NULL; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 2749 | LPWININETAPPINFOW hIC = NULL; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2750 | BOOL r; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2751 | |
Rob Shearman | 2e21d09 | 2007-05-25 12:07:26 +0100 | [diff] [blame] | 2752 | TRACE("%p, %s, %i, %p, %i)\n", hHttpRequest, |
| 2753 | debugstr_wn(lpszHeaders, dwHeaderLength), dwHeaderLength, lpOptional, dwOptionalLength); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2754 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2755 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2756 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 2757 | { |
| 2758 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2759 | r = FALSE; |
| 2760 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
Jacek Caban | 61a1cef | 2006-10-29 18:51:15 +0100 | [diff] [blame] | 2763 | lpwhs = lpwhr->lpHttpSession; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2764 | if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION) |
| 2765 | { |
| 2766 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2767 | r = FALSE; |
| 2768 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
Jacek Caban | a541a44 | 2006-10-29 18:49:39 +0100 | [diff] [blame] | 2771 | hIC = lpwhs->lpAppInfo; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2772 | if (NULL == hIC || hIC->hdr.htype != WH_HINIT) |
| 2773 | { |
| 2774 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2775 | r = FALSE; |
| 2776 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) |
| 2780 | { |
| 2781 | WORKREQUEST workRequest; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2782 | struct WORKREQ_HTTPSENDREQUESTW *req; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2783 | |
Jacek Caban | c156845 | 2006-12-25 21:33:36 +0100 | [diff] [blame] | 2784 | workRequest.asyncproc = AsyncHttpSendRequestProc; |
| 2785 | workRequest.hdr = WININET_AddRef( &lpwhr->hdr ); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2786 | req = &workRequest.u.HttpSendRequestW; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2787 | if (lpszHeaders) |
Rob Shearman | 2e21d09 | 2007-05-25 12:07:26 +0100 | [diff] [blame] | 2788 | { |
| 2789 | req->lpszHeader = HeapAlloc(GetProcessHeap(), 0, dwHeaderLength * sizeof(WCHAR)); |
| 2790 | memcpy(req->lpszHeader, lpszHeaders, dwHeaderLength * sizeof(WCHAR)); |
| 2791 | } |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2792 | else |
Mike McCormack | b8921a2 | 2003-09-25 20:25:22 +0000 | [diff] [blame] | 2793 | req->lpszHeader = 0; |
| 2794 | req->dwHeaderLength = dwHeaderLength; |
| 2795 | req->lpOptional = lpOptional; |
| 2796 | req->dwOptionalLength = dwOptionalLength; |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2797 | req->dwContentLength = dwOptionalLength; |
| 2798 | req->bEndRequest = TRUE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2799 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2800 | INTERNET_AsyncCall(&workRequest); |
| 2801 | /* |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2802 | * This is from windows. |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2803 | */ |
Francois Gouget | e66d1cd | 2007-01-09 12:30:45 +0100 | [diff] [blame] | 2804 | INTERNET_SetLastError(ERROR_IO_PENDING); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2805 | r = FALSE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2806 | } |
| 2807 | else |
| 2808 | { |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2809 | r = HTTP_HttpSendRequestW(lpwhr, lpszHeaders, |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2810 | dwHeaderLength, lpOptional, dwOptionalLength, |
| 2811 | dwOptionalLength, TRUE); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2812 | } |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2813 | lend: |
| 2814 | if( lpwhr ) |
| 2815 | WININET_Release( &lpwhr->hdr ); |
| 2816 | return r; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2817 | } |
| 2818 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2819 | /*********************************************************************** |
Dimitrie O. Paun | f3b681a | 2004-06-28 20:28:38 +0000 | [diff] [blame] | 2820 | * HttpSendRequestA (WININET.@) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2821 | * |
| 2822 | * Sends the specified request to the HTTP server |
| 2823 | * |
| 2824 | * RETURNS |
| 2825 | * TRUE on success |
| 2826 | * FALSE on failure |
| 2827 | * |
| 2828 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2829 | BOOL WINAPI HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders, |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2830 | DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength) |
| 2831 | { |
| 2832 | BOOL result; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2833 | LPWSTR szHeaders=NULL; |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2834 | DWORD nLen=dwHeaderLength; |
| 2835 | if(lpszHeaders!=NULL) |
| 2836 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2837 | nLen=MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,NULL,0); |
| 2838 | szHeaders=HeapAlloc(GetProcessHeap(),0,nLen*sizeof(WCHAR)); |
| 2839 | MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,szHeaders,nLen); |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2840 | } |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2841 | result=HttpSendRequestW(hHttpRequest, szHeaders, nLen, lpOptional, dwOptionalLength); |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 2842 | HeapFree(GetProcessHeap(),0,szHeaders); |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 2843 | return result; |
| 2844 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2845 | |
Jacek Caban | d7a49e8 | 2008-02-13 13:32:49 +0100 | [diff] [blame] | 2846 | static BOOL HTTP_GetRequestURL(WININETHTTPREQW *req, LPWSTR buf) |
| 2847 | { |
| 2848 | LPHTTPHEADERW host_header; |
| 2849 | |
| 2850 | static const WCHAR formatW[] = {'h','t','t','p',':','/','/','%','s','%','s',0}; |
| 2851 | |
| 2852 | host_header = HTTP_GetHeader(req, szHost); |
| 2853 | if(!host_header) |
| 2854 | return FALSE; |
| 2855 | |
| 2856 | sprintfW(buf, formatW, host_header->lpszValue, req->lpszPath); /* FIXME */ |
| 2857 | return TRUE; |
| 2858 | } |
| 2859 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2860 | /*********************************************************************** |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2861 | * HTTP_HandleRedirect (internal) |
| 2862 | */ |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 2863 | static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl) |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2864 | { |
Jacek Caban | 61a1cef | 2006-10-29 18:51:15 +0100 | [diff] [blame] | 2865 | LPWININETHTTPSESSIONW lpwhs = lpwhr->lpHttpSession; |
Jacek Caban | a541a44 | 2006-10-29 18:49:39 +0100 | [diff] [blame] | 2866 | LPWININETAPPINFOW hIC = lpwhs->lpAppInfo; |
Hans Leidekker | 8210e1b | 2008-03-31 20:25:57 +0200 | [diff] [blame] | 2867 | BOOL using_proxy = hIC->lpszProxy && hIC->lpszProxy[0]; |
Hans Leidekker | 612f3c1 | 2008-03-31 20:26:16 +0200 | [diff] [blame^] | 2868 | WCHAR path[INTERNET_MAX_URL_LENGTH]; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 2869 | |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2870 | if(lpszUrl[0]=='/') |
| 2871 | { |
| 2872 | /* if it's an absolute path, keep the same session info */ |
Hans Leidekker | 612f3c1 | 2008-03-31 20:26:16 +0200 | [diff] [blame^] | 2873 | lstrcpynW(path, lpszUrl, INTERNET_MAX_URL_LENGTH); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2874 | } |
| 2875 | else |
| 2876 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2877 | URL_COMPONENTSW urlComponents; |
| 2878 | WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024]; |
Hans Leidekker | 781f3f7 | 2006-10-13 15:43:54 +0200 | [diff] [blame] | 2879 | static WCHAR szHttp[] = {'h','t','t','p',0}; |
| 2880 | static WCHAR szHttps[] = {'h','t','t','p','s',0}; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2881 | DWORD url_length = 0; |
| 2882 | LPWSTR orig_url; |
| 2883 | LPWSTR combined_url; |
| 2884 | |
| 2885 | urlComponents.dwStructSize = sizeof(URL_COMPONENTSW); |
Hans Leidekker | 781f3f7 | 2006-10-13 15:43:54 +0200 | [diff] [blame] | 2886 | urlComponents.lpszScheme = (lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE) ? szHttps : szHttp; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2887 | urlComponents.dwSchemeLength = 0; |
| 2888 | urlComponents.lpszHostName = lpwhs->lpszHostName; |
| 2889 | urlComponents.dwHostNameLength = 0; |
| 2890 | urlComponents.nPort = lpwhs->nHostPort; |
| 2891 | urlComponents.lpszUserName = lpwhs->lpszUserName; |
| 2892 | urlComponents.dwUserNameLength = 0; |
| 2893 | urlComponents.lpszPassword = NULL; |
| 2894 | urlComponents.dwPasswordLength = 0; |
| 2895 | urlComponents.lpszUrlPath = lpwhr->lpszPath; |
| 2896 | urlComponents.dwUrlPathLength = 0; |
| 2897 | urlComponents.lpszExtraInfo = NULL; |
| 2898 | urlComponents.dwExtraInfoLength = 0; |
| 2899 | |
| 2900 | if (!InternetCreateUrlW(&urlComponents, 0, NULL, &url_length) && |
| 2901 | (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) |
| 2902 | return FALSE; |
| 2903 | |
Robert Shearman | 80e4fb5 | 2006-03-21 13:44:36 +0000 | [diff] [blame] | 2904 | orig_url = HeapAlloc(GetProcessHeap(), 0, url_length); |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2905 | |
Robert Shearman | 80e4fb5 | 2006-03-21 13:44:36 +0000 | [diff] [blame] | 2906 | /* convert from bytes to characters */ |
| 2907 | url_length = url_length / sizeof(WCHAR) - 1; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2908 | if (!InternetCreateUrlW(&urlComponents, 0, orig_url, &url_length)) |
| 2909 | { |
| 2910 | HeapFree(GetProcessHeap(), 0, orig_url); |
| 2911 | return FALSE; |
| 2912 | } |
| 2913 | |
| 2914 | url_length = 0; |
| 2915 | if (!InternetCombineUrlW(orig_url, lpszUrl, NULL, &url_length, ICU_ENCODE_SPACES_ONLY) && |
| 2916 | (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) |
| 2917 | { |
| 2918 | HeapFree(GetProcessHeap(), 0, orig_url); |
| 2919 | return FALSE; |
| 2920 | } |
| 2921 | combined_url = HeapAlloc(GetProcessHeap(), 0, url_length * sizeof(WCHAR)); |
| 2922 | |
| 2923 | if (!InternetCombineUrlW(orig_url, lpszUrl, combined_url, &url_length, ICU_ENCODE_SPACES_ONLY)) |
| 2924 | { |
| 2925 | HeapFree(GetProcessHeap(), 0, orig_url); |
| 2926 | HeapFree(GetProcessHeap(), 0, combined_url); |
| 2927 | return FALSE; |
| 2928 | } |
| 2929 | HeapFree(GetProcessHeap(), 0, orig_url); |
| 2930 | |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2931 | userName[0] = 0; |
| 2932 | hostName[0] = 0; |
| 2933 | protocol[0] = 0; |
| 2934 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2935 | urlComponents.dwStructSize = sizeof(URL_COMPONENTSW); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2936 | urlComponents.lpszScheme = protocol; |
| 2937 | urlComponents.dwSchemeLength = 32; |
| 2938 | urlComponents.lpszHostName = hostName; |
| 2939 | urlComponents.dwHostNameLength = MAXHOSTNAME; |
| 2940 | urlComponents.lpszUserName = userName; |
| 2941 | urlComponents.dwUserNameLength = 1024; |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 2942 | urlComponents.lpszPassword = NULL; |
| 2943 | urlComponents.dwPasswordLength = 0; |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2944 | urlComponents.lpszUrlPath = path; |
| 2945 | urlComponents.dwUrlPathLength = 2048; |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 2946 | urlComponents.lpszExtraInfo = NULL; |
| 2947 | urlComponents.dwExtraInfoLength = 0; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2948 | if(!InternetCrackUrlW(combined_url, strlenW(combined_url), 0, &urlComponents)) |
| 2949 | { |
| 2950 | HeapFree(GetProcessHeap(), 0, combined_url); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2951 | return FALSE; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2952 | } |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 2953 | |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2954 | HeapFree(GetProcessHeap(), 0, combined_url); |
Robert Shearman | efac01b | 2005-11-29 11:25:31 +0100 | [diff] [blame] | 2955 | |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 2956 | if (!strncmpW(szHttp, urlComponents.lpszScheme, strlenW(szHttp)) && |
Robert Shearman | efac01b | 2005-11-29 11:25:31 +0100 | [diff] [blame] | 2957 | (lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE)) |
| 2958 | { |
| 2959 | TRACE("redirect from secure page to non-secure page\n"); |
| 2960 | /* FIXME: warn about from secure redirect to non-secure page */ |
| 2961 | lpwhr->hdr.dwFlags &= ~INTERNET_FLAG_SECURE; |
| 2962 | } |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 2963 | if (!strncmpW(szHttps, urlComponents.lpszScheme, strlenW(szHttps)) && |
Robert Shearman | efac01b | 2005-11-29 11:25:31 +0100 | [diff] [blame] | 2964 | !(lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE)) |
| 2965 | { |
| 2966 | TRACE("redirect from non-secure page to secure page\n"); |
| 2967 | /* FIXME: notify about redirect to secure page */ |
| 2968 | lpwhr->hdr.dwFlags |= INTERNET_FLAG_SECURE; |
| 2969 | } |
| 2970 | |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2971 | if (urlComponents.nPort == INTERNET_INVALID_PORT_NUMBER) |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2972 | { |
| 2973 | if (lstrlenW(protocol)>4) /*https*/ |
| 2974 | urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT; |
| 2975 | else /*http*/ |
| 2976 | urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT; |
| 2977 | } |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2978 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 2979 | #if 0 |
| 2980 | /* |
| 2981 | * This upsets redirects to binary files on sourceforge.net |
| 2982 | * and gives an html page instead of the target file |
| 2983 | * Examination of the HTTP request sent by native wininet.dll |
| 2984 | * reveals that it doesn't send a referrer in that case. |
| 2985 | * Maybe there's a flag that enables this, or maybe a referrer |
| 2986 | * shouldn't be added in case of a redirect. |
| 2987 | */ |
| 2988 | |
| 2989 | /* consider the current host as the referrer */ |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 2990 | if (lpwhs->lpszServerName && *lpwhs->lpszServerName) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 2991 | HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpwhs->lpszServerName, |
| 2992 | HTTP_ADDHDR_FLAG_REQ|HTTP_ADDREQ_FLAG_REPLACE| |
| 2993 | HTTP_ADDHDR_FLAG_ADD_IF_NEW); |
| 2994 | #endif |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2995 | |
Robert Shearman | 8a8ce9c | 2005-11-29 11:35:19 +0100 | [diff] [blame] | 2996 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszHostName); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2997 | if (urlComponents.nPort != INTERNET_DEFAULT_HTTP_PORT && |
Hans Leidekker | 8210e1b | 2008-03-31 20:25:57 +0200 | [diff] [blame] | 2998 | urlComponents.nPort != INTERNET_DEFAULT_HTTPS_PORT) |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2999 | { |
| 3000 | int len; |
Andrew Ziem | 7053321 | 2006-05-24 00:22:38 -0600 | [diff] [blame] | 3001 | static const WCHAR fmt[] = {'%','s',':','%','i',0}; |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 3002 | len = lstrlenW(hostName); |
Robert Shearman | 8a8ce9c | 2005-11-29 11:35:19 +0100 | [diff] [blame] | 3003 | len += 7; /* 5 for strlen("65535") + 1 for ":" + 1 for '\0' */ |
| 3004 | lpwhs->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
| 3005 | sprintfW(lpwhs->lpszHostName, fmt, hostName, urlComponents.nPort); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 3006 | } |
| 3007 | else |
Robert Shearman | 8a8ce9c | 2005-11-29 11:35:19 +0100 | [diff] [blame] | 3008 | lpwhs->lpszHostName = WININET_strdupW(hostName); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 3009 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3010 | HTTP_ProcessHeader(lpwhr, szHost, lpwhs->lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 3011 | |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 3012 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName); |
Robert Shearman | ef20936 | 2006-03-10 12:28:52 +0000 | [diff] [blame] | 3013 | lpwhs->lpszUserName = NULL; |
| 3014 | if (userName[0]) |
| 3015 | lpwhs->lpszUserName = WININET_strdupW(userName); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3016 | |
Hans Leidekker | 8210e1b | 2008-03-31 20:25:57 +0200 | [diff] [blame] | 3017 | if (!using_proxy) |
| 3018 | { |
| 3019 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); |
| 3020 | lpwhs->lpszServerName = WININET_strdupW(hostName); |
| 3021 | lpwhs->nServerPort = urlComponents.nPort; |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3022 | |
Hans Leidekker | 8210e1b | 2008-03-31 20:25:57 +0200 | [diff] [blame] | 3023 | if (!HTTP_ResolveName(lpwhr)) |
| 3024 | return FALSE; |
Robert Shearman | 9981f33 | 2006-03-06 17:31:09 +0000 | [diff] [blame] | 3025 | |
Hans Leidekker | 8210e1b | 2008-03-31 20:25:57 +0200 | [diff] [blame] | 3026 | NETCON_close(&lpwhr->netConnection); |
| 3027 | |
| 3028 | if (!NETCON_init(&lpwhr->netConnection,lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE)) |
| 3029 | return FALSE; |
| 3030 | } |
| 3031 | else |
| 3032 | TRACE("Redirect through proxy\n"); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3033 | } |
| 3034 | |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 3035 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3036 | lpwhr->lpszPath=NULL; |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 3037 | if (*path) |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3038 | { |
| 3039 | DWORD needed = 0; |
| 3040 | HRESULT rc; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3041 | |
| 3042 | rc = UrlEscapeW(path, NULL, &needed, URL_ESCAPE_SPACES_ONLY); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3043 | if (rc != E_POINTER) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3044 | needed = strlenW(path)+1; |
| 3045 | lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, needed*sizeof(WCHAR)); |
| 3046 | rc = UrlEscapeW(path, lpwhr->lpszPath, &needed, |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3047 | URL_ESCAPE_SPACES_ONLY); |
| 3048 | if (rc) |
| 3049 | { |
Hans Leidekker | cd2c458 | 2006-10-05 13:18:56 +0200 | [diff] [blame] | 3050 | ERR("Unable to escape string!(%s) (%d)\n",debugstr_w(path),rc); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3051 | strcpyW(lpwhr->lpszPath,path); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3052 | } |
| 3053 | } |
| 3054 | |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 3055 | return TRUE; |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | /*********************************************************************** |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 3059 | * HTTP_build_req (internal) |
| 3060 | * |
| 3061 | * concatenate all the strings in the request together |
| 3062 | */ |
| 3063 | static LPWSTR HTTP_build_req( LPCWSTR *list, int len ) |
| 3064 | { |
| 3065 | LPCWSTR *t; |
| 3066 | LPWSTR str; |
| 3067 | |
| 3068 | for( t = list; *t ; t++ ) |
| 3069 | len += strlenW( *t ); |
| 3070 | len++; |
| 3071 | |
| 3072 | str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); |
| 3073 | *str = 0; |
| 3074 | |
| 3075 | for( t = list; *t ; t++ ) |
| 3076 | strcatW( str, *t ); |
| 3077 | |
| 3078 | return str; |
| 3079 | } |
| 3080 | |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 3081 | static BOOL HTTP_SecureProxyConnect(LPWININETHTTPREQW lpwhr) |
| 3082 | { |
| 3083 | LPWSTR lpszPath; |
| 3084 | LPWSTR requestString; |
| 3085 | INT len; |
| 3086 | INT cnt; |
| 3087 | INT responseLen; |
| 3088 | char *ascii_req; |
| 3089 | BOOL ret; |
| 3090 | static const WCHAR szConnect[] = {'C','O','N','N','E','C','T',0}; |
| 3091 | static const WCHAR szFormat[] = {'%','s',':','%','d',0}; |
Jacek Caban | 61a1cef | 2006-10-29 18:51:15 +0100 | [diff] [blame] | 3092 | LPWININETHTTPSESSIONW lpwhs = lpwhr->lpHttpSession; |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 3093 | |
| 3094 | TRACE("\n"); |
| 3095 | |
| 3096 | lpszPath = HeapAlloc( GetProcessHeap(), 0, (lstrlenW( lpwhs->lpszHostName ) + 13)*sizeof(WCHAR) ); |
| 3097 | sprintfW( lpszPath, szFormat, lpwhs->lpszHostName, lpwhs->nHostPort ); |
Hans Leidekker | d0033db | 2008-02-17 20:41:42 +0100 | [diff] [blame] | 3098 | requestString = HTTP_BuildHeaderRequestString( lpwhr, szConnect, lpszPath, g_szHttp1_1 ); |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 3099 | HeapFree( GetProcessHeap(), 0, lpszPath ); |
| 3100 | |
| 3101 | len = WideCharToMultiByte( CP_ACP, 0, requestString, -1, |
| 3102 | NULL, 0, NULL, NULL ); |
| 3103 | len--; /* the nul terminator isn't needed */ |
| 3104 | ascii_req = HeapAlloc( GetProcessHeap(), 0, len ); |
| 3105 | WideCharToMultiByte( CP_ACP, 0, requestString, -1, |
| 3106 | ascii_req, len, NULL, NULL ); |
| 3107 | HeapFree( GetProcessHeap(), 0, requestString ); |
| 3108 | |
| 3109 | TRACE("full request -> %s\n", debugstr_an( ascii_req, len ) ); |
| 3110 | |
| 3111 | ret = NETCON_send( &lpwhr->netConnection, ascii_req, len, 0, &cnt ); |
| 3112 | HeapFree( GetProcessHeap(), 0, ascii_req ); |
| 3113 | if (!ret || cnt < 0) |
| 3114 | return FALSE; |
| 3115 | |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 3116 | responseLen = HTTP_GetResponseHeaders( lpwhr, TRUE ); |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 3117 | if (!responseLen) |
| 3118 | return FALSE; |
| 3119 | |
| 3120 | return TRUE; |
| 3121 | } |
| 3122 | |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 3123 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3124 | * HTTP_HttpSendRequestW (internal) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3125 | * |
| 3126 | * Sends the specified request to the HTTP server |
| 3127 | * |
| 3128 | * RETURNS |
| 3129 | * TRUE on success |
| 3130 | * FALSE on failure |
| 3131 | * |
| 3132 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3133 | BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders, |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 3134 | DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength, |
| 3135 | DWORD dwContentLength, BOOL bEndRequest) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3136 | { |
| 3137 | INT cnt; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3138 | BOOL bSuccess = FALSE; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3139 | LPWSTR requestString = NULL; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3140 | INT responseLen; |
Rob Shearman | 14fb418 | 2007-01-04 18:21:13 +0000 | [diff] [blame] | 3141 | BOOL loop_next; |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 3142 | INTERNET_ASYNC_RESULT iar; |
Rob Shearman | cf43b16 | 2007-01-04 18:21:34 +0000 | [diff] [blame] | 3143 | static const WCHAR szClose[] = { 'C','l','o','s','e',0 }; |
Hans Leidekker | b0912d1 | 2008-02-02 16:08:28 +0100 | [diff] [blame] | 3144 | static const WCHAR szPost[] = { 'P','O','S','T',0 }; |
Hans Leidekker | 64359c2 | 2007-10-28 16:32:46 +0100 | [diff] [blame] | 3145 | static const WCHAR szContentLength[] = |
| 3146 | { 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','l','i','\r','\n',0 }; |
| 3147 | WCHAR contentLengthStr[sizeof szContentLength/2 /* includes \r\n */ + 20 /* int */ ]; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3148 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3149 | TRACE("--> %p\n", lpwhr); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3150 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3151 | assert(lpwhr->hdr.htype == WH_HHTTPREQ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3152 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3153 | /* Clear any error information */ |
| 3154 | INTERNET_SetLastError(0); |
| 3155 | |
Jacek Caban | f979134 | 2008-02-13 13:34:05 +0100 | [diff] [blame] | 3156 | /* if the verb is NULL default to GET */ |
| 3157 | if (!lpwhr->lpszVerb) |
| 3158 | lpwhr->lpszVerb = WININET_strdupW(szGET); |
| 3159 | |
Hans Leidekker | b0912d1 | 2008-02-02 16:08:28 +0100 | [diff] [blame] | 3160 | if (dwContentLength || !strcmpW(lpwhr->lpszVerb, szPost)) |
| 3161 | { |
| 3162 | sprintfW(contentLengthStr, szContentLength, dwContentLength); |
| 3163 | HTTP_HttpAddRequestHeadersW(lpwhr, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE); |
| 3164 | } |
David Hammerton | 6226f3f | 2003-08-05 18:31:02 +0000 | [diff] [blame] | 3165 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 3166 | do |
Nikolas Zimmermann | 7659882 | 2001-10-04 18:12:41 +0000 | [diff] [blame] | 3167 | { |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 3168 | DWORD len; |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 3169 | char *ascii_req; |
| 3170 | |
Rob Shearman | 14fb418 | 2007-01-04 18:21:13 +0000 | [diff] [blame] | 3171 | loop_next = FALSE; |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 3172 | |
| 3173 | /* like native, just in case the caller forgot to call InternetReadFile |
| 3174 | * for all the data */ |
| 3175 | HTTP_DrainContent(lpwhr); |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 3176 | lpwhr->dwContentRead = 0; |
Rob Shearman | 14fb418 | 2007-01-04 18:21:13 +0000 | [diff] [blame] | 3177 | |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 3178 | if (TRACE_ON(wininet)) |
| 3179 | { |
| 3180 | LPHTTPHEADERW Host = HTTP_GetHeader(lpwhr,szHost); |
| 3181 | TRACE("Going to url %s %s\n", debugstr_w(Host->lpszValue), debugstr_w(lpwhr->lpszPath)); |
| 3182 | } |
Nikolas Zimmermann | 7659882 | 2001-10-04 18:12:41 +0000 | [diff] [blame] | 3183 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 3184 | HTTP_FixURL(lpwhr); |
Hans Leidekker | bb9413d | 2007-08-09 21:43:25 +0200 | [diff] [blame] | 3185 | HTTP_ProcessHeader(lpwhr, szConnection, |
| 3186 | lpwhr->hdr.dwFlags & INTERNET_FLAG_KEEP_CONNECTION ? szKeepAlive : szClose, |
| 3187 | HTTP_ADDHDR_FLAG_REQ | HTTP_ADDHDR_FLAG_REPLACE); |
| 3188 | |
Rob Shearman | ebaa4d9 | 2008-03-12 13:27:46 +0000 | [diff] [blame] | 3189 | HTTP_InsertAuthorization(lpwhr, lpwhr->pAuthInfo, szAuthorization); |
| 3190 | HTTP_InsertAuthorization(lpwhr, lpwhr->pProxyAuthInfo, szProxy_Authorization); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3191 | |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 3192 | /* add the headers the caller supplied */ |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 3193 | if( lpszHeaders && dwHeaderLength ) |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 3194 | { |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 3195 | HTTP_HttpAddRequestHeadersW(lpwhr, lpszHeaders, dwHeaderLength, |
| 3196 | HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE); |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
Hans Leidekker | 0ffe9f5 | 2008-03-30 19:16:52 +0100 | [diff] [blame] | 3199 | if (lpwhr->lpHttpSession->lpAppInfo->lpszProxy && lpwhr->lpHttpSession->lpAppInfo->lpszProxy[0]) |
| 3200 | { |
| 3201 | WCHAR *url = HTTP_BuildProxyRequestUrl(lpwhr); |
| 3202 | requestString = HTTP_BuildHeaderRequestString(lpwhr, lpwhr->lpszVerb, url, lpwhr->lpszVersion); |
| 3203 | HeapFree(GetProcessHeap(), 0, url); |
| 3204 | } |
| 3205 | else |
| 3206 | requestString = HTTP_BuildHeaderRequestString(lpwhr, lpwhr->lpszVerb, lpwhr->lpszPath, lpwhr->lpszVersion); |
| 3207 | |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 3208 | |
| 3209 | TRACE("Request header -> %s\n", debugstr_w(requestString) ); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3210 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 3211 | /* Send the request and store the results */ |
| 3212 | if (!HTTP_OpenConnection(lpwhr)) |
| 3213 | goto lend; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3214 | |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 3215 | /* send the request as ASCII, tack on the optional data */ |
| 3216 | if( !lpOptional ) |
| 3217 | dwOptionalLength = 0; |
| 3218 | len = WideCharToMultiByte( CP_ACP, 0, requestString, -1, |
| 3219 | NULL, 0, NULL, NULL ); |
| 3220 | ascii_req = HeapAlloc( GetProcessHeap(), 0, len + dwOptionalLength ); |
| 3221 | WideCharToMultiByte( CP_ACP, 0, requestString, -1, |
| 3222 | ascii_req, len, NULL, NULL ); |
| 3223 | if( lpOptional ) |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 3224 | memcpy( &ascii_req[len-1], lpOptional, dwOptionalLength ); |
| 3225 | len = (len + dwOptionalLength - 1); |
| 3226 | ascii_req[len] = 0; |
Aric Stewart | 44cbdf2 | 2005-10-19 18:28:35 +0000 | [diff] [blame] | 3227 | TRACE("full request -> %s\n", debugstr_a(ascii_req) ); |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 3228 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 3229 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 3230 | INTERNET_STATUS_SENDING_REQUEST, NULL, 0); |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 3231 | |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 3232 | NETCON_send(&lpwhr->netConnection, ascii_req, len, 0, &cnt); |
| 3233 | HeapFree( GetProcessHeap(), 0, ascii_req ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 3234 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 3235 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 3236 | INTERNET_STATUS_REQUEST_SENT, |
| 3237 | &len, sizeof(DWORD)); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 3238 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 3239 | if (bEndRequest) |
| 3240 | { |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 3241 | DWORD dwBufferSize; |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 3242 | DWORD dwStatusCode; |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 3243 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 3244 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 3245 | INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0); |
| 3246 | |
| 3247 | if (cnt < 0) |
| 3248 | goto lend; |
| 3249 | |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 3250 | responseLen = HTTP_GetResponseHeaders(lpwhr, TRUE); |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 3251 | if (responseLen) |
| 3252 | bSuccess = TRUE; |
| 3253 | |
| 3254 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 3255 | INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen, |
| 3256 | sizeof(DWORD)); |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 3257 | |
Hans Leidekker | 9717113 | 2008-02-17 21:29:45 +0100 | [diff] [blame] | 3258 | HTTP_ProcessCookies(lpwhr); |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 3259 | |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 3260 | dwBufferSize = sizeof(lpwhr->dwContentLength); |
| 3261 | if (!HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, |
| 3262 | &lpwhr->dwContentLength,&dwBufferSize,NULL)) |
| 3263 | lpwhr->dwContentLength = -1; |
| 3264 | |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 3265 | if (lpwhr->dwContentLength == 0) |
| 3266 | HTTP_FinishedReading(lpwhr); |
| 3267 | |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 3268 | dwBufferSize = sizeof(dwStatusCode); |
| 3269 | if (!HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE, |
| 3270 | &dwStatusCode,&dwBufferSize,NULL)) |
| 3271 | dwStatusCode = 0; |
| 3272 | |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 3273 | if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT) && bSuccess) |
| 3274 | { |
Hans Leidekker | 612f3c1 | 2008-03-31 20:26:16 +0200 | [diff] [blame^] | 3275 | WCHAR szNewLocation[INTERNET_MAX_URL_LENGTH]; |
Rob Shearman | 9efe083 | 2007-01-12 19:19:18 -0600 | [diff] [blame] | 3276 | dwBufferSize=sizeof(szNewLocation); |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 3277 | if ((dwStatusCode==HTTP_STATUS_REDIRECT || dwStatusCode==HTTP_STATUS_MOVED) && |
Rob Shearman | ac1b527 | 2007-01-04 18:21:49 +0000 | [diff] [blame] | 3278 | HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,NULL)) |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 3279 | { |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 3280 | HTTP_DrainContent(lpwhr); |
Rob Shearman | 4319ec6 | 2006-12-07 00:53:27 +0000 | [diff] [blame] | 3281 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 3282 | INTERNET_STATUS_REDIRECT, szNewLocation, |
| 3283 | dwBufferSize); |
| 3284 | bSuccess = HTTP_HandleRedirect(lpwhr, szNewLocation); |
| 3285 | if (bSuccess) |
| 3286 | { |
| 3287 | HeapFree(GetProcessHeap(), 0, requestString); |
| 3288 | loop_next = TRUE; |
| 3289 | } |
| 3290 | } |
| 3291 | } |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 3292 | if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_AUTH) && bSuccess) |
| 3293 | { |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 3294 | WCHAR szAuthValue[2048]; |
| 3295 | dwBufferSize=2048; |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 3296 | if (dwStatusCode == HTTP_STATUS_DENIED) |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 3297 | { |
| 3298 | DWORD dwIndex = 0; |
| 3299 | while (HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_WWW_AUTHENTICATE,szAuthValue,&dwBufferSize,&dwIndex)) |
| 3300 | { |
Rob Shearman | cb28969 | 2007-06-05 19:49:58 +0100 | [diff] [blame] | 3301 | if (HTTP_DoAuthorization(lpwhr, szAuthValue, |
| 3302 | &lpwhr->pAuthInfo, |
| 3303 | lpwhr->lpHttpSession->lpszUserName, |
| 3304 | lpwhr->lpHttpSession->lpszPassword)) |
| 3305 | { |
| 3306 | loop_next = TRUE; |
| 3307 | break; |
| 3308 | } |
| 3309 | } |
| 3310 | } |
| 3311 | if (dwStatusCode == HTTP_STATUS_PROXY_AUTH_REQ) |
| 3312 | { |
| 3313 | DWORD dwIndex = 0; |
| 3314 | while (HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_PROXY_AUTHENTICATE,szAuthValue,&dwBufferSize,&dwIndex)) |
| 3315 | { |
| 3316 | if (HTTP_DoAuthorization(lpwhr, szAuthValue, |
| 3317 | &lpwhr->pProxyAuthInfo, |
| 3318 | lpwhr->lpHttpSession->lpAppInfo->lpszProxyUsername, |
| 3319 | lpwhr->lpHttpSession->lpAppInfo->lpszProxyPassword)) |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 3320 | { |
| 3321 | loop_next = TRUE; |
| 3322 | break; |
| 3323 | } |
| 3324 | } |
| 3325 | } |
| 3326 | } |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 3327 | } |
| 3328 | else |
| 3329 | bSuccess = TRUE; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 3330 | } |
| 3331 | while (loop_next); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3332 | |
Jacek Caban | d7a49e8 | 2008-02-13 13:32:49 +0100 | [diff] [blame] | 3333 | /* FIXME: Better check, when we have to create the cache file */ |
| 3334 | if(bSuccess && (lpwhr->hdr.dwFlags & INTERNET_FLAG_NEED_FILE)) { |
| 3335 | WCHAR url[INTERNET_MAX_URL_LENGTH]; |
| 3336 | WCHAR cacheFileName[MAX_PATH+1]; |
| 3337 | BOOL b; |
| 3338 | |
| 3339 | b = HTTP_GetRequestURL(lpwhr, url); |
| 3340 | if(!b) { |
| 3341 | WARN("Could not get URL\n"); |
| 3342 | goto lend; |
| 3343 | } |
| 3344 | |
| 3345 | b = CreateUrlCacheEntryW(url, lpwhr->dwContentLength > 0 ? lpwhr->dwContentLength : 0, NULL, cacheFileName, 0); |
| 3346 | if(b) { |
| 3347 | lpwhr->lpszCacheFile = WININET_strdupW(cacheFileName); |
| 3348 | lpwhr->hCacheFile = CreateFileW(lpwhr->lpszCacheFile, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, |
| 3349 | NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 3350 | if(lpwhr->hCacheFile == INVALID_HANDLE_VALUE) { |
| 3351 | WARN("Could not create file: %u\n", GetLastError()); |
| 3352 | lpwhr->hCacheFile = NULL; |
| 3353 | } |
| 3354 | }else { |
| 3355 | WARN("Could not create cache entry: %08x\n", GetLastError()); |
| 3356 | } |
| 3357 | } |
| 3358 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3359 | lend: |
| 3360 | |
Michael Stefaniuc | 7cb43c9 | 2004-12-21 14:42:35 +0000 | [diff] [blame] | 3361 | HeapFree(GetProcessHeap(), 0, requestString); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3362 | |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3363 | /* TODO: send notification for P3P header */ |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 3364 | |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 3365 | iar.dwResult = (DWORD)bSuccess; |
| 3366 | iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError(); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3367 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 3368 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 3369 | INTERNET_STATUS_REQUEST_COMPLETE, &iar, |
| 3370 | sizeof(INTERNET_ASYNC_RESULT)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3371 | |
| 3372 | TRACE("<--\n"); |
| 3373 | return bSuccess; |
| 3374 | } |
| 3375 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3376 | /*********************************************************************** |
Jacek Caban | 5a535d6 | 2008-02-26 20:20:41 +0100 | [diff] [blame] | 3377 | * HTTPSESSION_Destroy (internal) |
| 3378 | * |
| 3379 | * Deallocate session handle |
| 3380 | * |
| 3381 | */ |
| 3382 | static void HTTPSESSION_Destroy(WININETHANDLEHEADER *hdr) |
| 3383 | { |
| 3384 | LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) hdr; |
| 3385 | |
| 3386 | TRACE("%p\n", lpwhs); |
| 3387 | |
| 3388 | WININET_Release(&lpwhs->lpAppInfo->hdr); |
| 3389 | |
| 3390 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszHostName); |
| 3391 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); |
| 3392 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszPassword); |
| 3393 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName); |
| 3394 | HeapFree(GetProcessHeap(), 0, lpwhs); |
| 3395 | } |
| 3396 | |
Jacek Caban | e2933c2 | 2008-03-12 02:23:20 +0100 | [diff] [blame] | 3397 | static DWORD HTTPSESSION_QueryOption(WININETHANDLEHEADER *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode) |
| 3398 | { |
| 3399 | switch(option) { |
| 3400 | case INTERNET_OPTION_HANDLE_TYPE: |
| 3401 | TRACE("INTERNET_OPTION_HANDLE_TYPE\n"); |
| 3402 | |
| 3403 | if (*size < sizeof(ULONG)) |
| 3404 | return ERROR_INSUFFICIENT_BUFFER; |
| 3405 | |
| 3406 | *size = sizeof(DWORD); |
| 3407 | *(DWORD*)buffer = INTERNET_HANDLE_TYPE_CONNECT_HTTP; |
| 3408 | return ERROR_SUCCESS; |
| 3409 | } |
| 3410 | |
| 3411 | FIXME("Not implemented option %d\n", option); |
| 3412 | return ERROR_INTERNET_INVALID_OPTION; |
| 3413 | } |
Jacek Caban | 5a535d6 | 2008-02-26 20:20:41 +0100 | [diff] [blame] | 3414 | |
| 3415 | static const HANDLEHEADERVtbl HTTPSESSIONVtbl = { |
Jacek Caban | 7dc9bf6 | 2008-02-26 20:21:00 +0100 | [diff] [blame] | 3416 | HTTPSESSION_Destroy, |
Jacek Caban | 1ffcfbc | 2008-02-26 20:21:34 +0100 | [diff] [blame] | 3417 | NULL, |
Jacek Caban | e2933c2 | 2008-03-12 02:23:20 +0100 | [diff] [blame] | 3418 | HTTPSESSION_QueryOption, |
Jacek Caban | 0e33eee | 2008-02-26 20:22:02 +0100 | [diff] [blame] | 3419 | NULL, |
Jacek Caban | 8c45eec | 2008-02-27 18:55:09 +0100 | [diff] [blame] | 3420 | NULL, |
Jacek Caban | 3314184 | 2008-02-29 12:57:57 +0100 | [diff] [blame] | 3421 | NULL, |
Jacek Caban | 3b4ca69 | 2008-03-02 19:35:11 +0100 | [diff] [blame] | 3422 | NULL, |
Jacek Caban | d597fd1 | 2008-03-03 18:07:20 +0100 | [diff] [blame] | 3423 | NULL, |
Jacek Caban | 7dc9bf6 | 2008-02-26 20:21:00 +0100 | [diff] [blame] | 3424 | NULL |
Jacek Caban | 5a535d6 | 2008-02-26 20:20:41 +0100 | [diff] [blame] | 3425 | }; |
| 3426 | |
| 3427 | |
| 3428 | /*********************************************************************** |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3429 | * HTTP_Connect (internal) |
| 3430 | * |
| 3431 | * Create http session handle |
| 3432 | * |
| 3433 | * RETURNS |
| 3434 | * HINTERNET a session handle on success |
| 3435 | * NULL on failure |
| 3436 | * |
| 3437 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3438 | HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3439 | INTERNET_PORT nServerPort, LPCWSTR lpszUserName, |
Francois Gouget | d4337f2 | 2007-08-30 16:21:33 +0200 | [diff] [blame] | 3440 | LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext, |
Kevin Koltzau | 917df92 | 2004-05-13 05:17:25 +0000 | [diff] [blame] | 3441 | DWORD dwInternalFlags) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3442 | { |
| 3443 | BOOL bSuccess = FALSE; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3444 | LPWININETHTTPSESSIONW lpwhs = NULL; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 3445 | HINTERNET handle = NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3446 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3447 | TRACE("-->\n"); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3448 | |
Rob Shearman | 59ab0cf | 2008-01-31 14:47:25 +0000 | [diff] [blame] | 3449 | if (!lpszServerName || !lpszServerName[0]) |
| 3450 | { |
| 3451 | INTERNET_SetLastError(ERROR_INVALID_PARAMETER); |
| 3452 | goto lerror; |
| 3453 | } |
| 3454 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3455 | assert( hIC->hdr.htype == WH_HINIT ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3456 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3457 | lpwhs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPSESSIONW)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3458 | if (NULL == lpwhs) |
| 3459 | { |
| 3460 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
| 3461 | goto lerror; |
| 3462 | } |
| 3463 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3464 | /* |
| 3465 | * According to my tests. The name is not resolved until a request is sent |
| 3466 | */ |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3467 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3468 | lpwhs->hdr.htype = WH_HHTTPSESSION; |
Jacek Caban | 5a535d6 | 2008-02-26 20:20:41 +0100 | [diff] [blame] | 3469 | lpwhs->hdr.vtbl = &HTTPSESSIONVtbl; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3470 | lpwhs->hdr.dwFlags = dwFlags; |
| 3471 | lpwhs->hdr.dwContext = dwContext; |
Jacek Caban | 5c53baa | 2006-10-30 22:14:59 +0100 | [diff] [blame] | 3472 | lpwhs->hdr.dwInternalFlags = dwInternalFlags | (hIC->hdr.dwInternalFlags & INET_CALLBACKW); |
Rob Shearman | bdc81d9 | 2008-03-10 16:39:15 +0000 | [diff] [blame] | 3473 | lpwhs->hdr.refs = 1; |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 3474 | lpwhs->hdr.lpfnStatusCB = hIC->hdr.lpfnStatusCB; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3475 | |
Jacek Caban | c250617 | 2006-10-29 18:48:48 +0100 | [diff] [blame] | 3476 | WININET_AddRef( &hIC->hdr ); |
| 3477 | lpwhs->lpAppInfo = hIC; |
Misha Koshelev | 728e5fa | 2007-09-20 20:59:40 -0500 | [diff] [blame] | 3478 | list_add_head( &hIC->hdr.children, &lpwhs->hdr.entry ); |
Jacek Caban | c250617 | 2006-10-29 18:48:48 +0100 | [diff] [blame] | 3479 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3480 | handle = WININET_AllocHandle( &lpwhs->hdr ); |
| 3481 | if (NULL == handle) |
| 3482 | { |
| 3483 | ERR("Failed to alloc handle\n"); |
| 3484 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
| 3485 | goto lerror; |
| 3486 | } |
| 3487 | |
Dominik Strasser | 94c02fe | 2003-04-14 21:32:36 +0000 | [diff] [blame] | 3488 | if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) { |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 3489 | if(strchrW(hIC->lpszProxy, ' ')) |
Dominik Strasser | 94c02fe | 2003-04-14 21:32:36 +0000 | [diff] [blame] | 3490 | FIXME("Several proxies not implemented.\n"); |
| 3491 | if(hIC->lpszProxyBypass) |
| 3492 | FIXME("Proxy bypass is ignored.\n"); |
| 3493 | } |
Robert Shearman | ef20936 | 2006-03-10 12:28:52 +0000 | [diff] [blame] | 3494 | if (lpszServerName && lpszServerName[0]) |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 3495 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3496 | lpwhs->lpszServerName = WININET_strdupW(lpszServerName); |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 3497 | lpwhs->lpszHostName = WININET_strdupW(lpszServerName); |
| 3498 | } |
Robert Shearman | ef20936 | 2006-03-10 12:28:52 +0000 | [diff] [blame] | 3499 | if (lpszUserName && lpszUserName[0]) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3500 | lpwhs->lpszUserName = WININET_strdupW(lpszUserName); |
Rob Shearman | 4b50768 | 2007-05-21 14:26:26 +0100 | [diff] [blame] | 3501 | if (lpszPassword && lpszPassword[0]) |
| 3502 | lpwhs->lpszPassword = WININET_strdupW(lpszPassword); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3503 | lpwhs->nServerPort = nServerPort; |
Robert Shearman | 3592110 | 2005-11-28 11:53:05 +0100 | [diff] [blame] | 3504 | lpwhs->nHostPort = nServerPort; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3505 | |
Kevin Koltzau | 917df92 | 2004-05-13 05:17:25 +0000 | [diff] [blame] | 3506 | /* Don't send a handle created callback if this handle was created with InternetOpenUrl */ |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 3507 | if (!(lpwhs->hdr.dwInternalFlags & INET_OPENURL)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3508 | { |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 3509 | INTERNET_SendCallback(&hIC->hdr, dwContext, |
| 3510 | INTERNET_STATUS_HANDLE_CREATED, &handle, |
| 3511 | sizeof(handle)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | bSuccess = TRUE; |
| 3515 | |
| 3516 | lerror: |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3517 | if( lpwhs ) |
| 3518 | WININET_Release( &lpwhs->hdr ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3519 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3520 | /* |
Francois Gouget | 93416cd | 2005-03-23 13:15:18 +0000 | [diff] [blame] | 3521 | * an INTERNET_STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3522 | * windows |
| 3523 | */ |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 3524 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 3525 | TRACE("%p --> %p (%p)\n", hIC, handle, lpwhs); |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 3526 | return handle; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | |
| 3530 | /*********************************************************************** |
| 3531 | * HTTP_OpenConnection (internal) |
| 3532 | * |
| 3533 | * Connect to a web server |
| 3534 | * |
| 3535 | * RETURNS |
| 3536 | * |
| 3537 | * TRUE on success |
| 3538 | * FALSE on failure |
| 3539 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 3540 | static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3541 | { |
| 3542 | BOOL bSuccess = FALSE; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3543 | LPWININETHTTPSESSIONW lpwhs; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 3544 | LPWININETAPPINFOW hIC = NULL; |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 3545 | char szaddr[32]; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3546 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3547 | TRACE("-->\n"); |
| 3548 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3549 | |
| 3550 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 3551 | { |
| 3552 | INTERNET_SetLastError(ERROR_INVALID_PARAMETER); |
| 3553 | goto lend; |
| 3554 | } |
| 3555 | |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 3556 | if (NETCON_connected(&lpwhr->netConnection)) |
| 3557 | { |
| 3558 | bSuccess = TRUE; |
| 3559 | goto lend; |
| 3560 | } |
| 3561 | |
Jacek Caban | 61a1cef | 2006-10-29 18:51:15 +0100 | [diff] [blame] | 3562 | lpwhs = lpwhr->lpHttpSession; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3563 | |
Jacek Caban | a541a44 | 2006-10-29 18:49:39 +0100 | [diff] [blame] | 3564 | hIC = lpwhs->lpAppInfo; |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 3565 | inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr, |
| 3566 | szaddr, sizeof(szaddr)); |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 3567 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 3568 | INTERNET_STATUS_CONNECTING_TO_SERVER, |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 3569 | szaddr, |
| 3570 | strlen(szaddr)+1); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3571 | |
Robert Shearman | e6157dd | 2005-11-15 18:16:55 +0000 | [diff] [blame] | 3572 | if (!NETCON_create(&lpwhr->netConnection, lpwhs->socketAddress.sin_family, |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 3573 | SOCK_STREAM, 0)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3574 | { |
| 3575 | WARN("Socket creation failed\n"); |
| 3576 | goto lend; |
| 3577 | } |
| 3578 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 3579 | if (!NETCON_connect(&lpwhr->netConnection, (struct sockaddr *)&lpwhs->socketAddress, |
| 3580 | sizeof(lpwhs->socketAddress))) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3581 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3582 | |
Robert Shearman | 13d371d | 2005-11-28 11:54:31 +0100 | [diff] [blame] | 3583 | if (lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE) |
| 3584 | { |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 3585 | /* Note: we differ from Microsoft's WinINet here. they seem to have |
| 3586 | * a bug that causes no status callbacks to be sent when starting |
| 3587 | * a tunnel to a proxy server using the CONNECT verb. i believe our |
| 3588 | * behaviour to be more correct and to not cause any incompatibilities |
| 3589 | * because using a secure connection through a proxy server is a rare |
| 3590 | * case that would be hard for anyone to depend on */ |
| 3591 | if (hIC->lpszProxy && !HTTP_SecureProxyConnect(lpwhr)) |
| 3592 | goto lend; |
| 3593 | |
Robert Shearman | 13d371d | 2005-11-28 11:54:31 +0100 | [diff] [blame] | 3594 | if (!NETCON_secure_connect(&lpwhr->netConnection, lpwhs->lpszHostName)) |
| 3595 | { |
| 3596 | WARN("Couldn't connect securely to host\n"); |
| 3597 | goto lend; |
| 3598 | } |
| 3599 | } |
| 3600 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 3601 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 3602 | INTERNET_STATUS_CONNECTED_TO_SERVER, |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 3603 | szaddr, strlen(szaddr)+1); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3604 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3605 | bSuccess = TRUE; |
| 3606 | |
| 3607 | lend: |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3608 | TRACE("%d <--\n", bSuccess); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3609 | return bSuccess; |
| 3610 | } |
| 3611 | |
| 3612 | |
| 3613 | /*********************************************************************** |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 3614 | * HTTP_clear_response_headers (internal) |
| 3615 | * |
| 3616 | * clear out any old response headers |
| 3617 | */ |
| 3618 | static void HTTP_clear_response_headers( LPWININETHTTPREQW lpwhr ) |
| 3619 | { |
| 3620 | DWORD i; |
| 3621 | |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 3622 | for( i=0; i<lpwhr->nCustHeaders; i++) |
| 3623 | { |
| 3624 | if( !lpwhr->pCustHeaders[i].lpszField ) |
| 3625 | continue; |
| 3626 | if( !lpwhr->pCustHeaders[i].lpszValue ) |
| 3627 | continue; |
| 3628 | if ( lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST ) |
| 3629 | continue; |
Robert Shearman | 7707a76 | 2005-03-10 11:14:24 +0000 | [diff] [blame] | 3630 | HTTP_DeleteCustomHeader( lpwhr, i ); |
| 3631 | i--; |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | |
| 3635 | /*********************************************************************** |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3636 | * HTTP_GetResponseHeaders (internal) |
| 3637 | * |
| 3638 | * Read server response |
| 3639 | * |
| 3640 | * RETURNS |
| 3641 | * |
| 3642 | * TRUE on success |
| 3643 | * FALSE on error |
| 3644 | */ |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 3645 | static INT HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr, BOOL clear) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3646 | { |
| 3647 | INT cbreaks = 0; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3648 | WCHAR buffer[MAX_REPLY_LEN]; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3649 | DWORD buflen = MAX_REPLY_LEN; |
| 3650 | BOOL bSuccess = FALSE; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3651 | INT rc = 0; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 3652 | static const WCHAR szCrLf[] = {'\r','\n',0}; |
Hans Leidekker | 2617fb6 | 2008-02-17 20:41:56 +0100 | [diff] [blame] | 3653 | static const WCHAR szHundred[] = {'1','0','0',0}; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3654 | char bufferA[MAX_REPLY_LEN]; |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 3655 | LPWSTR status_code, status_text; |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 3656 | DWORD cchMaxRawHeaders = 1024; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 3657 | LPWSTR lpszRawHeaders = HeapAlloc(GetProcessHeap(), 0, (cchMaxRawHeaders+1)*sizeof(WCHAR)); |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 3658 | DWORD cchRawHeaders = 0; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3659 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3660 | TRACE("-->\n"); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3661 | |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 3662 | /* clear old response headers (eg. from a redirect response) */ |
Hans Leidekker | 0936601 | 2008-03-26 11:31:21 +0100 | [diff] [blame] | 3663 | if (clear) HTTP_clear_response_headers( lpwhr ); |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 3664 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 3665 | if (!NETCON_connected(&lpwhr->netConnection)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3666 | goto lend; |
| 3667 | |
Hans Leidekker | 2617fb6 | 2008-02-17 20:41:56 +0100 | [diff] [blame] | 3668 | do { |
| 3669 | /* |
| 3670 | * HACK peek at the buffer |
| 3671 | */ |
| 3672 | buflen = MAX_REPLY_LEN; |
| 3673 | NETCON_recv(&lpwhr->netConnection, buffer, buflen, MSG_PEEK, &rc); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3674 | |
Hans Leidekker | 2617fb6 | 2008-02-17 20:41:56 +0100 | [diff] [blame] | 3675 | /* |
| 3676 | * We should first receive 'HTTP/1.x nnn OK' where nnn is the status code. |
| 3677 | */ |
| 3678 | memset(buffer, 0, MAX_REPLY_LEN); |
| 3679 | if (!NETCON_getNextLine(&lpwhr->netConnection, bufferA, &buflen)) |
| 3680 | goto lend; |
| 3681 | MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN ); |
| 3682 | |
| 3683 | /* split the version from the status code */ |
| 3684 | status_code = strchrW( buffer, ' ' ); |
| 3685 | if( !status_code ) |
| 3686 | goto lend; |
| 3687 | *status_code++=0; |
| 3688 | |
| 3689 | /* split the status code from the status text */ |
| 3690 | status_text = strchrW( status_code, ' ' ); |
| 3691 | if( !status_text ) |
| 3692 | goto lend; |
| 3693 | *status_text++=0; |
| 3694 | |
| 3695 | TRACE("version [%s] status code [%s] status text [%s]\n", |
| 3696 | debugstr_w(buffer), debugstr_w(status_code), debugstr_w(status_text) ); |
| 3697 | |
| 3698 | } while (!strcmpW(status_code, szHundred)); /* ignore "100 Continue" responses */ |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3699 | |
Maarten Lankhorst | 5132fb4 | 2008-02-25 11:05:41 -0800 | [diff] [blame] | 3700 | /* Add status code */ |
| 3701 | HTTP_ProcessHeader(lpwhr, szStatus, status_code, |
| 3702 | HTTP_ADDHDR_FLAG_REPLACE); |
| 3703 | |
| 3704 | HeapFree(GetProcessHeap(),0,lpwhr->lpszVersion); |
| 3705 | HeapFree(GetProcessHeap(),0,lpwhr->lpszStatusText); |
| 3706 | |
| 3707 | lpwhr->lpszVersion= WININET_strdupW(buffer); |
| 3708 | lpwhr->lpszStatusText = WININET_strdupW(status_text); |
| 3709 | |
| 3710 | /* Restore the spaces */ |
| 3711 | *(status_code-1) = ' '; |
| 3712 | *(status_text-1) = ' '; |
| 3713 | |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 3714 | /* regenerate raw headers */ |
| 3715 | while (cchRawHeaders + buflen + strlenW(szCrLf) > cchMaxRawHeaders) |
| 3716 | { |
| 3717 | cchMaxRawHeaders *= 2; |
| 3718 | lpszRawHeaders = HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders, (cchMaxRawHeaders+1)*sizeof(WCHAR)); |
| 3719 | } |
| 3720 | memcpy(lpszRawHeaders+cchRawHeaders, buffer, (buflen-1)*sizeof(WCHAR)); |
| 3721 | cchRawHeaders += (buflen-1); |
| 3722 | memcpy(lpszRawHeaders+cchRawHeaders, szCrLf, sizeof(szCrLf)); |
| 3723 | cchRawHeaders += sizeof(szCrLf)/sizeof(szCrLf[0])-1; |
| 3724 | lpszRawHeaders[cchRawHeaders] = '\0'; |
| 3725 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3726 | /* Parse each response line */ |
| 3727 | do |
| 3728 | { |
| 3729 | buflen = MAX_REPLY_LEN; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3730 | if (NETCON_getNextLine(&lpwhr->netConnection, bufferA, &buflen)) |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3731 | { |
| 3732 | LPWSTR * pFieldAndValue; |
| 3733 | |
Francois Gouget | da8b3dd | 2005-01-26 21:09:04 +0000 | [diff] [blame] | 3734 | TRACE("got line %s, now interpreting\n", debugstr_a(bufferA)); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3735 | MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN ); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 3736 | |
| 3737 | while (cchRawHeaders + buflen + strlenW(szCrLf) > cchMaxRawHeaders) |
| 3738 | { |
| 3739 | cchMaxRawHeaders *= 2; |
| 3740 | lpszRawHeaders = HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders, (cchMaxRawHeaders+1)*sizeof(WCHAR)); |
| 3741 | } |
| 3742 | memcpy(lpszRawHeaders+cchRawHeaders, buffer, (buflen-1)*sizeof(WCHAR)); |
| 3743 | cchRawHeaders += (buflen-1); |
| 3744 | memcpy(lpszRawHeaders+cchRawHeaders, szCrLf, sizeof(szCrLf)); |
| 3745 | cchRawHeaders += sizeof(szCrLf)/sizeof(szCrLf[0])-1; |
| 3746 | lpszRawHeaders[cchRawHeaders] = '\0'; |
| 3747 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3748 | pFieldAndValue = HTTP_InterpretHttpHeader(buffer); |
| 3749 | if (!pFieldAndValue) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3750 | break; |
| 3751 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3752 | HTTP_ProcessHeader(lpwhr, pFieldAndValue[0], pFieldAndValue[1], |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3753 | HTTP_ADDREQ_FLAG_ADD ); |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3754 | |
| 3755 | HTTP_FreeTokens(pFieldAndValue); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3756 | } |
| 3757 | else |
| 3758 | { |
| 3759 | cbreaks++; |
| 3760 | if (cbreaks >= 2) |
| 3761 | break; |
| 3762 | } |
| 3763 | }while(1); |
| 3764 | |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 3765 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 3766 | lpwhr->lpszRawHeaders = lpszRawHeaders; |
| 3767 | TRACE("raw headers: %s\n", debugstr_w(lpszRawHeaders)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3768 | bSuccess = TRUE; |
| 3769 | |
| 3770 | lend: |
| 3771 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3772 | TRACE("<--\n"); |
| 3773 | if (bSuccess) |
| 3774 | return rc; |
| 3775 | else |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 3776 | return 0; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3780 | static void strip_spaces(LPWSTR start) |
| 3781 | { |
| 3782 | LPWSTR str = start; |
| 3783 | LPWSTR end; |
| 3784 | |
| 3785 | while (*str == ' ' && *str != '\0') |
| 3786 | str++; |
| 3787 | |
| 3788 | if (str != start) |
| 3789 | memmove(start, str, sizeof(WCHAR) * (strlenW(str) + 1)); |
| 3790 | |
| 3791 | end = start + strlenW(start) - 1; |
| 3792 | while (end >= start && *end == ' ') |
| 3793 | { |
| 3794 | *end = '\0'; |
| 3795 | end--; |
| 3796 | } |
| 3797 | } |
| 3798 | |
| 3799 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3800 | /*********************************************************************** |
| 3801 | * HTTP_InterpretHttpHeader (internal) |
| 3802 | * |
| 3803 | * Parse server response |
| 3804 | * |
| 3805 | * RETURNS |
| 3806 | * |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3807 | * Pointer to array of field, value, NULL on success. |
| 3808 | * NULL on error. |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3809 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 3810 | static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3811 | { |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3812 | LPWSTR * pTokenPair; |
| 3813 | LPWSTR pszColon; |
| 3814 | INT len; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3815 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3816 | pTokenPair = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pTokenPair)*3); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3817 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3818 | pszColon = strchrW(buffer, ':'); |
| 3819 | /* must have two tokens */ |
| 3820 | if (!pszColon) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3821 | { |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3822 | HTTP_FreeTokens(pTokenPair); |
Robert Shearman | 7707a76 | 2005-03-10 11:14:24 +0000 | [diff] [blame] | 3823 | if (buffer[0]) |
| 3824 | TRACE("No ':' in line: %s\n", debugstr_w(buffer)); |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3825 | return NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3828 | pTokenPair[0] = HeapAlloc(GetProcessHeap(), 0, (pszColon - buffer + 1) * sizeof(WCHAR)); |
| 3829 | if (!pTokenPair[0]) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3830 | { |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3831 | HTTP_FreeTokens(pTokenPair); |
| 3832 | return NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3833 | } |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3834 | memcpy(pTokenPair[0], buffer, (pszColon - buffer) * sizeof(WCHAR)); |
| 3835 | pTokenPair[0][pszColon - buffer] = '\0'; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3836 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3837 | /* skip colon */ |
| 3838 | pszColon++; |
| 3839 | len = strlenW(pszColon); |
| 3840 | pTokenPair[1] = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR)); |
| 3841 | if (!pTokenPair[1]) |
| 3842 | { |
| 3843 | HTTP_FreeTokens(pTokenPair); |
| 3844 | return NULL; |
| 3845 | } |
| 3846 | memcpy(pTokenPair[1], pszColon, (len + 1) * sizeof(WCHAR)); |
| 3847 | |
| 3848 | strip_spaces(pTokenPair[0]); |
| 3849 | strip_spaces(pTokenPair[1]); |
| 3850 | |
| 3851 | TRACE("field(%s) Value(%s)\n", debugstr_w(pTokenPair[0]), debugstr_w(pTokenPair[1])); |
| 3852 | return pTokenPair; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3853 | } |
| 3854 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3855 | /*********************************************************************** |
| 3856 | * HTTP_ProcessHeader (internal) |
| 3857 | * |
| 3858 | * Stuff header into header tables according to <dwModifier> |
| 3859 | * |
| 3860 | */ |
| 3861 | |
Juan Lang | a1ab4a7 | 2007-11-07 14:45:06 -0800 | [diff] [blame] | 3862 | #define COALESCEFLAGS (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3863 | |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 3864 | static BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3865 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3866 | LPHTTPHEADERW lphttpHdr = NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3867 | BOOL bSuccess = FALSE; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3868 | INT index = -1; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3869 | BOOL request_only = dwModifier & HTTP_ADDHDR_FLAG_REQ; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3870 | |
Hans Leidekker | cd2c458 | 2006-10-05 13:18:56 +0200 | [diff] [blame] | 3871 | TRACE("--> %s: %s - 0x%08x\n", debugstr_w(field), debugstr_w(value), dwModifier); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3872 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3873 | /* REPLACE wins out over ADD */ |
| 3874 | if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE) |
| 3875 | dwModifier &= ~HTTP_ADDHDR_FLAG_ADD; |
| 3876 | |
| 3877 | if (dwModifier & HTTP_ADDHDR_FLAG_ADD) |
| 3878 | index = -1; |
| 3879 | else |
| 3880 | index = HTTP_GetCustomHeaderIndex(lpwhr, field, 0, request_only); |
| 3881 | |
| 3882 | if (index >= 0) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3883 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3884 | if (dwModifier & HTTP_ADDHDR_FLAG_ADD_IF_NEW) |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3885 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3886 | return FALSE; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3887 | } |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3888 | lphttpHdr = &lpwhr->pCustHeaders[index]; |
| 3889 | } |
| 3890 | else if (value) |
| 3891 | { |
| 3892 | HTTPHEADERW hdr; |
| 3893 | |
| 3894 | hdr.lpszField = (LPWSTR)field; |
| 3895 | hdr.lpszValue = (LPWSTR)value; |
| 3896 | hdr.wFlags = hdr.wCount = 0; |
| 3897 | |
| 3898 | if (dwModifier & HTTP_ADDHDR_FLAG_REQ) |
| 3899 | hdr.wFlags |= HDR_ISREQUEST; |
| 3900 | |
| 3901 | return HTTP_InsertCustomHeader(lpwhr, &hdr); |
| 3902 | } |
Rob Shearman | 7b002a3 | 2007-01-12 19:16:49 -0600 | [diff] [blame] | 3903 | /* no value to delete */ |
| 3904 | else return TRUE; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3905 | |
| 3906 | if (dwModifier & HTTP_ADDHDR_FLAG_REQ) |
| 3907 | lphttpHdr->wFlags |= HDR_ISREQUEST; |
| 3908 | else |
| 3909 | lphttpHdr->wFlags &= ~HDR_ISREQUEST; |
| 3910 | |
| 3911 | if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE) |
| 3912 | { |
| 3913 | HTTP_DeleteCustomHeader( lpwhr, index ); |
| 3914 | |
| 3915 | if (value) |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3916 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3917 | HTTPHEADERW hdr; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3918 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3919 | hdr.lpszField = (LPWSTR)field; |
| 3920 | hdr.lpszValue = (LPWSTR)value; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3921 | hdr.wFlags = hdr.wCount = 0; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3922 | |
| 3923 | if (dwModifier & HTTP_ADDHDR_FLAG_REQ) |
| 3924 | hdr.wFlags |= HDR_ISREQUEST; |
| 3925 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 3926 | return HTTP_InsertCustomHeader(lpwhr, &hdr); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 3927 | } |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3928 | |
| 3929 | return TRUE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3930 | } |
Juan Lang | a1ab4a7 | 2007-11-07 14:45:06 -0800 | [diff] [blame] | 3931 | else if (dwModifier & COALESCEFLAGS) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3932 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3933 | LPWSTR lpsztmp; |
| 3934 | WCHAR ch = 0; |
| 3935 | INT len = 0; |
| 3936 | INT origlen = strlenW(lphttpHdr->lpszValue); |
| 3937 | INT valuelen = strlenW(value); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3938 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3939 | if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3940 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3941 | ch = ','; |
| 3942 | lphttpHdr->wFlags |= HDR_COMMADELIMITED; |
| 3943 | } |
| 3944 | else if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON) |
| 3945 | { |
| 3946 | ch = ';'; |
| 3947 | lphttpHdr->wFlags |= HDR_COMMADELIMITED; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3950 | len = origlen + valuelen + ((ch > 0) ? 2 : 0); |
| 3951 | |
Juan Lang | 9adf83e | 2007-11-07 14:58:14 -0800 | [diff] [blame] | 3952 | lpsztmp = HeapReAlloc(GetProcessHeap(), 0, lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR)); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3953 | if (lpsztmp) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3954 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3955 | lphttpHdr->lpszValue = lpsztmp; |
| 3956 | /* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */ |
| 3957 | if (ch > 0) |
| 3958 | { |
| 3959 | lphttpHdr->lpszValue[origlen] = ch; |
| 3960 | origlen++; |
| 3961 | lphttpHdr->lpszValue[origlen] = ' '; |
| 3962 | origlen++; |
| 3963 | } |
| 3964 | |
| 3965 | memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR)); |
| 3966 | lphttpHdr->lpszValue[len] = '\0'; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3967 | bSuccess = TRUE; |
| 3968 | } |
| 3969 | else |
| 3970 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 3971 | WARN("HeapReAlloc (%d bytes) failed\n",len+1); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3972 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
| 3973 | } |
| 3974 | } |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 3975 | TRACE("<-- %d\n",bSuccess); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3976 | return bSuccess; |
| 3977 | } |
| 3978 | |
| 3979 | |
| 3980 | /*********************************************************************** |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 3981 | * HTTP_FinishedReading (internal) |
| 3982 | * |
| 3983 | * Called when all content from server has been read by client. |
| 3984 | * |
| 3985 | */ |
| 3986 | BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr) |
| 3987 | { |
Rob Shearman | e74514b | 2008-03-14 18:10:08 +0000 | [diff] [blame] | 3988 | WCHAR szVersion[10]; |
| 3989 | DWORD dwBufferSize = sizeof(szVersion); |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 3990 | |
| 3991 | TRACE("\n"); |
| 3992 | |
Rob Shearman | e74514b | 2008-03-14 18:10:08 +0000 | [diff] [blame] | 3993 | /* as per RFC 2068, S8.1.2.1, if the client is HTTP/1.1 then assume that |
| 3994 | * the connection is keep-alive by default */ |
| 3995 | if (!HTTP_HttpQueryInfoW(lpwhr, HTTP_QUERY_VERSION, szVersion, |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 3996 | &dwBufferSize, NULL) || |
Rob Shearman | e74514b | 2008-03-14 18:10:08 +0000 | [diff] [blame] | 3997 | strcmpiW(szVersion, g_szHttp1_1)) |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 3998 | { |
Rob Shearman | e74514b | 2008-03-14 18:10:08 +0000 | [diff] [blame] | 3999 | WCHAR szConnectionResponse[20]; |
| 4000 | dwBufferSize = sizeof(szConnectionResponse); |
Hans Leidekker | 454fae8 | 2008-03-30 19:16:34 +0100 | [diff] [blame] | 4001 | if ((!HTTP_HttpQueryInfoW(lpwhr, HTTP_QUERY_CONNECTION, szConnectionResponse, &dwBufferSize, NULL) || |
| 4002 | strcmpiW(szConnectionResponse, szKeepAlive)) && |
| 4003 | (!HTTP_HttpQueryInfoW(lpwhr, HTTP_QUERY_PROXY_CONNECTION, szConnectionResponse, &dwBufferSize, NULL) || |
| 4004 | strcmpiW(szConnectionResponse, szKeepAlive))) |
Rob Shearman | e74514b | 2008-03-14 18:10:08 +0000 | [diff] [blame] | 4005 | { |
| 4006 | HTTPREQ_CloseConnection(&lpwhr->hdr); |
| 4007 | } |
Rob Shearman | 272954b | 2007-01-04 18:23:17 +0000 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | /* FIXME: store data in the URL cache here */ |
| 4011 | |
| 4012 | return TRUE; |
| 4013 | } |
| 4014 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4015 | |
| 4016 | /*********************************************************************** |
| 4017 | * HTTP_GetCustomHeaderIndex (internal) |
| 4018 | * |
| 4019 | * Return index of custom header from header array |
| 4020 | * |
| 4021 | */ |
Mike McCormack | 92ddc1c | 2006-03-30 18:20:04 +0900 | [diff] [blame] | 4022 | static INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField, |
| 4023 | int requested_index, BOOL request_only) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4024 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 4025 | DWORD index; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4026 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 4027 | TRACE("%s\n", debugstr_w(lpszField)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4028 | |
| 4029 | for (index = 0; index < lpwhr->nCustHeaders; index++) |
| 4030 | { |
Mike McCormack | 92ddc1c | 2006-03-30 18:20:04 +0900 | [diff] [blame] | 4031 | if (strcmpiW(lpwhr->pCustHeaders[index].lpszField, lpszField)) |
| 4032 | continue; |
| 4033 | |
| 4034 | if (request_only && !(lpwhr->pCustHeaders[index].wFlags & HDR_ISREQUEST)) |
| 4035 | continue; |
| 4036 | |
| 4037 | if (!request_only && (lpwhr->pCustHeaders[index].wFlags & HDR_ISREQUEST)) |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 4038 | continue; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4039 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 4040 | if (requested_index == 0) |
Mike McCormack | 92ddc1c | 2006-03-30 18:20:04 +0900 | [diff] [blame] | 4041 | break; |
| 4042 | requested_index --; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | if (index >= lpwhr->nCustHeaders) |
| 4046 | index = -1; |
| 4047 | |
Hans Leidekker | cd2c458 | 2006-10-05 13:18:56 +0200 | [diff] [blame] | 4048 | TRACE("Return: %d\n", index); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4049 | return index; |
| 4050 | } |
| 4051 | |
| 4052 | |
| 4053 | /*********************************************************************** |
| 4054 | * HTTP_InsertCustomHeader (internal) |
| 4055 | * |
| 4056 | * Insert header into array |
| 4057 | * |
| 4058 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 4059 | static BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4060 | { |
| 4061 | INT count; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 4062 | LPHTTPHEADERW lph = NULL; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 4063 | BOOL r = FALSE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4064 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 4065 | TRACE("--> %s: %s\n", debugstr_w(lpHdr->lpszField), debugstr_w(lpHdr->lpszValue)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4066 | count = lpwhr->nCustHeaders + 1; |
| 4067 | if (count > 1) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 4068 | lph = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpwhr->pCustHeaders, sizeof(HTTPHEADERW) * count); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4069 | else |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 4070 | lph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HTTPHEADERW) * count); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4071 | |
| 4072 | if (NULL != lph) |
| 4073 | { |
| 4074 | lpwhr->pCustHeaders = lph; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 4075 | lpwhr->pCustHeaders[count-1].lpszField = WININET_strdupW(lpHdr->lpszField); |
| 4076 | lpwhr->pCustHeaders[count-1].lpszValue = WININET_strdupW(lpHdr->lpszValue); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4077 | lpwhr->pCustHeaders[count-1].wFlags = lpHdr->wFlags; |
| 4078 | lpwhr->pCustHeaders[count-1].wCount= lpHdr->wCount; |
| 4079 | lpwhr->nCustHeaders++; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 4080 | r = TRUE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4081 | } |
| 4082 | else |
| 4083 | { |
| 4084 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4085 | } |
| 4086 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 4087 | return r; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | |
| 4091 | /*********************************************************************** |
| 4092 | * HTTP_DeleteCustomHeader (internal) |
| 4093 | * |
| 4094 | * Delete header from array |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 4095 | * If this function is called, the indexs may change. |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4096 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 4097 | static BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, DWORD index) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4098 | { |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 4099 | if( lpwhr->nCustHeaders <= 0 ) |
| 4100 | return FALSE; |
Robert Shearman | 7707a76 | 2005-03-10 11:14:24 +0000 | [diff] [blame] | 4101 | if( index >= lpwhr->nCustHeaders ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 4102 | return FALSE; |
| 4103 | lpwhr->nCustHeaders--; |
| 4104 | |
| 4105 | memmove( &lpwhr->pCustHeaders[index], &lpwhr->pCustHeaders[index+1], |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 4106 | (lpwhr->nCustHeaders - index)* sizeof(HTTPHEADERW) ); |
| 4107 | memset( &lpwhr->pCustHeaders[lpwhr->nCustHeaders], 0, sizeof(HTTPHEADERW) ); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 4108 | |
| 4109 | return TRUE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 4110 | } |
Alberto Massari | b09eef2 | 2002-11-13 04:08:26 +0000 | [diff] [blame] | 4111 | |
Aric Stewart | c8dfc02 | 2007-07-26 08:59:00 -0500 | [diff] [blame] | 4112 | |
| 4113 | /*********************************************************************** |
| 4114 | * HTTP_VerifyValidHeader (internal) |
| 4115 | * |
| 4116 | * Verify the given header is not invalid for the given http request |
| 4117 | * |
| 4118 | */ |
| 4119 | static BOOL HTTP_VerifyValidHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field) |
| 4120 | { |
Aric Stewart | c8dfc02 | 2007-07-26 08:59:00 -0500 | [diff] [blame] | 4121 | /* Accept-Encoding is stripped from HTTP/1.0 requests. It is invalid */ |
Hans Leidekker | 3a57711 | 2008-03-24 21:31:53 +0100 | [diff] [blame] | 4122 | if (!strcmpW(lpwhr->lpszVersion, g_szHttp1_0) && !strcmpiW(field, szAccept_Encoding)) |
Aric Stewart | c8dfc02 | 2007-07-26 08:59:00 -0500 | [diff] [blame] | 4123 | return FALSE; |
| 4124 | |
Hans Leidekker | 3a57711 | 2008-03-24 21:31:53 +0100 | [diff] [blame] | 4125 | return TRUE; |
Aric Stewart | c8dfc02 | 2007-07-26 08:59:00 -0500 | [diff] [blame] | 4126 | } |
| 4127 | |
Alberto Massari | b09eef2 | 2002-11-13 04:08:26 +0000 | [diff] [blame] | 4128 | /*********************************************************************** |
| 4129 | * IsHostInProxyBypassList (@) |
| 4130 | * |
| 4131 | * Undocumented |
| 4132 | * |
| 4133 | */ |
| 4134 | BOOL WINAPI IsHostInProxyBypassList(DWORD flags, LPCSTR szHost, DWORD length) |
| 4135 | { |
Hans Leidekker | cd2c458 | 2006-10-05 13:18:56 +0200 | [diff] [blame] | 4136 | FIXME("STUB: flags=%d host=%s length=%d\n",flags,szHost,length); |
Alberto Massari | b09eef2 | 2002-11-13 04:08:26 +0000 | [diff] [blame] | 4137 | return FALSE; |
| 4138 | } |