wininet: Moved DllInstall to internet.c.
[wine/multimedia.git] / dlls / wininet / internet.c
blob2a2876c0909cd9fc65b65e484802e6ef7fb65b06
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "config.h"
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
33 #include <ws2tcpip.h>
34 #endif
36 #include <string.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
42 #endif
43 #ifdef HAVE_POLL_H
44 #include <poll.h>
45 #endif
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
48 #endif
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
51 #endif
52 #include <stdlib.h>
53 #include <ctype.h>
54 #ifdef HAVE_UNISTD_H
55 # include <unistd.h>
56 #endif
57 #include <assert.h>
59 #ifdef HAVE_CORESERVICES_CORESERVICES_H
60 #define GetCurrentThread MacGetCurrentThread
61 #define LoadResource MacLoadResource
62 #include <CoreServices/CoreServices.h>
63 #undef GetCurrentThread
64 #undef LoadResource
65 #undef DPRINTF
66 #endif
68 #include "windef.h"
69 #include "winbase.h"
70 #include "winreg.h"
71 #include "winuser.h"
72 #include "wininet.h"
73 #include "winnls.h"
74 #include "wine/debug.h"
75 #include "winerror.h"
76 #define NO_SHLWAPI_STREAM
77 #include "shlwapi.h"
79 #include "wine/exception.h"
81 #include "internet.h"
82 #include "resource.h"
84 #include "wine/unicode.h"
86 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
88 #define RESPONSE_TIMEOUT 30
90 typedef struct
92 DWORD dwError;
93 CHAR response[MAX_REPLY_LEN];
94 } WITHREADERROR, *LPWITHREADERROR;
96 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
97 HMODULE WININET_hModule;
99 static CRITICAL_SECTION WININET_cs;
100 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
102 0, 0, &WININET_cs,
103 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
104 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
106 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
108 static object_header_t **handle_table;
109 static UINT_PTR next_handle;
110 static UINT_PTR handle_table_size;
112 typedef struct
114 DWORD proxyEnabled;
115 LPWSTR proxy;
116 LPWSTR proxyBypass;
117 LPWSTR proxyUsername;
118 LPWSTR proxyPassword;
119 } proxyinfo_t;
121 static ULONG max_conns = 2, max_1_0_conns = 4;
122 static ULONG connect_timeout = 60000;
124 static const WCHAR szInternetSettings[] =
125 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
126 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
127 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
128 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
129 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
130 static const WCHAR szProxyOverride[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
132 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
134 UINT_PTR handle = 0, num;
135 object_header_t *ret;
136 object_header_t **p;
137 BOOL res = TRUE;
139 ret = heap_alloc_zero(size);
140 if(!ret)
141 return NULL;
143 list_init(&ret->children);
145 EnterCriticalSection( &WININET_cs );
147 if(!handle_table_size) {
148 num = 16;
149 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
150 if(p) {
151 handle_table = p;
152 handle_table_size = num;
153 next_handle = 1;
154 }else {
155 res = FALSE;
157 }else if(next_handle == handle_table_size) {
158 num = handle_table_size * 2;
159 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
160 if(p) {
161 handle_table = p;
162 handle_table_size = num;
163 }else {
164 res = FALSE;
168 if(res) {
169 handle = next_handle;
170 if(handle_table[handle])
171 ERR("handle isn't free but should be\n");
172 handle_table[handle] = ret;
173 ret->valid_handle = TRUE;
175 while(handle_table[next_handle] && next_handle < handle_table_size)
176 next_handle++;
179 LeaveCriticalSection( &WININET_cs );
181 if(!res) {
182 heap_free(ret);
183 return NULL;
186 ret->vtbl = vtbl;
187 ret->refs = 1;
188 ret->hInternet = (HINTERNET)handle;
190 if(parent) {
191 ret->lpfnStatusCB = parent->lpfnStatusCB;
192 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
195 return ret;
198 object_header_t *WININET_AddRef( object_header_t *info )
200 ULONG refs = InterlockedIncrement(&info->refs);
201 TRACE("%p -> refcount = %d\n", info, refs );
202 return info;
205 object_header_t *get_handle_object( HINTERNET hinternet )
207 object_header_t *info = NULL;
208 UINT_PTR handle = (UINT_PTR) hinternet;
210 EnterCriticalSection( &WININET_cs );
212 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
213 info = WININET_AddRef(handle_table[handle]);
215 LeaveCriticalSection( &WININET_cs );
217 TRACE("handle %ld -> %p\n", handle, info);
219 return info;
222 static void invalidate_handle(object_header_t *info)
224 object_header_t *child, *next;
226 if(!info->valid_handle)
227 return;
228 info->valid_handle = FALSE;
230 /* Free all children as native does */
231 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
233 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
234 invalidate_handle( child );
237 WININET_Release(info);
240 BOOL WININET_Release( object_header_t *info )
242 ULONG refs = InterlockedDecrement(&info->refs);
243 TRACE( "object %p refcount = %d\n", info, refs );
244 if( !refs )
246 invalidate_handle(info);
247 if ( info->vtbl->CloseConnection )
249 TRACE( "closing connection %p\n", info);
250 info->vtbl->CloseConnection( info );
252 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
253 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
254 || !(info->dwInternalFlags & INET_OPENURL))
256 INTERNET_SendCallback(info, info->dwContext,
257 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
258 sizeof(HINTERNET));
260 TRACE( "destroying object %p\n", info);
261 if ( info->htype != WH_HINIT )
262 list_remove( &info->entry );
263 info->vtbl->Destroy( info );
265 if(info->hInternet) {
266 UINT_PTR handle = (UINT_PTR)info->hInternet;
268 EnterCriticalSection( &WININET_cs );
270 handle_table[handle] = NULL;
271 if(next_handle > handle)
272 next_handle = handle;
274 LeaveCriticalSection( &WININET_cs );
277 heap_free(info);
279 return TRUE;
282 /***********************************************************************
283 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
285 * PARAMS
286 * hinstDLL [I] handle to the DLL's instance
287 * fdwReason [I]
288 * lpvReserved [I] reserved, must be NULL
290 * RETURNS
291 * Success: TRUE
292 * Failure: FALSE
295 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
297 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
299 switch (fdwReason) {
300 case DLL_PROCESS_ATTACH:
302 g_dwTlsErrIndex = TlsAlloc();
304 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
305 return FALSE;
307 if(!init_urlcache())
309 TlsFree(g_dwTlsErrIndex);
310 return FALSE;
313 WININET_hModule = hinstDLL;
314 break;
316 case DLL_THREAD_ATTACH:
317 break;
319 case DLL_THREAD_DETACH:
320 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
322 heap_free(TlsGetValue(g_dwTlsErrIndex));
324 break;
326 case DLL_PROCESS_DETACH:
327 if (lpvReserved) break;
328 collect_connections(COLLECT_CLEANUP);
329 NETCON_unload();
330 free_urlcache();
331 free_cookie();
333 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
335 heap_free(TlsGetValue(g_dwTlsErrIndex));
336 TlsFree(g_dwTlsErrIndex);
338 break;
340 return TRUE;
343 /***********************************************************************
344 * DllInstall (WININET.@)
346 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
348 FIXME("(%x %s): stub\n", bInstall, debugstr_w(cmdline));
349 return S_OK;
352 /***********************************************************************
353 * INTERNET_SaveProxySettings
355 * Stores the proxy settings given by lpwai into the registry
357 * RETURNS
358 * ERROR_SUCCESS if no error, or error code on fail
360 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
362 HKEY key;
363 LONG ret;
365 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
366 return ret;
368 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
370 RegCloseKey( key );
371 return ret;
374 if (lpwpi->proxy)
376 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
378 RegCloseKey( key );
379 return ret;
382 else
384 if ((ret = RegDeleteValueW( key, szProxyServer )))
386 RegCloseKey( key );
387 return ret;
391 RegCloseKey(key);
392 return ERROR_SUCCESS;
395 /***********************************************************************
396 * INTERNET_FindProxyForProtocol
398 * Searches the proxy string for a proxy of the given protocol.
399 * Returns the found proxy, or the default proxy if none of the given
400 * protocol is found.
402 * PARAMETERS
403 * szProxy [In] proxy string to search
404 * proto [In] protocol to search for, e.g. "http"
405 * foundProxy [Out] found proxy
406 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
408 * RETURNS
409 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
410 * *foundProxyLen is set to the required size in WCHARs, including the
411 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
413 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
415 LPCWSTR ptr;
416 BOOL ret = FALSE;
418 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
420 /* First, look for the specified protocol (proto=scheme://host:port) */
421 for (ptr = szProxy; !ret && ptr && *ptr; )
423 LPCWSTR end, equal;
425 if (!(end = strchrW(ptr, ' ')))
426 end = ptr + strlenW(ptr);
427 if ((equal = strchrW(ptr, '=')) && equal < end &&
428 equal - ptr == strlenW(proto) &&
429 !strncmpiW(proto, ptr, strlenW(proto)))
431 if (end - equal > *foundProxyLen)
433 WARN("buffer too short for %s\n",
434 debugstr_wn(equal + 1, end - equal - 1));
435 *foundProxyLen = end - equal;
436 SetLastError(ERROR_INSUFFICIENT_BUFFER);
438 else
440 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
441 foundProxy[end - equal] = 0;
442 ret = TRUE;
445 if (*end == ' ')
446 ptr = end + 1;
447 else
448 ptr = end;
450 if (!ret)
452 /* It wasn't found: look for no protocol */
453 for (ptr = szProxy; !ret && ptr && *ptr; )
455 LPCWSTR end;
457 if (!(end = strchrW(ptr, ' ')))
458 end = ptr + strlenW(ptr);
459 if (!strchrW(ptr, '='))
461 if (end - ptr + 1 > *foundProxyLen)
463 WARN("buffer too short for %s\n",
464 debugstr_wn(ptr, end - ptr));
465 *foundProxyLen = end - ptr + 1;
466 SetLastError(ERROR_INSUFFICIENT_BUFFER);
468 else
470 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
471 foundProxy[end - ptr] = 0;
472 ret = TRUE;
475 if (*end == ' ')
476 ptr = end + 1;
477 else
478 ptr = end;
481 if (ret)
482 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
483 debugstr_w(foundProxy));
484 return ret;
487 /***********************************************************************
488 * InternetInitializeAutoProxyDll (WININET.@)
490 * Setup the internal proxy
492 * PARAMETERS
493 * dwReserved
495 * RETURNS
496 * FALSE on failure
499 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
501 FIXME("STUB\n");
502 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
503 return FALSE;
506 /***********************************************************************
507 * DetectAutoProxyUrl (WININET.@)
509 * Auto detect the proxy url
511 * RETURNS
512 * FALSE on failure
515 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
516 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
518 FIXME("STUB\n");
519 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
520 return FALSE;
523 static void FreeProxyInfo( proxyinfo_t *lpwpi )
525 heap_free(lpwpi->proxy);
526 heap_free(lpwpi->proxyBypass);
527 heap_free(lpwpi->proxyUsername);
528 heap_free(lpwpi->proxyPassword);
531 static proxyinfo_t *global_proxy;
533 static void free_global_proxy( void )
535 EnterCriticalSection( &WININET_cs );
536 if (global_proxy)
538 FreeProxyInfo( global_proxy );
539 heap_free( global_proxy );
541 LeaveCriticalSection( &WININET_cs );
544 static BOOL parse_proxy_url( proxyinfo_t *info, const WCHAR *url )
546 static const WCHAR fmt[] = {'%','s',':','%','u',0};
547 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH] = {};
548 WCHAR username[INTERNET_MAX_USER_NAME_LENGTH] = {};
549 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH] = {};
550 URL_COMPONENTSW uc;
552 memset( &uc, 0, sizeof(uc) );
553 uc.dwStructSize = sizeof(uc);
554 uc.lpszHostName = hostname;
555 uc.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
556 uc.lpszUserName = username;
557 uc.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
558 uc.lpszPassword = password;
559 uc.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
561 if (!InternetCrackUrlW( url, 0, 0, &uc )) return FALSE;
562 if (!hostname[0])
564 if (!(info->proxy = heap_strdupW( url ))) return FALSE;
565 info->proxyUsername = NULL;
566 info->proxyPassword = NULL;
567 return TRUE;
569 if (!(info->proxy = heap_alloc( (strlenW(hostname) + 12) * sizeof(WCHAR) ))) return FALSE;
570 sprintfW( info->proxy, fmt, hostname, uc.nPort );
572 if (!username[0]) info->proxyUsername = NULL;
573 else if (!(info->proxyUsername = heap_strdupW( username )))
575 heap_free( info->proxy );
576 return FALSE;
578 if (!password[0]) info->proxyPassword = NULL;
579 else if (!(info->proxyPassword = heap_strdupW( password )))
581 heap_free( info->proxyUsername );
582 heap_free( info->proxy );
583 return FALSE;
585 return TRUE;
588 /***********************************************************************
589 * INTERNET_LoadProxySettings
591 * Loads proxy information from process-wide global settings, the registry,
592 * or the environment into lpwpi.
594 * The caller should call FreeProxyInfo when done with lpwpi.
596 * FIXME:
597 * The proxy may be specified in the form 'http=proxy.my.org'
598 * Presumably that means there can be ftp=ftpproxy.my.org too.
600 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
602 HKEY key;
603 DWORD type, len;
604 LPCSTR envproxy;
605 LONG ret;
607 memset( lpwpi, 0, sizeof(*lpwpi) );
609 EnterCriticalSection( &WININET_cs );
610 if (global_proxy)
612 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
613 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
614 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
616 LeaveCriticalSection( &WININET_cs );
618 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
620 FreeProxyInfo( lpwpi );
621 return ret;
624 len = sizeof(DWORD);
625 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
627 lpwpi->proxyEnabled = 0;
628 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
630 FreeProxyInfo( lpwpi );
631 RegCloseKey( key );
632 return ret;
636 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->proxyEnabled)
638 /* figure out how much memory the proxy setting takes */
639 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
641 LPWSTR szProxy, p;
642 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
644 if (!(szProxy = heap_alloc(len)))
646 RegCloseKey( key );
647 FreeProxyInfo( lpwpi );
648 return ERROR_OUTOFMEMORY;
650 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
652 /* find the http proxy, and strip away everything else */
653 p = strstrW( szProxy, szHttp );
654 if (p)
656 p += lstrlenW( szHttp );
657 lstrcpyW( szProxy, p );
659 p = strchrW( szProxy, ';' );
660 if (p) *p = 0;
662 FreeProxyInfo( lpwpi );
663 lpwpi->proxy = szProxy;
664 lpwpi->proxyBypass = NULL;
666 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi->proxy));
668 else
670 TRACE("No proxy server settings in registry.\n");
671 FreeProxyInfo( lpwpi );
672 lpwpi->proxy = NULL;
673 lpwpi->proxyBypass = NULL;
676 else if (envproxy)
678 WCHAR *envproxyW;
680 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
681 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
683 RegCloseKey( key );
684 return ERROR_OUTOFMEMORY;
686 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
688 FreeProxyInfo( lpwpi );
689 if (parse_proxy_url( lpwpi, envproxyW ))
691 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
692 lpwpi->proxyEnabled = 1;
693 lpwpi->proxyBypass = NULL;
695 else
697 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW));
698 lpwpi->proxyEnabled = 0;
699 lpwpi->proxy = NULL;
700 lpwpi->proxyBypass = NULL;
702 heap_free( envproxyW );
705 if (lpwpi->proxyEnabled)
707 TRACE("Proxy is enabled.\n");
709 if (!(envproxy = getenv( "no_proxy" )))
711 /* figure out how much memory the proxy setting takes */
712 if (!RegQueryValueExW( key, szProxyOverride, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
714 LPWSTR szProxy;
716 if (!(szProxy = heap_alloc(len)))
718 RegCloseKey( key );
719 return ERROR_OUTOFMEMORY;
721 RegQueryValueExW( key, szProxyOverride, NULL, &type, (BYTE*)szProxy, &len );
723 heap_free( lpwpi->proxyBypass );
724 lpwpi->proxyBypass = szProxy;
726 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi->proxyBypass));
728 else
730 heap_free( lpwpi->proxyBypass );
731 lpwpi->proxyBypass = NULL;
733 TRACE("No proxy bypass server settings in registry.\n");
736 else
738 WCHAR *envproxyW;
740 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
741 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
743 RegCloseKey( key );
744 return ERROR_OUTOFMEMORY;
746 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
748 heap_free( lpwpi->proxyBypass );
749 lpwpi->proxyBypass = envproxyW;
751 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
754 else TRACE("Proxy is disabled.\n");
756 RegCloseKey( key );
757 return ERROR_SUCCESS;
760 /***********************************************************************
761 * INTERNET_ConfigureProxy
763 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
765 proxyinfo_t wpi;
767 if (INTERNET_LoadProxySettings( &wpi ))
768 return FALSE;
770 if (wpi.proxyEnabled)
772 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai->proxy), debugstr_w(lpwai->proxyBypass));
774 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
775 lpwai->proxy = wpi.proxy;
776 lpwai->proxyBypass = wpi.proxyBypass;
777 lpwai->proxyUsername = wpi.proxyUsername;
778 lpwai->proxyPassword = wpi.proxyPassword;
779 return TRUE;
782 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
783 FreeProxyInfo(&wpi);
784 return FALSE;
787 /***********************************************************************
788 * dump_INTERNET_FLAGS
790 * Helper function to TRACE the internet flags.
792 * RETURNS
793 * None
796 static void dump_INTERNET_FLAGS(DWORD dwFlags)
798 #define FE(x) { x, #x }
799 static const wininet_flag_info flag[] = {
800 FE(INTERNET_FLAG_RELOAD),
801 FE(INTERNET_FLAG_RAW_DATA),
802 FE(INTERNET_FLAG_EXISTING_CONNECT),
803 FE(INTERNET_FLAG_ASYNC),
804 FE(INTERNET_FLAG_PASSIVE),
805 FE(INTERNET_FLAG_NO_CACHE_WRITE),
806 FE(INTERNET_FLAG_MAKE_PERSISTENT),
807 FE(INTERNET_FLAG_FROM_CACHE),
808 FE(INTERNET_FLAG_SECURE),
809 FE(INTERNET_FLAG_KEEP_CONNECTION),
810 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
811 FE(INTERNET_FLAG_READ_PREFETCH),
812 FE(INTERNET_FLAG_NO_COOKIES),
813 FE(INTERNET_FLAG_NO_AUTH),
814 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
815 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
816 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
817 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
818 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
819 FE(INTERNET_FLAG_RESYNCHRONIZE),
820 FE(INTERNET_FLAG_HYPERLINK),
821 FE(INTERNET_FLAG_NO_UI),
822 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
823 FE(INTERNET_FLAG_CACHE_ASYNC),
824 FE(INTERNET_FLAG_FORMS_SUBMIT),
825 FE(INTERNET_FLAG_NEED_FILE),
826 FE(INTERNET_FLAG_TRANSFER_ASCII),
827 FE(INTERNET_FLAG_TRANSFER_BINARY)
829 #undef FE
830 unsigned int i;
832 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
833 if (flag[i].val & dwFlags) {
834 TRACE(" %s", flag[i].name);
835 dwFlags &= ~flag[i].val;
838 if (dwFlags)
839 TRACE(" Unknown flags (%08x)\n", dwFlags);
840 else
841 TRACE("\n");
844 /***********************************************************************
845 * INTERNET_CloseHandle (internal)
847 * Close internet handle
850 static VOID APPINFO_Destroy(object_header_t *hdr)
852 appinfo_t *lpwai = (appinfo_t*)hdr;
854 TRACE("%p\n",lpwai);
856 heap_free(lpwai->agent);
857 heap_free(lpwai->proxy);
858 heap_free(lpwai->proxyBypass);
859 heap_free(lpwai->proxyUsername);
860 heap_free(lpwai->proxyPassword);
863 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
865 appinfo_t *ai = (appinfo_t*)hdr;
867 switch(option) {
868 case INTERNET_OPTION_HANDLE_TYPE:
869 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
871 if (*size < sizeof(ULONG))
872 return ERROR_INSUFFICIENT_BUFFER;
874 *size = sizeof(DWORD);
875 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
876 return ERROR_SUCCESS;
878 case INTERNET_OPTION_USER_AGENT: {
879 DWORD bufsize;
881 TRACE("INTERNET_OPTION_USER_AGENT\n");
883 bufsize = *size;
885 if (unicode) {
886 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
888 *size = (len + 1) * sizeof(WCHAR);
889 if(!buffer || bufsize < *size)
890 return ERROR_INSUFFICIENT_BUFFER;
892 if (ai->agent)
893 strcpyW(buffer, ai->agent);
894 else
895 *(WCHAR *)buffer = 0;
896 /* If the buffer is copied, the returned length doesn't include
897 * the NULL terminator.
899 *size = len;
900 }else {
901 if (ai->agent)
902 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
903 else
904 *size = 1;
905 if(!buffer || bufsize < *size)
906 return ERROR_INSUFFICIENT_BUFFER;
908 if (ai->agent)
909 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
910 else
911 *(char *)buffer = 0;
912 /* If the buffer is copied, the returned length doesn't include
913 * the NULL terminator.
915 *size -= 1;
918 return ERROR_SUCCESS;
921 case INTERNET_OPTION_PROXY:
922 if(!size) return ERROR_INVALID_PARAMETER;
923 if (unicode) {
924 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
925 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
926 LPWSTR proxy, proxy_bypass;
928 if (ai->proxy)
929 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
930 if (ai->proxyBypass)
931 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
932 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
934 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
935 return ERROR_INSUFFICIENT_BUFFER;
937 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
938 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
940 pi->dwAccessType = ai->accessType;
941 pi->lpszProxy = NULL;
942 pi->lpszProxyBypass = NULL;
943 if (ai->proxy) {
944 lstrcpyW(proxy, ai->proxy);
945 pi->lpszProxy = proxy;
948 if (ai->proxyBypass) {
949 lstrcpyW(proxy_bypass, ai->proxyBypass);
950 pi->lpszProxyBypass = proxy_bypass;
953 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
954 return ERROR_SUCCESS;
955 }else {
956 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
957 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
958 LPSTR proxy, proxy_bypass;
960 if (ai->proxy)
961 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
962 if (ai->proxyBypass)
963 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
964 NULL, 0, NULL, NULL);
965 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
967 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
968 return ERROR_INSUFFICIENT_BUFFER;
970 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
971 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
973 pi->dwAccessType = ai->accessType;
974 pi->lpszProxy = NULL;
975 pi->lpszProxyBypass = NULL;
976 if (ai->proxy) {
977 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
978 pi->lpszProxy = proxy;
981 if (ai->proxyBypass) {
982 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
983 proxyBypassBytesRequired, NULL, NULL);
984 pi->lpszProxyBypass = proxy_bypass;
987 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
988 return ERROR_SUCCESS;
991 case INTERNET_OPTION_CONNECT_TIMEOUT:
992 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
994 if (*size < sizeof(ULONG))
995 return ERROR_INSUFFICIENT_BUFFER;
997 *(ULONG*)buffer = ai->connect_timeout;
998 *size = sizeof(ULONG);
1000 return ERROR_SUCCESS;
1003 return INET_QueryOption(hdr, option, buffer, size, unicode);
1006 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
1008 appinfo_t *ai = (appinfo_t*)hdr;
1010 switch(option) {
1011 case INTERNET_OPTION_CONNECT_TIMEOUT:
1012 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
1014 if(size != sizeof(connect_timeout))
1015 return ERROR_INTERNET_BAD_OPTION_LENGTH;
1016 if(!*(ULONG*)buf)
1017 return ERROR_BAD_ARGUMENTS;
1019 ai->connect_timeout = *(ULONG*)buf;
1020 return ERROR_SUCCESS;
1021 case INTERNET_OPTION_USER_AGENT:
1022 heap_free(ai->agent);
1023 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
1024 return ERROR_SUCCESS;
1027 return INET_SetOption(hdr, option, buf, size);
1030 static const object_vtbl_t APPINFOVtbl = {
1031 APPINFO_Destroy,
1032 NULL,
1033 APPINFO_QueryOption,
1034 APPINFO_SetOption,
1035 NULL,
1036 NULL,
1037 NULL,
1038 NULL
1042 /***********************************************************************
1043 * InternetOpenW (WININET.@)
1045 * Per-application initialization of wininet
1047 * RETURNS
1048 * HINTERNET on success
1049 * NULL on failure
1052 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
1053 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
1055 appinfo_t *lpwai = NULL;
1057 if (TRACE_ON(wininet)) {
1058 #define FE(x) { x, #x }
1059 static const wininet_flag_info access_type[] = {
1060 FE(INTERNET_OPEN_TYPE_PRECONFIG),
1061 FE(INTERNET_OPEN_TYPE_DIRECT),
1062 FE(INTERNET_OPEN_TYPE_PROXY),
1063 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
1065 #undef FE
1066 DWORD i;
1067 const char *access_type_str = "Unknown";
1069 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
1070 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
1071 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
1072 if (access_type[i].val == dwAccessType) {
1073 access_type_str = access_type[i].name;
1074 break;
1077 TRACE(" access type : %s\n", access_type_str);
1078 TRACE(" flags :");
1079 dump_INTERNET_FLAGS(dwFlags);
1082 /* Clear any error information */
1083 INTERNET_SetLastError(0);
1085 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1086 SetLastError(ERROR_INVALID_PARAMETER);
1087 return NULL;
1090 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1091 if (!lpwai) {
1092 SetLastError(ERROR_OUTOFMEMORY);
1093 return NULL;
1096 lpwai->hdr.htype = WH_HINIT;
1097 lpwai->hdr.dwFlags = dwFlags;
1098 lpwai->accessType = dwAccessType;
1099 lpwai->proxyUsername = NULL;
1100 lpwai->proxyPassword = NULL;
1101 lpwai->connect_timeout = connect_timeout;
1103 lpwai->agent = heap_strdupW(lpszAgent);
1104 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1105 INTERNET_ConfigureProxy( lpwai );
1106 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1107 lpwai->proxy = heap_strdupW(lpszProxy);
1108 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1111 TRACE("returning %p\n", lpwai);
1113 return lpwai->hdr.hInternet;
1117 /***********************************************************************
1118 * InternetOpenA (WININET.@)
1120 * Per-application initialization of wininet
1122 * RETURNS
1123 * HINTERNET on success
1124 * NULL on failure
1127 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1128 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1130 WCHAR *szAgent, *szProxy, *szBypass;
1131 HINTERNET rc;
1133 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1134 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1136 szAgent = heap_strdupAtoW(lpszAgent);
1137 szProxy = heap_strdupAtoW(lpszProxy);
1138 szBypass = heap_strdupAtoW(lpszProxyBypass);
1140 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1142 heap_free(szAgent);
1143 heap_free(szProxy);
1144 heap_free(szBypass);
1145 return rc;
1148 /***********************************************************************
1149 * InternetGetLastResponseInfoA (WININET.@)
1151 * Return last wininet error description on the calling thread
1153 * RETURNS
1154 * TRUE on success of writing to buffer
1155 * FALSE on failure
1158 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1159 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1161 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1163 TRACE("\n");
1165 if (lpwite)
1167 *lpdwError = lpwite->dwError;
1168 if (lpwite->dwError)
1170 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1171 *lpdwBufferLength = strlen(lpszBuffer);
1173 else
1174 *lpdwBufferLength = 0;
1176 else
1178 *lpdwError = 0;
1179 *lpdwBufferLength = 0;
1182 return TRUE;
1185 /***********************************************************************
1186 * InternetGetLastResponseInfoW (WININET.@)
1188 * Return last wininet error description on the calling thread
1190 * RETURNS
1191 * TRUE on success of writing to buffer
1192 * FALSE on failure
1195 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1196 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1198 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1200 TRACE("\n");
1202 if (lpwite)
1204 *lpdwError = lpwite->dwError;
1205 if (lpwite->dwError)
1207 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1208 *lpdwBufferLength = lstrlenW(lpszBuffer);
1210 else
1211 *lpdwBufferLength = 0;
1213 else
1215 *lpdwError = 0;
1216 *lpdwBufferLength = 0;
1219 return TRUE;
1222 /***********************************************************************
1223 * InternetGetConnectedState (WININET.@)
1225 * Return connected state
1227 * RETURNS
1228 * TRUE if connected
1229 * if lpdwStatus is not null, return the status (off line,
1230 * modem, lan...) in it.
1231 * FALSE if not connected
1233 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1235 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1237 if (lpdwStatus) {
1238 WARN("always returning LAN connection.\n");
1239 *lpdwStatus = INTERNET_CONNECTION_LAN;
1241 return TRUE;
1245 /***********************************************************************
1246 * InternetGetConnectedStateExW (WININET.@)
1248 * Return connected state
1250 * PARAMS
1252 * lpdwStatus [O] Flags specifying the status of the internet connection.
1253 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1254 * dwNameLen [I] Size of the buffer, in characters.
1255 * dwReserved [I] Reserved. Must be set to 0.
1257 * RETURNS
1258 * TRUE if connected
1259 * if lpdwStatus is not null, return the status (off line,
1260 * modem, lan...) in it.
1261 * FALSE if not connected
1263 * NOTES
1264 * If the system has no available network connections, an empty string is
1265 * stored in lpszConnectionName. If there is a LAN connection, a localized
1266 * "LAN Connection" string is stored. Presumably, if only a dial-up
1267 * connection is available then the name of the dial-up connection is
1268 * returned. Why any application, other than the "Internet Settings" CPL,
1269 * would want to use this function instead of the simpler InternetGetConnectedStateW
1270 * function is beyond me.
1272 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1273 DWORD dwNameLen, DWORD dwReserved)
1275 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1277 /* Must be zero */
1278 if(dwReserved)
1279 return FALSE;
1281 if (lpdwStatus) {
1282 WARN("always returning LAN connection.\n");
1283 *lpdwStatus = INTERNET_CONNECTION_LAN;
1285 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen) > 0;
1289 /***********************************************************************
1290 * InternetGetConnectedStateExA (WININET.@)
1292 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1293 DWORD dwNameLen, DWORD dwReserved)
1295 LPWSTR lpwszConnectionName = NULL;
1296 BOOL rc;
1298 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1300 if (lpszConnectionName && dwNameLen > 0)
1301 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1303 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1304 dwReserved);
1305 if (rc && lpwszConnectionName)
1306 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1307 dwNameLen, NULL, NULL);
1309 heap_free(lpwszConnectionName);
1310 return rc;
1314 /***********************************************************************
1315 * InternetConnectW (WININET.@)
1317 * Open a ftp, gopher or http session
1319 * RETURNS
1320 * HINTERNET a session handle on success
1321 * NULL on failure
1324 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1325 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1326 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1327 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1329 appinfo_t *hIC;
1330 HINTERNET rc = NULL;
1331 DWORD res = ERROR_SUCCESS;
1333 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1334 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1335 dwService, dwFlags, dwContext);
1337 if (!lpszServerName)
1339 SetLastError(ERROR_INVALID_PARAMETER);
1340 return NULL;
1343 hIC = (appinfo_t*)get_handle_object( hInternet );
1344 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1346 res = ERROR_INVALID_HANDLE;
1347 goto lend;
1350 switch (dwService)
1352 case INTERNET_SERVICE_FTP:
1353 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1354 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1355 if(!rc)
1356 res = INTERNET_GetLastError();
1357 break;
1359 case INTERNET_SERVICE_HTTP:
1360 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1361 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1362 break;
1364 case INTERNET_SERVICE_GOPHER:
1365 default:
1366 break;
1368 lend:
1369 if( hIC )
1370 WININET_Release( &hIC->hdr );
1372 TRACE("returning %p\n", rc);
1373 SetLastError(res);
1374 return rc;
1378 /***********************************************************************
1379 * InternetConnectA (WININET.@)
1381 * Open a ftp, gopher or http session
1383 * RETURNS
1384 * HINTERNET a session handle on success
1385 * NULL on failure
1388 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1389 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1390 LPCSTR lpszUserName, LPCSTR lpszPassword,
1391 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1393 HINTERNET rc = NULL;
1394 LPWSTR szServerName;
1395 LPWSTR szUserName;
1396 LPWSTR szPassword;
1398 szServerName = heap_strdupAtoW(lpszServerName);
1399 szUserName = heap_strdupAtoW(lpszUserName);
1400 szPassword = heap_strdupAtoW(lpszPassword);
1402 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1403 szUserName, szPassword, dwService, dwFlags, dwContext);
1405 heap_free(szServerName);
1406 heap_free(szUserName);
1407 heap_free(szPassword);
1408 return rc;
1412 /***********************************************************************
1413 * InternetFindNextFileA (WININET.@)
1415 * Continues a file search from a previous call to FindFirstFile
1417 * RETURNS
1418 * TRUE on success
1419 * FALSE on failure
1422 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1424 BOOL ret;
1425 WIN32_FIND_DATAW fd;
1427 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1428 if(lpvFindData)
1429 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1430 return ret;
1433 /***********************************************************************
1434 * InternetFindNextFileW (WININET.@)
1436 * Continues a file search from a previous call to FindFirstFile
1438 * RETURNS
1439 * TRUE on success
1440 * FALSE on failure
1443 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1445 object_header_t *hdr;
1446 DWORD res;
1448 TRACE("\n");
1450 hdr = get_handle_object(hFind);
1451 if(!hdr) {
1452 WARN("Invalid handle\n");
1453 SetLastError(ERROR_INVALID_HANDLE);
1454 return FALSE;
1457 if(hdr->vtbl->FindNextFileW) {
1458 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1459 }else {
1460 WARN("Handle doesn't support NextFile\n");
1461 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1464 WININET_Release(hdr);
1466 if(res != ERROR_SUCCESS)
1467 SetLastError(res);
1468 return res == ERROR_SUCCESS;
1471 /***********************************************************************
1472 * InternetCloseHandle (WININET.@)
1474 * Generic close handle function
1476 * RETURNS
1477 * TRUE on success
1478 * FALSE on failure
1481 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1483 object_header_t *obj;
1485 TRACE("%p\n", hInternet);
1487 obj = get_handle_object( hInternet );
1488 if (!obj) {
1489 SetLastError(ERROR_INVALID_HANDLE);
1490 return FALSE;
1493 invalidate_handle(obj);
1494 WININET_Release(obj);
1496 return TRUE;
1500 /***********************************************************************
1501 * ConvertUrlComponentValue (Internal)
1503 * Helper function for InternetCrackUrlA
1506 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1507 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1508 LPCSTR lpszStart, LPCWSTR lpwszStart)
1510 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1511 if (*dwComponentLen != 0)
1513 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1514 if (*lppszComponent == NULL)
1516 if (lpwszComponent)
1518 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1519 *lppszComponent = (LPSTR)lpszStart + offset;
1521 else
1522 *lppszComponent = NULL;
1524 *dwComponentLen = nASCIILength;
1526 else
1528 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1529 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1530 (*lppszComponent)[ncpylen]=0;
1531 *dwComponentLen = ncpylen;
1537 /***********************************************************************
1538 * InternetCrackUrlA (WININET.@)
1540 * See InternetCrackUrlW.
1542 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1543 LPURL_COMPONENTSA lpUrlComponents)
1545 DWORD nLength;
1546 URL_COMPONENTSW UCW;
1547 BOOL ret = FALSE;
1548 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1549 *scheme = NULL, *extra = NULL;
1551 TRACE("(%s %u %x %p)\n",
1552 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1553 dwUrlLength, dwFlags, lpUrlComponents);
1555 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1556 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1558 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1559 return FALSE;
1562 if(dwUrlLength<=0)
1563 dwUrlLength=-1;
1564 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1566 /* if dwUrlLength=-1 then nLength includes null but length to
1567 InternetCrackUrlW should not include it */
1568 if (dwUrlLength == -1) nLength--;
1570 lpwszUrl = heap_alloc((nLength + 1) * sizeof(WCHAR));
1571 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1572 lpwszUrl[nLength] = '\0';
1574 memset(&UCW,0,sizeof(UCW));
1575 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1576 if (lpUrlComponents->dwHostNameLength)
1578 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1579 if (lpUrlComponents->lpszHostName)
1581 hostname = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1582 UCW.lpszHostName = hostname;
1585 if (lpUrlComponents->dwUserNameLength)
1587 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1588 if (lpUrlComponents->lpszUserName)
1590 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1591 UCW.lpszUserName = username;
1594 if (lpUrlComponents->dwPasswordLength)
1596 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1597 if (lpUrlComponents->lpszPassword)
1599 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1600 UCW.lpszPassword = password;
1603 if (lpUrlComponents->dwUrlPathLength)
1605 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1606 if (lpUrlComponents->lpszUrlPath)
1608 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1609 UCW.lpszUrlPath = path;
1612 if (lpUrlComponents->dwSchemeLength)
1614 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1615 if (lpUrlComponents->lpszScheme)
1617 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1618 UCW.lpszScheme = scheme;
1621 if (lpUrlComponents->dwExtraInfoLength)
1623 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1624 if (lpUrlComponents->lpszExtraInfo)
1626 extra = heap_alloc(UCW.dwExtraInfoLength * sizeof(WCHAR));
1627 UCW.lpszExtraInfo = extra;
1630 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1632 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1633 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1634 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1635 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1636 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1637 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1638 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1639 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1640 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1641 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1642 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1643 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1645 lpUrlComponents->nScheme = UCW.nScheme;
1646 lpUrlComponents->nPort = UCW.nPort;
1648 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1649 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1650 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1651 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1652 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1654 heap_free(lpwszUrl);
1655 heap_free(hostname);
1656 heap_free(username);
1657 heap_free(password);
1658 heap_free(path);
1659 heap_free(scheme);
1660 heap_free(extra);
1661 return ret;
1664 static const WCHAR url_schemes[][7] =
1666 {'f','t','p',0},
1667 {'g','o','p','h','e','r',0},
1668 {'h','t','t','p',0},
1669 {'h','t','t','p','s',0},
1670 {'f','i','l','e',0},
1671 {'n','e','w','s',0},
1672 {'m','a','i','l','t','o',0},
1673 {'r','e','s',0},
1676 /***********************************************************************
1677 * GetInternetSchemeW (internal)
1679 * Get scheme of url
1681 * RETURNS
1682 * scheme on success
1683 * INTERNET_SCHEME_UNKNOWN on failure
1686 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1688 int i;
1690 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1692 if(lpszScheme==NULL)
1693 return INTERNET_SCHEME_UNKNOWN;
1695 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1696 if (!strncmpiW(lpszScheme, url_schemes[i], nMaxCmp))
1697 return INTERNET_SCHEME_FIRST + i;
1699 return INTERNET_SCHEME_UNKNOWN;
1702 /***********************************************************************
1703 * SetUrlComponentValueW (Internal)
1705 * Helper function for InternetCrackUrlW
1707 * PARAMS
1708 * lppszComponent [O] Holds the returned string
1709 * dwComponentLen [I] Holds the size of lppszComponent
1710 * [O] Holds the length of the string in lppszComponent without '\0'
1711 * lpszStart [I] Holds the string to copy from
1712 * len [I] Holds the length of lpszStart without '\0'
1714 * RETURNS
1715 * TRUE on success
1716 * FALSE on failure
1719 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1721 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1723 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1724 return FALSE;
1726 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1728 if (*lppszComponent == NULL)
1730 *lppszComponent = (LPWSTR)lpszStart;
1731 *dwComponentLen = len;
1733 else
1735 DWORD ncpylen = min((*dwComponentLen)-1, len);
1736 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1737 (*lppszComponent)[ncpylen] = '\0';
1738 *dwComponentLen = ncpylen;
1742 return TRUE;
1745 /***********************************************************************
1746 * InternetCrackUrlW (WININET.@)
1748 * Break up URL into its components
1750 * RETURNS
1751 * TRUE on success
1752 * FALSE on failure
1754 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1755 LPURL_COMPONENTSW lpUC)
1758 * RFC 1808
1759 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1762 LPCWSTR lpszParam = NULL;
1763 BOOL found_colon = FALSE;
1764 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1765 LPCWSTR lpszcp = NULL, lpszNetLoc;
1766 LPWSTR lpszUrl_decode = NULL;
1767 DWORD dwUrlLength = dwUrlLength_orig;
1769 TRACE("(%s %u %x %p)\n",
1770 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1771 dwUrlLength, dwFlags, lpUC);
1773 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1775 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1776 return FALSE;
1778 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1780 if (dwFlags & ICU_DECODE)
1782 WCHAR *url_tmp;
1783 DWORD len = dwUrlLength + 1;
1785 if (!(url_tmp = heap_alloc(len * sizeof(WCHAR))))
1787 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1788 return FALSE;
1790 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1791 url_tmp[dwUrlLength] = 0;
1792 if (!(lpszUrl_decode = heap_alloc(len * sizeof(WCHAR))))
1794 heap_free(url_tmp);
1795 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1796 return FALSE;
1798 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1800 dwUrlLength = len;
1801 lpszUrl = lpszUrl_decode;
1803 heap_free(url_tmp);
1805 lpszap = lpszUrl;
1807 /* Determine if the URI is absolute. */
1808 while (lpszap - lpszUrl < dwUrlLength)
1810 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1812 lpszap++;
1813 continue;
1815 if (*lpszap == ':')
1817 found_colon = TRUE;
1818 lpszcp = lpszap;
1820 else
1822 lpszcp = lpszUrl; /* Relative url */
1825 break;
1828 if(!found_colon){
1829 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1830 return FALSE;
1833 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1834 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1836 /* Parse <params> */
1837 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1838 if(!lpszParam)
1839 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1841 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1842 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1845 /* Get scheme first. */
1846 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1847 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1848 lpszUrl, lpszcp - lpszUrl);
1850 /* Eat ':' in protocol. */
1851 lpszcp++;
1853 /* double slash indicates the net_loc portion is present */
1854 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1856 lpszcp += 2;
1858 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1859 if (lpszParam)
1861 if (lpszNetLoc)
1862 lpszNetLoc = min(lpszNetLoc, lpszParam);
1863 else
1864 lpszNetLoc = lpszParam;
1866 else if (!lpszNetLoc)
1867 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1869 /* Parse net-loc */
1870 if (lpszNetLoc)
1872 LPCWSTR lpszHost;
1873 LPCWSTR lpszPort;
1875 /* [<user>[<:password>]@]<host>[:<port>] */
1876 /* First find the user and password if they exist */
1878 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1879 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1881 /* username and password not specified. */
1882 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1883 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1885 else /* Parse out username and password */
1887 LPCWSTR lpszUser = lpszcp;
1888 LPCWSTR lpszPasswd = lpszHost;
1890 while (lpszcp < lpszHost)
1892 if (*lpszcp == ':')
1893 lpszPasswd = lpszcp;
1895 lpszcp++;
1898 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1899 lpszUser, lpszPasswd - lpszUser);
1901 if (lpszPasswd != lpszHost)
1902 lpszPasswd++;
1903 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1904 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1905 lpszHost - lpszPasswd);
1907 lpszcp++; /* Advance to beginning of host */
1910 /* Parse <host><:port> */
1912 lpszHost = lpszcp;
1913 lpszPort = lpszNetLoc;
1915 /* special case for res:// URLs: there is no port here, so the host is the
1916 entire string up to the first '/' */
1917 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1919 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1920 lpszHost, lpszPort - lpszHost);
1921 lpszcp=lpszNetLoc;
1923 else
1925 while (lpszcp < lpszNetLoc)
1927 if (*lpszcp == ':')
1928 lpszPort = lpszcp;
1930 lpszcp++;
1933 /* If the scheme is "file" and the host is just one letter, it's not a host */
1934 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1936 lpszcp=lpszHost;
1937 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1938 NULL, 0);
1940 else
1942 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1943 lpszHost, lpszPort - lpszHost);
1944 if (lpszPort != lpszNetLoc)
1945 lpUC->nPort = atoiW(++lpszPort);
1946 else switch (lpUC->nScheme)
1948 case INTERNET_SCHEME_HTTP:
1949 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1950 break;
1951 case INTERNET_SCHEME_HTTPS:
1952 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1953 break;
1954 case INTERNET_SCHEME_FTP:
1955 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1956 break;
1957 case INTERNET_SCHEME_GOPHER:
1958 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1959 break;
1960 default:
1961 break;
1967 else
1969 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1970 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1971 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1974 /* Here lpszcp points to:
1976 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1977 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1979 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1981 DWORD len;
1983 /* Only truncate the parameter list if it's already been saved
1984 * in lpUC->lpszExtraInfo.
1986 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1987 len = lpszParam - lpszcp;
1988 else
1990 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1991 * newlines if necessary.
1993 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1994 if (lpsznewline != NULL)
1995 len = lpsznewline - lpszcp;
1996 else
1997 len = dwUrlLength-(lpszcp-lpszUrl);
1999 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
2000 lpUC->nScheme == INTERNET_SCHEME_FILE)
2002 WCHAR tmppath[MAX_PATH];
2003 if (*lpszcp == '/')
2005 len = MAX_PATH;
2006 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
2008 else
2010 WCHAR *iter;
2011 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
2012 tmppath[len] = '\0';
2014 iter = tmppath;
2015 while (*iter) {
2016 if (*iter == '/')
2017 *iter = '\\';
2018 ++iter;
2021 /* if ends in \. or \.. append a backslash */
2022 if (tmppath[len - 1] == '.' &&
2023 (tmppath[len - 2] == '\\' ||
2024 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
2026 if (len < MAX_PATH - 1)
2028 tmppath[len] = '\\';
2029 tmppath[len+1] = '\0';
2030 ++len;
2033 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
2034 tmppath, len);
2036 else
2037 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
2038 lpszcp, len);
2040 else
2042 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
2043 lpUC->lpszUrlPath[0] = 0;
2044 lpUC->dwUrlPathLength = 0;
2047 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
2048 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
2049 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
2050 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
2051 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
2053 heap_free( lpszUrl_decode );
2054 return TRUE;
2057 /***********************************************************************
2058 * InternetAttemptConnect (WININET.@)
2060 * Attempt to make a connection to the internet
2062 * RETURNS
2063 * ERROR_SUCCESS on success
2064 * Error value on failure
2067 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
2069 FIXME("Stub\n");
2070 return ERROR_SUCCESS;
2074 /***********************************************************************
2075 * convert_url_canonicalization_flags
2077 * Helper for InternetCanonicalizeUrl
2079 * PARAMS
2080 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2082 * RETURNS
2083 * Flags suitable for UrlCanonicalize
2085 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
2087 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
2089 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
2090 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
2091 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
2092 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
2093 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2094 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
2095 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
2097 return dwUrlFlags;
2100 /***********************************************************************
2101 * InternetCanonicalizeUrlA (WININET.@)
2103 * Escape unsafe characters and spaces
2105 * RETURNS
2106 * TRUE on success
2107 * FALSE on failure
2110 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
2111 LPDWORD lpdwBufferLength, DWORD dwFlags)
2113 HRESULT hr;
2115 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl), lpszBuffer,
2116 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2118 dwFlags = convert_url_canonicalization_flags(dwFlags);
2119 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2120 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2121 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2123 return hr == S_OK;
2126 /***********************************************************************
2127 * InternetCanonicalizeUrlW (WININET.@)
2129 * Escape unsafe characters and spaces
2131 * RETURNS
2132 * TRUE on success
2133 * FALSE on failure
2136 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
2137 LPDWORD lpdwBufferLength, DWORD dwFlags)
2139 HRESULT hr;
2141 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2142 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2144 dwFlags = convert_url_canonicalization_flags(dwFlags);
2145 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2146 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2147 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2149 return hr == S_OK;
2152 /* #################################################### */
2154 static INTERNET_STATUS_CALLBACK set_status_callback(
2155 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2157 INTERNET_STATUS_CALLBACK ret;
2159 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2160 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2162 ret = lpwh->lpfnStatusCB;
2163 lpwh->lpfnStatusCB = callback;
2165 return ret;
2168 /***********************************************************************
2169 * InternetSetStatusCallbackA (WININET.@)
2171 * Sets up a callback function which is called as progress is made
2172 * during an operation.
2174 * RETURNS
2175 * Previous callback or NULL on success
2176 * INTERNET_INVALID_STATUS_CALLBACK on failure
2179 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2180 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2182 INTERNET_STATUS_CALLBACK retVal;
2183 object_header_t *lpwh;
2185 TRACE("%p\n", hInternet);
2187 if (!(lpwh = get_handle_object(hInternet)))
2188 return INTERNET_INVALID_STATUS_CALLBACK;
2190 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2192 WININET_Release( lpwh );
2193 return retVal;
2196 /***********************************************************************
2197 * InternetSetStatusCallbackW (WININET.@)
2199 * Sets up a callback function which is called as progress is made
2200 * during an operation.
2202 * RETURNS
2203 * Previous callback or NULL on success
2204 * INTERNET_INVALID_STATUS_CALLBACK on failure
2207 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2208 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2210 INTERNET_STATUS_CALLBACK retVal;
2211 object_header_t *lpwh;
2213 TRACE("%p\n", hInternet);
2215 if (!(lpwh = get_handle_object(hInternet)))
2216 return INTERNET_INVALID_STATUS_CALLBACK;
2218 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2220 WININET_Release( lpwh );
2221 return retVal;
2224 /***********************************************************************
2225 * InternetSetFilePointer (WININET.@)
2227 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2228 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2230 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2231 return FALSE;
2234 /***********************************************************************
2235 * InternetWriteFile (WININET.@)
2237 * Write data to an open internet file
2239 * RETURNS
2240 * TRUE on success
2241 * FALSE on failure
2244 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2245 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2247 object_header_t *lpwh;
2248 BOOL res;
2250 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2252 lpwh = get_handle_object( hFile );
2253 if (!lpwh) {
2254 WARN("Invalid handle\n");
2255 SetLastError(ERROR_INVALID_HANDLE);
2256 return FALSE;
2259 if(lpwh->vtbl->WriteFile) {
2260 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2261 }else {
2262 WARN("No Writefile method.\n");
2263 res = ERROR_INVALID_HANDLE;
2266 WININET_Release( lpwh );
2268 if(res != ERROR_SUCCESS)
2269 SetLastError(res);
2270 return res == ERROR_SUCCESS;
2274 /***********************************************************************
2275 * InternetReadFile (WININET.@)
2277 * Read data from an open internet file
2279 * RETURNS
2280 * TRUE on success
2281 * FALSE on failure
2284 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2285 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2287 object_header_t *hdr;
2288 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2290 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2292 hdr = get_handle_object(hFile);
2293 if (!hdr) {
2294 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2295 return FALSE;
2298 if(hdr->vtbl->ReadFile)
2299 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2301 WININET_Release(hdr);
2303 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2304 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2306 if(res != ERROR_SUCCESS)
2307 SetLastError(res);
2308 return res == ERROR_SUCCESS;
2311 /***********************************************************************
2312 * InternetReadFileExA (WININET.@)
2314 * Read data from an open internet file
2316 * PARAMS
2317 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2318 * lpBuffersOut [I/O] Buffer.
2319 * dwFlags [I] Flags. See notes.
2320 * dwContext [I] Context for callbacks.
2322 * RETURNS
2323 * TRUE on success
2324 * FALSE on failure
2326 * NOTES
2327 * The parameter dwFlags include zero or more of the following flags:
2328 *|IRF_ASYNC - Makes the call asynchronous.
2329 *|IRF_SYNC - Makes the call synchronous.
2330 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2331 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2333 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2335 * SEE
2336 * InternetOpenUrlA(), HttpOpenRequestA()
2338 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2339 DWORD dwFlags, DWORD_PTR dwContext)
2341 object_header_t *hdr;
2342 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2344 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2346 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2347 SetLastError(ERROR_INVALID_PARAMETER);
2348 return FALSE;
2351 hdr = get_handle_object(hFile);
2352 if (!hdr) {
2353 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2354 return FALSE;
2357 if(hdr->vtbl->ReadFileEx)
2358 res = hdr->vtbl->ReadFileEx(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2359 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2361 WININET_Release(hdr);
2363 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2364 res, lpBuffersOut->dwBufferLength);
2366 if(res != ERROR_SUCCESS)
2367 SetLastError(res);
2368 return res == ERROR_SUCCESS;
2371 /***********************************************************************
2372 * InternetReadFileExW (WININET.@)
2373 * SEE
2374 * InternetReadFileExA()
2376 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2377 DWORD dwFlags, DWORD_PTR dwContext)
2379 object_header_t *hdr;
2380 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2382 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2384 if (lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2385 SetLastError(ERROR_INVALID_PARAMETER);
2386 return FALSE;
2389 hdr = get_handle_object(hFile);
2390 if (!hdr) {
2391 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2392 return FALSE;
2395 if(hdr->vtbl->ReadFileEx)
2396 res = hdr->vtbl->ReadFileEx(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2397 dwFlags, dwContext);
2399 WININET_Release(hdr);
2401 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2402 res, lpBuffer->dwBufferLength);
2404 if(res != ERROR_SUCCESS)
2405 SetLastError(res);
2406 return res == ERROR_SUCCESS;
2409 static BOOL get_proxy_autoconfig_url( char *buf, DWORD buflen )
2411 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2413 CFDictionaryRef settings = CFNetworkCopySystemProxySettings();
2414 const void *ref;
2415 BOOL ret = FALSE;
2417 if (!settings) return FALSE;
2419 if (!(ref = CFDictionaryGetValue( settings, kCFNetworkProxiesProxyAutoConfigURLString )))
2421 CFRelease( settings );
2422 return FALSE;
2424 if (CFStringGetCString( ref, buf, buflen, kCFStringEncodingASCII ))
2426 TRACE( "returning %s\n", debugstr_a(buf) );
2427 ret = TRUE;
2429 CFRelease( settings );
2430 return ret;
2431 #else
2432 FIXME( "no support on this platform\n" );
2433 return FALSE;
2434 #endif
2437 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2439 /* FIXME: This function currently handles more options than it should. Options requiring
2440 * proper handles should be moved to proper functions */
2441 switch(option) {
2442 case INTERNET_OPTION_HTTP_VERSION:
2443 if (*size < sizeof(HTTP_VERSION_INFO))
2444 return ERROR_INSUFFICIENT_BUFFER;
2447 * Presently hardcoded to 1.1
2449 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2450 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2451 *size = sizeof(HTTP_VERSION_INFO);
2453 return ERROR_SUCCESS;
2455 case INTERNET_OPTION_CONNECTED_STATE:
2456 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2458 if (*size < sizeof(ULONG))
2459 return ERROR_INSUFFICIENT_BUFFER;
2461 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2462 *size = sizeof(ULONG);
2464 return ERROR_SUCCESS;
2466 case INTERNET_OPTION_PROXY: {
2467 appinfo_t ai;
2468 BOOL ret;
2470 TRACE("Getting global proxy info\n");
2471 memset(&ai, 0, sizeof(appinfo_t));
2472 INTERNET_ConfigureProxy(&ai);
2474 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2475 APPINFO_Destroy(&ai.hdr);
2476 return ret;
2479 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2480 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2482 if (*size < sizeof(ULONG))
2483 return ERROR_INSUFFICIENT_BUFFER;
2485 *(ULONG*)buffer = max_conns;
2486 *size = sizeof(ULONG);
2488 return ERROR_SUCCESS;
2490 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2491 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2493 if (*size < sizeof(ULONG))
2494 return ERROR_INSUFFICIENT_BUFFER;
2496 *(ULONG*)buffer = max_1_0_conns;
2497 *size = sizeof(ULONG);
2499 return ERROR_SUCCESS;
2501 case INTERNET_OPTION_SECURITY_FLAGS:
2502 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2503 return ERROR_SUCCESS;
2505 case INTERNET_OPTION_VERSION: {
2506 static const INTERNET_VERSION_INFO info = { 1, 2 };
2508 TRACE("INTERNET_OPTION_VERSION\n");
2510 if (*size < sizeof(INTERNET_VERSION_INFO))
2511 return ERROR_INSUFFICIENT_BUFFER;
2513 memcpy(buffer, &info, sizeof(info));
2514 *size = sizeof(info);
2516 return ERROR_SUCCESS;
2519 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2520 char url[INTERNET_MAX_URL_LENGTH + 1];
2521 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2522 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2523 DWORD res = ERROR_SUCCESS, i;
2524 proxyinfo_t pi;
2525 BOOL have_url;
2526 LONG ret;
2528 TRACE("Getting global proxy info\n");
2529 if((ret = INTERNET_LoadProxySettings(&pi)))
2530 return ret;
2532 have_url = get_proxy_autoconfig_url(url, sizeof(url));
2534 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2536 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2537 FreeProxyInfo(&pi);
2538 return ERROR_INSUFFICIENT_BUFFER;
2541 for (i = 0; i < con->dwOptionCount; i++) {
2542 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2543 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2545 switch (optionW->dwOption) {
2546 case INTERNET_PER_CONN_FLAGS:
2547 if(pi.proxyEnabled)
2548 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2549 else
2550 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2551 if (have_url)
2552 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2553 optionW->Value.dwValue |= PROXY_TYPE_DIRECT|PROXY_TYPE_AUTO_PROXY_URL;
2554 break;
2556 case INTERNET_PER_CONN_PROXY_SERVER:
2557 if (unicode)
2558 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2559 else
2560 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2561 break;
2563 case INTERNET_PER_CONN_PROXY_BYPASS:
2564 if (unicode)
2565 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2566 else
2567 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2568 break;
2570 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2571 if (!have_url)
2572 optionW->Value.pszValue = NULL;
2573 else if (unicode)
2574 optionW->Value.pszValue = heap_strdupAtoW(url);
2575 else
2576 optionA->Value.pszValue = heap_strdupA(url);
2577 break;
2579 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2580 optionW->Value.dwValue = AUTO_PROXY_FLAG_ALWAYS_DETECT;
2581 break;
2583 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2584 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2585 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2586 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2587 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2588 memset(&optionW->Value, 0, sizeof(optionW->Value));
2589 break;
2591 default:
2592 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2593 res = ERROR_INVALID_PARAMETER;
2594 break;
2597 FreeProxyInfo(&pi);
2599 return res;
2601 case INTERNET_OPTION_REQUEST_FLAGS:
2602 case INTERNET_OPTION_USER_AGENT:
2603 *size = 0;
2604 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2605 case INTERNET_OPTION_POLICY:
2606 return ERROR_INVALID_PARAMETER;
2607 case INTERNET_OPTION_CONNECT_TIMEOUT:
2608 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2610 if (*size < sizeof(ULONG))
2611 return ERROR_INSUFFICIENT_BUFFER;
2613 *(ULONG*)buffer = connect_timeout;
2614 *size = sizeof(ULONG);
2616 return ERROR_SUCCESS;
2619 FIXME("Stub for %d\n", option);
2620 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2623 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2625 switch(option) {
2626 case INTERNET_OPTION_CONTEXT_VALUE:
2627 if (!size)
2628 return ERROR_INVALID_PARAMETER;
2630 if (*size < sizeof(DWORD_PTR)) {
2631 *size = sizeof(DWORD_PTR);
2632 return ERROR_INSUFFICIENT_BUFFER;
2634 if (!buffer)
2635 return ERROR_INVALID_PARAMETER;
2637 *(DWORD_PTR *)buffer = hdr->dwContext;
2638 *size = sizeof(DWORD_PTR);
2639 return ERROR_SUCCESS;
2641 case INTERNET_OPTION_REQUEST_FLAGS:
2642 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2643 *size = sizeof(DWORD);
2644 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2646 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2647 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2648 WARN("Called on global option %u\n", option);
2649 return ERROR_INTERNET_INVALID_OPERATION;
2652 /* FIXME: we shouldn't call it here */
2653 return query_global_option(option, buffer, size, unicode);
2656 /***********************************************************************
2657 * InternetQueryOptionW (WININET.@)
2659 * Queries an options on the specified handle
2661 * RETURNS
2662 * TRUE on success
2663 * FALSE on failure
2666 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2667 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2669 object_header_t *hdr;
2670 DWORD res = ERROR_INVALID_HANDLE;
2672 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2674 if(hInternet) {
2675 hdr = get_handle_object(hInternet);
2676 if (hdr) {
2677 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2678 WININET_Release(hdr);
2680 }else {
2681 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2684 if(res != ERROR_SUCCESS)
2685 SetLastError(res);
2686 return res == ERROR_SUCCESS;
2689 /***********************************************************************
2690 * InternetQueryOptionA (WININET.@)
2692 * Queries an options on the specified handle
2694 * RETURNS
2695 * TRUE on success
2696 * FALSE on failure
2699 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2700 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2702 object_header_t *hdr;
2703 DWORD res = ERROR_INVALID_HANDLE;
2705 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2707 if(hInternet) {
2708 hdr = get_handle_object(hInternet);
2709 if (hdr) {
2710 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2711 WININET_Release(hdr);
2713 }else {
2714 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2717 if(res != ERROR_SUCCESS)
2718 SetLastError(res);
2719 return res == ERROR_SUCCESS;
2722 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2724 switch(option) {
2725 case INTERNET_OPTION_CALLBACK:
2726 WARN("Not settable option %u\n", option);
2727 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2728 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2729 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2730 WARN("Called on global option %u\n", option);
2731 return ERROR_INTERNET_INVALID_OPERATION;
2734 return ERROR_INTERNET_INVALID_OPTION;
2737 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2739 switch(option) {
2740 case INTERNET_OPTION_CALLBACK:
2741 WARN("Not global option %u\n", option);
2742 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2744 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2745 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2747 if(size != sizeof(max_conns))
2748 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2749 if(!*(ULONG*)buf)
2750 return ERROR_BAD_ARGUMENTS;
2752 max_conns = *(ULONG*)buf;
2753 return ERROR_SUCCESS;
2755 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2756 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2758 if(size != sizeof(max_1_0_conns))
2759 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2760 if(!*(ULONG*)buf)
2761 return ERROR_BAD_ARGUMENTS;
2763 max_1_0_conns = *(ULONG*)buf;
2764 return ERROR_SUCCESS;
2766 case INTERNET_OPTION_CONNECT_TIMEOUT:
2767 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2769 if(size != sizeof(connect_timeout))
2770 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2771 if(!*(ULONG*)buf)
2772 return ERROR_BAD_ARGUMENTS;
2774 connect_timeout = *(ULONG*)buf;
2775 return ERROR_SUCCESS;
2777 case INTERNET_OPTION_SETTINGS_CHANGED:
2778 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2779 collect_connections(COLLECT_CONNECTIONS);
2780 return ERROR_SUCCESS;
2783 return ERROR_INTERNET_INVALID_OPTION;
2786 /***********************************************************************
2787 * InternetSetOptionW (WININET.@)
2789 * Sets an options on the specified handle
2791 * RETURNS
2792 * TRUE on success
2793 * FALSE on failure
2796 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2797 LPVOID lpBuffer, DWORD dwBufferLength)
2799 object_header_t *lpwhh;
2800 BOOL ret = TRUE;
2801 DWORD res;
2803 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2805 lpwhh = (object_header_t*) get_handle_object( hInternet );
2806 if(lpwhh)
2807 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2808 else
2809 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2811 if(res != ERROR_INTERNET_INVALID_OPTION) {
2812 if(lpwhh)
2813 WININET_Release(lpwhh);
2815 if(res != ERROR_SUCCESS)
2816 SetLastError(res);
2818 return res == ERROR_SUCCESS;
2821 switch (dwOption)
2823 case INTERNET_OPTION_HTTP_VERSION:
2825 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2826 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2828 break;
2829 case INTERNET_OPTION_ERROR_MASK:
2831 if(!lpwhh) {
2832 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2833 return FALSE;
2834 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2835 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2836 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2837 SetLastError(ERROR_INVALID_PARAMETER);
2838 ret = FALSE;
2839 } else if(dwBufferLength != sizeof(ULONG)) {
2840 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2841 ret = FALSE;
2842 } else
2843 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2844 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2846 break;
2847 case INTERNET_OPTION_PROXY:
2849 INTERNET_PROXY_INFOW *info = lpBuffer;
2851 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2853 SetLastError(ERROR_INVALID_PARAMETER);
2854 return FALSE;
2856 if (!hInternet)
2858 EnterCriticalSection( &WININET_cs );
2859 free_global_proxy();
2860 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2861 if (global_proxy)
2863 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2865 global_proxy->proxyEnabled = 1;
2866 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2867 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2869 else
2871 global_proxy->proxyEnabled = 0;
2872 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2875 LeaveCriticalSection( &WININET_cs );
2877 else
2879 /* In general, each type of object should handle
2880 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2881 * get silently dropped.
2883 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2884 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2885 ret = FALSE;
2887 break;
2889 case INTERNET_OPTION_CODEPAGE:
2891 ULONG codepage = *(ULONG *)lpBuffer;
2892 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2894 break;
2895 case INTERNET_OPTION_REQUEST_PRIORITY:
2897 ULONG priority = *(ULONG *)lpBuffer;
2898 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2900 break;
2901 case INTERNET_OPTION_CONNECT_TIMEOUT:
2903 ULONG connecttimeout = *(ULONG *)lpBuffer;
2904 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2906 break;
2907 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2909 ULONG receivetimeout = *(ULONG *)lpBuffer;
2910 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2912 break;
2913 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2914 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2915 break;
2916 case INTERNET_OPTION_END_BROWSER_SESSION:
2917 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2918 break;
2919 case INTERNET_OPTION_CONNECTED_STATE:
2920 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2921 break;
2922 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2923 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2924 break;
2925 case INTERNET_OPTION_SEND_TIMEOUT:
2926 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2927 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2929 ULONG timeout = *(ULONG *)lpBuffer;
2930 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2931 break;
2933 case INTERNET_OPTION_CONNECT_RETRIES:
2935 ULONG retries = *(ULONG *)lpBuffer;
2936 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2937 break;
2939 case INTERNET_OPTION_CONTEXT_VALUE:
2941 if (!lpwhh)
2943 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2944 return FALSE;
2946 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2948 SetLastError(ERROR_INVALID_PARAMETER);
2949 ret = FALSE;
2951 else
2952 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2953 break;
2955 case INTERNET_OPTION_SECURITY_FLAGS:
2956 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2957 break;
2958 case INTERNET_OPTION_DISABLE_AUTODIAL:
2959 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2960 break;
2961 case INTERNET_OPTION_HTTP_DECODING:
2962 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2963 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2964 ret = FALSE;
2965 break;
2966 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2967 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2968 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2969 ret = FALSE;
2970 break;
2971 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2972 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2973 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2974 ret = FALSE;
2975 break;
2976 case INTERNET_OPTION_CODEPAGE_PATH:
2977 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2978 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2979 ret = FALSE;
2980 break;
2981 case INTERNET_OPTION_CODEPAGE_EXTRA:
2982 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2983 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2984 ret = FALSE;
2985 break;
2986 case INTERNET_OPTION_IDN:
2987 FIXME("INTERNET_OPTION_IDN; STUB\n");
2988 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2989 ret = FALSE;
2990 break;
2991 case INTERNET_OPTION_POLICY:
2992 SetLastError(ERROR_INVALID_PARAMETER);
2993 ret = FALSE;
2994 break;
2995 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2996 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2997 LONG res;
2998 unsigned int i;
2999 proxyinfo_t pi;
3001 if (INTERNET_LoadProxySettings(&pi)) return FALSE;
3003 for (i = 0; i < con->dwOptionCount; i++) {
3004 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
3006 switch (option->dwOption) {
3007 case INTERNET_PER_CONN_PROXY_SERVER:
3008 heap_free(pi.proxy);
3009 pi.proxy = heap_strdupW(option->Value.pszValue);
3010 break;
3012 case INTERNET_PER_CONN_FLAGS:
3013 if(option->Value.dwValue & PROXY_TYPE_PROXY)
3014 pi.proxyEnabled = 1;
3015 else
3017 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
3018 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
3019 pi.proxyEnabled = 0;
3021 break;
3023 case INTERNET_PER_CONN_PROXY_BYPASS:
3024 heap_free(pi.proxyBypass);
3025 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
3026 break;
3028 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3029 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3030 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3031 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3032 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3033 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3034 FIXME("Unhandled dwOption %d\n", option->dwOption);
3035 break;
3037 default:
3038 FIXME("Unknown dwOption %d\n", option->dwOption);
3039 SetLastError(ERROR_INVALID_PARAMETER);
3040 break;
3044 if ((res = INTERNET_SaveProxySettings(&pi)))
3045 SetLastError(res);
3047 FreeProxyInfo(&pi);
3049 ret = (res == ERROR_SUCCESS);
3050 break;
3052 default:
3053 FIXME("Option %d STUB\n",dwOption);
3054 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3055 ret = FALSE;
3056 break;
3059 if(lpwhh)
3060 WININET_Release( lpwhh );
3062 return ret;
3066 /***********************************************************************
3067 * InternetSetOptionA (WININET.@)
3069 * Sets an options on the specified handle.
3071 * RETURNS
3072 * TRUE on success
3073 * FALSE on failure
3076 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
3077 LPVOID lpBuffer, DWORD dwBufferLength)
3079 LPVOID wbuffer;
3080 DWORD wlen;
3081 BOOL r;
3083 switch( dwOption )
3085 case INTERNET_OPTION_PROXY:
3087 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
3088 LPINTERNET_PROXY_INFOW piw;
3089 DWORD proxlen, prbylen;
3090 LPWSTR prox, prby;
3092 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
3093 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
3094 wlen = sizeof(*piw) + proxlen + prbylen;
3095 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
3096 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
3097 piw->dwAccessType = pi->dwAccessType;
3098 prox = (LPWSTR) &piw[1];
3099 prby = &prox[proxlen+1];
3100 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
3101 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
3102 piw->lpszProxy = prox;
3103 piw->lpszProxyBypass = prby;
3105 break;
3106 case INTERNET_OPTION_USER_AGENT:
3107 case INTERNET_OPTION_USERNAME:
3108 case INTERNET_OPTION_PASSWORD:
3109 case INTERNET_OPTION_PROXY_USERNAME:
3110 case INTERNET_OPTION_PROXY_PASSWORD:
3111 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3112 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3113 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3114 break;
3115 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3116 unsigned int i;
3117 INTERNET_PER_CONN_OPTION_LISTW *listW;
3118 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3119 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3120 wbuffer = heap_alloc(wlen);
3121 listW = wbuffer;
3123 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3124 if (listA->pszConnection)
3126 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3127 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3128 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3130 else
3131 listW->pszConnection = NULL;
3132 listW->dwOptionCount = listA->dwOptionCount;
3133 listW->dwOptionError = listA->dwOptionError;
3134 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3136 for (i = 0; i < listA->dwOptionCount; ++i) {
3137 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3138 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3140 optW->dwOption = optA->dwOption;
3142 switch (optA->dwOption) {
3143 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3144 case INTERNET_PER_CONN_PROXY_BYPASS:
3145 case INTERNET_PER_CONN_PROXY_SERVER:
3146 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3147 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3148 if (optA->Value.pszValue)
3150 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3151 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3152 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3154 else
3155 optW->Value.pszValue = NULL;
3156 break;
3157 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3158 case INTERNET_PER_CONN_FLAGS:
3159 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3160 optW->Value.dwValue = optA->Value.dwValue;
3161 break;
3162 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3163 optW->Value.ftValue = optA->Value.ftValue;
3164 break;
3165 default:
3166 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3167 optW->Value.dwValue = optA->Value.dwValue;
3168 break;
3172 break;
3173 default:
3174 wbuffer = lpBuffer;
3175 wlen = dwBufferLength;
3178 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3180 if( lpBuffer != wbuffer )
3182 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3184 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3185 unsigned int i;
3186 for (i = 0; i < list->dwOptionCount; ++i) {
3187 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3188 switch (opt->dwOption) {
3189 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3190 case INTERNET_PER_CONN_PROXY_BYPASS:
3191 case INTERNET_PER_CONN_PROXY_SERVER:
3192 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3193 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3194 heap_free( opt->Value.pszValue );
3195 break;
3196 default:
3197 break;
3200 heap_free( list->pOptions );
3202 heap_free( wbuffer );
3205 return r;
3209 /***********************************************************************
3210 * InternetSetOptionExA (WININET.@)
3212 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3213 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3215 FIXME("Flags %08x ignored\n", dwFlags);
3216 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3219 /***********************************************************************
3220 * InternetSetOptionExW (WININET.@)
3222 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3223 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3225 FIXME("Flags %08x ignored\n", dwFlags);
3226 if( dwFlags & ~ISO_VALID_FLAGS )
3228 SetLastError( ERROR_INVALID_PARAMETER );
3229 return FALSE;
3231 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3234 static const WCHAR WININET_wkday[7][4] =
3235 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3236 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3237 static const WCHAR WININET_month[12][4] =
3238 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3239 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3240 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3242 /***********************************************************************
3243 * InternetTimeFromSystemTimeA (WININET.@)
3245 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3247 BOOL ret;
3248 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3250 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3252 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3254 SetLastError(ERROR_INVALID_PARAMETER);
3255 return FALSE;
3258 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3260 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3261 return FALSE;
3264 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3265 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3267 return ret;
3270 /***********************************************************************
3271 * InternetTimeFromSystemTimeW (WININET.@)
3273 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3275 static const WCHAR date[] =
3276 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3277 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3279 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3281 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3283 SetLastError(ERROR_INVALID_PARAMETER);
3284 return FALSE;
3287 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3289 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3290 return FALSE;
3293 sprintfW( string, date,
3294 WININET_wkday[time->wDayOfWeek],
3295 time->wDay,
3296 WININET_month[time->wMonth - 1],
3297 time->wYear,
3298 time->wHour,
3299 time->wMinute,
3300 time->wSecond );
3302 return TRUE;
3305 /***********************************************************************
3306 * InternetTimeToSystemTimeA (WININET.@)
3308 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3310 BOOL ret = FALSE;
3311 WCHAR *stringW;
3313 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3315 stringW = heap_strdupAtoW(string);
3316 if (stringW)
3318 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3319 heap_free( stringW );
3321 return ret;
3324 /***********************************************************************
3325 * InternetTimeToSystemTimeW (WININET.@)
3327 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3329 unsigned int i;
3330 const WCHAR *s = string;
3331 WCHAR *end;
3333 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3335 if (!string || !time) return FALSE;
3337 /* Windows does this too */
3338 GetSystemTime( time );
3340 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3341 * a SYSTEMTIME structure.
3344 while (*s && !isalphaW( *s )) s++;
3345 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3346 time->wDayOfWeek = 7;
3348 for (i = 0; i < 7; i++)
3350 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3351 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3352 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3354 time->wDayOfWeek = i;
3355 break;
3359 if (time->wDayOfWeek > 6) return TRUE;
3360 while (*s && !isdigitW( *s )) s++;
3361 time->wDay = strtolW( s, &end, 10 );
3362 s = end;
3364 while (*s && !isalphaW( *s )) s++;
3365 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3366 time->wMonth = 0;
3368 for (i = 0; i < 12; i++)
3370 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3371 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3372 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3374 time->wMonth = i + 1;
3375 break;
3378 if (time->wMonth == 0) return TRUE;
3380 while (*s && !isdigitW( *s )) s++;
3381 if (*s == '\0') return TRUE;
3382 time->wYear = strtolW( s, &end, 10 );
3383 s = end;
3385 while (*s && !isdigitW( *s )) s++;
3386 if (*s == '\0') return TRUE;
3387 time->wHour = strtolW( s, &end, 10 );
3388 s = end;
3390 while (*s && !isdigitW( *s )) s++;
3391 if (*s == '\0') return TRUE;
3392 time->wMinute = strtolW( s, &end, 10 );
3393 s = end;
3395 while (*s && !isdigitW( *s )) s++;
3396 if (*s == '\0') return TRUE;
3397 time->wSecond = strtolW( s, &end, 10 );
3398 s = end;
3400 time->wMilliseconds = 0;
3401 return TRUE;
3404 /***********************************************************************
3405 * InternetCheckConnectionW (WININET.@)
3407 * Pings a requested host to check internet connection
3409 * RETURNS
3410 * TRUE on success and FALSE on failure. If a failure then
3411 * ERROR_NOT_CONNECTED is placed into GetLastError
3414 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3417 * this is a kludge which runs the resident ping program and reads the output.
3419 * Anyone have a better idea?
3422 BOOL rc = FALSE;
3423 static const CHAR ping[] = "ping -c 1 ";
3424 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3425 CHAR *command = NULL;
3426 WCHAR hostW[INTERNET_MAX_HOST_NAME_LENGTH];
3427 DWORD len;
3428 INTERNET_PORT port;
3429 int status = -1;
3431 FIXME("\n");
3434 * Crack or set the Address
3436 if (lpszUrl == NULL)
3439 * According to the doc we are supposed to use the ip for the next
3440 * server in the WnInet internal server database. I have
3441 * no idea what that is or how to get it.
3443 * So someone needs to implement this.
3445 FIXME("Unimplemented with URL of NULL\n");
3446 return TRUE;
3448 else
3450 URL_COMPONENTSW components;
3452 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3453 components.lpszHostName = (LPWSTR)hostW;
3454 components.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3456 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3457 goto End;
3459 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3460 port = components.nPort;
3461 TRACE("port: %d\n", port);
3464 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3466 struct sockaddr_storage saddr;
3467 socklen_t sa_len = sizeof(saddr);
3468 int fd;
3470 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3471 goto End;
3472 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3473 if (fd != -1)
3475 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3476 rc = TRUE;
3477 close(fd);
3480 else
3483 * Build our ping command
3485 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3486 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3487 strcpy(command,ping);
3488 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3489 strcat(command,redirect);
3491 TRACE("Ping command is : %s\n",command);
3493 status = system(command);
3495 TRACE("Ping returned a code of %i\n",status);
3497 /* Ping return code of 0 indicates success */
3498 if (status == 0)
3499 rc = TRUE;
3502 End:
3503 heap_free( command );
3504 if (rc == FALSE)
3505 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3507 return rc;
3511 /***********************************************************************
3512 * InternetCheckConnectionA (WININET.@)
3514 * Pings a requested host to check internet connection
3516 * RETURNS
3517 * TRUE on success and FALSE on failure. If a failure then
3518 * ERROR_NOT_CONNECTED is placed into GetLastError
3521 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3523 WCHAR *url = NULL;
3524 BOOL rc;
3526 if(lpszUrl) {
3527 url = heap_strdupAtoW(lpszUrl);
3528 if(!url)
3529 return FALSE;
3532 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3534 heap_free(url);
3535 return rc;
3539 /**********************************************************
3540 * INTERNET_InternetOpenUrlW (internal)
3542 * Opens an URL
3544 * RETURNS
3545 * handle of connection or NULL on failure
3547 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3548 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3550 URL_COMPONENTSW urlComponents;
3551 WCHAR protocol[INTERNET_MAX_SCHEME_LENGTH];
3552 WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH];
3553 WCHAR userName[INTERNET_MAX_USER_NAME_LENGTH];
3554 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
3555 WCHAR path[INTERNET_MAX_PATH_LENGTH];
3556 WCHAR extra[1024];
3557 HINTERNET client = NULL, client1 = NULL;
3558 DWORD res;
3560 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3561 dwHeadersLength, dwFlags, dwContext);
3563 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3564 urlComponents.lpszScheme = protocol;
3565 urlComponents.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH;
3566 urlComponents.lpszHostName = hostName;
3567 urlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3568 urlComponents.lpszUserName = userName;
3569 urlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
3570 urlComponents.lpszPassword = password;
3571 urlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
3572 urlComponents.lpszUrlPath = path;
3573 urlComponents.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
3574 urlComponents.lpszExtraInfo = extra;
3575 urlComponents.dwExtraInfoLength = 1024;
3576 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3577 return NULL;
3578 switch(urlComponents.nScheme) {
3579 case INTERNET_SCHEME_FTP:
3580 if(urlComponents.nPort == 0)
3581 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3582 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3583 userName, password, dwFlags, dwContext, INET_OPENURL);
3584 if(client == NULL)
3585 break;
3586 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3587 if(client1 == NULL) {
3588 InternetCloseHandle(client);
3589 break;
3591 break;
3593 case INTERNET_SCHEME_HTTP:
3594 case INTERNET_SCHEME_HTTPS: {
3595 static const WCHAR szStars[] = { '*','/','*', 0 };
3596 LPCWSTR accept[2] = { szStars, NULL };
3597 if(urlComponents.nPort == 0) {
3598 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3599 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3600 else
3601 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3603 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3605 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3606 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3607 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3608 if(res != ERROR_SUCCESS) {
3609 INTERNET_SetLastError(res);
3610 break;
3613 if (urlComponents.dwExtraInfoLength) {
3614 WCHAR *path_extra;
3615 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3617 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3619 InternetCloseHandle(client);
3620 break;
3622 strcpyW(path_extra, urlComponents.lpszUrlPath);
3623 strcatW(path_extra, urlComponents.lpszExtraInfo);
3624 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3625 heap_free(path_extra);
3627 else
3628 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3630 if(client1 == NULL) {
3631 InternetCloseHandle(client);
3632 break;
3634 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3635 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3636 GetLastError() != ERROR_IO_PENDING) {
3637 InternetCloseHandle(client1);
3638 client1 = NULL;
3639 break;
3642 case INTERNET_SCHEME_GOPHER:
3643 /* gopher doesn't seem to be implemented in wine, but it's supposed
3644 * to be supported by InternetOpenUrlA. */
3645 default:
3646 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3647 break;
3650 TRACE(" %p <--\n", client1);
3652 return client1;
3655 /**********************************************************
3656 * InternetOpenUrlW (WININET.@)
3658 * Opens an URL
3660 * RETURNS
3661 * handle of connection or NULL on failure
3663 typedef struct {
3664 task_header_t hdr;
3665 WCHAR *url;
3666 WCHAR *headers;
3667 DWORD headers_len;
3668 DWORD flags;
3669 DWORD_PTR context;
3670 } open_url_task_t;
3672 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3674 open_url_task_t *task = (open_url_task_t*)hdr;
3676 TRACE("%p\n", task->hdr.hdr);
3678 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3679 task->headers_len, task->flags, task->context);
3680 heap_free(task->url);
3681 heap_free(task->headers);
3684 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3685 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3687 HINTERNET ret = NULL;
3688 appinfo_t *hIC = NULL;
3690 if (TRACE_ON(wininet)) {
3691 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3692 dwHeadersLength, dwFlags, dwContext);
3693 TRACE(" flags :");
3694 dump_INTERNET_FLAGS(dwFlags);
3697 if (!lpszUrl)
3699 SetLastError(ERROR_INVALID_PARAMETER);
3700 goto lend;
3703 hIC = (appinfo_t*)get_handle_object( hInternet );
3704 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3705 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3706 goto lend;
3709 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3710 open_url_task_t *task;
3712 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3713 task->url = heap_strdupW(lpszUrl);
3714 task->headers = heap_strdupW(lpszHeaders);
3715 task->headers_len = dwHeadersLength;
3716 task->flags = dwFlags;
3717 task->context = dwContext;
3719 INTERNET_AsyncCall(&task->hdr);
3720 SetLastError(ERROR_IO_PENDING);
3721 } else {
3722 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3725 lend:
3726 if( hIC )
3727 WININET_Release( &hIC->hdr );
3728 TRACE(" %p <--\n", ret);
3730 return ret;
3733 /**********************************************************
3734 * InternetOpenUrlA (WININET.@)
3736 * Opens an URL
3738 * RETURNS
3739 * handle of connection or NULL on failure
3741 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3742 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3744 HINTERNET rc = NULL;
3745 DWORD lenHeaders = 0;
3746 LPWSTR szUrl = NULL;
3747 LPWSTR szHeaders = NULL;
3749 TRACE("\n");
3751 if(lpszUrl) {
3752 szUrl = heap_strdupAtoW(lpszUrl);
3753 if(!szUrl)
3754 return NULL;
3757 if(lpszHeaders) {
3758 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3759 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3760 if(!szHeaders) {
3761 heap_free(szUrl);
3762 return NULL;
3764 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3767 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3768 lenHeaders, dwFlags, dwContext);
3770 heap_free(szUrl);
3771 heap_free(szHeaders);
3772 return rc;
3776 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3778 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3780 if (lpwite)
3782 lpwite->dwError = 0;
3783 lpwite->response[0] = '\0';
3786 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3788 heap_free(lpwite);
3789 return NULL;
3791 return lpwite;
3795 /***********************************************************************
3796 * INTERNET_SetLastError (internal)
3798 * Set last thread specific error
3800 * RETURNS
3803 void INTERNET_SetLastError(DWORD dwError)
3805 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3807 if (!lpwite)
3808 lpwite = INTERNET_AllocThreadError();
3810 SetLastError(dwError);
3811 if(lpwite)
3812 lpwite->dwError = dwError;
3816 /***********************************************************************
3817 * INTERNET_GetLastError (internal)
3819 * Get last thread specific error
3821 * RETURNS
3824 DWORD INTERNET_GetLastError(void)
3826 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3827 if (!lpwite) return 0;
3828 /* TlsGetValue clears last error, so set it again here */
3829 SetLastError(lpwite->dwError);
3830 return lpwite->dwError;
3834 /***********************************************************************
3835 * INTERNET_WorkerThreadFunc (internal)
3837 * Worker thread execution function
3839 * RETURNS
3842 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3844 task_header_t *task = lpvParam;
3846 TRACE("\n");
3848 task->proc(task);
3849 WININET_Release(task->hdr);
3850 heap_free(task);
3852 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3854 heap_free(TlsGetValue(g_dwTlsErrIndex));
3855 TlsSetValue(g_dwTlsErrIndex, NULL);
3857 return TRUE;
3860 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3862 task_header_t *task;
3864 task = heap_alloc(size);
3865 if(!task)
3866 return NULL;
3868 task->hdr = WININET_AddRef(hdr);
3869 task->proc = proc;
3870 return task;
3873 /***********************************************************************
3874 * INTERNET_AsyncCall (internal)
3876 * Retrieves work request from queue
3878 * RETURNS
3881 DWORD INTERNET_AsyncCall(task_header_t *task)
3883 BOOL bSuccess;
3885 TRACE("\n");
3887 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3888 if (!bSuccess)
3890 heap_free(task);
3891 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3893 return ERROR_SUCCESS;
3897 /***********************************************************************
3898 * INTERNET_GetResponseBuffer (internal)
3900 * RETURNS
3903 LPSTR INTERNET_GetResponseBuffer(void)
3905 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3906 if (!lpwite)
3907 lpwite = INTERNET_AllocThreadError();
3908 TRACE("\n");
3909 return lpwite->response;
3912 /***********************************************************************
3913 * INTERNET_GetNextLine (internal)
3915 * Parse next line in directory string listing
3917 * RETURNS
3918 * Pointer to beginning of next line
3919 * NULL on failure
3923 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3925 struct pollfd pfd;
3926 BOOL bSuccess = FALSE;
3927 INT nRecv = 0;
3928 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3930 TRACE("\n");
3932 pfd.fd = nSocket;
3933 pfd.events = POLLIN;
3935 while (nRecv < MAX_REPLY_LEN)
3937 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3939 if (sock_recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3941 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3942 goto lend;
3945 if (lpszBuffer[nRecv] == '\n')
3947 bSuccess = TRUE;
3948 break;
3950 if (lpszBuffer[nRecv] != '\r')
3951 nRecv++;
3953 else
3955 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3956 goto lend;
3960 lend:
3961 if (bSuccess)
3963 lpszBuffer[nRecv] = '\0';
3964 *dwLen = nRecv - 1;
3965 TRACE(":%d %s\n", nRecv, lpszBuffer);
3966 return lpszBuffer;
3968 else
3970 return NULL;
3974 /**********************************************************
3975 * InternetQueryDataAvailable (WININET.@)
3977 * Determines how much data is available to be read.
3979 * RETURNS
3980 * TRUE on success, FALSE if an error occurred. If
3981 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3982 * no data is presently available, FALSE is returned with
3983 * the last error ERROR_IO_PENDING; a callback with status
3984 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3985 * data is available.
3987 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3988 LPDWORD lpdwNumberOfBytesAvailable,
3989 DWORD dwFlags, DWORD_PTR dwContext)
3991 object_header_t *hdr;
3992 DWORD res;
3994 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3996 hdr = get_handle_object( hFile );
3997 if (!hdr) {
3998 SetLastError(ERROR_INVALID_HANDLE);
3999 return FALSE;
4002 if(hdr->vtbl->QueryDataAvailable) {
4003 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
4004 }else {
4005 WARN("wrong handle\n");
4006 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4009 WININET_Release(hdr);
4011 if(res != ERROR_SUCCESS)
4012 SetLastError(res);
4013 return res == ERROR_SUCCESS;
4016 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
4018 req_file_t *req_file;
4020 req_file = heap_alloc_zero(sizeof(*req_file));
4021 if(!req_file)
4022 return ERROR_NOT_ENOUGH_MEMORY;
4024 req_file->ref = 1;
4026 req_file->file_name = heap_strdupW(file_name);
4027 if(!req_file->file_name) {
4028 heap_free(req_file);
4029 return ERROR_NOT_ENOUGH_MEMORY;
4032 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
4033 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
4034 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
4035 req_file_release(req_file);
4036 return GetLastError();
4039 *ret = req_file;
4040 return ERROR_SUCCESS;
4043 void req_file_release(req_file_t *req_file)
4045 if(InterlockedDecrement(&req_file->ref))
4046 return;
4048 if(!req_file->is_committed)
4049 DeleteFileW(req_file->file_name);
4050 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
4051 CloseHandle(req_file->file_handle);
4052 heap_free(req_file->file_name);
4053 heap_free(req_file);
4056 /***********************************************************************
4057 * InternetLockRequestFile (WININET.@)
4059 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
4061 req_file_t *req_file = NULL;
4062 object_header_t *hdr;
4063 DWORD res;
4065 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
4067 hdr = get_handle_object(hInternet);
4068 if (!hdr) {
4069 SetLastError(ERROR_INVALID_HANDLE);
4070 return FALSE;
4073 if(hdr->vtbl->LockRequestFile) {
4074 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
4075 }else {
4076 WARN("wrong handle\n");
4077 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4080 WININET_Release(hdr);
4082 *lphLockReqHandle = req_file;
4083 if(res != ERROR_SUCCESS)
4084 SetLastError(res);
4085 return res == ERROR_SUCCESS;
4088 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
4090 TRACE("(%p)\n", hLockHandle);
4092 req_file_release(hLockHandle);
4093 return TRUE;
4097 /***********************************************************************
4098 * InternetAutodial (WININET.@)
4100 * On windows this function is supposed to dial the default internet
4101 * connection. We don't want to have Wine dial out to the internet so
4102 * we return TRUE by default. It might be nice to check if we are connected.
4104 * RETURNS
4105 * TRUE on success
4106 * FALSE on failure
4109 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4111 FIXME("STUB\n");
4113 /* Tell that we are connected to the internet. */
4114 return TRUE;
4117 /***********************************************************************
4118 * InternetAutodialHangup (WININET.@)
4120 * Hangs up a connection made with InternetAutodial
4122 * PARAM
4123 * dwReserved
4124 * RETURNS
4125 * TRUE on success
4126 * FALSE on failure
4129 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4131 FIXME("STUB\n");
4133 /* we didn't dial, we don't disconnect */
4134 return TRUE;
4137 /***********************************************************************
4138 * InternetCombineUrlA (WININET.@)
4140 * Combine a base URL with a relative URL
4142 * RETURNS
4143 * TRUE on success
4144 * FALSE on failure
4148 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4149 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4150 DWORD dwFlags)
4152 HRESULT hr=S_OK;
4154 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4156 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4157 dwFlags ^= ICU_NO_ENCODE;
4158 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4160 return (hr==S_OK);
4163 /***********************************************************************
4164 * InternetCombineUrlW (WININET.@)
4166 * Combine a base URL with a relative URL
4168 * RETURNS
4169 * TRUE on success
4170 * FALSE on failure
4174 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4175 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4176 DWORD dwFlags)
4178 HRESULT hr=S_OK;
4180 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4182 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4183 dwFlags ^= ICU_NO_ENCODE;
4184 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4186 return (hr==S_OK);
4189 /* max port num is 65535 => 5 digits */
4190 #define MAX_WORD_DIGITS 5
4192 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4193 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4194 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4195 (url)->dw##component##Length : strlen((url)->lpsz##component))
4197 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4199 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4200 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4201 return TRUE;
4202 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4203 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4204 return TRUE;
4205 if ((nScheme == INTERNET_SCHEME_FTP) &&
4206 (nPort == INTERNET_DEFAULT_FTP_PORT))
4207 return TRUE;
4208 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4209 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4210 return TRUE;
4212 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4213 return TRUE;
4215 return FALSE;
4218 /* opaque urls do not fit into the standard url hierarchy and don't have
4219 * two following slashes */
4220 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4222 return (nScheme != INTERNET_SCHEME_FTP) &&
4223 (nScheme != INTERNET_SCHEME_GOPHER) &&
4224 (nScheme != INTERNET_SCHEME_HTTP) &&
4225 (nScheme != INTERNET_SCHEME_HTTPS) &&
4226 (nScheme != INTERNET_SCHEME_FILE);
4229 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4231 int index;
4232 if (scheme < INTERNET_SCHEME_FIRST)
4233 return NULL;
4234 index = scheme - INTERNET_SCHEME_FIRST;
4235 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
4236 return NULL;
4237 return (LPCWSTR)url_schemes[index];
4240 /* we can calculate using ansi strings because we're just
4241 * calculating string length, not size
4243 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4244 LPDWORD lpdwUrlLength)
4246 INTERNET_SCHEME nScheme;
4248 *lpdwUrlLength = 0;
4250 if (lpUrlComponents->lpszScheme)
4252 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4253 *lpdwUrlLength += dwLen;
4254 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4256 else
4258 LPCWSTR scheme;
4260 nScheme = lpUrlComponents->nScheme;
4262 if (nScheme == INTERNET_SCHEME_DEFAULT)
4263 nScheme = INTERNET_SCHEME_HTTP;
4264 scheme = INTERNET_GetSchemeString(nScheme);
4265 *lpdwUrlLength += strlenW(scheme);
4268 (*lpdwUrlLength)++; /* ':' */
4269 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4270 *lpdwUrlLength += strlen("//");
4272 if (lpUrlComponents->lpszUserName)
4274 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4275 *lpdwUrlLength += strlen("@");
4277 else
4279 if (lpUrlComponents->lpszPassword)
4281 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4282 return FALSE;
4286 if (lpUrlComponents->lpszPassword)
4288 *lpdwUrlLength += strlen(":");
4289 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4292 if (lpUrlComponents->lpszHostName)
4294 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4296 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4298 char szPort[MAX_WORD_DIGITS+1];
4300 sprintf(szPort, "%d", lpUrlComponents->nPort);
4301 *lpdwUrlLength += strlen(szPort);
4302 *lpdwUrlLength += strlen(":");
4305 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4306 (*lpdwUrlLength)++; /* '/' */
4309 if (lpUrlComponents->lpszUrlPath)
4310 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4312 if (lpUrlComponents->lpszExtraInfo)
4313 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4315 return TRUE;
4318 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4320 INT len;
4322 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4324 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4325 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4326 urlCompW->nScheme = lpUrlComponents->nScheme;
4327 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4328 urlCompW->nPort = lpUrlComponents->nPort;
4329 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4330 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4331 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4332 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4334 if (lpUrlComponents->lpszScheme)
4336 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4337 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4338 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4339 -1, urlCompW->lpszScheme, len);
4342 if (lpUrlComponents->lpszHostName)
4344 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4345 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4346 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4347 -1, urlCompW->lpszHostName, len);
4350 if (lpUrlComponents->lpszUserName)
4352 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4353 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4354 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4355 -1, urlCompW->lpszUserName, len);
4358 if (lpUrlComponents->lpszPassword)
4360 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4361 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4362 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4363 -1, urlCompW->lpszPassword, len);
4366 if (lpUrlComponents->lpszUrlPath)
4368 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4369 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4370 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4371 -1, urlCompW->lpszUrlPath, len);
4374 if (lpUrlComponents->lpszExtraInfo)
4376 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4377 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4378 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4379 -1, urlCompW->lpszExtraInfo, len);
4383 /***********************************************************************
4384 * InternetCreateUrlA (WININET.@)
4386 * See InternetCreateUrlW.
4388 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4389 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4391 BOOL ret;
4392 LPWSTR urlW = NULL;
4393 URL_COMPONENTSW urlCompW;
4395 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4397 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4399 SetLastError(ERROR_INVALID_PARAMETER);
4400 return FALSE;
4403 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4405 if (lpszUrl)
4406 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4408 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4410 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4411 *lpdwUrlLength /= sizeof(WCHAR);
4413 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4414 * minus one, so add one to leave room for NULL terminator
4416 if (ret)
4417 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4419 heap_free(urlCompW.lpszScheme);
4420 heap_free(urlCompW.lpszHostName);
4421 heap_free(urlCompW.lpszUserName);
4422 heap_free(urlCompW.lpszPassword);
4423 heap_free(urlCompW.lpszUrlPath);
4424 heap_free(urlCompW.lpszExtraInfo);
4425 heap_free(urlW);
4426 return ret;
4429 /***********************************************************************
4430 * InternetCreateUrlW (WININET.@)
4432 * Creates a URL from its component parts.
4434 * PARAMS
4435 * lpUrlComponents [I] URL Components.
4436 * dwFlags [I] Flags. See notes.
4437 * lpszUrl [I] Buffer in which to store the created URL.
4438 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4439 * lpszUrl in characters. On output, the number of bytes
4440 * required to store the URL including terminator.
4442 * NOTES
4444 * The dwFlags parameter can be zero or more of the following:
4445 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4447 * RETURNS
4448 * TRUE on success
4449 * FALSE on failure
4452 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4453 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4455 DWORD dwLen;
4456 INTERNET_SCHEME nScheme;
4458 static const WCHAR slashSlashW[] = {'/','/'};
4459 static const WCHAR fmtW[] = {'%','u',0};
4461 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4463 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4465 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4466 return FALSE;
4469 if (!calc_url_length(lpUrlComponents, &dwLen))
4470 return FALSE;
4472 if (!lpszUrl || *lpdwUrlLength < dwLen)
4474 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4475 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4476 return FALSE;
4479 *lpdwUrlLength = dwLen;
4480 lpszUrl[0] = 0x00;
4482 dwLen = 0;
4484 if (lpUrlComponents->lpszScheme)
4486 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4487 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4488 lpszUrl += dwLen;
4490 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4492 else
4494 LPCWSTR scheme;
4495 nScheme = lpUrlComponents->nScheme;
4497 if (nScheme == INTERNET_SCHEME_DEFAULT)
4498 nScheme = INTERNET_SCHEME_HTTP;
4500 scheme = INTERNET_GetSchemeString(nScheme);
4501 dwLen = strlenW(scheme);
4502 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4503 lpszUrl += dwLen;
4506 /* all schemes are followed by at least a colon */
4507 *lpszUrl = ':';
4508 lpszUrl++;
4510 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4512 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4513 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4516 if (lpUrlComponents->lpszUserName)
4518 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4519 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4520 lpszUrl += dwLen;
4522 if (lpUrlComponents->lpszPassword)
4524 *lpszUrl = ':';
4525 lpszUrl++;
4527 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4528 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4529 lpszUrl += dwLen;
4532 *lpszUrl = '@';
4533 lpszUrl++;
4536 if (lpUrlComponents->lpszHostName)
4538 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4539 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4540 lpszUrl += dwLen;
4542 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4544 WCHAR szPort[MAX_WORD_DIGITS+1];
4546 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4547 *lpszUrl = ':';
4548 lpszUrl++;
4549 dwLen = strlenW(szPort);
4550 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4551 lpszUrl += dwLen;
4554 /* add slash between hostname and path if necessary */
4555 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4557 *lpszUrl = '/';
4558 lpszUrl++;
4562 if (lpUrlComponents->lpszUrlPath)
4564 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4565 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4566 lpszUrl += dwLen;
4569 if (lpUrlComponents->lpszExtraInfo)
4571 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4572 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4573 lpszUrl += dwLen;
4576 *lpszUrl = '\0';
4578 return TRUE;
4581 /***********************************************************************
4582 * InternetConfirmZoneCrossingA (WININET.@)
4585 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4587 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4588 return ERROR_SUCCESS;
4591 /***********************************************************************
4592 * InternetConfirmZoneCrossingW (WININET.@)
4595 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4597 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4598 return ERROR_SUCCESS;
4601 static DWORD zone_preference = 3;
4603 /***********************************************************************
4604 * PrivacySetZonePreferenceW (WININET.@)
4606 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4608 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4610 zone_preference = template;
4611 return 0;
4614 /***********************************************************************
4615 * PrivacyGetZonePreferenceW (WININET.@)
4617 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4618 LPWSTR preference, LPDWORD length )
4620 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4622 if (template) *template = zone_preference;
4623 return 0;
4626 /***********************************************************************
4627 * InternetGetSecurityInfoByURLA (WININET.@)
4629 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4631 WCHAR *url;
4632 BOOL res;
4634 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4636 url = heap_strdupAtoW(lpszURL);
4637 if(!url)
4638 return FALSE;
4640 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4641 heap_free(url);
4642 return res;
4645 /***********************************************************************
4646 * InternetGetSecurityInfoByURLW (WININET.@)
4648 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4650 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
4651 URL_COMPONENTSW url = {sizeof(url)};
4652 server_t *server;
4653 BOOL res = FALSE;
4655 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4657 url.lpszHostName = hostname;
4658 url.dwHostNameLength = sizeof(hostname)/sizeof(WCHAR);
4660 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4661 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4662 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4663 return FALSE;
4666 server = get_server(hostname, url.nPort, TRUE, FALSE);
4667 if(!server) {
4668 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4669 return FALSE;
4672 if(server->cert_chain) {
4673 const CERT_CHAIN_CONTEXT *chain_dup;
4675 chain_dup = CertDuplicateCertificateChain(server->cert_chain);
4676 if(chain_dup) {
4677 *ppCertChain = chain_dup;
4678 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4679 }else {
4680 res = FALSE;
4682 }else {
4683 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4684 res = FALSE;
4687 server_release(server);
4688 return res;
4691 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4692 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4694 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4695 lpdwConnection, dwReserved);
4696 return ERROR_SUCCESS;
4699 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4700 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4702 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4703 lpdwConnection, dwReserved);
4704 return ERROR_SUCCESS;
4707 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4709 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4710 return TRUE;
4713 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4715 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4716 return TRUE;
4719 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4721 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4722 return ERROR_SUCCESS;
4725 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4726 PBYTE pbHexHash )
4728 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4729 debugstr_w(pwszTarget), pbHexHash);
4730 return FALSE;
4733 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4735 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4736 return FALSE;
4739 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4741 FIXME("(%p, %08lx) stub\n", a, b);
4742 return FALSE;
4745 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4747 FIXME("%p: stub\n", parent);
4748 return 0;