wininet: Avoid empty initializer braces.
[wine/multimedia.git] / dlls / wininet / internet.c
blob7eddb2c1f90d8900c6966bef66a15ed606fee3c8
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
30 #include "ws2tcpip.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>
39 #ifdef HAVE_CORESERVICES_CORESERVICES_H
40 #define GetCurrentThread MacGetCurrentThread
41 #define LoadResource MacLoadResource
42 #include <CoreServices/CoreServices.h>
43 #undef GetCurrentThread
44 #undef LoadResource
45 #undef DPRINTF
46 #endif
48 #include "windef.h"
49 #include "winbase.h"
50 #include "winreg.h"
51 #include "winuser.h"
52 #include "wininet.h"
53 #include "winnls.h"
54 #include "wine/debug.h"
55 #include "winerror.h"
56 #define NO_SHLWAPI_STREAM
57 #include "shlwapi.h"
59 #include "wine/exception.h"
61 #include "internet.h"
62 #include "resource.h"
64 #include "wine/unicode.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
68 typedef struct
70 DWORD dwError;
71 CHAR response[MAX_REPLY_LEN];
72 } WITHREADERROR, *LPWITHREADERROR;
74 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
75 HMODULE WININET_hModule;
77 static CRITICAL_SECTION WININET_cs;
78 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
80 0, 0, &WININET_cs,
81 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
82 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
84 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
86 static object_header_t **handle_table;
87 static UINT_PTR next_handle;
88 static UINT_PTR handle_table_size;
90 typedef struct
92 DWORD proxyEnabled;
93 LPWSTR proxy;
94 LPWSTR proxyBypass;
95 LPWSTR proxyUsername;
96 LPWSTR proxyPassword;
97 } proxyinfo_t;
99 static ULONG max_conns = 2, max_1_0_conns = 4;
100 static ULONG connect_timeout = 60000;
102 static const WCHAR szInternetSettings[] =
103 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
104 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
105 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
106 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
107 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
108 static const WCHAR szProxyOverride[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
110 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
112 UINT_PTR handle = 0, num;
113 object_header_t *ret;
114 object_header_t **p;
115 BOOL res = TRUE;
117 ret = heap_alloc_zero(size);
118 if(!ret)
119 return NULL;
121 list_init(&ret->children);
123 EnterCriticalSection( &WININET_cs );
125 if(!handle_table_size) {
126 num = 16;
127 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
128 if(p) {
129 handle_table = p;
130 handle_table_size = num;
131 next_handle = 1;
132 }else {
133 res = FALSE;
135 }else if(next_handle == handle_table_size) {
136 num = handle_table_size * 2;
137 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
138 if(p) {
139 handle_table = p;
140 handle_table_size = num;
141 }else {
142 res = FALSE;
146 if(res) {
147 handle = next_handle;
148 if(handle_table[handle])
149 ERR("handle isn't free but should be\n");
150 handle_table[handle] = ret;
151 ret->valid_handle = TRUE;
153 while(handle_table[next_handle] && next_handle < handle_table_size)
154 next_handle++;
157 LeaveCriticalSection( &WININET_cs );
159 if(!res) {
160 heap_free(ret);
161 return NULL;
164 ret->vtbl = vtbl;
165 ret->refs = 1;
166 ret->hInternet = (HINTERNET)handle;
168 if(parent) {
169 ret->lpfnStatusCB = parent->lpfnStatusCB;
170 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
173 return ret;
176 object_header_t *WININET_AddRef( object_header_t *info )
178 ULONG refs = InterlockedIncrement(&info->refs);
179 TRACE("%p -> refcount = %d\n", info, refs );
180 return info;
183 object_header_t *get_handle_object( HINTERNET hinternet )
185 object_header_t *info = NULL;
186 UINT_PTR handle = (UINT_PTR) hinternet;
188 EnterCriticalSection( &WININET_cs );
190 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
191 info = WININET_AddRef(handle_table[handle]);
193 LeaveCriticalSection( &WININET_cs );
195 TRACE("handle %ld -> %p\n", handle, info);
197 return info;
200 static void invalidate_handle(object_header_t *info)
202 object_header_t *child, *next;
204 if(!info->valid_handle)
205 return;
206 info->valid_handle = FALSE;
208 /* Free all children as native does */
209 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
211 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
212 invalidate_handle( child );
215 WININET_Release(info);
218 BOOL WININET_Release( object_header_t *info )
220 ULONG refs = InterlockedDecrement(&info->refs);
221 TRACE( "object %p refcount = %d\n", info, refs );
222 if( !refs )
224 invalidate_handle(info);
225 if ( info->vtbl->CloseConnection )
227 TRACE( "closing connection %p\n", info);
228 info->vtbl->CloseConnection( info );
230 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
231 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
232 || !(info->dwInternalFlags & INET_OPENURL))
234 INTERNET_SendCallback(info, info->dwContext,
235 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
236 sizeof(HINTERNET));
238 TRACE( "destroying object %p\n", info);
239 if ( info->htype != WH_HINIT )
240 list_remove( &info->entry );
241 info->vtbl->Destroy( info );
243 if(info->hInternet) {
244 UINT_PTR handle = (UINT_PTR)info->hInternet;
246 EnterCriticalSection( &WININET_cs );
248 handle_table[handle] = NULL;
249 if(next_handle > handle)
250 next_handle = handle;
252 LeaveCriticalSection( &WININET_cs );
255 heap_free(info);
257 return TRUE;
260 /***********************************************************************
261 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
263 * PARAMS
264 * hinstDLL [I] handle to the DLL's instance
265 * fdwReason [I]
266 * lpvReserved [I] reserved, must be NULL
268 * RETURNS
269 * Success: TRUE
270 * Failure: FALSE
273 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
275 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
277 switch (fdwReason) {
278 case DLL_PROCESS_ATTACH:
280 g_dwTlsErrIndex = TlsAlloc();
282 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
283 return FALSE;
285 if(!init_urlcache())
287 TlsFree(g_dwTlsErrIndex);
288 return FALSE;
291 WININET_hModule = hinstDLL;
292 break;
294 case DLL_THREAD_ATTACH:
295 break;
297 case DLL_THREAD_DETACH:
298 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
300 heap_free(TlsGetValue(g_dwTlsErrIndex));
302 break;
304 case DLL_PROCESS_DETACH:
305 if (lpvReserved) break;
306 collect_connections(COLLECT_CLEANUP);
307 NETCON_unload();
308 free_urlcache();
309 free_cookie();
311 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
313 heap_free(TlsGetValue(g_dwTlsErrIndex));
314 TlsFree(g_dwTlsErrIndex);
316 break;
318 return TRUE;
321 /***********************************************************************
322 * DllInstall (WININET.@)
324 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
326 FIXME("(%x %s): stub\n", bInstall, debugstr_w(cmdline));
327 return S_OK;
330 /***********************************************************************
331 * INTERNET_SaveProxySettings
333 * Stores the proxy settings given by lpwai into the registry
335 * RETURNS
336 * ERROR_SUCCESS if no error, or error code on fail
338 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
340 HKEY key;
341 LONG ret;
343 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
344 return ret;
346 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
348 RegCloseKey( key );
349 return ret;
352 if (lpwpi->proxy)
354 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
356 RegCloseKey( key );
357 return ret;
360 else
362 if ((ret = RegDeleteValueW( key, szProxyServer )))
364 RegCloseKey( key );
365 return ret;
369 RegCloseKey(key);
370 return ERROR_SUCCESS;
373 /***********************************************************************
374 * INTERNET_FindProxyForProtocol
376 * Searches the proxy string for a proxy of the given protocol.
377 * Returns the found proxy, or the default proxy if none of the given
378 * protocol is found.
380 * PARAMETERS
381 * szProxy [In] proxy string to search
382 * proto [In] protocol to search for, e.g. "http"
383 * foundProxy [Out] found proxy
384 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
386 * RETURNS
387 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
388 * *foundProxyLen is set to the required size in WCHARs, including the
389 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
391 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
393 LPCWSTR ptr;
394 BOOL ret = FALSE;
396 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
398 /* First, look for the specified protocol (proto=scheme://host:port) */
399 for (ptr = szProxy; !ret && ptr && *ptr; )
401 LPCWSTR end, equal;
403 if (!(end = strchrW(ptr, ' ')))
404 end = ptr + strlenW(ptr);
405 if ((equal = strchrW(ptr, '=')) && equal < end &&
406 equal - ptr == strlenW(proto) &&
407 !strncmpiW(proto, ptr, strlenW(proto)))
409 if (end - equal > *foundProxyLen)
411 WARN("buffer too short for %s\n",
412 debugstr_wn(equal + 1, end - equal - 1));
413 *foundProxyLen = end - equal;
414 SetLastError(ERROR_INSUFFICIENT_BUFFER);
416 else
418 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
419 foundProxy[end - equal] = 0;
420 ret = TRUE;
423 if (*end == ' ')
424 ptr = end + 1;
425 else
426 ptr = end;
428 if (!ret)
430 /* It wasn't found: look for no protocol */
431 for (ptr = szProxy; !ret && ptr && *ptr; )
433 LPCWSTR end;
435 if (!(end = strchrW(ptr, ' ')))
436 end = ptr + strlenW(ptr);
437 if (!strchrW(ptr, '='))
439 if (end - ptr + 1 > *foundProxyLen)
441 WARN("buffer too short for %s\n",
442 debugstr_wn(ptr, end - ptr));
443 *foundProxyLen = end - ptr + 1;
444 SetLastError(ERROR_INSUFFICIENT_BUFFER);
446 else
448 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
449 foundProxy[end - ptr] = 0;
450 ret = TRUE;
453 if (*end == ' ')
454 ptr = end + 1;
455 else
456 ptr = end;
459 if (ret)
460 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
461 debugstr_w(foundProxy));
462 return ret;
465 /***********************************************************************
466 * InternetInitializeAutoProxyDll (WININET.@)
468 * Setup the internal proxy
470 * PARAMETERS
471 * dwReserved
473 * RETURNS
474 * FALSE on failure
477 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
479 FIXME("STUB\n");
480 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
481 return FALSE;
484 /***********************************************************************
485 * DetectAutoProxyUrl (WININET.@)
487 * Auto detect the proxy url
489 * RETURNS
490 * FALSE on failure
493 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
494 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
496 FIXME("STUB\n");
497 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
498 return FALSE;
501 static void FreeProxyInfo( proxyinfo_t *lpwpi )
503 heap_free(lpwpi->proxy);
504 heap_free(lpwpi->proxyBypass);
505 heap_free(lpwpi->proxyUsername);
506 heap_free(lpwpi->proxyPassword);
509 static proxyinfo_t *global_proxy;
511 static void free_global_proxy( void )
513 EnterCriticalSection( &WININET_cs );
514 if (global_proxy)
516 FreeProxyInfo( global_proxy );
517 heap_free( global_proxy );
519 LeaveCriticalSection( &WININET_cs );
522 static BOOL parse_proxy_url( proxyinfo_t *info, const WCHAR *url )
524 static const WCHAR fmt[] = {'%','s',':','%','u',0};
525 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
526 WCHAR username[INTERNET_MAX_USER_NAME_LENGTH];
527 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
528 URL_COMPONENTSW uc;
530 hostname[0] = username[0] = password[0] = 0;
531 memset( &uc, 0, sizeof(uc) );
532 uc.dwStructSize = sizeof(uc);
533 uc.lpszHostName = hostname;
534 uc.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
535 uc.lpszUserName = username;
536 uc.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
537 uc.lpszPassword = password;
538 uc.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
540 if (!InternetCrackUrlW( url, 0, 0, &uc )) return FALSE;
541 if (!hostname[0])
543 if (!(info->proxy = heap_strdupW( url ))) return FALSE;
544 info->proxyUsername = NULL;
545 info->proxyPassword = NULL;
546 return TRUE;
548 if (!(info->proxy = heap_alloc( (strlenW(hostname) + 12) * sizeof(WCHAR) ))) return FALSE;
549 sprintfW( info->proxy, fmt, hostname, uc.nPort );
551 if (!username[0]) info->proxyUsername = NULL;
552 else if (!(info->proxyUsername = heap_strdupW( username )))
554 heap_free( info->proxy );
555 return FALSE;
557 if (!password[0]) info->proxyPassword = NULL;
558 else if (!(info->proxyPassword = heap_strdupW( password )))
560 heap_free( info->proxyUsername );
561 heap_free( info->proxy );
562 return FALSE;
564 return TRUE;
567 /***********************************************************************
568 * INTERNET_LoadProxySettings
570 * Loads proxy information from process-wide global settings, the registry,
571 * or the environment into lpwpi.
573 * The caller should call FreeProxyInfo when done with lpwpi.
575 * FIXME:
576 * The proxy may be specified in the form 'http=proxy.my.org'
577 * Presumably that means there can be ftp=ftpproxy.my.org too.
579 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
581 HKEY key;
582 DWORD type, len;
583 LPCSTR envproxy;
584 LONG ret;
586 memset( lpwpi, 0, sizeof(*lpwpi) );
588 EnterCriticalSection( &WININET_cs );
589 if (global_proxy)
591 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
592 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
593 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
595 LeaveCriticalSection( &WININET_cs );
597 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
599 FreeProxyInfo( lpwpi );
600 return ret;
603 len = sizeof(DWORD);
604 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
606 lpwpi->proxyEnabled = 0;
607 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
609 FreeProxyInfo( lpwpi );
610 RegCloseKey( key );
611 return ret;
615 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->proxyEnabled)
617 /* figure out how much memory the proxy setting takes */
618 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
620 LPWSTR szProxy, p;
621 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
623 if (!(szProxy = heap_alloc(len)))
625 RegCloseKey( key );
626 FreeProxyInfo( lpwpi );
627 return ERROR_OUTOFMEMORY;
629 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
631 /* find the http proxy, and strip away everything else */
632 p = strstrW( szProxy, szHttp );
633 if (p)
635 p += lstrlenW( szHttp );
636 lstrcpyW( szProxy, p );
638 p = strchrW( szProxy, ';' );
639 if (p) *p = 0;
641 FreeProxyInfo( lpwpi );
642 lpwpi->proxy = szProxy;
643 lpwpi->proxyBypass = NULL;
645 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi->proxy));
647 else
649 TRACE("No proxy server settings in registry.\n");
650 FreeProxyInfo( lpwpi );
651 lpwpi->proxy = NULL;
652 lpwpi->proxyBypass = NULL;
655 else if (envproxy)
657 WCHAR *envproxyW;
659 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
660 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
662 RegCloseKey( key );
663 return ERROR_OUTOFMEMORY;
665 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
667 FreeProxyInfo( lpwpi );
668 if (parse_proxy_url( lpwpi, envproxyW ))
670 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
671 lpwpi->proxyEnabled = 1;
672 lpwpi->proxyBypass = NULL;
674 else
676 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW));
677 lpwpi->proxyEnabled = 0;
678 lpwpi->proxy = NULL;
679 lpwpi->proxyBypass = NULL;
681 heap_free( envproxyW );
684 if (lpwpi->proxyEnabled)
686 TRACE("Proxy is enabled.\n");
688 if (!(envproxy = getenv( "no_proxy" )))
690 /* figure out how much memory the proxy setting takes */
691 if (!RegQueryValueExW( key, szProxyOverride, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
693 LPWSTR szProxy;
695 if (!(szProxy = heap_alloc(len)))
697 RegCloseKey( key );
698 return ERROR_OUTOFMEMORY;
700 RegQueryValueExW( key, szProxyOverride, NULL, &type, (BYTE*)szProxy, &len );
702 heap_free( lpwpi->proxyBypass );
703 lpwpi->proxyBypass = szProxy;
705 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi->proxyBypass));
707 else
709 heap_free( lpwpi->proxyBypass );
710 lpwpi->proxyBypass = NULL;
712 TRACE("No proxy bypass server settings in registry.\n");
715 else
717 WCHAR *envproxyW;
719 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
720 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
722 RegCloseKey( key );
723 return ERROR_OUTOFMEMORY;
725 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
727 heap_free( lpwpi->proxyBypass );
728 lpwpi->proxyBypass = envproxyW;
730 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
733 else TRACE("Proxy is disabled.\n");
735 RegCloseKey( key );
736 return ERROR_SUCCESS;
739 /***********************************************************************
740 * INTERNET_ConfigureProxy
742 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
744 proxyinfo_t wpi;
746 if (INTERNET_LoadProxySettings( &wpi ))
747 return FALSE;
749 if (wpi.proxyEnabled)
751 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai->proxy), debugstr_w(lpwai->proxyBypass));
753 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
754 lpwai->proxy = wpi.proxy;
755 lpwai->proxyBypass = wpi.proxyBypass;
756 lpwai->proxyUsername = wpi.proxyUsername;
757 lpwai->proxyPassword = wpi.proxyPassword;
758 return TRUE;
761 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
762 FreeProxyInfo(&wpi);
763 return FALSE;
766 /***********************************************************************
767 * dump_INTERNET_FLAGS
769 * Helper function to TRACE the internet flags.
771 * RETURNS
772 * None
775 static void dump_INTERNET_FLAGS(DWORD dwFlags)
777 #define FE(x) { x, #x }
778 static const wininet_flag_info flag[] = {
779 FE(INTERNET_FLAG_RELOAD),
780 FE(INTERNET_FLAG_RAW_DATA),
781 FE(INTERNET_FLAG_EXISTING_CONNECT),
782 FE(INTERNET_FLAG_ASYNC),
783 FE(INTERNET_FLAG_PASSIVE),
784 FE(INTERNET_FLAG_NO_CACHE_WRITE),
785 FE(INTERNET_FLAG_MAKE_PERSISTENT),
786 FE(INTERNET_FLAG_FROM_CACHE),
787 FE(INTERNET_FLAG_SECURE),
788 FE(INTERNET_FLAG_KEEP_CONNECTION),
789 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
790 FE(INTERNET_FLAG_READ_PREFETCH),
791 FE(INTERNET_FLAG_NO_COOKIES),
792 FE(INTERNET_FLAG_NO_AUTH),
793 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
794 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
795 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
796 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
797 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
798 FE(INTERNET_FLAG_RESYNCHRONIZE),
799 FE(INTERNET_FLAG_HYPERLINK),
800 FE(INTERNET_FLAG_NO_UI),
801 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
802 FE(INTERNET_FLAG_CACHE_ASYNC),
803 FE(INTERNET_FLAG_FORMS_SUBMIT),
804 FE(INTERNET_FLAG_NEED_FILE),
805 FE(INTERNET_FLAG_TRANSFER_ASCII),
806 FE(INTERNET_FLAG_TRANSFER_BINARY)
808 #undef FE
809 unsigned int i;
811 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
812 if (flag[i].val & dwFlags) {
813 TRACE(" %s", flag[i].name);
814 dwFlags &= ~flag[i].val;
817 if (dwFlags)
818 TRACE(" Unknown flags (%08x)\n", dwFlags);
819 else
820 TRACE("\n");
823 /***********************************************************************
824 * INTERNET_CloseHandle (internal)
826 * Close internet handle
829 static VOID APPINFO_Destroy(object_header_t *hdr)
831 appinfo_t *lpwai = (appinfo_t*)hdr;
833 TRACE("%p\n",lpwai);
835 heap_free(lpwai->agent);
836 heap_free(lpwai->proxy);
837 heap_free(lpwai->proxyBypass);
838 heap_free(lpwai->proxyUsername);
839 heap_free(lpwai->proxyPassword);
842 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
844 appinfo_t *ai = (appinfo_t*)hdr;
846 switch(option) {
847 case INTERNET_OPTION_HANDLE_TYPE:
848 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
850 if (*size < sizeof(ULONG))
851 return ERROR_INSUFFICIENT_BUFFER;
853 *size = sizeof(DWORD);
854 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
855 return ERROR_SUCCESS;
857 case INTERNET_OPTION_USER_AGENT: {
858 DWORD bufsize;
860 TRACE("INTERNET_OPTION_USER_AGENT\n");
862 bufsize = *size;
864 if (unicode) {
865 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
867 *size = (len + 1) * sizeof(WCHAR);
868 if(!buffer || bufsize < *size)
869 return ERROR_INSUFFICIENT_BUFFER;
871 if (ai->agent)
872 strcpyW(buffer, ai->agent);
873 else
874 *(WCHAR *)buffer = 0;
875 /* If the buffer is copied, the returned length doesn't include
876 * the NULL terminator.
878 *size = len;
879 }else {
880 if (ai->agent)
881 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
882 else
883 *size = 1;
884 if(!buffer || bufsize < *size)
885 return ERROR_INSUFFICIENT_BUFFER;
887 if (ai->agent)
888 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
889 else
890 *(char *)buffer = 0;
891 /* If the buffer is copied, the returned length doesn't include
892 * the NULL terminator.
894 *size -= 1;
897 return ERROR_SUCCESS;
900 case INTERNET_OPTION_PROXY:
901 if(!size) return ERROR_INVALID_PARAMETER;
902 if (unicode) {
903 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
904 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
905 LPWSTR proxy, proxy_bypass;
907 if (ai->proxy)
908 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
909 if (ai->proxyBypass)
910 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
911 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
913 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
914 return ERROR_INSUFFICIENT_BUFFER;
916 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
917 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
919 pi->dwAccessType = ai->accessType;
920 pi->lpszProxy = NULL;
921 pi->lpszProxyBypass = NULL;
922 if (ai->proxy) {
923 lstrcpyW(proxy, ai->proxy);
924 pi->lpszProxy = proxy;
927 if (ai->proxyBypass) {
928 lstrcpyW(proxy_bypass, ai->proxyBypass);
929 pi->lpszProxyBypass = proxy_bypass;
932 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
933 return ERROR_SUCCESS;
934 }else {
935 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
936 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
937 LPSTR proxy, proxy_bypass;
939 if (ai->proxy)
940 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
941 if (ai->proxyBypass)
942 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
943 NULL, 0, NULL, NULL);
944 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
946 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
947 return ERROR_INSUFFICIENT_BUFFER;
949 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
950 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
952 pi->dwAccessType = ai->accessType;
953 pi->lpszProxy = NULL;
954 pi->lpszProxyBypass = NULL;
955 if (ai->proxy) {
956 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
957 pi->lpszProxy = proxy;
960 if (ai->proxyBypass) {
961 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
962 proxyBypassBytesRequired, NULL, NULL);
963 pi->lpszProxyBypass = proxy_bypass;
966 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
967 return ERROR_SUCCESS;
970 case INTERNET_OPTION_CONNECT_TIMEOUT:
971 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
973 if (*size < sizeof(ULONG))
974 return ERROR_INSUFFICIENT_BUFFER;
976 *(ULONG*)buffer = ai->connect_timeout;
977 *size = sizeof(ULONG);
979 return ERROR_SUCCESS;
982 return INET_QueryOption(hdr, option, buffer, size, unicode);
985 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
987 appinfo_t *ai = (appinfo_t*)hdr;
989 switch(option) {
990 case INTERNET_OPTION_CONNECT_TIMEOUT:
991 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
993 if(size != sizeof(connect_timeout))
994 return ERROR_INTERNET_BAD_OPTION_LENGTH;
995 if(!*(ULONG*)buf)
996 return ERROR_BAD_ARGUMENTS;
998 ai->connect_timeout = *(ULONG*)buf;
999 return ERROR_SUCCESS;
1000 case INTERNET_OPTION_USER_AGENT:
1001 heap_free(ai->agent);
1002 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
1003 return ERROR_SUCCESS;
1006 return INET_SetOption(hdr, option, buf, size);
1009 static const object_vtbl_t APPINFOVtbl = {
1010 APPINFO_Destroy,
1011 NULL,
1012 APPINFO_QueryOption,
1013 APPINFO_SetOption,
1014 NULL,
1015 NULL,
1016 NULL,
1017 NULL
1021 /***********************************************************************
1022 * InternetOpenW (WININET.@)
1024 * Per-application initialization of wininet
1026 * RETURNS
1027 * HINTERNET on success
1028 * NULL on failure
1031 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
1032 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
1034 appinfo_t *lpwai = NULL;
1036 if (TRACE_ON(wininet)) {
1037 #define FE(x) { x, #x }
1038 static const wininet_flag_info access_type[] = {
1039 FE(INTERNET_OPEN_TYPE_PRECONFIG),
1040 FE(INTERNET_OPEN_TYPE_DIRECT),
1041 FE(INTERNET_OPEN_TYPE_PROXY),
1042 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
1044 #undef FE
1045 DWORD i;
1046 const char *access_type_str = "Unknown";
1048 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
1049 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
1050 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
1051 if (access_type[i].val == dwAccessType) {
1052 access_type_str = access_type[i].name;
1053 break;
1056 TRACE(" access type : %s\n", access_type_str);
1057 TRACE(" flags :");
1058 dump_INTERNET_FLAGS(dwFlags);
1061 /* Clear any error information */
1062 INTERNET_SetLastError(0);
1064 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1065 SetLastError(ERROR_INVALID_PARAMETER);
1066 return NULL;
1069 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1070 if (!lpwai) {
1071 SetLastError(ERROR_OUTOFMEMORY);
1072 return NULL;
1075 lpwai->hdr.htype = WH_HINIT;
1076 lpwai->hdr.dwFlags = dwFlags;
1077 lpwai->accessType = dwAccessType;
1078 lpwai->proxyUsername = NULL;
1079 lpwai->proxyPassword = NULL;
1080 lpwai->connect_timeout = connect_timeout;
1082 lpwai->agent = heap_strdupW(lpszAgent);
1083 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1084 INTERNET_ConfigureProxy( lpwai );
1085 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1086 lpwai->proxy = heap_strdupW(lpszProxy);
1087 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1090 TRACE("returning %p\n", lpwai);
1092 return lpwai->hdr.hInternet;
1096 /***********************************************************************
1097 * InternetOpenA (WININET.@)
1099 * Per-application initialization of wininet
1101 * RETURNS
1102 * HINTERNET on success
1103 * NULL on failure
1106 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1107 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1109 WCHAR *szAgent, *szProxy, *szBypass;
1110 HINTERNET rc;
1112 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1113 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1115 szAgent = heap_strdupAtoW(lpszAgent);
1116 szProxy = heap_strdupAtoW(lpszProxy);
1117 szBypass = heap_strdupAtoW(lpszProxyBypass);
1119 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1121 heap_free(szAgent);
1122 heap_free(szProxy);
1123 heap_free(szBypass);
1124 return rc;
1127 /***********************************************************************
1128 * InternetGetLastResponseInfoA (WININET.@)
1130 * Return last wininet error description on the calling thread
1132 * RETURNS
1133 * TRUE on success of writing to buffer
1134 * FALSE on failure
1137 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1138 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1140 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1142 TRACE("\n");
1144 if (lpwite)
1146 *lpdwError = lpwite->dwError;
1147 if (lpwite->dwError)
1149 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1150 *lpdwBufferLength = strlen(lpszBuffer);
1152 else
1153 *lpdwBufferLength = 0;
1155 else
1157 *lpdwError = 0;
1158 *lpdwBufferLength = 0;
1161 return TRUE;
1164 /***********************************************************************
1165 * InternetGetLastResponseInfoW (WININET.@)
1167 * Return last wininet error description on the calling thread
1169 * RETURNS
1170 * TRUE on success of writing to buffer
1171 * FALSE on failure
1174 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1175 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1177 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1179 TRACE("\n");
1181 if (lpwite)
1183 *lpdwError = lpwite->dwError;
1184 if (lpwite->dwError)
1186 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1187 *lpdwBufferLength = lstrlenW(lpszBuffer);
1189 else
1190 *lpdwBufferLength = 0;
1192 else
1194 *lpdwError = 0;
1195 *lpdwBufferLength = 0;
1198 return TRUE;
1201 /***********************************************************************
1202 * InternetGetConnectedState (WININET.@)
1204 * Return connected state
1206 * RETURNS
1207 * TRUE if connected
1208 * if lpdwStatus is not null, return the status (off line,
1209 * modem, lan...) in it.
1210 * FALSE if not connected
1212 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1214 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1216 if (lpdwStatus) {
1217 WARN("always returning LAN connection.\n");
1218 *lpdwStatus = INTERNET_CONNECTION_LAN;
1220 return TRUE;
1224 /***********************************************************************
1225 * InternetGetConnectedStateExW (WININET.@)
1227 * Return connected state
1229 * PARAMS
1231 * lpdwStatus [O] Flags specifying the status of the internet connection.
1232 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1233 * dwNameLen [I] Size of the buffer, in characters.
1234 * dwReserved [I] Reserved. Must be set to 0.
1236 * RETURNS
1237 * TRUE if connected
1238 * if lpdwStatus is not null, return the status (off line,
1239 * modem, lan...) in it.
1240 * FALSE if not connected
1242 * NOTES
1243 * If the system has no available network connections, an empty string is
1244 * stored in lpszConnectionName. If there is a LAN connection, a localized
1245 * "LAN Connection" string is stored. Presumably, if only a dial-up
1246 * connection is available then the name of the dial-up connection is
1247 * returned. Why any application, other than the "Internet Settings" CPL,
1248 * would want to use this function instead of the simpler InternetGetConnectedStateW
1249 * function is beyond me.
1251 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1252 DWORD dwNameLen, DWORD dwReserved)
1254 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1256 /* Must be zero */
1257 if(dwReserved)
1258 return FALSE;
1260 if (lpdwStatus) {
1261 WARN("always returning LAN connection.\n");
1262 *lpdwStatus = INTERNET_CONNECTION_LAN;
1265 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1266 * the resource, avoid it as we must not change the buffer in this case */
1267 if(lpszConnectionName && dwNameLen) {
1268 *lpszConnectionName = '\0';
1269 LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1272 return TRUE;
1276 /***********************************************************************
1277 * InternetGetConnectedStateExA (WININET.@)
1279 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1280 DWORD dwNameLen, DWORD dwReserved)
1282 LPWSTR lpwszConnectionName = NULL;
1283 BOOL rc;
1285 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1287 if (lpszConnectionName && dwNameLen > 0)
1288 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1290 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1291 dwReserved);
1292 if (rc && lpwszConnectionName)
1293 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1294 dwNameLen, NULL, NULL);
1296 heap_free(lpwszConnectionName);
1297 return rc;
1301 /***********************************************************************
1302 * InternetConnectW (WININET.@)
1304 * Open a ftp, gopher or http session
1306 * RETURNS
1307 * HINTERNET a session handle on success
1308 * NULL on failure
1311 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1312 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1313 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1314 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1316 appinfo_t *hIC;
1317 HINTERNET rc = NULL;
1318 DWORD res = ERROR_SUCCESS;
1320 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1321 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1322 dwService, dwFlags, dwContext);
1324 if (!lpszServerName)
1326 SetLastError(ERROR_INVALID_PARAMETER);
1327 return NULL;
1330 hIC = (appinfo_t*)get_handle_object( hInternet );
1331 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1333 res = ERROR_INVALID_HANDLE;
1334 goto lend;
1337 switch (dwService)
1339 case INTERNET_SERVICE_FTP:
1340 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1341 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1342 if(!rc)
1343 res = INTERNET_GetLastError();
1344 break;
1346 case INTERNET_SERVICE_HTTP:
1347 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1348 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1349 break;
1351 case INTERNET_SERVICE_GOPHER:
1352 default:
1353 break;
1355 lend:
1356 if( hIC )
1357 WININET_Release( &hIC->hdr );
1359 TRACE("returning %p\n", rc);
1360 SetLastError(res);
1361 return rc;
1365 /***********************************************************************
1366 * InternetConnectA (WININET.@)
1368 * Open a ftp, gopher or http session
1370 * RETURNS
1371 * HINTERNET a session handle on success
1372 * NULL on failure
1375 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1376 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1377 LPCSTR lpszUserName, LPCSTR lpszPassword,
1378 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1380 HINTERNET rc = NULL;
1381 LPWSTR szServerName;
1382 LPWSTR szUserName;
1383 LPWSTR szPassword;
1385 szServerName = heap_strdupAtoW(lpszServerName);
1386 szUserName = heap_strdupAtoW(lpszUserName);
1387 szPassword = heap_strdupAtoW(lpszPassword);
1389 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1390 szUserName, szPassword, dwService, dwFlags, dwContext);
1392 heap_free(szServerName);
1393 heap_free(szUserName);
1394 heap_free(szPassword);
1395 return rc;
1399 /***********************************************************************
1400 * InternetFindNextFileA (WININET.@)
1402 * Continues a file search from a previous call to FindFirstFile
1404 * RETURNS
1405 * TRUE on success
1406 * FALSE on failure
1409 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1411 BOOL ret;
1412 WIN32_FIND_DATAW fd;
1414 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1415 if(lpvFindData)
1416 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1417 return ret;
1420 /***********************************************************************
1421 * InternetFindNextFileW (WININET.@)
1423 * Continues a file search from a previous call to FindFirstFile
1425 * RETURNS
1426 * TRUE on success
1427 * FALSE on failure
1430 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1432 object_header_t *hdr;
1433 DWORD res;
1435 TRACE("\n");
1437 hdr = get_handle_object(hFind);
1438 if(!hdr) {
1439 WARN("Invalid handle\n");
1440 SetLastError(ERROR_INVALID_HANDLE);
1441 return FALSE;
1444 if(hdr->vtbl->FindNextFileW) {
1445 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1446 }else {
1447 WARN("Handle doesn't support NextFile\n");
1448 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1451 WININET_Release(hdr);
1453 if(res != ERROR_SUCCESS)
1454 SetLastError(res);
1455 return res == ERROR_SUCCESS;
1458 /***********************************************************************
1459 * InternetCloseHandle (WININET.@)
1461 * Generic close handle function
1463 * RETURNS
1464 * TRUE on success
1465 * FALSE on failure
1468 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1470 object_header_t *obj;
1472 TRACE("%p\n", hInternet);
1474 obj = get_handle_object( hInternet );
1475 if (!obj) {
1476 SetLastError(ERROR_INVALID_HANDLE);
1477 return FALSE;
1480 invalidate_handle(obj);
1481 WININET_Release(obj);
1483 return TRUE;
1487 /***********************************************************************
1488 * ConvertUrlComponentValue (Internal)
1490 * Helper function for InternetCrackUrlA
1493 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1494 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1495 LPCSTR lpszStart, LPCWSTR lpwszStart)
1497 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1498 if (*dwComponentLen != 0)
1500 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1501 if (*lppszComponent == NULL)
1503 if (lpwszComponent)
1505 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1506 *lppszComponent = (LPSTR)lpszStart + offset;
1508 else
1509 *lppszComponent = NULL;
1511 *dwComponentLen = nASCIILength;
1513 else
1515 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1516 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1517 (*lppszComponent)[ncpylen]=0;
1518 *dwComponentLen = ncpylen;
1524 /***********************************************************************
1525 * InternetCrackUrlA (WININET.@)
1527 * See InternetCrackUrlW.
1529 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1530 LPURL_COMPONENTSA lpUrlComponents)
1532 DWORD nLength;
1533 URL_COMPONENTSW UCW;
1534 BOOL ret = FALSE;
1535 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1536 *scheme = NULL, *extra = NULL;
1538 TRACE("(%s %u %x %p)\n",
1539 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1540 dwUrlLength, dwFlags, lpUrlComponents);
1542 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1543 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1545 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1546 return FALSE;
1549 if(dwUrlLength<=0)
1550 dwUrlLength=-1;
1551 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1553 /* if dwUrlLength=-1 then nLength includes null but length to
1554 InternetCrackUrlW should not include it */
1555 if (dwUrlLength == -1) nLength--;
1557 lpwszUrl = heap_alloc((nLength + 1) * sizeof(WCHAR));
1558 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1559 lpwszUrl[nLength] = '\0';
1561 memset(&UCW,0,sizeof(UCW));
1562 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1563 if (lpUrlComponents->dwHostNameLength)
1565 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1566 if (lpUrlComponents->lpszHostName)
1568 hostname = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1569 UCW.lpszHostName = hostname;
1572 if (lpUrlComponents->dwUserNameLength)
1574 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1575 if (lpUrlComponents->lpszUserName)
1577 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1578 UCW.lpszUserName = username;
1581 if (lpUrlComponents->dwPasswordLength)
1583 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1584 if (lpUrlComponents->lpszPassword)
1586 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1587 UCW.lpszPassword = password;
1590 if (lpUrlComponents->dwUrlPathLength)
1592 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1593 if (lpUrlComponents->lpszUrlPath)
1595 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1596 UCW.lpszUrlPath = path;
1599 if (lpUrlComponents->dwSchemeLength)
1601 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1602 if (lpUrlComponents->lpszScheme)
1604 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1605 UCW.lpszScheme = scheme;
1608 if (lpUrlComponents->dwExtraInfoLength)
1610 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1611 if (lpUrlComponents->lpszExtraInfo)
1613 extra = heap_alloc(UCW.dwExtraInfoLength * sizeof(WCHAR));
1614 UCW.lpszExtraInfo = extra;
1617 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1619 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1620 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1621 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1622 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1623 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1624 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1625 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1626 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1627 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1628 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1629 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1630 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1632 lpUrlComponents->nScheme = UCW.nScheme;
1633 lpUrlComponents->nPort = UCW.nPort;
1635 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1636 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1637 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1638 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1639 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1641 heap_free(lpwszUrl);
1642 heap_free(hostname);
1643 heap_free(username);
1644 heap_free(password);
1645 heap_free(path);
1646 heap_free(scheme);
1647 heap_free(extra);
1648 return ret;
1651 static const WCHAR url_schemes[][7] =
1653 {'f','t','p',0},
1654 {'g','o','p','h','e','r',0},
1655 {'h','t','t','p',0},
1656 {'h','t','t','p','s',0},
1657 {'f','i','l','e',0},
1658 {'n','e','w','s',0},
1659 {'m','a','i','l','t','o',0},
1660 {'r','e','s',0},
1663 /***********************************************************************
1664 * GetInternetSchemeW (internal)
1666 * Get scheme of url
1668 * RETURNS
1669 * scheme on success
1670 * INTERNET_SCHEME_UNKNOWN on failure
1673 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1675 int i;
1677 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1679 if(lpszScheme==NULL)
1680 return INTERNET_SCHEME_UNKNOWN;
1682 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1683 if (!strncmpiW(lpszScheme, url_schemes[i], nMaxCmp))
1684 return INTERNET_SCHEME_FIRST + i;
1686 return INTERNET_SCHEME_UNKNOWN;
1689 /***********************************************************************
1690 * SetUrlComponentValueW (Internal)
1692 * Helper function for InternetCrackUrlW
1694 * PARAMS
1695 * lppszComponent [O] Holds the returned string
1696 * dwComponentLen [I] Holds the size of lppszComponent
1697 * [O] Holds the length of the string in lppszComponent without '\0'
1698 * lpszStart [I] Holds the string to copy from
1699 * len [I] Holds the length of lpszStart without '\0'
1701 * RETURNS
1702 * TRUE on success
1703 * FALSE on failure
1706 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1708 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1710 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1711 return FALSE;
1713 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1715 if (*lppszComponent == NULL)
1717 *lppszComponent = (LPWSTR)lpszStart;
1718 *dwComponentLen = len;
1720 else
1722 DWORD ncpylen = min((*dwComponentLen)-1, len);
1723 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1724 (*lppszComponent)[ncpylen] = '\0';
1725 *dwComponentLen = ncpylen;
1729 return TRUE;
1732 /***********************************************************************
1733 * InternetCrackUrlW (WININET.@)
1735 * Break up URL into its components
1737 * RETURNS
1738 * TRUE on success
1739 * FALSE on failure
1741 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1742 LPURL_COMPONENTSW lpUC)
1745 * RFC 1808
1746 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1749 LPCWSTR lpszParam = NULL;
1750 BOOL found_colon = FALSE;
1751 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1752 LPCWSTR lpszcp = NULL, lpszNetLoc;
1753 LPWSTR lpszUrl_decode = NULL;
1754 DWORD dwUrlLength = dwUrlLength_orig;
1756 TRACE("(%s %u %x %p)\n",
1757 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1758 dwUrlLength, dwFlags, lpUC);
1760 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1762 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1763 return FALSE;
1765 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1767 if (dwFlags & ICU_DECODE)
1769 WCHAR *url_tmp;
1770 DWORD len = dwUrlLength + 1;
1772 if (!(url_tmp = heap_alloc(len * sizeof(WCHAR))))
1774 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1775 return FALSE;
1777 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1778 url_tmp[dwUrlLength] = 0;
1779 if (!(lpszUrl_decode = heap_alloc(len * sizeof(WCHAR))))
1781 heap_free(url_tmp);
1782 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1783 return FALSE;
1785 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1787 dwUrlLength = len;
1788 lpszUrl = lpszUrl_decode;
1790 heap_free(url_tmp);
1792 lpszap = lpszUrl;
1794 /* Determine if the URI is absolute. */
1795 while (lpszap - lpszUrl < dwUrlLength)
1797 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1799 lpszap++;
1800 continue;
1802 if (*lpszap == ':')
1804 found_colon = TRUE;
1805 lpszcp = lpszap;
1807 else
1809 lpszcp = lpszUrl; /* Relative url */
1812 break;
1815 if(!found_colon){
1816 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1817 return FALSE;
1820 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1821 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1823 /* Parse <params> */
1824 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1825 if(!lpszParam)
1826 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1828 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1829 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1832 /* Get scheme first. */
1833 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1834 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1835 lpszUrl, lpszcp - lpszUrl);
1837 /* Eat ':' in protocol. */
1838 lpszcp++;
1840 /* double slash indicates the net_loc portion is present */
1841 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1843 lpszcp += 2;
1845 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1846 if (lpszParam)
1848 if (lpszNetLoc)
1849 lpszNetLoc = min(lpszNetLoc, lpszParam);
1850 else
1851 lpszNetLoc = lpszParam;
1853 else if (!lpszNetLoc)
1854 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1856 /* Parse net-loc */
1857 if (lpszNetLoc)
1859 LPCWSTR lpszHost;
1860 LPCWSTR lpszPort;
1862 /* [<user>[<:password>]@]<host>[:<port>] */
1863 /* First find the user and password if they exist */
1865 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1866 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1868 /* username and password not specified. */
1869 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1870 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1872 else /* Parse out username and password */
1874 LPCWSTR lpszUser = lpszcp;
1875 LPCWSTR lpszPasswd = lpszHost;
1877 while (lpszcp < lpszHost)
1879 if (*lpszcp == ':')
1880 lpszPasswd = lpszcp;
1882 lpszcp++;
1885 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1886 lpszUser, lpszPasswd - lpszUser);
1888 if (lpszPasswd != lpszHost)
1889 lpszPasswd++;
1890 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1891 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1892 lpszHost - lpszPasswd);
1894 lpszcp++; /* Advance to beginning of host */
1897 /* Parse <host><:port> */
1899 lpszHost = lpszcp;
1900 lpszPort = lpszNetLoc;
1902 /* special case for res:// URLs: there is no port here, so the host is the
1903 entire string up to the first '/' */
1904 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1906 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1907 lpszHost, lpszPort - lpszHost);
1908 lpszcp=lpszNetLoc;
1910 else
1912 while (lpszcp < lpszNetLoc)
1914 if (*lpszcp == ':')
1915 lpszPort = lpszcp;
1917 lpszcp++;
1920 /* If the scheme is "file" and the host is just one letter, it's not a host */
1921 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1923 lpszcp=lpszHost;
1924 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1925 NULL, 0);
1927 else
1929 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1930 lpszHost, lpszPort - lpszHost);
1931 if (lpszPort != lpszNetLoc)
1932 lpUC->nPort = atoiW(++lpszPort);
1933 else switch (lpUC->nScheme)
1935 case INTERNET_SCHEME_HTTP:
1936 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1937 break;
1938 case INTERNET_SCHEME_HTTPS:
1939 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1940 break;
1941 case INTERNET_SCHEME_FTP:
1942 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1943 break;
1944 case INTERNET_SCHEME_GOPHER:
1945 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1946 break;
1947 default:
1948 break;
1954 else
1956 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1957 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1958 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1961 /* Here lpszcp points to:
1963 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1964 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1966 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1968 DWORD len;
1970 /* Only truncate the parameter list if it's already been saved
1971 * in lpUC->lpszExtraInfo.
1973 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1974 len = lpszParam - lpszcp;
1975 else
1977 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1978 * newlines if necessary.
1980 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1981 if (lpsznewline != NULL)
1982 len = lpsznewline - lpszcp;
1983 else
1984 len = dwUrlLength-(lpszcp-lpszUrl);
1986 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1987 lpUC->nScheme == INTERNET_SCHEME_FILE)
1989 WCHAR tmppath[MAX_PATH];
1990 if (*lpszcp == '/')
1992 len = MAX_PATH;
1993 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
1995 else
1997 WCHAR *iter;
1998 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1999 tmppath[len] = '\0';
2001 iter = tmppath;
2002 while (*iter) {
2003 if (*iter == '/')
2004 *iter = '\\';
2005 ++iter;
2008 /* if ends in \. or \.. append a backslash */
2009 if (tmppath[len - 1] == '.' &&
2010 (tmppath[len - 2] == '\\' ||
2011 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
2013 if (len < MAX_PATH - 1)
2015 tmppath[len] = '\\';
2016 tmppath[len+1] = '\0';
2017 ++len;
2020 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
2021 tmppath, len);
2023 else
2024 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
2025 lpszcp, len);
2027 else
2029 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
2030 lpUC->lpszUrlPath[0] = 0;
2031 lpUC->dwUrlPathLength = 0;
2034 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
2035 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
2036 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
2037 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
2038 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
2040 heap_free( lpszUrl_decode );
2041 return TRUE;
2044 /***********************************************************************
2045 * InternetAttemptConnect (WININET.@)
2047 * Attempt to make a connection to the internet
2049 * RETURNS
2050 * ERROR_SUCCESS on success
2051 * Error value on failure
2054 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
2056 FIXME("Stub\n");
2057 return ERROR_SUCCESS;
2061 /***********************************************************************
2062 * convert_url_canonicalization_flags
2064 * Helper for InternetCanonicalizeUrl
2066 * PARAMS
2067 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2069 * RETURNS
2070 * Flags suitable for UrlCanonicalize
2072 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
2074 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
2076 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
2077 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
2078 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
2079 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
2080 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2081 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
2082 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
2084 return dwUrlFlags;
2087 /***********************************************************************
2088 * InternetCanonicalizeUrlA (WININET.@)
2090 * Escape unsafe characters and spaces
2092 * RETURNS
2093 * TRUE on success
2094 * FALSE on failure
2097 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
2098 LPDWORD lpdwBufferLength, DWORD dwFlags)
2100 HRESULT hr;
2102 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl), lpszBuffer,
2103 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2105 dwFlags = convert_url_canonicalization_flags(dwFlags);
2106 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2107 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2108 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2110 return hr == S_OK;
2113 /***********************************************************************
2114 * InternetCanonicalizeUrlW (WININET.@)
2116 * Escape unsafe characters and spaces
2118 * RETURNS
2119 * TRUE on success
2120 * FALSE on failure
2123 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
2124 LPDWORD lpdwBufferLength, DWORD dwFlags)
2126 HRESULT hr;
2128 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2129 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2131 dwFlags = convert_url_canonicalization_flags(dwFlags);
2132 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2133 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2134 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2136 return hr == S_OK;
2139 /* #################################################### */
2141 static INTERNET_STATUS_CALLBACK set_status_callback(
2142 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2144 INTERNET_STATUS_CALLBACK ret;
2146 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2147 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2149 ret = lpwh->lpfnStatusCB;
2150 lpwh->lpfnStatusCB = callback;
2152 return ret;
2155 /***********************************************************************
2156 * InternetSetStatusCallbackA (WININET.@)
2158 * Sets up a callback function which is called as progress is made
2159 * during an operation.
2161 * RETURNS
2162 * Previous callback or NULL on success
2163 * INTERNET_INVALID_STATUS_CALLBACK on failure
2166 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2167 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2169 INTERNET_STATUS_CALLBACK retVal;
2170 object_header_t *lpwh;
2172 TRACE("%p\n", hInternet);
2174 if (!(lpwh = get_handle_object(hInternet)))
2175 return INTERNET_INVALID_STATUS_CALLBACK;
2177 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2179 WININET_Release( lpwh );
2180 return retVal;
2183 /***********************************************************************
2184 * InternetSetStatusCallbackW (WININET.@)
2186 * Sets up a callback function which is called as progress is made
2187 * during an operation.
2189 * RETURNS
2190 * Previous callback or NULL on success
2191 * INTERNET_INVALID_STATUS_CALLBACK on failure
2194 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2195 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2197 INTERNET_STATUS_CALLBACK retVal;
2198 object_header_t *lpwh;
2200 TRACE("%p\n", hInternet);
2202 if (!(lpwh = get_handle_object(hInternet)))
2203 return INTERNET_INVALID_STATUS_CALLBACK;
2205 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2207 WININET_Release( lpwh );
2208 return retVal;
2211 /***********************************************************************
2212 * InternetSetFilePointer (WININET.@)
2214 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2215 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2217 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2218 return FALSE;
2221 /***********************************************************************
2222 * InternetWriteFile (WININET.@)
2224 * Write data to an open internet file
2226 * RETURNS
2227 * TRUE on success
2228 * FALSE on failure
2231 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2232 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2234 object_header_t *lpwh;
2235 BOOL res;
2237 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2239 lpwh = get_handle_object( hFile );
2240 if (!lpwh) {
2241 WARN("Invalid handle\n");
2242 SetLastError(ERROR_INVALID_HANDLE);
2243 return FALSE;
2246 if(lpwh->vtbl->WriteFile) {
2247 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2248 }else {
2249 WARN("No Writefile method.\n");
2250 res = ERROR_INVALID_HANDLE;
2253 WININET_Release( lpwh );
2255 if(res != ERROR_SUCCESS)
2256 SetLastError(res);
2257 return res == ERROR_SUCCESS;
2261 /***********************************************************************
2262 * InternetReadFile (WININET.@)
2264 * Read data from an open internet file
2266 * RETURNS
2267 * TRUE on success
2268 * FALSE on failure
2271 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2272 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2274 object_header_t *hdr;
2275 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2277 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2279 hdr = get_handle_object(hFile);
2280 if (!hdr) {
2281 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2282 return FALSE;
2285 if(hdr->vtbl->ReadFile)
2286 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2288 WININET_Release(hdr);
2290 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2291 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2293 if(res != ERROR_SUCCESS)
2294 SetLastError(res);
2295 return res == ERROR_SUCCESS;
2298 /***********************************************************************
2299 * InternetReadFileExA (WININET.@)
2301 * Read data from an open internet file
2303 * PARAMS
2304 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2305 * lpBuffersOut [I/O] Buffer.
2306 * dwFlags [I] Flags. See notes.
2307 * dwContext [I] Context for callbacks.
2309 * RETURNS
2310 * TRUE on success
2311 * FALSE on failure
2313 * NOTES
2314 * The parameter dwFlags include zero or more of the following flags:
2315 *|IRF_ASYNC - Makes the call asynchronous.
2316 *|IRF_SYNC - Makes the call synchronous.
2317 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2318 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2320 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2322 * SEE
2323 * InternetOpenUrlA(), HttpOpenRequestA()
2325 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2326 DWORD dwFlags, DWORD_PTR dwContext)
2328 object_header_t *hdr;
2329 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2331 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2333 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2334 SetLastError(ERROR_INVALID_PARAMETER);
2335 return FALSE;
2338 hdr = get_handle_object(hFile);
2339 if (!hdr) {
2340 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2341 return FALSE;
2344 if(hdr->vtbl->ReadFileEx)
2345 res = hdr->vtbl->ReadFileEx(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2346 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2348 WININET_Release(hdr);
2350 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2351 res, lpBuffersOut->dwBufferLength);
2353 if(res != ERROR_SUCCESS)
2354 SetLastError(res);
2355 return res == ERROR_SUCCESS;
2358 /***********************************************************************
2359 * InternetReadFileExW (WININET.@)
2360 * SEE
2361 * InternetReadFileExA()
2363 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2364 DWORD dwFlags, DWORD_PTR dwContext)
2366 object_header_t *hdr;
2367 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2369 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2371 if (lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2372 SetLastError(ERROR_INVALID_PARAMETER);
2373 return FALSE;
2376 hdr = get_handle_object(hFile);
2377 if (!hdr) {
2378 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2379 return FALSE;
2382 if(hdr->vtbl->ReadFileEx)
2383 res = hdr->vtbl->ReadFileEx(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2384 dwFlags, dwContext);
2386 WININET_Release(hdr);
2388 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2389 res, lpBuffer->dwBufferLength);
2391 if(res != ERROR_SUCCESS)
2392 SetLastError(res);
2393 return res == ERROR_SUCCESS;
2396 static BOOL get_proxy_autoconfig_url( char *buf, DWORD buflen )
2398 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2400 CFDictionaryRef settings = CFNetworkCopySystemProxySettings();
2401 const void *ref;
2402 BOOL ret = FALSE;
2404 if (!settings) return FALSE;
2406 if (!(ref = CFDictionaryGetValue( settings, kCFNetworkProxiesProxyAutoConfigURLString )))
2408 CFRelease( settings );
2409 return FALSE;
2411 if (CFStringGetCString( ref, buf, buflen, kCFStringEncodingASCII ))
2413 TRACE( "returning %s\n", debugstr_a(buf) );
2414 ret = TRUE;
2416 CFRelease( settings );
2417 return ret;
2418 #else
2419 FIXME( "no support on this platform\n" );
2420 return FALSE;
2421 #endif
2424 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2426 /* FIXME: This function currently handles more options than it should. Options requiring
2427 * proper handles should be moved to proper functions */
2428 switch(option) {
2429 case INTERNET_OPTION_HTTP_VERSION:
2430 if (*size < sizeof(HTTP_VERSION_INFO))
2431 return ERROR_INSUFFICIENT_BUFFER;
2434 * Presently hardcoded to 1.1
2436 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2437 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2438 *size = sizeof(HTTP_VERSION_INFO);
2440 return ERROR_SUCCESS;
2442 case INTERNET_OPTION_CONNECTED_STATE:
2443 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2445 if (*size < sizeof(ULONG))
2446 return ERROR_INSUFFICIENT_BUFFER;
2448 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2449 *size = sizeof(ULONG);
2451 return ERROR_SUCCESS;
2453 case INTERNET_OPTION_PROXY: {
2454 appinfo_t ai;
2455 BOOL ret;
2457 TRACE("Getting global proxy info\n");
2458 memset(&ai, 0, sizeof(appinfo_t));
2459 INTERNET_ConfigureProxy(&ai);
2461 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2462 APPINFO_Destroy(&ai.hdr);
2463 return ret;
2466 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2467 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2469 if (*size < sizeof(ULONG))
2470 return ERROR_INSUFFICIENT_BUFFER;
2472 *(ULONG*)buffer = max_conns;
2473 *size = sizeof(ULONG);
2475 return ERROR_SUCCESS;
2477 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2478 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2480 if (*size < sizeof(ULONG))
2481 return ERROR_INSUFFICIENT_BUFFER;
2483 *(ULONG*)buffer = max_1_0_conns;
2484 *size = sizeof(ULONG);
2486 return ERROR_SUCCESS;
2488 case INTERNET_OPTION_SECURITY_FLAGS:
2489 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2490 return ERROR_SUCCESS;
2492 case INTERNET_OPTION_VERSION: {
2493 static const INTERNET_VERSION_INFO info = { 1, 2 };
2495 TRACE("INTERNET_OPTION_VERSION\n");
2497 if (*size < sizeof(INTERNET_VERSION_INFO))
2498 return ERROR_INSUFFICIENT_BUFFER;
2500 memcpy(buffer, &info, sizeof(info));
2501 *size = sizeof(info);
2503 return ERROR_SUCCESS;
2506 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2507 char url[INTERNET_MAX_URL_LENGTH + 1];
2508 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2509 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2510 DWORD res = ERROR_SUCCESS, i;
2511 proxyinfo_t pi;
2512 BOOL have_url;
2513 LONG ret;
2515 TRACE("Getting global proxy info\n");
2516 if((ret = INTERNET_LoadProxySettings(&pi)))
2517 return ret;
2519 have_url = get_proxy_autoconfig_url(url, sizeof(url));
2521 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2523 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2524 FreeProxyInfo(&pi);
2525 return ERROR_INSUFFICIENT_BUFFER;
2528 for (i = 0; i < con->dwOptionCount; i++) {
2529 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2530 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2532 switch (optionW->dwOption) {
2533 case INTERNET_PER_CONN_FLAGS:
2534 if(pi.proxyEnabled)
2535 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2536 else
2537 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2538 if (have_url)
2539 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2540 optionW->Value.dwValue |= PROXY_TYPE_DIRECT|PROXY_TYPE_AUTO_PROXY_URL;
2541 break;
2543 case INTERNET_PER_CONN_PROXY_SERVER:
2544 if (unicode)
2545 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2546 else
2547 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2548 break;
2550 case INTERNET_PER_CONN_PROXY_BYPASS:
2551 if (unicode)
2552 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2553 else
2554 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2555 break;
2557 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2558 if (!have_url)
2559 optionW->Value.pszValue = NULL;
2560 else if (unicode)
2561 optionW->Value.pszValue = heap_strdupAtoW(url);
2562 else
2563 optionA->Value.pszValue = heap_strdupA(url);
2564 break;
2566 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2567 optionW->Value.dwValue = AUTO_PROXY_FLAG_ALWAYS_DETECT;
2568 break;
2570 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2571 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2572 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2573 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2574 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2575 memset(&optionW->Value, 0, sizeof(optionW->Value));
2576 break;
2578 default:
2579 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2580 res = ERROR_INVALID_PARAMETER;
2581 break;
2584 FreeProxyInfo(&pi);
2586 return res;
2588 case INTERNET_OPTION_REQUEST_FLAGS:
2589 case INTERNET_OPTION_USER_AGENT:
2590 *size = 0;
2591 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2592 case INTERNET_OPTION_POLICY:
2593 return ERROR_INVALID_PARAMETER;
2594 case INTERNET_OPTION_CONNECT_TIMEOUT:
2595 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2597 if (*size < sizeof(ULONG))
2598 return ERROR_INSUFFICIENT_BUFFER;
2600 *(ULONG*)buffer = connect_timeout;
2601 *size = sizeof(ULONG);
2603 return ERROR_SUCCESS;
2606 FIXME("Stub for %d\n", option);
2607 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2610 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2612 switch(option) {
2613 case INTERNET_OPTION_CONTEXT_VALUE:
2614 if (!size)
2615 return ERROR_INVALID_PARAMETER;
2617 if (*size < sizeof(DWORD_PTR)) {
2618 *size = sizeof(DWORD_PTR);
2619 return ERROR_INSUFFICIENT_BUFFER;
2621 if (!buffer)
2622 return ERROR_INVALID_PARAMETER;
2624 *(DWORD_PTR *)buffer = hdr->dwContext;
2625 *size = sizeof(DWORD_PTR);
2626 return ERROR_SUCCESS;
2628 case INTERNET_OPTION_REQUEST_FLAGS:
2629 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2630 *size = sizeof(DWORD);
2631 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2633 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2634 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2635 WARN("Called on global option %u\n", option);
2636 return ERROR_INTERNET_INVALID_OPERATION;
2639 /* FIXME: we shouldn't call it here */
2640 return query_global_option(option, buffer, size, unicode);
2643 /***********************************************************************
2644 * InternetQueryOptionW (WININET.@)
2646 * Queries an options on the specified handle
2648 * RETURNS
2649 * TRUE on success
2650 * FALSE on failure
2653 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2654 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2656 object_header_t *hdr;
2657 DWORD res = ERROR_INVALID_HANDLE;
2659 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2661 if(hInternet) {
2662 hdr = get_handle_object(hInternet);
2663 if (hdr) {
2664 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2665 WININET_Release(hdr);
2667 }else {
2668 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2671 if(res != ERROR_SUCCESS)
2672 SetLastError(res);
2673 return res == ERROR_SUCCESS;
2676 /***********************************************************************
2677 * InternetQueryOptionA (WININET.@)
2679 * Queries an options on the specified handle
2681 * RETURNS
2682 * TRUE on success
2683 * FALSE on failure
2686 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2687 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2689 object_header_t *hdr;
2690 DWORD res = ERROR_INVALID_HANDLE;
2692 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2694 if(hInternet) {
2695 hdr = get_handle_object(hInternet);
2696 if (hdr) {
2697 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2698 WININET_Release(hdr);
2700 }else {
2701 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2704 if(res != ERROR_SUCCESS)
2705 SetLastError(res);
2706 return res == ERROR_SUCCESS;
2709 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2711 switch(option) {
2712 case INTERNET_OPTION_CALLBACK:
2713 WARN("Not settable option %u\n", option);
2714 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2715 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2716 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2717 WARN("Called on global option %u\n", option);
2718 return ERROR_INTERNET_INVALID_OPERATION;
2721 return ERROR_INTERNET_INVALID_OPTION;
2724 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2726 switch(option) {
2727 case INTERNET_OPTION_CALLBACK:
2728 WARN("Not global option %u\n", option);
2729 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2731 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2732 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2734 if(size != sizeof(max_conns))
2735 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2736 if(!*(ULONG*)buf)
2737 return ERROR_BAD_ARGUMENTS;
2739 max_conns = *(ULONG*)buf;
2740 return ERROR_SUCCESS;
2742 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2743 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2745 if(size != sizeof(max_1_0_conns))
2746 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2747 if(!*(ULONG*)buf)
2748 return ERROR_BAD_ARGUMENTS;
2750 max_1_0_conns = *(ULONG*)buf;
2751 return ERROR_SUCCESS;
2753 case INTERNET_OPTION_CONNECT_TIMEOUT:
2754 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2756 if(size != sizeof(connect_timeout))
2757 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2758 if(!*(ULONG*)buf)
2759 return ERROR_BAD_ARGUMENTS;
2761 connect_timeout = *(ULONG*)buf;
2762 return ERROR_SUCCESS;
2764 case INTERNET_OPTION_SETTINGS_CHANGED:
2765 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2766 collect_connections(COLLECT_CONNECTIONS);
2767 return ERROR_SUCCESS;
2770 return ERROR_INTERNET_INVALID_OPTION;
2773 /***********************************************************************
2774 * InternetSetOptionW (WININET.@)
2776 * Sets an options on the specified handle
2778 * RETURNS
2779 * TRUE on success
2780 * FALSE on failure
2783 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2784 LPVOID lpBuffer, DWORD dwBufferLength)
2786 object_header_t *lpwhh;
2787 BOOL ret = TRUE;
2788 DWORD res;
2790 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2792 lpwhh = (object_header_t*) get_handle_object( hInternet );
2793 if(lpwhh)
2794 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2795 else
2796 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2798 if(res != ERROR_INTERNET_INVALID_OPTION) {
2799 if(lpwhh)
2800 WININET_Release(lpwhh);
2802 if(res != ERROR_SUCCESS)
2803 SetLastError(res);
2805 return res == ERROR_SUCCESS;
2808 switch (dwOption)
2810 case INTERNET_OPTION_HTTP_VERSION:
2812 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2813 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2815 break;
2816 case INTERNET_OPTION_ERROR_MASK:
2818 if(!lpwhh) {
2819 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2820 return FALSE;
2821 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2822 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2823 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2824 SetLastError(ERROR_INVALID_PARAMETER);
2825 ret = FALSE;
2826 } else if(dwBufferLength != sizeof(ULONG)) {
2827 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2828 ret = FALSE;
2829 } else
2830 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2831 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2833 break;
2834 case INTERNET_OPTION_PROXY:
2836 INTERNET_PROXY_INFOW *info = lpBuffer;
2838 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2840 SetLastError(ERROR_INVALID_PARAMETER);
2841 return FALSE;
2843 if (!hInternet)
2845 EnterCriticalSection( &WININET_cs );
2846 free_global_proxy();
2847 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2848 if (global_proxy)
2850 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2852 global_proxy->proxyEnabled = 1;
2853 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2854 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2856 else
2858 global_proxy->proxyEnabled = 0;
2859 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2862 LeaveCriticalSection( &WININET_cs );
2864 else
2866 /* In general, each type of object should handle
2867 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2868 * get silently dropped.
2870 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2871 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2872 ret = FALSE;
2874 break;
2876 case INTERNET_OPTION_CODEPAGE:
2878 ULONG codepage = *(ULONG *)lpBuffer;
2879 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2881 break;
2882 case INTERNET_OPTION_REQUEST_PRIORITY:
2884 ULONG priority = *(ULONG *)lpBuffer;
2885 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2887 break;
2888 case INTERNET_OPTION_CONNECT_TIMEOUT:
2890 ULONG connecttimeout = *(ULONG *)lpBuffer;
2891 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2893 break;
2894 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2896 ULONG receivetimeout = *(ULONG *)lpBuffer;
2897 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2899 break;
2900 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2901 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2902 break;
2903 case INTERNET_OPTION_END_BROWSER_SESSION:
2904 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2905 break;
2906 case INTERNET_OPTION_CONNECTED_STATE:
2907 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2908 break;
2909 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2910 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2911 break;
2912 case INTERNET_OPTION_SEND_TIMEOUT:
2913 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2914 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2916 ULONG timeout = *(ULONG *)lpBuffer;
2917 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2918 break;
2920 case INTERNET_OPTION_CONNECT_RETRIES:
2922 ULONG retries = *(ULONG *)lpBuffer;
2923 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2924 break;
2926 case INTERNET_OPTION_CONTEXT_VALUE:
2928 if (!lpwhh)
2930 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2931 return FALSE;
2933 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2935 SetLastError(ERROR_INVALID_PARAMETER);
2936 ret = FALSE;
2938 else
2939 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2940 break;
2942 case INTERNET_OPTION_SECURITY_FLAGS:
2943 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2944 break;
2945 case INTERNET_OPTION_DISABLE_AUTODIAL:
2946 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2947 break;
2948 case INTERNET_OPTION_HTTP_DECODING:
2949 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2950 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2951 ret = FALSE;
2952 break;
2953 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2954 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2955 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2956 ret = FALSE;
2957 break;
2958 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2959 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2960 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2961 ret = FALSE;
2962 break;
2963 case INTERNET_OPTION_CODEPAGE_PATH:
2964 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2965 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2966 ret = FALSE;
2967 break;
2968 case INTERNET_OPTION_CODEPAGE_EXTRA:
2969 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2970 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2971 ret = FALSE;
2972 break;
2973 case INTERNET_OPTION_IDN:
2974 FIXME("INTERNET_OPTION_IDN; STUB\n");
2975 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2976 ret = FALSE;
2977 break;
2978 case INTERNET_OPTION_POLICY:
2979 SetLastError(ERROR_INVALID_PARAMETER);
2980 ret = FALSE;
2981 break;
2982 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2983 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2984 LONG res;
2985 unsigned int i;
2986 proxyinfo_t pi;
2988 if (INTERNET_LoadProxySettings(&pi)) return FALSE;
2990 for (i = 0; i < con->dwOptionCount; i++) {
2991 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2993 switch (option->dwOption) {
2994 case INTERNET_PER_CONN_PROXY_SERVER:
2995 heap_free(pi.proxy);
2996 pi.proxy = heap_strdupW(option->Value.pszValue);
2997 break;
2999 case INTERNET_PER_CONN_FLAGS:
3000 if(option->Value.dwValue & PROXY_TYPE_PROXY)
3001 pi.proxyEnabled = 1;
3002 else
3004 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
3005 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
3006 pi.proxyEnabled = 0;
3008 break;
3010 case INTERNET_PER_CONN_PROXY_BYPASS:
3011 heap_free(pi.proxyBypass);
3012 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
3013 break;
3015 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3016 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3017 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3018 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3019 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3020 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3021 FIXME("Unhandled dwOption %d\n", option->dwOption);
3022 break;
3024 default:
3025 FIXME("Unknown dwOption %d\n", option->dwOption);
3026 SetLastError(ERROR_INVALID_PARAMETER);
3027 break;
3031 if ((res = INTERNET_SaveProxySettings(&pi)))
3032 SetLastError(res);
3034 FreeProxyInfo(&pi);
3036 ret = (res == ERROR_SUCCESS);
3037 break;
3039 default:
3040 FIXME("Option %d STUB\n",dwOption);
3041 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3042 ret = FALSE;
3043 break;
3046 if(lpwhh)
3047 WININET_Release( lpwhh );
3049 return ret;
3053 /***********************************************************************
3054 * InternetSetOptionA (WININET.@)
3056 * Sets an options on the specified handle.
3058 * RETURNS
3059 * TRUE on success
3060 * FALSE on failure
3063 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
3064 LPVOID lpBuffer, DWORD dwBufferLength)
3066 LPVOID wbuffer;
3067 DWORD wlen;
3068 BOOL r;
3070 switch( dwOption )
3072 case INTERNET_OPTION_PROXY:
3074 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
3075 LPINTERNET_PROXY_INFOW piw;
3076 DWORD proxlen, prbylen;
3077 LPWSTR prox, prby;
3079 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
3080 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
3081 wlen = sizeof(*piw) + proxlen + prbylen;
3082 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
3083 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
3084 piw->dwAccessType = pi->dwAccessType;
3085 prox = (LPWSTR) &piw[1];
3086 prby = &prox[proxlen+1];
3087 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
3088 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
3089 piw->lpszProxy = prox;
3090 piw->lpszProxyBypass = prby;
3092 break;
3093 case INTERNET_OPTION_USER_AGENT:
3094 case INTERNET_OPTION_USERNAME:
3095 case INTERNET_OPTION_PASSWORD:
3096 case INTERNET_OPTION_PROXY_USERNAME:
3097 case INTERNET_OPTION_PROXY_PASSWORD:
3098 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3099 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3100 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3101 break;
3102 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3103 unsigned int i;
3104 INTERNET_PER_CONN_OPTION_LISTW *listW;
3105 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3106 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3107 wbuffer = heap_alloc(wlen);
3108 listW = wbuffer;
3110 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3111 if (listA->pszConnection)
3113 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3114 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3115 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3117 else
3118 listW->pszConnection = NULL;
3119 listW->dwOptionCount = listA->dwOptionCount;
3120 listW->dwOptionError = listA->dwOptionError;
3121 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3123 for (i = 0; i < listA->dwOptionCount; ++i) {
3124 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3125 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3127 optW->dwOption = optA->dwOption;
3129 switch (optA->dwOption) {
3130 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3131 case INTERNET_PER_CONN_PROXY_BYPASS:
3132 case INTERNET_PER_CONN_PROXY_SERVER:
3133 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3134 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3135 if (optA->Value.pszValue)
3137 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3138 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3139 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3141 else
3142 optW->Value.pszValue = NULL;
3143 break;
3144 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3145 case INTERNET_PER_CONN_FLAGS:
3146 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3147 optW->Value.dwValue = optA->Value.dwValue;
3148 break;
3149 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3150 optW->Value.ftValue = optA->Value.ftValue;
3151 break;
3152 default:
3153 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3154 optW->Value.dwValue = optA->Value.dwValue;
3155 break;
3159 break;
3160 default:
3161 wbuffer = lpBuffer;
3162 wlen = dwBufferLength;
3165 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3167 if( lpBuffer != wbuffer )
3169 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3171 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3172 unsigned int i;
3173 for (i = 0; i < list->dwOptionCount; ++i) {
3174 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3175 switch (opt->dwOption) {
3176 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3177 case INTERNET_PER_CONN_PROXY_BYPASS:
3178 case INTERNET_PER_CONN_PROXY_SERVER:
3179 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3180 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3181 heap_free( opt->Value.pszValue );
3182 break;
3183 default:
3184 break;
3187 heap_free( list->pOptions );
3189 heap_free( wbuffer );
3192 return r;
3196 /***********************************************************************
3197 * InternetSetOptionExA (WININET.@)
3199 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3200 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3202 FIXME("Flags %08x ignored\n", dwFlags);
3203 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3206 /***********************************************************************
3207 * InternetSetOptionExW (WININET.@)
3209 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3210 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3212 FIXME("Flags %08x ignored\n", dwFlags);
3213 if( dwFlags & ~ISO_VALID_FLAGS )
3215 SetLastError( ERROR_INVALID_PARAMETER );
3216 return FALSE;
3218 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3221 static const WCHAR WININET_wkday[7][4] =
3222 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3223 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3224 static const WCHAR WININET_month[12][4] =
3225 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3226 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3227 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3229 /***********************************************************************
3230 * InternetTimeFromSystemTimeA (WININET.@)
3232 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3234 BOOL ret;
3235 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3237 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3239 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3241 SetLastError(ERROR_INVALID_PARAMETER);
3242 return FALSE;
3245 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3247 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3248 return FALSE;
3251 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3252 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3254 return ret;
3257 /***********************************************************************
3258 * InternetTimeFromSystemTimeW (WININET.@)
3260 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3262 static const WCHAR date[] =
3263 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3264 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3266 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3268 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3270 SetLastError(ERROR_INVALID_PARAMETER);
3271 return FALSE;
3274 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3276 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3277 return FALSE;
3280 sprintfW( string, date,
3281 WININET_wkday[time->wDayOfWeek],
3282 time->wDay,
3283 WININET_month[time->wMonth - 1],
3284 time->wYear,
3285 time->wHour,
3286 time->wMinute,
3287 time->wSecond );
3289 return TRUE;
3292 /***********************************************************************
3293 * InternetTimeToSystemTimeA (WININET.@)
3295 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3297 BOOL ret = FALSE;
3298 WCHAR *stringW;
3300 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3302 stringW = heap_strdupAtoW(string);
3303 if (stringW)
3305 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3306 heap_free( stringW );
3308 return ret;
3311 /***********************************************************************
3312 * InternetTimeToSystemTimeW (WININET.@)
3314 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3316 unsigned int i;
3317 const WCHAR *s = string;
3318 WCHAR *end;
3320 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3322 if (!string || !time) return FALSE;
3324 /* Windows does this too */
3325 GetSystemTime( time );
3327 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3328 * a SYSTEMTIME structure.
3331 while (*s && !isalphaW( *s )) s++;
3332 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3333 time->wDayOfWeek = 7;
3335 for (i = 0; i < 7; i++)
3337 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3338 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3339 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3341 time->wDayOfWeek = i;
3342 break;
3346 if (time->wDayOfWeek > 6) return TRUE;
3347 while (*s && !isdigitW( *s )) s++;
3348 time->wDay = strtolW( s, &end, 10 );
3349 s = end;
3351 while (*s && !isalphaW( *s )) s++;
3352 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3353 time->wMonth = 0;
3355 for (i = 0; i < 12; i++)
3357 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3358 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3359 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3361 time->wMonth = i + 1;
3362 break;
3365 if (time->wMonth == 0) return TRUE;
3367 while (*s && !isdigitW( *s )) s++;
3368 if (*s == '\0') return TRUE;
3369 time->wYear = strtolW( s, &end, 10 );
3370 s = end;
3372 while (*s && !isdigitW( *s )) s++;
3373 if (*s == '\0') return TRUE;
3374 time->wHour = strtolW( s, &end, 10 );
3375 s = end;
3377 while (*s && !isdigitW( *s )) s++;
3378 if (*s == '\0') return TRUE;
3379 time->wMinute = strtolW( s, &end, 10 );
3380 s = end;
3382 while (*s && !isdigitW( *s )) s++;
3383 if (*s == '\0') return TRUE;
3384 time->wSecond = strtolW( s, &end, 10 );
3385 s = end;
3387 time->wMilliseconds = 0;
3388 return TRUE;
3391 /***********************************************************************
3392 * InternetCheckConnectionW (WININET.@)
3394 * Pings a requested host to check internet connection
3396 * RETURNS
3397 * TRUE on success and FALSE on failure. If a failure then
3398 * ERROR_NOT_CONNECTED is placed into GetLastError
3401 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3404 * this is a kludge which runs the resident ping program and reads the output.
3406 * Anyone have a better idea?
3409 BOOL rc = FALSE;
3410 static const CHAR ping[] = "ping -c 1 ";
3411 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3412 CHAR *command = NULL;
3413 WCHAR hostW[INTERNET_MAX_HOST_NAME_LENGTH];
3414 DWORD len;
3415 INTERNET_PORT port;
3416 int status = -1;
3418 FIXME("\n");
3421 * Crack or set the Address
3423 if (lpszUrl == NULL)
3426 * According to the doc we are supposed to use the ip for the next
3427 * server in the WnInet internal server database. I have
3428 * no idea what that is or how to get it.
3430 * So someone needs to implement this.
3432 FIXME("Unimplemented with URL of NULL\n");
3433 return TRUE;
3435 else
3437 URL_COMPONENTSW components;
3439 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3440 components.lpszHostName = (LPWSTR)hostW;
3441 components.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3443 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3444 goto End;
3446 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3447 port = components.nPort;
3448 TRACE("port: %d\n", port);
3451 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3453 struct sockaddr_storage saddr;
3454 socklen_t sa_len = sizeof(saddr);
3455 int fd;
3457 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len, NULL))
3458 goto End;
3459 init_winsock();
3460 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3461 if (fd != -1)
3463 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3464 rc = TRUE;
3465 closesocket(fd);
3468 else
3471 * Build our ping command
3473 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3474 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3475 strcpy(command,ping);
3476 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3477 strcat(command,redirect);
3479 TRACE("Ping command is : %s\n",command);
3481 status = system(command);
3483 TRACE("Ping returned a code of %i\n",status);
3485 /* Ping return code of 0 indicates success */
3486 if (status == 0)
3487 rc = TRUE;
3490 End:
3491 heap_free( command );
3492 if (rc == FALSE)
3493 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3495 return rc;
3499 /***********************************************************************
3500 * InternetCheckConnectionA (WININET.@)
3502 * Pings a requested host to check internet connection
3504 * RETURNS
3505 * TRUE on success and FALSE on failure. If a failure then
3506 * ERROR_NOT_CONNECTED is placed into GetLastError
3509 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3511 WCHAR *url = NULL;
3512 BOOL rc;
3514 if(lpszUrl) {
3515 url = heap_strdupAtoW(lpszUrl);
3516 if(!url)
3517 return FALSE;
3520 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3522 heap_free(url);
3523 return rc;
3527 /**********************************************************
3528 * INTERNET_InternetOpenUrlW (internal)
3530 * Opens an URL
3532 * RETURNS
3533 * handle of connection or NULL on failure
3535 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3536 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3538 URL_COMPONENTSW urlComponents;
3539 WCHAR protocol[INTERNET_MAX_SCHEME_LENGTH];
3540 WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH];
3541 WCHAR userName[INTERNET_MAX_USER_NAME_LENGTH];
3542 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
3543 WCHAR path[INTERNET_MAX_PATH_LENGTH];
3544 WCHAR extra[1024];
3545 HINTERNET client = NULL, client1 = NULL;
3546 DWORD res;
3548 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3549 dwHeadersLength, dwFlags, dwContext);
3551 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3552 urlComponents.lpszScheme = protocol;
3553 urlComponents.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH;
3554 urlComponents.lpszHostName = hostName;
3555 urlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3556 urlComponents.lpszUserName = userName;
3557 urlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
3558 urlComponents.lpszPassword = password;
3559 urlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
3560 urlComponents.lpszUrlPath = path;
3561 urlComponents.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
3562 urlComponents.lpszExtraInfo = extra;
3563 urlComponents.dwExtraInfoLength = 1024;
3564 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3565 return NULL;
3566 switch(urlComponents.nScheme) {
3567 case INTERNET_SCHEME_FTP:
3568 if(urlComponents.nPort == 0)
3569 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3570 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3571 userName, password, dwFlags, dwContext, INET_OPENURL);
3572 if(client == NULL)
3573 break;
3574 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3575 if(client1 == NULL) {
3576 InternetCloseHandle(client);
3577 break;
3579 break;
3581 case INTERNET_SCHEME_HTTP:
3582 case INTERNET_SCHEME_HTTPS: {
3583 static const WCHAR szStars[] = { '*','/','*', 0 };
3584 LPCWSTR accept[2] = { szStars, NULL };
3585 if(urlComponents.nPort == 0) {
3586 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3587 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3588 else
3589 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3591 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3593 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3594 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3595 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3596 if(res != ERROR_SUCCESS) {
3597 INTERNET_SetLastError(res);
3598 break;
3601 if (urlComponents.dwExtraInfoLength) {
3602 WCHAR *path_extra;
3603 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3605 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3607 InternetCloseHandle(client);
3608 break;
3610 strcpyW(path_extra, urlComponents.lpszUrlPath);
3611 strcatW(path_extra, urlComponents.lpszExtraInfo);
3612 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3613 heap_free(path_extra);
3615 else
3616 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3618 if(client1 == NULL) {
3619 InternetCloseHandle(client);
3620 break;
3622 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3623 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3624 GetLastError() != ERROR_IO_PENDING) {
3625 InternetCloseHandle(client1);
3626 client1 = NULL;
3627 break;
3630 case INTERNET_SCHEME_GOPHER:
3631 /* gopher doesn't seem to be implemented in wine, but it's supposed
3632 * to be supported by InternetOpenUrlA. */
3633 default:
3634 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3635 break;
3638 TRACE(" %p <--\n", client1);
3640 return client1;
3643 /**********************************************************
3644 * InternetOpenUrlW (WININET.@)
3646 * Opens an URL
3648 * RETURNS
3649 * handle of connection or NULL on failure
3651 typedef struct {
3652 task_header_t hdr;
3653 WCHAR *url;
3654 WCHAR *headers;
3655 DWORD headers_len;
3656 DWORD flags;
3657 DWORD_PTR context;
3658 } open_url_task_t;
3660 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3662 open_url_task_t *task = (open_url_task_t*)hdr;
3664 TRACE("%p\n", task->hdr.hdr);
3666 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3667 task->headers_len, task->flags, task->context);
3668 heap_free(task->url);
3669 heap_free(task->headers);
3672 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3673 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3675 HINTERNET ret = NULL;
3676 appinfo_t *hIC = NULL;
3678 if (TRACE_ON(wininet)) {
3679 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3680 dwHeadersLength, dwFlags, dwContext);
3681 TRACE(" flags :");
3682 dump_INTERNET_FLAGS(dwFlags);
3685 if (!lpszUrl)
3687 SetLastError(ERROR_INVALID_PARAMETER);
3688 goto lend;
3691 hIC = (appinfo_t*)get_handle_object( hInternet );
3692 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3693 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3694 goto lend;
3697 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3698 open_url_task_t *task;
3700 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3701 task->url = heap_strdupW(lpszUrl);
3702 task->headers = heap_strdupW(lpszHeaders);
3703 task->headers_len = dwHeadersLength;
3704 task->flags = dwFlags;
3705 task->context = dwContext;
3707 INTERNET_AsyncCall(&task->hdr);
3708 SetLastError(ERROR_IO_PENDING);
3709 } else {
3710 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3713 lend:
3714 if( hIC )
3715 WININET_Release( &hIC->hdr );
3716 TRACE(" %p <--\n", ret);
3718 return ret;
3721 /**********************************************************
3722 * InternetOpenUrlA (WININET.@)
3724 * Opens an URL
3726 * RETURNS
3727 * handle of connection or NULL on failure
3729 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3730 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3732 HINTERNET rc = NULL;
3733 DWORD lenHeaders = 0;
3734 LPWSTR szUrl = NULL;
3735 LPWSTR szHeaders = NULL;
3737 TRACE("\n");
3739 if(lpszUrl) {
3740 szUrl = heap_strdupAtoW(lpszUrl);
3741 if(!szUrl)
3742 return NULL;
3745 if(lpszHeaders) {
3746 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3747 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3748 if(!szHeaders) {
3749 heap_free(szUrl);
3750 return NULL;
3752 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3755 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3756 lenHeaders, dwFlags, dwContext);
3758 heap_free(szUrl);
3759 heap_free(szHeaders);
3760 return rc;
3764 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3766 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3768 if (lpwite)
3770 lpwite->dwError = 0;
3771 lpwite->response[0] = '\0';
3774 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3776 heap_free(lpwite);
3777 return NULL;
3779 return lpwite;
3783 /***********************************************************************
3784 * INTERNET_SetLastError (internal)
3786 * Set last thread specific error
3788 * RETURNS
3791 void INTERNET_SetLastError(DWORD dwError)
3793 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3795 if (!lpwite)
3796 lpwite = INTERNET_AllocThreadError();
3798 SetLastError(dwError);
3799 if(lpwite)
3800 lpwite->dwError = dwError;
3804 /***********************************************************************
3805 * INTERNET_GetLastError (internal)
3807 * Get last thread specific error
3809 * RETURNS
3812 DWORD INTERNET_GetLastError(void)
3814 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3815 if (!lpwite) return 0;
3816 /* TlsGetValue clears last error, so set it again here */
3817 SetLastError(lpwite->dwError);
3818 return lpwite->dwError;
3822 /***********************************************************************
3823 * INTERNET_WorkerThreadFunc (internal)
3825 * Worker thread execution function
3827 * RETURNS
3830 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3832 task_header_t *task = lpvParam;
3834 TRACE("\n");
3836 task->proc(task);
3837 WININET_Release(task->hdr);
3838 heap_free(task);
3840 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3842 heap_free(TlsGetValue(g_dwTlsErrIndex));
3843 TlsSetValue(g_dwTlsErrIndex, NULL);
3845 return TRUE;
3848 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3850 task_header_t *task;
3852 task = heap_alloc(size);
3853 if(!task)
3854 return NULL;
3856 task->hdr = WININET_AddRef(hdr);
3857 task->proc = proc;
3858 return task;
3861 /***********************************************************************
3862 * INTERNET_AsyncCall (internal)
3864 * Retrieves work request from queue
3866 * RETURNS
3869 DWORD INTERNET_AsyncCall(task_header_t *task)
3871 BOOL bSuccess;
3873 TRACE("\n");
3875 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3876 if (!bSuccess)
3878 heap_free(task);
3879 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3881 return ERROR_SUCCESS;
3885 /***********************************************************************
3886 * INTERNET_GetResponseBuffer (internal)
3888 * RETURNS
3891 LPSTR INTERNET_GetResponseBuffer(void)
3893 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3894 if (!lpwite)
3895 lpwite = INTERNET_AllocThreadError();
3896 TRACE("\n");
3897 return lpwite->response;
3900 /**********************************************************
3901 * InternetQueryDataAvailable (WININET.@)
3903 * Determines how much data is available to be read.
3905 * RETURNS
3906 * TRUE on success, FALSE if an error occurred. If
3907 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3908 * no data is presently available, FALSE is returned with
3909 * the last error ERROR_IO_PENDING; a callback with status
3910 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3911 * data is available.
3913 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3914 LPDWORD lpdwNumberOfBytesAvailable,
3915 DWORD dwFlags, DWORD_PTR dwContext)
3917 object_header_t *hdr;
3918 DWORD res;
3920 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3922 hdr = get_handle_object( hFile );
3923 if (!hdr) {
3924 SetLastError(ERROR_INVALID_HANDLE);
3925 return FALSE;
3928 if(hdr->vtbl->QueryDataAvailable) {
3929 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3930 }else {
3931 WARN("wrong handle\n");
3932 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3935 WININET_Release(hdr);
3937 if(res != ERROR_SUCCESS)
3938 SetLastError(res);
3939 return res == ERROR_SUCCESS;
3942 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
3944 req_file_t *req_file;
3946 req_file = heap_alloc_zero(sizeof(*req_file));
3947 if(!req_file)
3948 return ERROR_NOT_ENOUGH_MEMORY;
3950 req_file->ref = 1;
3952 req_file->file_name = heap_strdupW(file_name);
3953 if(!req_file->file_name) {
3954 heap_free(req_file);
3955 return ERROR_NOT_ENOUGH_MEMORY;
3958 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
3959 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3960 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
3961 req_file_release(req_file);
3962 return GetLastError();
3965 *ret = req_file;
3966 return ERROR_SUCCESS;
3969 void req_file_release(req_file_t *req_file)
3971 if(InterlockedDecrement(&req_file->ref))
3972 return;
3974 if(!req_file->is_committed)
3975 DeleteFileW(req_file->file_name);
3976 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
3977 CloseHandle(req_file->file_handle);
3978 heap_free(req_file->file_name);
3979 heap_free(req_file);
3982 /***********************************************************************
3983 * InternetLockRequestFile (WININET.@)
3985 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
3987 req_file_t *req_file = NULL;
3988 object_header_t *hdr;
3989 DWORD res;
3991 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
3993 hdr = get_handle_object(hInternet);
3994 if (!hdr) {
3995 SetLastError(ERROR_INVALID_HANDLE);
3996 return FALSE;
3999 if(hdr->vtbl->LockRequestFile) {
4000 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
4001 }else {
4002 WARN("wrong handle\n");
4003 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4006 WININET_Release(hdr);
4008 *lphLockReqHandle = req_file;
4009 if(res != ERROR_SUCCESS)
4010 SetLastError(res);
4011 return res == ERROR_SUCCESS;
4014 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
4016 TRACE("(%p)\n", hLockHandle);
4018 req_file_release(hLockHandle);
4019 return TRUE;
4023 /***********************************************************************
4024 * InternetAutodial (WININET.@)
4026 * On windows this function is supposed to dial the default internet
4027 * connection. We don't want to have Wine dial out to the internet so
4028 * we return TRUE by default. It might be nice to check if we are connected.
4030 * RETURNS
4031 * TRUE on success
4032 * FALSE on failure
4035 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4037 FIXME("STUB\n");
4039 /* Tell that we are connected to the internet. */
4040 return TRUE;
4043 /***********************************************************************
4044 * InternetAutodialHangup (WININET.@)
4046 * Hangs up a connection made with InternetAutodial
4048 * PARAM
4049 * dwReserved
4050 * RETURNS
4051 * TRUE on success
4052 * FALSE on failure
4055 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4057 FIXME("STUB\n");
4059 /* we didn't dial, we don't disconnect */
4060 return TRUE;
4063 /***********************************************************************
4064 * InternetCombineUrlA (WININET.@)
4066 * Combine a base URL with a relative URL
4068 * RETURNS
4069 * TRUE on success
4070 * FALSE on failure
4074 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4075 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4076 DWORD dwFlags)
4078 HRESULT hr=S_OK;
4080 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4082 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4083 dwFlags ^= ICU_NO_ENCODE;
4084 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4086 return (hr==S_OK);
4089 /***********************************************************************
4090 * InternetCombineUrlW (WININET.@)
4092 * Combine a base URL with a relative URL
4094 * RETURNS
4095 * TRUE on success
4096 * FALSE on failure
4100 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4101 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4102 DWORD dwFlags)
4104 HRESULT hr=S_OK;
4106 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4108 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4109 dwFlags ^= ICU_NO_ENCODE;
4110 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4112 return (hr==S_OK);
4115 /* max port num is 65535 => 5 digits */
4116 #define MAX_WORD_DIGITS 5
4118 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4119 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4120 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4121 (url)->dw##component##Length : strlen((url)->lpsz##component))
4123 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4125 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4126 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4127 return TRUE;
4128 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4129 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4130 return TRUE;
4131 if ((nScheme == INTERNET_SCHEME_FTP) &&
4132 (nPort == INTERNET_DEFAULT_FTP_PORT))
4133 return TRUE;
4134 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4135 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4136 return TRUE;
4138 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4139 return TRUE;
4141 return FALSE;
4144 /* opaque urls do not fit into the standard url hierarchy and don't have
4145 * two following slashes */
4146 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4148 return (nScheme != INTERNET_SCHEME_FTP) &&
4149 (nScheme != INTERNET_SCHEME_GOPHER) &&
4150 (nScheme != INTERNET_SCHEME_HTTP) &&
4151 (nScheme != INTERNET_SCHEME_HTTPS) &&
4152 (nScheme != INTERNET_SCHEME_FILE);
4155 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4157 int index;
4158 if (scheme < INTERNET_SCHEME_FIRST)
4159 return NULL;
4160 index = scheme - INTERNET_SCHEME_FIRST;
4161 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
4162 return NULL;
4163 return (LPCWSTR)url_schemes[index];
4166 /* we can calculate using ansi strings because we're just
4167 * calculating string length, not size
4169 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4170 LPDWORD lpdwUrlLength)
4172 INTERNET_SCHEME nScheme;
4174 *lpdwUrlLength = 0;
4176 if (lpUrlComponents->lpszScheme)
4178 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4179 *lpdwUrlLength += dwLen;
4180 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4182 else
4184 LPCWSTR scheme;
4186 nScheme = lpUrlComponents->nScheme;
4188 if (nScheme == INTERNET_SCHEME_DEFAULT)
4189 nScheme = INTERNET_SCHEME_HTTP;
4190 scheme = INTERNET_GetSchemeString(nScheme);
4191 *lpdwUrlLength += strlenW(scheme);
4194 (*lpdwUrlLength)++; /* ':' */
4195 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4196 *lpdwUrlLength += strlen("//");
4198 if (lpUrlComponents->lpszUserName)
4200 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4201 *lpdwUrlLength += strlen("@");
4203 else
4205 if (lpUrlComponents->lpszPassword)
4207 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4208 return FALSE;
4212 if (lpUrlComponents->lpszPassword)
4214 *lpdwUrlLength += strlen(":");
4215 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4218 if (lpUrlComponents->lpszHostName)
4220 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4222 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4224 char szPort[MAX_WORD_DIGITS+1];
4226 sprintf(szPort, "%d", lpUrlComponents->nPort);
4227 *lpdwUrlLength += strlen(szPort);
4228 *lpdwUrlLength += strlen(":");
4231 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4232 (*lpdwUrlLength)++; /* '/' */
4235 if (lpUrlComponents->lpszUrlPath)
4236 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4238 if (lpUrlComponents->lpszExtraInfo)
4239 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4241 return TRUE;
4244 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4246 INT len;
4248 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4250 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4251 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4252 urlCompW->nScheme = lpUrlComponents->nScheme;
4253 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4254 urlCompW->nPort = lpUrlComponents->nPort;
4255 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4256 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4257 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4258 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4260 if (lpUrlComponents->lpszScheme)
4262 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4263 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4264 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4265 -1, urlCompW->lpszScheme, len);
4268 if (lpUrlComponents->lpszHostName)
4270 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4271 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4272 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4273 -1, urlCompW->lpszHostName, len);
4276 if (lpUrlComponents->lpszUserName)
4278 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4279 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4280 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4281 -1, urlCompW->lpszUserName, len);
4284 if (lpUrlComponents->lpszPassword)
4286 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4287 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4288 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4289 -1, urlCompW->lpszPassword, len);
4292 if (lpUrlComponents->lpszUrlPath)
4294 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4295 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4296 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4297 -1, urlCompW->lpszUrlPath, len);
4300 if (lpUrlComponents->lpszExtraInfo)
4302 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4303 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4304 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4305 -1, urlCompW->lpszExtraInfo, len);
4309 /***********************************************************************
4310 * InternetCreateUrlA (WININET.@)
4312 * See InternetCreateUrlW.
4314 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4315 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4317 BOOL ret;
4318 LPWSTR urlW = NULL;
4319 URL_COMPONENTSW urlCompW;
4321 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4323 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4325 SetLastError(ERROR_INVALID_PARAMETER);
4326 return FALSE;
4329 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4331 if (lpszUrl)
4332 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4334 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4336 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4337 *lpdwUrlLength /= sizeof(WCHAR);
4339 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4340 * minus one, so add one to leave room for NULL terminator
4342 if (ret)
4343 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4345 heap_free(urlCompW.lpszScheme);
4346 heap_free(urlCompW.lpszHostName);
4347 heap_free(urlCompW.lpszUserName);
4348 heap_free(urlCompW.lpszPassword);
4349 heap_free(urlCompW.lpszUrlPath);
4350 heap_free(urlCompW.lpszExtraInfo);
4351 heap_free(urlW);
4352 return ret;
4355 /***********************************************************************
4356 * InternetCreateUrlW (WININET.@)
4358 * Creates a URL from its component parts.
4360 * PARAMS
4361 * lpUrlComponents [I] URL Components.
4362 * dwFlags [I] Flags. See notes.
4363 * lpszUrl [I] Buffer in which to store the created URL.
4364 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4365 * lpszUrl in characters. On output, the number of bytes
4366 * required to store the URL including terminator.
4368 * NOTES
4370 * The dwFlags parameter can be zero or more of the following:
4371 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4373 * RETURNS
4374 * TRUE on success
4375 * FALSE on failure
4378 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4379 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4381 DWORD dwLen;
4382 INTERNET_SCHEME nScheme;
4384 static const WCHAR slashSlashW[] = {'/','/'};
4385 static const WCHAR fmtW[] = {'%','u',0};
4387 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4389 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4391 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4392 return FALSE;
4395 if (!calc_url_length(lpUrlComponents, &dwLen))
4396 return FALSE;
4398 if (!lpszUrl || *lpdwUrlLength < dwLen)
4400 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4401 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4402 return FALSE;
4405 *lpdwUrlLength = dwLen;
4406 lpszUrl[0] = 0x00;
4408 dwLen = 0;
4410 if (lpUrlComponents->lpszScheme)
4412 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4413 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4414 lpszUrl += dwLen;
4416 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4418 else
4420 LPCWSTR scheme;
4421 nScheme = lpUrlComponents->nScheme;
4423 if (nScheme == INTERNET_SCHEME_DEFAULT)
4424 nScheme = INTERNET_SCHEME_HTTP;
4426 scheme = INTERNET_GetSchemeString(nScheme);
4427 dwLen = strlenW(scheme);
4428 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4429 lpszUrl += dwLen;
4432 /* all schemes are followed by at least a colon */
4433 *lpszUrl = ':';
4434 lpszUrl++;
4436 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4438 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4439 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4442 if (lpUrlComponents->lpszUserName)
4444 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4445 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4446 lpszUrl += dwLen;
4448 if (lpUrlComponents->lpszPassword)
4450 *lpszUrl = ':';
4451 lpszUrl++;
4453 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4454 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4455 lpszUrl += dwLen;
4458 *lpszUrl = '@';
4459 lpszUrl++;
4462 if (lpUrlComponents->lpszHostName)
4464 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4465 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4466 lpszUrl += dwLen;
4468 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4470 WCHAR szPort[MAX_WORD_DIGITS+1];
4472 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4473 *lpszUrl = ':';
4474 lpszUrl++;
4475 dwLen = strlenW(szPort);
4476 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4477 lpszUrl += dwLen;
4480 /* add slash between hostname and path if necessary */
4481 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4483 *lpszUrl = '/';
4484 lpszUrl++;
4488 if (lpUrlComponents->lpszUrlPath)
4490 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4491 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4492 lpszUrl += dwLen;
4495 if (lpUrlComponents->lpszExtraInfo)
4497 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4498 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4499 lpszUrl += dwLen;
4502 *lpszUrl = '\0';
4504 return TRUE;
4507 /***********************************************************************
4508 * InternetConfirmZoneCrossingA (WININET.@)
4511 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4513 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4514 return ERROR_SUCCESS;
4517 /***********************************************************************
4518 * InternetConfirmZoneCrossingW (WININET.@)
4521 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4523 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4524 return ERROR_SUCCESS;
4527 static DWORD zone_preference = 3;
4529 /***********************************************************************
4530 * PrivacySetZonePreferenceW (WININET.@)
4532 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4534 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4536 zone_preference = template;
4537 return 0;
4540 /***********************************************************************
4541 * PrivacyGetZonePreferenceW (WININET.@)
4543 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4544 LPWSTR preference, LPDWORD length )
4546 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4548 if (template) *template = zone_preference;
4549 return 0;
4552 /***********************************************************************
4553 * InternetGetSecurityInfoByURLA (WININET.@)
4555 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4557 WCHAR *url;
4558 BOOL res;
4560 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4562 url = heap_strdupAtoW(lpszURL);
4563 if(!url)
4564 return FALSE;
4566 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4567 heap_free(url);
4568 return res;
4571 /***********************************************************************
4572 * InternetGetSecurityInfoByURLW (WININET.@)
4574 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4576 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
4577 URL_COMPONENTSW url = {sizeof(url)};
4578 server_t *server;
4579 BOOL res = FALSE;
4581 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4583 url.lpszHostName = hostname;
4584 url.dwHostNameLength = sizeof(hostname)/sizeof(WCHAR);
4586 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4587 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4588 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4589 return FALSE;
4592 server = get_server(hostname, url.nPort, TRUE, FALSE);
4593 if(!server) {
4594 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4595 return FALSE;
4598 if(server->cert_chain) {
4599 const CERT_CHAIN_CONTEXT *chain_dup;
4601 chain_dup = CertDuplicateCertificateChain(server->cert_chain);
4602 if(chain_dup) {
4603 *ppCertChain = chain_dup;
4604 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4605 }else {
4606 res = FALSE;
4608 }else {
4609 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4610 res = FALSE;
4613 server_release(server);
4614 return res;
4617 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4618 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4620 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4621 lpdwConnection, dwReserved);
4622 return ERROR_SUCCESS;
4625 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4626 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4628 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4629 lpdwConnection, dwReserved);
4630 return ERROR_SUCCESS;
4633 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4635 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4636 return TRUE;
4639 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4641 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4642 return TRUE;
4645 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4647 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4648 return ERROR_SUCCESS;
4651 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4652 PBYTE pbHexHash )
4654 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4655 debugstr_w(pwszTarget), pbHexHash);
4656 return FALSE;
4659 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4661 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4662 return FALSE;
4665 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4667 FIXME("(%p, %08lx) stub\n", a, b);
4668 return FALSE;
4671 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4673 FIXME("%p: stub\n", parent);
4674 return 0;