wininet: InternetGetConnectedStateExW must return TRUE for success.
[wine.git] / dlls / wininet / internet.c
blob3cf3ea63406c76239a39408d9a05d91f4747593d
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "config.h"
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
33 #include <ws2tcpip.h>
34 #endif
36 #include <string.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
42 #endif
43 #ifdef HAVE_POLL_H
44 #include <poll.h>
45 #endif
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
48 #endif
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
51 #endif
52 #include <stdlib.h>
53 #include <ctype.h>
54 #ifdef HAVE_UNISTD_H
55 # include <unistd.h>
56 #endif
57 #include <assert.h>
59 #include "windef.h"
60 #include "winbase.h"
61 #include "winreg.h"
62 #include "winuser.h"
63 #include "wininet.h"
64 #include "winnls.h"
65 #include "wine/debug.h"
66 #include "winerror.h"
67 #define NO_SHLWAPI_STREAM
68 #include "shlwapi.h"
70 #include "wine/exception.h"
72 #include "internet.h"
73 #include "resource.h"
75 #include "wine/unicode.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
79 #define RESPONSE_TIMEOUT 30
81 typedef struct
83 DWORD dwError;
84 CHAR response[MAX_REPLY_LEN];
85 } WITHREADERROR, *LPWITHREADERROR;
87 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
88 HMODULE WININET_hModule;
90 static CRITICAL_SECTION WININET_cs;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
93 0, 0, &WININET_cs,
94 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
95 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
99 static object_header_t **handle_table;
100 static UINT_PTR next_handle;
101 static UINT_PTR handle_table_size;
103 typedef struct
105 DWORD proxyEnabled;
106 LPWSTR proxy;
107 LPWSTR proxyBypass;
108 } proxyinfo_t;
110 static ULONG max_conns = 2, max_1_0_conns = 4;
111 static ULONG connect_timeout = 60000;
113 static const WCHAR szInternetSettings[] =
114 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
115 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
116 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
117 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
118 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
119 static const WCHAR szProxyOverride[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
121 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
123 UINT_PTR handle = 0, num;
124 object_header_t *ret;
125 object_header_t **p;
126 BOOL res = TRUE;
128 ret = heap_alloc_zero(size);
129 if(!ret)
130 return NULL;
132 list_init(&ret->children);
134 EnterCriticalSection( &WININET_cs );
136 if(!handle_table_size) {
137 num = 16;
138 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
139 if(p) {
140 handle_table = p;
141 handle_table_size = num;
142 next_handle = 1;
143 }else {
144 res = FALSE;
146 }else if(next_handle == handle_table_size) {
147 num = handle_table_size * 2;
148 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
149 if(p) {
150 handle_table = p;
151 handle_table_size = num;
152 }else {
153 res = FALSE;
157 if(res) {
158 handle = next_handle;
159 if(handle_table[handle])
160 ERR("handle isn't free but should be\n");
161 handle_table[handle] = ret;
162 ret->valid_handle = TRUE;
164 while(handle_table[next_handle] && next_handle < handle_table_size)
165 next_handle++;
168 LeaveCriticalSection( &WININET_cs );
170 if(!res) {
171 heap_free(ret);
172 return NULL;
175 ret->vtbl = vtbl;
176 ret->refs = 1;
177 ret->hInternet = (HINTERNET)handle;
179 if(parent) {
180 ret->lpfnStatusCB = parent->lpfnStatusCB;
181 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
184 return ret;
187 object_header_t *WININET_AddRef( object_header_t *info )
189 ULONG refs = InterlockedIncrement(&info->refs);
190 TRACE("%p -> refcount = %d\n", info, refs );
191 return info;
194 object_header_t *get_handle_object( HINTERNET hinternet )
196 object_header_t *info = NULL;
197 UINT_PTR handle = (UINT_PTR) hinternet;
199 EnterCriticalSection( &WININET_cs );
201 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
202 info = WININET_AddRef(handle_table[handle]);
204 LeaveCriticalSection( &WININET_cs );
206 TRACE("handle %ld -> %p\n", handle, info);
208 return info;
211 static void invalidate_handle(object_header_t *info)
213 object_header_t *child, *next;
215 if(!info->valid_handle)
216 return;
217 info->valid_handle = FALSE;
219 /* Free all children as native does */
220 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
222 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
223 invalidate_handle( child );
226 WININET_Release(info);
229 BOOL WININET_Release( object_header_t *info )
231 ULONG refs = InterlockedDecrement(&info->refs);
232 TRACE( "object %p refcount = %d\n", info, refs );
233 if( !refs )
235 invalidate_handle(info);
236 if ( info->vtbl->CloseConnection )
238 TRACE( "closing connection %p\n", info);
239 info->vtbl->CloseConnection( info );
241 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
242 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
243 || !(info->dwInternalFlags & INET_OPENURL))
245 INTERNET_SendCallback(info, info->dwContext,
246 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
247 sizeof(HINTERNET));
249 TRACE( "destroying object %p\n", info);
250 if ( info->htype != WH_HINIT )
251 list_remove( &info->entry );
252 info->vtbl->Destroy( info );
254 if(info->hInternet) {
255 UINT_PTR handle = (UINT_PTR)info->hInternet;
257 EnterCriticalSection( &WININET_cs );
259 handle_table[handle] = NULL;
260 if(next_handle > handle)
261 next_handle = handle;
263 LeaveCriticalSection( &WININET_cs );
266 heap_free(info);
268 return TRUE;
271 /***********************************************************************
272 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
274 * PARAMS
275 * hinstDLL [I] handle to the DLL's instance
276 * fdwReason [I]
277 * lpvReserved [I] reserved, must be NULL
279 * RETURNS
280 * Success: TRUE
281 * Failure: FALSE
284 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
286 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
288 switch (fdwReason) {
289 case DLL_PROCESS_ATTACH:
291 g_dwTlsErrIndex = TlsAlloc();
293 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
294 return FALSE;
296 if(!init_urlcache())
298 TlsFree(g_dwTlsErrIndex);
299 return FALSE;
302 WININET_hModule = hinstDLL;
303 break;
305 case DLL_THREAD_ATTACH:
306 break;
308 case DLL_THREAD_DETACH:
309 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
311 heap_free(TlsGetValue(g_dwTlsErrIndex));
313 break;
315 case DLL_PROCESS_DETACH:
316 if (lpvReserved) break;
317 collect_connections(COLLECT_CLEANUP);
318 NETCON_unload();
319 free_urlcache();
320 free_cookie();
322 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
324 heap_free(TlsGetValue(g_dwTlsErrIndex));
325 TlsFree(g_dwTlsErrIndex);
327 break;
329 return TRUE;
332 /***********************************************************************
333 * INTERNET_SaveProxySettings
335 * Stores the proxy settings given by lpwai into the registry
337 * RETURNS
338 * ERROR_SUCCESS if no error, or error code on fail
340 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
342 HKEY key;
343 LONG ret;
345 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
346 return ret;
348 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
350 RegCloseKey( key );
351 return ret;
354 if (lpwpi->proxy)
356 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
358 RegCloseKey( key );
359 return ret;
362 else
364 if ((ret = RegDeleteValueW( key, szProxyServer )))
366 RegCloseKey( key );
367 return ret;
371 RegCloseKey(key);
372 return ERROR_SUCCESS;
375 /***********************************************************************
376 * INTERNET_FindProxyForProtocol
378 * Searches the proxy string for a proxy of the given protocol.
379 * Returns the found proxy, or the default proxy if none of the given
380 * protocol is found.
382 * PARAMETERS
383 * szProxy [In] proxy string to search
384 * proto [In] protocol to search for, e.g. "http"
385 * foundProxy [Out] found proxy
386 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
388 * RETURNS
389 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
390 * *foundProxyLen is set to the required size in WCHARs, including the
391 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
393 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
395 LPCWSTR ptr;
396 BOOL ret = FALSE;
398 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
400 /* First, look for the specified protocol (proto=scheme://host:port) */
401 for (ptr = szProxy; !ret && ptr && *ptr; )
403 LPCWSTR end, equal;
405 if (!(end = strchrW(ptr, ' ')))
406 end = ptr + strlenW(ptr);
407 if ((equal = strchrW(ptr, '=')) && equal < end &&
408 equal - ptr == strlenW(proto) &&
409 !strncmpiW(proto, ptr, strlenW(proto)))
411 if (end - equal > *foundProxyLen)
413 WARN("buffer too short for %s\n",
414 debugstr_wn(equal + 1, end - equal - 1));
415 *foundProxyLen = end - equal;
416 SetLastError(ERROR_INSUFFICIENT_BUFFER);
418 else
420 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
421 foundProxy[end - equal] = 0;
422 ret = TRUE;
425 if (*end == ' ')
426 ptr = end + 1;
427 else
428 ptr = end;
430 if (!ret)
432 /* It wasn't found: look for no protocol */
433 for (ptr = szProxy; !ret && ptr && *ptr; )
435 LPCWSTR end;
437 if (!(end = strchrW(ptr, ' ')))
438 end = ptr + strlenW(ptr);
439 if (!strchrW(ptr, '='))
441 if (end - ptr + 1 > *foundProxyLen)
443 WARN("buffer too short for %s\n",
444 debugstr_wn(ptr, end - ptr));
445 *foundProxyLen = end - ptr + 1;
446 SetLastError(ERROR_INSUFFICIENT_BUFFER);
448 else
450 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
451 foundProxy[end - ptr] = 0;
452 ret = TRUE;
455 if (*end == ' ')
456 ptr = end + 1;
457 else
458 ptr = end;
461 if (ret)
462 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
463 debugstr_w(foundProxy));
464 return ret;
467 /***********************************************************************
468 * InternetInitializeAutoProxyDll (WININET.@)
470 * Setup the internal proxy
472 * PARAMETERS
473 * dwReserved
475 * RETURNS
476 * FALSE on failure
479 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
481 FIXME("STUB\n");
482 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
483 return FALSE;
486 /***********************************************************************
487 * DetectAutoProxyUrl (WININET.@)
489 * Auto detect the proxy url
491 * RETURNS
492 * FALSE on failure
495 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
496 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
498 FIXME("STUB\n");
499 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
500 return FALSE;
503 static void FreeProxyInfo( proxyinfo_t *lpwpi )
505 heap_free(lpwpi->proxy);
506 heap_free(lpwpi->proxyBypass);
509 static proxyinfo_t *global_proxy;
511 static void free_global_proxy( void )
513 EnterCriticalSection( &WININET_cs );
514 if (global_proxy)
516 FreeProxyInfo( global_proxy );
517 heap_free( global_proxy );
519 LeaveCriticalSection( &WININET_cs );
522 /***********************************************************************
523 * INTERNET_LoadProxySettings
525 * Loads proxy information from process-wide global settings, the registry,
526 * or the environment into lpwpi.
528 * The caller should call FreeProxyInfo when done with lpwpi.
530 * FIXME:
531 * The proxy may be specified in the form 'http=proxy.my.org'
532 * Presumably that means there can be ftp=ftpproxy.my.org too.
534 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
536 HKEY key;
537 DWORD type, len;
538 LPCSTR envproxy;
539 LONG ret;
541 EnterCriticalSection( &WININET_cs );
542 if (global_proxy)
544 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
545 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
546 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
548 LeaveCriticalSection( &WININET_cs );
550 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
551 return ret;
553 len = sizeof(DWORD);
554 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
556 lpwpi->proxyEnabled = 0;
557 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
559 RegCloseKey( key );
560 return ret;
564 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->proxyEnabled)
566 TRACE("Proxy is enabled.\n");
568 /* figure out how much memory the proxy setting takes */
569 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
571 LPWSTR szProxy, p;
572 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
574 if (!(szProxy = heap_alloc(len)))
576 RegCloseKey( key );
577 return ERROR_OUTOFMEMORY;
579 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
581 /* find the http proxy, and strip away everything else */
582 p = strstrW( szProxy, szHttp );
583 if (p)
585 p += lstrlenW( szHttp );
586 lstrcpyW( szProxy, p );
588 p = strchrW( szProxy, ' ' );
589 if (p) *p = 0;
591 lpwpi->proxy = szProxy;
593 TRACE("http proxy = %s\n", debugstr_w(lpwpi->proxy));
595 else
597 TRACE("No proxy server settings in registry.\n");
598 lpwpi->proxy = NULL;
601 else if (envproxy)
603 WCHAR *envproxyW;
605 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
606 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
607 return ERROR_OUTOFMEMORY;
608 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
610 lpwpi->proxyEnabled = 1;
611 lpwpi->proxy = envproxyW;
613 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
616 lpwpi->proxyBypass = NULL;
617 if (lpwpi->proxyEnabled)
619 if (!(envproxy = getenv( "no_proxy" )))
621 /* figure out how much memory the proxy setting takes */
622 if (!RegQueryValueExW( key, szProxyOverride, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
624 LPWSTR szProxy;
626 if (!(szProxy = heap_alloc(len)))
628 RegCloseKey( key );
629 return ERROR_OUTOFMEMORY;
631 RegQueryValueExW( key, szProxyOverride, NULL, &type, (BYTE*)szProxy, &len );
633 lpwpi->proxyBypass = szProxy;
635 TRACE("http proxy bypass = %s\n", debugstr_w(lpwpi->proxyBypass));
637 else
639 TRACE("No proxy bypass server settings in registry.\n");
642 else if (envproxy)
644 WCHAR *envproxyW;
646 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
647 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
648 return ERROR_OUTOFMEMORY;
649 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
651 lpwpi->proxyBypass = envproxyW;
653 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
657 RegCloseKey( key );
659 return ERROR_SUCCESS;
662 /***********************************************************************
663 * INTERNET_ConfigureProxy
665 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
667 proxyinfo_t wpi = {0};
669 if (INTERNET_LoadProxySettings( &wpi ))
670 return FALSE;
672 if (wpi.proxyEnabled)
674 WCHAR proxyurl[INTERNET_MAX_URL_LENGTH];
675 WCHAR username[INTERNET_MAX_USER_NAME_LENGTH];
676 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
677 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
678 URL_COMPONENTSW UrlComponents;
680 UrlComponents.dwStructSize = sizeof UrlComponents;
681 UrlComponents.dwSchemeLength = 0;
682 UrlComponents.lpszHostName = hostname;
683 UrlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
684 UrlComponents.lpszUserName = username;
685 UrlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
686 UrlComponents.lpszPassword = password;
687 UrlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
688 UrlComponents.dwUrlPathLength = 0;
689 UrlComponents.dwExtraInfoLength = 0;
691 if(InternetCrackUrlW(wpi.proxy, 0, 0, &UrlComponents))
693 static const WCHAR szFormat[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
695 if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
696 UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
697 sprintfW(proxyurl, szFormat, hostname, UrlComponents.nPort);
699 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
700 lpwai->proxy = heap_strdupW(proxyurl);
701 lpwai->proxyBypass = heap_strdupW(wpi.proxyBypass);
702 if (UrlComponents.dwUserNameLength)
704 lpwai->proxyUsername = heap_strdupW(UrlComponents.lpszUserName);
705 lpwai->proxyPassword = heap_strdupW(UrlComponents.lpszPassword);
708 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai->proxy), debugstr_w(lpwai->proxyBypass));
709 FreeProxyInfo(&wpi);
710 return TRUE;
712 else
714 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi.proxy));
715 lpwai->proxy = NULL;
719 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
720 FreeProxyInfo(&wpi);
721 return FALSE;
724 /***********************************************************************
725 * dump_INTERNET_FLAGS
727 * Helper function to TRACE the internet flags.
729 * RETURNS
730 * None
733 static void dump_INTERNET_FLAGS(DWORD dwFlags)
735 #define FE(x) { x, #x }
736 static const wininet_flag_info flag[] = {
737 FE(INTERNET_FLAG_RELOAD),
738 FE(INTERNET_FLAG_RAW_DATA),
739 FE(INTERNET_FLAG_EXISTING_CONNECT),
740 FE(INTERNET_FLAG_ASYNC),
741 FE(INTERNET_FLAG_PASSIVE),
742 FE(INTERNET_FLAG_NO_CACHE_WRITE),
743 FE(INTERNET_FLAG_MAKE_PERSISTENT),
744 FE(INTERNET_FLAG_FROM_CACHE),
745 FE(INTERNET_FLAG_SECURE),
746 FE(INTERNET_FLAG_KEEP_CONNECTION),
747 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
748 FE(INTERNET_FLAG_READ_PREFETCH),
749 FE(INTERNET_FLAG_NO_COOKIES),
750 FE(INTERNET_FLAG_NO_AUTH),
751 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
752 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
753 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
754 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
755 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
756 FE(INTERNET_FLAG_RESYNCHRONIZE),
757 FE(INTERNET_FLAG_HYPERLINK),
758 FE(INTERNET_FLAG_NO_UI),
759 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
760 FE(INTERNET_FLAG_CACHE_ASYNC),
761 FE(INTERNET_FLAG_FORMS_SUBMIT),
762 FE(INTERNET_FLAG_NEED_FILE),
763 FE(INTERNET_FLAG_TRANSFER_ASCII),
764 FE(INTERNET_FLAG_TRANSFER_BINARY)
766 #undef FE
767 unsigned int i;
769 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
770 if (flag[i].val & dwFlags) {
771 TRACE(" %s", flag[i].name);
772 dwFlags &= ~flag[i].val;
775 if (dwFlags)
776 TRACE(" Unknown flags (%08x)\n", dwFlags);
777 else
778 TRACE("\n");
781 /***********************************************************************
782 * INTERNET_CloseHandle (internal)
784 * Close internet handle
787 static VOID APPINFO_Destroy(object_header_t *hdr)
789 appinfo_t *lpwai = (appinfo_t*)hdr;
791 TRACE("%p\n",lpwai);
793 heap_free(lpwai->agent);
794 heap_free(lpwai->proxy);
795 heap_free(lpwai->proxyBypass);
796 heap_free(lpwai->proxyUsername);
797 heap_free(lpwai->proxyPassword);
800 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
802 appinfo_t *ai = (appinfo_t*)hdr;
804 switch(option) {
805 case INTERNET_OPTION_HANDLE_TYPE:
806 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
808 if (*size < sizeof(ULONG))
809 return ERROR_INSUFFICIENT_BUFFER;
811 *size = sizeof(DWORD);
812 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
813 return ERROR_SUCCESS;
815 case INTERNET_OPTION_USER_AGENT: {
816 DWORD bufsize;
818 TRACE("INTERNET_OPTION_USER_AGENT\n");
820 bufsize = *size;
822 if (unicode) {
823 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
825 *size = (len + 1) * sizeof(WCHAR);
826 if(!buffer || bufsize < *size)
827 return ERROR_INSUFFICIENT_BUFFER;
829 if (ai->agent)
830 strcpyW(buffer, ai->agent);
831 else
832 *(WCHAR *)buffer = 0;
833 /* If the buffer is copied, the returned length doesn't include
834 * the NULL terminator.
836 *size = len;
837 }else {
838 if (ai->agent)
839 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
840 else
841 *size = 1;
842 if(!buffer || bufsize < *size)
843 return ERROR_INSUFFICIENT_BUFFER;
845 if (ai->agent)
846 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
847 else
848 *(char *)buffer = 0;
849 /* If the buffer is copied, the returned length doesn't include
850 * the NULL terminator.
852 *size -= 1;
855 return ERROR_SUCCESS;
858 case INTERNET_OPTION_PROXY:
859 if(!size) return ERROR_INVALID_PARAMETER;
860 if (unicode) {
861 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
862 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
863 LPWSTR proxy, proxy_bypass;
865 if (ai->proxy)
866 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
867 if (ai->proxyBypass)
868 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
869 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
871 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
872 return ERROR_INSUFFICIENT_BUFFER;
874 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
875 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
877 pi->dwAccessType = ai->accessType;
878 pi->lpszProxy = NULL;
879 pi->lpszProxyBypass = NULL;
880 if (ai->proxy) {
881 lstrcpyW(proxy, ai->proxy);
882 pi->lpszProxy = proxy;
885 if (ai->proxyBypass) {
886 lstrcpyW(proxy_bypass, ai->proxyBypass);
887 pi->lpszProxyBypass = proxy_bypass;
890 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
891 return ERROR_SUCCESS;
892 }else {
893 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
894 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
895 LPSTR proxy, proxy_bypass;
897 if (ai->proxy)
898 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
899 if (ai->proxyBypass)
900 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
901 NULL, 0, NULL, NULL);
902 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
904 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
905 return ERROR_INSUFFICIENT_BUFFER;
907 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
908 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
910 pi->dwAccessType = ai->accessType;
911 pi->lpszProxy = NULL;
912 pi->lpszProxyBypass = NULL;
913 if (ai->proxy) {
914 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
915 pi->lpszProxy = proxy;
918 if (ai->proxyBypass) {
919 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
920 proxyBypassBytesRequired, NULL, NULL);
921 pi->lpszProxyBypass = proxy_bypass;
924 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
925 return ERROR_SUCCESS;
928 case INTERNET_OPTION_CONNECT_TIMEOUT:
929 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
931 if (*size < sizeof(ULONG))
932 return ERROR_INSUFFICIENT_BUFFER;
934 *(ULONG*)buffer = ai->connect_timeout;
935 *size = sizeof(ULONG);
937 return ERROR_SUCCESS;
940 return INET_QueryOption(hdr, option, buffer, size, unicode);
943 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
945 appinfo_t *ai = (appinfo_t*)hdr;
947 switch(option) {
948 case INTERNET_OPTION_CONNECT_TIMEOUT:
949 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
951 if(size != sizeof(connect_timeout))
952 return ERROR_INTERNET_BAD_OPTION_LENGTH;
953 if(!*(ULONG*)buf)
954 return ERROR_BAD_ARGUMENTS;
956 ai->connect_timeout = *(ULONG*)buf;
957 return ERROR_SUCCESS;
958 case INTERNET_OPTION_USER_AGENT:
959 heap_free(ai->agent);
960 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
961 return ERROR_SUCCESS;
964 return INET_SetOption(hdr, option, buf, size);
967 static const object_vtbl_t APPINFOVtbl = {
968 APPINFO_Destroy,
969 NULL,
970 APPINFO_QueryOption,
971 APPINFO_SetOption,
972 NULL,
973 NULL,
974 NULL,
975 NULL
979 /***********************************************************************
980 * InternetOpenW (WININET.@)
982 * Per-application initialization of wininet
984 * RETURNS
985 * HINTERNET on success
986 * NULL on failure
989 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
990 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
992 appinfo_t *lpwai = NULL;
994 if (TRACE_ON(wininet)) {
995 #define FE(x) { x, #x }
996 static const wininet_flag_info access_type[] = {
997 FE(INTERNET_OPEN_TYPE_PRECONFIG),
998 FE(INTERNET_OPEN_TYPE_DIRECT),
999 FE(INTERNET_OPEN_TYPE_PROXY),
1000 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
1002 #undef FE
1003 DWORD i;
1004 const char *access_type_str = "Unknown";
1006 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
1007 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
1008 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
1009 if (access_type[i].val == dwAccessType) {
1010 access_type_str = access_type[i].name;
1011 break;
1014 TRACE(" access type : %s\n", access_type_str);
1015 TRACE(" flags :");
1016 dump_INTERNET_FLAGS(dwFlags);
1019 /* Clear any error information */
1020 INTERNET_SetLastError(0);
1022 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1023 SetLastError(ERROR_INVALID_PARAMETER);
1024 return NULL;
1027 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1028 if (!lpwai) {
1029 SetLastError(ERROR_OUTOFMEMORY);
1030 return NULL;
1033 lpwai->hdr.htype = WH_HINIT;
1034 lpwai->hdr.dwFlags = dwFlags;
1035 lpwai->accessType = dwAccessType;
1036 lpwai->proxyUsername = NULL;
1037 lpwai->proxyPassword = NULL;
1038 lpwai->connect_timeout = connect_timeout;
1040 lpwai->agent = heap_strdupW(lpszAgent);
1041 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1042 INTERNET_ConfigureProxy( lpwai );
1043 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1044 lpwai->proxy = heap_strdupW(lpszProxy);
1045 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1048 TRACE("returning %p\n", lpwai);
1050 return lpwai->hdr.hInternet;
1054 /***********************************************************************
1055 * InternetOpenA (WININET.@)
1057 * Per-application initialization of wininet
1059 * RETURNS
1060 * HINTERNET on success
1061 * NULL on failure
1064 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1065 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1067 WCHAR *szAgent, *szProxy, *szBypass;
1068 HINTERNET rc;
1070 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1071 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1073 szAgent = heap_strdupAtoW(lpszAgent);
1074 szProxy = heap_strdupAtoW(lpszProxy);
1075 szBypass = heap_strdupAtoW(lpszProxyBypass);
1077 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1079 heap_free(szAgent);
1080 heap_free(szProxy);
1081 heap_free(szBypass);
1082 return rc;
1085 /***********************************************************************
1086 * InternetGetLastResponseInfoA (WININET.@)
1088 * Return last wininet error description on the calling thread
1090 * RETURNS
1091 * TRUE on success of writing to buffer
1092 * FALSE on failure
1095 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1096 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1098 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1100 TRACE("\n");
1102 if (lpwite)
1104 *lpdwError = lpwite->dwError;
1105 if (lpwite->dwError)
1107 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1108 *lpdwBufferLength = strlen(lpszBuffer);
1110 else
1111 *lpdwBufferLength = 0;
1113 else
1115 *lpdwError = 0;
1116 *lpdwBufferLength = 0;
1119 return TRUE;
1122 /***********************************************************************
1123 * InternetGetLastResponseInfoW (WININET.@)
1125 * Return last wininet error description on the calling thread
1127 * RETURNS
1128 * TRUE on success of writing to buffer
1129 * FALSE on failure
1132 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1133 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1135 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1137 TRACE("\n");
1139 if (lpwite)
1141 *lpdwError = lpwite->dwError;
1142 if (lpwite->dwError)
1144 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1145 *lpdwBufferLength = lstrlenW(lpszBuffer);
1147 else
1148 *lpdwBufferLength = 0;
1150 else
1152 *lpdwError = 0;
1153 *lpdwBufferLength = 0;
1156 return TRUE;
1159 /***********************************************************************
1160 * InternetGetConnectedState (WININET.@)
1162 * Return connected state
1164 * RETURNS
1165 * TRUE if connected
1166 * if lpdwStatus is not null, return the status (off line,
1167 * modem, lan...) in it.
1168 * FALSE if not connected
1170 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1172 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1174 if (lpdwStatus) {
1175 WARN("always returning LAN connection.\n");
1176 *lpdwStatus = INTERNET_CONNECTION_LAN;
1178 return TRUE;
1182 /***********************************************************************
1183 * InternetGetConnectedStateExW (WININET.@)
1185 * Return connected state
1187 * PARAMS
1189 * lpdwStatus [O] Flags specifying the status of the internet connection.
1190 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1191 * dwNameLen [I] Size of the buffer, in characters.
1192 * dwReserved [I] Reserved. Must be set to 0.
1194 * RETURNS
1195 * TRUE if connected
1196 * if lpdwStatus is not null, return the status (off line,
1197 * modem, lan...) in it.
1198 * FALSE if not connected
1200 * NOTES
1201 * If the system has no available network connections, an empty string is
1202 * stored in lpszConnectionName. If there is a LAN connection, a localized
1203 * "LAN Connection" string is stored. Presumably, if only a dial-up
1204 * connection is available then the name of the dial-up connection is
1205 * returned. Why any application, other than the "Internet Settings" CPL,
1206 * would want to use this function instead of the simpler InternetGetConnectedStateW
1207 * function is beyond me.
1209 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1210 DWORD dwNameLen, DWORD dwReserved)
1212 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1214 /* Must be zero */
1215 if(dwReserved)
1216 return FALSE;
1218 if (lpdwStatus) {
1219 WARN("always returning LAN connection.\n");
1220 *lpdwStatus = INTERNET_CONNECTION_LAN;
1222 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen) > 0;
1226 /***********************************************************************
1227 * InternetGetConnectedStateExA (WININET.@)
1229 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1230 DWORD dwNameLen, DWORD dwReserved)
1232 LPWSTR lpwszConnectionName = NULL;
1233 BOOL rc;
1235 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1237 if (lpszConnectionName && dwNameLen > 0)
1238 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1240 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1241 dwReserved);
1242 if (rc && lpwszConnectionName)
1244 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1245 dwNameLen, NULL, NULL);
1246 heap_free(lpwszConnectionName);
1248 return rc;
1252 /***********************************************************************
1253 * InternetConnectW (WININET.@)
1255 * Open a ftp, gopher or http session
1257 * RETURNS
1258 * HINTERNET a session handle on success
1259 * NULL on failure
1262 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1263 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1264 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1265 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1267 appinfo_t *hIC;
1268 HINTERNET rc = NULL;
1269 DWORD res = ERROR_SUCCESS;
1271 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1272 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1273 dwService, dwFlags, dwContext);
1275 if (!lpszServerName)
1277 SetLastError(ERROR_INVALID_PARAMETER);
1278 return NULL;
1281 hIC = (appinfo_t*)get_handle_object( hInternet );
1282 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1284 res = ERROR_INVALID_HANDLE;
1285 goto lend;
1288 switch (dwService)
1290 case INTERNET_SERVICE_FTP:
1291 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1292 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1293 if(!rc)
1294 res = INTERNET_GetLastError();
1295 break;
1297 case INTERNET_SERVICE_HTTP:
1298 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1299 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1300 break;
1302 case INTERNET_SERVICE_GOPHER:
1303 default:
1304 break;
1306 lend:
1307 if( hIC )
1308 WININET_Release( &hIC->hdr );
1310 TRACE("returning %p\n", rc);
1311 SetLastError(res);
1312 return rc;
1316 /***********************************************************************
1317 * InternetConnectA (WININET.@)
1319 * Open a ftp, gopher or http session
1321 * RETURNS
1322 * HINTERNET a session handle on success
1323 * NULL on failure
1326 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1327 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1328 LPCSTR lpszUserName, LPCSTR lpszPassword,
1329 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1331 HINTERNET rc = NULL;
1332 LPWSTR szServerName;
1333 LPWSTR szUserName;
1334 LPWSTR szPassword;
1336 szServerName = heap_strdupAtoW(lpszServerName);
1337 szUserName = heap_strdupAtoW(lpszUserName);
1338 szPassword = heap_strdupAtoW(lpszPassword);
1340 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1341 szUserName, szPassword, dwService, dwFlags, dwContext);
1343 heap_free(szServerName);
1344 heap_free(szUserName);
1345 heap_free(szPassword);
1346 return rc;
1350 /***********************************************************************
1351 * InternetFindNextFileA (WININET.@)
1353 * Continues a file search from a previous call to FindFirstFile
1355 * RETURNS
1356 * TRUE on success
1357 * FALSE on failure
1360 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1362 BOOL ret;
1363 WIN32_FIND_DATAW fd;
1365 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1366 if(lpvFindData)
1367 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1368 return ret;
1371 /***********************************************************************
1372 * InternetFindNextFileW (WININET.@)
1374 * Continues a file search from a previous call to FindFirstFile
1376 * RETURNS
1377 * TRUE on success
1378 * FALSE on failure
1381 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1383 object_header_t *hdr;
1384 DWORD res;
1386 TRACE("\n");
1388 hdr = get_handle_object(hFind);
1389 if(!hdr) {
1390 WARN("Invalid handle\n");
1391 SetLastError(ERROR_INVALID_HANDLE);
1392 return FALSE;
1395 if(hdr->vtbl->FindNextFileW) {
1396 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1397 }else {
1398 WARN("Handle doesn't support NextFile\n");
1399 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1402 WININET_Release(hdr);
1404 if(res != ERROR_SUCCESS)
1405 SetLastError(res);
1406 return res == ERROR_SUCCESS;
1409 /***********************************************************************
1410 * InternetCloseHandle (WININET.@)
1412 * Generic close handle function
1414 * RETURNS
1415 * TRUE on success
1416 * FALSE on failure
1419 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1421 object_header_t *obj;
1423 TRACE("%p\n", hInternet);
1425 obj = get_handle_object( hInternet );
1426 if (!obj) {
1427 SetLastError(ERROR_INVALID_HANDLE);
1428 return FALSE;
1431 invalidate_handle(obj);
1432 WININET_Release(obj);
1434 return TRUE;
1438 /***********************************************************************
1439 * ConvertUrlComponentValue (Internal)
1441 * Helper function for InternetCrackUrlA
1444 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1445 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1446 LPCSTR lpszStart, LPCWSTR lpwszStart)
1448 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1449 if (*dwComponentLen != 0)
1451 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1452 if (*lppszComponent == NULL)
1454 if (lpwszComponent)
1456 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1457 *lppszComponent = (LPSTR)lpszStart + offset;
1459 else
1460 *lppszComponent = NULL;
1462 *dwComponentLen = nASCIILength;
1464 else
1466 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1467 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1468 (*lppszComponent)[ncpylen]=0;
1469 *dwComponentLen = ncpylen;
1475 /***********************************************************************
1476 * InternetCrackUrlA (WININET.@)
1478 * See InternetCrackUrlW.
1480 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1481 LPURL_COMPONENTSA lpUrlComponents)
1483 DWORD nLength;
1484 URL_COMPONENTSW UCW;
1485 BOOL ret = FALSE;
1486 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1487 *scheme = NULL, *extra = NULL;
1489 TRACE("(%s %u %x %p)\n",
1490 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1491 dwUrlLength, dwFlags, lpUrlComponents);
1493 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1494 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1496 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1497 return FALSE;
1500 if(dwUrlLength<=0)
1501 dwUrlLength=-1;
1502 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1504 /* if dwUrlLength=-1 then nLength includes null but length to
1505 InternetCrackUrlW should not include it */
1506 if (dwUrlLength == -1) nLength--;
1508 lpwszUrl = heap_alloc((nLength + 1) * sizeof(WCHAR));
1509 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1510 lpwszUrl[nLength] = '\0';
1512 memset(&UCW,0,sizeof(UCW));
1513 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1514 if (lpUrlComponents->dwHostNameLength)
1516 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1517 if (lpUrlComponents->lpszHostName)
1519 hostname = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1520 UCW.lpszHostName = hostname;
1523 if (lpUrlComponents->dwUserNameLength)
1525 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1526 if (lpUrlComponents->lpszUserName)
1528 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1529 UCW.lpszUserName = username;
1532 if (lpUrlComponents->dwPasswordLength)
1534 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1535 if (lpUrlComponents->lpszPassword)
1537 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1538 UCW.lpszPassword = password;
1541 if (lpUrlComponents->dwUrlPathLength)
1543 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1544 if (lpUrlComponents->lpszUrlPath)
1546 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1547 UCW.lpszUrlPath = path;
1550 if (lpUrlComponents->dwSchemeLength)
1552 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1553 if (lpUrlComponents->lpszScheme)
1555 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1556 UCW.lpszScheme = scheme;
1559 if (lpUrlComponents->dwExtraInfoLength)
1561 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1562 if (lpUrlComponents->lpszExtraInfo)
1564 extra = heap_alloc(UCW.dwExtraInfoLength * sizeof(WCHAR));
1565 UCW.lpszExtraInfo = extra;
1568 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1570 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1571 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1572 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1573 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1574 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1575 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1576 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1577 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1578 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1579 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1580 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1581 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1583 lpUrlComponents->nScheme = UCW.nScheme;
1584 lpUrlComponents->nPort = UCW.nPort;
1586 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1587 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1588 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1589 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1590 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1592 heap_free(lpwszUrl);
1593 heap_free(hostname);
1594 heap_free(username);
1595 heap_free(password);
1596 heap_free(path);
1597 heap_free(scheme);
1598 heap_free(extra);
1599 return ret;
1602 static const WCHAR url_schemes[][7] =
1604 {'f','t','p',0},
1605 {'g','o','p','h','e','r',0},
1606 {'h','t','t','p',0},
1607 {'h','t','t','p','s',0},
1608 {'f','i','l','e',0},
1609 {'n','e','w','s',0},
1610 {'m','a','i','l','t','o',0},
1611 {'r','e','s',0},
1614 /***********************************************************************
1615 * GetInternetSchemeW (internal)
1617 * Get scheme of url
1619 * RETURNS
1620 * scheme on success
1621 * INTERNET_SCHEME_UNKNOWN on failure
1624 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1626 int i;
1628 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1630 if(lpszScheme==NULL)
1631 return INTERNET_SCHEME_UNKNOWN;
1633 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1634 if (!strncmpiW(lpszScheme, url_schemes[i], nMaxCmp))
1635 return INTERNET_SCHEME_FIRST + i;
1637 return INTERNET_SCHEME_UNKNOWN;
1640 /***********************************************************************
1641 * SetUrlComponentValueW (Internal)
1643 * Helper function for InternetCrackUrlW
1645 * PARAMS
1646 * lppszComponent [O] Holds the returned string
1647 * dwComponentLen [I] Holds the size of lppszComponent
1648 * [O] Holds the length of the string in lppszComponent without '\0'
1649 * lpszStart [I] Holds the string to copy from
1650 * len [I] Holds the length of lpszStart without '\0'
1652 * RETURNS
1653 * TRUE on success
1654 * FALSE on failure
1657 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1659 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1661 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1662 return FALSE;
1664 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1666 if (*lppszComponent == NULL)
1668 *lppszComponent = (LPWSTR)lpszStart;
1669 *dwComponentLen = len;
1671 else
1673 DWORD ncpylen = min((*dwComponentLen)-1, len);
1674 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1675 (*lppszComponent)[ncpylen] = '\0';
1676 *dwComponentLen = ncpylen;
1680 return TRUE;
1683 /***********************************************************************
1684 * InternetCrackUrlW (WININET.@)
1686 * Break up URL into its components
1688 * RETURNS
1689 * TRUE on success
1690 * FALSE on failure
1692 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1693 LPURL_COMPONENTSW lpUC)
1696 * RFC 1808
1697 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1700 LPCWSTR lpszParam = NULL;
1701 BOOL found_colon = FALSE;
1702 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1703 LPCWSTR lpszcp = NULL, lpszNetLoc;
1704 LPWSTR lpszUrl_decode = NULL;
1705 DWORD dwUrlLength = dwUrlLength_orig;
1707 TRACE("(%s %u %x %p)\n",
1708 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1709 dwUrlLength, dwFlags, lpUC);
1711 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1713 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1714 return FALSE;
1716 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1718 if (dwFlags & ICU_DECODE)
1720 WCHAR *url_tmp;
1721 DWORD len = dwUrlLength + 1;
1723 if (!(url_tmp = heap_alloc(len * sizeof(WCHAR))))
1725 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1726 return FALSE;
1728 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1729 url_tmp[dwUrlLength] = 0;
1730 if (!(lpszUrl_decode = heap_alloc(len * sizeof(WCHAR))))
1732 heap_free(url_tmp);
1733 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1734 return FALSE;
1736 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1738 dwUrlLength = len;
1739 lpszUrl = lpszUrl_decode;
1741 heap_free(url_tmp);
1743 lpszap = lpszUrl;
1745 /* Determine if the URI is absolute. */
1746 while (lpszap - lpszUrl < dwUrlLength)
1748 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1750 lpszap++;
1751 continue;
1753 if (*lpszap == ':')
1755 found_colon = TRUE;
1756 lpszcp = lpszap;
1758 else
1760 lpszcp = lpszUrl; /* Relative url */
1763 break;
1766 if(!found_colon){
1767 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1768 return 0;
1771 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1772 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1774 /* Parse <params> */
1775 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1776 if(!lpszParam)
1777 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1779 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1780 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1783 /* Get scheme first. */
1784 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1785 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1786 lpszUrl, lpszcp - lpszUrl);
1788 /* Eat ':' in protocol. */
1789 lpszcp++;
1791 /* double slash indicates the net_loc portion is present */
1792 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1794 lpszcp += 2;
1796 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1797 if (lpszParam)
1799 if (lpszNetLoc)
1800 lpszNetLoc = min(lpszNetLoc, lpszParam);
1801 else
1802 lpszNetLoc = lpszParam;
1804 else if (!lpszNetLoc)
1805 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1807 /* Parse net-loc */
1808 if (lpszNetLoc)
1810 LPCWSTR lpszHost;
1811 LPCWSTR lpszPort;
1813 /* [<user>[<:password>]@]<host>[:<port>] */
1814 /* First find the user and password if they exist */
1816 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1817 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1819 /* username and password not specified. */
1820 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1821 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1823 else /* Parse out username and password */
1825 LPCWSTR lpszUser = lpszcp;
1826 LPCWSTR lpszPasswd = lpszHost;
1828 while (lpszcp < lpszHost)
1830 if (*lpszcp == ':')
1831 lpszPasswd = lpszcp;
1833 lpszcp++;
1836 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1837 lpszUser, lpszPasswd - lpszUser);
1839 if (lpszPasswd != lpszHost)
1840 lpszPasswd++;
1841 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1842 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1843 lpszHost - lpszPasswd);
1845 lpszcp++; /* Advance to beginning of host */
1848 /* Parse <host><:port> */
1850 lpszHost = lpszcp;
1851 lpszPort = lpszNetLoc;
1853 /* special case for res:// URLs: there is no port here, so the host is the
1854 entire string up to the first '/' */
1855 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1857 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1858 lpszHost, lpszPort - lpszHost);
1859 lpszcp=lpszNetLoc;
1861 else
1863 while (lpszcp < lpszNetLoc)
1865 if (*lpszcp == ':')
1866 lpszPort = lpszcp;
1868 lpszcp++;
1871 /* If the scheme is "file" and the host is just one letter, it's not a host */
1872 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1874 lpszcp=lpszHost;
1875 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1876 NULL, 0);
1878 else
1880 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1881 lpszHost, lpszPort - lpszHost);
1882 if (lpszPort != lpszNetLoc)
1883 lpUC->nPort = atoiW(++lpszPort);
1884 else switch (lpUC->nScheme)
1886 case INTERNET_SCHEME_HTTP:
1887 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1888 break;
1889 case INTERNET_SCHEME_HTTPS:
1890 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1891 break;
1892 case INTERNET_SCHEME_FTP:
1893 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1894 break;
1895 case INTERNET_SCHEME_GOPHER:
1896 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1897 break;
1898 default:
1899 break;
1905 else
1907 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1908 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1909 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1912 /* Here lpszcp points to:
1914 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1915 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1917 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1919 DWORD len;
1921 /* Only truncate the parameter list if it's already been saved
1922 * in lpUC->lpszExtraInfo.
1924 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1925 len = lpszParam - lpszcp;
1926 else
1928 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1929 * newlines if necessary.
1931 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1932 if (lpsznewline != NULL)
1933 len = lpsznewline - lpszcp;
1934 else
1935 len = dwUrlLength-(lpszcp-lpszUrl);
1937 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1938 lpUC->nScheme == INTERNET_SCHEME_FILE)
1940 WCHAR tmppath[MAX_PATH];
1941 if (*lpszcp == '/')
1943 len = MAX_PATH;
1944 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
1946 else
1948 WCHAR *iter;
1949 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1950 tmppath[len] = '\0';
1952 iter = tmppath;
1953 while (*iter) {
1954 if (*iter == '/')
1955 *iter = '\\';
1956 ++iter;
1959 /* if ends in \. or \.. append a backslash */
1960 if (tmppath[len - 1] == '.' &&
1961 (tmppath[len - 2] == '\\' ||
1962 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1964 if (len < MAX_PATH - 1)
1966 tmppath[len] = '\\';
1967 tmppath[len+1] = '\0';
1968 ++len;
1971 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1972 tmppath, len);
1974 else
1975 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1976 lpszcp, len);
1978 else
1980 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1981 lpUC->lpszUrlPath[0] = 0;
1982 lpUC->dwUrlPathLength = 0;
1985 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1986 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1987 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1988 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1989 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1991 heap_free( lpszUrl_decode );
1992 return TRUE;
1995 /***********************************************************************
1996 * InternetAttemptConnect (WININET.@)
1998 * Attempt to make a connection to the internet
2000 * RETURNS
2001 * ERROR_SUCCESS on success
2002 * Error value on failure
2005 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
2007 FIXME("Stub\n");
2008 return ERROR_SUCCESS;
2012 /***********************************************************************
2013 * convert_url_canonicalization_flags
2015 * Helper for InternetCanonicalizeUrl
2017 * PARAMS
2018 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2020 * RETURNS
2021 * Flags suitable for UrlCanonicalize
2023 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
2025 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
2027 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
2028 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
2029 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
2030 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
2031 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2032 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
2033 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
2035 return dwUrlFlags;
2038 /***********************************************************************
2039 * InternetCanonicalizeUrlA (WININET.@)
2041 * Escape unsafe characters and spaces
2043 * RETURNS
2044 * TRUE on success
2045 * FALSE on failure
2048 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
2049 LPDWORD lpdwBufferLength, DWORD dwFlags)
2051 HRESULT hr;
2053 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
2054 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2056 dwFlags = convert_url_canonicalization_flags(dwFlags);
2057 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2058 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2059 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2061 return hr == S_OK;
2064 /***********************************************************************
2065 * InternetCanonicalizeUrlW (WININET.@)
2067 * Escape unsafe characters and spaces
2069 * RETURNS
2070 * TRUE on success
2071 * FALSE on failure
2074 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
2075 LPDWORD lpdwBufferLength, DWORD dwFlags)
2077 HRESULT hr;
2079 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2080 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2082 dwFlags = convert_url_canonicalization_flags(dwFlags);
2083 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2084 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2085 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2087 return hr == S_OK;
2090 /* #################################################### */
2092 static INTERNET_STATUS_CALLBACK set_status_callback(
2093 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2095 INTERNET_STATUS_CALLBACK ret;
2097 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2098 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2100 ret = lpwh->lpfnStatusCB;
2101 lpwh->lpfnStatusCB = callback;
2103 return ret;
2106 /***********************************************************************
2107 * InternetSetStatusCallbackA (WININET.@)
2109 * Sets up a callback function which is called as progress is made
2110 * during an operation.
2112 * RETURNS
2113 * Previous callback or NULL on success
2114 * INTERNET_INVALID_STATUS_CALLBACK on failure
2117 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2118 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2120 INTERNET_STATUS_CALLBACK retVal;
2121 object_header_t *lpwh;
2123 TRACE("%p\n", hInternet);
2125 if (!(lpwh = get_handle_object(hInternet)))
2126 return INTERNET_INVALID_STATUS_CALLBACK;
2128 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2130 WININET_Release( lpwh );
2131 return retVal;
2134 /***********************************************************************
2135 * InternetSetStatusCallbackW (WININET.@)
2137 * Sets up a callback function which is called as progress is made
2138 * during an operation.
2140 * RETURNS
2141 * Previous callback or NULL on success
2142 * INTERNET_INVALID_STATUS_CALLBACK on failure
2145 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2146 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2148 INTERNET_STATUS_CALLBACK retVal;
2149 object_header_t *lpwh;
2151 TRACE("%p\n", hInternet);
2153 if (!(lpwh = get_handle_object(hInternet)))
2154 return INTERNET_INVALID_STATUS_CALLBACK;
2156 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2158 WININET_Release( lpwh );
2159 return retVal;
2162 /***********************************************************************
2163 * InternetSetFilePointer (WININET.@)
2165 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2166 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2168 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2169 return FALSE;
2172 /***********************************************************************
2173 * InternetWriteFile (WININET.@)
2175 * Write data to an open internet file
2177 * RETURNS
2178 * TRUE on success
2179 * FALSE on failure
2182 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2183 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2185 object_header_t *lpwh;
2186 BOOL res;
2188 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2190 lpwh = get_handle_object( hFile );
2191 if (!lpwh) {
2192 WARN("Invalid handle\n");
2193 SetLastError(ERROR_INVALID_HANDLE);
2194 return FALSE;
2197 if(lpwh->vtbl->WriteFile) {
2198 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2199 }else {
2200 WARN("No Writefile method.\n");
2201 res = ERROR_INVALID_HANDLE;
2204 WININET_Release( lpwh );
2206 if(res != ERROR_SUCCESS)
2207 SetLastError(res);
2208 return res == ERROR_SUCCESS;
2212 /***********************************************************************
2213 * InternetReadFile (WININET.@)
2215 * Read data from an open internet file
2217 * RETURNS
2218 * TRUE on success
2219 * FALSE on failure
2222 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2223 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2225 object_header_t *hdr;
2226 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2228 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2230 hdr = get_handle_object(hFile);
2231 if (!hdr) {
2232 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2233 return FALSE;
2236 if(hdr->vtbl->ReadFile)
2237 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2239 WININET_Release(hdr);
2241 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2242 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2244 if(res != ERROR_SUCCESS)
2245 SetLastError(res);
2246 return res == ERROR_SUCCESS;
2249 /***********************************************************************
2250 * InternetReadFileExA (WININET.@)
2252 * Read data from an open internet file
2254 * PARAMS
2255 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2256 * lpBuffersOut [I/O] Buffer.
2257 * dwFlags [I] Flags. See notes.
2258 * dwContext [I] Context for callbacks.
2260 * RETURNS
2261 * TRUE on success
2262 * FALSE on failure
2264 * NOTES
2265 * The parameter dwFlags include zero or more of the following flags:
2266 *|IRF_ASYNC - Makes the call asynchronous.
2267 *|IRF_SYNC - Makes the call synchronous.
2268 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2269 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2271 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2273 * SEE
2274 * InternetOpenUrlA(), HttpOpenRequestA()
2276 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2277 DWORD dwFlags, DWORD_PTR dwContext)
2279 object_header_t *hdr;
2280 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2282 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2284 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2285 SetLastError(ERROR_INVALID_PARAMETER);
2286 return FALSE;
2289 hdr = get_handle_object(hFile);
2290 if (!hdr) {
2291 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2292 return FALSE;
2295 if(hdr->vtbl->ReadFileEx)
2296 res = hdr->vtbl->ReadFileEx(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2297 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2299 WININET_Release(hdr);
2301 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2302 res, lpBuffersOut->dwBufferLength);
2304 if(res != ERROR_SUCCESS)
2305 SetLastError(res);
2306 return res == ERROR_SUCCESS;
2309 /***********************************************************************
2310 * InternetReadFileExW (WININET.@)
2311 * SEE
2312 * InternetReadFileExA()
2314 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2315 DWORD dwFlags, DWORD_PTR dwContext)
2317 object_header_t *hdr;
2318 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2320 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2322 if (lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2323 SetLastError(ERROR_INVALID_PARAMETER);
2324 return FALSE;
2327 hdr = get_handle_object(hFile);
2328 if (!hdr) {
2329 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2330 return FALSE;
2333 if(hdr->vtbl->ReadFileEx)
2334 res = hdr->vtbl->ReadFileEx(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2335 dwFlags, dwContext);
2337 WININET_Release(hdr);
2339 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2340 res, lpBuffer->dwBufferLength);
2342 if(res != ERROR_SUCCESS)
2343 SetLastError(res);
2344 return res == ERROR_SUCCESS;
2347 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2349 /* FIXME: This function currently handles more options than it should. Options requiring
2350 * proper handles should be moved to proper functions */
2351 switch(option) {
2352 case INTERNET_OPTION_HTTP_VERSION:
2353 if (*size < sizeof(HTTP_VERSION_INFO))
2354 return ERROR_INSUFFICIENT_BUFFER;
2357 * Presently hardcoded to 1.1
2359 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2360 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2361 *size = sizeof(HTTP_VERSION_INFO);
2363 return ERROR_SUCCESS;
2365 case INTERNET_OPTION_CONNECTED_STATE:
2366 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2368 if (*size < sizeof(ULONG))
2369 return ERROR_INSUFFICIENT_BUFFER;
2371 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2372 *size = sizeof(ULONG);
2374 return ERROR_SUCCESS;
2376 case INTERNET_OPTION_PROXY: {
2377 appinfo_t ai;
2378 BOOL ret;
2380 TRACE("Getting global proxy info\n");
2381 memset(&ai, 0, sizeof(appinfo_t));
2382 INTERNET_ConfigureProxy(&ai);
2384 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2385 APPINFO_Destroy(&ai.hdr);
2386 return ret;
2389 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2390 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2392 if (*size < sizeof(ULONG))
2393 return ERROR_INSUFFICIENT_BUFFER;
2395 *(ULONG*)buffer = max_conns;
2396 *size = sizeof(ULONG);
2398 return ERROR_SUCCESS;
2400 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2401 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2403 if (*size < sizeof(ULONG))
2404 return ERROR_INSUFFICIENT_BUFFER;
2406 *(ULONG*)buffer = max_1_0_conns;
2407 *size = sizeof(ULONG);
2409 return ERROR_SUCCESS;
2411 case INTERNET_OPTION_SECURITY_FLAGS:
2412 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2413 return ERROR_SUCCESS;
2415 case INTERNET_OPTION_VERSION: {
2416 static const INTERNET_VERSION_INFO info = { 1, 2 };
2418 TRACE("INTERNET_OPTION_VERSION\n");
2420 if (*size < sizeof(INTERNET_VERSION_INFO))
2421 return ERROR_INSUFFICIENT_BUFFER;
2423 memcpy(buffer, &info, sizeof(info));
2424 *size = sizeof(info);
2426 return ERROR_SUCCESS;
2429 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2430 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2431 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2432 DWORD res = ERROR_SUCCESS, i;
2433 proxyinfo_t pi;
2434 LONG ret;
2436 TRACE("Getting global proxy info\n");
2437 if((ret = INTERNET_LoadProxySettings(&pi)))
2438 return ret;
2440 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2442 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2443 FreeProxyInfo(&pi);
2444 return ERROR_INSUFFICIENT_BUFFER;
2447 for (i = 0; i < con->dwOptionCount; i++) {
2448 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2449 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2451 switch (optionW->dwOption) {
2452 case INTERNET_PER_CONN_FLAGS:
2453 if(pi.proxyEnabled)
2454 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2455 else
2456 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2457 break;
2459 case INTERNET_PER_CONN_PROXY_SERVER:
2460 if (unicode)
2461 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2462 else
2463 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2464 break;
2466 case INTERNET_PER_CONN_PROXY_BYPASS:
2467 if (unicode)
2468 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2469 else
2470 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2471 break;
2473 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2474 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2475 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2476 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2477 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2478 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2479 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2480 memset(&optionW->Value, 0, sizeof(optionW->Value));
2481 break;
2483 default:
2484 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2485 res = ERROR_INVALID_PARAMETER;
2486 break;
2489 FreeProxyInfo(&pi);
2491 return res;
2493 case INTERNET_OPTION_REQUEST_FLAGS:
2494 case INTERNET_OPTION_USER_AGENT:
2495 *size = 0;
2496 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2497 case INTERNET_OPTION_POLICY:
2498 return ERROR_INVALID_PARAMETER;
2499 case INTERNET_OPTION_CONNECT_TIMEOUT:
2500 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2502 if (*size < sizeof(ULONG))
2503 return ERROR_INSUFFICIENT_BUFFER;
2505 *(ULONG*)buffer = connect_timeout;
2506 *size = sizeof(ULONG);
2508 return ERROR_SUCCESS;
2511 FIXME("Stub for %d\n", option);
2512 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2515 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2517 switch(option) {
2518 case INTERNET_OPTION_CONTEXT_VALUE:
2519 if (!size)
2520 return ERROR_INVALID_PARAMETER;
2522 if (*size < sizeof(DWORD_PTR)) {
2523 *size = sizeof(DWORD_PTR);
2524 return ERROR_INSUFFICIENT_BUFFER;
2526 if (!buffer)
2527 return ERROR_INVALID_PARAMETER;
2529 *(DWORD_PTR *)buffer = hdr->dwContext;
2530 *size = sizeof(DWORD_PTR);
2531 return ERROR_SUCCESS;
2533 case INTERNET_OPTION_REQUEST_FLAGS:
2534 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2535 *size = sizeof(DWORD);
2536 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2538 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2539 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2540 WARN("Called on global option %u\n", option);
2541 return ERROR_INTERNET_INVALID_OPERATION;
2544 /* FIXME: we shouldn't call it here */
2545 return query_global_option(option, buffer, size, unicode);
2548 /***********************************************************************
2549 * InternetQueryOptionW (WININET.@)
2551 * Queries an options on the specified handle
2553 * RETURNS
2554 * TRUE on success
2555 * FALSE on failure
2558 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2559 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2561 object_header_t *hdr;
2562 DWORD res = ERROR_INVALID_HANDLE;
2564 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2566 if(hInternet) {
2567 hdr = get_handle_object(hInternet);
2568 if (hdr) {
2569 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2570 WININET_Release(hdr);
2572 }else {
2573 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2576 if(res != ERROR_SUCCESS)
2577 SetLastError(res);
2578 return res == ERROR_SUCCESS;
2581 /***********************************************************************
2582 * InternetQueryOptionA (WININET.@)
2584 * Queries an options on the specified handle
2586 * RETURNS
2587 * TRUE on success
2588 * FALSE on failure
2591 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2592 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2594 object_header_t *hdr;
2595 DWORD res = ERROR_INVALID_HANDLE;
2597 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2599 if(hInternet) {
2600 hdr = get_handle_object(hInternet);
2601 if (hdr) {
2602 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2603 WININET_Release(hdr);
2605 }else {
2606 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2609 if(res != ERROR_SUCCESS)
2610 SetLastError(res);
2611 return res == ERROR_SUCCESS;
2614 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2616 switch(option) {
2617 case INTERNET_OPTION_CALLBACK:
2618 WARN("Not settable option %u\n", option);
2619 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2620 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2621 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2622 WARN("Called on global option %u\n", option);
2623 return ERROR_INTERNET_INVALID_OPERATION;
2626 return ERROR_INTERNET_INVALID_OPTION;
2629 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2631 switch(option) {
2632 case INTERNET_OPTION_CALLBACK:
2633 WARN("Not global option %u\n", option);
2634 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2636 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2637 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2639 if(size != sizeof(max_conns))
2640 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2641 if(!*(ULONG*)buf)
2642 return ERROR_BAD_ARGUMENTS;
2644 max_conns = *(ULONG*)buf;
2645 return ERROR_SUCCESS;
2647 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2648 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2650 if(size != sizeof(max_1_0_conns))
2651 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2652 if(!*(ULONG*)buf)
2653 return ERROR_BAD_ARGUMENTS;
2655 max_1_0_conns = *(ULONG*)buf;
2656 return ERROR_SUCCESS;
2658 case INTERNET_OPTION_CONNECT_TIMEOUT:
2659 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2661 if(size != sizeof(connect_timeout))
2662 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2663 if(!*(ULONG*)buf)
2664 return ERROR_BAD_ARGUMENTS;
2666 connect_timeout = *(ULONG*)buf;
2667 return ERROR_SUCCESS;
2669 case INTERNET_OPTION_SETTINGS_CHANGED:
2670 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2671 collect_connections(COLLECT_CONNECTIONS);
2672 return ERROR_SUCCESS;
2675 return ERROR_INTERNET_INVALID_OPTION;
2678 /***********************************************************************
2679 * InternetSetOptionW (WININET.@)
2681 * Sets an options on the specified handle
2683 * RETURNS
2684 * TRUE on success
2685 * FALSE on failure
2688 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2689 LPVOID lpBuffer, DWORD dwBufferLength)
2691 object_header_t *lpwhh;
2692 BOOL ret = TRUE;
2693 DWORD res;
2695 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2697 lpwhh = (object_header_t*) get_handle_object( hInternet );
2698 if(lpwhh)
2699 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2700 else
2701 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2703 if(res != ERROR_INTERNET_INVALID_OPTION) {
2704 if(lpwhh)
2705 WININET_Release(lpwhh);
2707 if(res != ERROR_SUCCESS)
2708 SetLastError(res);
2710 return res == ERROR_SUCCESS;
2713 switch (dwOption)
2715 case INTERNET_OPTION_HTTP_VERSION:
2717 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2718 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2720 break;
2721 case INTERNET_OPTION_ERROR_MASK:
2723 if(!lpwhh) {
2724 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2725 return FALSE;
2726 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2727 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2728 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2729 SetLastError(ERROR_INVALID_PARAMETER);
2730 ret = FALSE;
2731 } else if(dwBufferLength != sizeof(ULONG)) {
2732 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2733 ret = FALSE;
2734 } else
2735 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2736 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2738 break;
2739 case INTERNET_OPTION_PROXY:
2741 INTERNET_PROXY_INFOW *info = lpBuffer;
2743 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2745 SetLastError(ERROR_INVALID_PARAMETER);
2746 return FALSE;
2748 if (!hInternet)
2750 EnterCriticalSection( &WININET_cs );
2751 free_global_proxy();
2752 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2753 if (global_proxy)
2755 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2757 global_proxy->proxyEnabled = 1;
2758 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2759 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2761 else
2763 global_proxy->proxyEnabled = 0;
2764 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2767 LeaveCriticalSection( &WININET_cs );
2769 else
2771 /* In general, each type of object should handle
2772 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2773 * get silently dropped.
2775 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2776 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2777 ret = FALSE;
2779 break;
2781 case INTERNET_OPTION_CODEPAGE:
2783 ULONG codepage = *(ULONG *)lpBuffer;
2784 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2786 break;
2787 case INTERNET_OPTION_REQUEST_PRIORITY:
2789 ULONG priority = *(ULONG *)lpBuffer;
2790 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2792 break;
2793 case INTERNET_OPTION_CONNECT_TIMEOUT:
2795 ULONG connecttimeout = *(ULONG *)lpBuffer;
2796 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2798 break;
2799 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2801 ULONG receivetimeout = *(ULONG *)lpBuffer;
2802 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2804 break;
2805 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2806 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2807 break;
2808 case INTERNET_OPTION_END_BROWSER_SESSION:
2809 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2810 break;
2811 case INTERNET_OPTION_CONNECTED_STATE:
2812 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2813 break;
2814 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2815 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2816 break;
2817 case INTERNET_OPTION_SEND_TIMEOUT:
2818 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2819 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2821 ULONG timeout = *(ULONG *)lpBuffer;
2822 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2823 break;
2825 case INTERNET_OPTION_CONNECT_RETRIES:
2827 ULONG retries = *(ULONG *)lpBuffer;
2828 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2829 break;
2831 case INTERNET_OPTION_CONTEXT_VALUE:
2833 if (!lpwhh)
2835 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2836 return FALSE;
2838 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2840 SetLastError(ERROR_INVALID_PARAMETER);
2841 ret = FALSE;
2843 else
2844 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2845 break;
2847 case INTERNET_OPTION_SECURITY_FLAGS:
2848 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2849 break;
2850 case INTERNET_OPTION_DISABLE_AUTODIAL:
2851 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2852 break;
2853 case INTERNET_OPTION_HTTP_DECODING:
2854 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2855 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2856 ret = FALSE;
2857 break;
2858 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2859 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2860 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2861 ret = FALSE;
2862 break;
2863 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2864 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2865 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2866 ret = FALSE;
2867 break;
2868 case INTERNET_OPTION_CODEPAGE_PATH:
2869 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2870 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2871 ret = FALSE;
2872 break;
2873 case INTERNET_OPTION_CODEPAGE_EXTRA:
2874 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2875 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2876 ret = FALSE;
2877 break;
2878 case INTERNET_OPTION_IDN:
2879 FIXME("INTERNET_OPTION_IDN; STUB\n");
2880 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2881 ret = FALSE;
2882 break;
2883 case INTERNET_OPTION_POLICY:
2884 SetLastError(ERROR_INVALID_PARAMETER);
2885 ret = FALSE;
2886 break;
2887 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2888 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2889 LONG res;
2890 unsigned int i;
2891 proxyinfo_t pi;
2893 INTERNET_LoadProxySettings(&pi);
2895 for (i = 0; i < con->dwOptionCount; i++) {
2896 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2898 switch (option->dwOption) {
2899 case INTERNET_PER_CONN_PROXY_SERVER:
2900 heap_free(pi.proxy);
2901 pi.proxy = heap_strdupW(option->Value.pszValue);
2902 break;
2904 case INTERNET_PER_CONN_FLAGS:
2905 if(option->Value.dwValue & PROXY_TYPE_PROXY)
2906 pi.proxyEnabled = 1;
2907 else
2909 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
2910 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
2911 pi.proxyEnabled = 0;
2913 break;
2915 case INTERNET_PER_CONN_PROXY_BYPASS:
2916 heap_free(pi.proxyBypass);
2917 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
2918 break;
2920 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2921 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2922 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2923 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2924 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2925 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2926 FIXME("Unhandled dwOption %d\n", option->dwOption);
2927 break;
2929 default:
2930 FIXME("Unknown dwOption %d\n", option->dwOption);
2931 SetLastError(ERROR_INVALID_PARAMETER);
2932 break;
2936 if ((res = INTERNET_SaveProxySettings(&pi)))
2937 SetLastError(res);
2939 FreeProxyInfo(&pi);
2941 ret = (res == ERROR_SUCCESS);
2942 break;
2944 default:
2945 FIXME("Option %d STUB\n",dwOption);
2946 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2947 ret = FALSE;
2948 break;
2951 if(lpwhh)
2952 WININET_Release( lpwhh );
2954 return ret;
2958 /***********************************************************************
2959 * InternetSetOptionA (WININET.@)
2961 * Sets an options on the specified handle.
2963 * RETURNS
2964 * TRUE on success
2965 * FALSE on failure
2968 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2969 LPVOID lpBuffer, DWORD dwBufferLength)
2971 LPVOID wbuffer;
2972 DWORD wlen;
2973 BOOL r;
2975 switch( dwOption )
2977 case INTERNET_OPTION_PROXY:
2979 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2980 LPINTERNET_PROXY_INFOW piw;
2981 DWORD proxlen, prbylen;
2982 LPWSTR prox, prby;
2984 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2985 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2986 wlen = sizeof(*piw) + proxlen + prbylen;
2987 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2988 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2989 piw->dwAccessType = pi->dwAccessType;
2990 prox = (LPWSTR) &piw[1];
2991 prby = &prox[proxlen+1];
2992 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2993 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2994 piw->lpszProxy = prox;
2995 piw->lpszProxyBypass = prby;
2997 break;
2998 case INTERNET_OPTION_USER_AGENT:
2999 case INTERNET_OPTION_USERNAME:
3000 case INTERNET_OPTION_PASSWORD:
3001 case INTERNET_OPTION_PROXY_USERNAME:
3002 case INTERNET_OPTION_PROXY_PASSWORD:
3003 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3004 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3005 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3006 break;
3007 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3008 unsigned int i;
3009 INTERNET_PER_CONN_OPTION_LISTW *listW;
3010 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3011 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3012 wbuffer = heap_alloc(wlen);
3013 listW = wbuffer;
3015 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3016 if (listA->pszConnection)
3018 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3019 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3020 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3022 else
3023 listW->pszConnection = NULL;
3024 listW->dwOptionCount = listA->dwOptionCount;
3025 listW->dwOptionError = listA->dwOptionError;
3026 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3028 for (i = 0; i < listA->dwOptionCount; ++i) {
3029 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3030 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3032 optW->dwOption = optA->dwOption;
3034 switch (optA->dwOption) {
3035 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3036 case INTERNET_PER_CONN_PROXY_BYPASS:
3037 case INTERNET_PER_CONN_PROXY_SERVER:
3038 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3039 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3040 if (optA->Value.pszValue)
3042 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3043 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3044 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3046 else
3047 optW->Value.pszValue = NULL;
3048 break;
3049 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3050 case INTERNET_PER_CONN_FLAGS:
3051 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3052 optW->Value.dwValue = optA->Value.dwValue;
3053 break;
3054 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3055 optW->Value.ftValue = optA->Value.ftValue;
3056 break;
3057 default:
3058 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3059 optW->Value.dwValue = optA->Value.dwValue;
3060 break;
3064 break;
3065 default:
3066 wbuffer = lpBuffer;
3067 wlen = dwBufferLength;
3070 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3072 if( lpBuffer != wbuffer )
3074 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3076 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3077 unsigned int i;
3078 for (i = 0; i < list->dwOptionCount; ++i) {
3079 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3080 switch (opt->dwOption) {
3081 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3082 case INTERNET_PER_CONN_PROXY_BYPASS:
3083 case INTERNET_PER_CONN_PROXY_SERVER:
3084 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3085 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3086 heap_free( opt->Value.pszValue );
3087 break;
3088 default:
3089 break;
3092 heap_free( list->pOptions );
3094 heap_free( wbuffer );
3097 return r;
3101 /***********************************************************************
3102 * InternetSetOptionExA (WININET.@)
3104 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3105 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3107 FIXME("Flags %08x ignored\n", dwFlags);
3108 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3111 /***********************************************************************
3112 * InternetSetOptionExW (WININET.@)
3114 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3115 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3117 FIXME("Flags %08x ignored\n", dwFlags);
3118 if( dwFlags & ~ISO_VALID_FLAGS )
3120 SetLastError( ERROR_INVALID_PARAMETER );
3121 return FALSE;
3123 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3126 static const WCHAR WININET_wkday[7][4] =
3127 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3128 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3129 static const WCHAR WININET_month[12][4] =
3130 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3131 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3132 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3134 /***********************************************************************
3135 * InternetTimeFromSystemTimeA (WININET.@)
3137 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3139 BOOL ret;
3140 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3142 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3144 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3146 SetLastError(ERROR_INVALID_PARAMETER);
3147 return FALSE;
3150 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3152 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3153 return FALSE;
3156 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3157 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3159 return ret;
3162 /***********************************************************************
3163 * InternetTimeFromSystemTimeW (WININET.@)
3165 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3167 static const WCHAR date[] =
3168 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3169 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3171 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3173 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3175 SetLastError(ERROR_INVALID_PARAMETER);
3176 return FALSE;
3179 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3181 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3182 return FALSE;
3185 sprintfW( string, date,
3186 WININET_wkday[time->wDayOfWeek],
3187 time->wDay,
3188 WININET_month[time->wMonth - 1],
3189 time->wYear,
3190 time->wHour,
3191 time->wMinute,
3192 time->wSecond );
3194 return TRUE;
3197 /***********************************************************************
3198 * InternetTimeToSystemTimeA (WININET.@)
3200 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3202 BOOL ret = FALSE;
3203 WCHAR *stringW;
3205 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3207 stringW = heap_strdupAtoW(string);
3208 if (stringW)
3210 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3211 heap_free( stringW );
3213 return ret;
3216 /***********************************************************************
3217 * InternetTimeToSystemTimeW (WININET.@)
3219 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3221 unsigned int i;
3222 const WCHAR *s = string;
3223 WCHAR *end;
3225 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3227 if (!string || !time) return FALSE;
3229 /* Windows does this too */
3230 GetSystemTime( time );
3232 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3233 * a SYSTEMTIME structure.
3236 while (*s && !isalphaW( *s )) s++;
3237 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3238 time->wDayOfWeek = 7;
3240 for (i = 0; i < 7; i++)
3242 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3243 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3244 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3246 time->wDayOfWeek = i;
3247 break;
3251 if (time->wDayOfWeek > 6) return TRUE;
3252 while (*s && !isdigitW( *s )) s++;
3253 time->wDay = strtolW( s, &end, 10 );
3254 s = end;
3256 while (*s && !isalphaW( *s )) s++;
3257 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3258 time->wMonth = 0;
3260 for (i = 0; i < 12; i++)
3262 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3263 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3264 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3266 time->wMonth = i + 1;
3267 break;
3270 if (time->wMonth == 0) return TRUE;
3272 while (*s && !isdigitW( *s )) s++;
3273 if (*s == '\0') return TRUE;
3274 time->wYear = strtolW( s, &end, 10 );
3275 s = end;
3277 while (*s && !isdigitW( *s )) s++;
3278 if (*s == '\0') return TRUE;
3279 time->wHour = strtolW( s, &end, 10 );
3280 s = end;
3282 while (*s && !isdigitW( *s )) s++;
3283 if (*s == '\0') return TRUE;
3284 time->wMinute = strtolW( s, &end, 10 );
3285 s = end;
3287 while (*s && !isdigitW( *s )) s++;
3288 if (*s == '\0') return TRUE;
3289 time->wSecond = strtolW( s, &end, 10 );
3290 s = end;
3292 time->wMilliseconds = 0;
3293 return TRUE;
3296 /***********************************************************************
3297 * InternetCheckConnectionW (WININET.@)
3299 * Pings a requested host to check internet connection
3301 * RETURNS
3302 * TRUE on success and FALSE on failure. If a failure then
3303 * ERROR_NOT_CONNECTED is placed into GetLastError
3306 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3309 * this is a kludge which runs the resident ping program and reads the output.
3311 * Anyone have a better idea?
3314 BOOL rc = FALSE;
3315 static const CHAR ping[] = "ping -c 1 ";
3316 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3317 CHAR *command = NULL;
3318 WCHAR hostW[INTERNET_MAX_HOST_NAME_LENGTH];
3319 DWORD len;
3320 INTERNET_PORT port;
3321 int status = -1;
3323 FIXME("\n");
3326 * Crack or set the Address
3328 if (lpszUrl == NULL)
3331 * According to the doc we are supposed to use the ip for the next
3332 * server in the WnInet internal server database. I have
3333 * no idea what that is or how to get it.
3335 * So someone needs to implement this.
3337 FIXME("Unimplemented with URL of NULL\n");
3338 return TRUE;
3340 else
3342 URL_COMPONENTSW components;
3344 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3345 components.lpszHostName = (LPWSTR)hostW;
3346 components.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3348 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3349 goto End;
3351 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3352 port = components.nPort;
3353 TRACE("port: %d\n", port);
3356 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3358 struct sockaddr_storage saddr;
3359 socklen_t sa_len = sizeof(saddr);
3360 int fd;
3362 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3363 goto End;
3364 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3365 if (fd != -1)
3367 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3368 rc = TRUE;
3369 close(fd);
3372 else
3375 * Build our ping command
3377 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3378 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3379 strcpy(command,ping);
3380 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3381 strcat(command,redirect);
3383 TRACE("Ping command is : %s\n",command);
3385 status = system(command);
3387 TRACE("Ping returned a code of %i\n",status);
3389 /* Ping return code of 0 indicates success */
3390 if (status == 0)
3391 rc = TRUE;
3394 End:
3395 heap_free( command );
3396 if (rc == FALSE)
3397 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3399 return rc;
3403 /***********************************************************************
3404 * InternetCheckConnectionA (WININET.@)
3406 * Pings a requested host to check internet connection
3408 * RETURNS
3409 * TRUE on success and FALSE on failure. If a failure then
3410 * ERROR_NOT_CONNECTED is placed into GetLastError
3413 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3415 WCHAR *url = NULL;
3416 BOOL rc;
3418 if(lpszUrl) {
3419 url = heap_strdupAtoW(lpszUrl);
3420 if(!url)
3421 return FALSE;
3424 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3426 heap_free(url);
3427 return rc;
3431 /**********************************************************
3432 * INTERNET_InternetOpenUrlW (internal)
3434 * Opens an URL
3436 * RETURNS
3437 * handle of connection or NULL on failure
3439 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3440 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3442 URL_COMPONENTSW urlComponents;
3443 WCHAR protocol[INTERNET_MAX_SCHEME_LENGTH];
3444 WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH];
3445 WCHAR userName[INTERNET_MAX_USER_NAME_LENGTH];
3446 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
3447 WCHAR path[INTERNET_MAX_PATH_LENGTH];
3448 WCHAR extra[1024];
3449 HINTERNET client = NULL, client1 = NULL;
3450 DWORD res;
3452 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3453 dwHeadersLength, dwFlags, dwContext);
3455 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3456 urlComponents.lpszScheme = protocol;
3457 urlComponents.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH;
3458 urlComponents.lpszHostName = hostName;
3459 urlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3460 urlComponents.lpszUserName = userName;
3461 urlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
3462 urlComponents.lpszPassword = password;
3463 urlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
3464 urlComponents.lpszUrlPath = path;
3465 urlComponents.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
3466 urlComponents.lpszExtraInfo = extra;
3467 urlComponents.dwExtraInfoLength = 1024;
3468 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3469 return NULL;
3470 switch(urlComponents.nScheme) {
3471 case INTERNET_SCHEME_FTP:
3472 if(urlComponents.nPort == 0)
3473 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3474 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3475 userName, password, dwFlags, dwContext, INET_OPENURL);
3476 if(client == NULL)
3477 break;
3478 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3479 if(client1 == NULL) {
3480 InternetCloseHandle(client);
3481 break;
3483 break;
3485 case INTERNET_SCHEME_HTTP:
3486 case INTERNET_SCHEME_HTTPS: {
3487 static const WCHAR szStars[] = { '*','/','*', 0 };
3488 LPCWSTR accept[2] = { szStars, NULL };
3489 if(urlComponents.nPort == 0) {
3490 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3491 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3492 else
3493 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3495 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3497 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3498 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3499 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3500 if(res != ERROR_SUCCESS) {
3501 INTERNET_SetLastError(res);
3502 break;
3505 if (urlComponents.dwExtraInfoLength) {
3506 WCHAR *path_extra;
3507 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3509 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3511 InternetCloseHandle(client);
3512 break;
3514 strcpyW(path_extra, urlComponents.lpszUrlPath);
3515 strcatW(path_extra, urlComponents.lpszExtraInfo);
3516 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3517 heap_free(path_extra);
3519 else
3520 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3522 if(client1 == NULL) {
3523 InternetCloseHandle(client);
3524 break;
3526 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3527 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3528 GetLastError() != ERROR_IO_PENDING) {
3529 InternetCloseHandle(client1);
3530 client1 = NULL;
3531 break;
3534 case INTERNET_SCHEME_GOPHER:
3535 /* gopher doesn't seem to be implemented in wine, but it's supposed
3536 * to be supported by InternetOpenUrlA. */
3537 default:
3538 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3539 break;
3542 TRACE(" %p <--\n", client1);
3544 return client1;
3547 /**********************************************************
3548 * InternetOpenUrlW (WININET.@)
3550 * Opens an URL
3552 * RETURNS
3553 * handle of connection or NULL on failure
3555 typedef struct {
3556 task_header_t hdr;
3557 WCHAR *url;
3558 WCHAR *headers;
3559 DWORD headers_len;
3560 DWORD flags;
3561 DWORD_PTR context;
3562 } open_url_task_t;
3564 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3566 open_url_task_t *task = (open_url_task_t*)hdr;
3568 TRACE("%p\n", task->hdr.hdr);
3570 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3571 task->headers_len, task->flags, task->context);
3572 heap_free(task->url);
3573 heap_free(task->headers);
3576 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3577 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3579 HINTERNET ret = NULL;
3580 appinfo_t *hIC = NULL;
3582 if (TRACE_ON(wininet)) {
3583 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3584 dwHeadersLength, dwFlags, dwContext);
3585 TRACE(" flags :");
3586 dump_INTERNET_FLAGS(dwFlags);
3589 if (!lpszUrl)
3591 SetLastError(ERROR_INVALID_PARAMETER);
3592 goto lend;
3595 hIC = (appinfo_t*)get_handle_object( hInternet );
3596 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3597 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3598 goto lend;
3601 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3602 open_url_task_t *task;
3604 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3605 task->url = heap_strdupW(lpszUrl);
3606 task->headers = heap_strdupW(lpszHeaders);
3607 task->headers_len = dwHeadersLength;
3608 task->flags = dwFlags;
3609 task->context = dwContext;
3611 INTERNET_AsyncCall(&task->hdr);
3612 SetLastError(ERROR_IO_PENDING);
3613 } else {
3614 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3617 lend:
3618 if( hIC )
3619 WININET_Release( &hIC->hdr );
3620 TRACE(" %p <--\n", ret);
3622 return ret;
3625 /**********************************************************
3626 * InternetOpenUrlA (WININET.@)
3628 * Opens an URL
3630 * RETURNS
3631 * handle of connection or NULL on failure
3633 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3634 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3636 HINTERNET rc = NULL;
3637 DWORD lenHeaders = 0;
3638 LPWSTR szUrl = NULL;
3639 LPWSTR szHeaders = NULL;
3641 TRACE("\n");
3643 if(lpszUrl) {
3644 szUrl = heap_strdupAtoW(lpszUrl);
3645 if(!szUrl)
3646 return NULL;
3649 if(lpszHeaders) {
3650 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3651 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3652 if(!szHeaders) {
3653 heap_free(szUrl);
3654 return NULL;
3656 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3659 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3660 lenHeaders, dwFlags, dwContext);
3662 heap_free(szUrl);
3663 heap_free(szHeaders);
3664 return rc;
3668 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3670 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3672 if (lpwite)
3674 lpwite->dwError = 0;
3675 lpwite->response[0] = '\0';
3678 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3680 heap_free(lpwite);
3681 return NULL;
3683 return lpwite;
3687 /***********************************************************************
3688 * INTERNET_SetLastError (internal)
3690 * Set last thread specific error
3692 * RETURNS
3695 void INTERNET_SetLastError(DWORD dwError)
3697 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3699 if (!lpwite)
3700 lpwite = INTERNET_AllocThreadError();
3702 SetLastError(dwError);
3703 if(lpwite)
3704 lpwite->dwError = dwError;
3708 /***********************************************************************
3709 * INTERNET_GetLastError (internal)
3711 * Get last thread specific error
3713 * RETURNS
3716 DWORD INTERNET_GetLastError(void)
3718 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3719 if (!lpwite) return 0;
3720 /* TlsGetValue clears last error, so set it again here */
3721 SetLastError(lpwite->dwError);
3722 return lpwite->dwError;
3726 /***********************************************************************
3727 * INTERNET_WorkerThreadFunc (internal)
3729 * Worker thread execution function
3731 * RETURNS
3734 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3736 task_header_t *task = lpvParam;
3738 TRACE("\n");
3740 task->proc(task);
3741 WININET_Release(task->hdr);
3742 heap_free(task);
3744 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3746 heap_free(TlsGetValue(g_dwTlsErrIndex));
3747 TlsSetValue(g_dwTlsErrIndex, NULL);
3749 return TRUE;
3752 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3754 task_header_t *task;
3756 task = heap_alloc(size);
3757 if(!task)
3758 return NULL;
3760 task->hdr = WININET_AddRef(hdr);
3761 task->proc = proc;
3762 return task;
3765 /***********************************************************************
3766 * INTERNET_AsyncCall (internal)
3768 * Retrieves work request from queue
3770 * RETURNS
3773 DWORD INTERNET_AsyncCall(task_header_t *task)
3775 BOOL bSuccess;
3777 TRACE("\n");
3779 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3780 if (!bSuccess)
3782 heap_free(task);
3783 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3785 return ERROR_SUCCESS;
3789 /***********************************************************************
3790 * INTERNET_GetResponseBuffer (internal)
3792 * RETURNS
3795 LPSTR INTERNET_GetResponseBuffer(void)
3797 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3798 if (!lpwite)
3799 lpwite = INTERNET_AllocThreadError();
3800 TRACE("\n");
3801 return lpwite->response;
3804 /***********************************************************************
3805 * INTERNET_GetNextLine (internal)
3807 * Parse next line in directory string listing
3809 * RETURNS
3810 * Pointer to beginning of next line
3811 * NULL on failure
3815 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3817 struct pollfd pfd;
3818 BOOL bSuccess = FALSE;
3819 INT nRecv = 0;
3820 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3822 TRACE("\n");
3824 pfd.fd = nSocket;
3825 pfd.events = POLLIN;
3827 while (nRecv < MAX_REPLY_LEN)
3829 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3831 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3833 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3834 goto lend;
3837 if (lpszBuffer[nRecv] == '\n')
3839 bSuccess = TRUE;
3840 break;
3842 if (lpszBuffer[nRecv] != '\r')
3843 nRecv++;
3845 else
3847 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3848 goto lend;
3852 lend:
3853 if (bSuccess)
3855 lpszBuffer[nRecv] = '\0';
3856 *dwLen = nRecv - 1;
3857 TRACE(":%d %s\n", nRecv, lpszBuffer);
3858 return lpszBuffer;
3860 else
3862 return NULL;
3866 /**********************************************************
3867 * InternetQueryDataAvailable (WININET.@)
3869 * Determines how much data is available to be read.
3871 * RETURNS
3872 * TRUE on success, FALSE if an error occurred. If
3873 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3874 * no data is presently available, FALSE is returned with
3875 * the last error ERROR_IO_PENDING; a callback with status
3876 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3877 * data is available.
3879 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3880 LPDWORD lpdwNumberOfBytesAvailable,
3881 DWORD dwFlags, DWORD_PTR dwContext)
3883 object_header_t *hdr;
3884 DWORD res;
3886 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3888 hdr = get_handle_object( hFile );
3889 if (!hdr) {
3890 SetLastError(ERROR_INVALID_HANDLE);
3891 return FALSE;
3894 if(hdr->vtbl->QueryDataAvailable) {
3895 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3896 }else {
3897 WARN("wrong handle\n");
3898 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3901 WININET_Release(hdr);
3903 if(res != ERROR_SUCCESS)
3904 SetLastError(res);
3905 return res == ERROR_SUCCESS;
3908 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
3910 req_file_t *req_file;
3912 req_file = heap_alloc_zero(sizeof(*req_file));
3913 if(!req_file)
3914 return ERROR_NOT_ENOUGH_MEMORY;
3916 req_file->ref = 1;
3918 req_file->file_name = heap_strdupW(file_name);
3919 if(!req_file->file_name) {
3920 heap_free(req_file);
3921 return ERROR_NOT_ENOUGH_MEMORY;
3924 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
3925 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3926 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
3927 req_file_release(req_file);
3928 return GetLastError();
3931 *ret = req_file;
3932 return ERROR_SUCCESS;
3935 void req_file_release(req_file_t *req_file)
3937 if(InterlockedDecrement(&req_file->ref))
3938 return;
3940 if(!req_file->is_committed)
3941 DeleteFileW(req_file->file_name);
3942 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
3943 CloseHandle(req_file->file_handle);
3944 heap_free(req_file->file_name);
3945 heap_free(req_file);
3948 /***********************************************************************
3949 * InternetLockRequestFile (WININET.@)
3951 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
3953 req_file_t *req_file = NULL;
3954 object_header_t *hdr;
3955 DWORD res;
3957 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
3959 hdr = get_handle_object(hInternet);
3960 if (!hdr) {
3961 SetLastError(ERROR_INVALID_HANDLE);
3962 return FALSE;
3965 if(hdr->vtbl->LockRequestFile) {
3966 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
3967 }else {
3968 WARN("wrong handle\n");
3969 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3972 WININET_Release(hdr);
3974 *lphLockReqHandle = req_file;
3975 if(res != ERROR_SUCCESS)
3976 SetLastError(res);
3977 return res == ERROR_SUCCESS;
3980 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
3982 TRACE("(%p)\n", hLockHandle);
3984 req_file_release(hLockHandle);
3985 return TRUE;
3989 /***********************************************************************
3990 * InternetAutodial (WININET.@)
3992 * On windows this function is supposed to dial the default internet
3993 * connection. We don't want to have Wine dial out to the internet so
3994 * we return TRUE by default. It might be nice to check if we are connected.
3996 * RETURNS
3997 * TRUE on success
3998 * FALSE on failure
4001 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4003 FIXME("STUB\n");
4005 /* Tell that we are connected to the internet. */
4006 return TRUE;
4009 /***********************************************************************
4010 * InternetAutodialHangup (WININET.@)
4012 * Hangs up a connection made with InternetAutodial
4014 * PARAM
4015 * dwReserved
4016 * RETURNS
4017 * TRUE on success
4018 * FALSE on failure
4021 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4023 FIXME("STUB\n");
4025 /* we didn't dial, we don't disconnect */
4026 return TRUE;
4029 /***********************************************************************
4030 * InternetCombineUrlA (WININET.@)
4032 * Combine a base URL with a relative URL
4034 * RETURNS
4035 * TRUE on success
4036 * FALSE on failure
4040 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4041 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4042 DWORD dwFlags)
4044 HRESULT hr=S_OK;
4046 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4048 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4049 dwFlags ^= ICU_NO_ENCODE;
4050 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4052 return (hr==S_OK);
4055 /***********************************************************************
4056 * InternetCombineUrlW (WININET.@)
4058 * Combine a base URL with a relative URL
4060 * RETURNS
4061 * TRUE on success
4062 * FALSE on failure
4066 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4067 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4068 DWORD dwFlags)
4070 HRESULT hr=S_OK;
4072 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4074 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4075 dwFlags ^= ICU_NO_ENCODE;
4076 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4078 return (hr==S_OK);
4081 /* max port num is 65535 => 5 digits */
4082 #define MAX_WORD_DIGITS 5
4084 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4085 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4086 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4087 (url)->dw##component##Length : strlen((url)->lpsz##component))
4089 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4091 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4092 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4093 return TRUE;
4094 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4095 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4096 return TRUE;
4097 if ((nScheme == INTERNET_SCHEME_FTP) &&
4098 (nPort == INTERNET_DEFAULT_FTP_PORT))
4099 return TRUE;
4100 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4101 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4102 return TRUE;
4104 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4105 return TRUE;
4107 return FALSE;
4110 /* opaque urls do not fit into the standard url hierarchy and don't have
4111 * two following slashes */
4112 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4114 return (nScheme != INTERNET_SCHEME_FTP) &&
4115 (nScheme != INTERNET_SCHEME_GOPHER) &&
4116 (nScheme != INTERNET_SCHEME_HTTP) &&
4117 (nScheme != INTERNET_SCHEME_HTTPS) &&
4118 (nScheme != INTERNET_SCHEME_FILE);
4121 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4123 int index;
4124 if (scheme < INTERNET_SCHEME_FIRST)
4125 return NULL;
4126 index = scheme - INTERNET_SCHEME_FIRST;
4127 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
4128 return NULL;
4129 return (LPCWSTR)url_schemes[index];
4132 /* we can calculate using ansi strings because we're just
4133 * calculating string length, not size
4135 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4136 LPDWORD lpdwUrlLength)
4138 INTERNET_SCHEME nScheme;
4140 *lpdwUrlLength = 0;
4142 if (lpUrlComponents->lpszScheme)
4144 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4145 *lpdwUrlLength += dwLen;
4146 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4148 else
4150 LPCWSTR scheme;
4152 nScheme = lpUrlComponents->nScheme;
4154 if (nScheme == INTERNET_SCHEME_DEFAULT)
4155 nScheme = INTERNET_SCHEME_HTTP;
4156 scheme = INTERNET_GetSchemeString(nScheme);
4157 *lpdwUrlLength += strlenW(scheme);
4160 (*lpdwUrlLength)++; /* ':' */
4161 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4162 *lpdwUrlLength += strlen("//");
4164 if (lpUrlComponents->lpszUserName)
4166 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4167 *lpdwUrlLength += strlen("@");
4169 else
4171 if (lpUrlComponents->lpszPassword)
4173 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4174 return FALSE;
4178 if (lpUrlComponents->lpszPassword)
4180 *lpdwUrlLength += strlen(":");
4181 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4184 if (lpUrlComponents->lpszHostName)
4186 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4188 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4190 char szPort[MAX_WORD_DIGITS+1];
4192 sprintf(szPort, "%d", lpUrlComponents->nPort);
4193 *lpdwUrlLength += strlen(szPort);
4194 *lpdwUrlLength += strlen(":");
4197 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4198 (*lpdwUrlLength)++; /* '/' */
4201 if (lpUrlComponents->lpszUrlPath)
4202 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4204 if (lpUrlComponents->lpszExtraInfo)
4205 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4207 return TRUE;
4210 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4212 INT len;
4214 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4216 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4217 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4218 urlCompW->nScheme = lpUrlComponents->nScheme;
4219 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4220 urlCompW->nPort = lpUrlComponents->nPort;
4221 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4222 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4223 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4224 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4226 if (lpUrlComponents->lpszScheme)
4228 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4229 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4230 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4231 -1, urlCompW->lpszScheme, len);
4234 if (lpUrlComponents->lpszHostName)
4236 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4237 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4238 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4239 -1, urlCompW->lpszHostName, len);
4242 if (lpUrlComponents->lpszUserName)
4244 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4245 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4246 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4247 -1, urlCompW->lpszUserName, len);
4250 if (lpUrlComponents->lpszPassword)
4252 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4253 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4254 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4255 -1, urlCompW->lpszPassword, len);
4258 if (lpUrlComponents->lpszUrlPath)
4260 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4261 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4262 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4263 -1, urlCompW->lpszUrlPath, len);
4266 if (lpUrlComponents->lpszExtraInfo)
4268 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4269 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4270 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4271 -1, urlCompW->lpszExtraInfo, len);
4275 /***********************************************************************
4276 * InternetCreateUrlA (WININET.@)
4278 * See InternetCreateUrlW.
4280 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4281 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4283 BOOL ret;
4284 LPWSTR urlW = NULL;
4285 URL_COMPONENTSW urlCompW;
4287 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4289 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4291 SetLastError(ERROR_INVALID_PARAMETER);
4292 return FALSE;
4295 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4297 if (lpszUrl)
4298 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4300 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4302 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4303 *lpdwUrlLength /= sizeof(WCHAR);
4305 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4306 * minus one, so add one to leave room for NULL terminator
4308 if (ret)
4309 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4311 heap_free(urlCompW.lpszScheme);
4312 heap_free(urlCompW.lpszHostName);
4313 heap_free(urlCompW.lpszUserName);
4314 heap_free(urlCompW.lpszPassword);
4315 heap_free(urlCompW.lpszUrlPath);
4316 heap_free(urlCompW.lpszExtraInfo);
4317 heap_free(urlW);
4318 return ret;
4321 /***********************************************************************
4322 * InternetCreateUrlW (WININET.@)
4324 * Creates a URL from its component parts.
4326 * PARAMS
4327 * lpUrlComponents [I] URL Components.
4328 * dwFlags [I] Flags. See notes.
4329 * lpszUrl [I] Buffer in which to store the created URL.
4330 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4331 * lpszUrl in characters. On output, the number of bytes
4332 * required to store the URL including terminator.
4334 * NOTES
4336 * The dwFlags parameter can be zero or more of the following:
4337 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4339 * RETURNS
4340 * TRUE on success
4341 * FALSE on failure
4344 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4345 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4347 DWORD dwLen;
4348 INTERNET_SCHEME nScheme;
4350 static const WCHAR slashSlashW[] = {'/','/'};
4351 static const WCHAR fmtW[] = {'%','u',0};
4353 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4355 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4357 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4358 return FALSE;
4361 if (!calc_url_length(lpUrlComponents, &dwLen))
4362 return FALSE;
4364 if (!lpszUrl || *lpdwUrlLength < dwLen)
4366 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4367 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4368 return FALSE;
4371 *lpdwUrlLength = dwLen;
4372 lpszUrl[0] = 0x00;
4374 dwLen = 0;
4376 if (lpUrlComponents->lpszScheme)
4378 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4379 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4380 lpszUrl += dwLen;
4382 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4384 else
4386 LPCWSTR scheme;
4387 nScheme = lpUrlComponents->nScheme;
4389 if (nScheme == INTERNET_SCHEME_DEFAULT)
4390 nScheme = INTERNET_SCHEME_HTTP;
4392 scheme = INTERNET_GetSchemeString(nScheme);
4393 dwLen = strlenW(scheme);
4394 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4395 lpszUrl += dwLen;
4398 /* all schemes are followed by at least a colon */
4399 *lpszUrl = ':';
4400 lpszUrl++;
4402 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4404 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4405 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4408 if (lpUrlComponents->lpszUserName)
4410 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4411 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4412 lpszUrl += dwLen;
4414 if (lpUrlComponents->lpszPassword)
4416 *lpszUrl = ':';
4417 lpszUrl++;
4419 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4420 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4421 lpszUrl += dwLen;
4424 *lpszUrl = '@';
4425 lpszUrl++;
4428 if (lpUrlComponents->lpszHostName)
4430 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4431 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4432 lpszUrl += dwLen;
4434 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4436 WCHAR szPort[MAX_WORD_DIGITS+1];
4438 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4439 *lpszUrl = ':';
4440 lpszUrl++;
4441 dwLen = strlenW(szPort);
4442 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4443 lpszUrl += dwLen;
4446 /* add slash between hostname and path if necessary */
4447 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4449 *lpszUrl = '/';
4450 lpszUrl++;
4454 if (lpUrlComponents->lpszUrlPath)
4456 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4457 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4458 lpszUrl += dwLen;
4461 if (lpUrlComponents->lpszExtraInfo)
4463 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4464 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4465 lpszUrl += dwLen;
4468 *lpszUrl = '\0';
4470 return TRUE;
4473 /***********************************************************************
4474 * InternetConfirmZoneCrossingA (WININET.@)
4477 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4479 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4480 return ERROR_SUCCESS;
4483 /***********************************************************************
4484 * InternetConfirmZoneCrossingW (WININET.@)
4487 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4489 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4490 return ERROR_SUCCESS;
4493 static DWORD zone_preference = 3;
4495 /***********************************************************************
4496 * PrivacySetZonePreferenceW (WININET.@)
4498 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4500 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4502 zone_preference = template;
4503 return 0;
4506 /***********************************************************************
4507 * PrivacyGetZonePreferenceW (WININET.@)
4509 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4510 LPWSTR preference, LPDWORD length )
4512 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4514 if (template) *template = zone_preference;
4515 return 0;
4518 /***********************************************************************
4519 * InternetGetSecurityInfoByURLA (WININET.@)
4521 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4523 WCHAR *url;
4524 BOOL res;
4526 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4528 url = heap_strdupAtoW(lpszURL);
4529 if(!url)
4530 return FALSE;
4532 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4533 heap_free(url);
4534 return res;
4537 /***********************************************************************
4538 * InternetGetSecurityInfoByURLW (WININET.@)
4540 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4542 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
4543 URL_COMPONENTSW url = {sizeof(url)};
4544 server_t *server;
4545 BOOL res = FALSE;
4547 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4549 url.lpszHostName = hostname;
4550 url.dwHostNameLength = sizeof(hostname)/sizeof(WCHAR);
4552 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4553 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4554 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4555 return FALSE;
4558 server = get_server(hostname, url.nPort, TRUE, FALSE);
4559 if(!server) {
4560 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4561 return FALSE;
4564 if(server->cert_chain) {
4565 const CERT_CHAIN_CONTEXT *chain_dup;
4567 chain_dup = CertDuplicateCertificateChain(server->cert_chain);
4568 if(chain_dup) {
4569 *ppCertChain = chain_dup;
4570 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4571 }else {
4572 res = FALSE;
4574 }else {
4575 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4576 res = FALSE;
4579 server_release(server);
4580 return res;
4583 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4584 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4586 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4587 lpdwConnection, dwReserved);
4588 return ERROR_SUCCESS;
4591 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4592 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4594 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4595 lpdwConnection, dwReserved);
4596 return ERROR_SUCCESS;
4599 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4601 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4602 return TRUE;
4605 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4607 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4608 return TRUE;
4611 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4613 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4614 return ERROR_SUCCESS;
4617 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4618 PBYTE pbHexHash )
4620 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4621 debugstr_w(pwszTarget), pbHexHash);
4622 return FALSE;
4625 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4627 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4628 return FALSE;
4631 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4633 FIXME("(%p, %08lx) stub\n", a, b);
4634 return FALSE;
4637 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4639 FIXME("%p: stub\n", parent);
4640 return 0;