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 |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 9 | * |
| 10 | * Ulrich Czekalla |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 11 | * David Hammerton |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 12 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 13 | * This library is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU Lesser General Public |
| 15 | * License as published by the Free Software Foundation; either |
| 16 | * version 2.1 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This library is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | * Lesser General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU Lesser General Public |
| 24 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
Patrik Stridvall | 4710be2 | 2000-06-23 15:47:14 +0000 | [diff] [blame] | 28 | #include "config.h" |
Alexandre Julliard | 754e7aa | 2004-09-03 18:30:28 +0000 | [diff] [blame] | 29 | #include "wine/port.h" |
Patrik Stridvall | 4710be2 | 2000-06-23 15:47:14 +0000 | [diff] [blame] | 30 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 31 | #include <sys/types.h> |
Patrik Stridvall | 4710be2 | 2000-06-23 15:47:14 +0000 | [diff] [blame] | 32 | #ifdef HAVE_SYS_SOCKET_H |
| 33 | # include <sys/socket.h> |
| 34 | #endif |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 35 | #ifdef HAVE_ARPA_INET_H |
| 36 | # include <arpa/inet.h> |
| 37 | #endif |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 38 | #include <stdarg.h> |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 39 | #include <stdio.h> |
| 40 | #include <stdlib.h> |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 41 | #ifdef HAVE_UNISTD_H |
| 42 | # include <unistd.h> |
| 43 | #endif |
Chris Morgan | b9807b4 | 2001-02-15 21:24:07 +0000 | [diff] [blame] | 44 | #include <time.h> |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 45 | #include <assert.h> |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 46 | |
Guy Albertelli | aafec98 | 2001-11-06 22:31:19 +0000 | [diff] [blame] | 47 | #include "windef.h" |
| 48 | #include "winbase.h" |
| 49 | #include "wininet.h" |
| 50 | #include "winreg.h" |
| 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" |
| 57 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 58 | #include "internet.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 59 | #include "wine/debug.h" |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 60 | #include "wine/unicode.h" |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 61 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 62 | WINE_DEFAULT_DEBUG_CHANNEL(wininet); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 63 | |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 64 | static const WCHAR g_szHttp1_0[] = {' ','H','T','T','P','/','1','.','0',0 }; |
| 65 | 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] | 66 | static const WCHAR g_szReferer[] = {'R','e','f','e','r','e','r',0}; |
| 67 | static const WCHAR g_szAccept[] = {'A','c','c','e','p','t',0}; |
| 68 | 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] | 69 | static const WCHAR szHost[] = { 'H','o','s','t',0 }; |
| 70 | static const WCHAR szProxy_Authorization[] = { 'P','r','o','x','y','-','A','u','t','h','o','r','i','z','a','t','i','o','n',0 }; |
| 71 | static const WCHAR szStatus[] = { 'S','t','a','t','u','s',0 }; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 72 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 73 | #define MAXHOSTNAME 100 |
| 74 | #define MAX_FIELD_VALUE_LEN 256 |
| 75 | #define MAX_FIELD_LEN 256 |
| 76 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 77 | #define HTTP_REFERER g_szReferer |
| 78 | #define HTTP_ACCEPT g_szAccept |
| 79 | #define HTTP_USERAGENT g_szUserAgent |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 80 | |
| 81 | #define HTTP_ADDHDR_FLAG_ADD 0x20000000 |
| 82 | #define HTTP_ADDHDR_FLAG_ADD_IF_NEW 0x10000000 |
| 83 | #define HTTP_ADDHDR_FLAG_COALESCE 0x40000000 |
| 84 | #define HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA 0x40000000 |
| 85 | #define HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON 0x01000000 |
| 86 | #define HTTP_ADDHDR_FLAG_REPLACE 0x80000000 |
| 87 | #define HTTP_ADDHDR_FLAG_REQ 0x02000000 |
| 88 | |
| 89 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 90 | static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr); |
| 91 | static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr); |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 92 | static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr); |
| 93 | static BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr); |
| 94 | static BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier); |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 95 | static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer); |
| 96 | static BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 97 | static INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField, INT index, BOOL Request); |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 98 | static BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, DWORD index); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 99 | static LPWSTR HTTP_build_req( LPCWSTR *list, int len ); |
| 100 | static BOOL HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr, |
| 101 | LPCWSTR username, LPCWSTR password ); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 102 | static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD |
| 103 | dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD |
| 104 | lpdwIndex); |
| 105 | static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl, |
| 106 | LPCWSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 107 | dwOptionalLength, DWORD dwContentLength); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 108 | |
| 109 | |
| 110 | LPHTTPHEADERW HTTP_GetHeader(LPWININETHTTPREQW req, LPCWSTR head) |
| 111 | { |
| 112 | int HeaderIndex = 0; |
| 113 | HeaderIndex = HTTP_GetCustomHeaderIndex(req, head, 0, TRUE); |
| 114 | if (HeaderIndex == -1) |
| 115 | return NULL; |
| 116 | else |
| 117 | return &req->pCustHeaders[HeaderIndex]; |
| 118 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 119 | |
| 120 | /*********************************************************************** |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 121 | * HTTP_Tokenize (internal) |
| 122 | * |
| 123 | * Tokenize a string, allocating memory for the tokens. |
| 124 | */ |
| 125 | static LPWSTR * HTTP_Tokenize(LPCWSTR string, LPCWSTR token_string) |
| 126 | { |
| 127 | LPWSTR * token_array; |
| 128 | int tokens = 0; |
| 129 | int i; |
| 130 | LPCWSTR next_token; |
| 131 | |
| 132 | /* empty string has no tokens */ |
| 133 | if (*string) |
| 134 | tokens++; |
| 135 | /* count tokens */ |
| 136 | for (i = 0; string[i]; i++) |
| 137 | if (!strncmpW(string+i, token_string, strlenW(token_string))) |
| 138 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 139 | DWORD j; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 140 | tokens++; |
| 141 | /* we want to skip over separators, but not the null terminator */ |
| 142 | for (j = 0; j < strlenW(token_string) - 1; j++) |
| 143 | if (!string[i+j]) |
| 144 | break; |
| 145 | i += j; |
| 146 | } |
| 147 | |
| 148 | /* add 1 for terminating NULL */ |
| 149 | token_array = HeapAlloc(GetProcessHeap(), 0, (tokens+1) * sizeof(*token_array)); |
| 150 | token_array[tokens] = NULL; |
| 151 | if (!tokens) |
| 152 | return token_array; |
| 153 | for (i = 0; i < tokens; i++) |
| 154 | { |
| 155 | int len; |
| 156 | next_token = strstrW(string, token_string); |
| 157 | if (!next_token) next_token = string+strlenW(string); |
| 158 | len = next_token - string; |
| 159 | token_array[i] = HeapAlloc(GetProcessHeap(), 0, (len+1)*sizeof(WCHAR)); |
| 160 | memcpy(token_array[i], string, len*sizeof(WCHAR)); |
| 161 | token_array[i][len] = '\0'; |
| 162 | string = next_token+strlenW(token_string); |
| 163 | } |
| 164 | return token_array; |
| 165 | } |
| 166 | |
| 167 | /*********************************************************************** |
| 168 | * HTTP_FreeTokens (internal) |
| 169 | * |
| 170 | * Frees memory returned from HTTP_Tokenize. |
| 171 | */ |
| 172 | static void HTTP_FreeTokens(LPWSTR * token_array) |
| 173 | { |
| 174 | int i; |
| 175 | for (i = 0; token_array[i]; i++) |
| 176 | HeapFree(GetProcessHeap(), 0, token_array[i]); |
| 177 | HeapFree(GetProcessHeap(), 0, token_array); |
| 178 | } |
| 179 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 180 | /* ********************************************************************** |
| 181 | * |
| 182 | * Helper functions for the HttpSendRequest(Ex) functions |
| 183 | * |
| 184 | */ |
| 185 | static void HTTP_FixVerb( LPWININETHTTPREQW lpwhr ) |
| 186 | { |
| 187 | /* if the verb is NULL default to GET */ |
| 188 | if (NULL == lpwhr->lpszVerb) |
| 189 | { |
| 190 | static const WCHAR szGET[] = { 'G','E','T', 0 }; |
| 191 | lpwhr->lpszVerb = WININET_strdupW(szGET); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | static void HTTP_FixURL( LPWININETHTTPREQW lpwhr) |
| 196 | { |
| 197 | static const WCHAR szSlash[] = { '/',0 }; |
| 198 | static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/', 0 }; |
| 199 | |
| 200 | /* If we don't have a path we set it to root */ |
| 201 | if (NULL == lpwhr->lpszPath) |
| 202 | lpwhr->lpszPath = WININET_strdupW(szSlash); |
| 203 | else /* remove \r and \n*/ |
| 204 | { |
| 205 | int nLen = strlenW(lpwhr->lpszPath); |
| 206 | while ((nLen >0 ) && ((lpwhr->lpszPath[nLen-1] == '\r')||(lpwhr->lpszPath[nLen-1] == '\n'))) |
| 207 | { |
| 208 | nLen--; |
| 209 | lpwhr->lpszPath[nLen]='\0'; |
| 210 | } |
| 211 | /* Replace '\' with '/' */ |
| 212 | while (nLen>0) { |
| 213 | nLen--; |
| 214 | if (lpwhr->lpszPath[nLen] == '\\') lpwhr->lpszPath[nLen]='/'; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if(CSTR_EQUAL != CompareStringW( LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, |
| 219 | lpwhr->lpszPath, strlenW(szHttp), szHttp, strlenW(szHttp) ) |
| 220 | && lpwhr->lpszPath[0] != '/') /* not an absolute path ?? --> fix it !! */ |
| 221 | { |
| 222 | WCHAR *fixurl = HeapAlloc(GetProcessHeap(), 0, |
| 223 | (strlenW(lpwhr->lpszPath) + 2)*sizeof(WCHAR)); |
| 224 | *fixurl = '/'; |
| 225 | strcpyW(fixurl + 1, lpwhr->lpszPath); |
| 226 | HeapFree( GetProcessHeap(), 0, lpwhr->lpszPath ); |
| 227 | lpwhr->lpszPath = fixurl; |
| 228 | } |
| 229 | } |
| 230 | |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 231 | static LPWSTR HTTP_BuildHeaderRequestString( LPWININETHTTPREQW lpwhr, LPCWSTR verb, LPCWSTR path, BOOL http1_1 ) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 232 | { |
| 233 | LPWSTR requestString; |
| 234 | DWORD len, n; |
| 235 | LPCWSTR *req; |
| 236 | INT i; |
| 237 | LPWSTR p; |
| 238 | |
| 239 | static const WCHAR szSpace[] = { ' ',0 }; |
| 240 | static const WCHAR szcrlf[] = {'\r','\n', 0}; |
| 241 | static const WCHAR szColon[] = { ':',' ',0 }; |
| 242 | static const WCHAR sztwocrlf[] = {'\r','\n','\r','\n', 0}; |
| 243 | |
| 244 | /* allocate space for an array of all the string pointers to be added */ |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 245 | len = (lpwhr->nCustHeaders)*4 + 9; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 246 | req = HeapAlloc( GetProcessHeap(), 0, len*sizeof(LPCWSTR) ); |
| 247 | |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 248 | /* add the verb, path and HTTP version string */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 249 | n = 0; |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 250 | req[n++] = verb; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 251 | req[n++] = szSpace; |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 252 | req[n++] = path; |
| 253 | req[n++] = http1_1 ? g_szHttp1_1 : g_szHttp1_0; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 254 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 255 | /* Append custom request heades */ |
| 256 | for (i = 0; i < lpwhr->nCustHeaders; i++) |
| 257 | { |
| 258 | if (lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST) |
| 259 | { |
| 260 | req[n++] = szcrlf; |
| 261 | req[n++] = lpwhr->pCustHeaders[i].lpszField; |
| 262 | req[n++] = szColon; |
| 263 | req[n++] = lpwhr->pCustHeaders[i].lpszValue; |
| 264 | |
| 265 | TRACE("Adding custom header %s (%s)\n", |
| 266 | debugstr_w(lpwhr->pCustHeaders[i].lpszField), |
| 267 | debugstr_w(lpwhr->pCustHeaders[i].lpszValue)); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if( n >= len ) |
| 272 | ERR("oops. buffer overrun\n"); |
| 273 | |
| 274 | req[n] = NULL; |
| 275 | requestString = HTTP_build_req( req, 4 ); |
| 276 | HeapFree( GetProcessHeap(), 0, req ); |
| 277 | |
| 278 | /* |
| 279 | * Set (header) termination string for request |
| 280 | * Make sure there's exactly two new lines at the end of the request |
| 281 | */ |
| 282 | p = &requestString[strlenW(requestString)-1]; |
| 283 | while ( (*p == '\n') || (*p == '\r') ) |
| 284 | p--; |
| 285 | strcpyW( p+1, sztwocrlf ); |
| 286 | |
| 287 | return requestString; |
| 288 | } |
| 289 | |
| 290 | static void HTTP_ProcessHeaders( LPWININETHTTPREQW lpwhr ) |
| 291 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 292 | static const WCHAR szSet_Cookie[] = { 'S','e','t','-','C','o','o','k','i','e',0 }; |
| 293 | int HeaderIndex; |
| 294 | LPHTTPHEADERW setCookieHeader; |
| 295 | |
| 296 | HeaderIndex = HTTP_GetCustomHeaderIndex(lpwhr, szSet_Cookie, 0, FALSE); |
| 297 | if (HeaderIndex == -1) |
| 298 | return; |
| 299 | setCookieHeader = &lpwhr->pCustHeaders[HeaderIndex]; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 300 | |
Robert Shearman | 225a9fa | 2005-11-28 11:24:41 +0100 | [diff] [blame] | 301 | if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) && setCookieHeader->lpszValue) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 302 | { |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 303 | int nPosStart = 0, nPosEnd = 0, len; |
| 304 | static const WCHAR szFmt[] = { 'h','t','t','p',':','/','/','%','s','/',0}; |
| 305 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 306 | while (setCookieHeader->lpszValue[nPosEnd] != '\0') |
| 307 | { |
| 308 | LPWSTR buf_cookie, cookie_name, cookie_data; |
| 309 | LPWSTR buf_url; |
| 310 | LPWSTR domain = NULL; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 311 | LPHTTPHEADERW Host; |
| 312 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 313 | int nEqualPos = 0; |
| 314 | while (setCookieHeader->lpszValue[nPosEnd] != ';' && setCookieHeader->lpszValue[nPosEnd] != ',' && |
| 315 | setCookieHeader->lpszValue[nPosEnd] != '\0') |
| 316 | { |
| 317 | nPosEnd++; |
| 318 | } |
| 319 | if (setCookieHeader->lpszValue[nPosEnd] == ';') |
| 320 | { |
| 321 | /* fixme: not case sensitive, strcasestr is gnu only */ |
| 322 | int nDomainPosEnd = 0; |
| 323 | int nDomainPosStart = 0, nDomainLength = 0; |
| 324 | static const WCHAR szDomain[] = {'d','o','m','a','i','n','=',0}; |
| 325 | LPWSTR lpszDomain = strstrW(&setCookieHeader->lpszValue[nPosEnd], szDomain); |
| 326 | if (lpszDomain) |
| 327 | { /* they have specified their own domain, lets use it */ |
| 328 | while (lpszDomain[nDomainPosEnd] != ';' && lpszDomain[nDomainPosEnd] != ',' && |
| 329 | lpszDomain[nDomainPosEnd] != '\0') |
| 330 | { |
| 331 | nDomainPosEnd++; |
| 332 | } |
| 333 | nDomainPosStart = strlenW(szDomain); |
| 334 | nDomainLength = (nDomainPosEnd - nDomainPosStart) + 1; |
| 335 | domain = HeapAlloc(GetProcessHeap(), 0, (nDomainLength + 1)*sizeof(WCHAR)); |
| 336 | lstrcpynW(domain, &lpszDomain[nDomainPosStart], nDomainLength + 1); |
| 337 | } |
| 338 | } |
| 339 | if (setCookieHeader->lpszValue[nPosEnd] == '\0') break; |
| 340 | buf_cookie = HeapAlloc(GetProcessHeap(), 0, ((nPosEnd - nPosStart) + 1)*sizeof(WCHAR)); |
| 341 | lstrcpynW(buf_cookie, &setCookieHeader->lpszValue[nPosStart], (nPosEnd - nPosStart) + 1); |
| 342 | TRACE("%s\n", debugstr_w(buf_cookie)); |
| 343 | while (buf_cookie[nEqualPos] != '=' && buf_cookie[nEqualPos] != '\0') |
| 344 | { |
| 345 | nEqualPos++; |
| 346 | } |
| 347 | if (buf_cookie[nEqualPos] == '\0' || buf_cookie[nEqualPos + 1] == '\0') |
| 348 | { |
| 349 | HeapFree(GetProcessHeap(), 0, buf_cookie); |
| 350 | break; |
| 351 | } |
| 352 | |
| 353 | cookie_name = HeapAlloc(GetProcessHeap(), 0, (nEqualPos + 1)*sizeof(WCHAR)); |
| 354 | lstrcpynW(cookie_name, buf_cookie, nEqualPos + 1); |
| 355 | cookie_data = &buf_cookie[nEqualPos + 1]; |
| 356 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 357 | Host = HTTP_GetHeader(lpwhr,szHost); |
| 358 | len = lstrlenW((domain ? domain : (Host?Host->lpszValue:NULL))) + |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 359 | strlenW(lpwhr->lpszPath) + 9; |
| 360 | buf_url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 361 | sprintfW(buf_url, szFmt, (domain ? domain : (Host?Host->lpszValue:NULL))); /* FIXME PATH!!! */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 362 | InternetSetCookieW(buf_url, cookie_name, cookie_data); |
| 363 | |
| 364 | HeapFree(GetProcessHeap(), 0, buf_url); |
| 365 | HeapFree(GetProcessHeap(), 0, buf_cookie); |
| 366 | HeapFree(GetProcessHeap(), 0, cookie_name); |
| 367 | HeapFree(GetProcessHeap(), 0, domain); |
| 368 | nPosStart = nPosEnd; |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | static void HTTP_AddProxyInfo( LPWININETHTTPREQW lpwhr ) |
| 374 | { |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 375 | LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW)lpwhr->hdr.lpwhparent; |
| 376 | LPWININETAPPINFOW hIC = (LPWININETAPPINFOW)lpwhs->hdr.lpwhparent; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 377 | |
Robert Shearman | 0adec2b | 2005-11-28 11:28:06 +0100 | [diff] [blame] | 378 | assert(lpwhs->hdr.htype == WH_HHTTPSESSION); |
Robert Shearman | 0adec2b | 2005-11-28 11:28:06 +0100 | [diff] [blame] | 379 | assert(hIC->hdr.htype == WH_HINIT); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 380 | |
| 381 | if (hIC && (hIC->lpszProxyUsername || hIC->lpszProxyPassword )) |
| 382 | HTTP_InsertProxyAuthorization(lpwhr, hIC->lpszProxyUsername, |
| 383 | hIC->lpszProxyPassword); |
| 384 | } |
| 385 | |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 386 | /*********************************************************************** |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 387 | * HTTP_HttpAddRequestHeadersW (internal) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 388 | */ |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 389 | static BOOL WINAPI HTTP_HttpAddRequestHeadersW(LPWININETHTTPREQW lpwhr, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 390 | LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 391 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 392 | LPWSTR lpszStart; |
| 393 | LPWSTR lpszEnd; |
| 394 | LPWSTR buffer; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 395 | BOOL bSuccess = FALSE; |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 396 | DWORD len; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 397 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 398 | TRACE("copying header: %s\n", debugstr_w(lpszHeader)); |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 399 | |
Alexandre Julliard | 7c1925a0 | 2005-09-13 15:00:32 +0000 | [diff] [blame] | 400 | if( dwHeaderLength == ~0U ) |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 401 | len = strlenW(lpszHeader); |
| 402 | else |
| 403 | len = dwHeaderLength; |
| 404 | buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*(len+1) ); |
Peter Berg Larsen | e732fc0 | 2005-03-28 14:17:51 +0000 | [diff] [blame] | 405 | lstrcpynW( buffer, lpszHeader, len + 1); |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 406 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 407 | lpszStart = buffer; |
| 408 | |
| 409 | do |
| 410 | { |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 411 | LPWSTR * pFieldAndValue; |
| 412 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 413 | lpszEnd = lpszStart; |
| 414 | |
| 415 | while (*lpszEnd != '\0') |
| 416 | { |
| 417 | if (*lpszEnd == '\r' && *(lpszEnd + 1) == '\n') |
| 418 | break; |
| 419 | lpszEnd++; |
| 420 | } |
| 421 | |
Robert Shearman | 4cd38b4 | 2004-07-13 23:34:28 +0000 | [diff] [blame] | 422 | if (*lpszStart == '\0') |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 423 | break; |
| 424 | |
Robert Shearman | 4cd38b4 | 2004-07-13 23:34:28 +0000 | [diff] [blame] | 425 | if (*lpszEnd == '\r') |
| 426 | { |
| 427 | *lpszEnd = '\0'; |
| 428 | lpszEnd += 2; /* Jump over \r\n */ |
| 429 | } |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 430 | TRACE("interpreting header %s\n", debugstr_w(lpszStart)); |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 431 | pFieldAndValue = HTTP_InterpretHttpHeader(lpszStart); |
| 432 | if (pFieldAndValue) |
| 433 | { |
| 434 | bSuccess = HTTP_ProcessHeader(lpwhr, pFieldAndValue[0], |
| 435 | pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ); |
| 436 | HTTP_FreeTokens(pFieldAndValue); |
| 437 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 438 | |
Robert Shearman | 4cd38b4 | 2004-07-13 23:34:28 +0000 | [diff] [blame] | 439 | lpszStart = lpszEnd; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 440 | } while (bSuccess); |
| 441 | |
| 442 | HeapFree(GetProcessHeap(), 0, buffer); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 443 | |
| 444 | return bSuccess; |
| 445 | } |
| 446 | |
| 447 | /*********************************************************************** |
| 448 | * HttpAddRequestHeadersW (WININET.@) |
| 449 | * |
| 450 | * Adds one or more HTTP header to the request handler |
| 451 | * |
| 452 | * RETURNS |
| 453 | * TRUE on success |
| 454 | * FALSE on failure |
| 455 | * |
| 456 | */ |
| 457 | BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest, |
| 458 | LPCWSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) |
| 459 | { |
| 460 | BOOL bSuccess = FALSE; |
| 461 | LPWININETHTTPREQW lpwhr; |
| 462 | |
| 463 | TRACE("%p, %s, %li, %li\n", hHttpRequest, debugstr_w(lpszHeader), dwHeaderLength, |
| 464 | dwModifier); |
| 465 | |
| 466 | if (!lpszHeader) |
| 467 | return TRUE; |
| 468 | |
| 469 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest ); |
| 470 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 471 | { |
| 472 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 473 | goto lend; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 474 | } |
| 475 | bSuccess = HTTP_HttpAddRequestHeadersW( lpwhr, lpszHeader, dwHeaderLength, dwModifier ); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 476 | lend: |
| 477 | if( lpwhr ) |
| 478 | WININET_Release( &lpwhr->hdr ); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 479 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 480 | return bSuccess; |
| 481 | } |
| 482 | |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 483 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 484 | * HttpAddRequestHeadersA (WININET.@) |
| 485 | * |
| 486 | * Adds one or more HTTP header to the request handler |
| 487 | * |
| 488 | * RETURNS |
| 489 | * TRUE on success |
| 490 | * FALSE on failure |
| 491 | * |
| 492 | */ |
| 493 | BOOL WINAPI HttpAddRequestHeadersA(HINTERNET hHttpRequest, |
| 494 | LPCSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) |
| 495 | { |
| 496 | DWORD len; |
| 497 | LPWSTR hdr; |
| 498 | BOOL r; |
| 499 | |
| 500 | TRACE("%p, %s, %li, %li\n", hHttpRequest, debugstr_a(lpszHeader), dwHeaderLength, |
| 501 | dwModifier); |
| 502 | |
| 503 | len = MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, NULL, 0 ); |
| 504 | hdr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); |
| 505 | MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, hdr, len ); |
Alexandre Julliard | 7c1925a0 | 2005-09-13 15:00:32 +0000 | [diff] [blame] | 506 | if( dwHeaderLength != ~0U ) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 507 | dwHeaderLength = len; |
| 508 | |
| 509 | r = HttpAddRequestHeadersW( hHttpRequest, hdr, dwHeaderLength, dwModifier ); |
| 510 | |
| 511 | HeapFree( GetProcessHeap(), 0, hdr ); |
| 512 | |
| 513 | return r; |
| 514 | } |
| 515 | |
| 516 | /*********************************************************************** |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 517 | * HttpEndRequestA (WININET.@) |
| 518 | * |
| 519 | * Ends an HTTP request that was started by HttpSendRequestEx |
| 520 | * |
| 521 | * RETURNS |
| 522 | * TRUE if successful |
| 523 | * FALSE on failure |
| 524 | * |
| 525 | */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 526 | BOOL WINAPI HttpEndRequestA(HINTERNET hRequest, |
| 527 | LPINTERNET_BUFFERSA lpBuffersOut, DWORD dwFlags, DWORD dwContext) |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 528 | { |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 529 | LPINTERNET_BUFFERSA ptr; |
| 530 | LPINTERNET_BUFFERSW lpBuffersOutW,ptrW; |
| 531 | BOOL rc = FALSE; |
| 532 | |
| 533 | TRACE("(%p, %p, %08lx, %08lx): stub\n", hRequest, lpBuffersOut, dwFlags, |
| 534 | dwContext); |
| 535 | |
| 536 | ptr = lpBuffersOut; |
| 537 | if (ptr) |
| 538 | lpBuffersOutW = (LPINTERNET_BUFFERSW)HeapAlloc(GetProcessHeap(), |
| 539 | HEAP_ZERO_MEMORY, sizeof(INTERNET_BUFFERSW)); |
| 540 | else |
| 541 | lpBuffersOutW = NULL; |
| 542 | |
| 543 | ptrW = lpBuffersOutW; |
| 544 | while (ptr) |
| 545 | { |
| 546 | if (ptr->lpvBuffer && ptr->dwBufferLength) |
| 547 | ptrW->lpvBuffer = HeapAlloc(GetProcessHeap(),0,ptr->dwBufferLength); |
| 548 | ptrW->dwBufferLength = ptr->dwBufferLength; |
| 549 | ptrW->dwBufferTotal= ptr->dwBufferTotal; |
| 550 | |
| 551 | if (ptr->Next) |
| 552 | ptrW->Next = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, |
| 553 | sizeof(INTERNET_BUFFERSW)); |
| 554 | |
| 555 | ptr = ptr->Next; |
| 556 | ptrW = ptrW->Next; |
| 557 | } |
| 558 | |
| 559 | rc = HttpEndRequestW(hRequest, lpBuffersOutW, dwFlags, dwContext); |
| 560 | |
| 561 | if (lpBuffersOutW) |
| 562 | { |
| 563 | ptrW = lpBuffersOutW; |
| 564 | while (ptrW) |
| 565 | { |
| 566 | LPINTERNET_BUFFERSW ptrW2; |
| 567 | |
| 568 | FIXME("Do we need to translate info out of these buffer?\n"); |
| 569 | |
| 570 | HeapFree(GetProcessHeap(),0,(LPVOID)ptrW->lpvBuffer); |
| 571 | ptrW2 = ptrW->Next; |
| 572 | HeapFree(GetProcessHeap(),0,ptrW); |
| 573 | ptrW = ptrW2; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | return rc; |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /*********************************************************************** |
| 581 | * HttpEndRequestW (WININET.@) |
| 582 | * |
| 583 | * Ends an HTTP request that was started by HttpSendRequestEx |
| 584 | * |
| 585 | * RETURNS |
| 586 | * TRUE if successful |
| 587 | * FALSE on failure |
| 588 | * |
| 589 | */ |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 590 | BOOL WINAPI HttpEndRequestW(HINTERNET hRequest, |
| 591 | LPINTERNET_BUFFERSW lpBuffersOut, DWORD dwFlags, DWORD dwContext) |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 592 | { |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 593 | BOOL rc = FALSE; |
| 594 | LPWININETHTTPREQW lpwhr; |
| 595 | INT responseLen; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 596 | |
| 597 | TRACE("-->\n"); |
| 598 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hRequest ); |
| 599 | |
| 600 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 601 | { |
| 602 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
| 603 | return FALSE; |
| 604 | } |
| 605 | |
| 606 | lpwhr->hdr.dwFlags |= dwFlags; |
| 607 | lpwhr->hdr.dwContext = dwContext; |
| 608 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 609 | SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 610 | INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0); |
| 611 | |
| 612 | responseLen = HTTP_GetResponseHeaders(lpwhr); |
| 613 | if (responseLen) |
| 614 | rc = TRUE; |
| 615 | |
| 616 | SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 617 | INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen, sizeof(DWORD)); |
| 618 | |
| 619 | /* process headers here. Is this right? */ |
| 620 | HTTP_ProcessHeaders(lpwhr); |
| 621 | |
| 622 | /* We appear to do nothing with the buffer.. is that correct? */ |
| 623 | |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 624 | if(!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT)) |
| 625 | { |
| 626 | DWORD dwCode,dwCodeLength=sizeof(DWORD),dwIndex=0; |
| 627 | if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,&dwCode,&dwCodeLength,&dwIndex) && |
| 628 | (dwCode==302 || dwCode==301)) |
| 629 | { |
| 630 | WCHAR szNewLocation[2048]; |
| 631 | DWORD dwBufferSize=2048; |
| 632 | dwIndex=0; |
| 633 | if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,&dwIndex)) |
| 634 | { |
| 635 | static const WCHAR szGET[] = { 'G','E','T', 0 }; |
| 636 | /* redirects are always GETs */ |
| 637 | HeapFree(GetProcessHeap(),0,lpwhr->lpszVerb); |
| 638 | lpwhr->lpszVerb = WININET_strdupW(szGET); |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 639 | return HTTP_HandleRedirect(lpwhr, szNewLocation, NULL, 0, NULL, 0, 0); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | } |
| 643 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 644 | TRACE("%i <--\n",rc); |
| 645 | return rc; |
Chris Morgan | a8b3216 | 2002-09-27 22:05:23 +0000 | [diff] [blame] | 646 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 647 | |
| 648 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 649 | * HttpOpenRequestW (WININET.@) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 650 | * |
| 651 | * Open a HTTP request handle |
| 652 | * |
| 653 | * RETURNS |
| 654 | * HINTERNET a HTTP request handle on success |
| 655 | * NULL on failure |
| 656 | * |
| 657 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 658 | HINTERNET WINAPI HttpOpenRequestW(HINTERNET hHttpSession, |
| 659 | LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, |
| 660 | LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes, |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 661 | DWORD dwFlags, DWORD dwContext) |
| 662 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 663 | LPWININETHTTPSESSIONW lpwhs; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 664 | HINTERNET handle = NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 665 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 666 | TRACE("(%p, %s, %s, %s, %s, %p, %08lx, %08lx)\n", hHttpSession, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 667 | debugstr_w(lpszVerb), debugstr_w(lpszObjectName), |
| 668 | debugstr_w(lpszVersion), debugstr_w(lpszReferrer), lpszAcceptTypes, |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 669 | dwFlags, dwContext); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 670 | if(lpszAcceptTypes!=NULL) |
| 671 | { |
| 672 | int i; |
| 673 | for(i=0;lpszAcceptTypes[i]!=NULL;i++) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 674 | TRACE("\taccept type: %s\n",debugstr_w(lpszAcceptTypes[i])); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 675 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 676 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 677 | lpwhs = (LPWININETHTTPSESSIONW) WININET_GetObject( hHttpSession ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 678 | if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION) |
| 679 | { |
| 680 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 681 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 682 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 683 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 684 | /* |
| 685 | * My tests seem to show that the windows version does not |
| 686 | * become asynchronous until after this point. And anyhow |
| 687 | * if this call was asynchronous then how would you get the |
| 688 | * necessary HINTERNET pointer returned by this function. |
| 689 | * |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 690 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 691 | handle = HTTP_HttpOpenRequestW(lpwhs, lpszVerb, lpszObjectName, |
| 692 | lpszVersion, lpszReferrer, lpszAcceptTypes, |
| 693 | dwFlags, dwContext); |
| 694 | lend: |
| 695 | if( lpwhs ) |
| 696 | WININET_Release( &lpwhs->hdr ); |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 697 | TRACE("returning %p\n", handle); |
| 698 | return handle; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 699 | } |
| 700 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 701 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 702 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 703 | * HttpOpenRequestA (WININET.@) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 704 | * |
| 705 | * Open a HTTP request handle |
| 706 | * |
| 707 | * RETURNS |
| 708 | * HINTERNET a HTTP request handle on success |
| 709 | * NULL on failure |
| 710 | * |
| 711 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 712 | HINTERNET WINAPI HttpOpenRequestA(HINTERNET hHttpSession, |
| 713 | LPCSTR lpszVerb, LPCSTR lpszObjectName, LPCSTR lpszVersion, |
| 714 | LPCSTR lpszReferrer , LPCSTR *lpszAcceptTypes, |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 715 | DWORD dwFlags, DWORD dwContext) |
| 716 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 717 | LPWSTR szVerb = NULL, szObjectName = NULL; |
| 718 | LPWSTR szVersion = NULL, szReferrer = NULL, *szAcceptTypes = NULL; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 719 | INT len; |
| 720 | INT acceptTypesCount; |
| 721 | HINTERNET rc = FALSE; |
| 722 | TRACE("(%p, %s, %s, %s, %s, %p, %08lx, %08lx)\n", hHttpSession, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 723 | debugstr_a(lpszVerb), debugstr_a(lpszObjectName), |
| 724 | debugstr_a(lpszVersion), debugstr_a(lpszReferrer), lpszAcceptTypes, |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 725 | dwFlags, dwContext); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 726 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 727 | if (lpszVerb) |
| 728 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 729 | len = MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, NULL, 0 ); |
| 730 | szVerb = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) ); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 731 | if ( !szVerb ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 732 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 733 | MultiByteToWideChar(CP_ACP, 0, lpszVerb, -1, szVerb, len); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | if (lpszObjectName) |
| 737 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 738 | len = MultiByteToWideChar(CP_ACP, 0, lpszObjectName, -1, NULL, 0 ); |
| 739 | szObjectName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR) ); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 740 | if ( !szObjectName ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 741 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 742 | MultiByteToWideChar(CP_ACP, 0, lpszObjectName, -1, szObjectName, len ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | if (lpszVersion) |
| 746 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 747 | len = MultiByteToWideChar(CP_ACP, 0, lpszVersion, -1, NULL, 0 ); |
| 748 | szVersion = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 749 | if ( !szVersion ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 750 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 751 | MultiByteToWideChar(CP_ACP, 0, lpszVersion, -1, szVersion, len ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | if (lpszReferrer) |
| 755 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 756 | len = MultiByteToWideChar(CP_ACP, 0, lpszReferrer, -1, NULL, 0 ); |
| 757 | szReferrer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 758 | if ( !szReferrer ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 759 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 760 | MultiByteToWideChar(CP_ACP, 0, lpszReferrer, -1, szReferrer, len ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | acceptTypesCount = 0; |
| 764 | if (lpszAcceptTypes) |
| 765 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 766 | /* find out how many there are */ |
| 767 | while (lpszAcceptTypes[acceptTypesCount]) |
| 768 | acceptTypesCount++; |
| 769 | szAcceptTypes = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR *) * (acceptTypesCount+1)); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 770 | acceptTypesCount = 0; |
| 771 | while (lpszAcceptTypes[acceptTypesCount]) |
| 772 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 773 | len = MultiByteToWideChar(CP_ACP, 0, lpszAcceptTypes[acceptTypesCount], |
| 774 | -1, NULL, 0 ); |
| 775 | szAcceptTypes[acceptTypesCount] = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); |
Mike McCormack | 43629c9 | 2003-08-15 03:47:30 +0000 | [diff] [blame] | 776 | if (!szAcceptTypes[acceptTypesCount] ) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 777 | goto end; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 778 | MultiByteToWideChar(CP_ACP, 0, lpszAcceptTypes[acceptTypesCount], |
| 779 | -1, szAcceptTypes[acceptTypesCount], len ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 780 | acceptTypesCount++; |
| 781 | } |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 782 | szAcceptTypes[acceptTypesCount] = NULL; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 783 | } |
| 784 | else szAcceptTypes = 0; |
| 785 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 786 | rc = HttpOpenRequestW(hHttpSession, szVerb, szObjectName, |
| 787 | szVersion, szReferrer, |
| 788 | (LPCWSTR*)szAcceptTypes, dwFlags, dwContext); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 789 | |
| 790 | end: |
| 791 | if (szAcceptTypes) |
| 792 | { |
| 793 | acceptTypesCount = 0; |
| 794 | while (szAcceptTypes[acceptTypesCount]) |
| 795 | { |
| 796 | HeapFree(GetProcessHeap(), 0, szAcceptTypes[acceptTypesCount]); |
| 797 | acceptTypesCount++; |
| 798 | } |
| 799 | HeapFree(GetProcessHeap(), 0, szAcceptTypes); |
| 800 | } |
Michael Stefaniuc | 7cb43c9 | 2004-12-21 14:42:35 +0000 | [diff] [blame] | 801 | HeapFree(GetProcessHeap(), 0, szReferrer); |
| 802 | HeapFree(GetProcessHeap(), 0, szVersion); |
| 803 | HeapFree(GetProcessHeap(), 0, szObjectName); |
| 804 | HeapFree(GetProcessHeap(), 0, szVerb); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 805 | |
| 806 | return rc; |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 807 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 808 | |
| 809 | /*********************************************************************** |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 810 | * HTTP_Base64 |
| 811 | */ |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 812 | static UINT HTTP_Base64( LPCWSTR bin, LPWSTR base64 ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 813 | { |
| 814 | UINT n = 0, x; |
Mike McCormack | 9b95bb5 | 2005-06-13 19:05:42 +0000 | [diff] [blame] | 815 | static LPCSTR HTTP_Base64Enc = |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 816 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 817 | |
| 818 | while( bin[0] ) |
| 819 | { |
| 820 | /* first 6 bits, all from bin[0] */ |
| 821 | base64[n++] = HTTP_Base64Enc[(bin[0] & 0xfc) >> 2]; |
| 822 | x = (bin[0] & 3) << 4; |
| 823 | |
| 824 | /* next 6 bits, 2 from bin[0] and 4 from bin[1] */ |
| 825 | if( !bin[1] ) |
| 826 | { |
| 827 | base64[n++] = HTTP_Base64Enc[x]; |
| 828 | base64[n++] = '='; |
| 829 | base64[n++] = '='; |
| 830 | break; |
| 831 | } |
| 832 | base64[n++] = HTTP_Base64Enc[ x | ( (bin[1]&0xf0) >> 4 ) ]; |
| 833 | x = ( bin[1] & 0x0f ) << 2; |
| 834 | |
| 835 | /* next 6 bits 4 from bin[1] and 2 from bin[2] */ |
| 836 | if( !bin[2] ) |
| 837 | { |
| 838 | base64[n++] = HTTP_Base64Enc[x]; |
| 839 | base64[n++] = '='; |
| 840 | break; |
| 841 | } |
| 842 | base64[n++] = HTTP_Base64Enc[ x | ( (bin[2]&0xc0 ) >> 6 ) ]; |
| 843 | |
| 844 | /* last 6 bits, all from bin [2] */ |
| 845 | base64[n++] = HTTP_Base64Enc[ bin[2] & 0x3f ]; |
| 846 | bin += 3; |
| 847 | } |
| 848 | base64[n] = 0; |
| 849 | return n; |
| 850 | } |
| 851 | |
| 852 | /*********************************************************************** |
| 853 | * HTTP_EncodeBasicAuth |
| 854 | * |
| 855 | * Encode the basic authentication string for HTTP 1.1 |
| 856 | */ |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 857 | static LPWSTR HTTP_EncodeBasicAuth( LPCWSTR username, LPCWSTR password) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 858 | { |
| 859 | UINT len; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 860 | LPWSTR in, out; |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 861 | static const WCHAR szBasic[] = {'B','a','s','i','c',' ',0}; |
| 862 | static const WCHAR szColon[] = {':',0}; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 863 | |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 864 | len = lstrlenW( username ) + 1 + lstrlenW ( password ) + 1; |
| 865 | in = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 866 | if( !in ) |
| 867 | return NULL; |
| 868 | |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 869 | len = lstrlenW(szBasic) + |
| 870 | (lstrlenW( username ) + 1 + lstrlenW ( password ))*2 + 1 + 1; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 871 | out = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 872 | if( out ) |
| 873 | { |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 874 | lstrcpyW( in, username ); |
| 875 | lstrcatW( in, szColon ); |
| 876 | lstrcatW( in, password ); |
| 877 | lstrcpyW( out, szBasic ); |
| 878 | HTTP_Base64( in, &out[strlenW(out)] ); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 879 | } |
| 880 | HeapFree( GetProcessHeap(), 0, in ); |
| 881 | |
| 882 | return out; |
| 883 | } |
| 884 | |
| 885 | /*********************************************************************** |
| 886 | * HTTP_InsertProxyAuthorization |
| 887 | * |
| 888 | * Insert the basic authorization field in the request header |
| 889 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 890 | static BOOL HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr, |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 891 | LPCWSTR username, LPCWSTR password ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 892 | { |
Robert Shearman | 22edb3e | 2005-11-28 11:17:06 +0100 | [diff] [blame] | 893 | WCHAR *authorization = HTTP_EncodeBasicAuth( username, password ); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 894 | BOOL ret = TRUE; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 895 | |
Robert Shearman | 22edb3e | 2005-11-28 11:17:06 +0100 | [diff] [blame] | 896 | if (!authorization) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 897 | return FALSE; |
| 898 | |
Robert Shearman | 22edb3e | 2005-11-28 11:17:06 +0100 | [diff] [blame] | 899 | TRACE( "Inserting authorization: %s\n", debugstr_w( authorization ) ); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 900 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 901 | HTTP_ProcessHeader(lpwhr, szProxy_Authorization, authorization, |
| 902 | HTTP_ADDHDR_FLAG_REPLACE); |
Robert Shearman | 22edb3e | 2005-11-28 11:17:06 +0100 | [diff] [blame] | 903 | |
| 904 | HeapFree( GetProcessHeap(), 0, authorization ); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 905 | |
Robert Shearman | 22edb3e | 2005-11-28 11:17:06 +0100 | [diff] [blame] | 906 | return ret; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | /*********************************************************************** |
| 910 | * HTTP_DealWithProxy |
| 911 | */ |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 912 | static BOOL HTTP_DealWithProxy( LPWININETAPPINFOW hIC, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 913 | LPWININETHTTPSESSIONW lpwhs, LPWININETHTTPREQW lpwhr) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 914 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 915 | WCHAR buf[MAXHOSTNAME]; |
| 916 | WCHAR proxy[MAXHOSTNAME + 15]; /* 15 == "http://" + sizeof(port#) + ":/\0" */ |
Francois Gouget | 8fc374d | 2004-04-20 02:14:00 +0000 | [diff] [blame] | 917 | WCHAR* url; |
| 918 | static const WCHAR szNul[] = { 0 }; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 919 | URL_COMPONENTSW UrlComponents; |
Francois Gouget | 8fc374d | 2004-04-20 02:14:00 +0000 | [diff] [blame] | 920 | static const WCHAR szHttp[] = { 'h','t','t','p',':','/','/',0 }, szSlash[] = { '/',0 } ; |
Mike McCormack | a9b405c | 2004-06-01 20:19:56 +0000 | [diff] [blame] | 921 | static const WCHAR szFormat1[] = { 'h','t','t','p',':','/','/','%','s',0 }; |
Francois Gouget | 8fc374d | 2004-04-20 02:14:00 +0000 | [diff] [blame] | 922 | static const WCHAR szFormat2[] = { 'h','t','t','p',':','/','/','%','s',':','%','d',0 }; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 923 | int len; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 924 | |
| 925 | memset( &UrlComponents, 0, sizeof UrlComponents ); |
| 926 | UrlComponents.dwStructSize = sizeof UrlComponents; |
| 927 | UrlComponents.lpszHostName = buf; |
| 928 | UrlComponents.dwHostNameLength = MAXHOSTNAME; |
| 929 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 930 | if( CSTR_EQUAL != CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, |
Robert Shearman | cc44f3a | 2005-11-28 11:31:11 +0100 | [diff] [blame] | 931 | hIC->lpszProxy,strlenW(szHttp),szHttp,strlenW(szHttp)) ) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 932 | sprintfW(proxy, szFormat1, hIC->lpszProxy); |
Uwe Bonnes | 599c452 | 2003-12-15 19:47:31 +0000 | [diff] [blame] | 933 | else |
Robert Shearman | cc44f3a | 2005-11-28 11:31:11 +0100 | [diff] [blame] | 934 | strcpyW(proxy, hIC->lpszProxy); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 935 | if( !InternetCrackUrlW(proxy, 0, 0, &UrlComponents) ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 936 | return FALSE; |
| 937 | if( UrlComponents.dwHostNameLength == 0 ) |
| 938 | return FALSE; |
| 939 | |
| 940 | if( !lpwhr->lpszPath ) |
Francois Gouget | 8fc374d | 2004-04-20 02:14:00 +0000 | [diff] [blame] | 941 | lpwhr->lpszPath = (LPWSTR)szNul; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 942 | TRACE("server='%s' path='%s'\n", |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 943 | debugstr_w(lpwhs->lpszHostName), debugstr_w(lpwhr->lpszPath)); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 944 | /* for constant 15 see above */ |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 945 | len = strlenW(lpwhs->lpszHostName) + strlenW(lpwhr->lpszPath) + 15; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 946 | url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 947 | |
| 948 | if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER) |
| 949 | UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT; |
| 950 | |
Robert Shearman | 3592110 | 2005-11-28 11:53:05 +0100 | [diff] [blame] | 951 | sprintfW(url, szFormat2, lpwhs->lpszHostName, lpwhs->nHostPort); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 952 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 953 | if( lpwhr->lpszPath[0] != '/' ) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 954 | strcatW( url, szSlash ); |
| 955 | strcatW(url, lpwhr->lpszPath); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 956 | if(lpwhr->lpszPath != szNul) |
| 957 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath); |
| 958 | lpwhr->lpszPath = url; |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 959 | |
| 960 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 961 | lpwhs->lpszServerName = WININET_strdupW(UrlComponents.lpszHostName); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 962 | lpwhs->nServerPort = UrlComponents.nPort; |
| 963 | |
| 964 | return TRUE; |
| 965 | } |
| 966 | |
| 967 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 968 | * HTTP_HttpOpenRequestW (internal) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 969 | * |
| 970 | * Open a HTTP request handle |
| 971 | * |
| 972 | * RETURNS |
| 973 | * HINTERNET a HTTP request handle on success |
| 974 | * NULL on failure |
| 975 | * |
| 976 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 977 | HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 978 | LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, |
| 979 | LPCWSTR lpszReferrer , LPCWSTR *lpszAcceptTypes, |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 980 | DWORD dwFlags, DWORD dwContext) |
| 981 | { |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 982 | LPWININETAPPINFOW hIC = NULL; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 983 | LPWININETHTTPREQW lpwhr; |
| 984 | LPWSTR lpszCookies; |
| 985 | LPWSTR lpszUrl = NULL; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 986 | DWORD nCookieSize; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 987 | HINTERNET handle = NULL; |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 988 | static const WCHAR szUrlForm[] = {'h','t','t','p',':','/','/','%','s',0}; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 989 | DWORD len; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 990 | LPHTTPHEADERW Host; |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 991 | char szaddr[32]; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 992 | |
Francois Gouget | 0edbaf7 | 2005-11-10 12:14:56 +0000 | [diff] [blame] | 993 | TRACE("-->\n"); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 994 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 995 | assert( lpwhs->hdr.htype == WH_HHTTPSESSION ); |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 996 | hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 997 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 998 | lpwhr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPREQW)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 999 | if (NULL == lpwhr) |
| 1000 | { |
| 1001 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1002 | goto lend; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 1003 | } |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1004 | lpwhr->hdr.htype = WH_HHTTPREQ; |
| 1005 | lpwhr->hdr.lpwhparent = WININET_AddRef( &lpwhs->hdr ); |
| 1006 | lpwhr->hdr.dwFlags = dwFlags; |
| 1007 | lpwhr->hdr.dwContext = dwContext; |
| 1008 | lpwhr->hdr.dwRefCount = 1; |
| 1009 | lpwhr->hdr.destroy = HTTP_CloseHTTPRequestHandle; |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 1010 | lpwhr->hdr.lpfnStatusCB = lpwhs->hdr.lpfnStatusCB; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1011 | |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 1012 | handle = WININET_AllocHandle( &lpwhr->hdr ); |
| 1013 | if (NULL == handle) |
| 1014 | { |
| 1015 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1016 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Robert Shearman | 9981f33 | 2006-03-06 17:31:09 +0000 | [diff] [blame] | 1019 | if (!NETCON_init(&lpwhr->netConnection, dwFlags & INTERNET_FLAG_SECURE)) |
| 1020 | { |
| 1021 | InternetCloseHandle( handle ); |
| 1022 | handle = NULL; |
| 1023 | goto lend; |
| 1024 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1025 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1026 | if (NULL != lpszObjectName && strlenW(lpszObjectName)) { |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1027 | HRESULT rc; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1028 | |
| 1029 | len = 0; |
| 1030 | rc = UrlEscapeW(lpszObjectName, NULL, &len, URL_ESCAPE_SPACES_ONLY); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1031 | if (rc != E_POINTER) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1032 | len = strlenW(lpszObjectName)+1; |
| 1033 | lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
| 1034 | rc = UrlEscapeW(lpszObjectName, lpwhr->lpszPath, &len, |
Huw D M Davies | 0aebee9 | 2001-01-21 21:09:00 +0000 | [diff] [blame] | 1035 | URL_ESCAPE_SPACES_ONLY); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1036 | if (rc) |
| 1037 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1038 | ERR("Unable to escape string!(%s) (%ld)\n",debugstr_w(lpszObjectName),rc); |
| 1039 | strcpyW(lpwhr->lpszPath,lpszObjectName); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1040 | } |
Huw D M Davies | 0aebee9 | 2001-01-21 21:09:00 +0000 | [diff] [blame] | 1041 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1042 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1043 | if (NULL != lpszReferrer && strlenW(lpszReferrer)) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1044 | HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpszReferrer, HTTP_ADDHDR_FLAG_COALESCE); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1045 | |
| 1046 | if(lpszAcceptTypes!=NULL) |
| 1047 | { |
| 1048 | int i; |
| 1049 | for(i=0;lpszAcceptTypes[i]!=NULL;i++) |
| 1050 | HTTP_ProcessHeader(lpwhr, HTTP_ACCEPT, lpszAcceptTypes[i], HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_REQ|HTTP_ADDHDR_FLAG_ADD_IF_NEW); |
| 1051 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1052 | |
| 1053 | if (NULL == lpszVerb) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1054 | { |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 1055 | static const WCHAR szGet[] = {'G','E','T',0}; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1056 | lpwhr->lpszVerb = WININET_strdupW(szGet); |
| 1057 | } |
| 1058 | else if (strlenW(lpszVerb)) |
| 1059 | lpwhr->lpszVerb = WININET_strdupW(lpszVerb); |
| 1060 | |
| 1061 | if (NULL != lpszReferrer && strlenW(lpszReferrer)) |
| 1062 | { |
| 1063 | WCHAR buf[MAXHOSTNAME]; |
| 1064 | URL_COMPONENTSW UrlComponents; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1065 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1066 | memset( &UrlComponents, 0, sizeof UrlComponents ); |
| 1067 | UrlComponents.dwStructSize = sizeof UrlComponents; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1068 | UrlComponents.lpszHostName = buf; |
| 1069 | UrlComponents.dwHostNameLength = MAXHOSTNAME; |
| 1070 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1071 | InternetCrackUrlW(lpszReferrer, 0, 0, &UrlComponents); |
| 1072 | if (strlenW(UrlComponents.lpszHostName)) |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1073 | HTTP_ProcessHeader(lpwhr, szHost, UrlComponents.lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1074 | } |
Robert Shearman | 37f2cc8 | 2004-09-13 19:33:17 +0000 | [diff] [blame] | 1075 | else |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1076 | HTTP_ProcessHeader(lpwhr, szHost, lpwhs->lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ); |
Robert Shearman | 37f2cc8 | 2004-09-13 19:33:17 +0000 | [diff] [blame] | 1077 | |
Mike McCormack | 403e58f | 2005-10-19 19:07:08 +0000 | [diff] [blame] | 1078 | if (lpwhs->nServerPort == INTERNET_INVALID_PORT_NUMBER) |
| 1079 | lpwhs->nServerPort = (dwFlags & INTERNET_FLAG_SECURE ? |
| 1080 | INTERNET_DEFAULT_HTTPS_PORT : |
| 1081 | INTERNET_DEFAULT_HTTP_PORT); |
Robert Shearman | 3592110 | 2005-11-28 11:53:05 +0100 | [diff] [blame] | 1082 | lpwhs->nHostPort = lpwhs->nServerPort; |
Mike McCormack | 403e58f | 2005-10-19 19:07:08 +0000 | [diff] [blame] | 1083 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1084 | if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0) |
| 1085 | HTTP_DealWithProxy( hIC, lpwhs, lpwhr ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1086 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1087 | if (hIC->lpszAgent) |
| 1088 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1089 | WCHAR *agent_header; |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 1090 | 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] | 1091 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1092 | len = strlenW(hIC->lpszAgent) + strlenW(user_agent); |
| 1093 | agent_header = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); |
| 1094 | sprintfW(agent_header, user_agent, hIC->lpszAgent ); |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 1095 | |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1096 | HTTP_HttpAddRequestHeadersW(lpwhr, agent_header, strlenW(agent_header), |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1097 | HTTP_ADDREQ_FLAG_ADD); |
| 1098 | HeapFree(GetProcessHeap(), 0, agent_header); |
| 1099 | } |
| 1100 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1101 | Host = HTTP_GetHeader(lpwhr,szHost); |
| 1102 | |
| 1103 | len = lstrlenW(Host->lpszValue) + strlenW(szUrlForm); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1104 | lpszUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1105 | sprintfW( lpszUrl, szUrlForm, Host->lpszValue ); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1106 | |
Robert Shearman | d631592 | 2004-07-19 21:18:33 +0000 | [diff] [blame] | 1107 | if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) && |
| 1108 | InternetGetCookieW(lpszUrl, NULL, NULL, &nCookieSize)) |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1109 | { |
| 1110 | int cnt = 0; |
Francois Gouget | 6a6c85c | 2004-04-19 20:12:14 +0000 | [diff] [blame] | 1111 | static const WCHAR szCookie[] = {'C','o','o','k','i','e',':',' ',0}; |
| 1112 | static const WCHAR szcrlf[] = {'\r','\n',0}; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1113 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1114 | lpszCookies = HeapAlloc(GetProcessHeap(), 0, (nCookieSize + 1 + 8)*sizeof(WCHAR)); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1115 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1116 | cnt += sprintfW(lpszCookies, szCookie); |
| 1117 | InternetGetCookieW(lpszUrl, NULL, lpszCookies + cnt, &nCookieSize); |
| 1118 | strcatW(lpszCookies, szcrlf); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1119 | |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1120 | HTTP_HttpAddRequestHeadersW(lpwhr, lpszCookies, strlenW(lpszCookies), |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 1121 | HTTP_ADDREQ_FLAG_ADD); |
| 1122 | HeapFree(GetProcessHeap(), 0, lpszCookies); |
| 1123 | } |
| 1124 | HeapFree(GetProcessHeap(), 0, lpszUrl); |
| 1125 | |
| 1126 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 1127 | INTERNET_SendCallback(&lpwhs->hdr, dwContext, |
| 1128 | INTERNET_STATUS_HANDLE_CREATED, &handle, |
| 1129 | sizeof(handle)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1130 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1131 | /* |
| 1132 | * A STATUS_REQUEST_COMPLETE is NOT sent here as per my tests on windows |
| 1133 | */ |
| 1134 | |
| 1135 | /* |
| 1136 | * According to my tests. The name is not resolved until a request is Opened |
| 1137 | */ |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 1138 | INTERNET_SendCallback(&lpwhr->hdr, dwContext, |
| 1139 | INTERNET_STATUS_RESOLVING_NAME, |
| 1140 | lpwhs->lpszServerName, |
| 1141 | strlenW(lpwhs->lpszServerName)+1); |
Maarten Lankhorst | e325f7e | 2005-06-21 20:02:34 +0000 | [diff] [blame] | 1142 | |
Mike McCormack | 403e58f | 2005-10-19 19:07:08 +0000 | [diff] [blame] | 1143 | if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort, |
Robert Shearman | e6157dd | 2005-11-15 18:16:55 +0000 | [diff] [blame] | 1144 | &lpwhs->socketAddress)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1145 | { |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1146 | INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1147 | InternetCloseHandle( handle ); |
| 1148 | handle = NULL; |
| 1149 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 1152 | inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr, |
| 1153 | szaddr, sizeof(szaddr)); |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 1154 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 1155 | INTERNET_STATUS_NAME_RESOLVED, |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 1156 | szaddr, strlen(szaddr)+1); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1157 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1158 | lend: |
| 1159 | if( lpwhr ) |
| 1160 | WININET_Release( &lpwhr->hdr ); |
| 1161 | |
| 1162 | TRACE("<-- %p (%p)\n", handle, lpwhr); |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 1163 | return handle; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1166 | static const WCHAR szAccept[] = { 'A','c','c','e','p','t',0 }; |
| 1167 | static const WCHAR szAccept_Charset[] = { 'A','c','c','e','p','t','-','C','h','a','r','s','e','t', 0 }; |
| 1168 | static const WCHAR szAccept_Encoding[] = { 'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',0 }; |
| 1169 | static const WCHAR szAccept_Language[] = { 'A','c','c','e','p','t','-','L','a','n','g','u','a','g','e',0 }; |
| 1170 | static const WCHAR szAccept_Ranges[] = { 'A','c','c','e','p','t','-','R','a','n','g','e','s',0 }; |
| 1171 | static const WCHAR szAge[] = { 'A','g','e',0 }; |
| 1172 | static const WCHAR szAllow[] = { 'A','l','l','o','w',0 }; |
| 1173 | static const WCHAR szAuthorization[] = { 'A','u','t','h','o','r','i','z','a','t','i','o','n',0 }; |
| 1174 | static const WCHAR szCache_Control[] = { 'C','a','c','h','e','-','C','o','n','t','r','o','l',0 }; |
| 1175 | static const WCHAR szConnection[] = { 'C','o','n','n','e','c','t','i','o','n',0 }; |
| 1176 | static const WCHAR szContent_Base[] = { 'C','o','n','t','e','n','t','-','B','a','s','e',0 }; |
| 1177 | static const WCHAR szContent_Encoding[] = { 'C','o','n','t','e','n','t','-','E','n','c','o','d','i','n','g',0 }; |
| 1178 | static const WCHAR szContent_ID[] = { 'C','o','n','t','e','n','t','-','I','D',0 }; |
| 1179 | static const WCHAR szContent_Language[] = { 'C','o','n','t','e','n','t','-','L','a','n','g','u','a','g','e',0 }; |
| 1180 | static const WCHAR szContent_Length[] = { 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',0 }; |
| 1181 | static const WCHAR szContent_Location[] = { 'C','o','n','t','e','n','t','-','L','o','c','a','t','i','o','n',0 }; |
| 1182 | static const WCHAR szContent_MD5[] = { 'C','o','n','t','e','n','t','-','M','D','5',0 }; |
| 1183 | static const WCHAR szContent_Range[] = { 'C','o','n','t','e','n','t','-','R','a','n','g','e',0 }; |
| 1184 | 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 }; |
| 1185 | static const WCHAR szContent_Type[] = { 'C','o','n','t','e','n','t','-','T','y','p','e',0 }; |
| 1186 | static const WCHAR szCookie[] = { 'C','o','o','k','i','e',0 }; |
| 1187 | static const WCHAR szDate[] = { 'D','a','t','e',0 }; |
| 1188 | static const WCHAR szFrom[] = { 'F','r','o','m',0 }; |
| 1189 | static const WCHAR szETag[] = { 'E','T','a','g',0 }; |
| 1190 | static const WCHAR szExpect[] = { 'E','x','p','e','c','t',0 }; |
| 1191 | static const WCHAR szExpires[] = { 'E','x','p','i','r','e','s',0 }; |
| 1192 | static const WCHAR szIf_Match[] = { 'I','f','-','M','a','t','c','h',0 }; |
| 1193 | static const WCHAR szIf_Modified_Since[] = { 'I','f','-','M','o','d','i','f','i','e','d','-','S','i','n','c','e',0 }; |
| 1194 | static const WCHAR szIf_None_Match[] = { 'I','f','-','N','o','n','e','-','M','a','t','c','h',0 }; |
| 1195 | static const WCHAR szIf_Range[] = { 'I','f','-','R','a','n','g','e',0 }; |
| 1196 | static const WCHAR szIf_Unmodified_Since[] = { 'I','f','-','U','n','m','o','d','i','f','i','e','d','-','S','i','n','c','e',0 }; |
| 1197 | static const WCHAR szLast_Modified[] = { 'L','a','s','t','-','M','o','d','i','f','i','e','d',0 }; |
| 1198 | static const WCHAR szLocation[] = { 'L','o','c','a','t','i','o','n',0 }; |
| 1199 | static const WCHAR szMax_Forwards[] = { 'M','a','x','-','F','o','r','w','a','r','d','s',0 }; |
| 1200 | static const WCHAR szMime_Version[] = { 'M','i','m','e','-','V','e','r','s','i','o','n',0 }; |
| 1201 | static const WCHAR szPragma[] = { 'P','r','a','g','m','a',0 }; |
| 1202 | static const WCHAR szProxy_Authenticate[] = { 'P','r','o','x','y','-','A','u','t','h','e','n','t','i','c','a','t','e',0 }; |
| 1203 | static const WCHAR szProxy_Connection[] = { 'P','r','o','x','y','-','C','o','n','n','e','c','t','i','o','n',0 }; |
| 1204 | static const WCHAR szPublic[] = { 'P','u','b','l','i','c',0 }; |
| 1205 | static const WCHAR szRange[] = { 'R','a','n','g','e',0 }; |
| 1206 | static const WCHAR szReferer[] = { 'R','e','f','e','r','e','r',0 }; |
| 1207 | static const WCHAR szRetry_After[] = { 'R','e','t','r','y','-','A','f','t','e','r',0 }; |
| 1208 | static const WCHAR szServer[] = { 'S','e','r','v','e','r',0 }; |
| 1209 | static const WCHAR szSet_Cookie[] = { 'S','e','t','-','C','o','o','k','i','e',0 }; |
| 1210 | static const WCHAR szTransfer_Encoding[] = { 'T','r','a','n','s','f','e','r','-','E','n','c','o','d','i','n','g',0 }; |
| 1211 | 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 }; |
| 1212 | static const WCHAR szUpgrade[] = { 'U','p','g','r','a','d','e',0 }; |
| 1213 | static const WCHAR szURI[] = { 'U','R','I',0 }; |
| 1214 | static const WCHAR szUser_Agent[] = { 'U','s','e','r','-','A','g','e','n','t',0 }; |
| 1215 | static const WCHAR szVary[] = { 'V','a','r','y',0 }; |
| 1216 | static const WCHAR szVia[] = { 'V','i','a',0 }; |
| 1217 | static const WCHAR szWarning[] = { 'W','a','r','n','i','n','g',0 }; |
| 1218 | static const WCHAR szWWW_Authenticate[] = { 'W','W','W','-','A','u','t','h','e','n','t','i','c','a','t','e',0 }; |
| 1219 | |
Mike McCormack | 7f5e273 | 2006-03-30 18:02:54 +0900 | [diff] [blame] | 1220 | static const LPCWSTR header_lookup[] = { |
| 1221 | szMime_Version, /* HTTP_QUERY_MIME_VERSION = 0 */ |
| 1222 | szContent_Type, /* HTTP_QUERY_CONTENT_TYPE = 1 */ |
| 1223 | szContent_Transfer_Encoding,/* HTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2 */ |
| 1224 | szContent_ID, /* HTTP_QUERY_CONTENT_ID = 3 */ |
| 1225 | NULL, /* HTTP_QUERY_CONTENT_DESCRIPTION = 4 */ |
| 1226 | szContent_Length, /* HTTP_QUERY_CONTENT_LENGTH = 5 */ |
| 1227 | szContent_Language, /* HTTP_QUERY_CONTENT_LANGUAGE = 6 */ |
| 1228 | szAllow, /* HTTP_QUERY_ALLOW = 7 */ |
| 1229 | szPublic, /* HTTP_QUERY_PUBLIC = 8 */ |
| 1230 | szDate, /* HTTP_QUERY_DATE = 9 */ |
| 1231 | szExpires, /* HTTP_QUERY_EXPIRES = 10 */ |
| 1232 | szLast_Modified, /* HTTP_QUERY_LAST_MODIFIED = 11 */ |
| 1233 | NULL, /* HTTP_QUERY_MESSAGE_ID = 12 */ |
| 1234 | szURI, /* HTTP_QUERY_URI = 13 */ |
| 1235 | szFrom, /* HTTP_QUERY_DERIVED_FROM = 14 */ |
| 1236 | NULL, /* HTTP_QUERY_COST = 15 */ |
| 1237 | NULL, /* HTTP_QUERY_LINK = 16 */ |
| 1238 | szPragma, /* HTTP_QUERY_PRAGMA = 17 */ |
| 1239 | NULL, /* HTTP_QUERY_VERSION = 18 */ |
| 1240 | szStatus, /* HTTP_QUERY_STATUS_CODE = 19 */ |
| 1241 | NULL, /* HTTP_QUERY_STATUS_TEXT = 20 */ |
| 1242 | NULL, /* HTTP_QUERY_RAW_HEADERS = 21 */ |
| 1243 | NULL, /* HTTP_QUERY_RAW_HEADERS_CRLF = 22 */ |
| 1244 | szConnection, /* HTTP_QUERY_CONNECTION = 23 */ |
| 1245 | szAccept, /* HTTP_QUERY_ACCEPT = 24 */ |
| 1246 | szAccept_Charset, /* HTTP_QUERY_ACCEPT_CHARSET = 25 */ |
| 1247 | szAccept_Encoding, /* HTTP_QUERY_ACCEPT_ENCODING = 26 */ |
| 1248 | szAccept_Language, /* HTTP_QUERY_ACCEPT_LANGUAGE = 27 */ |
| 1249 | szAuthorization, /* HTTP_QUERY_AUTHORIZATION = 28 */ |
| 1250 | szContent_Encoding, /* HTTP_QUERY_CONTENT_ENCODING = 29 */ |
| 1251 | NULL, /* HTTP_QUERY_FORWARDED = 30 */ |
| 1252 | NULL, /* HTTP_QUERY_FROM = 31 */ |
| 1253 | szIf_Modified_Since, /* HTTP_QUERY_IF_MODIFIED_SINCE = 32 */ |
| 1254 | szLocation, /* HTTP_QUERY_LOCATION = 33 */ |
| 1255 | NULL, /* HTTP_QUERY_ORIG_URI = 34 */ |
| 1256 | szReferer, /* HTTP_QUERY_REFERER = 35 */ |
| 1257 | szRetry_After, /* HTTP_QUERY_RETRY_AFTER = 36 */ |
| 1258 | szServer, /* HTTP_QUERY_SERVER = 37 */ |
| 1259 | NULL, /* HTTP_TITLE = 38 */ |
| 1260 | szUser_Agent, /* HTTP_QUERY_USER_AGENT = 39 */ |
| 1261 | szWWW_Authenticate, /* HTTP_QUERY_WWW_AUTHENTICATE = 40 */ |
| 1262 | szProxy_Authenticate, /* HTTP_QUERY_PROXY_AUTHENTICATE = 41 */ |
| 1263 | szAccept_Ranges, /* HTTP_QUERY_ACCEPT_RANGES = 42 */ |
| 1264 | szSet_Cookie, /* HTTP_QUERY_SET_COOKIE = 43 */ |
| 1265 | szCookie, /* HTTP_QUERY_COOKIE = 44 */ |
| 1266 | NULL, /* HTTP_QUERY_REQUEST_METHOD = 45 */ |
| 1267 | NULL, /* HTTP_QUERY_REFRESH = 46 */ |
| 1268 | NULL, /* HTTP_QUERY_CONTENT_DISPOSITION = 47 */ |
| 1269 | szAge, /* HTTP_QUERY_AGE = 48 */ |
| 1270 | szCache_Control, /* HTTP_QUERY_CACHE_CONTROL = 49 */ |
| 1271 | szContent_Base, /* HTTP_QUERY_CONTENT_BASE = 50 */ |
| 1272 | szContent_Location, /* HTTP_QUERY_CONTENT_LOCATION = 51 */ |
| 1273 | szContent_MD5, /* HTTP_QUERY_CONTENT_MD5 = 52 */ |
| 1274 | szContent_Range, /* HTTP_QUERY_CONTENT_RANGE = 53 */ |
| 1275 | szETag, /* HTTP_QUERY_ETAG = 54 */ |
| 1276 | szHost, /* HTTP_QUERY_HOST = 55 */ |
| 1277 | szIf_Match, /* HTTP_QUERY_IF_MATCH = 56 */ |
| 1278 | szIf_None_Match, /* HTTP_QUERY_IF_NONE_MATCH = 57 */ |
| 1279 | szIf_Range, /* HTTP_QUERY_IF_RANGE = 58 */ |
| 1280 | szIf_Unmodified_Since, /* HTTP_QUERY_IF_UNMODIFIED_SINCE = 59 */ |
| 1281 | szMax_Forwards, /* HTTP_QUERY_MAX_FORWARDS = 60 */ |
| 1282 | szProxy_Authorization, /* HTTP_QUERY_PROXY_AUTHORIZATION = 61 */ |
| 1283 | szRange, /* HTTP_QUERY_RANGE = 62 */ |
| 1284 | szTransfer_Encoding, /* HTTP_QUERY_TRANSFER_ENCODING = 63 */ |
| 1285 | szUpgrade, /* HTTP_QUERY_UPGRADE = 64 */ |
| 1286 | szVary, /* HTTP_QUERY_VARY = 65 */ |
| 1287 | szVia, /* HTTP_QUERY_VIA = 66 */ |
| 1288 | szWarning, /* HTTP_QUERY_WARNING = 67 */ |
| 1289 | szExpect, /* HTTP_QUERY_EXPECT = 68 */ |
| 1290 | szProxy_Connection, /* HTTP_QUERY_PROXY_CONNECTION = 69 */ |
| 1291 | szUnless_Modified_Since, /* HTTP_QUERY_UNLESS_MODIFIED_SINCE = 70 */ |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1292 | }; |
| 1293 | |
Mike McCormack | 7f5e273 | 2006-03-30 18:02:54 +0900 | [diff] [blame] | 1294 | #define LAST_TABLE_HEADER (sizeof(header_lookup)/sizeof(header_lookup[0])) |
| 1295 | |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 1296 | /*********************************************************************** |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1297 | * HTTP_HttpQueryInfoW (internal) |
| 1298 | */ |
Mike McCormack | 9b95bb5 | 2005-06-13 19:05:42 +0000 | [diff] [blame] | 1299 | static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD dwInfoLevel, |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1300 | LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex) |
| 1301 | { |
| 1302 | LPHTTPHEADERW lphttpHdr = NULL; |
| 1303 | BOOL bSuccess = FALSE; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1304 | BOOL request_only = dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS; |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1305 | INT requested_index = lpdwIndex ? *lpdwIndex : 0; |
| 1306 | INT level = (dwInfoLevel & ~HTTP_QUERY_MODIFIER_FLAGS_MASK); |
| 1307 | INT index = -1; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1308 | |
| 1309 | /* Find requested header structure */ |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1310 | switch (level) |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1311 | { |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1312 | case HTTP_QUERY_CUSTOM: |
| 1313 | index = HTTP_GetCustomHeaderIndex(lpwhr, lpBuffer, requested_index, request_only); |
| 1314 | break; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1315 | |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1316 | case HTTP_QUERY_RAW_HEADERS_CRLF: |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 1317 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 1318 | DWORD len = strlenW(lpwhr->lpszRawHeaders); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 1319 | if (len + 1 > *lpdwBufferLength/sizeof(WCHAR)) |
| 1320 | { |
| 1321 | *lpdwBufferLength = (len + 1) * sizeof(WCHAR); |
| 1322 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 1323 | return FALSE; |
| 1324 | } |
| 1325 | memcpy(lpBuffer, lpwhr->lpszRawHeaders, (len+1)*sizeof(WCHAR)); |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 1326 | *lpdwBufferLength = len * sizeof(WCHAR); |
| 1327 | |
| 1328 | TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len)); |
| 1329 | |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 1330 | return TRUE; |
| 1331 | } |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1332 | case HTTP_QUERY_RAW_HEADERS: |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 1333 | { |
| 1334 | static const WCHAR szCrLf[] = {'\r','\n',0}; |
| 1335 | LPWSTR * ppszRawHeaderLines = HTTP_Tokenize(lpwhr->lpszRawHeaders, szCrLf); |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 1336 | DWORD i, size = 0; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 1337 | LPWSTR pszString = (WCHAR*)lpBuffer; |
| 1338 | |
| 1339 | for (i = 0; ppszRawHeaderLines[i]; i++) |
| 1340 | size += strlenW(ppszRawHeaderLines[i]) + 1; |
| 1341 | |
| 1342 | if (size + 1 > *lpdwBufferLength/sizeof(WCHAR)) |
| 1343 | { |
| 1344 | HTTP_FreeTokens(ppszRawHeaderLines); |
| 1345 | *lpdwBufferLength = (size + 1) * sizeof(WCHAR); |
| 1346 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 1347 | return FALSE; |
| 1348 | } |
| 1349 | |
| 1350 | for (i = 0; ppszRawHeaderLines[i]; i++) |
| 1351 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 1352 | DWORD len = strlenW(ppszRawHeaderLines[i]); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 1353 | memcpy(pszString, ppszRawHeaderLines[i], (len+1)*sizeof(WCHAR)); |
| 1354 | pszString += len+1; |
| 1355 | } |
| 1356 | *pszString = '\0'; |
| 1357 | |
| 1358 | TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, size)); |
| 1359 | |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 1360 | *lpdwBufferLength = size * sizeof(WCHAR); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 1361 | HTTP_FreeTokens(ppszRawHeaderLines); |
| 1362 | |
| 1363 | return TRUE; |
| 1364 | } |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1365 | case HTTP_QUERY_STATUS_TEXT: |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1366 | { |
| 1367 | DWORD len = strlenW(lpwhr->lpszStatusText); |
| 1368 | if (len + 1 > *lpdwBufferLength/sizeof(WCHAR)) |
| 1369 | { |
| 1370 | *lpdwBufferLength = (len + 1) * sizeof(WCHAR); |
| 1371 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 1372 | return FALSE; |
| 1373 | } |
| 1374 | memcpy(lpBuffer, lpwhr->lpszStatusText, (len+1)*sizeof(WCHAR)); |
| 1375 | *lpdwBufferLength = len * sizeof(WCHAR); |
| 1376 | |
| 1377 | TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len)); |
| 1378 | |
| 1379 | return TRUE; |
| 1380 | } |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1381 | case HTTP_QUERY_VERSION: |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1382 | { |
| 1383 | DWORD len = strlenW(lpwhr->lpszVersion); |
| 1384 | if (len + 1 > *lpdwBufferLength/sizeof(WCHAR)) |
| 1385 | { |
| 1386 | *lpdwBufferLength = (len + 1) * sizeof(WCHAR); |
| 1387 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 1388 | return FALSE; |
| 1389 | } |
| 1390 | memcpy(lpBuffer, lpwhr->lpszVersion, (len+1)*sizeof(WCHAR)); |
| 1391 | *lpdwBufferLength = len * sizeof(WCHAR); |
| 1392 | |
| 1393 | TRACE("returning data: %s\n", debugstr_wn((WCHAR*)lpBuffer, len)); |
| 1394 | |
| 1395 | return TRUE; |
| 1396 | } |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1397 | default: |
Mike McCormack | 7f5e273 | 2006-03-30 18:02:54 +0900 | [diff] [blame] | 1398 | assert (LAST_TABLE_HEADER == (HTTP_QUERY_UNLESS_MODIFIED_SINCE + 1)); |
| 1399 | |
| 1400 | if (level >= 0 && level < LAST_TABLE_HEADER && header_lookup[level]) |
| 1401 | index = HTTP_GetCustomHeaderIndex(lpwhr, header_lookup[level], |
| 1402 | requested_index,request_only); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1405 | if (index >= 0) |
| 1406 | lphttpHdr = &lpwhr->pCustHeaders[index]; |
| 1407 | |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1408 | /* Ensure header satisifies requested attributes */ |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1409 | if (!lphttpHdr || |
| 1410 | ((dwInfoLevel & HTTP_QUERY_FLAG_REQUEST_HEADERS) && |
| 1411 | (~lphttpHdr->wFlags & HDR_ISREQUEST))) |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 1412 | { |
| 1413 | SetLastError(ERROR_HTTP_HEADER_NOT_FOUND); |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1414 | return bSuccess; |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 1415 | } |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1416 | |
Mike McCormack | ae30088 | 2006-03-30 18:01:48 +0900 | [diff] [blame] | 1417 | if (lpdwIndex) |
| 1418 | (*lpdwIndex)++; |
| 1419 | |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1420 | /* coalesce value to reuqested type */ |
| 1421 | if (dwInfoLevel & HTTP_QUERY_FLAG_NUMBER) |
| 1422 | { |
| 1423 | *(int *)lpBuffer = atoiW(lphttpHdr->lpszValue); |
| 1424 | bSuccess = TRUE; |
| 1425 | |
| 1426 | TRACE(" returning number : %d\n", *(int *)lpBuffer); |
| 1427 | } |
| 1428 | else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME) |
| 1429 | { |
| 1430 | time_t tmpTime; |
| 1431 | struct tm tmpTM; |
| 1432 | SYSTEMTIME *STHook; |
| 1433 | |
| 1434 | tmpTime = ConvertTimeString(lphttpHdr->lpszValue); |
| 1435 | |
| 1436 | tmpTM = *gmtime(&tmpTime); |
| 1437 | STHook = (SYSTEMTIME *) lpBuffer; |
| 1438 | if(STHook==NULL) |
| 1439 | return bSuccess; |
| 1440 | |
| 1441 | STHook->wDay = tmpTM.tm_mday; |
| 1442 | STHook->wHour = tmpTM.tm_hour; |
| 1443 | STHook->wMilliseconds = 0; |
| 1444 | STHook->wMinute = tmpTM.tm_min; |
| 1445 | STHook->wDayOfWeek = tmpTM.tm_wday; |
| 1446 | STHook->wMonth = tmpTM.tm_mon + 1; |
| 1447 | STHook->wSecond = tmpTM.tm_sec; |
| 1448 | STHook->wYear = tmpTM.tm_year; |
| 1449 | |
| 1450 | bSuccess = TRUE; |
| 1451 | |
| 1452 | TRACE(" returning time : %04d/%02d/%02d - %d - %02d:%02d:%02d.%02d\n", |
| 1453 | STHook->wYear, STHook->wMonth, STHook->wDay, STHook->wDayOfWeek, |
| 1454 | STHook->wHour, STHook->wMinute, STHook->wSecond, STHook->wMilliseconds); |
| 1455 | } |
Aric Stewart | 7bca41a | 2005-12-08 12:44:45 +0100 | [diff] [blame] | 1456 | else if (lphttpHdr->lpszValue) |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1457 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 1458 | DWORD len = (strlenW(lphttpHdr->lpszValue) + 1) * sizeof(WCHAR); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1459 | |
| 1460 | if (len > *lpdwBufferLength) |
| 1461 | { |
| 1462 | *lpdwBufferLength = len; |
| 1463 | INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); |
| 1464 | return bSuccess; |
| 1465 | } |
| 1466 | |
| 1467 | memcpy(lpBuffer, lphttpHdr->lpszValue, len); |
| 1468 | *lpdwBufferLength = len - sizeof(WCHAR); |
| 1469 | bSuccess = TRUE; |
| 1470 | |
| 1471 | TRACE(" returning string : '%s'\n", debugstr_w(lpBuffer)); |
| 1472 | } |
| 1473 | return bSuccess; |
| 1474 | } |
| 1475 | |
| 1476 | /*********************************************************************** |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 1477 | * HttpQueryInfoW (WININET.@) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1478 | * |
| 1479 | * Queries for information about an HTTP request |
| 1480 | * |
| 1481 | * RETURNS |
| 1482 | * TRUE on success |
| 1483 | * FALSE on failure |
| 1484 | * |
| 1485 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1486 | BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel, |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1487 | LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex) |
| 1488 | { |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1489 | BOOL bSuccess = FALSE; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1490 | LPWININETHTTPREQW lpwhr; |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1491 | |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1492 | if (TRACE_ON(wininet)) { |
| 1493 | #define FE(x) { x, #x } |
| 1494 | static const wininet_flag_info query_flags[] = { |
| 1495 | FE(HTTP_QUERY_MIME_VERSION), |
| 1496 | FE(HTTP_QUERY_CONTENT_TYPE), |
| 1497 | FE(HTTP_QUERY_CONTENT_TRANSFER_ENCODING), |
| 1498 | FE(HTTP_QUERY_CONTENT_ID), |
| 1499 | FE(HTTP_QUERY_CONTENT_DESCRIPTION), |
| 1500 | FE(HTTP_QUERY_CONTENT_LENGTH), |
| 1501 | FE(HTTP_QUERY_CONTENT_LANGUAGE), |
| 1502 | FE(HTTP_QUERY_ALLOW), |
| 1503 | FE(HTTP_QUERY_PUBLIC), |
| 1504 | FE(HTTP_QUERY_DATE), |
| 1505 | FE(HTTP_QUERY_EXPIRES), |
| 1506 | FE(HTTP_QUERY_LAST_MODIFIED), |
| 1507 | FE(HTTP_QUERY_MESSAGE_ID), |
| 1508 | FE(HTTP_QUERY_URI), |
| 1509 | FE(HTTP_QUERY_DERIVED_FROM), |
| 1510 | FE(HTTP_QUERY_COST), |
| 1511 | FE(HTTP_QUERY_LINK), |
| 1512 | FE(HTTP_QUERY_PRAGMA), |
| 1513 | FE(HTTP_QUERY_VERSION), |
| 1514 | FE(HTTP_QUERY_STATUS_CODE), |
| 1515 | FE(HTTP_QUERY_STATUS_TEXT), |
| 1516 | FE(HTTP_QUERY_RAW_HEADERS), |
| 1517 | FE(HTTP_QUERY_RAW_HEADERS_CRLF), |
| 1518 | FE(HTTP_QUERY_CONNECTION), |
| 1519 | FE(HTTP_QUERY_ACCEPT), |
| 1520 | FE(HTTP_QUERY_ACCEPT_CHARSET), |
| 1521 | FE(HTTP_QUERY_ACCEPT_ENCODING), |
| 1522 | FE(HTTP_QUERY_ACCEPT_LANGUAGE), |
| 1523 | FE(HTTP_QUERY_AUTHORIZATION), |
| 1524 | FE(HTTP_QUERY_CONTENT_ENCODING), |
| 1525 | FE(HTTP_QUERY_FORWARDED), |
| 1526 | FE(HTTP_QUERY_FROM), |
| 1527 | FE(HTTP_QUERY_IF_MODIFIED_SINCE), |
| 1528 | FE(HTTP_QUERY_LOCATION), |
| 1529 | FE(HTTP_QUERY_ORIG_URI), |
| 1530 | FE(HTTP_QUERY_REFERER), |
| 1531 | FE(HTTP_QUERY_RETRY_AFTER), |
| 1532 | FE(HTTP_QUERY_SERVER), |
| 1533 | FE(HTTP_QUERY_TITLE), |
| 1534 | FE(HTTP_QUERY_USER_AGENT), |
| 1535 | FE(HTTP_QUERY_WWW_AUTHENTICATE), |
| 1536 | FE(HTTP_QUERY_PROXY_AUTHENTICATE), |
| 1537 | FE(HTTP_QUERY_ACCEPT_RANGES), |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 1538 | FE(HTTP_QUERY_SET_COOKIE), |
| 1539 | FE(HTTP_QUERY_COOKIE), |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1540 | FE(HTTP_QUERY_REQUEST_METHOD), |
| 1541 | FE(HTTP_QUERY_REFRESH), |
| 1542 | FE(HTTP_QUERY_CONTENT_DISPOSITION), |
| 1543 | FE(HTTP_QUERY_AGE), |
| 1544 | FE(HTTP_QUERY_CACHE_CONTROL), |
| 1545 | FE(HTTP_QUERY_CONTENT_BASE), |
| 1546 | FE(HTTP_QUERY_CONTENT_LOCATION), |
| 1547 | FE(HTTP_QUERY_CONTENT_MD5), |
| 1548 | FE(HTTP_QUERY_CONTENT_RANGE), |
| 1549 | FE(HTTP_QUERY_ETAG), |
| 1550 | FE(HTTP_QUERY_HOST), |
| 1551 | FE(HTTP_QUERY_IF_MATCH), |
| 1552 | FE(HTTP_QUERY_IF_NONE_MATCH), |
| 1553 | FE(HTTP_QUERY_IF_RANGE), |
| 1554 | FE(HTTP_QUERY_IF_UNMODIFIED_SINCE), |
| 1555 | FE(HTTP_QUERY_MAX_FORWARDS), |
| 1556 | FE(HTTP_QUERY_PROXY_AUTHORIZATION), |
| 1557 | FE(HTTP_QUERY_RANGE), |
| 1558 | FE(HTTP_QUERY_TRANSFER_ENCODING), |
| 1559 | FE(HTTP_QUERY_UPGRADE), |
| 1560 | FE(HTTP_QUERY_VARY), |
| 1561 | FE(HTTP_QUERY_VIA), |
| 1562 | FE(HTTP_QUERY_WARNING), |
| 1563 | FE(HTTP_QUERY_CUSTOM) |
| 1564 | }; |
| 1565 | static const wininet_flag_info modifier_flags[] = { |
| 1566 | FE(HTTP_QUERY_FLAG_REQUEST_HEADERS), |
| 1567 | FE(HTTP_QUERY_FLAG_SYSTEMTIME), |
| 1568 | FE(HTTP_QUERY_FLAG_NUMBER), |
| 1569 | FE(HTTP_QUERY_FLAG_COALESCE) |
| 1570 | }; |
| 1571 | #undef FE |
| 1572 | DWORD info_mod = dwInfoLevel & HTTP_QUERY_MODIFIER_FLAGS_MASK; |
| 1573 | DWORD info = dwInfoLevel & HTTP_QUERY_HEADER_MASK; |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 1574 | DWORD i; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1575 | |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1576 | TRACE("(%p, 0x%08lx)--> %ld\n", hHttpRequest, dwInfoLevel, dwInfoLevel); |
| 1577 | TRACE(" Attribute:"); |
| 1578 | for (i = 0; i < (sizeof(query_flags) / sizeof(query_flags[0])); i++) { |
| 1579 | if (query_flags[i].val == info) { |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 1580 | TRACE(" %s", query_flags[i].name); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1581 | break; |
| 1582 | } |
| 1583 | } |
| 1584 | if (i == (sizeof(query_flags) / sizeof(query_flags[0]))) { |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 1585 | TRACE(" Unknown (%08lx)", info); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1586 | } |
| 1587 | |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 1588 | TRACE(" Modifier:"); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1589 | for (i = 0; i < (sizeof(modifier_flags) / sizeof(modifier_flags[0])); i++) { |
| 1590 | if (modifier_flags[i].val & info_mod) { |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 1591 | TRACE(" %s", modifier_flags[i].name); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1592 | info_mod &= ~ modifier_flags[i].val; |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | if (info_mod) { |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 1597 | TRACE(" Unknown (%08lx)", info_mod); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1598 | } |
Diego Pettenò | 869a66a | 2005-01-07 17:09:39 +0000 | [diff] [blame] | 1599 | TRACE("\n"); |
Lionel Ulmer | 1d5e6b6 | 2004-02-09 22:01:49 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1602 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1603 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 1604 | { |
| 1605 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1606 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 1609 | bSuccess = HTTP_HttpQueryInfoW( lpwhr, dwInfoLevel, |
| 1610 | lpBuffer, lpdwBufferLength, lpdwIndex); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1611 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1612 | lend: |
| 1613 | if( lpwhr ) |
| 1614 | WININET_Release( &lpwhr->hdr ); |
| 1615 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1616 | TRACE("%d <--\n", bSuccess); |
| 1617 | return bSuccess; |
| 1618 | } |
| 1619 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1620 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1621 | * HttpQueryInfoA (WININET.@) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1622 | * |
| 1623 | * Queries for information about an HTTP request |
| 1624 | * |
| 1625 | * RETURNS |
| 1626 | * TRUE on success |
| 1627 | * FALSE on failure |
| 1628 | * |
| 1629 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1630 | BOOL WINAPI HttpQueryInfoA(HINTERNET hHttpRequest, DWORD dwInfoLevel, |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1631 | LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex) |
| 1632 | { |
| 1633 | BOOL result; |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 1634 | DWORD len; |
| 1635 | WCHAR* bufferW; |
| 1636 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1637 | if((dwInfoLevel & HTTP_QUERY_FLAG_NUMBER) || |
| 1638 | (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME)) |
| 1639 | { |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 1640 | return HttpQueryInfoW( hHttpRequest, dwInfoLevel, lpBuffer, |
| 1641 | lpdwBufferLength, lpdwIndex ); |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1642 | } |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 1643 | |
| 1644 | len = (*lpdwBufferLength)*sizeof(WCHAR); |
| 1645 | bufferW = HeapAlloc( GetProcessHeap(), 0, len ); |
Aric Stewart | 7bca41a | 2005-12-08 12:44:45 +0100 | [diff] [blame] | 1646 | /* buffer is in/out because of HTTP_QUERY_CUSTOM */ |
| 1647 | if ((dwInfoLevel & HTTP_QUERY_HEADER_MASK) == HTTP_QUERY_CUSTOM) |
| 1648 | MultiByteToWideChar(CP_ACP,0,lpBuffer,-1,bufferW,len); |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 1649 | result = HttpQueryInfoW( hHttpRequest, dwInfoLevel, bufferW, |
| 1650 | &len, lpdwIndex ); |
| 1651 | if( result ) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1652 | { |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 1653 | len = WideCharToMultiByte( CP_ACP,0, bufferW, len / sizeof(WCHAR) + 1, |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 1654 | lpBuffer, *lpdwBufferLength, NULL, NULL ); |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 1655 | *lpdwBufferLength = len - 1; |
| 1656 | |
| 1657 | TRACE("lpBuffer: %s\n", debugstr_a(lpBuffer)); |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1658 | } |
Robert Shearman | 907ac44 | 2004-07-20 01:21:08 +0000 | [diff] [blame] | 1659 | else |
| 1660 | /* since the strings being returned from HttpQueryInfoW should be |
| 1661 | * only ASCII characters, it is reasonable to assume that all of |
| 1662 | * the Unicode characters can be reduced to a single byte */ |
| 1663 | *lpdwBufferLength = len / sizeof(WCHAR); |
Robert Shearman | 4385d30 | 2004-07-21 21:17:03 +0000 | [diff] [blame] | 1664 | |
Mike McCormack | 1baf39f | 2004-03-30 20:37:49 +0000 | [diff] [blame] | 1665 | HeapFree(GetProcessHeap(), 0, bufferW ); |
| 1666 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1667 | return result; |
| 1668 | } |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 1669 | |
| 1670 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 1671 | * HttpSendRequestExA (WININET.@) |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 1672 | * |
| 1673 | * Sends the specified request to the HTTP server and allows chunked |
Robert Shearman | 7a2357a | 2006-02-14 11:34:14 +0100 | [diff] [blame] | 1674 | * transfers. |
| 1675 | * |
| 1676 | * RETURNS |
| 1677 | * Success: TRUE |
| 1678 | * Failure: FALSE, call GetLastError() for more information. |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 1679 | */ |
| 1680 | BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest, |
| 1681 | LPINTERNET_BUFFERSA lpBuffersIn, |
| 1682 | LPINTERNET_BUFFERSA lpBuffersOut, |
| 1683 | DWORD dwFlags, DWORD dwContext) |
| 1684 | { |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 1685 | INTERNET_BUFFERSW BuffersInW; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1686 | BOOL rc = FALSE; |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 1687 | DWORD headerlen; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1688 | |
| 1689 | TRACE("(%p, %p, %p, %08lx, %08lx): stub\n", hRequest, lpBuffersIn, |
| 1690 | lpBuffersOut, dwFlags, dwContext); |
| 1691 | |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 1692 | if (lpBuffersIn) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1693 | { |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 1694 | BuffersInW.dwStructSize = sizeof(LPINTERNET_BUFFERSW); |
| 1695 | if (lpBuffersIn->lpcszHeader) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1696 | { |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 1697 | headerlen = MultiByteToWideChar(CP_ACP,0,lpBuffersIn->lpcszHeader, |
| 1698 | lpBuffersIn->dwHeadersLength,0,0); |
| 1699 | BuffersInW.lpcszHeader = HeapAlloc(GetProcessHeap(),0,headerlen* |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1700 | sizeof(WCHAR)); |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 1701 | if (!BuffersInW.lpcszHeader) |
| 1702 | { |
| 1703 | SetLastError(ERROR_OUTOFMEMORY); |
| 1704 | return FALSE; |
| 1705 | } |
| 1706 | BuffersInW.dwHeadersLength = MultiByteToWideChar(CP_ACP, 0, |
| 1707 | lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength, |
| 1708 | (LPWSTR)BuffersInW.lpcszHeader, headerlen); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1709 | } |
Aric Stewart | d30cec7 | 2005-12-08 11:54:24 +0100 | [diff] [blame] | 1710 | else |
| 1711 | BuffersInW.lpcszHeader = NULL; |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 1712 | BuffersInW.dwHeadersTotal = lpBuffersIn->dwHeadersTotal; |
| 1713 | BuffersInW.lpvBuffer = lpBuffersIn->lpvBuffer; |
| 1714 | BuffersInW.dwBufferLength = lpBuffersIn->dwBufferLength; |
| 1715 | BuffersInW.dwBufferTotal = lpBuffersIn->dwBufferTotal; |
| 1716 | BuffersInW.Next = NULL; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Robert Shearman | 4350357 | 2005-11-29 11:42:23 +0100 | [diff] [blame] | 1719 | rc = HttpSendRequestExW(hRequest, lpBuffersIn ? &BuffersInW : NULL, NULL, dwFlags, dwContext); |
| 1720 | |
| 1721 | if (lpBuffersIn) |
| 1722 | HeapFree(GetProcessHeap(),0,(LPVOID)BuffersInW.lpcszHeader); |
| 1723 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1724 | return rc; |
Huw D M Davies | f9b6d7b | 2000-10-28 00:30:23 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1727 | /*********************************************************************** |
Hans Leidekker | 6a367db | 2005-02-01 18:50:53 +0000 | [diff] [blame] | 1728 | * HttpSendRequestExW (WININET.@) |
| 1729 | * |
| 1730 | * Sends the specified request to the HTTP server and allows chunked |
| 1731 | * transfers |
Robert Shearman | 7a2357a | 2006-02-14 11:34:14 +0100 | [diff] [blame] | 1732 | * |
| 1733 | * RETURNS |
| 1734 | * Success: TRUE |
| 1735 | * Failure: FALSE, call GetLastError() for more information. |
Hans Leidekker | 6a367db | 2005-02-01 18:50:53 +0000 | [diff] [blame] | 1736 | */ |
| 1737 | BOOL WINAPI HttpSendRequestExW(HINTERNET hRequest, |
| 1738 | LPINTERNET_BUFFERSW lpBuffersIn, |
| 1739 | LPINTERNET_BUFFERSW lpBuffersOut, |
| 1740 | DWORD dwFlags, DWORD dwContext) |
| 1741 | { |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1742 | BOOL ret; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1743 | LPWININETHTTPREQW lpwhr; |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1744 | LPWININETHTTPSESSIONW lpwhs; |
| 1745 | LPWININETAPPINFOW hIC; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1746 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1747 | TRACE("(%p, %p, %p, %08lx, %08lx)\n", hRequest, lpBuffersIn, |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1748 | lpBuffersOut, dwFlags, dwContext); |
| 1749 | |
| 1750 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hRequest ); |
| 1751 | |
| 1752 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 1753 | { |
| 1754 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
| 1755 | return FALSE; |
| 1756 | } |
| 1757 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1758 | lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent; |
| 1759 | assert(lpwhs->hdr.htype == WH_HHTTPSESSION); |
| 1760 | hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent; |
| 1761 | assert(hIC->hdr.htype == WH_HINIT); |
| 1762 | |
| 1763 | if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1764 | { |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1765 | WORKREQUEST workRequest; |
| 1766 | struct WORKREQ_HTTPSENDREQUESTW *req; |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1767 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1768 | workRequest.asyncall = HTTPSENDREQUESTW; |
| 1769 | workRequest.hdr = WININET_AddRef( &lpwhr->hdr ); |
| 1770 | req = &workRequest.u.HttpSendRequestW; |
Aric Stewart | 21712d3 | 2006-01-13 13:52:38 +0100 | [diff] [blame] | 1771 | if (lpBuffersIn) |
| 1772 | { |
| 1773 | if (lpBuffersIn->lpcszHeader) |
| 1774 | /* FIXME: this should use dwHeadersLength or may not be necessary at all */ |
| 1775 | req->lpszHeader = WININET_strdupW(lpBuffersIn->lpcszHeader); |
| 1776 | else |
| 1777 | req->lpszHeader = NULL; |
| 1778 | req->dwHeaderLength = lpBuffersIn->dwHeadersLength; |
| 1779 | req->lpOptional = lpBuffersIn->lpvBuffer; |
| 1780 | req->dwOptionalLength = lpBuffersIn->dwBufferLength; |
| 1781 | req->dwContentLength = lpBuffersIn->dwBufferTotal; |
| 1782 | } |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1783 | else |
Aric Stewart | 21712d3 | 2006-01-13 13:52:38 +0100 | [diff] [blame] | 1784 | { |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1785 | req->lpszHeader = NULL; |
Aric Stewart | 21712d3 | 2006-01-13 13:52:38 +0100 | [diff] [blame] | 1786 | req->dwHeaderLength = 0; |
| 1787 | req->lpOptional = NULL; |
| 1788 | req->dwOptionalLength = 0; |
| 1789 | req->dwContentLength = 0; |
| 1790 | } |
| 1791 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1792 | req->bEndRequest = FALSE; |
| 1793 | |
| 1794 | INTERNET_AsyncCall(&workRequest); |
| 1795 | /* |
| 1796 | * This is from windows. |
| 1797 | */ |
| 1798 | SetLastError(ERROR_IO_PENDING); |
| 1799 | ret = FALSE; |
| 1800 | } |
| 1801 | else |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1802 | { |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1803 | ret = HTTP_HttpSendRequestW(lpwhr, lpBuffersIn->lpcszHeader, lpBuffersIn->dwHeadersLength, |
| 1804 | lpBuffersIn->lpvBuffer, lpBuffersIn->dwBufferLength, |
| 1805 | lpBuffersIn->dwBufferTotal, FALSE); |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1806 | } |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1807 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 1808 | WININET_Release(&lpwhr->hdr); |
| 1809 | TRACE("<---\n"); |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1810 | return ret; |
Hans Leidekker | 6a367db | 2005-02-01 18:50:53 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /*********************************************************************** |
Dimitrie O. Paun | f3b681a | 2004-06-28 20:28:38 +0000 | [diff] [blame] | 1814 | * HttpSendRequestW (WININET.@) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1815 | * |
| 1816 | * Sends the specified request to the HTTP server |
| 1817 | * |
| 1818 | * RETURNS |
| 1819 | * TRUE on success |
| 1820 | * FALSE on failure |
| 1821 | * |
| 1822 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1823 | BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders, |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1824 | DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength) |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1825 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1826 | LPWININETHTTPREQW lpwhr; |
| 1827 | LPWININETHTTPSESSIONW lpwhs = NULL; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 1828 | LPWININETAPPINFOW hIC = NULL; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1829 | BOOL r; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1830 | |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 1831 | TRACE("%p, %p (%s), %li, %p, %li)\n", hHttpRequest, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1832 | lpszHeaders, debugstr_w(lpszHeaders), dwHeaderLength, lpOptional, dwOptionalLength); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1833 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1834 | lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hHttpRequest ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1835 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 1836 | { |
| 1837 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1838 | r = FALSE; |
| 1839 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1842 | lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1843 | if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION) |
| 1844 | { |
| 1845 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1846 | r = FALSE; |
| 1847 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 1850 | hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1851 | if (NULL == hIC || hIC->hdr.htype != WH_HINIT) |
| 1852 | { |
| 1853 | INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1854 | r = FALSE; |
| 1855 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) |
| 1859 | { |
| 1860 | WORKREQUEST workRequest; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1861 | struct WORKREQ_HTTPSENDREQUESTW *req; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1862 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1863 | workRequest.asyncall = HTTPSENDREQUESTW; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1864 | workRequest.hdr = WININET_AddRef( &lpwhr->hdr ); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1865 | req = &workRequest.u.HttpSendRequestW; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1866 | if (lpszHeaders) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1867 | req->lpszHeader = WININET_strdupW(lpszHeaders); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1868 | else |
Mike McCormack | b8921a2 | 2003-09-25 20:25:22 +0000 | [diff] [blame] | 1869 | req->lpszHeader = 0; |
| 1870 | req->dwHeaderLength = dwHeaderLength; |
| 1871 | req->lpOptional = lpOptional; |
| 1872 | req->dwOptionalLength = dwOptionalLength; |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1873 | req->dwContentLength = dwOptionalLength; |
| 1874 | req->bEndRequest = TRUE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1875 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1876 | INTERNET_AsyncCall(&workRequest); |
| 1877 | /* |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1878 | * This is from windows. |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 1879 | */ |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1880 | SetLastError(ERROR_IO_PENDING); |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1881 | r = FALSE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1882 | } |
| 1883 | else |
| 1884 | { |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1885 | r = HTTP_HttpSendRequestW(lpwhr, lpszHeaders, |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1886 | dwHeaderLength, lpOptional, dwOptionalLength, |
| 1887 | dwOptionalLength, TRUE); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1888 | } |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 1889 | lend: |
| 1890 | if( lpwhr ) |
| 1891 | WININET_Release( &lpwhr->hdr ); |
| 1892 | return r; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1895 | /*********************************************************************** |
Dimitrie O. Paun | f3b681a | 2004-06-28 20:28:38 +0000 | [diff] [blame] | 1896 | * HttpSendRequestA (WININET.@) |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1897 | * |
| 1898 | * Sends the specified request to the HTTP server |
| 1899 | * |
| 1900 | * RETURNS |
| 1901 | * TRUE on success |
| 1902 | * FALSE on failure |
| 1903 | * |
| 1904 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1905 | BOOL WINAPI HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders, |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1906 | DWORD dwHeaderLength, LPVOID lpOptional ,DWORD dwOptionalLength) |
| 1907 | { |
| 1908 | BOOL result; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1909 | LPWSTR szHeaders=NULL; |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1910 | DWORD nLen=dwHeaderLength; |
| 1911 | if(lpszHeaders!=NULL) |
| 1912 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1913 | nLen=MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,NULL,0); |
| 1914 | szHeaders=HeapAlloc(GetProcessHeap(),0,nLen*sizeof(WCHAR)); |
| 1915 | MultiByteToWideChar(CP_ACP,0,lpszHeaders,dwHeaderLength,szHeaders,nLen); |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1916 | } |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1917 | result=HttpSendRequestW(hHttpRequest, szHeaders, nLen, lpOptional, dwOptionalLength); |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 1918 | HeapFree(GetProcessHeap(),0,szHeaders); |
Alberto Massari | d476a5a | 2002-11-12 02:13:04 +0000 | [diff] [blame] | 1919 | return result; |
| 1920 | } |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 1921 | |
| 1922 | /*********************************************************************** |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1923 | * HTTP_HandleRedirect (internal) |
| 1924 | */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1925 | static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl, LPCWSTR lpszHeaders, |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 1926 | DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength, |
| 1927 | DWORD dwContentLength) |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1928 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1929 | LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 1930 | LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1931 | WCHAR path[2048]; |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 1932 | char szaddr[32]; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 1933 | |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1934 | if(lpszUrl[0]=='/') |
| 1935 | { |
| 1936 | /* if it's an absolute path, keep the same session info */ |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 1937 | lstrcpynW(path, lpszUrl, 2048); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1938 | } |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1939 | else if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0) |
| 1940 | { |
| 1941 | TRACE("Redirect through proxy\n"); |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 1942 | lstrcpynW(path, lpszUrl, 2048); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 1943 | } |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 1944 | else |
| 1945 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 1946 | URL_COMPONENTSW urlComponents; |
| 1947 | WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024]; |
Robert Shearman | efac01b | 2005-11-29 11:25:31 +0100 | [diff] [blame] | 1948 | static const WCHAR szHttp[] = {'h','t','t','p',0}; |
| 1949 | static const WCHAR szHttps[] = {'h','t','t','p','s',0}; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 1950 | DWORD url_length = 0; |
| 1951 | LPWSTR orig_url; |
| 1952 | LPWSTR combined_url; |
| 1953 | |
| 1954 | urlComponents.dwStructSize = sizeof(URL_COMPONENTSW); |
| 1955 | urlComponents.lpszScheme = (lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE) ? (LPWSTR)szHttps : (LPWSTR)szHttp; |
| 1956 | urlComponents.dwSchemeLength = 0; |
| 1957 | urlComponents.lpszHostName = lpwhs->lpszHostName; |
| 1958 | urlComponents.dwHostNameLength = 0; |
| 1959 | urlComponents.nPort = lpwhs->nHostPort; |
| 1960 | urlComponents.lpszUserName = lpwhs->lpszUserName; |
| 1961 | urlComponents.dwUserNameLength = 0; |
| 1962 | urlComponents.lpszPassword = NULL; |
| 1963 | urlComponents.dwPasswordLength = 0; |
| 1964 | urlComponents.lpszUrlPath = lpwhr->lpszPath; |
| 1965 | urlComponents.dwUrlPathLength = 0; |
| 1966 | urlComponents.lpszExtraInfo = NULL; |
| 1967 | urlComponents.dwExtraInfoLength = 0; |
| 1968 | |
| 1969 | if (!InternetCreateUrlW(&urlComponents, 0, NULL, &url_length) && |
| 1970 | (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) |
| 1971 | return FALSE; |
| 1972 | |
Robert Shearman | 80e4fb5 | 2006-03-21 13:44:36 +0000 | [diff] [blame] | 1973 | orig_url = HeapAlloc(GetProcessHeap(), 0, url_length); |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 1974 | |
Robert Shearman | 80e4fb5 | 2006-03-21 13:44:36 +0000 | [diff] [blame] | 1975 | /* convert from bytes to characters */ |
| 1976 | url_length = url_length / sizeof(WCHAR) - 1; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 1977 | if (!InternetCreateUrlW(&urlComponents, 0, orig_url, &url_length)) |
| 1978 | { |
| 1979 | HeapFree(GetProcessHeap(), 0, orig_url); |
| 1980 | return FALSE; |
| 1981 | } |
| 1982 | |
| 1983 | url_length = 0; |
| 1984 | if (!InternetCombineUrlW(orig_url, lpszUrl, NULL, &url_length, ICU_ENCODE_SPACES_ONLY) && |
| 1985 | (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) |
| 1986 | { |
| 1987 | HeapFree(GetProcessHeap(), 0, orig_url); |
| 1988 | return FALSE; |
| 1989 | } |
| 1990 | combined_url = HeapAlloc(GetProcessHeap(), 0, url_length * sizeof(WCHAR)); |
| 1991 | |
| 1992 | if (!InternetCombineUrlW(orig_url, lpszUrl, combined_url, &url_length, ICU_ENCODE_SPACES_ONLY)) |
| 1993 | { |
| 1994 | HeapFree(GetProcessHeap(), 0, orig_url); |
| 1995 | HeapFree(GetProcessHeap(), 0, combined_url); |
| 1996 | return FALSE; |
| 1997 | } |
| 1998 | HeapFree(GetProcessHeap(), 0, orig_url); |
| 1999 | |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2000 | userName[0] = 0; |
| 2001 | hostName[0] = 0; |
| 2002 | protocol[0] = 0; |
| 2003 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2004 | urlComponents.dwStructSize = sizeof(URL_COMPONENTSW); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2005 | urlComponents.lpszScheme = protocol; |
| 2006 | urlComponents.dwSchemeLength = 32; |
| 2007 | urlComponents.lpszHostName = hostName; |
| 2008 | urlComponents.dwHostNameLength = MAXHOSTNAME; |
| 2009 | urlComponents.lpszUserName = userName; |
| 2010 | urlComponents.dwUserNameLength = 1024; |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 2011 | urlComponents.lpszPassword = NULL; |
| 2012 | urlComponents.dwPasswordLength = 0; |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2013 | urlComponents.lpszUrlPath = path; |
| 2014 | urlComponents.dwUrlPathLength = 2048; |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 2015 | urlComponents.lpszExtraInfo = NULL; |
| 2016 | urlComponents.dwExtraInfoLength = 0; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2017 | if(!InternetCrackUrlW(combined_url, strlenW(combined_url), 0, &urlComponents)) |
| 2018 | { |
| 2019 | HeapFree(GetProcessHeap(), 0, combined_url); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2020 | return FALSE; |
Robert Shearman | 0590025 | 2006-03-09 15:11:59 +0000 | [diff] [blame] | 2021 | } |
| 2022 | HeapFree(GetProcessHeap(), 0, combined_url); |
Robert Shearman | efac01b | 2005-11-29 11:25:31 +0100 | [diff] [blame] | 2023 | |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 2024 | if (!strncmpW(szHttp, urlComponents.lpszScheme, strlenW(szHttp)) && |
Robert Shearman | efac01b | 2005-11-29 11:25:31 +0100 | [diff] [blame] | 2025 | (lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE)) |
| 2026 | { |
| 2027 | TRACE("redirect from secure page to non-secure page\n"); |
| 2028 | /* FIXME: warn about from secure redirect to non-secure page */ |
| 2029 | lpwhr->hdr.dwFlags &= ~INTERNET_FLAG_SECURE; |
| 2030 | } |
Robert Shearman | dc5f1cb | 2005-11-30 12:01:50 +0100 | [diff] [blame] | 2031 | if (!strncmpW(szHttps, urlComponents.lpszScheme, strlenW(szHttps)) && |
Robert Shearman | efac01b | 2005-11-29 11:25:31 +0100 | [diff] [blame] | 2032 | !(lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE)) |
| 2033 | { |
| 2034 | TRACE("redirect from non-secure page to secure page\n"); |
| 2035 | /* FIXME: notify about redirect to secure page */ |
| 2036 | lpwhr->hdr.dwFlags |= INTERNET_FLAG_SECURE; |
| 2037 | } |
| 2038 | |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2039 | if (urlComponents.nPort == INTERNET_INVALID_PORT_NUMBER) |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2040 | { |
| 2041 | if (lstrlenW(protocol)>4) /*https*/ |
| 2042 | urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT; |
| 2043 | else /*http*/ |
| 2044 | urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT; |
| 2045 | } |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2046 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 2047 | #if 0 |
| 2048 | /* |
| 2049 | * This upsets redirects to binary files on sourceforge.net |
| 2050 | * and gives an html page instead of the target file |
| 2051 | * Examination of the HTTP request sent by native wininet.dll |
| 2052 | * reveals that it doesn't send a referrer in that case. |
| 2053 | * Maybe there's a flag that enables this, or maybe a referrer |
| 2054 | * shouldn't be added in case of a redirect. |
| 2055 | */ |
| 2056 | |
| 2057 | /* consider the current host as the referrer */ |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2058 | if (NULL != lpwhs->lpszServerName && strlenW(lpwhs->lpszServerName)) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 2059 | HTTP_ProcessHeader(lpwhr, HTTP_REFERER, lpwhs->lpszServerName, |
| 2060 | HTTP_ADDHDR_FLAG_REQ|HTTP_ADDREQ_FLAG_REPLACE| |
| 2061 | HTTP_ADDHDR_FLAG_ADD_IF_NEW); |
| 2062 | #endif |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2063 | |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 2064 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); |
Robert Shearman | 8a8ce9c | 2005-11-29 11:35:19 +0100 | [diff] [blame] | 2065 | lpwhs->lpszServerName = WININET_strdupW(hostName); |
| 2066 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszHostName); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2067 | if (urlComponents.nPort != INTERNET_DEFAULT_HTTP_PORT && |
| 2068 | urlComponents.nPort != INTERNET_DEFAULT_HTTPS_PORT) |
| 2069 | { |
| 2070 | int len; |
Andrew Ziem | 7053321 | 2006-05-24 00:22:38 -0600 | [diff] [blame^] | 2071 | static const WCHAR fmt[] = {'%','s',':','%','i',0}; |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2072 | len = lstrlenW(hostName); |
Robert Shearman | 8a8ce9c | 2005-11-29 11:35:19 +0100 | [diff] [blame] | 2073 | len += 7; /* 5 for strlen("65535") + 1 for ":" + 1 for '\0' */ |
| 2074 | lpwhs->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); |
| 2075 | sprintfW(lpwhs->lpszHostName, fmt, hostName, urlComponents.nPort); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2076 | } |
| 2077 | else |
Robert Shearman | 8a8ce9c | 2005-11-29 11:35:19 +0100 | [diff] [blame] | 2078 | lpwhs->lpszHostName = WININET_strdupW(hostName); |
Aric Stewart | 1fc760d | 2005-11-28 17:31:02 +0100 | [diff] [blame] | 2079 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2080 | 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] | 2081 | |
| 2082 | |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 2083 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName); |
Robert Shearman | ef20936 | 2006-03-10 12:28:52 +0000 | [diff] [blame] | 2084 | lpwhs->lpszUserName = NULL; |
| 2085 | if (userName[0]) |
| 2086 | lpwhs->lpszUserName = WININET_strdupW(userName); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2087 | lpwhs->nServerPort = urlComponents.nPort; |
| 2088 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2089 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2090 | INTERNET_STATUS_RESOLVING_NAME, |
| 2091 | lpwhs->lpszServerName, |
| 2092 | strlenW(lpwhs->lpszServerName)+1); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2093 | |
| 2094 | if (!GetAddress(lpwhs->lpszServerName, lpwhs->nServerPort, |
Robert Shearman | e6157dd | 2005-11-15 18:16:55 +0000 | [diff] [blame] | 2095 | &lpwhs->socketAddress)) |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2096 | { |
| 2097 | INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED); |
| 2098 | return FALSE; |
| 2099 | } |
| 2100 | |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 2101 | inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr, |
| 2102 | szaddr, sizeof(szaddr)); |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2103 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2104 | INTERNET_STATUS_NAME_RESOLVED, |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 2105 | szaddr, strlen(szaddr)+1); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2106 | |
Robert Shearman | efac01b | 2005-11-29 11:25:31 +0100 | [diff] [blame] | 2107 | NETCON_close(&lpwhr->netConnection); |
Robert Shearman | 9981f33 | 2006-03-06 17:31:09 +0000 | [diff] [blame] | 2108 | |
| 2109 | if (!NETCON_init(&lpwhr->netConnection,lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE)) |
| 2110 | return FALSE; |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 2113 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2114 | lpwhr->lpszPath=NULL; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2115 | if (strlenW(path)) |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2116 | { |
| 2117 | DWORD needed = 0; |
| 2118 | HRESULT rc; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2119 | |
| 2120 | rc = UrlEscapeW(path, NULL, &needed, URL_ESCAPE_SPACES_ONLY); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2121 | if (rc != E_POINTER) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2122 | needed = strlenW(path)+1; |
| 2123 | lpwhr->lpszPath = HeapAlloc(GetProcessHeap(), 0, needed*sizeof(WCHAR)); |
| 2124 | rc = UrlEscapeW(path, lpwhr->lpszPath, &needed, |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2125 | URL_ESCAPE_SPACES_ONLY); |
| 2126 | if (rc) |
| 2127 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2128 | ERR("Unable to escape string!(%s) (%ld)\n",debugstr_w(path),rc); |
| 2129 | strcpyW(lpwhr->lpszPath,path); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2133 | return HTTP_HttpSendRequestW(lpwhr, lpszHeaders, dwHeaderLength, lpOptional, |
| 2134 | dwOptionalLength, dwContentLength, TRUE); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | /*********************************************************************** |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 2138 | * HTTP_build_req (internal) |
| 2139 | * |
| 2140 | * concatenate all the strings in the request together |
| 2141 | */ |
| 2142 | static LPWSTR HTTP_build_req( LPCWSTR *list, int len ) |
| 2143 | { |
| 2144 | LPCWSTR *t; |
| 2145 | LPWSTR str; |
| 2146 | |
| 2147 | for( t = list; *t ; t++ ) |
| 2148 | len += strlenW( *t ); |
| 2149 | len++; |
| 2150 | |
| 2151 | str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); |
| 2152 | *str = 0; |
| 2153 | |
| 2154 | for( t = list; *t ; t++ ) |
| 2155 | strcatW( str, *t ); |
| 2156 | |
| 2157 | return str; |
| 2158 | } |
| 2159 | |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 2160 | static BOOL HTTP_SecureProxyConnect(LPWININETHTTPREQW lpwhr) |
| 2161 | { |
| 2162 | LPWSTR lpszPath; |
| 2163 | LPWSTR requestString; |
| 2164 | INT len; |
| 2165 | INT cnt; |
| 2166 | INT responseLen; |
| 2167 | char *ascii_req; |
| 2168 | BOOL ret; |
| 2169 | static const WCHAR szConnect[] = {'C','O','N','N','E','C','T',0}; |
| 2170 | static const WCHAR szFormat[] = {'%','s',':','%','d',0}; |
| 2171 | LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW)lpwhr->hdr.lpwhparent; |
| 2172 | |
| 2173 | TRACE("\n"); |
| 2174 | |
| 2175 | lpszPath = HeapAlloc( GetProcessHeap(), 0, (lstrlenW( lpwhs->lpszHostName ) + 13)*sizeof(WCHAR) ); |
| 2176 | sprintfW( lpszPath, szFormat, lpwhs->lpszHostName, lpwhs->nHostPort ); |
| 2177 | requestString = HTTP_BuildHeaderRequestString( lpwhr, szConnect, lpszPath, FALSE ); |
| 2178 | HeapFree( GetProcessHeap(), 0, lpszPath ); |
| 2179 | |
| 2180 | len = WideCharToMultiByte( CP_ACP, 0, requestString, -1, |
| 2181 | NULL, 0, NULL, NULL ); |
| 2182 | len--; /* the nul terminator isn't needed */ |
| 2183 | ascii_req = HeapAlloc( GetProcessHeap(), 0, len ); |
| 2184 | WideCharToMultiByte( CP_ACP, 0, requestString, -1, |
| 2185 | ascii_req, len, NULL, NULL ); |
| 2186 | HeapFree( GetProcessHeap(), 0, requestString ); |
| 2187 | |
| 2188 | TRACE("full request -> %s\n", debugstr_an( ascii_req, len ) ); |
| 2189 | |
| 2190 | ret = NETCON_send( &lpwhr->netConnection, ascii_req, len, 0, &cnt ); |
| 2191 | HeapFree( GetProcessHeap(), 0, ascii_req ); |
| 2192 | if (!ret || cnt < 0) |
| 2193 | return FALSE; |
| 2194 | |
| 2195 | responseLen = HTTP_GetResponseHeaders( lpwhr ); |
| 2196 | if (!responseLen) |
| 2197 | return FALSE; |
| 2198 | |
| 2199 | return TRUE; |
| 2200 | } |
| 2201 | |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 2202 | /*********************************************************************** |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2203 | * HTTP_HttpSendRequestW (internal) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2204 | * |
| 2205 | * Sends the specified request to the HTTP server |
| 2206 | * |
| 2207 | * RETURNS |
| 2208 | * TRUE on success |
| 2209 | * FALSE on failure |
| 2210 | * |
| 2211 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2212 | BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders, |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2213 | DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength, |
| 2214 | DWORD dwContentLength, BOOL bEndRequest) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2215 | { |
| 2216 | INT cnt; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2217 | BOOL bSuccess = FALSE; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2218 | LPWSTR requestString = NULL; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2219 | INT responseLen; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2220 | BOOL loop_next = FALSE; |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 2221 | INTERNET_ASYNC_RESULT iar; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2222 | LPHTTPHEADERW Host; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2223 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2224 | TRACE("--> %p\n", lpwhr); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2225 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2226 | assert(lpwhr->hdr.htype == WH_HHTTPREQ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2227 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2228 | /* Clear any error information */ |
| 2229 | INTERNET_SetLastError(0); |
| 2230 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2231 | HTTP_FixVerb(lpwhr); |
| 2232 | |
David Hammerton | 6226f3f | 2003-08-05 18:31:02 +0000 | [diff] [blame] | 2233 | /* if we are using optional stuff, we must add the fixed header of that option length */ |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2234 | if (dwContentLength > 0) |
David Hammerton | 6226f3f | 2003-08-05 18:31:02 +0000 | [diff] [blame] | 2235 | { |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2236 | static const WCHAR szContentLength[] = { |
| 2237 | 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','l','i','\r','\n',0}; |
| 2238 | WCHAR contentLengthStr[sizeof szContentLength/2 /* includes \n\r */ + 20 /* int */ ]; |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2239 | sprintfW(contentLengthStr, szContentLength, dwContentLength); |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2240 | HTTP_HttpAddRequestHeadersW(lpwhr, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD); |
David Hammerton | 6226f3f | 2003-08-05 18:31:02 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2243 | Host = HTTP_GetHeader(lpwhr,szHost); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2244 | do |
Nikolas Zimmermann | 7659882 | 2001-10-04 18:12:41 +0000 | [diff] [blame] | 2245 | { |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2246 | DWORD len; |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 2247 | char *ascii_req; |
| 2248 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2249 | TRACE("Going to url %s %s\n", debugstr_w(Host->lpszValue), debugstr_w(lpwhr->lpszPath)); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2250 | loop_next = FALSE; |
Nikolas Zimmermann | 7659882 | 2001-10-04 18:12:41 +0000 | [diff] [blame] | 2251 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2252 | HTTP_FixURL(lpwhr); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2253 | |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 2254 | /* add the headers the caller supplied */ |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 2255 | if( lpszHeaders && dwHeaderLength ) |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 2256 | { |
Mike McCormack | 08c6c69 | 2004-08-10 23:41:35 +0000 | [diff] [blame] | 2257 | HTTP_HttpAddRequestHeadersW(lpwhr, lpszHeaders, dwHeaderLength, |
| 2258 | HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE); |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
Aric Stewart | be918f4 | 2005-11-21 15:17:55 +0000 | [diff] [blame] | 2261 | /* if there's a proxy username and password, add it to the headers */ |
| 2262 | HTTP_AddProxyInfo(lpwhr); |
Mike McCormack | c72d956 | 2004-12-06 11:40:57 +0000 | [diff] [blame] | 2263 | |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 2264 | requestString = HTTP_BuildHeaderRequestString(lpwhr, lpwhr->lpszVerb, lpwhr->lpszPath, FALSE); |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 2265 | |
| 2266 | TRACE("Request header -> %s\n", debugstr_w(requestString) ); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2267 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2268 | /* Send the request and store the results */ |
| 2269 | if (!HTTP_OpenConnection(lpwhr)) |
| 2270 | goto lend; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2271 | |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 2272 | /* send the request as ASCII, tack on the optional data */ |
| 2273 | if( !lpOptional ) |
| 2274 | dwOptionalLength = 0; |
| 2275 | len = WideCharToMultiByte( CP_ACP, 0, requestString, -1, |
| 2276 | NULL, 0, NULL, NULL ); |
| 2277 | ascii_req = HeapAlloc( GetProcessHeap(), 0, len + dwOptionalLength ); |
| 2278 | WideCharToMultiByte( CP_ACP, 0, requestString, -1, |
| 2279 | ascii_req, len, NULL, NULL ); |
| 2280 | if( lpOptional ) |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 2281 | memcpy( &ascii_req[len-1], lpOptional, dwOptionalLength ); |
| 2282 | len = (len + dwOptionalLength - 1); |
| 2283 | ascii_req[len] = 0; |
Aric Stewart | 44cbdf2 | 2005-10-19 18:28:35 +0000 | [diff] [blame] | 2284 | TRACE("full request -> %s\n", debugstr_a(ascii_req) ); |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 2285 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2286 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2287 | INTERNET_STATUS_SENDING_REQUEST, NULL, 0); |
Mike McCormack | f1d7b14 | 2004-07-21 19:36:34 +0000 | [diff] [blame] | 2288 | |
Mike McCormack | a496906 | 2004-07-04 00:24:47 +0000 | [diff] [blame] | 2289 | NETCON_send(&lpwhr->netConnection, ascii_req, len, 0, &cnt); |
| 2290 | HeapFree( GetProcessHeap(), 0, ascii_req ); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2291 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2292 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2293 | INTERNET_STATUS_REQUEST_SENT, |
| 2294 | &len, sizeof(DWORD)); |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2295 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2296 | if (bEndRequest) |
| 2297 | { |
| 2298 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2299 | INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0); |
| 2300 | |
| 2301 | if (cnt < 0) |
| 2302 | goto lend; |
| 2303 | |
| 2304 | responseLen = HTTP_GetResponseHeaders(lpwhr); |
| 2305 | if (responseLen) |
| 2306 | bSuccess = TRUE; |
| 2307 | |
| 2308 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2309 | INTERNET_STATUS_RESPONSE_RECEIVED, &responseLen, |
| 2310 | sizeof(DWORD)); |
| 2311 | |
| 2312 | HTTP_ProcessHeaders(lpwhr); |
| 2313 | } |
| 2314 | else |
| 2315 | bSuccess = TRUE; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2316 | } |
| 2317 | while (loop_next); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2318 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2319 | lend: |
| 2320 | |
Michael Stefaniuc | 7cb43c9 | 2004-12-21 14:42:35 +0000 | [diff] [blame] | 2321 | HeapFree(GetProcessHeap(), 0, requestString); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2322 | |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2323 | /* TODO: send notification for P3P header */ |
| 2324 | |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2325 | if(!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT) && bSuccess && bEndRequest) |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2326 | { |
| 2327 | DWORD dwCode,dwCodeLength=sizeof(DWORD),dwIndex=0; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2328 | if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,&dwCode,&dwCodeLength,&dwIndex) && |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2329 | (dwCode==302 || dwCode==301)) |
| 2330 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2331 | WCHAR szNewLocation[2048]; |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2332 | DWORD dwBufferSize=2048; |
| 2333 | dwIndex=0; |
Mike McCormack | b288f71 | 2004-06-14 17:57:26 +0000 | [diff] [blame] | 2334 | if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,&dwIndex)) |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2335 | { |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2336 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2337 | INTERNET_STATUS_REDIRECT, szNewLocation, |
| 2338 | dwBufferSize); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2339 | return HTTP_HandleRedirect(lpwhr, szNewLocation, lpszHeaders, |
Robert Shearman | f6252cf | 2005-11-30 12:31:22 +0100 | [diff] [blame] | 2340 | dwHeaderLength, lpOptional, dwOptionalLength, |
| 2341 | dwContentLength); |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2342 | } |
| 2343 | } |
| 2344 | } |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2345 | |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 2346 | |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 2347 | iar.dwResult = (DWORD)bSuccess; |
| 2348 | iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError(); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2349 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2350 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2351 | INTERNET_STATUS_REQUEST_COMPLETE, &iar, |
| 2352 | sizeof(INTERNET_ASYNC_RESULT)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2353 | |
| 2354 | TRACE("<--\n"); |
| 2355 | return bSuccess; |
| 2356 | } |
| 2357 | |
| 2358 | |
| 2359 | /*********************************************************************** |
| 2360 | * HTTP_Connect (internal) |
| 2361 | * |
| 2362 | * Create http session handle |
| 2363 | * |
| 2364 | * RETURNS |
| 2365 | * HINTERNET a session handle on success |
| 2366 | * NULL on failure |
| 2367 | * |
| 2368 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2369 | HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2370 | INTERNET_PORT nServerPort, LPCWSTR lpszUserName, |
Kevin Koltzau | 917df92 | 2004-05-13 05:17:25 +0000 | [diff] [blame] | 2371 | LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext, |
| 2372 | DWORD dwInternalFlags) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2373 | { |
| 2374 | BOOL bSuccess = FALSE; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2375 | LPWININETHTTPSESSIONW lpwhs = NULL; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 2376 | HINTERNET handle = NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2377 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2378 | TRACE("-->\n"); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2379 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2380 | assert( hIC->hdr.htype == WH_HINIT ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2381 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2382 | hIC->hdr.dwContext = dwContext; |
Dominik Strasser | 94c02fe | 2003-04-14 21:32:36 +0000 | [diff] [blame] | 2383 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2384 | lpwhs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETHTTPSESSIONW)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2385 | if (NULL == lpwhs) |
| 2386 | { |
| 2387 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
| 2388 | goto lerror; |
| 2389 | } |
| 2390 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2391 | /* |
| 2392 | * According to my tests. The name is not resolved until a request is sent |
| 2393 | */ |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2394 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2395 | lpwhs->hdr.htype = WH_HHTTPSESSION; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2396 | lpwhs->hdr.lpwhparent = WININET_AddRef( &hIC->hdr ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2397 | lpwhs->hdr.dwFlags = dwFlags; |
| 2398 | lpwhs->hdr.dwContext = dwContext; |
Kevin Koltzau | 917df92 | 2004-05-13 05:17:25 +0000 | [diff] [blame] | 2399 | lpwhs->hdr.dwInternalFlags = dwInternalFlags; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2400 | lpwhs->hdr.dwRefCount = 1; |
| 2401 | lpwhs->hdr.destroy = HTTP_CloseHTTPSessionHandle; |
Robert Shearman | ed517f3 | 2004-09-20 19:10:31 +0000 | [diff] [blame] | 2402 | lpwhs->hdr.lpfnStatusCB = hIC->hdr.lpfnStatusCB; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2403 | |
| 2404 | handle = WININET_AllocHandle( &lpwhs->hdr ); |
| 2405 | if (NULL == handle) |
| 2406 | { |
| 2407 | ERR("Failed to alloc handle\n"); |
| 2408 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
| 2409 | goto lerror; |
| 2410 | } |
| 2411 | |
Dominik Strasser | 94c02fe | 2003-04-14 21:32:36 +0000 | [diff] [blame] | 2412 | if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) { |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 2413 | if(strchrW(hIC->lpszProxy, ' ')) |
Dominik Strasser | 94c02fe | 2003-04-14 21:32:36 +0000 | [diff] [blame] | 2414 | FIXME("Several proxies not implemented.\n"); |
| 2415 | if(hIC->lpszProxyBypass) |
| 2416 | FIXME("Proxy bypass is ignored.\n"); |
| 2417 | } |
Robert Shearman | ef20936 | 2006-03-10 12:28:52 +0000 | [diff] [blame] | 2418 | if (lpszServerName && lpszServerName[0]) |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 2419 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2420 | lpwhs->lpszServerName = WININET_strdupW(lpszServerName); |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 2421 | lpwhs->lpszHostName = WININET_strdupW(lpszServerName); |
| 2422 | } |
Robert Shearman | ef20936 | 2006-03-10 12:28:52 +0000 | [diff] [blame] | 2423 | if (lpszUserName && lpszUserName[0]) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2424 | lpwhs->lpszUserName = WININET_strdupW(lpszUserName); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2425 | lpwhs->nServerPort = nServerPort; |
Robert Shearman | 3592110 | 2005-11-28 11:53:05 +0100 | [diff] [blame] | 2426 | lpwhs->nHostPort = nServerPort; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2427 | |
Kevin Koltzau | 917df92 | 2004-05-13 05:17:25 +0000 | [diff] [blame] | 2428 | /* 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] | 2429 | if (!(lpwhs->hdr.dwInternalFlags & INET_OPENURL)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2430 | { |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2431 | INTERNET_SendCallback(&hIC->hdr, dwContext, |
| 2432 | INTERNET_STATUS_HANDLE_CREATED, &handle, |
| 2433 | sizeof(handle)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | bSuccess = TRUE; |
| 2437 | |
| 2438 | lerror: |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2439 | if( lpwhs ) |
| 2440 | WININET_Release( &lpwhs->hdr ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2441 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2442 | /* |
Francois Gouget | 93416cd | 2005-03-23 13:15:18 +0000 | [diff] [blame] | 2443 | * 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] | 2444 | * windows |
| 2445 | */ |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 2446 | |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2447 | TRACE("%p --> %p (%p)\n", hIC, handle, lpwhs); |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 2448 | return handle; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | |
| 2452 | /*********************************************************************** |
| 2453 | * HTTP_OpenConnection (internal) |
| 2454 | * |
| 2455 | * Connect to a web server |
| 2456 | * |
| 2457 | * RETURNS |
| 2458 | * |
| 2459 | * TRUE on success |
| 2460 | * FALSE on failure |
| 2461 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 2462 | static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2463 | { |
| 2464 | BOOL bSuccess = FALSE; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2465 | LPWININETHTTPSESSIONW lpwhs; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 2466 | LPWININETAPPINFOW hIC = NULL; |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 2467 | char szaddr[32]; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2468 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2469 | TRACE("-->\n"); |
| 2470 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2471 | |
| 2472 | if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ) |
| 2473 | { |
| 2474 | INTERNET_SetLastError(ERROR_INVALID_PARAMETER); |
| 2475 | goto lend; |
| 2476 | } |
| 2477 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2478 | lpwhs = (LPWININETHTTPSESSIONW)lpwhr->hdr.lpwhparent; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2479 | |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 2480 | hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent; |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 2481 | inet_ntop(lpwhs->socketAddress.sin_family, &lpwhs->socketAddress.sin_addr, |
| 2482 | szaddr, sizeof(szaddr)); |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2483 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2484 | INTERNET_STATUS_CONNECTING_TO_SERVER, |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 2485 | szaddr, |
| 2486 | strlen(szaddr)+1); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2487 | |
Robert Shearman | e6157dd | 2005-11-15 18:16:55 +0000 | [diff] [blame] | 2488 | if (!NETCON_create(&lpwhr->netConnection, lpwhs->socketAddress.sin_family, |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2489 | SOCK_STREAM, 0)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2490 | { |
| 2491 | WARN("Socket creation failed\n"); |
| 2492 | goto lend; |
| 2493 | } |
| 2494 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2495 | if (!NETCON_connect(&lpwhr->netConnection, (struct sockaddr *)&lpwhs->socketAddress, |
| 2496 | sizeof(lpwhs->socketAddress))) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2497 | goto lend; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2498 | |
Robert Shearman | 13d371d | 2005-11-28 11:54:31 +0100 | [diff] [blame] | 2499 | if (lpwhr->hdr.dwFlags & INTERNET_FLAG_SECURE) |
| 2500 | { |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 2501 | /* Note: we differ from Microsoft's WinINet here. they seem to have |
| 2502 | * a bug that causes no status callbacks to be sent when starting |
| 2503 | * a tunnel to a proxy server using the CONNECT verb. i believe our |
| 2504 | * behaviour to be more correct and to not cause any incompatibilities |
| 2505 | * because using a secure connection through a proxy server is a rare |
| 2506 | * case that would be hard for anyone to depend on */ |
| 2507 | if (hIC->lpszProxy && !HTTP_SecureProxyConnect(lpwhr)) |
| 2508 | goto lend; |
| 2509 | |
Robert Shearman | 13d371d | 2005-11-28 11:54:31 +0100 | [diff] [blame] | 2510 | if (!NETCON_secure_connect(&lpwhr->netConnection, lpwhs->lpszHostName)) |
| 2511 | { |
| 2512 | WARN("Couldn't connect securely to host\n"); |
| 2513 | goto lend; |
| 2514 | } |
| 2515 | } |
| 2516 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2517 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2518 | INTERNET_STATUS_CONNECTED_TO_SERVER, |
Jacek Caban | ad02317 | 2006-01-05 14:37:06 +0100 | [diff] [blame] | 2519 | szaddr, strlen(szaddr)+1); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2520 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2521 | bSuccess = TRUE; |
| 2522 | |
| 2523 | lend: |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2524 | TRACE("%d <--\n", bSuccess); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2525 | return bSuccess; |
| 2526 | } |
| 2527 | |
| 2528 | |
| 2529 | /*********************************************************************** |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2530 | * HTTP_clear_response_headers (internal) |
| 2531 | * |
| 2532 | * clear out any old response headers |
| 2533 | */ |
| 2534 | static void HTTP_clear_response_headers( LPWININETHTTPREQW lpwhr ) |
| 2535 | { |
| 2536 | DWORD i; |
| 2537 | |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2538 | for( i=0; i<lpwhr->nCustHeaders; i++) |
| 2539 | { |
| 2540 | if( !lpwhr->pCustHeaders[i].lpszField ) |
| 2541 | continue; |
| 2542 | if( !lpwhr->pCustHeaders[i].lpszValue ) |
| 2543 | continue; |
| 2544 | if ( lpwhr->pCustHeaders[i].wFlags & HDR_ISREQUEST ) |
| 2545 | continue; |
Robert Shearman | 7707a76 | 2005-03-10 11:14:24 +0000 | [diff] [blame] | 2546 | HTTP_DeleteCustomHeader( lpwhr, i ); |
| 2547 | i--; |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | /*********************************************************************** |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2552 | * HTTP_GetResponseHeaders (internal) |
| 2553 | * |
| 2554 | * Read server response |
| 2555 | * |
| 2556 | * RETURNS |
| 2557 | * |
| 2558 | * TRUE on success |
| 2559 | * FALSE on error |
| 2560 | */ |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 2561 | static INT HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2562 | { |
| 2563 | INT cbreaks = 0; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2564 | WCHAR buffer[MAX_REPLY_LEN]; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2565 | DWORD buflen = MAX_REPLY_LEN; |
| 2566 | BOOL bSuccess = FALSE; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2567 | INT rc = 0; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2568 | static const WCHAR szCrLf[] = {'\r','\n',0}; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2569 | char bufferA[MAX_REPLY_LEN]; |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2570 | LPWSTR status_code, status_text; |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2571 | DWORD cchMaxRawHeaders = 1024; |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2572 | LPWSTR lpszRawHeaders = HeapAlloc(GetProcessHeap(), 0, (cchMaxRawHeaders+1)*sizeof(WCHAR)); |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2573 | DWORD cchRawHeaders = 0; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2574 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2575 | TRACE("-->\n"); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2576 | |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2577 | /* clear old response headers (eg. from a redirect response) */ |
| 2578 | HTTP_clear_response_headers( lpwhr ); |
| 2579 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2580 | if (!NETCON_connected(&lpwhr->netConnection)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2581 | goto lend; |
| 2582 | |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 2583 | /* |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2584 | * HACK peek at the buffer |
| 2585 | */ |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2586 | NETCON_recv(&lpwhr->netConnection, buffer, buflen, MSG_PEEK, &rc); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2587 | |
| 2588 | /* |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2589 | * We should first receive 'HTTP/1.x nnn OK' where nnn is the status code. |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2590 | */ |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2591 | buflen = MAX_REPLY_LEN; |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2592 | memset(buffer, 0, MAX_REPLY_LEN); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2593 | if (!NETCON_getNextLine(&lpwhr->netConnection, bufferA, &buflen)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2594 | goto lend; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2595 | MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN ); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2596 | |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2597 | /* regenerate raw headers */ |
| 2598 | while (cchRawHeaders + buflen + strlenW(szCrLf) > cchMaxRawHeaders) |
| 2599 | { |
| 2600 | cchMaxRawHeaders *= 2; |
| 2601 | lpszRawHeaders = HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders, (cchMaxRawHeaders+1)*sizeof(WCHAR)); |
| 2602 | } |
| 2603 | memcpy(lpszRawHeaders+cchRawHeaders, buffer, (buflen-1)*sizeof(WCHAR)); |
| 2604 | cchRawHeaders += (buflen-1); |
| 2605 | memcpy(lpszRawHeaders+cchRawHeaders, szCrLf, sizeof(szCrLf)); |
| 2606 | cchRawHeaders += sizeof(szCrLf)/sizeof(szCrLf[0])-1; |
| 2607 | lpszRawHeaders[cchRawHeaders] = '\0'; |
| 2608 | |
Alexandre Julliard | 48243e3 | 2004-07-15 18:57:32 +0000 | [diff] [blame] | 2609 | /* split the version from the status code */ |
| 2610 | status_code = strchrW( buffer, ' ' ); |
| 2611 | if( !status_code ) |
| 2612 | goto lend; |
| 2613 | *status_code++=0; |
| 2614 | |
| 2615 | /* split the status code from the status text */ |
| 2616 | status_text = strchrW( status_code, ' ' ); |
| 2617 | if( !status_text ) |
| 2618 | goto lend; |
| 2619 | *status_text++=0; |
| 2620 | |
| 2621 | TRACE("version [%s] status code [%s] status text [%s]\n", |
| 2622 | debugstr_w(buffer), debugstr_w(status_code), debugstr_w(status_text) ); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2623 | |
| 2624 | HTTP_ProcessHeader(lpwhr, szStatus, status_code, |
| 2625 | HTTP_ADDHDR_FLAG_REPLACE); |
| 2626 | |
| 2627 | HeapFree(GetProcessHeap(),0,lpwhr->lpszVersion); |
| 2628 | HeapFree(GetProcessHeap(),0,lpwhr->lpszStatusText); |
| 2629 | |
| 2630 | lpwhr->lpszVersion= WININET_strdupW(buffer); |
| 2631 | lpwhr->lpszStatusText = WININET_strdupW(status_text); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2632 | |
| 2633 | /* Parse each response line */ |
| 2634 | do |
| 2635 | { |
| 2636 | buflen = MAX_REPLY_LEN; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2637 | if (NETCON_getNextLine(&lpwhr->netConnection, bufferA, &buflen)) |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2638 | { |
| 2639 | LPWSTR * pFieldAndValue; |
| 2640 | |
Francois Gouget | da8b3dd | 2005-01-26 21:09:04 +0000 | [diff] [blame] | 2641 | TRACE("got line %s, now interpreting\n", debugstr_a(bufferA)); |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2642 | MultiByteToWideChar( CP_ACP, 0, bufferA, buflen, buffer, MAX_REPLY_LEN ); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2643 | |
| 2644 | while (cchRawHeaders + buflen + strlenW(szCrLf) > cchMaxRawHeaders) |
| 2645 | { |
| 2646 | cchMaxRawHeaders *= 2; |
| 2647 | lpszRawHeaders = HeapReAlloc(GetProcessHeap(), 0, lpszRawHeaders, (cchMaxRawHeaders+1)*sizeof(WCHAR)); |
| 2648 | } |
| 2649 | memcpy(lpszRawHeaders+cchRawHeaders, buffer, (buflen-1)*sizeof(WCHAR)); |
| 2650 | cchRawHeaders += (buflen-1); |
| 2651 | memcpy(lpszRawHeaders+cchRawHeaders, szCrLf, sizeof(szCrLf)); |
| 2652 | cchRawHeaders += sizeof(szCrLf)/sizeof(szCrLf[0])-1; |
| 2653 | lpszRawHeaders[cchRawHeaders] = '\0'; |
| 2654 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2655 | pFieldAndValue = HTTP_InterpretHttpHeader(buffer); |
| 2656 | if (!pFieldAndValue) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2657 | break; |
| 2658 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2659 | HTTP_ProcessHeader(lpwhr, pFieldAndValue[0], pFieldAndValue[1], |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2660 | HTTP_ADDREQ_FLAG_ADD ); |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2661 | |
| 2662 | HTTP_FreeTokens(pFieldAndValue); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2663 | } |
| 2664 | else |
| 2665 | { |
| 2666 | cbreaks++; |
| 2667 | if (cbreaks >= 2) |
| 2668 | break; |
| 2669 | } |
| 2670 | }while(1); |
| 2671 | |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 2672 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders); |
Robert Shearman | dee8751 | 2004-07-19 20:09:20 +0000 | [diff] [blame] | 2673 | lpwhr->lpszRawHeaders = lpszRawHeaders; |
| 2674 | TRACE("raw headers: %s\n", debugstr_w(lpszRawHeaders)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2675 | bSuccess = TRUE; |
| 2676 | |
| 2677 | lend: |
| 2678 | |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2679 | TRACE("<--\n"); |
| 2680 | if (bSuccess) |
| 2681 | return rc; |
| 2682 | else |
Robert Shearman | 0e7c41e | 2005-11-28 11:55:16 +0100 | [diff] [blame] | 2683 | return 0; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2687 | static void strip_spaces(LPWSTR start) |
| 2688 | { |
| 2689 | LPWSTR str = start; |
| 2690 | LPWSTR end; |
| 2691 | |
| 2692 | while (*str == ' ' && *str != '\0') |
| 2693 | str++; |
| 2694 | |
| 2695 | if (str != start) |
| 2696 | memmove(start, str, sizeof(WCHAR) * (strlenW(str) + 1)); |
| 2697 | |
| 2698 | end = start + strlenW(start) - 1; |
| 2699 | while (end >= start && *end == ' ') |
| 2700 | { |
| 2701 | *end = '\0'; |
| 2702 | end--; |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2707 | /*********************************************************************** |
| 2708 | * HTTP_InterpretHttpHeader (internal) |
| 2709 | * |
| 2710 | * Parse server response |
| 2711 | * |
| 2712 | * RETURNS |
| 2713 | * |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2714 | * Pointer to array of field, value, NULL on success. |
| 2715 | * NULL on error. |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2716 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 2717 | static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2718 | { |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2719 | LPWSTR * pTokenPair; |
| 2720 | LPWSTR pszColon; |
| 2721 | INT len; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2722 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2723 | pTokenPair = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pTokenPair)*3); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2724 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2725 | pszColon = strchrW(buffer, ':'); |
| 2726 | /* must have two tokens */ |
| 2727 | if (!pszColon) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2728 | { |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2729 | HTTP_FreeTokens(pTokenPair); |
Robert Shearman | 7707a76 | 2005-03-10 11:14:24 +0000 | [diff] [blame] | 2730 | if (buffer[0]) |
| 2731 | TRACE("No ':' in line: %s\n", debugstr_w(buffer)); |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2732 | return NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2735 | pTokenPair[0] = HeapAlloc(GetProcessHeap(), 0, (pszColon - buffer + 1) * sizeof(WCHAR)); |
| 2736 | if (!pTokenPair[0]) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2737 | { |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2738 | HTTP_FreeTokens(pTokenPair); |
| 2739 | return NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2740 | } |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2741 | memcpy(pTokenPair[0], buffer, (pszColon - buffer) * sizeof(WCHAR)); |
| 2742 | pTokenPair[0][pszColon - buffer] = '\0'; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2743 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 2744 | /* skip colon */ |
| 2745 | pszColon++; |
| 2746 | len = strlenW(pszColon); |
| 2747 | pTokenPair[1] = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR)); |
| 2748 | if (!pTokenPair[1]) |
| 2749 | { |
| 2750 | HTTP_FreeTokens(pTokenPair); |
| 2751 | return NULL; |
| 2752 | } |
| 2753 | memcpy(pTokenPair[1], pszColon, (len + 1) * sizeof(WCHAR)); |
| 2754 | |
| 2755 | strip_spaces(pTokenPair[0]); |
| 2756 | strip_spaces(pTokenPair[1]); |
| 2757 | |
| 2758 | TRACE("field(%s) Value(%s)\n", debugstr_w(pTokenPair[0]), debugstr_w(pTokenPair[1])); |
| 2759 | return pTokenPair; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2762 | /*********************************************************************** |
| 2763 | * HTTP_ProcessHeader (internal) |
| 2764 | * |
| 2765 | * Stuff header into header tables according to <dwModifier> |
| 2766 | * |
| 2767 | */ |
| 2768 | |
| 2769 | #define COALESCEFLASG (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON) |
| 2770 | |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 2771 | static BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2772 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2773 | LPHTTPHEADERW lphttpHdr = NULL; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2774 | BOOL bSuccess = FALSE; |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2775 | INT index = -1; |
| 2776 | static const WCHAR szConnection[] = { 'C','o','n','n','e','c','t','i','o','n',0 }; |
| 2777 | BOOL request_only = dwModifier & HTTP_ADDHDR_FLAG_REQ; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2778 | |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2779 | TRACE("--> %s: %s - 0x%08lx\n", debugstr_w(field), debugstr_w(value), dwModifier); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2780 | |
Robert Shearman | 0e74f85 | 2004-09-14 19:38:59 +0000 | [diff] [blame] | 2781 | /* Don't let applications add Connection header to request */ |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2782 | if (strcmpW(szConnection,field)==0 && (dwModifier & HTTP_ADDHDR_FLAG_REQ)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2783 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2784 | return FALSE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2785 | } |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2786 | |
| 2787 | /* REPLACE wins out over ADD */ |
| 2788 | if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE) |
| 2789 | dwModifier &= ~HTTP_ADDHDR_FLAG_ADD; |
| 2790 | |
| 2791 | if (dwModifier & HTTP_ADDHDR_FLAG_ADD) |
| 2792 | index = -1; |
| 2793 | else |
| 2794 | index = HTTP_GetCustomHeaderIndex(lpwhr, field, 0, request_only); |
| 2795 | |
| 2796 | if (index >= 0) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2797 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2798 | if (dwModifier & HTTP_ADDHDR_FLAG_ADD_IF_NEW) |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2799 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2800 | return FALSE; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2801 | } |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2802 | lphttpHdr = &lpwhr->pCustHeaders[index]; |
| 2803 | } |
| 2804 | else if (value) |
| 2805 | { |
| 2806 | HTTPHEADERW hdr; |
| 2807 | |
| 2808 | hdr.lpszField = (LPWSTR)field; |
| 2809 | hdr.lpszValue = (LPWSTR)value; |
| 2810 | hdr.wFlags = hdr.wCount = 0; |
| 2811 | |
| 2812 | if (dwModifier & HTTP_ADDHDR_FLAG_REQ) |
| 2813 | hdr.wFlags |= HDR_ISREQUEST; |
| 2814 | |
| 2815 | return HTTP_InsertCustomHeader(lpwhr, &hdr); |
| 2816 | } |
| 2817 | |
| 2818 | if (dwModifier & HTTP_ADDHDR_FLAG_REQ) |
| 2819 | lphttpHdr->wFlags |= HDR_ISREQUEST; |
| 2820 | else |
| 2821 | lphttpHdr->wFlags &= ~HDR_ISREQUEST; |
| 2822 | |
| 2823 | if (dwModifier & HTTP_ADDHDR_FLAG_REPLACE) |
| 2824 | { |
| 2825 | HTTP_DeleteCustomHeader( lpwhr, index ); |
| 2826 | |
| 2827 | if (value) |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2828 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2829 | HTTPHEADERW hdr; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2830 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2831 | hdr.lpszField = (LPWSTR)field; |
| 2832 | hdr.lpszValue = (LPWSTR)value; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2833 | hdr.wFlags = hdr.wCount = 0; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2834 | |
| 2835 | if (dwModifier & HTTP_ADDHDR_FLAG_REQ) |
| 2836 | hdr.wFlags |= HDR_ISREQUEST; |
| 2837 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 2838 | return HTTP_InsertCustomHeader(lpwhr, &hdr); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2839 | } |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2840 | |
| 2841 | return TRUE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2842 | } |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2843 | else if (dwModifier & COALESCEFLASG) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2844 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2845 | LPWSTR lpsztmp; |
| 2846 | WCHAR ch = 0; |
| 2847 | INT len = 0; |
| 2848 | INT origlen = strlenW(lphttpHdr->lpszValue); |
| 2849 | INT valuelen = strlenW(value); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2850 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2851 | if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2852 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2853 | ch = ','; |
| 2854 | lphttpHdr->wFlags |= HDR_COMMADELIMITED; |
| 2855 | } |
| 2856 | else if (dwModifier & HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON) |
| 2857 | { |
| 2858 | ch = ';'; |
| 2859 | lphttpHdr->wFlags |= HDR_COMMADELIMITED; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2862 | len = origlen + valuelen + ((ch > 0) ? 2 : 0); |
| 2863 | |
| 2864 | lpsztmp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lphttpHdr->lpszValue, (len+1)*sizeof(WCHAR)); |
| 2865 | if (lpsztmp) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2866 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2867 | lphttpHdr->lpszValue = lpsztmp; |
| 2868 | /* FIXME: Increment lphttpHdr->wCount. Perhaps lpszValue should be an array */ |
| 2869 | if (ch > 0) |
| 2870 | { |
| 2871 | lphttpHdr->lpszValue[origlen] = ch; |
| 2872 | origlen++; |
| 2873 | lphttpHdr->lpszValue[origlen] = ' '; |
| 2874 | origlen++; |
| 2875 | } |
| 2876 | |
| 2877 | memcpy(&lphttpHdr->lpszValue[origlen], value, valuelen*sizeof(WCHAR)); |
| 2878 | lphttpHdr->lpszValue[len] = '\0'; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2879 | bSuccess = TRUE; |
| 2880 | } |
| 2881 | else |
| 2882 | { |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2883 | WARN("HeapReAlloc (%d bytes) failed\n",len+1); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2884 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
| 2885 | } |
| 2886 | } |
Alberto Massari | bc8bd72 | 2002-12-06 23:20:31 +0000 | [diff] [blame] | 2887 | TRACE("<-- %d\n",bSuccess); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2888 | return bSuccess; |
| 2889 | } |
| 2890 | |
| 2891 | |
| 2892 | /*********************************************************************** |
| 2893 | * HTTP_CloseConnection (internal) |
| 2894 | * |
| 2895 | * Close socket connection |
| 2896 | * |
| 2897 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 2898 | static VOID HTTP_CloseConnection(LPWININETHTTPREQW lpwhr) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2899 | { |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2900 | LPWININETHTTPSESSIONW lpwhs = NULL; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 2901 | LPWININETAPPINFOW hIC = NULL; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2902 | |
| 2903 | TRACE("%p\n",lpwhr); |
| 2904 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2905 | lpwhs = (LPWININETHTTPSESSIONW) lpwhr->hdr.lpwhparent; |
Mike McCormack | 09d2d47 | 2004-03-25 05:29:47 +0000 | [diff] [blame] | 2906 | hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent; |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2907 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2908 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2909 | INTERNET_STATUS_CLOSING_CONNECTION, 0, 0); |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2910 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2911 | if (NETCON_connected(&lpwhr->netConnection)) |
| 2912 | { |
| 2913 | NETCON_close(&lpwhr->netConnection); |
| 2914 | } |
Aric Stewart | ff9b9d4 | 2002-06-21 23:59:49 +0000 | [diff] [blame] | 2915 | |
Robert Shearman | de2666f | 2005-11-29 10:44:05 +0100 | [diff] [blame] | 2916 | INTERNET_SendCallback(&lpwhr->hdr, lpwhr->hdr.dwContext, |
| 2917 | INTERNET_STATUS_CONNECTION_CLOSED, 0, 0); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | |
| 2921 | /*********************************************************************** |
| 2922 | * HTTP_CloseHTTPRequestHandle (internal) |
| 2923 | * |
| 2924 | * Deallocate request handle |
| 2925 | * |
| 2926 | */ |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2927 | static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2928 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2929 | DWORD i; |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2930 | LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) hdr; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2931 | |
| 2932 | TRACE("\n"); |
| 2933 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2934 | if (NETCON_connected(&lpwhr->netConnection)) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2935 | HTTP_CloseConnection(lpwhr); |
| 2936 | |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 2937 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath); |
| 2938 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb); |
| 2939 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders); |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2940 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszVersion); |
| 2941 | HeapFree(GetProcessHeap(), 0, lpwhr->lpszStatusText); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2942 | |
| 2943 | for (i = 0; i < lpwhr->nCustHeaders; i++) |
| 2944 | { |
Michael Stefaniuc | 15a308a | 2005-01-03 14:56:42 +0000 | [diff] [blame] | 2945 | HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszField); |
| 2946 | HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszValue); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders); |
| 2950 | HeapFree(GetProcessHeap(), 0, lpwhr); |
| 2951 | } |
| 2952 | |
| 2953 | |
| 2954 | /*********************************************************************** |
| 2955 | * HTTP_CloseHTTPSessionHandle (internal) |
| 2956 | * |
| 2957 | * Deallocate session handle |
| 2958 | * |
| 2959 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 2960 | static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2961 | { |
Mike McCormack | 3a1391b | 2004-07-19 21:49:39 +0000 | [diff] [blame] | 2962 | LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) hdr; |
Mike McCormack | 7cc70c0 | 2004-02-07 01:03:41 +0000 | [diff] [blame] | 2963 | |
David Hammerton | 852c7ae | 2003-06-20 23:26:56 +0000 | [diff] [blame] | 2964 | TRACE("%p\n", lpwhs); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2965 | |
Robert Shearman | 7bb3463 | 2005-11-28 10:40:42 +0100 | [diff] [blame] | 2966 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszHostName); |
Michael Stefaniuc | 5ad7d85 | 2004-12-23 17:06:43 +0000 | [diff] [blame] | 2967 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); |
| 2968 | HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2969 | HeapFree(GetProcessHeap(), 0, lpwhs); |
| 2970 | } |
| 2971 | |
| 2972 | |
| 2973 | /*********************************************************************** |
| 2974 | * HTTP_GetCustomHeaderIndex (internal) |
| 2975 | * |
| 2976 | * Return index of custom header from header array |
| 2977 | * |
| 2978 | */ |
Mike McCormack | 92ddc1c | 2006-03-30 18:20:04 +0900 | [diff] [blame] | 2979 | static INT HTTP_GetCustomHeaderIndex(LPWININETHTTPREQW lpwhr, LPCWSTR lpszField, |
| 2980 | int requested_index, BOOL request_only) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2981 | { |
Mike McCormack | 13b6ce6d | 2004-08-09 18:54:23 +0000 | [diff] [blame] | 2982 | DWORD index; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2983 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 2984 | TRACE("%s\n", debugstr_w(lpszField)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2985 | |
| 2986 | for (index = 0; index < lpwhr->nCustHeaders; index++) |
| 2987 | { |
Mike McCormack | 92ddc1c | 2006-03-30 18:20:04 +0900 | [diff] [blame] | 2988 | if (strcmpiW(lpwhr->pCustHeaders[index].lpszField, lpszField)) |
| 2989 | continue; |
| 2990 | |
| 2991 | if (request_only && !(lpwhr->pCustHeaders[index].wFlags & HDR_ISREQUEST)) |
| 2992 | continue; |
| 2993 | |
| 2994 | if (!request_only && (lpwhr->pCustHeaders[index].wFlags & HDR_ISREQUEST)) |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2995 | continue; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 2996 | |
Aric Stewart | 1e946d3 | 2005-12-13 17:07:41 +0100 | [diff] [blame] | 2997 | if (requested_index == 0) |
Mike McCormack | 92ddc1c | 2006-03-30 18:20:04 +0900 | [diff] [blame] | 2998 | break; |
| 2999 | requested_index --; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | if (index >= lpwhr->nCustHeaders) |
| 3003 | index = -1; |
| 3004 | |
Robert Shearman | b72a682 | 2004-09-23 22:53:50 +0000 | [diff] [blame] | 3005 | TRACE("Return: %ld\n", index); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3006 | return index; |
| 3007 | } |
| 3008 | |
| 3009 | |
| 3010 | /*********************************************************************** |
| 3011 | * HTTP_InsertCustomHeader (internal) |
| 3012 | * |
| 3013 | * Insert header into array |
| 3014 | * |
| 3015 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 3016 | static BOOL HTTP_InsertCustomHeader(LPWININETHTTPREQW lpwhr, LPHTTPHEADERW lpHdr) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3017 | { |
| 3018 | INT count; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3019 | LPHTTPHEADERW lph = NULL; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 3020 | BOOL r = FALSE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3021 | |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3022 | TRACE("--> %s: %s\n", debugstr_w(lpHdr->lpszField), debugstr_w(lpHdr->lpszValue)); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3023 | count = lpwhr->nCustHeaders + 1; |
| 3024 | if (count > 1) |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3025 | lph = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lpwhr->pCustHeaders, sizeof(HTTPHEADERW) * count); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3026 | else |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3027 | lph = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HTTPHEADERW) * count); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3028 | |
| 3029 | if (NULL != lph) |
| 3030 | { |
| 3031 | lpwhr->pCustHeaders = lph; |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3032 | lpwhr->pCustHeaders[count-1].lpszField = WININET_strdupW(lpHdr->lpszField); |
| 3033 | lpwhr->pCustHeaders[count-1].lpszValue = WININET_strdupW(lpHdr->lpszValue); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3034 | lpwhr->pCustHeaders[count-1].wFlags = lpHdr->wFlags; |
| 3035 | lpwhr->pCustHeaders[count-1].wCount= lpHdr->wCount; |
| 3036 | lpwhr->nCustHeaders++; |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 3037 | r = TRUE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3038 | } |
| 3039 | else |
| 3040 | { |
| 3041 | INTERNET_SetLastError(ERROR_OUTOFMEMORY); |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 3044 | return r; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | |
| 3048 | /*********************************************************************** |
| 3049 | * HTTP_DeleteCustomHeader (internal) |
| 3050 | * |
| 3051 | * Delete header from array |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 3052 | * If this function is called, the indexs may change. |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3053 | */ |
Jacek Caban | 02708c6 | 2005-10-26 10:07:58 +0000 | [diff] [blame] | 3054 | static BOOL HTTP_DeleteCustomHeader(LPWININETHTTPREQW lpwhr, DWORD index) |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3055 | { |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 3056 | if( lpwhr->nCustHeaders <= 0 ) |
| 3057 | return FALSE; |
Robert Shearman | 7707a76 | 2005-03-10 11:14:24 +0000 | [diff] [blame] | 3058 | if( index >= lpwhr->nCustHeaders ) |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 3059 | return FALSE; |
| 3060 | lpwhr->nCustHeaders--; |
| 3061 | |
| 3062 | memmove( &lpwhr->pCustHeaders[index], &lpwhr->pCustHeaders[index+1], |
Mike McCormack | a4e902c | 2004-03-30 04:36:09 +0000 | [diff] [blame] | 3063 | (lpwhr->nCustHeaders - index)* sizeof(HTTPHEADERW) ); |
| 3064 | memset( &lpwhr->pCustHeaders[lpwhr->nCustHeaders], 0, sizeof(HTTPHEADERW) ); |
Mike McCormack | a1c16d2 | 2003-07-22 03:17:52 +0000 | [diff] [blame] | 3065 | |
| 3066 | return TRUE; |
Ulrich Czekalla | c275724 | 2000-06-11 20:04:44 +0000 | [diff] [blame] | 3067 | } |
Alberto Massari | b09eef2 | 2002-11-13 04:08:26 +0000 | [diff] [blame] | 3068 | |
| 3069 | /*********************************************************************** |
| 3070 | * IsHostInProxyBypassList (@) |
| 3071 | * |
| 3072 | * Undocumented |
| 3073 | * |
| 3074 | */ |
| 3075 | BOOL WINAPI IsHostInProxyBypassList(DWORD flags, LPCSTR szHost, DWORD length) |
| 3076 | { |
| 3077 | FIXME("STUB: flags=%ld host=%s length=%ld\n",flags,szHost,length); |
| 3078 | return FALSE; |
| 3079 | } |