msvcp90: Remove MSVCP_bool type.
[wine.git] / dlls / wininet / internet.c
blob1b6f060d607587db6d9ff98e2ed13c4cce54cfa9
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 "winsock2.h"
30 #include "ws2ipdef.h"
32 #include <string.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37 #include <assert.h>
38 #include <wchar.h>
40 #include "windef.h"
41 #include "winbase.h"
42 #include "winreg.h"
43 #include "winuser.h"
44 #include "wininet.h"
45 #include "winnls.h"
46 #include "wine/debug.h"
47 #include "winerror.h"
48 #define NO_SHLWAPI_STREAM
49 #include "shlwapi.h"
50 #include "ws2tcpip.h"
51 #include "winternl.h"
52 #include "iphlpapi.h"
53 #include "dhcpcsdk.h"
55 #include "wine/exception.h"
57 #include "internet.h"
58 #include "resource.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
62 typedef struct
64 DWORD dwError;
65 CHAR response[MAX_REPLY_LEN];
66 } WITHREADERROR, *LPWITHREADERROR;
68 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
69 HMODULE WININET_hModule;
71 static CRITICAL_SECTION WININET_cs;
72 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
74 0, 0, &WININET_cs,
75 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
76 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
78 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
80 static object_header_t **handle_table;
81 static UINT_PTR next_handle;
82 static UINT_PTR handle_table_size;
84 typedef struct
86 DWORD proxyEnabled;
87 LPWSTR proxy;
88 LPWSTR proxyBypass;
89 LPWSTR proxyUsername;
90 LPWSTR proxyPassword;
91 } proxyinfo_t;
93 static ULONG max_conns = 2, max_1_0_conns = 4;
94 static ULONG connect_timeout = 60000;
96 static const WCHAR szInternetSettings[] =
97 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
99 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
101 UINT_PTR handle = 0, num;
102 object_header_t *ret;
103 object_header_t **p;
104 BOOL res = TRUE;
106 ret = heap_alloc_zero(size);
107 if(!ret)
108 return NULL;
110 list_init(&ret->children);
112 EnterCriticalSection( &WININET_cs );
114 if(!handle_table_size) {
115 num = 16;
116 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
117 if(p) {
118 handle_table = p;
119 handle_table_size = num;
120 next_handle = 1;
121 }else {
122 res = FALSE;
124 }else if(next_handle == handle_table_size) {
125 num = handle_table_size * 2;
126 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
127 if(p) {
128 handle_table = p;
129 handle_table_size = num;
130 }else {
131 res = FALSE;
135 if(res) {
136 handle = next_handle;
137 if(handle_table[handle])
138 ERR("handle isn't free but should be\n");
139 handle_table[handle] = ret;
140 ret->valid_handle = TRUE;
142 while(next_handle < handle_table_size && handle_table[next_handle])
143 next_handle++;
146 LeaveCriticalSection( &WININET_cs );
148 if(!res) {
149 heap_free(ret);
150 return NULL;
153 ret->vtbl = vtbl;
154 ret->refs = 1;
155 ret->hInternet = (HINTERNET)handle;
157 if(parent) {
158 ret->lpfnStatusCB = parent->lpfnStatusCB;
159 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
162 return ret;
165 object_header_t *WININET_AddRef( object_header_t *info )
167 ULONG refs = InterlockedIncrement(&info->refs);
168 TRACE("%p -> refcount = %d\n", info, refs );
169 return info;
172 object_header_t *get_handle_object( HINTERNET hinternet )
174 object_header_t *info = NULL;
175 UINT_PTR handle = (UINT_PTR) hinternet;
177 EnterCriticalSection( &WININET_cs );
179 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
180 info = WININET_AddRef(handle_table[handle]);
182 LeaveCriticalSection( &WININET_cs );
184 TRACE("handle %ld -> %p\n", handle, info);
186 return info;
189 static void invalidate_handle(object_header_t *info)
191 object_header_t *child, *next;
193 if(!info->valid_handle)
194 return;
195 info->valid_handle = FALSE;
197 /* Free all children as native does */
198 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
200 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
201 invalidate_handle( child );
204 WININET_Release(info);
207 BOOL WININET_Release( object_header_t *info )
209 ULONG refs = InterlockedDecrement(&info->refs);
210 TRACE( "object %p refcount = %d\n", info, refs );
211 if( !refs )
213 invalidate_handle(info);
214 if ( info->vtbl->CloseConnection )
216 TRACE( "closing connection %p\n", info);
217 info->vtbl->CloseConnection( info );
219 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
220 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
221 || !(info->dwInternalFlags & INET_OPENURL))
223 INTERNET_SendCallback(info, info->dwContext,
224 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
225 sizeof(HINTERNET));
227 TRACE( "destroying object %p\n", info);
228 if ( info->htype != WH_HINIT )
229 list_remove( &info->entry );
230 info->vtbl->Destroy( info );
232 if(info->hInternet) {
233 UINT_PTR handle = (UINT_PTR)info->hInternet;
235 EnterCriticalSection( &WININET_cs );
237 handle_table[handle] = NULL;
238 if(next_handle > handle)
239 next_handle = handle;
241 LeaveCriticalSection( &WININET_cs );
244 heap_free(info);
246 return TRUE;
249 /***********************************************************************
250 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
252 * PARAMS
253 * hinstDLL [I] handle to the DLL's instance
254 * fdwReason [I]
255 * lpvReserved [I] reserved, must be NULL
257 * RETURNS
258 * Success: TRUE
259 * Failure: FALSE
262 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
264 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
266 switch (fdwReason) {
267 case DLL_PROCESS_ATTACH:
269 g_dwTlsErrIndex = TlsAlloc();
271 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
272 return FALSE;
274 if(!init_urlcache())
276 TlsFree(g_dwTlsErrIndex);
277 return FALSE;
280 WININET_hModule = hinstDLL;
281 break;
283 case DLL_THREAD_ATTACH:
284 break;
286 case DLL_THREAD_DETACH:
287 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
289 heap_free(TlsGetValue(g_dwTlsErrIndex));
291 break;
293 case DLL_PROCESS_DETACH:
294 if (lpvReserved) break;
295 collect_connections(COLLECT_CLEANUP);
296 NETCON_unload();
297 free_urlcache();
298 free_cookie();
300 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
302 heap_free(TlsGetValue(g_dwTlsErrIndex));
303 TlsFree(g_dwTlsErrIndex);
305 break;
307 return TRUE;
310 /***********************************************************************
311 * DllInstall (WININET.@)
313 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
315 FIXME("(%x %s): stub\n", bInstall, debugstr_w(cmdline));
316 return S_OK;
319 /***********************************************************************
320 * INTERNET_SaveProxySettings
322 * Stores the proxy settings given by lpwai into the registry
324 * RETURNS
325 * ERROR_SUCCESS if no error, or error code on fail
327 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
329 HKEY key;
330 LONG ret;
332 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
333 return ret;
335 if ((ret = RegSetValueExW( key, L"ProxyEnable", 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
337 RegCloseKey( key );
338 return ret;
341 if (lpwpi->proxy)
343 if ((ret = RegSetValueExW( key, L"ProxyServer", 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
345 RegCloseKey( key );
346 return ret;
349 else
351 if ((ret = RegDeleteValueW( key, L"ProxyServer" )) && ret != ERROR_FILE_NOT_FOUND)
353 RegCloseKey( key );
354 return ret;
358 RegCloseKey(key);
359 return ERROR_SUCCESS;
362 /***********************************************************************
363 * INTERNET_FindProxyForProtocol
365 * Searches the proxy string for a proxy of the given protocol.
366 * Returns the found proxy, or the default proxy if none of the given
367 * protocol is found.
369 * PARAMETERS
370 * szProxy [In] proxy string to search
371 * proto [In] protocol to search for, e.g. "http"
372 * foundProxy [Out] found proxy
373 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
375 * RETURNS
376 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
377 * *foundProxyLen is set to the required size in WCHARs, including the
378 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
380 WCHAR *INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto)
382 WCHAR *ret = NULL;
383 const WCHAR *ptr;
385 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
387 /* First, look for the specified protocol (proto=scheme://host:port) */
388 for (ptr = szProxy; ptr && *ptr; )
390 LPCWSTR end, equal;
392 if (!(end = wcschr(ptr, ' ')))
393 end = ptr + lstrlenW(ptr);
394 if ((equal = wcschr(ptr, '=')) && equal < end &&
395 equal - ptr == lstrlenW(proto) &&
396 !wcsnicmp(proto, ptr, lstrlenW(proto)))
398 ret = heap_strndupW(equal + 1, end - equal - 1);
399 TRACE("found proxy for %s: %s\n", debugstr_w(proto), debugstr_w(ret));
400 return ret;
402 if (*end == ' ')
403 ptr = end + 1;
404 else
405 ptr = end;
408 /* It wasn't found: look for no protocol */
409 for (ptr = szProxy; ptr && *ptr; )
411 LPCWSTR end;
413 if (!(end = wcschr(ptr, ' ')))
414 end = ptr + lstrlenW(ptr);
415 if (!wcschr(ptr, '='))
417 ret = heap_strndupW(ptr, end - ptr);
418 TRACE("found proxy for %s: %s\n", debugstr_w(proto), debugstr_w(ret));
419 return ret;
421 if (*end == ' ')
422 ptr = end + 1;
423 else
424 ptr = end;
427 return NULL;
430 /***********************************************************************
431 * InternetInitializeAutoProxyDll (WININET.@)
433 * Setup the internal proxy
435 * PARAMETERS
436 * dwReserved
438 * RETURNS
439 * FALSE on failure
442 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
444 FIXME("STUB\n");
445 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
446 return FALSE;
449 /***********************************************************************
450 * DetectAutoProxyUrl (WININET.@)
452 * Auto detect the proxy url
454 * RETURNS
455 * FALSE on failure
458 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
459 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
461 FIXME("STUB\n");
462 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
463 return FALSE;
466 static void FreeProxyInfo( proxyinfo_t *lpwpi )
468 heap_free(lpwpi->proxy);
469 heap_free(lpwpi->proxyBypass);
470 heap_free(lpwpi->proxyUsername);
471 heap_free(lpwpi->proxyPassword);
474 static proxyinfo_t *global_proxy;
476 static void free_global_proxy( void )
478 EnterCriticalSection( &WININET_cs );
479 if (global_proxy)
481 FreeProxyInfo( global_proxy );
482 heap_free( global_proxy );
484 LeaveCriticalSection( &WININET_cs );
487 static BOOL parse_proxy_url( proxyinfo_t *info, const WCHAR *url )
489 URL_COMPONENTSW uc = {sizeof(uc)};
491 uc.dwHostNameLength = 1;
492 uc.dwUserNameLength = 1;
493 uc.dwPasswordLength = 1;
495 if (!InternetCrackUrlW( url, 0, 0, &uc )) return FALSE;
496 if (!uc.dwHostNameLength)
498 if (!(info->proxy = heap_strdupW( url ))) return FALSE;
499 info->proxyUsername = NULL;
500 info->proxyPassword = NULL;
501 return TRUE;
503 if (!(info->proxy = heap_alloc( (uc.dwHostNameLength + 12) * sizeof(WCHAR) ))) return FALSE;
504 swprintf( info->proxy, uc.dwHostNameLength + 12, L"%.*s:%u", uc.dwHostNameLength, uc.lpszHostName, uc.nPort );
506 if (!uc.dwUserNameLength) info->proxyUsername = NULL;
507 else if (!(info->proxyUsername = heap_strndupW( uc.lpszUserName, uc.dwUserNameLength )))
509 heap_free( info->proxy );
510 return FALSE;
512 if (!uc.dwPasswordLength) info->proxyPassword = NULL;
513 else if (!(info->proxyPassword = heap_strndupW( uc.lpszPassword, uc.dwPasswordLength )))
515 heap_free( info->proxyUsername );
516 heap_free( info->proxy );
517 return FALSE;
519 return TRUE;
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 const WCHAR *envproxy;
539 LONG ret;
541 memset( lpwpi, 0, sizeof(*lpwpi) );
543 EnterCriticalSection( &WININET_cs );
544 if (global_proxy)
546 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
547 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
548 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
550 LeaveCriticalSection( &WININET_cs );
552 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
554 FreeProxyInfo( lpwpi );
555 return ret;
558 len = sizeof(DWORD);
559 if (RegQueryValueExW( key, L"ProxyEnable", NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
561 lpwpi->proxyEnabled = 0;
562 if((ret = RegSetValueExW( key, L"ProxyEnable", 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
564 FreeProxyInfo( lpwpi );
565 RegCloseKey( key );
566 return ret;
570 if (!(envproxy = _wgetenv( L"http_proxy" )) || lpwpi->proxyEnabled)
572 /* figure out how much memory the proxy setting takes */
573 if (!RegQueryValueExW( key, L"ProxyServer", NULL, &type, NULL, &len ) && len && (type == REG_SZ))
575 LPWSTR szProxy, p;
577 if (!(szProxy = heap_alloc(len)))
579 RegCloseKey( key );
580 FreeProxyInfo( lpwpi );
581 return ERROR_OUTOFMEMORY;
583 RegQueryValueExW( key, L"ProxyServer", NULL, &type, (BYTE*)szProxy, &len );
585 /* find the http proxy, and strip away everything else */
586 p = wcsstr( szProxy, L"http=" );
587 if (p)
589 p += lstrlenW( L"http=" );
590 lstrcpyW( szProxy, p );
592 p = wcschr( szProxy, ';' );
593 if (p) *p = 0;
595 FreeProxyInfo( lpwpi );
596 lpwpi->proxy = szProxy;
597 lpwpi->proxyBypass = NULL;
599 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi->proxy));
601 else
603 TRACE("No proxy server settings in registry.\n");
604 FreeProxyInfo( lpwpi );
605 lpwpi->proxy = NULL;
606 lpwpi->proxyBypass = NULL;
609 else if (envproxy)
611 FreeProxyInfo( lpwpi );
612 if (parse_proxy_url( lpwpi, envproxy ))
614 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
615 lpwpi->proxyEnabled = 1;
616 lpwpi->proxyBypass = NULL;
618 else
620 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxy));
621 lpwpi->proxyEnabled = 0;
622 lpwpi->proxy = NULL;
623 lpwpi->proxyBypass = NULL;
627 if (lpwpi->proxyEnabled)
629 TRACE("Proxy is enabled.\n");
631 if (!(envproxy = _wgetenv( L"no_proxy" )))
633 /* figure out how much memory the proxy setting takes */
634 if (!RegQueryValueExW( key, L"ProxyOverride", NULL, &type, NULL, &len ) && len && (type == REG_SZ))
636 LPWSTR szProxy;
638 if (!(szProxy = heap_alloc(len)))
640 RegCloseKey( key );
641 return ERROR_OUTOFMEMORY;
643 RegQueryValueExW( key, L"ProxyOverride", NULL, &type, (BYTE*)szProxy, &len );
645 heap_free( lpwpi->proxyBypass );
646 lpwpi->proxyBypass = szProxy;
648 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi->proxyBypass));
650 else
652 heap_free( lpwpi->proxyBypass );
653 lpwpi->proxyBypass = NULL;
655 TRACE("No proxy bypass server settings in registry.\n");
658 else
660 WCHAR *envproxyW;
662 if (!(envproxyW = heap_alloc(lstrlenW(envproxy) * sizeof(WCHAR))))
664 RegCloseKey( key );
665 return ERROR_OUTOFMEMORY;
667 lstrcpyW( envproxyW, envproxy );
669 heap_free( lpwpi->proxyBypass );
670 lpwpi->proxyBypass = envproxyW;
672 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
675 else TRACE("Proxy is disabled.\n");
677 RegCloseKey( key );
678 return ERROR_SUCCESS;
681 /***********************************************************************
682 * INTERNET_ConfigureProxy
684 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
686 proxyinfo_t wpi;
688 if (INTERNET_LoadProxySettings( &wpi ))
689 return FALSE;
691 if (wpi.proxyEnabled)
693 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi.proxy), debugstr_w(wpi.proxyBypass));
695 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
696 lpwai->proxy = wpi.proxy;
697 lpwai->proxyBypass = wpi.proxyBypass;
698 lpwai->proxyUsername = wpi.proxyUsername;
699 lpwai->proxyPassword = wpi.proxyPassword;
700 return TRUE;
703 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
704 FreeProxyInfo(&wpi);
705 return FALSE;
708 /***********************************************************************
709 * dump_INTERNET_FLAGS
711 * Helper function to TRACE the internet flags.
713 * RETURNS
714 * None
717 static void dump_INTERNET_FLAGS(DWORD dwFlags)
719 #define FE(x) { x, #x }
720 static const wininet_flag_info flag[] = {
721 FE(INTERNET_FLAG_RELOAD),
722 FE(INTERNET_FLAG_RAW_DATA),
723 FE(INTERNET_FLAG_EXISTING_CONNECT),
724 FE(INTERNET_FLAG_ASYNC),
725 FE(INTERNET_FLAG_PASSIVE),
726 FE(INTERNET_FLAG_NO_CACHE_WRITE),
727 FE(INTERNET_FLAG_MAKE_PERSISTENT),
728 FE(INTERNET_FLAG_FROM_CACHE),
729 FE(INTERNET_FLAG_SECURE),
730 FE(INTERNET_FLAG_KEEP_CONNECTION),
731 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
732 FE(INTERNET_FLAG_READ_PREFETCH),
733 FE(INTERNET_FLAG_NO_COOKIES),
734 FE(INTERNET_FLAG_NO_AUTH),
735 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
736 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
737 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
738 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
739 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
740 FE(INTERNET_FLAG_RESYNCHRONIZE),
741 FE(INTERNET_FLAG_HYPERLINK),
742 FE(INTERNET_FLAG_NO_UI),
743 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
744 FE(INTERNET_FLAG_CACHE_ASYNC),
745 FE(INTERNET_FLAG_FORMS_SUBMIT),
746 FE(INTERNET_FLAG_NEED_FILE),
747 FE(INTERNET_FLAG_TRANSFER_ASCII),
748 FE(INTERNET_FLAG_TRANSFER_BINARY)
750 #undef FE
751 unsigned int i;
753 for (i = 0; i < ARRAY_SIZE(flag); i++) {
754 if (flag[i].val & dwFlags) {
755 TRACE(" %s", flag[i].name);
756 dwFlags &= ~flag[i].val;
759 if (dwFlags)
760 TRACE(" Unknown flags (%08x)\n", dwFlags);
761 else
762 TRACE("\n");
765 /***********************************************************************
766 * INTERNET_CloseHandle (internal)
768 * Close internet handle
771 static VOID APPINFO_Destroy(object_header_t *hdr)
773 appinfo_t *lpwai = (appinfo_t*)hdr;
775 TRACE("%p\n",lpwai);
777 heap_free(lpwai->agent);
778 heap_free(lpwai->proxy);
779 heap_free(lpwai->proxyBypass);
780 heap_free(lpwai->proxyUsername);
781 heap_free(lpwai->proxyPassword);
784 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
786 appinfo_t *ai = (appinfo_t*)hdr;
788 switch(option) {
789 case INTERNET_OPTION_HANDLE_TYPE:
790 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
792 if (*size < sizeof(ULONG))
793 return ERROR_INSUFFICIENT_BUFFER;
795 *size = sizeof(DWORD);
796 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
797 return ERROR_SUCCESS;
799 case INTERNET_OPTION_USER_AGENT: {
800 DWORD bufsize;
802 TRACE("INTERNET_OPTION_USER_AGENT\n");
804 bufsize = *size;
806 if (unicode) {
807 DWORD len = ai->agent ? lstrlenW(ai->agent) : 0;
809 *size = (len + 1) * sizeof(WCHAR);
810 if(!buffer || bufsize < *size)
811 return ERROR_INSUFFICIENT_BUFFER;
813 if (ai->agent)
814 lstrcpyW(buffer, ai->agent);
815 else
816 *(WCHAR *)buffer = 0;
817 /* If the buffer is copied, the returned length doesn't include
818 * the NULL terminator.
820 *size = len;
821 }else {
822 if (ai->agent)
823 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
824 else
825 *size = 1;
826 if(!buffer || bufsize < *size)
827 return ERROR_INSUFFICIENT_BUFFER;
829 if (ai->agent)
830 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
831 else
832 *(char *)buffer = 0;
833 /* If the buffer is copied, the returned length doesn't include
834 * the NULL terminator.
836 *size -= 1;
839 return ERROR_SUCCESS;
842 case INTERNET_OPTION_PROXY:
843 if(!size) return ERROR_INVALID_PARAMETER;
844 if (unicode) {
845 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
846 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
847 LPWSTR proxy, proxy_bypass;
849 if (ai->proxy)
850 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
851 if (ai->proxyBypass)
852 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
853 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
855 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
856 return ERROR_INSUFFICIENT_BUFFER;
858 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
859 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
861 pi->dwAccessType = ai->accessType;
862 pi->lpszProxy = NULL;
863 pi->lpszProxyBypass = NULL;
864 if (ai->proxy) {
865 lstrcpyW(proxy, ai->proxy);
866 pi->lpszProxy = proxy;
869 if (ai->proxyBypass) {
870 lstrcpyW(proxy_bypass, ai->proxyBypass);
871 pi->lpszProxyBypass = proxy_bypass;
874 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
875 return ERROR_SUCCESS;
876 }else {
877 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
878 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
879 LPSTR proxy, proxy_bypass;
881 if (ai->proxy)
882 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
883 if (ai->proxyBypass)
884 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
885 NULL, 0, NULL, NULL);
886 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
888 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
889 return ERROR_INSUFFICIENT_BUFFER;
891 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
892 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
894 pi->dwAccessType = ai->accessType;
895 pi->lpszProxy = NULL;
896 pi->lpszProxyBypass = NULL;
897 if (ai->proxy) {
898 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
899 pi->lpszProxy = proxy;
902 if (ai->proxyBypass) {
903 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
904 proxyBypassBytesRequired, NULL, NULL);
905 pi->lpszProxyBypass = proxy_bypass;
908 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
909 return ERROR_SUCCESS;
912 case INTERNET_OPTION_CONNECT_TIMEOUT:
913 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
915 if (*size < sizeof(ULONG))
916 return ERROR_INSUFFICIENT_BUFFER;
918 *(ULONG*)buffer = ai->connect_timeout;
919 *size = sizeof(ULONG);
921 return ERROR_SUCCESS;
924 return INET_QueryOption(hdr, option, buffer, size, unicode);
927 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
929 appinfo_t *ai = (appinfo_t*)hdr;
931 switch(option) {
932 case INTERNET_OPTION_CONNECT_TIMEOUT:
933 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
935 if(size != sizeof(connect_timeout))
936 return ERROR_INTERNET_BAD_OPTION_LENGTH;
937 if(!*(ULONG*)buf)
938 return ERROR_BAD_ARGUMENTS;
940 ai->connect_timeout = *(ULONG*)buf;
941 return ERROR_SUCCESS;
942 case INTERNET_OPTION_USER_AGENT:
943 heap_free(ai->agent);
944 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
945 return ERROR_SUCCESS;
946 case INTERNET_OPTION_REFRESH:
947 FIXME("INTERNET_OPTION_REFRESH\n");
948 return ERROR_SUCCESS;
951 return INET_SetOption(hdr, option, buf, size);
954 static const object_vtbl_t APPINFOVtbl = {
955 APPINFO_Destroy,
956 NULL,
957 APPINFO_QueryOption,
958 APPINFO_SetOption,
959 NULL,
960 NULL,
961 NULL
965 /***********************************************************************
966 * InternetOpenW (WININET.@)
968 * Per-application initialization of wininet
970 * RETURNS
971 * HINTERNET on success
972 * NULL on failure
975 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
976 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
978 appinfo_t *lpwai = NULL;
980 if (TRACE_ON(wininet)) {
981 #define FE(x) { x, #x }
982 static const wininet_flag_info access_type[] = {
983 FE(INTERNET_OPEN_TYPE_PRECONFIG),
984 FE(INTERNET_OPEN_TYPE_DIRECT),
985 FE(INTERNET_OPEN_TYPE_PROXY),
986 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
988 #undef FE
989 DWORD i;
990 const char *access_type_str = "Unknown";
992 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
993 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
994 for (i = 0; i < ARRAY_SIZE(access_type); i++) {
995 if (access_type[i].val == dwAccessType) {
996 access_type_str = access_type[i].name;
997 break;
1000 TRACE(" access type : %s\n", access_type_str);
1001 TRACE(" flags :");
1002 dump_INTERNET_FLAGS(dwFlags);
1005 /* Clear any error information */
1006 INTERNET_SetLastError(0);
1008 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1009 SetLastError(ERROR_INVALID_PARAMETER);
1010 return NULL;
1013 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1014 if (!lpwai) {
1015 SetLastError(ERROR_OUTOFMEMORY);
1016 return NULL;
1019 lpwai->hdr.htype = WH_HINIT;
1020 lpwai->hdr.dwFlags = dwFlags;
1021 lpwai->accessType = dwAccessType;
1022 lpwai->proxyUsername = NULL;
1023 lpwai->proxyPassword = NULL;
1024 lpwai->connect_timeout = connect_timeout;
1026 lpwai->agent = heap_strdupW(lpszAgent);
1027 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1028 INTERNET_ConfigureProxy( lpwai );
1029 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1030 lpwai->proxy = heap_strdupW(lpszProxy);
1031 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1034 TRACE("returning %p\n", lpwai);
1036 return lpwai->hdr.hInternet;
1040 /***********************************************************************
1041 * InternetOpenA (WININET.@)
1043 * Per-application initialization of wininet
1045 * RETURNS
1046 * HINTERNET on success
1047 * NULL on failure
1050 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1051 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1053 WCHAR *szAgent, *szProxy, *szBypass;
1054 HINTERNET rc;
1056 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1057 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1059 szAgent = heap_strdupAtoW(lpszAgent);
1060 szProxy = heap_strdupAtoW(lpszProxy);
1061 szBypass = heap_strdupAtoW(lpszProxyBypass);
1063 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1065 heap_free(szAgent);
1066 heap_free(szProxy);
1067 heap_free(szBypass);
1068 return rc;
1071 /***********************************************************************
1072 * InternetGetLastResponseInfoA (WININET.@)
1074 * Return last wininet error description on the calling thread
1076 * RETURNS
1077 * TRUE on success of writing to buffer
1078 * FALSE on failure
1081 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1082 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1084 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1086 TRACE("\n");
1088 if (lpwite)
1090 *lpdwError = lpwite->dwError;
1091 if (lpwite->dwError)
1093 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1094 *lpdwBufferLength = strlen(lpszBuffer);
1096 else
1097 *lpdwBufferLength = 0;
1099 else
1101 *lpdwError = 0;
1102 *lpdwBufferLength = 0;
1105 return TRUE;
1108 /***********************************************************************
1109 * InternetGetLastResponseInfoW (WININET.@)
1111 * Return last wininet error description on the calling thread
1113 * RETURNS
1114 * TRUE on success of writing to buffer
1115 * FALSE on failure
1118 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1119 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1121 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1123 TRACE("\n");
1125 if (lpwite)
1127 *lpdwError = lpwite->dwError;
1128 if (lpwite->dwError)
1130 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1131 *lpdwBufferLength = lstrlenW(lpszBuffer);
1133 else
1134 *lpdwBufferLength = 0;
1136 else
1138 *lpdwError = 0;
1139 *lpdwBufferLength = 0;
1142 return TRUE;
1145 /***********************************************************************
1146 * InternetGetConnectedState (WININET.@)
1148 * Return connected state
1150 * RETURNS
1151 * TRUE if connected
1152 * if lpdwStatus is not null, return the status (off line,
1153 * modem, lan...) in it.
1154 * FALSE if not connected
1156 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1158 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1160 return InternetGetConnectedStateExW(lpdwStatus, NULL, 0, dwReserved);
1164 /***********************************************************************
1165 * InternetGetConnectedStateExW (WININET.@)
1167 * Return connected state
1169 * PARAMS
1171 * lpdwStatus [O] Flags specifying the status of the internet connection.
1172 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1173 * dwNameLen [I] Size of the buffer, in characters.
1174 * dwReserved [I] Reserved. Must be set to 0.
1176 * RETURNS
1177 * TRUE if connected
1178 * if lpdwStatus is not null, return the status (off line,
1179 * modem, lan...) in it.
1180 * FALSE if not connected
1182 * NOTES
1183 * If the system has no available network connections, an empty string is
1184 * stored in lpszConnectionName. If there is a LAN connection, a localized
1185 * "LAN Connection" string is stored. Presumably, if only a dial-up
1186 * connection is available then the name of the dial-up connection is
1187 * returned. Why any application, other than the "Internet Settings" CPL,
1188 * would want to use this function instead of the simpler InternetGetConnectedStateW
1189 * function is beyond me.
1191 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1192 DWORD dwNameLen, DWORD dwReserved)
1194 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1196 /* Must be zero */
1197 if(dwReserved)
1198 return FALSE;
1200 if (lpdwStatus) {
1201 WARN("always returning LAN connection.\n");
1202 *lpdwStatus = INTERNET_CONNECTION_LAN;
1205 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1206 * the resource, avoid it as we must not change the buffer in this case */
1207 if(lpszConnectionName && dwNameLen) {
1208 *lpszConnectionName = '\0';
1209 LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1212 return TRUE;
1216 /***********************************************************************
1217 * InternetGetConnectedStateExA (WININET.@)
1219 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1220 DWORD dwNameLen, DWORD dwReserved)
1222 LPWSTR lpwszConnectionName = NULL;
1223 BOOL rc;
1225 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1227 if (lpszConnectionName && dwNameLen > 0)
1228 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1230 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1231 dwReserved);
1232 if (rc && lpwszConnectionName)
1233 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1234 dwNameLen, NULL, NULL);
1236 heap_free(lpwszConnectionName);
1237 return rc;
1241 /***********************************************************************
1242 * InternetConnectW (WININET.@)
1244 * Open a ftp, gopher or http session
1246 * RETURNS
1247 * HINTERNET a session handle on success
1248 * NULL on failure
1251 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1252 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1253 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1254 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1256 appinfo_t *hIC;
1257 HINTERNET rc = NULL;
1258 DWORD res = ERROR_SUCCESS;
1260 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1261 nServerPort, debugstr_w(lpszUserName), lpszPassword, dwService, dwFlags, dwContext);
1263 if (!lpszServerName)
1265 SetLastError(ERROR_INVALID_PARAMETER);
1266 return NULL;
1269 hIC = (appinfo_t*)get_handle_object( hInternet );
1270 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1272 res = ERROR_INVALID_HANDLE;
1273 goto lend;
1276 switch (dwService)
1278 case INTERNET_SERVICE_FTP:
1279 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1280 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1281 if(!rc)
1282 res = INTERNET_GetLastError();
1283 break;
1285 case INTERNET_SERVICE_HTTP:
1286 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1287 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1288 break;
1290 case INTERNET_SERVICE_GOPHER:
1291 default:
1292 break;
1294 lend:
1295 if( hIC )
1296 WININET_Release( &hIC->hdr );
1298 TRACE("returning %p\n", rc);
1299 SetLastError(res);
1300 return rc;
1304 /***********************************************************************
1305 * InternetConnectA (WININET.@)
1307 * Open a ftp, gopher or http session
1309 * RETURNS
1310 * HINTERNET a session handle on success
1311 * NULL on failure
1314 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1315 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1316 LPCSTR lpszUserName, LPCSTR lpszPassword,
1317 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1319 HINTERNET rc = NULL;
1320 LPWSTR szServerName;
1321 LPWSTR szUserName;
1322 LPWSTR szPassword;
1324 szServerName = heap_strdupAtoW(lpszServerName);
1325 szUserName = heap_strdupAtoW(lpszUserName);
1326 szPassword = heap_strdupAtoW(lpszPassword);
1328 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1329 szUserName, szPassword, dwService, dwFlags, dwContext);
1331 heap_free(szServerName);
1332 heap_free(szUserName);
1333 heap_free(szPassword);
1334 return rc;
1338 /***********************************************************************
1339 * InternetFindNextFileA (WININET.@)
1341 * Continues a file search from a previous call to FindFirstFile
1343 * RETURNS
1344 * TRUE on success
1345 * FALSE on failure
1348 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1350 BOOL ret;
1351 WIN32_FIND_DATAW fd;
1353 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1354 if(lpvFindData)
1355 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1356 return ret;
1359 /***********************************************************************
1360 * InternetFindNextFileW (WININET.@)
1362 * Continues a file search from a previous call to FindFirstFile
1364 * RETURNS
1365 * TRUE on success
1366 * FALSE on failure
1369 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1371 object_header_t *hdr;
1372 DWORD res;
1374 TRACE("\n");
1376 hdr = get_handle_object(hFind);
1377 if(!hdr) {
1378 WARN("Invalid handle\n");
1379 SetLastError(ERROR_INVALID_HANDLE);
1380 return FALSE;
1383 if(hdr->vtbl->FindNextFileW) {
1384 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1385 }else {
1386 WARN("Handle doesn't support NextFile\n");
1387 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1390 WININET_Release(hdr);
1392 if(res != ERROR_SUCCESS)
1393 SetLastError(res);
1394 return res == ERROR_SUCCESS;
1397 /***********************************************************************
1398 * InternetCloseHandle (WININET.@)
1400 * Generic close handle function
1402 * RETURNS
1403 * TRUE on success
1404 * FALSE on failure
1407 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1409 object_header_t *obj;
1411 TRACE("%p\n", hInternet);
1413 obj = get_handle_object( hInternet );
1414 if (!obj) {
1415 SetLastError(ERROR_INVALID_HANDLE);
1416 return FALSE;
1419 invalidate_handle(obj);
1420 WININET_Release(obj);
1422 return TRUE;
1425 static BOOL set_url_component(WCHAR **component, DWORD *component_length, const WCHAR *value, DWORD len)
1427 TRACE("%s (%d)\n", debugstr_wn(value, len), len);
1429 if (!*component_length)
1430 return TRUE;
1432 if (!*component) {
1433 *(const WCHAR**)component = value;
1434 *component_length = len;
1435 return TRUE;
1438 if (*component_length < len+1) {
1439 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1440 return FALSE;
1443 *component_length = len;
1444 if(len)
1445 memcpy(*component, value, len*sizeof(WCHAR));
1446 (*component)[len] = 0;
1447 return TRUE;
1450 static BOOL set_url_component_WtoA(const WCHAR *comp_w, DWORD length, const WCHAR *url_w, char **comp, DWORD *ret_length,
1451 const char *url_a)
1453 size_t size, ret_size = *ret_length;
1455 if (!*ret_length)
1456 return TRUE;
1457 size = WideCharToMultiByte(CP_ACP, 0, comp_w, length, NULL, 0, NULL, NULL);
1459 if (!*comp) {
1460 *comp = comp_w ? (char*)url_a + WideCharToMultiByte(CP_ACP, 0, url_w, comp_w-url_w, NULL, 0, NULL, NULL) : NULL;
1461 *ret_length = size;
1462 return TRUE;
1465 if (size+1 > ret_size) {
1466 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1467 *ret_length = size+1;
1468 return FALSE;
1471 *ret_length = size;
1472 WideCharToMultiByte(CP_ACP, 0, comp_w, length, *comp, ret_size-1, NULL, NULL);
1473 (*comp)[size] = 0;
1474 return TRUE;
1477 static BOOL set_url_component_AtoW(const char *comp_a, DWORD len_a, WCHAR **comp_w, DWORD *len_w, WCHAR **buf)
1479 *len_w = len_a;
1481 if(!comp_a) {
1482 *comp_w = NULL;
1483 return TRUE;
1486 if(!(*comp_w = *buf = heap_alloc(len_a*sizeof(WCHAR)))) {
1487 SetLastError(ERROR_OUTOFMEMORY);
1488 return FALSE;
1491 return TRUE;
1494 /***********************************************************************
1495 * InternetCrackUrlA (WININET.@)
1497 * See InternetCrackUrlW.
1499 BOOL WINAPI InternetCrackUrlA(const char *url, DWORD url_length, DWORD flags, URL_COMPONENTSA *ret_comp)
1501 WCHAR *host = NULL, *user = NULL, *pass = NULL, *path = NULL, *scheme = NULL, *extra = NULL;
1502 URL_COMPONENTSW comp;
1503 WCHAR *url_w = NULL;
1504 BOOL ret;
1506 TRACE("(%s %u %x %p)\n", url_length ? debugstr_an(url, url_length) : debugstr_a(url), url_length, flags, ret_comp);
1508 if (!url || !*url || !ret_comp || ret_comp->dwStructSize != sizeof(URL_COMPONENTSA)) {
1509 SetLastError(ERROR_INVALID_PARAMETER);
1510 return FALSE;
1513 comp.dwStructSize = sizeof(comp);
1515 ret = set_url_component_AtoW(ret_comp->lpszHostName, ret_comp->dwHostNameLength,
1516 &comp.lpszHostName, &comp.dwHostNameLength, &host)
1517 && set_url_component_AtoW(ret_comp->lpszUserName, ret_comp->dwUserNameLength,
1518 &comp.lpszUserName, &comp.dwUserNameLength, &user)
1519 && set_url_component_AtoW(ret_comp->lpszPassword, ret_comp->dwPasswordLength,
1520 &comp.lpszPassword, &comp.dwPasswordLength, &pass)
1521 && set_url_component_AtoW(ret_comp->lpszUrlPath, ret_comp->dwUrlPathLength,
1522 &comp.lpszUrlPath, &comp.dwUrlPathLength, &path)
1523 && set_url_component_AtoW(ret_comp->lpszScheme, ret_comp->dwSchemeLength,
1524 &comp.lpszScheme, &comp.dwSchemeLength, &scheme)
1525 && set_url_component_AtoW(ret_comp->lpszExtraInfo, ret_comp->dwExtraInfoLength,
1526 &comp.lpszExtraInfo, &comp.dwExtraInfoLength, &extra);
1528 if(ret && !(url_w = heap_strndupAtoW(url, url_length ? url_length : -1, &url_length))) {
1529 SetLastError(ERROR_OUTOFMEMORY);
1530 ret = FALSE;
1533 if (ret && (ret = InternetCrackUrlW(url_w, url_length, flags, &comp))) {
1534 ret_comp->nScheme = comp.nScheme;
1535 ret_comp->nPort = comp.nPort;
1537 ret = set_url_component_WtoA(comp.lpszHostName, comp.dwHostNameLength, url_w,
1538 &ret_comp->lpszHostName, &ret_comp->dwHostNameLength, url)
1539 && set_url_component_WtoA(comp.lpszUserName, comp.dwUserNameLength, url_w,
1540 &ret_comp->lpszUserName, &ret_comp->dwUserNameLength, url)
1541 && set_url_component_WtoA(comp.lpszPassword, comp.dwPasswordLength, url_w,
1542 &ret_comp->lpszPassword, &ret_comp->dwPasswordLength, url)
1543 && set_url_component_WtoA(comp.lpszUrlPath, comp.dwUrlPathLength, url_w,
1544 &ret_comp->lpszUrlPath, &ret_comp->dwUrlPathLength, url)
1545 && set_url_component_WtoA(comp.lpszScheme, comp.dwSchemeLength, url_w,
1546 &ret_comp->lpszScheme, &ret_comp->dwSchemeLength, url)
1547 && set_url_component_WtoA(comp.lpszExtraInfo, comp.dwExtraInfoLength, url_w,
1548 &ret_comp->lpszExtraInfo, &ret_comp->dwExtraInfoLength, url);
1550 if(ret)
1551 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url),
1552 debugstr_an(ret_comp->lpszScheme, ret_comp->dwSchemeLength),
1553 debugstr_an(ret_comp->lpszHostName, ret_comp->dwHostNameLength),
1554 debugstr_an(ret_comp->lpszUrlPath, ret_comp->dwUrlPathLength),
1555 debugstr_an(ret_comp->lpszExtraInfo, ret_comp->dwExtraInfoLength));
1558 heap_free(host);
1559 heap_free(user);
1560 heap_free(pass);
1561 heap_free(path);
1562 heap_free(scheme);
1563 heap_free(extra);
1564 heap_free(url_w);
1565 return ret;
1568 static const WCHAR *url_schemes[] =
1570 L"ftp",
1571 L"gopher",
1572 L"http",
1573 L"https",
1574 L"file",
1575 L"news",
1576 L"mailto",
1577 L"socks",
1578 L"javascript",
1579 L"vbscript",
1580 L"res"
1583 /***********************************************************************
1584 * GetInternetSchemeW (internal)
1586 * Get scheme of url
1588 * RETURNS
1589 * scheme on success
1590 * INTERNET_SCHEME_UNKNOWN on failure
1593 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1595 int i;
1597 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1599 if(lpszScheme==NULL)
1600 return INTERNET_SCHEME_UNKNOWN;
1602 for (i = 0; i < ARRAY_SIZE(url_schemes); i++)
1603 if (!wcsnicmp(lpszScheme, url_schemes[i], nMaxCmp))
1604 return INTERNET_SCHEME_FIRST + i;
1606 return INTERNET_SCHEME_UNKNOWN;
1609 /***********************************************************************
1610 * InternetCrackUrlW (WININET.@)
1612 * Break up URL into its components
1614 * RETURNS
1615 * TRUE on success
1616 * FALSE on failure
1618 BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
1621 * RFC 1808
1622 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1625 LPCWSTR lpszParam = NULL;
1626 BOOL found_colon = FALSE;
1627 LPCWSTR lpszap;
1628 LPCWSTR lpszcp = NULL, lpszNetLoc;
1630 TRACE("(%s %u %x %p)\n",
1631 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : lstrlenW(lpszUrl)) : "(null)",
1632 dwUrlLength, dwFlags, lpUC);
1634 if (!lpszUrl || !*lpszUrl || !lpUC)
1636 SetLastError(ERROR_INVALID_PARAMETER);
1637 return FALSE;
1639 if (!dwUrlLength) dwUrlLength = lstrlenW(lpszUrl);
1641 if (dwFlags & ICU_DECODE)
1643 WCHAR *url_tmp, *buffer;
1644 DWORD len = dwUrlLength + 1;
1645 BOOL ret;
1647 if (!(url_tmp = heap_strndupW(lpszUrl, dwUrlLength)))
1649 SetLastError(ERROR_OUTOFMEMORY);
1650 return FALSE;
1653 buffer = url_tmp;
1654 ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
1655 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1657 buffer = heap_alloc(len * sizeof(WCHAR));
1658 if (!buffer)
1660 SetLastError(ERROR_OUTOFMEMORY);
1661 heap_free(url_tmp);
1662 return FALSE;
1664 ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
1666 if (ret)
1667 ret = InternetCrackUrlW(buffer, len, dwFlags & ~ICU_DECODE, lpUC);
1669 if (buffer != url_tmp) heap_free(buffer);
1670 heap_free(url_tmp);
1671 return ret;
1673 lpszap = lpszUrl;
1675 /* Determine if the URI is absolute. */
1676 while (lpszap - lpszUrl < dwUrlLength)
1678 if (iswalnum(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1680 lpszap++;
1681 continue;
1683 if (*lpszap == ':')
1685 found_colon = TRUE;
1686 lpszcp = lpszap;
1688 else
1690 lpszcp = lpszUrl; /* Relative url */
1693 break;
1696 if(!found_colon){
1697 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1698 return FALSE;
1701 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1702 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1704 /* Parse <params> */
1705 lpszParam = wmemchr(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1706 if(!lpszParam)
1707 lpszParam = wmemchr(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1709 if(!set_url_component(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1710 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0))
1711 return FALSE;
1714 /* Get scheme first. */
1715 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1716 if(!set_url_component(&lpUC->lpszScheme, &lpUC->dwSchemeLength, lpszUrl, lpszcp - lpszUrl))
1717 return FALSE;
1719 /* Eat ':' in protocol. */
1720 lpszcp++;
1722 /* double slash indicates the net_loc portion is present */
1723 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1725 lpszcp += 2;
1727 lpszNetLoc = wmemchr(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1728 if (lpszParam)
1730 if (lpszNetLoc)
1731 lpszNetLoc = min(lpszNetLoc, lpszParam);
1732 else
1733 lpszNetLoc = lpszParam;
1735 else if (!lpszNetLoc)
1736 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1738 /* Parse net-loc */
1739 if (lpszNetLoc)
1741 LPCWSTR lpszHost;
1742 LPCWSTR lpszPort;
1744 /* [<user>[<:password>]@]<host>[:<port>] */
1745 /* First find the user and password if they exist */
1747 lpszHost = wmemchr(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1748 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1750 /* username and password not specified. */
1751 set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1752 set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1754 else /* Parse out username and password */
1756 LPCWSTR lpszUser = lpszcp;
1757 LPCWSTR lpszPasswd = lpszHost;
1759 while (lpszcp < lpszHost)
1761 if (*lpszcp == ':')
1762 lpszPasswd = lpszcp;
1764 lpszcp++;
1767 if(!set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, lpszUser, lpszPasswd - lpszUser))
1768 return FALSE;
1770 if (lpszPasswd != lpszHost)
1771 lpszPasswd++;
1772 if(!set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1773 lpszPasswd == lpszHost ? NULL : lpszPasswd, lpszHost - lpszPasswd))
1774 return FALSE;
1776 lpszcp++; /* Advance to beginning of host */
1779 /* Parse <host><:port> */
1781 lpszHost = lpszcp;
1782 lpszPort = lpszNetLoc;
1784 /* special case for res:// URLs: there is no port here, so the host is the
1785 entire string up to the first '/' */
1786 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1788 if(!set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost))
1789 return FALSE;
1790 lpszcp=lpszNetLoc;
1792 else
1794 while (lpszcp < lpszNetLoc)
1796 if (*lpszcp == ':')
1797 lpszPort = lpszcp;
1799 lpszcp++;
1802 /* If the scheme is "file" and the host is just one letter, it's not a host */
1803 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1805 lpszcp=lpszHost;
1806 set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1808 else
1810 if(!set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost))
1811 return FALSE;
1812 if (lpszPort != lpszNetLoc)
1813 lpUC->nPort = wcstol(++lpszPort, NULL, 10);
1814 else switch (lpUC->nScheme)
1816 case INTERNET_SCHEME_HTTP:
1817 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1818 break;
1819 case INTERNET_SCHEME_HTTPS:
1820 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1821 break;
1822 case INTERNET_SCHEME_FTP:
1823 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1824 break;
1825 default:
1826 break;
1832 else
1834 set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1835 set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1836 set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1839 /* Here lpszcp points to:
1841 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1842 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1844 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1846 DWORD len;
1848 /* Only truncate the parameter list if it's already been saved
1849 * in lpUC->lpszExtraInfo.
1851 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1852 len = lpszParam - lpszcp;
1853 else
1855 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1856 * newlines if necessary.
1858 LPWSTR lpsznewline = wmemchr(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1859 if (lpsznewline != NULL)
1860 len = lpsznewline - lpszcp;
1861 else
1862 len = dwUrlLength-(lpszcp-lpszUrl);
1864 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1865 lpUC->nScheme == INTERNET_SCHEME_FILE)
1867 WCHAR tmppath[MAX_PATH];
1868 if (*lpszcp == '/')
1870 len = MAX_PATH;
1871 PathCreateFromUrlW(lpszUrl, tmppath, &len, 0);
1873 else
1875 WCHAR *iter;
1876 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1877 tmppath[len] = '\0';
1879 iter = tmppath;
1880 while (*iter) {
1881 if (*iter == '/')
1882 *iter = '\\';
1883 ++iter;
1886 /* if ends in \. or \.. append a backslash */
1887 if (tmppath[len - 1] == '.' &&
1888 (tmppath[len - 2] == '\\' ||
1889 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1891 if (len < MAX_PATH - 1)
1893 tmppath[len] = '\\';
1894 tmppath[len+1] = '\0';
1895 ++len;
1898 if(!set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, tmppath, len))
1899 return FALSE;
1901 else if(!set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, lpszcp, len))
1902 return FALSE;
1904 else
1906 set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, lpszcp, 0);
1909 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1910 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1911 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1912 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1913 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1915 return TRUE;
1918 /***********************************************************************
1919 * InternetAttemptConnect (WININET.@)
1921 * Attempt to make a connection to the internet
1923 * RETURNS
1924 * ERROR_SUCCESS on success
1925 * Error value on failure
1928 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1930 FIXME("Stub\n");
1931 return ERROR_SUCCESS;
1935 /***********************************************************************
1936 * convert_url_canonicalization_flags
1938 * Helper for InternetCanonicalizeUrl
1940 * PARAMS
1941 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1943 * RETURNS
1944 * Flags suitable for UrlCanonicalize
1946 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
1948 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1950 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
1951 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
1952 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
1953 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
1954 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1955 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
1956 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
1958 return dwUrlFlags;
1961 /***********************************************************************
1962 * InternetCanonicalizeUrlA (WININET.@)
1964 * Escape unsafe characters and spaces
1966 * RETURNS
1967 * TRUE on success
1968 * FALSE on failure
1971 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1972 LPDWORD lpdwBufferLength, DWORD dwFlags)
1974 HRESULT hr;
1976 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1977 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1979 dwFlags = convert_url_canonicalization_flags(dwFlags);
1980 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1981 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1982 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1984 return hr == S_OK;
1987 /***********************************************************************
1988 * InternetCanonicalizeUrlW (WININET.@)
1990 * Escape unsafe characters and spaces
1992 * RETURNS
1993 * TRUE on success
1994 * FALSE on failure
1997 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1998 LPDWORD lpdwBufferLength, DWORD dwFlags)
2000 HRESULT hr;
2002 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2003 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2005 dwFlags = convert_url_canonicalization_flags(dwFlags);
2006 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2007 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2008 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2010 return hr == S_OK;
2013 /* #################################################### */
2015 static INTERNET_STATUS_CALLBACK set_status_callback(
2016 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2018 INTERNET_STATUS_CALLBACK ret;
2020 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2021 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2023 ret = lpwh->lpfnStatusCB;
2024 lpwh->lpfnStatusCB = callback;
2026 return ret;
2029 /***********************************************************************
2030 * InternetSetStatusCallbackA (WININET.@)
2032 * Sets up a callback function which is called as progress is made
2033 * during an operation.
2035 * RETURNS
2036 * Previous callback or NULL on success
2037 * INTERNET_INVALID_STATUS_CALLBACK on failure
2040 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2041 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2043 INTERNET_STATUS_CALLBACK retVal;
2044 object_header_t *lpwh;
2046 TRACE("%p\n", hInternet);
2048 if (!(lpwh = get_handle_object(hInternet)))
2049 return INTERNET_INVALID_STATUS_CALLBACK;
2051 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2053 WININET_Release( lpwh );
2054 return retVal;
2057 /***********************************************************************
2058 * InternetSetStatusCallbackW (WININET.@)
2060 * Sets up a callback function which is called as progress is made
2061 * during an operation.
2063 * RETURNS
2064 * Previous callback or NULL on success
2065 * INTERNET_INVALID_STATUS_CALLBACK on failure
2068 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2069 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2071 INTERNET_STATUS_CALLBACK retVal;
2072 object_header_t *lpwh;
2074 TRACE("%p\n", hInternet);
2076 if (!(lpwh = get_handle_object(hInternet)))
2077 return INTERNET_INVALID_STATUS_CALLBACK;
2079 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2081 WININET_Release( lpwh );
2082 return retVal;
2085 /***********************************************************************
2086 * InternetSetFilePointer (WININET.@)
2088 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2089 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2091 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2093 SetLastError(ERROR_INTERNET_INVALID_OPERATION);
2094 return INVALID_SET_FILE_POINTER;
2097 /***********************************************************************
2098 * InternetWriteFile (WININET.@)
2100 * Write data to an open internet file
2102 * RETURNS
2103 * TRUE on success
2104 * FALSE on failure
2107 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2108 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2110 object_header_t *lpwh;
2111 BOOL res;
2113 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2115 lpwh = get_handle_object( hFile );
2116 if (!lpwh) {
2117 WARN("Invalid handle\n");
2118 SetLastError(ERROR_INVALID_HANDLE);
2119 return FALSE;
2122 if(lpwh->vtbl->WriteFile) {
2123 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2124 }else {
2125 WARN("No Writefile method.\n");
2126 res = ERROR_INVALID_HANDLE;
2129 WININET_Release( lpwh );
2131 if(res != ERROR_SUCCESS)
2132 SetLastError(res);
2133 return res == ERROR_SUCCESS;
2137 /***********************************************************************
2138 * InternetReadFile (WININET.@)
2140 * Read data from an open internet file
2142 * RETURNS
2143 * TRUE on success
2144 * FALSE on failure
2147 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2148 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2150 object_header_t *hdr;
2151 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2153 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2155 hdr = get_handle_object(hFile);
2156 if (!hdr) {
2157 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2158 return FALSE;
2161 if(hdr->vtbl->ReadFile) {
2162 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, 0, 0);
2163 if(res == ERROR_IO_PENDING)
2164 *pdwNumOfBytesRead = 0;
2167 WININET_Release(hdr);
2169 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2170 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2172 SetLastError(res);
2173 return res == ERROR_SUCCESS;
2176 /***********************************************************************
2177 * InternetReadFileExA (WININET.@)
2179 * Read data from an open internet file
2181 * PARAMS
2182 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2183 * lpBuffersOut [I/O] Buffer.
2184 * dwFlags [I] Flags. See notes.
2185 * dwContext [I] Context for callbacks.
2187 * RETURNS
2188 * TRUE on success
2189 * FALSE on failure
2191 * NOTES
2192 * The parameter dwFlags include zero or more of the following flags:
2193 *|IRF_ASYNC - Makes the call asynchronous.
2194 *|IRF_SYNC - Makes the call synchronous.
2195 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2196 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2198 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2200 * SEE
2201 * InternetOpenUrlA(), HttpOpenRequestA()
2203 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2204 DWORD dwFlags, DWORD_PTR dwContext)
2206 object_header_t *hdr;
2207 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2209 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2211 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2212 SetLastError(ERROR_INVALID_PARAMETER);
2213 return FALSE;
2216 hdr = get_handle_object(hFile);
2217 if (!hdr) {
2218 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2219 return FALSE;
2222 if(hdr->vtbl->ReadFile)
2223 res = hdr->vtbl->ReadFile(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2224 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2226 WININET_Release(hdr);
2228 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2229 res, lpBuffersOut->dwBufferLength);
2231 if(res != ERROR_SUCCESS)
2232 SetLastError(res);
2233 return res == ERROR_SUCCESS;
2236 /***********************************************************************
2237 * InternetReadFileExW (WININET.@)
2238 * SEE
2239 * InternetReadFileExA()
2241 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2242 DWORD dwFlags, DWORD_PTR dwContext)
2244 object_header_t *hdr;
2245 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2247 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2249 if (!lpBuffer || lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2250 SetLastError(ERROR_INVALID_PARAMETER);
2251 return FALSE;
2254 hdr = get_handle_object(hFile);
2255 if (!hdr) {
2256 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2257 return FALSE;
2260 if(hdr->vtbl->ReadFile)
2261 res = hdr->vtbl->ReadFile(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2262 dwFlags, dwContext);
2264 WININET_Release(hdr);
2266 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2267 res, lpBuffer->dwBufferLength);
2269 if(res != ERROR_SUCCESS)
2270 SetLastError(res);
2271 return res == ERROR_SUCCESS;
2274 static IP_ADAPTER_ADDRESSES *get_adapters(void)
2276 ULONG err, size = 1024, flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
2277 GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME;
2278 IP_ADAPTER_ADDRESSES *tmp, *ret;
2280 if (!(ret = heap_alloc( size ))) return NULL;
2281 err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
2282 while (err == ERROR_BUFFER_OVERFLOW)
2284 if (!(tmp = heap_realloc( ret, size ))) break;
2285 ret = tmp;
2286 err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
2288 if (err == ERROR_SUCCESS) return ret;
2289 heap_free( ret );
2290 return NULL;
2293 static WCHAR *detect_proxy_autoconfig_url_dhcp(void)
2295 IP_ADAPTER_ADDRESSES *adapters, *ptr;
2296 DHCPCAPI_PARAMS_ARRAY send_params, recv_params;
2297 DHCPCAPI_PARAMS param;
2298 WCHAR name[MAX_ADAPTER_NAME_LENGTH + 1], *ret = NULL;
2299 DWORD err, size;
2300 BYTE *tmp, *buf = NULL;
2302 if (!(adapters = get_adapters())) return NULL;
2304 memset( &send_params, 0, sizeof(send_params) );
2305 memset( &param, 0, sizeof(param) );
2306 param.OptionId = OPTION_MSFT_IE_PROXY;
2307 recv_params.nParams = 1;
2308 recv_params.Params = &param;
2310 for (ptr = adapters; ptr; ptr = ptr->Next)
2312 MultiByteToWideChar( CP_ACP, 0, ptr->AdapterName, -1, name, ARRAY_SIZE(name) );
2313 TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name), ptr->IfType, ptr->Dhcpv4Enabled );
2315 if (ptr->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2316 /* FIXME: also skip adapters where DHCP is disabled */
2318 size = 256;
2319 if (!(buf = heap_alloc( size ))) goto done;
2320 err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
2321 buf, &size, NULL );
2322 while (err == ERROR_MORE_DATA)
2324 if (!(tmp = heap_realloc( buf, size ))) goto done;
2325 buf = tmp;
2326 err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
2327 buf, &size, NULL );
2329 if (err == ERROR_SUCCESS && param.nBytesData)
2331 int len = MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, NULL, 0 );
2332 if ((ret = heap_alloc( (len + 1) * sizeof(WCHAR) )))
2334 MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, ret, len );
2335 ret[len] = 0;
2337 TRACE("returning %s\n", debugstr_w(ret));
2338 break;
2342 done:
2343 heap_free( buf );
2344 heap_free( adapters );
2345 return ret;
2348 static char *get_computer_name( COMPUTER_NAME_FORMAT format )
2350 char *ret;
2351 DWORD size = 0;
2353 GetComputerNameExA( format, NULL, &size );
2354 if (GetLastError() != ERROR_MORE_DATA) return NULL;
2355 if (!(ret = heap_alloc( size ))) return NULL;
2356 if (!GetComputerNameExA( format, ret, &size ))
2358 heap_free( ret );
2359 return NULL;
2361 return ret;
2364 static BOOL is_domain_suffix( const char *domain, const char *suffix )
2366 int len_domain = strlen( domain ), len_suffix = strlen( suffix );
2368 if (len_suffix > len_domain) return FALSE;
2369 if (!stricmp( domain + len_domain - len_suffix, suffix )) return TRUE;
2370 return FALSE;
2373 static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len )
2375 return getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 );
2378 static WCHAR *build_wpad_url( const char *hostname, const struct addrinfo *ai )
2380 char name[NI_MAXHOST];
2381 WCHAR *ret, *p;
2382 int len;
2384 while (ai && ai->ai_family != AF_INET && ai->ai_family != AF_INET6) ai = ai->ai_next;
2385 if (!ai) return NULL;
2387 if (!reverse_lookup( ai, name, sizeof(name) )) hostname = name;
2389 len = lstrlenW( L"http://" ) + strlen( hostname ) + lstrlenW( L"/wpad.dat" );
2390 if (!(ret = p = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
2391 lstrcpyW( p, L"http://" );
2392 p += lstrlenW( L"http://" );
2393 while (*hostname) { *p++ = *hostname++; }
2394 lstrcpyW( p, L"/wpad.dat" );
2395 return ret;
2398 static WCHAR *detect_proxy_autoconfig_url_dns(void)
2400 char *fqdn, *domain, *p;
2401 WCHAR *ret;
2403 if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return NULL;
2404 if (!(domain = get_computer_name( ComputerNamePhysicalDnsDomain )))
2406 heap_free( fqdn );
2407 return NULL;
2409 p = fqdn;
2410 while ((p = strchr( p, '.' )) && is_domain_suffix( p + 1, domain ))
2412 char *name;
2413 struct addrinfo *ai;
2414 int res;
2416 if (!(name = heap_alloc( sizeof("wpad") + strlen(p) )))
2418 heap_free( fqdn );
2419 heap_free( domain );
2420 return NULL;
2422 strcpy( name, "wpad" );
2423 strcat( name, p );
2424 res = getaddrinfo( name, NULL, NULL, &ai );
2425 if (!res)
2427 ret = build_wpad_url( name, ai );
2428 freeaddrinfo( ai );
2429 if (ret)
2431 TRACE("returning %s\n", debugstr_w(ret));
2432 heap_free( name );
2433 break;
2436 heap_free( name );
2437 p++;
2439 heap_free( domain );
2440 heap_free( fqdn );
2441 return ret;
2444 static WCHAR *get_proxy_autoconfig_url(void)
2446 WCHAR *ret = detect_proxy_autoconfig_url_dhcp();
2447 if (!ret) ret = detect_proxy_autoconfig_url_dns();
2448 return ret;
2451 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2453 /* FIXME: This function currently handles more options than it should. Options requiring
2454 * proper handles should be moved to proper functions */
2455 switch(option) {
2456 case INTERNET_OPTION_HTTP_VERSION:
2457 if (*size < sizeof(HTTP_VERSION_INFO))
2458 return ERROR_INSUFFICIENT_BUFFER;
2461 * Presently hardcoded to 1.1
2463 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2464 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2465 *size = sizeof(HTTP_VERSION_INFO);
2467 return ERROR_SUCCESS;
2469 case INTERNET_OPTION_CONNECTED_STATE:
2470 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2472 if (*size < sizeof(ULONG))
2473 return ERROR_INSUFFICIENT_BUFFER;
2475 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2476 *size = sizeof(ULONG);
2478 return ERROR_SUCCESS;
2480 case INTERNET_OPTION_PROXY: {
2481 appinfo_t ai;
2482 BOOL ret;
2484 TRACE("Getting global proxy info\n");
2485 memset(&ai, 0, sizeof(appinfo_t));
2486 INTERNET_ConfigureProxy(&ai);
2488 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2489 APPINFO_Destroy(&ai.hdr);
2490 return ret;
2493 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2494 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2496 if (*size < sizeof(ULONG))
2497 return ERROR_INSUFFICIENT_BUFFER;
2499 *(ULONG*)buffer = max_conns;
2500 *size = sizeof(ULONG);
2502 return ERROR_SUCCESS;
2504 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2505 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2507 if (*size < sizeof(ULONG))
2508 return ERROR_INSUFFICIENT_BUFFER;
2510 *(ULONG*)buffer = max_1_0_conns;
2511 *size = sizeof(ULONG);
2513 return ERROR_SUCCESS;
2515 case INTERNET_OPTION_SECURITY_FLAGS:
2516 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2517 return ERROR_SUCCESS;
2519 case INTERNET_OPTION_VERSION: {
2520 static const INTERNET_VERSION_INFO info = { 1, 2 };
2522 TRACE("INTERNET_OPTION_VERSION\n");
2524 if (*size < sizeof(INTERNET_VERSION_INFO))
2525 return ERROR_INSUFFICIENT_BUFFER;
2527 memcpy(buffer, &info, sizeof(info));
2528 *size = sizeof(info);
2530 return ERROR_SUCCESS;
2533 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2534 WCHAR *url;
2535 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2536 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2537 DWORD res = ERROR_SUCCESS, i;
2538 proxyinfo_t pi;
2539 LONG ret;
2541 TRACE("Getting global proxy info\n");
2542 if((ret = INTERNET_LoadProxySettings(&pi)))
2543 return ret;
2545 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2547 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2548 FreeProxyInfo(&pi);
2549 return ERROR_INSUFFICIENT_BUFFER;
2552 url = get_proxy_autoconfig_url();
2554 for (i = 0; i < con->dwOptionCount; i++) {
2555 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2556 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2558 switch (optionW->dwOption) {
2559 case INTERNET_PER_CONN_FLAGS:
2560 if(pi.proxyEnabled)
2561 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2562 else
2563 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2564 if (url)
2565 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2566 optionW->Value.dwValue |= PROXY_TYPE_DIRECT|PROXY_TYPE_AUTO_PROXY_URL;
2567 break;
2569 case INTERNET_PER_CONN_PROXY_SERVER:
2570 if (unicode)
2571 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2572 else
2573 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2574 break;
2576 case INTERNET_PER_CONN_PROXY_BYPASS:
2577 if (unicode)
2578 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2579 else
2580 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2581 break;
2583 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2584 if (!url)
2585 optionW->Value.pszValue = NULL;
2586 else if (unicode)
2587 optionW->Value.pszValue = heap_strdupW(url);
2588 else
2589 optionA->Value.pszValue = heap_strdupWtoA(url);
2590 break;
2592 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2593 optionW->Value.dwValue = AUTO_PROXY_FLAG_ALWAYS_DETECT;
2594 break;
2596 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2597 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2598 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2599 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2600 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2601 memset(&optionW->Value, 0, sizeof(optionW->Value));
2602 break;
2604 default:
2605 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2606 res = ERROR_INVALID_PARAMETER;
2607 break;
2610 heap_free(url);
2611 FreeProxyInfo(&pi);
2613 return res;
2615 case INTERNET_OPTION_REQUEST_FLAGS:
2616 case INTERNET_OPTION_USER_AGENT:
2617 *size = 0;
2618 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2619 case INTERNET_OPTION_POLICY:
2620 return ERROR_INVALID_PARAMETER;
2621 case INTERNET_OPTION_CONNECT_TIMEOUT:
2622 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2624 if (*size < sizeof(ULONG))
2625 return ERROR_INSUFFICIENT_BUFFER;
2627 *(ULONG*)buffer = connect_timeout;
2628 *size = sizeof(ULONG);
2630 return ERROR_SUCCESS;
2633 FIXME("Stub for %d\n", option);
2634 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2637 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2639 switch(option) {
2640 case INTERNET_OPTION_CONTEXT_VALUE:
2641 if (!size)
2642 return ERROR_INVALID_PARAMETER;
2644 if (*size < sizeof(DWORD_PTR)) {
2645 *size = sizeof(DWORD_PTR);
2646 return ERROR_INSUFFICIENT_BUFFER;
2648 if (!buffer)
2649 return ERROR_INVALID_PARAMETER;
2651 *(DWORD_PTR *)buffer = hdr->dwContext;
2652 *size = sizeof(DWORD_PTR);
2653 return ERROR_SUCCESS;
2655 case INTERNET_OPTION_REQUEST_FLAGS:
2656 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2657 *size = sizeof(DWORD);
2658 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2660 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2661 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2662 WARN("Called on global option %u\n", option);
2663 return ERROR_INTERNET_INVALID_OPERATION;
2666 /* FIXME: we shouldn't call it here */
2667 return query_global_option(option, buffer, size, unicode);
2670 /***********************************************************************
2671 * InternetQueryOptionW (WININET.@)
2673 * Queries an options on the specified handle
2675 * RETURNS
2676 * TRUE on success
2677 * FALSE on failure
2680 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2681 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2683 object_header_t *hdr;
2684 DWORD res = ERROR_INVALID_HANDLE;
2686 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2688 if(hInternet) {
2689 hdr = get_handle_object(hInternet);
2690 if (hdr) {
2691 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2692 WININET_Release(hdr);
2694 }else {
2695 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2698 if(res != ERROR_SUCCESS)
2699 SetLastError(res);
2700 return res == ERROR_SUCCESS;
2703 /***********************************************************************
2704 * InternetQueryOptionA (WININET.@)
2706 * Queries an options on the specified handle
2708 * RETURNS
2709 * TRUE on success
2710 * FALSE on failure
2713 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2714 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2716 object_header_t *hdr;
2717 DWORD res = ERROR_INVALID_HANDLE;
2719 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2721 if(hInternet) {
2722 hdr = get_handle_object(hInternet);
2723 if (hdr) {
2724 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2725 WININET_Release(hdr);
2727 }else {
2728 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2731 if(res != ERROR_SUCCESS)
2732 SetLastError(res);
2733 return res == ERROR_SUCCESS;
2736 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2738 switch(option) {
2739 case INTERNET_OPTION_SETTINGS_CHANGED:
2740 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2741 collect_connections(COLLECT_CONNECTIONS);
2742 return ERROR_SUCCESS;
2743 case INTERNET_OPTION_CALLBACK:
2744 WARN("Not settable option %u\n", option);
2745 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2746 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2747 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2748 WARN("Called on global option %u\n", option);
2749 return ERROR_INTERNET_INVALID_OPERATION;
2750 case INTERNET_OPTION_REFRESH:
2751 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2754 return ERROR_INTERNET_INVALID_OPTION;
2757 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2759 switch(option) {
2760 case INTERNET_OPTION_CALLBACK:
2761 WARN("Not global option %u\n", option);
2762 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2764 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2765 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2767 if(size != sizeof(max_conns))
2768 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2769 if(!*(ULONG*)buf)
2770 return ERROR_BAD_ARGUMENTS;
2772 max_conns = *(ULONG*)buf;
2773 return ERROR_SUCCESS;
2775 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2776 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2778 if(size != sizeof(max_1_0_conns))
2779 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2780 if(!*(ULONG*)buf)
2781 return ERROR_BAD_ARGUMENTS;
2783 max_1_0_conns = *(ULONG*)buf;
2784 return ERROR_SUCCESS;
2786 case INTERNET_OPTION_CONNECT_TIMEOUT:
2787 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2789 if(size != sizeof(connect_timeout))
2790 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2791 if(!*(ULONG*)buf)
2792 return ERROR_BAD_ARGUMENTS;
2794 connect_timeout = *(ULONG*)buf;
2795 return ERROR_SUCCESS;
2797 case INTERNET_OPTION_SUPPRESS_BEHAVIOR:
2798 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2800 if(size != sizeof(ULONG))
2801 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2803 FIXME("%08x\n", *(ULONG*)buf);
2804 return ERROR_SUCCESS;
2807 return INET_SetOption(NULL, option, buf, size);
2810 /***********************************************************************
2811 * InternetSetOptionW (WININET.@)
2813 * Sets an options on the specified handle
2815 * RETURNS
2816 * TRUE on success
2817 * FALSE on failure
2820 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2821 LPVOID lpBuffer, DWORD dwBufferLength)
2823 object_header_t *lpwhh;
2824 BOOL ret = TRUE;
2825 DWORD res;
2827 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2829 lpwhh = (object_header_t*) get_handle_object( hInternet );
2830 if(lpwhh)
2831 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2832 else
2833 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2835 if(res != ERROR_INTERNET_INVALID_OPTION) {
2836 if(lpwhh)
2837 WININET_Release(lpwhh);
2839 if(res != ERROR_SUCCESS)
2840 SetLastError(res);
2842 return res == ERROR_SUCCESS;
2845 switch (dwOption)
2847 case INTERNET_OPTION_HTTP_VERSION:
2849 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2850 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2852 break;
2853 case INTERNET_OPTION_ERROR_MASK:
2855 if(!lpwhh) {
2856 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2857 return FALSE;
2858 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2859 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2860 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2861 SetLastError(ERROR_INVALID_PARAMETER);
2862 ret = FALSE;
2863 } else if(dwBufferLength != sizeof(ULONG)) {
2864 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2865 ret = FALSE;
2866 } else
2867 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2868 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2870 break;
2871 case INTERNET_OPTION_PROXY:
2873 INTERNET_PROXY_INFOW *info = lpBuffer;
2875 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2877 SetLastError(ERROR_INVALID_PARAMETER);
2878 return FALSE;
2880 if (!hInternet)
2882 EnterCriticalSection( &WININET_cs );
2883 free_global_proxy();
2884 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2885 if (global_proxy)
2887 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2889 global_proxy->proxyEnabled = 1;
2890 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2891 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2893 else
2895 global_proxy->proxyEnabled = 0;
2896 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2899 LeaveCriticalSection( &WININET_cs );
2901 else
2903 /* In general, each type of object should handle
2904 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2905 * get silently dropped.
2907 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2908 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2909 ret = FALSE;
2911 break;
2913 case INTERNET_OPTION_CODEPAGE:
2915 ULONG codepage = *(ULONG *)lpBuffer;
2916 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2918 break;
2919 case INTERNET_OPTION_REQUEST_PRIORITY:
2921 ULONG priority = *(ULONG *)lpBuffer;
2922 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2924 break;
2925 case INTERNET_OPTION_CONNECT_TIMEOUT:
2927 ULONG connecttimeout = *(ULONG *)lpBuffer;
2928 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2930 break;
2931 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2933 ULONG receivetimeout = *(ULONG *)lpBuffer;
2934 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2936 break;
2937 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2938 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2939 break;
2940 case INTERNET_OPTION_END_BROWSER_SESSION:
2941 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2942 free_cookie();
2943 free_authorization_cache();
2944 break;
2945 case INTERNET_OPTION_CONNECTED_STATE:
2946 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2947 break;
2948 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2949 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2950 break;
2951 case INTERNET_OPTION_IGNORE_OFFLINE:
2952 FIXME("Option INTERNET_OPTION_IGNORE_OFFLINE: STUB\n");
2953 break;
2954 case INTERNET_OPTION_SEND_TIMEOUT:
2955 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2956 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2958 ULONG timeout = *(ULONG *)lpBuffer;
2959 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2960 break;
2962 case INTERNET_OPTION_CONNECT_RETRIES:
2964 ULONG retries = *(ULONG *)lpBuffer;
2965 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2966 break;
2968 case INTERNET_OPTION_CONTEXT_VALUE:
2970 if (!lpwhh)
2972 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2973 return FALSE;
2975 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2977 SetLastError(ERROR_INVALID_PARAMETER);
2978 ret = FALSE;
2980 else
2981 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2982 break;
2984 case INTERNET_OPTION_SECURITY_FLAGS:
2985 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2986 break;
2987 case INTERNET_OPTION_DISABLE_AUTODIAL:
2988 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2989 break;
2990 case INTERNET_OPTION_HTTP_DECODING:
2991 if (!lpwhh)
2993 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2994 return FALSE;
2996 if (!lpBuffer || dwBufferLength != sizeof(BOOL))
2998 SetLastError(ERROR_INVALID_PARAMETER);
2999 ret = FALSE;
3001 else
3002 lpwhh->decoding = *(BOOL *)lpBuffer;
3003 break;
3004 case INTERNET_OPTION_COOKIES_3RD_PARTY:
3005 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
3006 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3007 ret = FALSE;
3008 break;
3009 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
3010 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
3011 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3012 ret = FALSE;
3013 break;
3014 case INTERNET_OPTION_CODEPAGE_PATH:
3015 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
3016 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3017 ret = FALSE;
3018 break;
3019 case INTERNET_OPTION_CODEPAGE_EXTRA:
3020 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
3021 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3022 ret = FALSE;
3023 break;
3024 case INTERNET_OPTION_IDN:
3025 FIXME("INTERNET_OPTION_IDN; STUB\n");
3026 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3027 ret = FALSE;
3028 break;
3029 case INTERNET_OPTION_POLICY:
3030 SetLastError(ERROR_INVALID_PARAMETER);
3031 ret = FALSE;
3032 break;
3033 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3034 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
3035 LONG res;
3036 unsigned int i;
3037 proxyinfo_t pi;
3039 if (INTERNET_LoadProxySettings(&pi)) return FALSE;
3041 for (i = 0; i < con->dwOptionCount; i++) {
3042 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
3044 switch (option->dwOption) {
3045 case INTERNET_PER_CONN_PROXY_SERVER:
3046 heap_free(pi.proxy);
3047 pi.proxy = heap_strdupW(option->Value.pszValue);
3048 break;
3050 case INTERNET_PER_CONN_FLAGS:
3051 if(option->Value.dwValue & PROXY_TYPE_PROXY)
3052 pi.proxyEnabled = 1;
3053 else
3055 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
3056 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
3057 pi.proxyEnabled = 0;
3059 break;
3061 case INTERNET_PER_CONN_PROXY_BYPASS:
3062 heap_free(pi.proxyBypass);
3063 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
3064 break;
3066 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3067 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3068 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3069 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3070 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3071 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3072 FIXME("Unhandled dwOption %d\n", option->dwOption);
3073 break;
3075 default:
3076 FIXME("Unknown dwOption %d\n", option->dwOption);
3077 SetLastError(ERROR_INVALID_PARAMETER);
3078 break;
3082 if ((res = INTERNET_SaveProxySettings(&pi)))
3083 SetLastError(res);
3085 FreeProxyInfo(&pi);
3087 ret = (res == ERROR_SUCCESS);
3088 break;
3090 default:
3091 FIXME("Option %d STUB\n",dwOption);
3092 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3093 ret = FALSE;
3094 break;
3097 if(lpwhh)
3098 WININET_Release( lpwhh );
3100 return ret;
3104 /***********************************************************************
3105 * InternetSetOptionA (WININET.@)
3107 * Sets an options on the specified handle.
3109 * RETURNS
3110 * TRUE on success
3111 * FALSE on failure
3114 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
3115 LPVOID lpBuffer, DWORD dwBufferLength)
3117 LPVOID wbuffer;
3118 DWORD wlen;
3119 BOOL r;
3121 switch( dwOption )
3123 case INTERNET_OPTION_PROXY:
3125 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
3126 LPINTERNET_PROXY_INFOW piw;
3127 DWORD proxlen, prbylen;
3128 LPWSTR prox, prby;
3130 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
3131 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
3132 wlen = sizeof(*piw) + proxlen + prbylen;
3133 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
3134 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
3135 piw->dwAccessType = pi->dwAccessType;
3136 prox = (LPWSTR) &piw[1];
3137 prby = &prox[proxlen+1];
3138 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
3139 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
3140 piw->lpszProxy = prox;
3141 piw->lpszProxyBypass = prby;
3143 break;
3144 case INTERNET_OPTION_USER_AGENT:
3145 case INTERNET_OPTION_USERNAME:
3146 case INTERNET_OPTION_PASSWORD:
3147 case INTERNET_OPTION_PROXY_USERNAME:
3148 case INTERNET_OPTION_PROXY_PASSWORD:
3149 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3150 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3151 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3152 break;
3153 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3154 unsigned int i;
3155 INTERNET_PER_CONN_OPTION_LISTW *listW;
3156 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3157 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3158 wbuffer = heap_alloc(wlen);
3159 listW = wbuffer;
3161 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3162 if (listA->pszConnection)
3164 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3165 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3166 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3168 else
3169 listW->pszConnection = NULL;
3170 listW->dwOptionCount = listA->dwOptionCount;
3171 listW->dwOptionError = listA->dwOptionError;
3172 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3174 for (i = 0; i < listA->dwOptionCount; ++i) {
3175 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3176 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3178 optW->dwOption = optA->dwOption;
3180 switch (optA->dwOption) {
3181 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3182 case INTERNET_PER_CONN_PROXY_BYPASS:
3183 case INTERNET_PER_CONN_PROXY_SERVER:
3184 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3185 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3186 if (optA->Value.pszValue)
3188 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3189 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3190 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3192 else
3193 optW->Value.pszValue = NULL;
3194 break;
3195 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3196 case INTERNET_PER_CONN_FLAGS:
3197 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3198 optW->Value.dwValue = optA->Value.dwValue;
3199 break;
3200 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3201 optW->Value.ftValue = optA->Value.ftValue;
3202 break;
3203 default:
3204 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3205 optW->Value.dwValue = optA->Value.dwValue;
3206 break;
3210 break;
3211 default:
3212 wbuffer = lpBuffer;
3213 wlen = dwBufferLength;
3216 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3218 if( lpBuffer != wbuffer )
3220 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3222 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3223 unsigned int i;
3224 for (i = 0; i < list->dwOptionCount; ++i) {
3225 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3226 switch (opt->dwOption) {
3227 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3228 case INTERNET_PER_CONN_PROXY_BYPASS:
3229 case INTERNET_PER_CONN_PROXY_SERVER:
3230 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3231 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3232 heap_free( opt->Value.pszValue );
3233 break;
3234 default:
3235 break;
3238 heap_free( list->pOptions );
3240 heap_free( wbuffer );
3243 return r;
3247 /***********************************************************************
3248 * InternetSetOptionExA (WININET.@)
3250 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3251 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3253 FIXME("Flags %08x ignored\n", dwFlags);
3254 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3257 /***********************************************************************
3258 * InternetSetOptionExW (WININET.@)
3260 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3261 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3263 FIXME("Flags %08x ignored\n", dwFlags);
3264 if( dwFlags & ~ISO_VALID_FLAGS )
3266 SetLastError( ERROR_INVALID_PARAMETER );
3267 return FALSE;
3269 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3272 static const WCHAR WININET_wkday[7][4] =
3273 { L"Sun", L"Mon", L"Tue", L"Wed",
3274 L"Thu", L"Fri", L"Sat"};
3275 static const WCHAR WININET_month[12][4] =
3276 { L"Jan", L"Feb", L"Mar", L"Apr",
3277 L"May", L"Jun", L"Jul", L"Aug",
3278 L"Sep", L"Oct", L"Nov", L"Dec"};
3280 /***********************************************************************
3281 * InternetTimeFromSystemTimeA (WININET.@)
3283 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3285 BOOL ret;
3286 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3288 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3290 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3292 SetLastError(ERROR_INVALID_PARAMETER);
3293 return FALSE;
3296 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3298 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3299 return FALSE;
3302 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3303 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3305 return ret;
3308 /***********************************************************************
3309 * InternetTimeFromSystemTimeW (WININET.@)
3311 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3313 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3315 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3317 SetLastError(ERROR_INVALID_PARAMETER);
3318 return FALSE;
3321 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3323 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3324 return FALSE;
3327 swprintf( string, size, L"%s, %02d %s %4d %02d:%02d:%02d GMT",
3328 WININET_wkday[time->wDayOfWeek],
3329 time->wDay,
3330 WININET_month[time->wMonth - 1],
3331 time->wYear,
3332 time->wHour,
3333 time->wMinute,
3334 time->wSecond );
3336 return TRUE;
3339 /***********************************************************************
3340 * InternetTimeToSystemTimeA (WININET.@)
3342 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3344 BOOL ret = FALSE;
3345 WCHAR *stringW;
3347 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3349 stringW = heap_strdupAtoW(string);
3350 if (stringW)
3352 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3353 heap_free( stringW );
3355 return ret;
3358 /***********************************************************************
3359 * InternetTimeToSystemTimeW (WININET.@)
3361 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3363 unsigned int i;
3364 const WCHAR *s = string;
3365 WCHAR *end;
3367 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3369 if (!string || !time) return FALSE;
3371 /* Windows does this too */
3372 GetSystemTime( time );
3374 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3375 * a SYSTEMTIME structure.
3378 while (*s && !iswalpha( *s )) s++;
3379 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3380 time->wDayOfWeek = 7;
3382 for (i = 0; i < 7; i++)
3384 if (!wcsnicmp( WININET_wkday[i], s, 3 ))
3386 time->wDayOfWeek = i;
3387 break;
3391 if (time->wDayOfWeek > 6) return TRUE;
3392 while (*s && !iswdigit( *s )) s++;
3393 time->wDay = wcstol( s, &end, 10 );
3394 s = end;
3396 while (*s && !iswalpha( *s )) s++;
3397 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3398 time->wMonth = 0;
3400 for (i = 0; i < 12; i++)
3402 if (!wcsnicmp( WININET_month[i], s, 3 ))
3404 time->wMonth = i + 1;
3405 break;
3408 if (time->wMonth == 0) return TRUE;
3410 while (*s && !iswdigit( *s )) s++;
3411 if (*s == '\0') return TRUE;
3412 time->wYear = wcstol( s, &end, 10 );
3413 s = end;
3415 while (*s && !iswdigit( *s )) s++;
3416 if (*s == '\0') return TRUE;
3417 time->wHour = wcstol( s, &end, 10 );
3418 s = end;
3420 while (*s && !iswdigit( *s )) s++;
3421 if (*s == '\0') return TRUE;
3422 time->wMinute = wcstol( s, &end, 10 );
3423 s = end;
3425 while (*s && !iswdigit( *s )) s++;
3426 if (*s == '\0') return TRUE;
3427 time->wSecond = wcstol( s, &end, 10 );
3428 s = end;
3430 time->wMilliseconds = 0;
3431 return TRUE;
3434 /***********************************************************************
3435 * InternetCheckConnectionW (WININET.@)
3437 * Pings a requested host to check internet connection
3439 * RETURNS
3440 * TRUE on success and FALSE on failure. If a failure then
3441 * ERROR_NOT_CONNECTED is placed into GetLastError
3444 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3447 * this is a kludge which runs the resident ping program and reads the output.
3449 * Anyone have a better idea?
3452 BOOL rc = FALSE;
3453 static const CHAR ping[] = "ping -c 1 ";
3454 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3455 WCHAR *host;
3456 DWORD len, host_len;
3457 INTERNET_PORT port;
3458 int status = -1;
3460 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl), dwFlags, dwReserved);
3463 * Crack or set the Address
3465 if (lpszUrl == NULL)
3468 * According to the doc we are supposed to use the ip for the next
3469 * server in the WnInet internal server database. I have
3470 * no idea what that is or how to get it.
3472 * So someone needs to implement this.
3474 FIXME("Unimplemented with URL of NULL\n");
3475 return TRUE;
3477 else
3479 URL_COMPONENTSW components = {sizeof(components)};
3481 components.dwHostNameLength = 1;
3483 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3484 goto End;
3486 host = components.lpszHostName;
3487 host_len = components.dwHostNameLength;
3488 port = components.nPort;
3489 TRACE("host name: %s port: %d\n",debugstr_wn(host, host_len), port);
3492 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3494 struct sockaddr_storage saddr;
3495 int sa_len = sizeof(saddr);
3496 WCHAR *host_z;
3497 int fd;
3498 BOOL b;
3500 host_z = heap_strndupW(host, host_len);
3501 if (!host_z)
3502 return FALSE;
3504 b = GetAddress(host_z, port, (struct sockaddr *)&saddr, &sa_len, NULL);
3505 heap_free(host_z);
3506 if(!b)
3507 goto End;
3508 init_winsock();
3509 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3510 if (fd != -1)
3512 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3513 rc = TRUE;
3514 closesocket(fd);
3517 else
3520 * Build our ping command
3522 char *command;
3524 len = WideCharToMultiByte(CP_UNIXCP, 0, host, host_len, NULL, 0, NULL, NULL);
3525 command = heap_alloc(strlen(ping)+len+strlen(redirect)+1);
3526 strcpy(command, ping);
3527 WideCharToMultiByte(CP_UNIXCP, 0, host, host_len, command+sizeof(ping)-1, len, NULL, NULL);
3528 strcpy(command+sizeof(ping)-1+len, redirect);
3530 TRACE("Ping command is : %s\n",command);
3532 status = system(command);
3533 heap_free( command );
3535 TRACE("Ping returned a code of %i\n",status);
3537 /* Ping return code of 0 indicates success */
3538 if (status == 0)
3539 rc = TRUE;
3542 End:
3543 if (rc == FALSE)
3544 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3546 return rc;
3550 /***********************************************************************
3551 * InternetCheckConnectionA (WININET.@)
3553 * Pings a requested host to check internet connection
3555 * RETURNS
3556 * TRUE on success and FALSE on failure. If a failure then
3557 * ERROR_NOT_CONNECTED is placed into GetLastError
3560 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3562 WCHAR *url = NULL;
3563 BOOL rc;
3565 if(lpszUrl) {
3566 url = heap_strdupAtoW(lpszUrl);
3567 if(!url)
3568 return FALSE;
3571 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3573 heap_free(url);
3574 return rc;
3578 /**********************************************************
3579 * INTERNET_InternetOpenUrlW (internal)
3581 * Opens an URL
3583 * RETURNS
3584 * handle of connection or NULL on failure
3586 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3587 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3589 URL_COMPONENTSW urlComponents = { sizeof(urlComponents) };
3590 WCHAR *host, *user = NULL, *pass = NULL, *path;
3591 HINTERNET client = NULL, client1 = NULL;
3592 DWORD res;
3594 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3595 dwHeadersLength, dwFlags, dwContext);
3597 urlComponents.dwHostNameLength = 1;
3598 urlComponents.dwUserNameLength = 1;
3599 urlComponents.dwPasswordLength = 1;
3600 urlComponents.dwUrlPathLength = 1;
3601 urlComponents.dwExtraInfoLength = 1;
3602 if(!InternetCrackUrlW(lpszUrl, lstrlenW(lpszUrl), 0, &urlComponents))
3603 return NULL;
3605 if ((urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS) &&
3606 urlComponents.dwExtraInfoLength)
3608 assert(urlComponents.lpszUrlPath + urlComponents.dwUrlPathLength == urlComponents.lpszExtraInfo);
3609 urlComponents.dwUrlPathLength += urlComponents.dwExtraInfoLength;
3612 host = heap_strndupW(urlComponents.lpszHostName, urlComponents.dwHostNameLength);
3613 path = heap_strndupW(urlComponents.lpszUrlPath, urlComponents.dwUrlPathLength);
3614 if(urlComponents.dwUserNameLength)
3615 user = heap_strndupW(urlComponents.lpszUserName, urlComponents.dwUserNameLength);
3616 if(urlComponents.dwPasswordLength)
3617 pass = heap_strndupW(urlComponents.lpszPassword, urlComponents.dwPasswordLength);
3619 switch(urlComponents.nScheme) {
3620 case INTERNET_SCHEME_FTP:
3621 client = FTP_Connect(hIC, host, urlComponents.nPort,
3622 user, pass, dwFlags, dwContext, INET_OPENURL);
3623 if(client == NULL)
3624 break;
3625 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3626 if(client1 == NULL) {
3627 InternetCloseHandle(client);
3628 break;
3630 break;
3632 case INTERNET_SCHEME_HTTP:
3633 case INTERNET_SCHEME_HTTPS: {
3634 LPCWSTR accept[2] = { L"*/*", NULL };
3636 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3638 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3639 res = HTTP_Connect(hIC, host, urlComponents.nPort,
3640 user, pass, dwFlags, dwContext, INET_OPENURL, &client);
3641 if(res != ERROR_SUCCESS) {
3642 INTERNET_SetLastError(res);
3643 break;
3646 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3647 if(client1 == NULL) {
3648 InternetCloseHandle(client);
3649 break;
3651 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3652 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3653 GetLastError() != ERROR_IO_PENDING) {
3654 InternetCloseHandle(client1);
3655 client1 = NULL;
3656 break;
3659 case INTERNET_SCHEME_GOPHER:
3660 /* gopher doesn't seem to be implemented in wine, but it's supposed
3661 * to be supported by InternetOpenUrlA. */
3662 default:
3663 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3664 break;
3667 TRACE(" %p <--\n", client1);
3669 heap_free(host);
3670 heap_free(path);
3671 heap_free(user);
3672 heap_free(pass);
3673 return client1;
3676 /**********************************************************
3677 * InternetOpenUrlW (WININET.@)
3679 * Opens an URL
3681 * RETURNS
3682 * handle of connection or NULL on failure
3684 typedef struct {
3685 task_header_t hdr;
3686 WCHAR *url;
3687 WCHAR *headers;
3688 DWORD headers_len;
3689 DWORD flags;
3690 DWORD_PTR context;
3691 } open_url_task_t;
3693 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3695 open_url_task_t *task = (open_url_task_t*)hdr;
3697 TRACE("%p\n", task->hdr.hdr);
3699 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3700 task->headers_len, task->flags, task->context);
3701 heap_free(task->url);
3702 heap_free(task->headers);
3705 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3706 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3708 HINTERNET ret = NULL;
3709 appinfo_t *hIC = NULL;
3711 if (TRACE_ON(wininet)) {
3712 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3713 dwHeadersLength, dwFlags, dwContext);
3714 TRACE(" flags :");
3715 dump_INTERNET_FLAGS(dwFlags);
3718 if (!lpszUrl)
3720 SetLastError(ERROR_INVALID_PARAMETER);
3721 goto lend;
3724 hIC = (appinfo_t*)get_handle_object( hInternet );
3725 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3726 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3727 goto lend;
3730 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3731 open_url_task_t *task;
3733 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3734 task->url = heap_strdupW(lpszUrl);
3735 task->headers = heap_strdupW(lpszHeaders);
3736 task->headers_len = dwHeadersLength;
3737 task->flags = dwFlags;
3738 task->context = dwContext;
3740 INTERNET_AsyncCall(&task->hdr);
3741 SetLastError(ERROR_IO_PENDING);
3742 } else {
3743 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3746 lend:
3747 if( hIC )
3748 WININET_Release( &hIC->hdr );
3749 TRACE(" %p <--\n", ret);
3751 return ret;
3754 /**********************************************************
3755 * InternetOpenUrlA (WININET.@)
3757 * Opens an URL
3759 * RETURNS
3760 * handle of connection or NULL on failure
3762 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3763 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3765 HINTERNET rc = NULL;
3766 LPWSTR szUrl = NULL;
3767 WCHAR *headers = NULL;
3769 TRACE("\n");
3771 if(lpszUrl) {
3772 szUrl = heap_strdupAtoW(lpszUrl);
3773 if(!szUrl)
3774 return NULL;
3777 if(lpszHeaders) {
3778 headers = heap_strndupAtoW(lpszHeaders, dwHeadersLength, &dwHeadersLength);
3779 if(!headers) {
3780 heap_free(szUrl);
3781 return NULL;
3785 rc = InternetOpenUrlW(hInternet, szUrl, headers, dwHeadersLength, dwFlags, dwContext);
3787 heap_free(szUrl);
3788 heap_free(headers);
3789 return rc;
3793 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3795 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3797 if (lpwite)
3799 lpwite->dwError = 0;
3800 lpwite->response[0] = '\0';
3803 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3805 heap_free(lpwite);
3806 return NULL;
3808 return lpwite;
3812 /***********************************************************************
3813 * INTERNET_SetLastError (internal)
3815 * Set last thread specific error
3817 * RETURNS
3820 void INTERNET_SetLastError(DWORD dwError)
3822 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3824 if (!lpwite)
3825 lpwite = INTERNET_AllocThreadError();
3827 SetLastError(dwError);
3828 if(lpwite)
3829 lpwite->dwError = dwError;
3833 /***********************************************************************
3834 * INTERNET_GetLastError (internal)
3836 * Get last thread specific error
3838 * RETURNS
3841 DWORD INTERNET_GetLastError(void)
3843 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3844 if (!lpwite) return 0;
3845 /* TlsGetValue clears last error, so set it again here */
3846 SetLastError(lpwite->dwError);
3847 return lpwite->dwError;
3851 /***********************************************************************
3852 * INTERNET_WorkerThreadFunc (internal)
3854 * Worker thread execution function
3856 * RETURNS
3859 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3861 task_header_t *task = lpvParam;
3863 TRACE("\n");
3865 task->proc(task);
3866 WININET_Release(task->hdr);
3867 heap_free(task);
3869 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3871 heap_free(TlsGetValue(g_dwTlsErrIndex));
3872 TlsSetValue(g_dwTlsErrIndex, NULL);
3874 return TRUE;
3877 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3879 task_header_t *task;
3881 task = heap_alloc(size);
3882 if(!task)
3883 return NULL;
3885 task->hdr = WININET_AddRef(hdr);
3886 task->proc = proc;
3887 return task;
3890 /***********************************************************************
3891 * INTERNET_AsyncCall (internal)
3893 * Retrieves work request from queue
3895 * RETURNS
3898 DWORD INTERNET_AsyncCall(task_header_t *task)
3900 BOOL bSuccess;
3902 TRACE("\n");
3904 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3905 if (!bSuccess)
3907 heap_free(task);
3908 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3910 return ERROR_SUCCESS;
3914 /***********************************************************************
3915 * INTERNET_GetResponseBuffer (internal)
3917 * RETURNS
3920 LPSTR INTERNET_GetResponseBuffer(void)
3922 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3923 if (!lpwite)
3924 lpwite = INTERNET_AllocThreadError();
3925 TRACE("\n");
3926 return lpwite->response;
3929 /**********************************************************
3930 * InternetQueryDataAvailable (WININET.@)
3932 * Determines how much data is available to be read.
3934 * RETURNS
3935 * TRUE on success, FALSE if an error occurred. If
3936 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3937 * no data is presently available, FALSE is returned with
3938 * the last error ERROR_IO_PENDING; a callback with status
3939 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3940 * data is available.
3942 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3943 LPDWORD lpdwNumberOfBytesAvailable,
3944 DWORD dwFlags, DWORD_PTR dwContext)
3946 object_header_t *hdr;
3947 DWORD res;
3949 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3951 hdr = get_handle_object( hFile );
3952 if (!hdr) {
3953 SetLastError(ERROR_INVALID_HANDLE);
3954 return FALSE;
3957 if(hdr->vtbl->QueryDataAvailable) {
3958 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3959 }else {
3960 WARN("wrong handle\n");
3961 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3964 WININET_Release(hdr);
3966 if(res != ERROR_SUCCESS)
3967 SetLastError(res);
3968 return res == ERROR_SUCCESS;
3971 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
3973 req_file_t *req_file;
3975 req_file = heap_alloc_zero(sizeof(*req_file));
3976 if(!req_file)
3977 return ERROR_NOT_ENOUGH_MEMORY;
3979 req_file->ref = 1;
3981 req_file->file_name = heap_strdupW(file_name);
3982 if(!req_file->file_name) {
3983 heap_free(req_file);
3984 return ERROR_NOT_ENOUGH_MEMORY;
3987 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
3988 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3989 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
3990 req_file_release(req_file);
3991 return GetLastError();
3994 *ret = req_file;
3995 return ERROR_SUCCESS;
3998 void req_file_release(req_file_t *req_file)
4000 if(InterlockedDecrement(&req_file->ref))
4001 return;
4003 if(!req_file->is_committed)
4004 DeleteFileW(req_file->file_name);
4005 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
4006 CloseHandle(req_file->file_handle);
4007 heap_free(req_file->file_name);
4008 heap_free(req_file->url);
4009 heap_free(req_file);
4012 /***********************************************************************
4013 * InternetLockRequestFile (WININET.@)
4015 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
4017 req_file_t *req_file = NULL;
4018 object_header_t *hdr;
4019 DWORD res;
4021 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
4023 hdr = get_handle_object(hInternet);
4024 if (!hdr) {
4025 SetLastError(ERROR_INVALID_HANDLE);
4026 return FALSE;
4029 if(hdr->vtbl->LockRequestFile) {
4030 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
4031 }else {
4032 WARN("wrong handle\n");
4033 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4036 WININET_Release(hdr);
4038 *lphLockReqHandle = req_file;
4039 if(res != ERROR_SUCCESS)
4040 SetLastError(res);
4041 return res == ERROR_SUCCESS;
4044 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
4046 TRACE("(%p)\n", hLockHandle);
4048 req_file_release(hLockHandle);
4049 return TRUE;
4053 /***********************************************************************
4054 * InternetAutodial (WININET.@)
4056 * On windows this function is supposed to dial the default internet
4057 * connection. We don't want to have Wine dial out to the internet so
4058 * we return TRUE by default. It might be nice to check if we are connected.
4060 * RETURNS
4061 * TRUE on success
4062 * FALSE on failure
4065 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4067 FIXME("STUB\n");
4069 /* Tell that we are connected to the internet. */
4070 return TRUE;
4073 /***********************************************************************
4074 * InternetAutodialHangup (WININET.@)
4076 * Hangs up a connection made with InternetAutodial
4078 * PARAM
4079 * dwReserved
4080 * RETURNS
4081 * TRUE on success
4082 * FALSE on failure
4085 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4087 FIXME("STUB\n");
4089 /* we didn't dial, we don't disconnect */
4090 return TRUE;
4093 /***********************************************************************
4094 * InternetCombineUrlA (WININET.@)
4096 * Combine a base URL with a relative URL
4098 * RETURNS
4099 * TRUE on success
4100 * FALSE on failure
4104 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4105 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4106 DWORD dwFlags)
4108 HRESULT hr=S_OK;
4110 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4112 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4113 dwFlags ^= ICU_NO_ENCODE;
4114 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4116 return (hr==S_OK);
4119 /***********************************************************************
4120 * InternetCombineUrlW (WININET.@)
4122 * Combine a base URL with a relative URL
4124 * RETURNS
4125 * TRUE on success
4126 * FALSE on failure
4130 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4131 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4132 DWORD dwFlags)
4134 HRESULT hr=S_OK;
4136 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4138 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4139 dwFlags ^= ICU_NO_ENCODE;
4140 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4142 return (hr==S_OK);
4145 /* max port num is 65535 => 5 digits */
4146 #define MAX_WORD_DIGITS 5
4148 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4149 (url)->dw##component##Length : lstrlenW((url)->lpsz##component))
4150 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4151 (url)->dw##component##Length : strlen((url)->lpsz##component))
4153 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4155 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4156 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4157 return TRUE;
4158 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4159 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4160 return TRUE;
4161 if ((nScheme == INTERNET_SCHEME_FTP) &&
4162 (nPort == INTERNET_DEFAULT_FTP_PORT))
4163 return TRUE;
4164 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4165 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4166 return TRUE;
4168 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4169 return TRUE;
4171 return FALSE;
4174 /* opaque urls do not fit into the standard url hierarchy and don't have
4175 * two following slashes */
4176 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4178 return (nScheme != INTERNET_SCHEME_FTP) &&
4179 (nScheme != INTERNET_SCHEME_GOPHER) &&
4180 (nScheme != INTERNET_SCHEME_HTTP) &&
4181 (nScheme != INTERNET_SCHEME_HTTPS) &&
4182 (nScheme != INTERNET_SCHEME_FILE);
4185 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4187 int index;
4188 if (scheme < INTERNET_SCHEME_FIRST)
4189 return NULL;
4190 index = scheme - INTERNET_SCHEME_FIRST;
4191 if (index >= ARRAY_SIZE(url_schemes))
4192 return NULL;
4193 return url_schemes[index];
4196 /* we can calculate using ansi strings because we're just
4197 * calculating string length, not size
4199 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4200 LPDWORD lpdwUrlLength)
4202 INTERNET_SCHEME nScheme;
4204 *lpdwUrlLength = 0;
4206 if (lpUrlComponents->lpszScheme)
4208 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4209 *lpdwUrlLength += dwLen;
4210 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4212 else
4214 LPCWSTR scheme;
4216 nScheme = lpUrlComponents->nScheme;
4218 if (nScheme == INTERNET_SCHEME_DEFAULT)
4219 nScheme = INTERNET_SCHEME_HTTP;
4220 scheme = INTERNET_GetSchemeString(nScheme);
4221 *lpdwUrlLength += lstrlenW(scheme);
4224 (*lpdwUrlLength)++; /* ':' */
4225 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4226 *lpdwUrlLength += strlen("//");
4228 if (lpUrlComponents->lpszUserName)
4230 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4231 *lpdwUrlLength += strlen("@");
4233 else
4235 if (lpUrlComponents->lpszPassword)
4237 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4238 return FALSE;
4242 if (lpUrlComponents->lpszPassword)
4244 *lpdwUrlLength += strlen(":");
4245 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4248 if (lpUrlComponents->lpszHostName)
4250 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4252 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4254 WCHAR port[MAX_WORD_DIGITS + 1];
4256 _ltow(lpUrlComponents->nPort, port, 10);
4257 *lpdwUrlLength += lstrlenW(port);
4258 *lpdwUrlLength += strlen(":");
4261 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4262 (*lpdwUrlLength)++; /* '/' */
4265 if (lpUrlComponents->lpszUrlPath)
4266 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4268 if (lpUrlComponents->lpszExtraInfo)
4269 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4271 return TRUE;
4274 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4276 INT len;
4278 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4280 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4281 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4282 urlCompW->nScheme = lpUrlComponents->nScheme;
4283 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4284 urlCompW->nPort = lpUrlComponents->nPort;
4285 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4286 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4287 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4288 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4290 if (lpUrlComponents->lpszScheme)
4292 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4293 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4294 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4295 -1, urlCompW->lpszScheme, len);
4298 if (lpUrlComponents->lpszHostName)
4300 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4301 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4302 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4303 -1, urlCompW->lpszHostName, len);
4306 if (lpUrlComponents->lpszUserName)
4308 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4309 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4310 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4311 -1, urlCompW->lpszUserName, len);
4314 if (lpUrlComponents->lpszPassword)
4316 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4317 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4318 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4319 -1, urlCompW->lpszPassword, len);
4322 if (lpUrlComponents->lpszUrlPath)
4324 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4325 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4326 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4327 -1, urlCompW->lpszUrlPath, len);
4330 if (lpUrlComponents->lpszExtraInfo)
4332 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4333 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4334 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4335 -1, urlCompW->lpszExtraInfo, len);
4339 /***********************************************************************
4340 * InternetCreateUrlA (WININET.@)
4342 * See InternetCreateUrlW.
4344 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4345 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4347 BOOL ret;
4348 LPWSTR urlW = NULL;
4349 URL_COMPONENTSW urlCompW;
4351 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4353 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4355 SetLastError(ERROR_INVALID_PARAMETER);
4356 return FALSE;
4359 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4361 if (lpszUrl)
4362 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4364 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4366 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4367 *lpdwUrlLength /= sizeof(WCHAR);
4369 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4370 * minus one, so add one to leave room for NULL terminator
4372 if (ret)
4373 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4375 heap_free(urlCompW.lpszScheme);
4376 heap_free(urlCompW.lpszHostName);
4377 heap_free(urlCompW.lpszUserName);
4378 heap_free(urlCompW.lpszPassword);
4379 heap_free(urlCompW.lpszUrlPath);
4380 heap_free(urlCompW.lpszExtraInfo);
4381 heap_free(urlW);
4382 return ret;
4385 /***********************************************************************
4386 * InternetCreateUrlW (WININET.@)
4388 * Creates a URL from its component parts.
4390 * PARAMS
4391 * lpUrlComponents [I] URL Components.
4392 * dwFlags [I] Flags. See notes.
4393 * lpszUrl [I] Buffer in which to store the created URL.
4394 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4395 * lpszUrl in characters. On output, the number of bytes
4396 * required to store the URL including terminator.
4398 * NOTES
4400 * The dwFlags parameter can be zero or more of the following:
4401 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4403 * RETURNS
4404 * TRUE on success
4405 * FALSE on failure
4408 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4409 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4411 DWORD dwLen;
4412 INTERNET_SCHEME nScheme;
4414 static const WCHAR slashSlashW[] = {'/','/'};
4416 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4418 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4420 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4421 return FALSE;
4424 if (!calc_url_length(lpUrlComponents, &dwLen))
4425 return FALSE;
4427 if (!lpszUrl || *lpdwUrlLength < dwLen)
4429 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4430 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4431 return FALSE;
4434 *lpdwUrlLength = dwLen;
4435 lpszUrl[0] = 0x00;
4437 dwLen = 0;
4439 if (lpUrlComponents->lpszScheme)
4441 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4442 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4443 lpszUrl += dwLen;
4445 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4447 else
4449 LPCWSTR scheme;
4450 nScheme = lpUrlComponents->nScheme;
4452 if (nScheme == INTERNET_SCHEME_DEFAULT)
4453 nScheme = INTERNET_SCHEME_HTTP;
4455 scheme = INTERNET_GetSchemeString(nScheme);
4456 dwLen = lstrlenW(scheme);
4457 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4458 lpszUrl += dwLen;
4461 /* all schemes are followed by at least a colon */
4462 *lpszUrl = ':';
4463 lpszUrl++;
4465 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4467 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4468 lpszUrl += ARRAY_SIZE(slashSlashW);
4471 if (lpUrlComponents->lpszUserName)
4473 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4474 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4475 lpszUrl += dwLen;
4477 if (lpUrlComponents->lpszPassword)
4479 *lpszUrl = ':';
4480 lpszUrl++;
4482 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4483 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4484 lpszUrl += dwLen;
4487 *lpszUrl = '@';
4488 lpszUrl++;
4491 if (lpUrlComponents->lpszHostName)
4493 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4494 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4495 lpszUrl += dwLen;
4497 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4499 *lpszUrl++ = ':';
4500 _ltow(lpUrlComponents->nPort, lpszUrl, 10);
4501 lpszUrl += lstrlenW(lpszUrl);
4504 /* add slash between hostname and path if necessary */
4505 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4507 *lpszUrl = '/';
4508 lpszUrl++;
4512 if (lpUrlComponents->lpszUrlPath)
4514 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4515 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4516 lpszUrl += dwLen;
4519 if (lpUrlComponents->lpszExtraInfo)
4521 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4522 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4523 lpszUrl += dwLen;
4526 *lpszUrl = '\0';
4528 return TRUE;
4531 /***********************************************************************
4532 * InternetConfirmZoneCrossingA (WININET.@)
4535 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4537 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4538 return ERROR_SUCCESS;
4541 /***********************************************************************
4542 * InternetConfirmZoneCrossingW (WININET.@)
4545 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4547 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4548 return ERROR_SUCCESS;
4551 static DWORD zone_preference = 3;
4553 /***********************************************************************
4554 * PrivacySetZonePreferenceW (WININET.@)
4556 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4558 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4560 zone_preference = template;
4561 return 0;
4564 /***********************************************************************
4565 * PrivacyGetZonePreferenceW (WININET.@)
4567 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4568 LPWSTR preference, LPDWORD length )
4570 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4572 if (template) *template = zone_preference;
4573 return 0;
4576 /***********************************************************************
4577 * InternetGetSecurityInfoByURLA (WININET.@)
4579 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4581 WCHAR *url;
4582 BOOL res;
4584 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4586 url = heap_strdupAtoW(lpszURL);
4587 if(!url)
4588 return FALSE;
4590 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4591 heap_free(url);
4592 return res;
4595 /***********************************************************************
4596 * InternetGetSecurityInfoByURLW (WININET.@)
4598 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4600 URL_COMPONENTSW url = {sizeof(url)};
4601 server_t *server;
4602 BOOL res;
4604 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4606 if (!ppCertChain && !pdwSecureFlags) {
4607 SetLastError(ERROR_INVALID_PARAMETER);
4608 return FALSE;
4611 url.dwHostNameLength = 1;
4612 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4613 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4614 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4615 return FALSE;
4618 server = get_server(substr(url.lpszHostName, url.dwHostNameLength), url.nPort, TRUE, FALSE);
4619 if(!server) {
4620 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4621 return FALSE;
4624 if(server->cert_chain) {
4625 if(pdwSecureFlags)
4626 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4628 if(ppCertChain && !(*ppCertChain = CertDuplicateCertificateChain(server->cert_chain)))
4629 res = FALSE;
4630 }else {
4631 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4632 res = FALSE;
4635 server_release(server);
4636 return res;
4639 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4640 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4642 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4643 lpdwConnection, dwReserved);
4644 return ERROR_SUCCESS;
4647 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4648 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4650 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4651 lpdwConnection, dwReserved);
4652 return ERROR_SUCCESS;
4655 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4657 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4658 return TRUE;
4661 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4663 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4664 return TRUE;
4667 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4669 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4670 return ERROR_SUCCESS;
4673 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4674 PBYTE pbHexHash )
4676 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4677 debugstr_w(pwszTarget), pbHexHash);
4678 return FALSE;
4681 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4683 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4684 return FALSE;
4687 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4689 FIXME("(%p, %08lx) stub\n", a, b);
4690 return FALSE;
4693 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4695 FIXME("%p: stub\n", parent);
4696 return 0;