wininet: Only parse proxy URLs taken from the environment.
[wine.git] / dlls / wininet / internet.c
blob30e8f60c0537b49c766a40449dde41a238c5f7ad
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "config.h"
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
33 #include <ws2tcpip.h>
34 #endif
36 #include <string.h>
37 #include <stdarg.h>
38 #include <stdio.h>
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
42 #endif
43 #ifdef HAVE_POLL_H
44 #include <poll.h>
45 #endif
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
48 #endif
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
51 #endif
52 #include <stdlib.h>
53 #include <ctype.h>
54 #ifdef HAVE_UNISTD_H
55 # include <unistd.h>
56 #endif
57 #include <assert.h>
59 #include "windef.h"
60 #include "winbase.h"
61 #include "winreg.h"
62 #include "winuser.h"
63 #include "wininet.h"
64 #include "winnls.h"
65 #include "wine/debug.h"
66 #include "winerror.h"
67 #define NO_SHLWAPI_STREAM
68 #include "shlwapi.h"
70 #include "wine/exception.h"
72 #include "internet.h"
73 #include "resource.h"
75 #include "wine/unicode.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
79 #define RESPONSE_TIMEOUT 30
81 typedef struct
83 DWORD dwError;
84 CHAR response[MAX_REPLY_LEN];
85 } WITHREADERROR, *LPWITHREADERROR;
87 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
88 HMODULE WININET_hModule;
90 static CRITICAL_SECTION WININET_cs;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
93 0, 0, &WININET_cs,
94 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
95 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
99 static object_header_t **handle_table;
100 static UINT_PTR next_handle;
101 static UINT_PTR handle_table_size;
103 typedef struct
105 DWORD proxyEnabled;
106 LPWSTR proxy;
107 LPWSTR proxyBypass;
108 LPWSTR proxyUsername;
109 LPWSTR proxyPassword;
110 } proxyinfo_t;
112 static ULONG max_conns = 2, max_1_0_conns = 4;
113 static ULONG connect_timeout = 60000;
115 static const WCHAR szInternetSettings[] =
116 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
117 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
118 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
119 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
120 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
121 static const WCHAR szProxyOverride[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
123 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
125 UINT_PTR handle = 0, num;
126 object_header_t *ret;
127 object_header_t **p;
128 BOOL res = TRUE;
130 ret = heap_alloc_zero(size);
131 if(!ret)
132 return NULL;
134 list_init(&ret->children);
136 EnterCriticalSection( &WININET_cs );
138 if(!handle_table_size) {
139 num = 16;
140 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
141 if(p) {
142 handle_table = p;
143 handle_table_size = num;
144 next_handle = 1;
145 }else {
146 res = FALSE;
148 }else if(next_handle == handle_table_size) {
149 num = handle_table_size * 2;
150 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
151 if(p) {
152 handle_table = p;
153 handle_table_size = num;
154 }else {
155 res = FALSE;
159 if(res) {
160 handle = next_handle;
161 if(handle_table[handle])
162 ERR("handle isn't free but should be\n");
163 handle_table[handle] = ret;
164 ret->valid_handle = TRUE;
166 while(handle_table[next_handle] && next_handle < handle_table_size)
167 next_handle++;
170 LeaveCriticalSection( &WININET_cs );
172 if(!res) {
173 heap_free(ret);
174 return NULL;
177 ret->vtbl = vtbl;
178 ret->refs = 1;
179 ret->hInternet = (HINTERNET)handle;
181 if(parent) {
182 ret->lpfnStatusCB = parent->lpfnStatusCB;
183 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
186 return ret;
189 object_header_t *WININET_AddRef( object_header_t *info )
191 ULONG refs = InterlockedIncrement(&info->refs);
192 TRACE("%p -> refcount = %d\n", info, refs );
193 return info;
196 object_header_t *get_handle_object( HINTERNET hinternet )
198 object_header_t *info = NULL;
199 UINT_PTR handle = (UINT_PTR) hinternet;
201 EnterCriticalSection( &WININET_cs );
203 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
204 info = WININET_AddRef(handle_table[handle]);
206 LeaveCriticalSection( &WININET_cs );
208 TRACE("handle %ld -> %p\n", handle, info);
210 return info;
213 static void invalidate_handle(object_header_t *info)
215 object_header_t *child, *next;
217 if(!info->valid_handle)
218 return;
219 info->valid_handle = FALSE;
221 /* Free all children as native does */
222 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
224 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
225 invalidate_handle( child );
228 WININET_Release(info);
231 BOOL WININET_Release( object_header_t *info )
233 ULONG refs = InterlockedDecrement(&info->refs);
234 TRACE( "object %p refcount = %d\n", info, refs );
235 if( !refs )
237 invalidate_handle(info);
238 if ( info->vtbl->CloseConnection )
240 TRACE( "closing connection %p\n", info);
241 info->vtbl->CloseConnection( info );
243 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
244 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
245 || !(info->dwInternalFlags & INET_OPENURL))
247 INTERNET_SendCallback(info, info->dwContext,
248 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
249 sizeof(HINTERNET));
251 TRACE( "destroying object %p\n", info);
252 if ( info->htype != WH_HINIT )
253 list_remove( &info->entry );
254 info->vtbl->Destroy( info );
256 if(info->hInternet) {
257 UINT_PTR handle = (UINT_PTR)info->hInternet;
259 EnterCriticalSection( &WININET_cs );
261 handle_table[handle] = NULL;
262 if(next_handle > handle)
263 next_handle = handle;
265 LeaveCriticalSection( &WININET_cs );
268 heap_free(info);
270 return TRUE;
273 /***********************************************************************
274 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
276 * PARAMS
277 * hinstDLL [I] handle to the DLL's instance
278 * fdwReason [I]
279 * lpvReserved [I] reserved, must be NULL
281 * RETURNS
282 * Success: TRUE
283 * Failure: FALSE
286 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
288 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
290 switch (fdwReason) {
291 case DLL_PROCESS_ATTACH:
293 g_dwTlsErrIndex = TlsAlloc();
295 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
296 return FALSE;
298 if(!init_urlcache())
300 TlsFree(g_dwTlsErrIndex);
301 return FALSE;
304 WININET_hModule = hinstDLL;
305 break;
307 case DLL_THREAD_ATTACH:
308 break;
310 case DLL_THREAD_DETACH:
311 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
313 heap_free(TlsGetValue(g_dwTlsErrIndex));
315 break;
317 case DLL_PROCESS_DETACH:
318 if (lpvReserved) break;
319 collect_connections(COLLECT_CLEANUP);
320 NETCON_unload();
321 free_urlcache();
322 free_cookie();
324 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
326 heap_free(TlsGetValue(g_dwTlsErrIndex));
327 TlsFree(g_dwTlsErrIndex);
329 break;
331 return TRUE;
334 /***********************************************************************
335 * INTERNET_SaveProxySettings
337 * Stores the proxy settings given by lpwai into the registry
339 * RETURNS
340 * ERROR_SUCCESS if no error, or error code on fail
342 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
344 HKEY key;
345 LONG ret;
347 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
348 return ret;
350 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
352 RegCloseKey( key );
353 return ret;
356 if (lpwpi->proxy)
358 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
360 RegCloseKey( key );
361 return ret;
364 else
366 if ((ret = RegDeleteValueW( key, szProxyServer )))
368 RegCloseKey( key );
369 return ret;
373 RegCloseKey(key);
374 return ERROR_SUCCESS;
377 /***********************************************************************
378 * INTERNET_FindProxyForProtocol
380 * Searches the proxy string for a proxy of the given protocol.
381 * Returns the found proxy, or the default proxy if none of the given
382 * protocol is found.
384 * PARAMETERS
385 * szProxy [In] proxy string to search
386 * proto [In] protocol to search for, e.g. "http"
387 * foundProxy [Out] found proxy
388 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
390 * RETURNS
391 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
392 * *foundProxyLen is set to the required size in WCHARs, including the
393 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
395 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
397 LPCWSTR ptr;
398 BOOL ret = FALSE;
400 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
402 /* First, look for the specified protocol (proto=scheme://host:port) */
403 for (ptr = szProxy; !ret && ptr && *ptr; )
405 LPCWSTR end, equal;
407 if (!(end = strchrW(ptr, ' ')))
408 end = ptr + strlenW(ptr);
409 if ((equal = strchrW(ptr, '=')) && equal < end &&
410 equal - ptr == strlenW(proto) &&
411 !strncmpiW(proto, ptr, strlenW(proto)))
413 if (end - equal > *foundProxyLen)
415 WARN("buffer too short for %s\n",
416 debugstr_wn(equal + 1, end - equal - 1));
417 *foundProxyLen = end - equal;
418 SetLastError(ERROR_INSUFFICIENT_BUFFER);
420 else
422 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
423 foundProxy[end - equal] = 0;
424 ret = TRUE;
427 if (*end == ' ')
428 ptr = end + 1;
429 else
430 ptr = end;
432 if (!ret)
434 /* It wasn't found: look for no protocol */
435 for (ptr = szProxy; !ret && ptr && *ptr; )
437 LPCWSTR end;
439 if (!(end = strchrW(ptr, ' ')))
440 end = ptr + strlenW(ptr);
441 if (!strchrW(ptr, '='))
443 if (end - ptr + 1 > *foundProxyLen)
445 WARN("buffer too short for %s\n",
446 debugstr_wn(ptr, end - ptr));
447 *foundProxyLen = end - ptr + 1;
448 SetLastError(ERROR_INSUFFICIENT_BUFFER);
450 else
452 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
453 foundProxy[end - ptr] = 0;
454 ret = TRUE;
457 if (*end == ' ')
458 ptr = end + 1;
459 else
460 ptr = end;
463 if (ret)
464 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
465 debugstr_w(foundProxy));
466 return ret;
469 /***********************************************************************
470 * InternetInitializeAutoProxyDll (WININET.@)
472 * Setup the internal proxy
474 * PARAMETERS
475 * dwReserved
477 * RETURNS
478 * FALSE on failure
481 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
483 FIXME("STUB\n");
484 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
485 return FALSE;
488 /***********************************************************************
489 * DetectAutoProxyUrl (WININET.@)
491 * Auto detect the proxy url
493 * RETURNS
494 * FALSE on failure
497 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
498 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
500 FIXME("STUB\n");
501 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
502 return FALSE;
505 static void FreeProxyInfo( proxyinfo_t *lpwpi )
507 heap_free(lpwpi->proxy);
508 heap_free(lpwpi->proxyBypass);
509 heap_free(lpwpi->proxyUsername);
510 heap_free(lpwpi->proxyPassword);
513 static proxyinfo_t *global_proxy;
515 static void free_global_proxy( void )
517 EnterCriticalSection( &WININET_cs );
518 if (global_proxy)
520 FreeProxyInfo( global_proxy );
521 heap_free( global_proxy );
523 LeaveCriticalSection( &WININET_cs );
526 static BOOL parse_proxy_url( proxyinfo_t *info, const WCHAR *url )
528 static const WCHAR fmt[] = {'%','s',':','%','u',0};
529 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH] = {};
530 WCHAR username[INTERNET_MAX_USER_NAME_LENGTH] = {};
531 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH] = {};
532 URL_COMPONENTSW uc;
534 memset( &uc, 0, sizeof(uc) );
535 uc.dwStructSize = sizeof(uc);
536 uc.lpszHostName = hostname;
537 uc.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
538 uc.lpszUserName = username;
539 uc.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
540 uc.lpszPassword = password;
541 uc.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
543 if (!InternetCrackUrlW( url, 0, 0, &uc )) return FALSE;
544 if (!hostname[0])
546 if (!(info->proxy = heap_strdupW( url ))) return FALSE;
547 info->proxyUsername = NULL;
548 info->proxyPassword = NULL;
549 return TRUE;
551 if (!(info->proxy = heap_alloc( (strlenW(hostname) + 12) * sizeof(WCHAR) ))) return FALSE;
552 sprintfW( info->proxy, fmt, hostname, uc.nPort );
554 if (!username[0]) info->proxyUsername = NULL;
555 else if (!(info->proxyUsername = heap_strdupW( username )))
557 heap_free( info->proxy );
558 return FALSE;
560 if (!password[0]) info->proxyPassword = NULL;
561 else if (!(info->proxyPassword = heap_strdupW( password )))
563 heap_free( info->proxyUsername );
564 heap_free( info->proxy );
565 return FALSE;
567 return TRUE;
570 /***********************************************************************
571 * INTERNET_LoadProxySettings
573 * Loads proxy information from process-wide global settings, the registry,
574 * or the environment into lpwpi.
576 * The caller should call FreeProxyInfo when done with lpwpi.
578 * FIXME:
579 * The proxy may be specified in the form 'http=proxy.my.org'
580 * Presumably that means there can be ftp=ftpproxy.my.org too.
582 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
584 HKEY key;
585 DWORD type, len;
586 LPCSTR envproxy;
587 LONG ret;
589 memset( lpwpi, 0, sizeof(*lpwpi) );
591 EnterCriticalSection( &WININET_cs );
592 if (global_proxy)
594 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
595 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
596 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
598 LeaveCriticalSection( &WININET_cs );
600 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
602 FreeProxyInfo( lpwpi );
603 return ret;
606 len = sizeof(DWORD);
607 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
609 lpwpi->proxyEnabled = 0;
610 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
612 FreeProxyInfo( lpwpi );
613 RegCloseKey( key );
614 return ret;
618 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->proxyEnabled)
620 /* figure out how much memory the proxy setting takes */
621 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
623 LPWSTR szProxy, p;
624 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
626 if (!(szProxy = heap_alloc(len)))
628 RegCloseKey( key );
629 FreeProxyInfo( lpwpi );
630 return ERROR_OUTOFMEMORY;
632 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
634 /* find the http proxy, and strip away everything else */
635 p = strstrW( szProxy, szHttp );
636 if (p)
638 p += lstrlenW( szHttp );
639 lstrcpyW( szProxy, p );
641 p = strchrW( szProxy, ';' );
642 if (p) *p = 0;
644 FreeProxyInfo( lpwpi );
645 lpwpi->proxy = szProxy;
646 lpwpi->proxyBypass = NULL;
648 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi->proxy));
650 else
652 TRACE("No proxy server settings in registry.\n");
653 FreeProxyInfo( lpwpi );
654 lpwpi->proxy = NULL;
655 lpwpi->proxyBypass = NULL;
658 else if (envproxy)
660 WCHAR *envproxyW;
662 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
663 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
665 RegCloseKey( key );
666 return ERROR_OUTOFMEMORY;
668 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
670 FreeProxyInfo( lpwpi );
671 if (parse_proxy_url( lpwpi, envproxyW ))
673 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
674 lpwpi->proxyEnabled = 1;
675 lpwpi->proxyBypass = NULL;
677 else
679 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW));
680 lpwpi->proxyEnabled = 0;
681 lpwpi->proxy = NULL;
682 lpwpi->proxyBypass = NULL;
684 heap_free( envproxyW );
687 if (lpwpi->proxyEnabled)
689 TRACE("Proxy is enabled.\n");
691 if (!(envproxy = getenv( "no_proxy" )))
693 /* figure out how much memory the proxy setting takes */
694 if (!RegQueryValueExW( key, szProxyOverride, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
696 LPWSTR szProxy;
698 if (!(szProxy = heap_alloc(len)))
700 RegCloseKey( key );
701 return ERROR_OUTOFMEMORY;
703 RegQueryValueExW( key, szProxyOverride, NULL, &type, (BYTE*)szProxy, &len );
705 heap_free( lpwpi->proxyBypass );
706 lpwpi->proxyBypass = szProxy;
708 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi->proxyBypass));
710 else
712 heap_free( lpwpi->proxyBypass );
713 lpwpi->proxyBypass = NULL;
715 TRACE("No proxy bypass server settings in registry.\n");
718 else
720 WCHAR *envproxyW;
722 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
723 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
725 RegCloseKey( key );
726 return ERROR_OUTOFMEMORY;
728 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
730 heap_free( lpwpi->proxyBypass );
731 lpwpi->proxyBypass = envproxyW;
733 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
736 else TRACE("Proxy is disabled.\n");
738 RegCloseKey( key );
739 return ERROR_SUCCESS;
742 /***********************************************************************
743 * INTERNET_ConfigureProxy
745 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
747 proxyinfo_t wpi;
749 if (INTERNET_LoadProxySettings( &wpi ))
750 return FALSE;
752 if (wpi.proxyEnabled)
754 TRACE("http proxy = %s bypass = %s\n", debugstr_w(lpwai->proxy), debugstr_w(lpwai->proxyBypass));
756 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
757 lpwai->proxy = wpi.proxy;
758 lpwai->proxyBypass = wpi.proxyBypass;
759 lpwai->proxyUsername = wpi.proxyUsername;
760 lpwai->proxyPassword = wpi.proxyPassword;
761 return TRUE;
764 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
765 FreeProxyInfo(&wpi);
766 return FALSE;
769 /***********************************************************************
770 * dump_INTERNET_FLAGS
772 * Helper function to TRACE the internet flags.
774 * RETURNS
775 * None
778 static void dump_INTERNET_FLAGS(DWORD dwFlags)
780 #define FE(x) { x, #x }
781 static const wininet_flag_info flag[] = {
782 FE(INTERNET_FLAG_RELOAD),
783 FE(INTERNET_FLAG_RAW_DATA),
784 FE(INTERNET_FLAG_EXISTING_CONNECT),
785 FE(INTERNET_FLAG_ASYNC),
786 FE(INTERNET_FLAG_PASSIVE),
787 FE(INTERNET_FLAG_NO_CACHE_WRITE),
788 FE(INTERNET_FLAG_MAKE_PERSISTENT),
789 FE(INTERNET_FLAG_FROM_CACHE),
790 FE(INTERNET_FLAG_SECURE),
791 FE(INTERNET_FLAG_KEEP_CONNECTION),
792 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
793 FE(INTERNET_FLAG_READ_PREFETCH),
794 FE(INTERNET_FLAG_NO_COOKIES),
795 FE(INTERNET_FLAG_NO_AUTH),
796 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
797 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
798 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
799 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
800 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
801 FE(INTERNET_FLAG_RESYNCHRONIZE),
802 FE(INTERNET_FLAG_HYPERLINK),
803 FE(INTERNET_FLAG_NO_UI),
804 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
805 FE(INTERNET_FLAG_CACHE_ASYNC),
806 FE(INTERNET_FLAG_FORMS_SUBMIT),
807 FE(INTERNET_FLAG_NEED_FILE),
808 FE(INTERNET_FLAG_TRANSFER_ASCII),
809 FE(INTERNET_FLAG_TRANSFER_BINARY)
811 #undef FE
812 unsigned int i;
814 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
815 if (flag[i].val & dwFlags) {
816 TRACE(" %s", flag[i].name);
817 dwFlags &= ~flag[i].val;
820 if (dwFlags)
821 TRACE(" Unknown flags (%08x)\n", dwFlags);
822 else
823 TRACE("\n");
826 /***********************************************************************
827 * INTERNET_CloseHandle (internal)
829 * Close internet handle
832 static VOID APPINFO_Destroy(object_header_t *hdr)
834 appinfo_t *lpwai = (appinfo_t*)hdr;
836 TRACE("%p\n",lpwai);
838 heap_free(lpwai->agent);
839 heap_free(lpwai->proxy);
840 heap_free(lpwai->proxyBypass);
841 heap_free(lpwai->proxyUsername);
842 heap_free(lpwai->proxyPassword);
845 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
847 appinfo_t *ai = (appinfo_t*)hdr;
849 switch(option) {
850 case INTERNET_OPTION_HANDLE_TYPE:
851 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
853 if (*size < sizeof(ULONG))
854 return ERROR_INSUFFICIENT_BUFFER;
856 *size = sizeof(DWORD);
857 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
858 return ERROR_SUCCESS;
860 case INTERNET_OPTION_USER_AGENT: {
861 DWORD bufsize;
863 TRACE("INTERNET_OPTION_USER_AGENT\n");
865 bufsize = *size;
867 if (unicode) {
868 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
870 *size = (len + 1) * sizeof(WCHAR);
871 if(!buffer || bufsize < *size)
872 return ERROR_INSUFFICIENT_BUFFER;
874 if (ai->agent)
875 strcpyW(buffer, ai->agent);
876 else
877 *(WCHAR *)buffer = 0;
878 /* If the buffer is copied, the returned length doesn't include
879 * the NULL terminator.
881 *size = len;
882 }else {
883 if (ai->agent)
884 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
885 else
886 *size = 1;
887 if(!buffer || bufsize < *size)
888 return ERROR_INSUFFICIENT_BUFFER;
890 if (ai->agent)
891 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
892 else
893 *(char *)buffer = 0;
894 /* If the buffer is copied, the returned length doesn't include
895 * the NULL terminator.
897 *size -= 1;
900 return ERROR_SUCCESS;
903 case INTERNET_OPTION_PROXY:
904 if(!size) return ERROR_INVALID_PARAMETER;
905 if (unicode) {
906 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
907 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
908 LPWSTR proxy, proxy_bypass;
910 if (ai->proxy)
911 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
912 if (ai->proxyBypass)
913 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
914 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
916 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
917 return ERROR_INSUFFICIENT_BUFFER;
919 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
920 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
922 pi->dwAccessType = ai->accessType;
923 pi->lpszProxy = NULL;
924 pi->lpszProxyBypass = NULL;
925 if (ai->proxy) {
926 lstrcpyW(proxy, ai->proxy);
927 pi->lpszProxy = proxy;
930 if (ai->proxyBypass) {
931 lstrcpyW(proxy_bypass, ai->proxyBypass);
932 pi->lpszProxyBypass = proxy_bypass;
935 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
936 return ERROR_SUCCESS;
937 }else {
938 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
939 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
940 LPSTR proxy, proxy_bypass;
942 if (ai->proxy)
943 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
944 if (ai->proxyBypass)
945 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
946 NULL, 0, NULL, NULL);
947 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
949 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
950 return ERROR_INSUFFICIENT_BUFFER;
952 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
953 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
955 pi->dwAccessType = ai->accessType;
956 pi->lpszProxy = NULL;
957 pi->lpszProxyBypass = NULL;
958 if (ai->proxy) {
959 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
960 pi->lpszProxy = proxy;
963 if (ai->proxyBypass) {
964 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
965 proxyBypassBytesRequired, NULL, NULL);
966 pi->lpszProxyBypass = proxy_bypass;
969 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
970 return ERROR_SUCCESS;
973 case INTERNET_OPTION_CONNECT_TIMEOUT:
974 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
976 if (*size < sizeof(ULONG))
977 return ERROR_INSUFFICIENT_BUFFER;
979 *(ULONG*)buffer = ai->connect_timeout;
980 *size = sizeof(ULONG);
982 return ERROR_SUCCESS;
985 return INET_QueryOption(hdr, option, buffer, size, unicode);
988 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
990 appinfo_t *ai = (appinfo_t*)hdr;
992 switch(option) {
993 case INTERNET_OPTION_CONNECT_TIMEOUT:
994 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
996 if(size != sizeof(connect_timeout))
997 return ERROR_INTERNET_BAD_OPTION_LENGTH;
998 if(!*(ULONG*)buf)
999 return ERROR_BAD_ARGUMENTS;
1001 ai->connect_timeout = *(ULONG*)buf;
1002 return ERROR_SUCCESS;
1003 case INTERNET_OPTION_USER_AGENT:
1004 heap_free(ai->agent);
1005 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
1006 return ERROR_SUCCESS;
1009 return INET_SetOption(hdr, option, buf, size);
1012 static const object_vtbl_t APPINFOVtbl = {
1013 APPINFO_Destroy,
1014 NULL,
1015 APPINFO_QueryOption,
1016 APPINFO_SetOption,
1017 NULL,
1018 NULL,
1019 NULL,
1020 NULL
1024 /***********************************************************************
1025 * InternetOpenW (WININET.@)
1027 * Per-application initialization of wininet
1029 * RETURNS
1030 * HINTERNET on success
1031 * NULL on failure
1034 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
1035 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
1037 appinfo_t *lpwai = NULL;
1039 if (TRACE_ON(wininet)) {
1040 #define FE(x) { x, #x }
1041 static const wininet_flag_info access_type[] = {
1042 FE(INTERNET_OPEN_TYPE_PRECONFIG),
1043 FE(INTERNET_OPEN_TYPE_DIRECT),
1044 FE(INTERNET_OPEN_TYPE_PROXY),
1045 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
1047 #undef FE
1048 DWORD i;
1049 const char *access_type_str = "Unknown";
1051 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
1052 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
1053 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
1054 if (access_type[i].val == dwAccessType) {
1055 access_type_str = access_type[i].name;
1056 break;
1059 TRACE(" access type : %s\n", access_type_str);
1060 TRACE(" flags :");
1061 dump_INTERNET_FLAGS(dwFlags);
1064 /* Clear any error information */
1065 INTERNET_SetLastError(0);
1067 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1068 SetLastError(ERROR_INVALID_PARAMETER);
1069 return NULL;
1072 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1073 if (!lpwai) {
1074 SetLastError(ERROR_OUTOFMEMORY);
1075 return NULL;
1078 lpwai->hdr.htype = WH_HINIT;
1079 lpwai->hdr.dwFlags = dwFlags;
1080 lpwai->accessType = dwAccessType;
1081 lpwai->proxyUsername = NULL;
1082 lpwai->proxyPassword = NULL;
1083 lpwai->connect_timeout = connect_timeout;
1085 lpwai->agent = heap_strdupW(lpszAgent);
1086 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1087 INTERNET_ConfigureProxy( lpwai );
1088 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1089 lpwai->proxy = heap_strdupW(lpszProxy);
1090 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1093 TRACE("returning %p\n", lpwai);
1095 return lpwai->hdr.hInternet;
1099 /***********************************************************************
1100 * InternetOpenA (WININET.@)
1102 * Per-application initialization of wininet
1104 * RETURNS
1105 * HINTERNET on success
1106 * NULL on failure
1109 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1110 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1112 WCHAR *szAgent, *szProxy, *szBypass;
1113 HINTERNET rc;
1115 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1116 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1118 szAgent = heap_strdupAtoW(lpszAgent);
1119 szProxy = heap_strdupAtoW(lpszProxy);
1120 szBypass = heap_strdupAtoW(lpszProxyBypass);
1122 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1124 heap_free(szAgent);
1125 heap_free(szProxy);
1126 heap_free(szBypass);
1127 return rc;
1130 /***********************************************************************
1131 * InternetGetLastResponseInfoA (WININET.@)
1133 * Return last wininet error description on the calling thread
1135 * RETURNS
1136 * TRUE on success of writing to buffer
1137 * FALSE on failure
1140 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1141 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1143 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1145 TRACE("\n");
1147 if (lpwite)
1149 *lpdwError = lpwite->dwError;
1150 if (lpwite->dwError)
1152 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1153 *lpdwBufferLength = strlen(lpszBuffer);
1155 else
1156 *lpdwBufferLength = 0;
1158 else
1160 *lpdwError = 0;
1161 *lpdwBufferLength = 0;
1164 return TRUE;
1167 /***********************************************************************
1168 * InternetGetLastResponseInfoW (WININET.@)
1170 * Return last wininet error description on the calling thread
1172 * RETURNS
1173 * TRUE on success of writing to buffer
1174 * FALSE on failure
1177 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1178 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1180 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1182 TRACE("\n");
1184 if (lpwite)
1186 *lpdwError = lpwite->dwError;
1187 if (lpwite->dwError)
1189 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1190 *lpdwBufferLength = lstrlenW(lpszBuffer);
1192 else
1193 *lpdwBufferLength = 0;
1195 else
1197 *lpdwError = 0;
1198 *lpdwBufferLength = 0;
1201 return TRUE;
1204 /***********************************************************************
1205 * InternetGetConnectedState (WININET.@)
1207 * Return connected state
1209 * RETURNS
1210 * TRUE if connected
1211 * if lpdwStatus is not null, return the status (off line,
1212 * modem, lan...) in it.
1213 * FALSE if not connected
1215 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1217 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1219 if (lpdwStatus) {
1220 WARN("always returning LAN connection.\n");
1221 *lpdwStatus = INTERNET_CONNECTION_LAN;
1223 return TRUE;
1227 /***********************************************************************
1228 * InternetGetConnectedStateExW (WININET.@)
1230 * Return connected state
1232 * PARAMS
1234 * lpdwStatus [O] Flags specifying the status of the internet connection.
1235 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1236 * dwNameLen [I] Size of the buffer, in characters.
1237 * dwReserved [I] Reserved. Must be set to 0.
1239 * RETURNS
1240 * TRUE if connected
1241 * if lpdwStatus is not null, return the status (off line,
1242 * modem, lan...) in it.
1243 * FALSE if not connected
1245 * NOTES
1246 * If the system has no available network connections, an empty string is
1247 * stored in lpszConnectionName. If there is a LAN connection, a localized
1248 * "LAN Connection" string is stored. Presumably, if only a dial-up
1249 * connection is available then the name of the dial-up connection is
1250 * returned. Why any application, other than the "Internet Settings" CPL,
1251 * would want to use this function instead of the simpler InternetGetConnectedStateW
1252 * function is beyond me.
1254 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1255 DWORD dwNameLen, DWORD dwReserved)
1257 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1259 /* Must be zero */
1260 if(dwReserved)
1261 return FALSE;
1263 if (lpdwStatus) {
1264 WARN("always returning LAN connection.\n");
1265 *lpdwStatus = INTERNET_CONNECTION_LAN;
1267 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen) > 0;
1271 /***********************************************************************
1272 * InternetGetConnectedStateExA (WININET.@)
1274 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1275 DWORD dwNameLen, DWORD dwReserved)
1277 LPWSTR lpwszConnectionName = NULL;
1278 BOOL rc;
1280 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1282 if (lpszConnectionName && dwNameLen > 0)
1283 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1285 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1286 dwReserved);
1287 if (rc && lpwszConnectionName)
1289 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1290 dwNameLen, NULL, NULL);
1291 heap_free(lpwszConnectionName);
1293 return rc;
1297 /***********************************************************************
1298 * InternetConnectW (WININET.@)
1300 * Open a ftp, gopher or http session
1302 * RETURNS
1303 * HINTERNET a session handle on success
1304 * NULL on failure
1307 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1308 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1309 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1310 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1312 appinfo_t *hIC;
1313 HINTERNET rc = NULL;
1314 DWORD res = ERROR_SUCCESS;
1316 TRACE("(%p, %s, %i, %s, %s, %i, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1317 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1318 dwService, dwFlags, dwContext);
1320 if (!lpszServerName)
1322 SetLastError(ERROR_INVALID_PARAMETER);
1323 return NULL;
1326 hIC = (appinfo_t*)get_handle_object( hInternet );
1327 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1329 res = ERROR_INVALID_HANDLE;
1330 goto lend;
1333 switch (dwService)
1335 case INTERNET_SERVICE_FTP:
1336 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1337 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1338 if(!rc)
1339 res = INTERNET_GetLastError();
1340 break;
1342 case INTERNET_SERVICE_HTTP:
1343 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1344 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1345 break;
1347 case INTERNET_SERVICE_GOPHER:
1348 default:
1349 break;
1351 lend:
1352 if( hIC )
1353 WININET_Release( &hIC->hdr );
1355 TRACE("returning %p\n", rc);
1356 SetLastError(res);
1357 return rc;
1361 /***********************************************************************
1362 * InternetConnectA (WININET.@)
1364 * Open a ftp, gopher or http session
1366 * RETURNS
1367 * HINTERNET a session handle on success
1368 * NULL on failure
1371 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1372 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1373 LPCSTR lpszUserName, LPCSTR lpszPassword,
1374 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1376 HINTERNET rc = NULL;
1377 LPWSTR szServerName;
1378 LPWSTR szUserName;
1379 LPWSTR szPassword;
1381 szServerName = heap_strdupAtoW(lpszServerName);
1382 szUserName = heap_strdupAtoW(lpszUserName);
1383 szPassword = heap_strdupAtoW(lpszPassword);
1385 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1386 szUserName, szPassword, dwService, dwFlags, dwContext);
1388 heap_free(szServerName);
1389 heap_free(szUserName);
1390 heap_free(szPassword);
1391 return rc;
1395 /***********************************************************************
1396 * InternetFindNextFileA (WININET.@)
1398 * Continues a file search from a previous call to FindFirstFile
1400 * RETURNS
1401 * TRUE on success
1402 * FALSE on failure
1405 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1407 BOOL ret;
1408 WIN32_FIND_DATAW fd;
1410 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1411 if(lpvFindData)
1412 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1413 return ret;
1416 /***********************************************************************
1417 * InternetFindNextFileW (WININET.@)
1419 * Continues a file search from a previous call to FindFirstFile
1421 * RETURNS
1422 * TRUE on success
1423 * FALSE on failure
1426 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1428 object_header_t *hdr;
1429 DWORD res;
1431 TRACE("\n");
1433 hdr = get_handle_object(hFind);
1434 if(!hdr) {
1435 WARN("Invalid handle\n");
1436 SetLastError(ERROR_INVALID_HANDLE);
1437 return FALSE;
1440 if(hdr->vtbl->FindNextFileW) {
1441 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1442 }else {
1443 WARN("Handle doesn't support NextFile\n");
1444 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1447 WININET_Release(hdr);
1449 if(res != ERROR_SUCCESS)
1450 SetLastError(res);
1451 return res == ERROR_SUCCESS;
1454 /***********************************************************************
1455 * InternetCloseHandle (WININET.@)
1457 * Generic close handle function
1459 * RETURNS
1460 * TRUE on success
1461 * FALSE on failure
1464 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1466 object_header_t *obj;
1468 TRACE("%p\n", hInternet);
1470 obj = get_handle_object( hInternet );
1471 if (!obj) {
1472 SetLastError(ERROR_INVALID_HANDLE);
1473 return FALSE;
1476 invalidate_handle(obj);
1477 WININET_Release(obj);
1479 return TRUE;
1483 /***********************************************************************
1484 * ConvertUrlComponentValue (Internal)
1486 * Helper function for InternetCrackUrlA
1489 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1490 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1491 LPCSTR lpszStart, LPCWSTR lpwszStart)
1493 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1494 if (*dwComponentLen != 0)
1496 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1497 if (*lppszComponent == NULL)
1499 if (lpwszComponent)
1501 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1502 *lppszComponent = (LPSTR)lpszStart + offset;
1504 else
1505 *lppszComponent = NULL;
1507 *dwComponentLen = nASCIILength;
1509 else
1511 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1512 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1513 (*lppszComponent)[ncpylen]=0;
1514 *dwComponentLen = ncpylen;
1520 /***********************************************************************
1521 * InternetCrackUrlA (WININET.@)
1523 * See InternetCrackUrlW.
1525 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1526 LPURL_COMPONENTSA lpUrlComponents)
1528 DWORD nLength;
1529 URL_COMPONENTSW UCW;
1530 BOOL ret = FALSE;
1531 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1532 *scheme = NULL, *extra = NULL;
1534 TRACE("(%s %u %x %p)\n",
1535 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1536 dwUrlLength, dwFlags, lpUrlComponents);
1538 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1539 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1541 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1542 return FALSE;
1545 if(dwUrlLength<=0)
1546 dwUrlLength=-1;
1547 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1549 /* if dwUrlLength=-1 then nLength includes null but length to
1550 InternetCrackUrlW should not include it */
1551 if (dwUrlLength == -1) nLength--;
1553 lpwszUrl = heap_alloc((nLength + 1) * sizeof(WCHAR));
1554 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1555 lpwszUrl[nLength] = '\0';
1557 memset(&UCW,0,sizeof(UCW));
1558 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1559 if (lpUrlComponents->dwHostNameLength)
1561 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1562 if (lpUrlComponents->lpszHostName)
1564 hostname = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1565 UCW.lpszHostName = hostname;
1568 if (lpUrlComponents->dwUserNameLength)
1570 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1571 if (lpUrlComponents->lpszUserName)
1573 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1574 UCW.lpszUserName = username;
1577 if (lpUrlComponents->dwPasswordLength)
1579 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1580 if (lpUrlComponents->lpszPassword)
1582 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1583 UCW.lpszPassword = password;
1586 if (lpUrlComponents->dwUrlPathLength)
1588 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1589 if (lpUrlComponents->lpszUrlPath)
1591 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1592 UCW.lpszUrlPath = path;
1595 if (lpUrlComponents->dwSchemeLength)
1597 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1598 if (lpUrlComponents->lpszScheme)
1600 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1601 UCW.lpszScheme = scheme;
1604 if (lpUrlComponents->dwExtraInfoLength)
1606 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1607 if (lpUrlComponents->lpszExtraInfo)
1609 extra = heap_alloc(UCW.dwExtraInfoLength * sizeof(WCHAR));
1610 UCW.lpszExtraInfo = extra;
1613 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1615 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1616 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1617 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1618 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1619 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1620 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1621 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1622 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1623 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1624 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1625 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1626 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1628 lpUrlComponents->nScheme = UCW.nScheme;
1629 lpUrlComponents->nPort = UCW.nPort;
1631 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1632 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1633 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1634 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1635 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1637 heap_free(lpwszUrl);
1638 heap_free(hostname);
1639 heap_free(username);
1640 heap_free(password);
1641 heap_free(path);
1642 heap_free(scheme);
1643 heap_free(extra);
1644 return ret;
1647 static const WCHAR url_schemes[][7] =
1649 {'f','t','p',0},
1650 {'g','o','p','h','e','r',0},
1651 {'h','t','t','p',0},
1652 {'h','t','t','p','s',0},
1653 {'f','i','l','e',0},
1654 {'n','e','w','s',0},
1655 {'m','a','i','l','t','o',0},
1656 {'r','e','s',0},
1659 /***********************************************************************
1660 * GetInternetSchemeW (internal)
1662 * Get scheme of url
1664 * RETURNS
1665 * scheme on success
1666 * INTERNET_SCHEME_UNKNOWN on failure
1669 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1671 int i;
1673 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1675 if(lpszScheme==NULL)
1676 return INTERNET_SCHEME_UNKNOWN;
1678 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1679 if (!strncmpiW(lpszScheme, url_schemes[i], nMaxCmp))
1680 return INTERNET_SCHEME_FIRST + i;
1682 return INTERNET_SCHEME_UNKNOWN;
1685 /***********************************************************************
1686 * SetUrlComponentValueW (Internal)
1688 * Helper function for InternetCrackUrlW
1690 * PARAMS
1691 * lppszComponent [O] Holds the returned string
1692 * dwComponentLen [I] Holds the size of lppszComponent
1693 * [O] Holds the length of the string in lppszComponent without '\0'
1694 * lpszStart [I] Holds the string to copy from
1695 * len [I] Holds the length of lpszStart without '\0'
1697 * RETURNS
1698 * TRUE on success
1699 * FALSE on failure
1702 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1704 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1706 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1707 return FALSE;
1709 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1711 if (*lppszComponent == NULL)
1713 *lppszComponent = (LPWSTR)lpszStart;
1714 *dwComponentLen = len;
1716 else
1718 DWORD ncpylen = min((*dwComponentLen)-1, len);
1719 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1720 (*lppszComponent)[ncpylen] = '\0';
1721 *dwComponentLen = ncpylen;
1725 return TRUE;
1728 /***********************************************************************
1729 * InternetCrackUrlW (WININET.@)
1731 * Break up URL into its components
1733 * RETURNS
1734 * TRUE on success
1735 * FALSE on failure
1737 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1738 LPURL_COMPONENTSW lpUC)
1741 * RFC 1808
1742 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1745 LPCWSTR lpszParam = NULL;
1746 BOOL found_colon = FALSE;
1747 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1748 LPCWSTR lpszcp = NULL, lpszNetLoc;
1749 LPWSTR lpszUrl_decode = NULL;
1750 DWORD dwUrlLength = dwUrlLength_orig;
1752 TRACE("(%s %u %x %p)\n",
1753 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1754 dwUrlLength, dwFlags, lpUC);
1756 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1758 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1759 return FALSE;
1761 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1763 if (dwFlags & ICU_DECODE)
1765 WCHAR *url_tmp;
1766 DWORD len = dwUrlLength + 1;
1768 if (!(url_tmp = heap_alloc(len * sizeof(WCHAR))))
1770 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1771 return FALSE;
1773 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1774 url_tmp[dwUrlLength] = 0;
1775 if (!(lpszUrl_decode = heap_alloc(len * sizeof(WCHAR))))
1777 heap_free(url_tmp);
1778 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1779 return FALSE;
1781 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1783 dwUrlLength = len;
1784 lpszUrl = lpszUrl_decode;
1786 heap_free(url_tmp);
1788 lpszap = lpszUrl;
1790 /* Determine if the URI is absolute. */
1791 while (lpszap - lpszUrl < dwUrlLength)
1793 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1795 lpszap++;
1796 continue;
1798 if (*lpszap == ':')
1800 found_colon = TRUE;
1801 lpszcp = lpszap;
1803 else
1805 lpszcp = lpszUrl; /* Relative url */
1808 break;
1811 if(!found_colon){
1812 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1813 return FALSE;
1816 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1817 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1819 /* Parse <params> */
1820 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1821 if(!lpszParam)
1822 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1824 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1825 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1828 /* Get scheme first. */
1829 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1830 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1831 lpszUrl, lpszcp - lpszUrl);
1833 /* Eat ':' in protocol. */
1834 lpszcp++;
1836 /* double slash indicates the net_loc portion is present */
1837 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1839 lpszcp += 2;
1841 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1842 if (lpszParam)
1844 if (lpszNetLoc)
1845 lpszNetLoc = min(lpszNetLoc, lpszParam);
1846 else
1847 lpszNetLoc = lpszParam;
1849 else if (!lpszNetLoc)
1850 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1852 /* Parse net-loc */
1853 if (lpszNetLoc)
1855 LPCWSTR lpszHost;
1856 LPCWSTR lpszPort;
1858 /* [<user>[<:password>]@]<host>[:<port>] */
1859 /* First find the user and password if they exist */
1861 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1862 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1864 /* username and password not specified. */
1865 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1866 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1868 else /* Parse out username and password */
1870 LPCWSTR lpszUser = lpszcp;
1871 LPCWSTR lpszPasswd = lpszHost;
1873 while (lpszcp < lpszHost)
1875 if (*lpszcp == ':')
1876 lpszPasswd = lpszcp;
1878 lpszcp++;
1881 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1882 lpszUser, lpszPasswd - lpszUser);
1884 if (lpszPasswd != lpszHost)
1885 lpszPasswd++;
1886 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1887 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1888 lpszHost - lpszPasswd);
1890 lpszcp++; /* Advance to beginning of host */
1893 /* Parse <host><:port> */
1895 lpszHost = lpszcp;
1896 lpszPort = lpszNetLoc;
1898 /* special case for res:// URLs: there is no port here, so the host is the
1899 entire string up to the first '/' */
1900 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1902 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1903 lpszHost, lpszPort - lpszHost);
1904 lpszcp=lpszNetLoc;
1906 else
1908 while (lpszcp < lpszNetLoc)
1910 if (*lpszcp == ':')
1911 lpszPort = lpszcp;
1913 lpszcp++;
1916 /* If the scheme is "file" and the host is just one letter, it's not a host */
1917 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1919 lpszcp=lpszHost;
1920 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1921 NULL, 0);
1923 else
1925 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1926 lpszHost, lpszPort - lpszHost);
1927 if (lpszPort != lpszNetLoc)
1928 lpUC->nPort = atoiW(++lpszPort);
1929 else switch (lpUC->nScheme)
1931 case INTERNET_SCHEME_HTTP:
1932 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1933 break;
1934 case INTERNET_SCHEME_HTTPS:
1935 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1936 break;
1937 case INTERNET_SCHEME_FTP:
1938 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1939 break;
1940 case INTERNET_SCHEME_GOPHER:
1941 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1942 break;
1943 default:
1944 break;
1950 else
1952 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1953 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1954 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1957 /* Here lpszcp points to:
1959 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1960 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1962 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1964 DWORD len;
1966 /* Only truncate the parameter list if it's already been saved
1967 * in lpUC->lpszExtraInfo.
1969 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1970 len = lpszParam - lpszcp;
1971 else
1973 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1974 * newlines if necessary.
1976 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1977 if (lpsznewline != NULL)
1978 len = lpsznewline - lpszcp;
1979 else
1980 len = dwUrlLength-(lpszcp-lpszUrl);
1982 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1983 lpUC->nScheme == INTERNET_SCHEME_FILE)
1985 WCHAR tmppath[MAX_PATH];
1986 if (*lpszcp == '/')
1988 len = MAX_PATH;
1989 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
1991 else
1993 WCHAR *iter;
1994 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1995 tmppath[len] = '\0';
1997 iter = tmppath;
1998 while (*iter) {
1999 if (*iter == '/')
2000 *iter = '\\';
2001 ++iter;
2004 /* if ends in \. or \.. append a backslash */
2005 if (tmppath[len - 1] == '.' &&
2006 (tmppath[len - 2] == '\\' ||
2007 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
2009 if (len < MAX_PATH - 1)
2011 tmppath[len] = '\\';
2012 tmppath[len+1] = '\0';
2013 ++len;
2016 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
2017 tmppath, len);
2019 else
2020 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
2021 lpszcp, len);
2023 else
2025 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
2026 lpUC->lpszUrlPath[0] = 0;
2027 lpUC->dwUrlPathLength = 0;
2030 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
2031 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
2032 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
2033 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
2034 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
2036 heap_free( lpszUrl_decode );
2037 return TRUE;
2040 /***********************************************************************
2041 * InternetAttemptConnect (WININET.@)
2043 * Attempt to make a connection to the internet
2045 * RETURNS
2046 * ERROR_SUCCESS on success
2047 * Error value on failure
2050 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
2052 FIXME("Stub\n");
2053 return ERROR_SUCCESS;
2057 /***********************************************************************
2058 * convert_url_canonicalization_flags
2060 * Helper for InternetCanonicalizeUrl
2062 * PARAMS
2063 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2065 * RETURNS
2066 * Flags suitable for UrlCanonicalize
2068 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
2070 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
2072 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
2073 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
2074 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
2075 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
2076 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2077 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
2078 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
2080 return dwUrlFlags;
2083 /***********************************************************************
2084 * InternetCanonicalizeUrlA (WININET.@)
2086 * Escape unsafe characters and spaces
2088 * RETURNS
2089 * TRUE on success
2090 * FALSE on failure
2093 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
2094 LPDWORD lpdwBufferLength, DWORD dwFlags)
2096 HRESULT hr;
2098 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
2099 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2101 dwFlags = convert_url_canonicalization_flags(dwFlags);
2102 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2103 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2104 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2106 return hr == S_OK;
2109 /***********************************************************************
2110 * InternetCanonicalizeUrlW (WININET.@)
2112 * Escape unsafe characters and spaces
2114 * RETURNS
2115 * TRUE on success
2116 * FALSE on failure
2119 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
2120 LPDWORD lpdwBufferLength, DWORD dwFlags)
2122 HRESULT hr;
2124 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2125 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2127 dwFlags = convert_url_canonicalization_flags(dwFlags);
2128 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2129 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2130 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2132 return hr == S_OK;
2135 /* #################################################### */
2137 static INTERNET_STATUS_CALLBACK set_status_callback(
2138 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2140 INTERNET_STATUS_CALLBACK ret;
2142 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2143 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2145 ret = lpwh->lpfnStatusCB;
2146 lpwh->lpfnStatusCB = callback;
2148 return ret;
2151 /***********************************************************************
2152 * InternetSetStatusCallbackA (WININET.@)
2154 * Sets up a callback function which is called as progress is made
2155 * during an operation.
2157 * RETURNS
2158 * Previous callback or NULL on success
2159 * INTERNET_INVALID_STATUS_CALLBACK on failure
2162 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2163 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2165 INTERNET_STATUS_CALLBACK retVal;
2166 object_header_t *lpwh;
2168 TRACE("%p\n", hInternet);
2170 if (!(lpwh = get_handle_object(hInternet)))
2171 return INTERNET_INVALID_STATUS_CALLBACK;
2173 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2175 WININET_Release( lpwh );
2176 return retVal;
2179 /***********************************************************************
2180 * InternetSetStatusCallbackW (WININET.@)
2182 * Sets up a callback function which is called as progress is made
2183 * during an operation.
2185 * RETURNS
2186 * Previous callback or NULL on success
2187 * INTERNET_INVALID_STATUS_CALLBACK on failure
2190 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2191 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2193 INTERNET_STATUS_CALLBACK retVal;
2194 object_header_t *lpwh;
2196 TRACE("%p\n", hInternet);
2198 if (!(lpwh = get_handle_object(hInternet)))
2199 return INTERNET_INVALID_STATUS_CALLBACK;
2201 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2203 WININET_Release( lpwh );
2204 return retVal;
2207 /***********************************************************************
2208 * InternetSetFilePointer (WININET.@)
2210 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2211 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2213 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2214 return FALSE;
2217 /***********************************************************************
2218 * InternetWriteFile (WININET.@)
2220 * Write data to an open internet file
2222 * RETURNS
2223 * TRUE on success
2224 * FALSE on failure
2227 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2228 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2230 object_header_t *lpwh;
2231 BOOL res;
2233 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2235 lpwh = get_handle_object( hFile );
2236 if (!lpwh) {
2237 WARN("Invalid handle\n");
2238 SetLastError(ERROR_INVALID_HANDLE);
2239 return FALSE;
2242 if(lpwh->vtbl->WriteFile) {
2243 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2244 }else {
2245 WARN("No Writefile method.\n");
2246 res = ERROR_INVALID_HANDLE;
2249 WININET_Release( lpwh );
2251 if(res != ERROR_SUCCESS)
2252 SetLastError(res);
2253 return res == ERROR_SUCCESS;
2257 /***********************************************************************
2258 * InternetReadFile (WININET.@)
2260 * Read data from an open internet file
2262 * RETURNS
2263 * TRUE on success
2264 * FALSE on failure
2267 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2268 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2270 object_header_t *hdr;
2271 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2273 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2275 hdr = get_handle_object(hFile);
2276 if (!hdr) {
2277 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2278 return FALSE;
2281 if(hdr->vtbl->ReadFile)
2282 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2284 WININET_Release(hdr);
2286 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2287 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2289 if(res != ERROR_SUCCESS)
2290 SetLastError(res);
2291 return res == ERROR_SUCCESS;
2294 /***********************************************************************
2295 * InternetReadFileExA (WININET.@)
2297 * Read data from an open internet file
2299 * PARAMS
2300 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2301 * lpBuffersOut [I/O] Buffer.
2302 * dwFlags [I] Flags. See notes.
2303 * dwContext [I] Context for callbacks.
2305 * RETURNS
2306 * TRUE on success
2307 * FALSE on failure
2309 * NOTES
2310 * The parameter dwFlags include zero or more of the following flags:
2311 *|IRF_ASYNC - Makes the call asynchronous.
2312 *|IRF_SYNC - Makes the call synchronous.
2313 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2314 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2316 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2318 * SEE
2319 * InternetOpenUrlA(), HttpOpenRequestA()
2321 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2322 DWORD dwFlags, DWORD_PTR dwContext)
2324 object_header_t *hdr;
2325 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2327 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2329 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2330 SetLastError(ERROR_INVALID_PARAMETER);
2331 return FALSE;
2334 hdr = get_handle_object(hFile);
2335 if (!hdr) {
2336 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2337 return FALSE;
2340 if(hdr->vtbl->ReadFileEx)
2341 res = hdr->vtbl->ReadFileEx(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2342 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2344 WININET_Release(hdr);
2346 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2347 res, lpBuffersOut->dwBufferLength);
2349 if(res != ERROR_SUCCESS)
2350 SetLastError(res);
2351 return res == ERROR_SUCCESS;
2354 /***********************************************************************
2355 * InternetReadFileExW (WININET.@)
2356 * SEE
2357 * InternetReadFileExA()
2359 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2360 DWORD dwFlags, DWORD_PTR dwContext)
2362 object_header_t *hdr;
2363 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2365 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2367 if (lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2368 SetLastError(ERROR_INVALID_PARAMETER);
2369 return FALSE;
2372 hdr = get_handle_object(hFile);
2373 if (!hdr) {
2374 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2375 return FALSE;
2378 if(hdr->vtbl->ReadFileEx)
2379 res = hdr->vtbl->ReadFileEx(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2380 dwFlags, dwContext);
2382 WININET_Release(hdr);
2384 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2385 res, lpBuffer->dwBufferLength);
2387 if(res != ERROR_SUCCESS)
2388 SetLastError(res);
2389 return res == ERROR_SUCCESS;
2392 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2394 /* FIXME: This function currently handles more options than it should. Options requiring
2395 * proper handles should be moved to proper functions */
2396 switch(option) {
2397 case INTERNET_OPTION_HTTP_VERSION:
2398 if (*size < sizeof(HTTP_VERSION_INFO))
2399 return ERROR_INSUFFICIENT_BUFFER;
2402 * Presently hardcoded to 1.1
2404 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2405 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2406 *size = sizeof(HTTP_VERSION_INFO);
2408 return ERROR_SUCCESS;
2410 case INTERNET_OPTION_CONNECTED_STATE:
2411 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2413 if (*size < sizeof(ULONG))
2414 return ERROR_INSUFFICIENT_BUFFER;
2416 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2417 *size = sizeof(ULONG);
2419 return ERROR_SUCCESS;
2421 case INTERNET_OPTION_PROXY: {
2422 appinfo_t ai;
2423 BOOL ret;
2425 TRACE("Getting global proxy info\n");
2426 memset(&ai, 0, sizeof(appinfo_t));
2427 INTERNET_ConfigureProxy(&ai);
2429 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2430 APPINFO_Destroy(&ai.hdr);
2431 return ret;
2434 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2435 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2437 if (*size < sizeof(ULONG))
2438 return ERROR_INSUFFICIENT_BUFFER;
2440 *(ULONG*)buffer = max_conns;
2441 *size = sizeof(ULONG);
2443 return ERROR_SUCCESS;
2445 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2446 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2448 if (*size < sizeof(ULONG))
2449 return ERROR_INSUFFICIENT_BUFFER;
2451 *(ULONG*)buffer = max_1_0_conns;
2452 *size = sizeof(ULONG);
2454 return ERROR_SUCCESS;
2456 case INTERNET_OPTION_SECURITY_FLAGS:
2457 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2458 return ERROR_SUCCESS;
2460 case INTERNET_OPTION_VERSION: {
2461 static const INTERNET_VERSION_INFO info = { 1, 2 };
2463 TRACE("INTERNET_OPTION_VERSION\n");
2465 if (*size < sizeof(INTERNET_VERSION_INFO))
2466 return ERROR_INSUFFICIENT_BUFFER;
2468 memcpy(buffer, &info, sizeof(info));
2469 *size = sizeof(info);
2471 return ERROR_SUCCESS;
2474 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2475 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2476 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2477 DWORD res = ERROR_SUCCESS, i;
2478 proxyinfo_t pi;
2479 LONG ret;
2481 TRACE("Getting global proxy info\n");
2482 if((ret = INTERNET_LoadProxySettings(&pi)))
2483 return ret;
2485 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2487 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2488 FreeProxyInfo(&pi);
2489 return ERROR_INSUFFICIENT_BUFFER;
2492 for (i = 0; i < con->dwOptionCount; i++) {
2493 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2494 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2496 switch (optionW->dwOption) {
2497 case INTERNET_PER_CONN_FLAGS:
2498 if(pi.proxyEnabled)
2499 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2500 else
2501 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2502 break;
2504 case INTERNET_PER_CONN_PROXY_SERVER:
2505 if (unicode)
2506 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2507 else
2508 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2509 break;
2511 case INTERNET_PER_CONN_PROXY_BYPASS:
2512 if (unicode)
2513 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2514 else
2515 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2516 break;
2518 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2519 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2520 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2521 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2522 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2523 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2524 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2525 memset(&optionW->Value, 0, sizeof(optionW->Value));
2526 break;
2528 default:
2529 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2530 res = ERROR_INVALID_PARAMETER;
2531 break;
2534 FreeProxyInfo(&pi);
2536 return res;
2538 case INTERNET_OPTION_REQUEST_FLAGS:
2539 case INTERNET_OPTION_USER_AGENT:
2540 *size = 0;
2541 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2542 case INTERNET_OPTION_POLICY:
2543 return ERROR_INVALID_PARAMETER;
2544 case INTERNET_OPTION_CONNECT_TIMEOUT:
2545 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2547 if (*size < sizeof(ULONG))
2548 return ERROR_INSUFFICIENT_BUFFER;
2550 *(ULONG*)buffer = connect_timeout;
2551 *size = sizeof(ULONG);
2553 return ERROR_SUCCESS;
2556 FIXME("Stub for %d\n", option);
2557 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2560 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2562 switch(option) {
2563 case INTERNET_OPTION_CONTEXT_VALUE:
2564 if (!size)
2565 return ERROR_INVALID_PARAMETER;
2567 if (*size < sizeof(DWORD_PTR)) {
2568 *size = sizeof(DWORD_PTR);
2569 return ERROR_INSUFFICIENT_BUFFER;
2571 if (!buffer)
2572 return ERROR_INVALID_PARAMETER;
2574 *(DWORD_PTR *)buffer = hdr->dwContext;
2575 *size = sizeof(DWORD_PTR);
2576 return ERROR_SUCCESS;
2578 case INTERNET_OPTION_REQUEST_FLAGS:
2579 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2580 *size = sizeof(DWORD);
2581 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2583 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2584 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2585 WARN("Called on global option %u\n", option);
2586 return ERROR_INTERNET_INVALID_OPERATION;
2589 /* FIXME: we shouldn't call it here */
2590 return query_global_option(option, buffer, size, unicode);
2593 /***********************************************************************
2594 * InternetQueryOptionW (WININET.@)
2596 * Queries an options on the specified handle
2598 * RETURNS
2599 * TRUE on success
2600 * FALSE on failure
2603 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2604 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2606 object_header_t *hdr;
2607 DWORD res = ERROR_INVALID_HANDLE;
2609 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2611 if(hInternet) {
2612 hdr = get_handle_object(hInternet);
2613 if (hdr) {
2614 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2615 WININET_Release(hdr);
2617 }else {
2618 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2621 if(res != ERROR_SUCCESS)
2622 SetLastError(res);
2623 return res == ERROR_SUCCESS;
2626 /***********************************************************************
2627 * InternetQueryOptionA (WININET.@)
2629 * Queries an options on the specified handle
2631 * RETURNS
2632 * TRUE on success
2633 * FALSE on failure
2636 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2637 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2639 object_header_t *hdr;
2640 DWORD res = ERROR_INVALID_HANDLE;
2642 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2644 if(hInternet) {
2645 hdr = get_handle_object(hInternet);
2646 if (hdr) {
2647 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2648 WININET_Release(hdr);
2650 }else {
2651 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2654 if(res != ERROR_SUCCESS)
2655 SetLastError(res);
2656 return res == ERROR_SUCCESS;
2659 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2661 switch(option) {
2662 case INTERNET_OPTION_CALLBACK:
2663 WARN("Not settable option %u\n", option);
2664 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2665 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2666 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2667 WARN("Called on global option %u\n", option);
2668 return ERROR_INTERNET_INVALID_OPERATION;
2671 return ERROR_INTERNET_INVALID_OPTION;
2674 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2676 switch(option) {
2677 case INTERNET_OPTION_CALLBACK:
2678 WARN("Not global option %u\n", option);
2679 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2681 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2682 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2684 if(size != sizeof(max_conns))
2685 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2686 if(!*(ULONG*)buf)
2687 return ERROR_BAD_ARGUMENTS;
2689 max_conns = *(ULONG*)buf;
2690 return ERROR_SUCCESS;
2692 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2693 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2695 if(size != sizeof(max_1_0_conns))
2696 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2697 if(!*(ULONG*)buf)
2698 return ERROR_BAD_ARGUMENTS;
2700 max_1_0_conns = *(ULONG*)buf;
2701 return ERROR_SUCCESS;
2703 case INTERNET_OPTION_CONNECT_TIMEOUT:
2704 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2706 if(size != sizeof(connect_timeout))
2707 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2708 if(!*(ULONG*)buf)
2709 return ERROR_BAD_ARGUMENTS;
2711 connect_timeout = *(ULONG*)buf;
2712 return ERROR_SUCCESS;
2714 case INTERNET_OPTION_SETTINGS_CHANGED:
2715 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2716 collect_connections(COLLECT_CONNECTIONS);
2717 return ERROR_SUCCESS;
2720 return ERROR_INTERNET_INVALID_OPTION;
2723 /***********************************************************************
2724 * InternetSetOptionW (WININET.@)
2726 * Sets an options on the specified handle
2728 * RETURNS
2729 * TRUE on success
2730 * FALSE on failure
2733 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2734 LPVOID lpBuffer, DWORD dwBufferLength)
2736 object_header_t *lpwhh;
2737 BOOL ret = TRUE;
2738 DWORD res;
2740 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2742 lpwhh = (object_header_t*) get_handle_object( hInternet );
2743 if(lpwhh)
2744 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2745 else
2746 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2748 if(res != ERROR_INTERNET_INVALID_OPTION) {
2749 if(lpwhh)
2750 WININET_Release(lpwhh);
2752 if(res != ERROR_SUCCESS)
2753 SetLastError(res);
2755 return res == ERROR_SUCCESS;
2758 switch (dwOption)
2760 case INTERNET_OPTION_HTTP_VERSION:
2762 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2763 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2765 break;
2766 case INTERNET_OPTION_ERROR_MASK:
2768 if(!lpwhh) {
2769 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2770 return FALSE;
2771 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2772 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2773 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2774 SetLastError(ERROR_INVALID_PARAMETER);
2775 ret = FALSE;
2776 } else if(dwBufferLength != sizeof(ULONG)) {
2777 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2778 ret = FALSE;
2779 } else
2780 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2781 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2783 break;
2784 case INTERNET_OPTION_PROXY:
2786 INTERNET_PROXY_INFOW *info = lpBuffer;
2788 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2790 SetLastError(ERROR_INVALID_PARAMETER);
2791 return FALSE;
2793 if (!hInternet)
2795 EnterCriticalSection( &WININET_cs );
2796 free_global_proxy();
2797 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2798 if (global_proxy)
2800 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2802 global_proxy->proxyEnabled = 1;
2803 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2804 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2806 else
2808 global_proxy->proxyEnabled = 0;
2809 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2812 LeaveCriticalSection( &WININET_cs );
2814 else
2816 /* In general, each type of object should handle
2817 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2818 * get silently dropped.
2820 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2821 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2822 ret = FALSE;
2824 break;
2826 case INTERNET_OPTION_CODEPAGE:
2828 ULONG codepage = *(ULONG *)lpBuffer;
2829 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2831 break;
2832 case INTERNET_OPTION_REQUEST_PRIORITY:
2834 ULONG priority = *(ULONG *)lpBuffer;
2835 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2837 break;
2838 case INTERNET_OPTION_CONNECT_TIMEOUT:
2840 ULONG connecttimeout = *(ULONG *)lpBuffer;
2841 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2843 break;
2844 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2846 ULONG receivetimeout = *(ULONG *)lpBuffer;
2847 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2849 break;
2850 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2851 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2852 break;
2853 case INTERNET_OPTION_END_BROWSER_SESSION:
2854 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2855 break;
2856 case INTERNET_OPTION_CONNECTED_STATE:
2857 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2858 break;
2859 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2860 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2861 break;
2862 case INTERNET_OPTION_SEND_TIMEOUT:
2863 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2864 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2866 ULONG timeout = *(ULONG *)lpBuffer;
2867 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2868 break;
2870 case INTERNET_OPTION_CONNECT_RETRIES:
2872 ULONG retries = *(ULONG *)lpBuffer;
2873 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2874 break;
2876 case INTERNET_OPTION_CONTEXT_VALUE:
2878 if (!lpwhh)
2880 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2881 return FALSE;
2883 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2885 SetLastError(ERROR_INVALID_PARAMETER);
2886 ret = FALSE;
2888 else
2889 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2890 break;
2892 case INTERNET_OPTION_SECURITY_FLAGS:
2893 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2894 break;
2895 case INTERNET_OPTION_DISABLE_AUTODIAL:
2896 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2897 break;
2898 case INTERNET_OPTION_HTTP_DECODING:
2899 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2900 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2901 ret = FALSE;
2902 break;
2903 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2904 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2905 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2906 ret = FALSE;
2907 break;
2908 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2909 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2910 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2911 ret = FALSE;
2912 break;
2913 case INTERNET_OPTION_CODEPAGE_PATH:
2914 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2915 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2916 ret = FALSE;
2917 break;
2918 case INTERNET_OPTION_CODEPAGE_EXTRA:
2919 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2920 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2921 ret = FALSE;
2922 break;
2923 case INTERNET_OPTION_IDN:
2924 FIXME("INTERNET_OPTION_IDN; STUB\n");
2925 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2926 ret = FALSE;
2927 break;
2928 case INTERNET_OPTION_POLICY:
2929 SetLastError(ERROR_INVALID_PARAMETER);
2930 ret = FALSE;
2931 break;
2932 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2933 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2934 LONG res;
2935 unsigned int i;
2936 proxyinfo_t pi;
2938 if (INTERNET_LoadProxySettings(&pi)) return FALSE;
2940 for (i = 0; i < con->dwOptionCount; i++) {
2941 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2943 switch (option->dwOption) {
2944 case INTERNET_PER_CONN_PROXY_SERVER:
2945 heap_free(pi.proxy);
2946 pi.proxy = heap_strdupW(option->Value.pszValue);
2947 break;
2949 case INTERNET_PER_CONN_FLAGS:
2950 if(option->Value.dwValue & PROXY_TYPE_PROXY)
2951 pi.proxyEnabled = 1;
2952 else
2954 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
2955 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
2956 pi.proxyEnabled = 0;
2958 break;
2960 case INTERNET_PER_CONN_PROXY_BYPASS:
2961 heap_free(pi.proxyBypass);
2962 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
2963 break;
2965 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2966 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2967 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2968 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2969 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2970 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2971 FIXME("Unhandled dwOption %d\n", option->dwOption);
2972 break;
2974 default:
2975 FIXME("Unknown dwOption %d\n", option->dwOption);
2976 SetLastError(ERROR_INVALID_PARAMETER);
2977 break;
2981 if ((res = INTERNET_SaveProxySettings(&pi)))
2982 SetLastError(res);
2984 FreeProxyInfo(&pi);
2986 ret = (res == ERROR_SUCCESS);
2987 break;
2989 default:
2990 FIXME("Option %d STUB\n",dwOption);
2991 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2992 ret = FALSE;
2993 break;
2996 if(lpwhh)
2997 WININET_Release( lpwhh );
2999 return ret;
3003 /***********************************************************************
3004 * InternetSetOptionA (WININET.@)
3006 * Sets an options on the specified handle.
3008 * RETURNS
3009 * TRUE on success
3010 * FALSE on failure
3013 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
3014 LPVOID lpBuffer, DWORD dwBufferLength)
3016 LPVOID wbuffer;
3017 DWORD wlen;
3018 BOOL r;
3020 switch( dwOption )
3022 case INTERNET_OPTION_PROXY:
3024 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
3025 LPINTERNET_PROXY_INFOW piw;
3026 DWORD proxlen, prbylen;
3027 LPWSTR prox, prby;
3029 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
3030 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
3031 wlen = sizeof(*piw) + proxlen + prbylen;
3032 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
3033 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
3034 piw->dwAccessType = pi->dwAccessType;
3035 prox = (LPWSTR) &piw[1];
3036 prby = &prox[proxlen+1];
3037 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
3038 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
3039 piw->lpszProxy = prox;
3040 piw->lpszProxyBypass = prby;
3042 break;
3043 case INTERNET_OPTION_USER_AGENT:
3044 case INTERNET_OPTION_USERNAME:
3045 case INTERNET_OPTION_PASSWORD:
3046 case INTERNET_OPTION_PROXY_USERNAME:
3047 case INTERNET_OPTION_PROXY_PASSWORD:
3048 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3049 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3050 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3051 break;
3052 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3053 unsigned int i;
3054 INTERNET_PER_CONN_OPTION_LISTW *listW;
3055 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3056 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3057 wbuffer = heap_alloc(wlen);
3058 listW = wbuffer;
3060 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3061 if (listA->pszConnection)
3063 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3064 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3065 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3067 else
3068 listW->pszConnection = NULL;
3069 listW->dwOptionCount = listA->dwOptionCount;
3070 listW->dwOptionError = listA->dwOptionError;
3071 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3073 for (i = 0; i < listA->dwOptionCount; ++i) {
3074 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3075 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3077 optW->dwOption = optA->dwOption;
3079 switch (optA->dwOption) {
3080 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3081 case INTERNET_PER_CONN_PROXY_BYPASS:
3082 case INTERNET_PER_CONN_PROXY_SERVER:
3083 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3084 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3085 if (optA->Value.pszValue)
3087 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3088 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3089 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3091 else
3092 optW->Value.pszValue = NULL;
3093 break;
3094 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3095 case INTERNET_PER_CONN_FLAGS:
3096 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3097 optW->Value.dwValue = optA->Value.dwValue;
3098 break;
3099 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3100 optW->Value.ftValue = optA->Value.ftValue;
3101 break;
3102 default:
3103 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3104 optW->Value.dwValue = optA->Value.dwValue;
3105 break;
3109 break;
3110 default:
3111 wbuffer = lpBuffer;
3112 wlen = dwBufferLength;
3115 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3117 if( lpBuffer != wbuffer )
3119 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3121 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3122 unsigned int i;
3123 for (i = 0; i < list->dwOptionCount; ++i) {
3124 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3125 switch (opt->dwOption) {
3126 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3127 case INTERNET_PER_CONN_PROXY_BYPASS:
3128 case INTERNET_PER_CONN_PROXY_SERVER:
3129 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3130 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3131 heap_free( opt->Value.pszValue );
3132 break;
3133 default:
3134 break;
3137 heap_free( list->pOptions );
3139 heap_free( wbuffer );
3142 return r;
3146 /***********************************************************************
3147 * InternetSetOptionExA (WININET.@)
3149 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3150 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3152 FIXME("Flags %08x ignored\n", dwFlags);
3153 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3156 /***********************************************************************
3157 * InternetSetOptionExW (WININET.@)
3159 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3160 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3162 FIXME("Flags %08x ignored\n", dwFlags);
3163 if( dwFlags & ~ISO_VALID_FLAGS )
3165 SetLastError( ERROR_INVALID_PARAMETER );
3166 return FALSE;
3168 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3171 static const WCHAR WININET_wkday[7][4] =
3172 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3173 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3174 static const WCHAR WININET_month[12][4] =
3175 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3176 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3177 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3179 /***********************************************************************
3180 * InternetTimeFromSystemTimeA (WININET.@)
3182 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3184 BOOL ret;
3185 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3187 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3189 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3191 SetLastError(ERROR_INVALID_PARAMETER);
3192 return FALSE;
3195 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3197 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3198 return FALSE;
3201 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3202 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3204 return ret;
3207 /***********************************************************************
3208 * InternetTimeFromSystemTimeW (WININET.@)
3210 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3212 static const WCHAR date[] =
3213 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3214 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3216 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3218 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3220 SetLastError(ERROR_INVALID_PARAMETER);
3221 return FALSE;
3224 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3226 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3227 return FALSE;
3230 sprintfW( string, date,
3231 WININET_wkday[time->wDayOfWeek],
3232 time->wDay,
3233 WININET_month[time->wMonth - 1],
3234 time->wYear,
3235 time->wHour,
3236 time->wMinute,
3237 time->wSecond );
3239 return TRUE;
3242 /***********************************************************************
3243 * InternetTimeToSystemTimeA (WININET.@)
3245 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3247 BOOL ret = FALSE;
3248 WCHAR *stringW;
3250 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3252 stringW = heap_strdupAtoW(string);
3253 if (stringW)
3255 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3256 heap_free( stringW );
3258 return ret;
3261 /***********************************************************************
3262 * InternetTimeToSystemTimeW (WININET.@)
3264 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3266 unsigned int i;
3267 const WCHAR *s = string;
3268 WCHAR *end;
3270 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3272 if (!string || !time) return FALSE;
3274 /* Windows does this too */
3275 GetSystemTime( time );
3277 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3278 * a SYSTEMTIME structure.
3281 while (*s && !isalphaW( *s )) s++;
3282 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3283 time->wDayOfWeek = 7;
3285 for (i = 0; i < 7; i++)
3287 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3288 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3289 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3291 time->wDayOfWeek = i;
3292 break;
3296 if (time->wDayOfWeek > 6) return TRUE;
3297 while (*s && !isdigitW( *s )) s++;
3298 time->wDay = strtolW( s, &end, 10 );
3299 s = end;
3301 while (*s && !isalphaW( *s )) s++;
3302 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3303 time->wMonth = 0;
3305 for (i = 0; i < 12; i++)
3307 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3308 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3309 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3311 time->wMonth = i + 1;
3312 break;
3315 if (time->wMonth == 0) return TRUE;
3317 while (*s && !isdigitW( *s )) s++;
3318 if (*s == '\0') return TRUE;
3319 time->wYear = strtolW( s, &end, 10 );
3320 s = end;
3322 while (*s && !isdigitW( *s )) s++;
3323 if (*s == '\0') return TRUE;
3324 time->wHour = strtolW( s, &end, 10 );
3325 s = end;
3327 while (*s && !isdigitW( *s )) s++;
3328 if (*s == '\0') return TRUE;
3329 time->wMinute = strtolW( s, &end, 10 );
3330 s = end;
3332 while (*s && !isdigitW( *s )) s++;
3333 if (*s == '\0') return TRUE;
3334 time->wSecond = strtolW( s, &end, 10 );
3335 s = end;
3337 time->wMilliseconds = 0;
3338 return TRUE;
3341 /***********************************************************************
3342 * InternetCheckConnectionW (WININET.@)
3344 * Pings a requested host to check internet connection
3346 * RETURNS
3347 * TRUE on success and FALSE on failure. If a failure then
3348 * ERROR_NOT_CONNECTED is placed into GetLastError
3351 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3354 * this is a kludge which runs the resident ping program and reads the output.
3356 * Anyone have a better idea?
3359 BOOL rc = FALSE;
3360 static const CHAR ping[] = "ping -c 1 ";
3361 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3362 CHAR *command = NULL;
3363 WCHAR hostW[INTERNET_MAX_HOST_NAME_LENGTH];
3364 DWORD len;
3365 INTERNET_PORT port;
3366 int status = -1;
3368 FIXME("\n");
3371 * Crack or set the Address
3373 if (lpszUrl == NULL)
3376 * According to the doc we are supposed to use the ip for the next
3377 * server in the WnInet internal server database. I have
3378 * no idea what that is or how to get it.
3380 * So someone needs to implement this.
3382 FIXME("Unimplemented with URL of NULL\n");
3383 return TRUE;
3385 else
3387 URL_COMPONENTSW components;
3389 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3390 components.lpszHostName = (LPWSTR)hostW;
3391 components.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3393 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3394 goto End;
3396 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3397 port = components.nPort;
3398 TRACE("port: %d\n", port);
3401 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3403 struct sockaddr_storage saddr;
3404 socklen_t sa_len = sizeof(saddr);
3405 int fd;
3407 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3408 goto End;
3409 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3410 if (fd != -1)
3412 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3413 rc = TRUE;
3414 close(fd);
3417 else
3420 * Build our ping command
3422 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3423 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3424 strcpy(command,ping);
3425 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3426 strcat(command,redirect);
3428 TRACE("Ping command is : %s\n",command);
3430 status = system(command);
3432 TRACE("Ping returned a code of %i\n",status);
3434 /* Ping return code of 0 indicates success */
3435 if (status == 0)
3436 rc = TRUE;
3439 End:
3440 heap_free( command );
3441 if (rc == FALSE)
3442 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3444 return rc;
3448 /***********************************************************************
3449 * InternetCheckConnectionA (WININET.@)
3451 * Pings a requested host to check internet connection
3453 * RETURNS
3454 * TRUE on success and FALSE on failure. If a failure then
3455 * ERROR_NOT_CONNECTED is placed into GetLastError
3458 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3460 WCHAR *url = NULL;
3461 BOOL rc;
3463 if(lpszUrl) {
3464 url = heap_strdupAtoW(lpszUrl);
3465 if(!url)
3466 return FALSE;
3469 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3471 heap_free(url);
3472 return rc;
3476 /**********************************************************
3477 * INTERNET_InternetOpenUrlW (internal)
3479 * Opens an URL
3481 * RETURNS
3482 * handle of connection or NULL on failure
3484 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3485 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3487 URL_COMPONENTSW urlComponents;
3488 WCHAR protocol[INTERNET_MAX_SCHEME_LENGTH];
3489 WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH];
3490 WCHAR userName[INTERNET_MAX_USER_NAME_LENGTH];
3491 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
3492 WCHAR path[INTERNET_MAX_PATH_LENGTH];
3493 WCHAR extra[1024];
3494 HINTERNET client = NULL, client1 = NULL;
3495 DWORD res;
3497 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3498 dwHeadersLength, dwFlags, dwContext);
3500 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3501 urlComponents.lpszScheme = protocol;
3502 urlComponents.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH;
3503 urlComponents.lpszHostName = hostName;
3504 urlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3505 urlComponents.lpszUserName = userName;
3506 urlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
3507 urlComponents.lpszPassword = password;
3508 urlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
3509 urlComponents.lpszUrlPath = path;
3510 urlComponents.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
3511 urlComponents.lpszExtraInfo = extra;
3512 urlComponents.dwExtraInfoLength = 1024;
3513 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3514 return NULL;
3515 switch(urlComponents.nScheme) {
3516 case INTERNET_SCHEME_FTP:
3517 if(urlComponents.nPort == 0)
3518 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3519 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3520 userName, password, dwFlags, dwContext, INET_OPENURL);
3521 if(client == NULL)
3522 break;
3523 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3524 if(client1 == NULL) {
3525 InternetCloseHandle(client);
3526 break;
3528 break;
3530 case INTERNET_SCHEME_HTTP:
3531 case INTERNET_SCHEME_HTTPS: {
3532 static const WCHAR szStars[] = { '*','/','*', 0 };
3533 LPCWSTR accept[2] = { szStars, NULL };
3534 if(urlComponents.nPort == 0) {
3535 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3536 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3537 else
3538 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3540 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3542 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3543 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3544 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3545 if(res != ERROR_SUCCESS) {
3546 INTERNET_SetLastError(res);
3547 break;
3550 if (urlComponents.dwExtraInfoLength) {
3551 WCHAR *path_extra;
3552 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3554 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3556 InternetCloseHandle(client);
3557 break;
3559 strcpyW(path_extra, urlComponents.lpszUrlPath);
3560 strcatW(path_extra, urlComponents.lpszExtraInfo);
3561 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3562 heap_free(path_extra);
3564 else
3565 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3567 if(client1 == NULL) {
3568 InternetCloseHandle(client);
3569 break;
3571 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3572 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3573 GetLastError() != ERROR_IO_PENDING) {
3574 InternetCloseHandle(client1);
3575 client1 = NULL;
3576 break;
3579 case INTERNET_SCHEME_GOPHER:
3580 /* gopher doesn't seem to be implemented in wine, but it's supposed
3581 * to be supported by InternetOpenUrlA. */
3582 default:
3583 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3584 break;
3587 TRACE(" %p <--\n", client1);
3589 return client1;
3592 /**********************************************************
3593 * InternetOpenUrlW (WININET.@)
3595 * Opens an URL
3597 * RETURNS
3598 * handle of connection or NULL on failure
3600 typedef struct {
3601 task_header_t hdr;
3602 WCHAR *url;
3603 WCHAR *headers;
3604 DWORD headers_len;
3605 DWORD flags;
3606 DWORD_PTR context;
3607 } open_url_task_t;
3609 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3611 open_url_task_t *task = (open_url_task_t*)hdr;
3613 TRACE("%p\n", task->hdr.hdr);
3615 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3616 task->headers_len, task->flags, task->context);
3617 heap_free(task->url);
3618 heap_free(task->headers);
3621 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3622 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3624 HINTERNET ret = NULL;
3625 appinfo_t *hIC = NULL;
3627 if (TRACE_ON(wininet)) {
3628 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3629 dwHeadersLength, dwFlags, dwContext);
3630 TRACE(" flags :");
3631 dump_INTERNET_FLAGS(dwFlags);
3634 if (!lpszUrl)
3636 SetLastError(ERROR_INVALID_PARAMETER);
3637 goto lend;
3640 hIC = (appinfo_t*)get_handle_object( hInternet );
3641 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3642 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3643 goto lend;
3646 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3647 open_url_task_t *task;
3649 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3650 task->url = heap_strdupW(lpszUrl);
3651 task->headers = heap_strdupW(lpszHeaders);
3652 task->headers_len = dwHeadersLength;
3653 task->flags = dwFlags;
3654 task->context = dwContext;
3656 INTERNET_AsyncCall(&task->hdr);
3657 SetLastError(ERROR_IO_PENDING);
3658 } else {
3659 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3662 lend:
3663 if( hIC )
3664 WININET_Release( &hIC->hdr );
3665 TRACE(" %p <--\n", ret);
3667 return ret;
3670 /**********************************************************
3671 * InternetOpenUrlA (WININET.@)
3673 * Opens an URL
3675 * RETURNS
3676 * handle of connection or NULL on failure
3678 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3679 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3681 HINTERNET rc = NULL;
3682 DWORD lenHeaders = 0;
3683 LPWSTR szUrl = NULL;
3684 LPWSTR szHeaders = NULL;
3686 TRACE("\n");
3688 if(lpszUrl) {
3689 szUrl = heap_strdupAtoW(lpszUrl);
3690 if(!szUrl)
3691 return NULL;
3694 if(lpszHeaders) {
3695 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3696 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3697 if(!szHeaders) {
3698 heap_free(szUrl);
3699 return NULL;
3701 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3704 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3705 lenHeaders, dwFlags, dwContext);
3707 heap_free(szUrl);
3708 heap_free(szHeaders);
3709 return rc;
3713 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3715 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3717 if (lpwite)
3719 lpwite->dwError = 0;
3720 lpwite->response[0] = '\0';
3723 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3725 heap_free(lpwite);
3726 return NULL;
3728 return lpwite;
3732 /***********************************************************************
3733 * INTERNET_SetLastError (internal)
3735 * Set last thread specific error
3737 * RETURNS
3740 void INTERNET_SetLastError(DWORD dwError)
3742 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3744 if (!lpwite)
3745 lpwite = INTERNET_AllocThreadError();
3747 SetLastError(dwError);
3748 if(lpwite)
3749 lpwite->dwError = dwError;
3753 /***********************************************************************
3754 * INTERNET_GetLastError (internal)
3756 * Get last thread specific error
3758 * RETURNS
3761 DWORD INTERNET_GetLastError(void)
3763 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3764 if (!lpwite) return 0;
3765 /* TlsGetValue clears last error, so set it again here */
3766 SetLastError(lpwite->dwError);
3767 return lpwite->dwError;
3771 /***********************************************************************
3772 * INTERNET_WorkerThreadFunc (internal)
3774 * Worker thread execution function
3776 * RETURNS
3779 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3781 task_header_t *task = lpvParam;
3783 TRACE("\n");
3785 task->proc(task);
3786 WININET_Release(task->hdr);
3787 heap_free(task);
3789 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3791 heap_free(TlsGetValue(g_dwTlsErrIndex));
3792 TlsSetValue(g_dwTlsErrIndex, NULL);
3794 return TRUE;
3797 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3799 task_header_t *task;
3801 task = heap_alloc(size);
3802 if(!task)
3803 return NULL;
3805 task->hdr = WININET_AddRef(hdr);
3806 task->proc = proc;
3807 return task;
3810 /***********************************************************************
3811 * INTERNET_AsyncCall (internal)
3813 * Retrieves work request from queue
3815 * RETURNS
3818 DWORD INTERNET_AsyncCall(task_header_t *task)
3820 BOOL bSuccess;
3822 TRACE("\n");
3824 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3825 if (!bSuccess)
3827 heap_free(task);
3828 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3830 return ERROR_SUCCESS;
3834 /***********************************************************************
3835 * INTERNET_GetResponseBuffer (internal)
3837 * RETURNS
3840 LPSTR INTERNET_GetResponseBuffer(void)
3842 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3843 if (!lpwite)
3844 lpwite = INTERNET_AllocThreadError();
3845 TRACE("\n");
3846 return lpwite->response;
3849 /***********************************************************************
3850 * INTERNET_GetNextLine (internal)
3852 * Parse next line in directory string listing
3854 * RETURNS
3855 * Pointer to beginning of next line
3856 * NULL on failure
3860 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3862 struct pollfd pfd;
3863 BOOL bSuccess = FALSE;
3864 INT nRecv = 0;
3865 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3867 TRACE("\n");
3869 pfd.fd = nSocket;
3870 pfd.events = POLLIN;
3872 while (nRecv < MAX_REPLY_LEN)
3874 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3876 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3878 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3879 goto lend;
3882 if (lpszBuffer[nRecv] == '\n')
3884 bSuccess = TRUE;
3885 break;
3887 if (lpszBuffer[nRecv] != '\r')
3888 nRecv++;
3890 else
3892 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3893 goto lend;
3897 lend:
3898 if (bSuccess)
3900 lpszBuffer[nRecv] = '\0';
3901 *dwLen = nRecv - 1;
3902 TRACE(":%d %s\n", nRecv, lpszBuffer);
3903 return lpszBuffer;
3905 else
3907 return NULL;
3911 /**********************************************************
3912 * InternetQueryDataAvailable (WININET.@)
3914 * Determines how much data is available to be read.
3916 * RETURNS
3917 * TRUE on success, FALSE if an error occurred. If
3918 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3919 * no data is presently available, FALSE is returned with
3920 * the last error ERROR_IO_PENDING; a callback with status
3921 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3922 * data is available.
3924 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3925 LPDWORD lpdwNumberOfBytesAvailable,
3926 DWORD dwFlags, DWORD_PTR dwContext)
3928 object_header_t *hdr;
3929 DWORD res;
3931 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3933 hdr = get_handle_object( hFile );
3934 if (!hdr) {
3935 SetLastError(ERROR_INVALID_HANDLE);
3936 return FALSE;
3939 if(hdr->vtbl->QueryDataAvailable) {
3940 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3941 }else {
3942 WARN("wrong handle\n");
3943 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3946 WININET_Release(hdr);
3948 if(res != ERROR_SUCCESS)
3949 SetLastError(res);
3950 return res == ERROR_SUCCESS;
3953 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
3955 req_file_t *req_file;
3957 req_file = heap_alloc_zero(sizeof(*req_file));
3958 if(!req_file)
3959 return ERROR_NOT_ENOUGH_MEMORY;
3961 req_file->ref = 1;
3963 req_file->file_name = heap_strdupW(file_name);
3964 if(!req_file->file_name) {
3965 heap_free(req_file);
3966 return ERROR_NOT_ENOUGH_MEMORY;
3969 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
3970 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3971 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
3972 req_file_release(req_file);
3973 return GetLastError();
3976 *ret = req_file;
3977 return ERROR_SUCCESS;
3980 void req_file_release(req_file_t *req_file)
3982 if(InterlockedDecrement(&req_file->ref))
3983 return;
3985 if(!req_file->is_committed)
3986 DeleteFileW(req_file->file_name);
3987 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
3988 CloseHandle(req_file->file_handle);
3989 heap_free(req_file->file_name);
3990 heap_free(req_file);
3993 /***********************************************************************
3994 * InternetLockRequestFile (WININET.@)
3996 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
3998 req_file_t *req_file = NULL;
3999 object_header_t *hdr;
4000 DWORD res;
4002 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
4004 hdr = get_handle_object(hInternet);
4005 if (!hdr) {
4006 SetLastError(ERROR_INVALID_HANDLE);
4007 return FALSE;
4010 if(hdr->vtbl->LockRequestFile) {
4011 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
4012 }else {
4013 WARN("wrong handle\n");
4014 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4017 WININET_Release(hdr);
4019 *lphLockReqHandle = req_file;
4020 if(res != ERROR_SUCCESS)
4021 SetLastError(res);
4022 return res == ERROR_SUCCESS;
4025 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
4027 TRACE("(%p)\n", hLockHandle);
4029 req_file_release(hLockHandle);
4030 return TRUE;
4034 /***********************************************************************
4035 * InternetAutodial (WININET.@)
4037 * On windows this function is supposed to dial the default internet
4038 * connection. We don't want to have Wine dial out to the internet so
4039 * we return TRUE by default. It might be nice to check if we are connected.
4041 * RETURNS
4042 * TRUE on success
4043 * FALSE on failure
4046 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4048 FIXME("STUB\n");
4050 /* Tell that we are connected to the internet. */
4051 return TRUE;
4054 /***********************************************************************
4055 * InternetAutodialHangup (WININET.@)
4057 * Hangs up a connection made with InternetAutodial
4059 * PARAM
4060 * dwReserved
4061 * RETURNS
4062 * TRUE on success
4063 * FALSE on failure
4066 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4068 FIXME("STUB\n");
4070 /* we didn't dial, we don't disconnect */
4071 return TRUE;
4074 /***********************************************************************
4075 * InternetCombineUrlA (WININET.@)
4077 * Combine a base URL with a relative URL
4079 * RETURNS
4080 * TRUE on success
4081 * FALSE on failure
4085 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4086 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4087 DWORD dwFlags)
4089 HRESULT hr=S_OK;
4091 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4093 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4094 dwFlags ^= ICU_NO_ENCODE;
4095 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4097 return (hr==S_OK);
4100 /***********************************************************************
4101 * InternetCombineUrlW (WININET.@)
4103 * Combine a base URL with a relative URL
4105 * RETURNS
4106 * TRUE on success
4107 * FALSE on failure
4111 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4112 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4113 DWORD dwFlags)
4115 HRESULT hr=S_OK;
4117 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4119 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4120 dwFlags ^= ICU_NO_ENCODE;
4121 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4123 return (hr==S_OK);
4126 /* max port num is 65535 => 5 digits */
4127 #define MAX_WORD_DIGITS 5
4129 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4130 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4131 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4132 (url)->dw##component##Length : strlen((url)->lpsz##component))
4134 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4136 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4137 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4138 return TRUE;
4139 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4140 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4141 return TRUE;
4142 if ((nScheme == INTERNET_SCHEME_FTP) &&
4143 (nPort == INTERNET_DEFAULT_FTP_PORT))
4144 return TRUE;
4145 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4146 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4147 return TRUE;
4149 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4150 return TRUE;
4152 return FALSE;
4155 /* opaque urls do not fit into the standard url hierarchy and don't have
4156 * two following slashes */
4157 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4159 return (nScheme != INTERNET_SCHEME_FTP) &&
4160 (nScheme != INTERNET_SCHEME_GOPHER) &&
4161 (nScheme != INTERNET_SCHEME_HTTP) &&
4162 (nScheme != INTERNET_SCHEME_HTTPS) &&
4163 (nScheme != INTERNET_SCHEME_FILE);
4166 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4168 int index;
4169 if (scheme < INTERNET_SCHEME_FIRST)
4170 return NULL;
4171 index = scheme - INTERNET_SCHEME_FIRST;
4172 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
4173 return NULL;
4174 return (LPCWSTR)url_schemes[index];
4177 /* we can calculate using ansi strings because we're just
4178 * calculating string length, not size
4180 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4181 LPDWORD lpdwUrlLength)
4183 INTERNET_SCHEME nScheme;
4185 *lpdwUrlLength = 0;
4187 if (lpUrlComponents->lpszScheme)
4189 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4190 *lpdwUrlLength += dwLen;
4191 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4193 else
4195 LPCWSTR scheme;
4197 nScheme = lpUrlComponents->nScheme;
4199 if (nScheme == INTERNET_SCHEME_DEFAULT)
4200 nScheme = INTERNET_SCHEME_HTTP;
4201 scheme = INTERNET_GetSchemeString(nScheme);
4202 *lpdwUrlLength += strlenW(scheme);
4205 (*lpdwUrlLength)++; /* ':' */
4206 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4207 *lpdwUrlLength += strlen("//");
4209 if (lpUrlComponents->lpszUserName)
4211 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4212 *lpdwUrlLength += strlen("@");
4214 else
4216 if (lpUrlComponents->lpszPassword)
4218 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4219 return FALSE;
4223 if (lpUrlComponents->lpszPassword)
4225 *lpdwUrlLength += strlen(":");
4226 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4229 if (lpUrlComponents->lpszHostName)
4231 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4233 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4235 char szPort[MAX_WORD_DIGITS+1];
4237 sprintf(szPort, "%d", lpUrlComponents->nPort);
4238 *lpdwUrlLength += strlen(szPort);
4239 *lpdwUrlLength += strlen(":");
4242 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4243 (*lpdwUrlLength)++; /* '/' */
4246 if (lpUrlComponents->lpszUrlPath)
4247 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4249 if (lpUrlComponents->lpszExtraInfo)
4250 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4252 return TRUE;
4255 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4257 INT len;
4259 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4261 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4262 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4263 urlCompW->nScheme = lpUrlComponents->nScheme;
4264 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4265 urlCompW->nPort = lpUrlComponents->nPort;
4266 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4267 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4268 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4269 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4271 if (lpUrlComponents->lpszScheme)
4273 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4274 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4275 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4276 -1, urlCompW->lpszScheme, len);
4279 if (lpUrlComponents->lpszHostName)
4281 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4282 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4283 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4284 -1, urlCompW->lpszHostName, len);
4287 if (lpUrlComponents->lpszUserName)
4289 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4290 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4291 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4292 -1, urlCompW->lpszUserName, len);
4295 if (lpUrlComponents->lpszPassword)
4297 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4298 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4299 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4300 -1, urlCompW->lpszPassword, len);
4303 if (lpUrlComponents->lpszUrlPath)
4305 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4306 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4307 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4308 -1, urlCompW->lpszUrlPath, len);
4311 if (lpUrlComponents->lpszExtraInfo)
4313 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4314 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4315 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4316 -1, urlCompW->lpszExtraInfo, len);
4320 /***********************************************************************
4321 * InternetCreateUrlA (WININET.@)
4323 * See InternetCreateUrlW.
4325 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4326 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4328 BOOL ret;
4329 LPWSTR urlW = NULL;
4330 URL_COMPONENTSW urlCompW;
4332 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4334 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4336 SetLastError(ERROR_INVALID_PARAMETER);
4337 return FALSE;
4340 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4342 if (lpszUrl)
4343 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4345 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4347 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4348 *lpdwUrlLength /= sizeof(WCHAR);
4350 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4351 * minus one, so add one to leave room for NULL terminator
4353 if (ret)
4354 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4356 heap_free(urlCompW.lpszScheme);
4357 heap_free(urlCompW.lpszHostName);
4358 heap_free(urlCompW.lpszUserName);
4359 heap_free(urlCompW.lpszPassword);
4360 heap_free(urlCompW.lpszUrlPath);
4361 heap_free(urlCompW.lpszExtraInfo);
4362 heap_free(urlW);
4363 return ret;
4366 /***********************************************************************
4367 * InternetCreateUrlW (WININET.@)
4369 * Creates a URL from its component parts.
4371 * PARAMS
4372 * lpUrlComponents [I] URL Components.
4373 * dwFlags [I] Flags. See notes.
4374 * lpszUrl [I] Buffer in which to store the created URL.
4375 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4376 * lpszUrl in characters. On output, the number of bytes
4377 * required to store the URL including terminator.
4379 * NOTES
4381 * The dwFlags parameter can be zero or more of the following:
4382 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4384 * RETURNS
4385 * TRUE on success
4386 * FALSE on failure
4389 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4390 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4392 DWORD dwLen;
4393 INTERNET_SCHEME nScheme;
4395 static const WCHAR slashSlashW[] = {'/','/'};
4396 static const WCHAR fmtW[] = {'%','u',0};
4398 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4400 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4402 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4403 return FALSE;
4406 if (!calc_url_length(lpUrlComponents, &dwLen))
4407 return FALSE;
4409 if (!lpszUrl || *lpdwUrlLength < dwLen)
4411 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4412 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4413 return FALSE;
4416 *lpdwUrlLength = dwLen;
4417 lpszUrl[0] = 0x00;
4419 dwLen = 0;
4421 if (lpUrlComponents->lpszScheme)
4423 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4424 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4425 lpszUrl += dwLen;
4427 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4429 else
4431 LPCWSTR scheme;
4432 nScheme = lpUrlComponents->nScheme;
4434 if (nScheme == INTERNET_SCHEME_DEFAULT)
4435 nScheme = INTERNET_SCHEME_HTTP;
4437 scheme = INTERNET_GetSchemeString(nScheme);
4438 dwLen = strlenW(scheme);
4439 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4440 lpszUrl += dwLen;
4443 /* all schemes are followed by at least a colon */
4444 *lpszUrl = ':';
4445 lpszUrl++;
4447 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4449 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4450 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4453 if (lpUrlComponents->lpszUserName)
4455 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4456 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4457 lpszUrl += dwLen;
4459 if (lpUrlComponents->lpszPassword)
4461 *lpszUrl = ':';
4462 lpszUrl++;
4464 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4465 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4466 lpszUrl += dwLen;
4469 *lpszUrl = '@';
4470 lpszUrl++;
4473 if (lpUrlComponents->lpszHostName)
4475 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4476 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4477 lpszUrl += dwLen;
4479 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4481 WCHAR szPort[MAX_WORD_DIGITS+1];
4483 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4484 *lpszUrl = ':';
4485 lpszUrl++;
4486 dwLen = strlenW(szPort);
4487 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4488 lpszUrl += dwLen;
4491 /* add slash between hostname and path if necessary */
4492 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4494 *lpszUrl = '/';
4495 lpszUrl++;
4499 if (lpUrlComponents->lpszUrlPath)
4501 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4502 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4503 lpszUrl += dwLen;
4506 if (lpUrlComponents->lpszExtraInfo)
4508 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4509 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4510 lpszUrl += dwLen;
4513 *lpszUrl = '\0';
4515 return TRUE;
4518 /***********************************************************************
4519 * InternetConfirmZoneCrossingA (WININET.@)
4522 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4524 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4525 return ERROR_SUCCESS;
4528 /***********************************************************************
4529 * InternetConfirmZoneCrossingW (WININET.@)
4532 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4534 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4535 return ERROR_SUCCESS;
4538 static DWORD zone_preference = 3;
4540 /***********************************************************************
4541 * PrivacySetZonePreferenceW (WININET.@)
4543 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4545 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4547 zone_preference = template;
4548 return 0;
4551 /***********************************************************************
4552 * PrivacyGetZonePreferenceW (WININET.@)
4554 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4555 LPWSTR preference, LPDWORD length )
4557 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4559 if (template) *template = zone_preference;
4560 return 0;
4563 /***********************************************************************
4564 * InternetGetSecurityInfoByURLA (WININET.@)
4566 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4568 WCHAR *url;
4569 BOOL res;
4571 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4573 url = heap_strdupAtoW(lpszURL);
4574 if(!url)
4575 return FALSE;
4577 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4578 heap_free(url);
4579 return res;
4582 /***********************************************************************
4583 * InternetGetSecurityInfoByURLW (WININET.@)
4585 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4587 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
4588 URL_COMPONENTSW url = {sizeof(url)};
4589 server_t *server;
4590 BOOL res = FALSE;
4592 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4594 url.lpszHostName = hostname;
4595 url.dwHostNameLength = sizeof(hostname)/sizeof(WCHAR);
4597 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4598 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4599 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4600 return FALSE;
4603 server = get_server(hostname, url.nPort, TRUE, FALSE);
4604 if(!server) {
4605 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4606 return FALSE;
4609 if(server->cert_chain) {
4610 const CERT_CHAIN_CONTEXT *chain_dup;
4612 chain_dup = CertDuplicateCertificateChain(server->cert_chain);
4613 if(chain_dup) {
4614 *ppCertChain = chain_dup;
4615 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4616 }else {
4617 res = FALSE;
4619 }else {
4620 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4621 res = FALSE;
4624 server_release(server);
4625 return res;
4628 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4629 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4631 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4632 lpdwConnection, dwReserved);
4633 return ERROR_SUCCESS;
4636 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4637 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4639 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4640 lpdwConnection, dwReserved);
4641 return ERROR_SUCCESS;
4644 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4646 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4647 return TRUE;
4650 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4652 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4653 return TRUE;
4656 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4658 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4659 return ERROR_SUCCESS;
4662 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4663 PBYTE pbHexHash )
4665 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4666 debugstr_w(pwszTarget), pbHexHash);
4667 return FALSE;
4670 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4672 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4673 return FALSE;
4676 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4678 FIXME("(%p, %08lx) stub\n", a, b);
4679 return FALSE;
4682 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4684 FIXME("%p: stub\n", parent);
4685 return 0;