webservices: Implement WsWriteEndAttribute.
[wine/multimedia.git] / dlls / wininet / internet.c
blob9045b0302d6b3edadc19987e6d6af769990c924a
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "ws2tcpip.h"
32 #include <string.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37 #include <assert.h>
39 #ifdef HAVE_CORESERVICES_CORESERVICES_H
40 #define GetCurrentThread MacGetCurrentThread
41 #define LoadResource MacLoadResource
42 #include <CoreServices/CoreServices.h>
43 #undef GetCurrentThread
44 #undef LoadResource
45 #undef DPRINTF
46 #endif
48 #include "windef.h"
49 #include "winbase.h"
50 #include "winreg.h"
51 #include "winuser.h"
52 #include "wininet.h"
53 #include "winnls.h"
54 #include "wine/debug.h"
55 #include "winerror.h"
56 #define NO_SHLWAPI_STREAM
57 #include "shlwapi.h"
59 #include "wine/exception.h"
61 #include "internet.h"
62 #include "resource.h"
64 #include "wine/unicode.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
68 typedef struct
70 DWORD dwError;
71 CHAR response[MAX_REPLY_LEN];
72 } WITHREADERROR, *LPWITHREADERROR;
74 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
75 HMODULE WININET_hModule;
77 static CRITICAL_SECTION WININET_cs;
78 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
80 0, 0, &WININET_cs,
81 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
82 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
84 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
86 static object_header_t **handle_table;
87 static UINT_PTR next_handle;
88 static UINT_PTR handle_table_size;
90 typedef struct
92 DWORD proxyEnabled;
93 LPWSTR proxy;
94 LPWSTR proxyBypass;
95 LPWSTR proxyUsername;
96 LPWSTR proxyPassword;
97 } proxyinfo_t;
99 static ULONG max_conns = 2, max_1_0_conns = 4;
100 static ULONG connect_timeout = 60000;
102 static const WCHAR szInternetSettings[] =
103 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
104 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
105 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
106 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
107 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
108 static const WCHAR szProxyOverride[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
110 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
112 UINT_PTR handle = 0, num;
113 object_header_t *ret;
114 object_header_t **p;
115 BOOL res = TRUE;
117 ret = heap_alloc_zero(size);
118 if(!ret)
119 return NULL;
121 list_init(&ret->children);
123 EnterCriticalSection( &WININET_cs );
125 if(!handle_table_size) {
126 num = 16;
127 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
128 if(p) {
129 handle_table = p;
130 handle_table_size = num;
131 next_handle = 1;
132 }else {
133 res = FALSE;
135 }else if(next_handle == handle_table_size) {
136 num = handle_table_size * 2;
137 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
138 if(p) {
139 handle_table = p;
140 handle_table_size = num;
141 }else {
142 res = FALSE;
146 if(res) {
147 handle = next_handle;
148 if(handle_table[handle])
149 ERR("handle isn't free but should be\n");
150 handle_table[handle] = ret;
151 ret->valid_handle = TRUE;
153 while(handle_table[next_handle] && next_handle < handle_table_size)
154 next_handle++;
157 LeaveCriticalSection( &WININET_cs );
159 if(!res) {
160 heap_free(ret);
161 return NULL;
164 ret->vtbl = vtbl;
165 ret->refs = 1;
166 ret->hInternet = (HINTERNET)handle;
168 if(parent) {
169 ret->lpfnStatusCB = parent->lpfnStatusCB;
170 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
173 return ret;
176 object_header_t *WININET_AddRef( object_header_t *info )
178 ULONG refs = InterlockedIncrement(&info->refs);
179 TRACE("%p -> refcount = %d\n", info, refs );
180 return info;
183 object_header_t *get_handle_object( HINTERNET hinternet )
185 object_header_t *info = NULL;
186 UINT_PTR handle = (UINT_PTR) hinternet;
188 EnterCriticalSection( &WININET_cs );
190 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
191 info = WININET_AddRef(handle_table[handle]);
193 LeaveCriticalSection( &WININET_cs );
195 TRACE("handle %ld -> %p\n", handle, info);
197 return info;
200 static void invalidate_handle(object_header_t *info)
202 object_header_t *child, *next;
204 if(!info->valid_handle)
205 return;
206 info->valid_handle = FALSE;
208 /* Free all children as native does */
209 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
211 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
212 invalidate_handle( child );
215 WININET_Release(info);
218 BOOL WININET_Release( object_header_t *info )
220 ULONG refs = InterlockedDecrement(&info->refs);
221 TRACE( "object %p refcount = %d\n", info, refs );
222 if( !refs )
224 invalidate_handle(info);
225 if ( info->vtbl->CloseConnection )
227 TRACE( "closing connection %p\n", info);
228 info->vtbl->CloseConnection( info );
230 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
231 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
232 || !(info->dwInternalFlags & INET_OPENURL))
234 INTERNET_SendCallback(info, info->dwContext,
235 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
236 sizeof(HINTERNET));
238 TRACE( "destroying object %p\n", info);
239 if ( info->htype != WH_HINIT )
240 list_remove( &info->entry );
241 info->vtbl->Destroy( info );
243 if(info->hInternet) {
244 UINT_PTR handle = (UINT_PTR)info->hInternet;
246 EnterCriticalSection( &WININET_cs );
248 handle_table[handle] = NULL;
249 if(next_handle > handle)
250 next_handle = handle;
252 LeaveCriticalSection( &WININET_cs );
255 heap_free(info);
257 return TRUE;
260 /***********************************************************************
261 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
263 * PARAMS
264 * hinstDLL [I] handle to the DLL's instance
265 * fdwReason [I]
266 * lpvReserved [I] reserved, must be NULL
268 * RETURNS
269 * Success: TRUE
270 * Failure: FALSE
273 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
275 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
277 switch (fdwReason) {
278 case DLL_PROCESS_ATTACH:
280 g_dwTlsErrIndex = TlsAlloc();
282 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
283 return FALSE;
285 if(!init_urlcache())
287 TlsFree(g_dwTlsErrIndex);
288 return FALSE;
291 WININET_hModule = hinstDLL;
292 break;
294 case DLL_THREAD_ATTACH:
295 break;
297 case DLL_THREAD_DETACH:
298 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
300 heap_free(TlsGetValue(g_dwTlsErrIndex));
302 break;
304 case DLL_PROCESS_DETACH:
305 if (lpvReserved) break;
306 collect_connections(COLLECT_CLEANUP);
307 NETCON_unload();
308 free_urlcache();
309 free_cookie();
311 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
313 heap_free(TlsGetValue(g_dwTlsErrIndex));
314 TlsFree(g_dwTlsErrIndex);
316 break;
318 return TRUE;
321 /***********************************************************************
322 * DllInstall (WININET.@)
324 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
326 FIXME("(%x %s): stub\n", bInstall, debugstr_w(cmdline));
327 return S_OK;
330 /***********************************************************************
331 * INTERNET_SaveProxySettings
333 * Stores the proxy settings given by lpwai into the registry
335 * RETURNS
336 * ERROR_SUCCESS if no error, or error code on fail
338 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
340 HKEY key;
341 LONG ret;
343 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
344 return ret;
346 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
348 RegCloseKey( key );
349 return ret;
352 if (lpwpi->proxy)
354 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
356 RegCloseKey( key );
357 return ret;
360 else
362 if ((ret = RegDeleteValueW( key, szProxyServer )) && ret != ERROR_FILE_NOT_FOUND)
364 RegCloseKey( key );
365 return ret;
369 RegCloseKey(key);
370 return ERROR_SUCCESS;
373 /***********************************************************************
374 * INTERNET_FindProxyForProtocol
376 * Searches the proxy string for a proxy of the given protocol.
377 * Returns the found proxy, or the default proxy if none of the given
378 * protocol is found.
380 * PARAMETERS
381 * szProxy [In] proxy string to search
382 * proto [In] protocol to search for, e.g. "http"
383 * foundProxy [Out] found proxy
384 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
386 * RETURNS
387 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
388 * *foundProxyLen is set to the required size in WCHARs, including the
389 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
391 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
393 LPCWSTR ptr;
394 BOOL ret = FALSE;
396 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
398 /* First, look for the specified protocol (proto=scheme://host:port) */
399 for (ptr = szProxy; !ret && ptr && *ptr; )
401 LPCWSTR end, equal;
403 if (!(end = strchrW(ptr, ' ')))
404 end = ptr + strlenW(ptr);
405 if ((equal = strchrW(ptr, '=')) && equal < end &&
406 equal - ptr == strlenW(proto) &&
407 !strncmpiW(proto, ptr, strlenW(proto)))
409 if (end - equal > *foundProxyLen)
411 WARN("buffer too short for %s\n",
412 debugstr_wn(equal + 1, end - equal - 1));
413 *foundProxyLen = end - equal;
414 SetLastError(ERROR_INSUFFICIENT_BUFFER);
416 else
418 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
419 foundProxy[end - equal] = 0;
420 ret = TRUE;
423 if (*end == ' ')
424 ptr = end + 1;
425 else
426 ptr = end;
428 if (!ret)
430 /* It wasn't found: look for no protocol */
431 for (ptr = szProxy; !ret && ptr && *ptr; )
433 LPCWSTR end;
435 if (!(end = strchrW(ptr, ' ')))
436 end = ptr + strlenW(ptr);
437 if (!strchrW(ptr, '='))
439 if (end - ptr + 1 > *foundProxyLen)
441 WARN("buffer too short for %s\n",
442 debugstr_wn(ptr, end - ptr));
443 *foundProxyLen = end - ptr + 1;
444 SetLastError(ERROR_INSUFFICIENT_BUFFER);
446 else
448 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
449 foundProxy[end - ptr] = 0;
450 ret = TRUE;
453 if (*end == ' ')
454 ptr = end + 1;
455 else
456 ptr = end;
459 if (ret)
460 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
461 debugstr_w(foundProxy));
462 return ret;
465 /***********************************************************************
466 * InternetInitializeAutoProxyDll (WININET.@)
468 * Setup the internal proxy
470 * PARAMETERS
471 * dwReserved
473 * RETURNS
474 * FALSE on failure
477 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
479 FIXME("STUB\n");
480 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
481 return FALSE;
484 /***********************************************************************
485 * DetectAutoProxyUrl (WININET.@)
487 * Auto detect the proxy url
489 * RETURNS
490 * FALSE on failure
493 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
494 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
496 FIXME("STUB\n");
497 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
498 return FALSE;
501 static void FreeProxyInfo( proxyinfo_t *lpwpi )
503 heap_free(lpwpi->proxy);
504 heap_free(lpwpi->proxyBypass);
505 heap_free(lpwpi->proxyUsername);
506 heap_free(lpwpi->proxyPassword);
509 static proxyinfo_t *global_proxy;
511 static void free_global_proxy( void )
513 EnterCriticalSection( &WININET_cs );
514 if (global_proxy)
516 FreeProxyInfo( global_proxy );
517 heap_free( global_proxy );
519 LeaveCriticalSection( &WININET_cs );
522 static BOOL parse_proxy_url( proxyinfo_t *info, const WCHAR *url )
524 static const WCHAR fmt[] = {'%','s',':','%','u',0};
525 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
526 WCHAR username[INTERNET_MAX_USER_NAME_LENGTH];
527 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
528 URL_COMPONENTSW uc;
530 hostname[0] = username[0] = password[0] = 0;
531 memset( &uc, 0, sizeof(uc) );
532 uc.dwStructSize = sizeof(uc);
533 uc.lpszHostName = hostname;
534 uc.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
535 uc.lpszUserName = username;
536 uc.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
537 uc.lpszPassword = password;
538 uc.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
540 if (!InternetCrackUrlW( url, 0, 0, &uc )) return FALSE;
541 if (!hostname[0])
543 if (!(info->proxy = heap_strdupW( url ))) return FALSE;
544 info->proxyUsername = NULL;
545 info->proxyPassword = NULL;
546 return TRUE;
548 if (!(info->proxy = heap_alloc( (strlenW(hostname) + 12) * sizeof(WCHAR) ))) return FALSE;
549 sprintfW( info->proxy, fmt, hostname, uc.nPort );
551 if (!username[0]) info->proxyUsername = NULL;
552 else if (!(info->proxyUsername = heap_strdupW( username )))
554 heap_free( info->proxy );
555 return FALSE;
557 if (!password[0]) info->proxyPassword = NULL;
558 else if (!(info->proxyPassword = heap_strdupW( password )))
560 heap_free( info->proxyUsername );
561 heap_free( info->proxy );
562 return FALSE;
564 return TRUE;
567 /***********************************************************************
568 * INTERNET_LoadProxySettings
570 * Loads proxy information from process-wide global settings, the registry,
571 * or the environment into lpwpi.
573 * The caller should call FreeProxyInfo when done with lpwpi.
575 * FIXME:
576 * The proxy may be specified in the form 'http=proxy.my.org'
577 * Presumably that means there can be ftp=ftpproxy.my.org too.
579 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
581 HKEY key;
582 DWORD type, len;
583 LPCSTR envproxy;
584 LONG ret;
586 memset( lpwpi, 0, sizeof(*lpwpi) );
588 EnterCriticalSection( &WININET_cs );
589 if (global_proxy)
591 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
592 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
593 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
595 LeaveCriticalSection( &WININET_cs );
597 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
599 FreeProxyInfo( lpwpi );
600 return ret;
603 len = sizeof(DWORD);
604 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
606 lpwpi->proxyEnabled = 0;
607 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
609 FreeProxyInfo( lpwpi );
610 RegCloseKey( key );
611 return ret;
615 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->proxyEnabled)
617 /* figure out how much memory the proxy setting takes */
618 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
620 LPWSTR szProxy, p;
621 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
623 if (!(szProxy = heap_alloc(len)))
625 RegCloseKey( key );
626 FreeProxyInfo( lpwpi );
627 return ERROR_OUTOFMEMORY;
629 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
631 /* find the http proxy, and strip away everything else */
632 p = strstrW( szProxy, szHttp );
633 if (p)
635 p += lstrlenW( szHttp );
636 lstrcpyW( szProxy, p );
638 p = strchrW( szProxy, ';' );
639 if (p) *p = 0;
641 FreeProxyInfo( lpwpi );
642 lpwpi->proxy = szProxy;
643 lpwpi->proxyBypass = NULL;
645 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi->proxy));
647 else
649 TRACE("No proxy server settings in registry.\n");
650 FreeProxyInfo( lpwpi );
651 lpwpi->proxy = NULL;
652 lpwpi->proxyBypass = NULL;
655 else if (envproxy)
657 WCHAR *envproxyW;
659 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
660 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
662 RegCloseKey( key );
663 return ERROR_OUTOFMEMORY;
665 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
667 FreeProxyInfo( lpwpi );
668 if (parse_proxy_url( lpwpi, envproxyW ))
670 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
671 lpwpi->proxyEnabled = 1;
672 lpwpi->proxyBypass = NULL;
674 else
676 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxyW));
677 lpwpi->proxyEnabled = 0;
678 lpwpi->proxy = NULL;
679 lpwpi->proxyBypass = NULL;
681 heap_free( envproxyW );
684 if (lpwpi->proxyEnabled)
686 TRACE("Proxy is enabled.\n");
688 if (!(envproxy = getenv( "no_proxy" )))
690 /* figure out how much memory the proxy setting takes */
691 if (!RegQueryValueExW( key, szProxyOverride, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
693 LPWSTR szProxy;
695 if (!(szProxy = heap_alloc(len)))
697 RegCloseKey( key );
698 return ERROR_OUTOFMEMORY;
700 RegQueryValueExW( key, szProxyOverride, NULL, &type, (BYTE*)szProxy, &len );
702 heap_free( lpwpi->proxyBypass );
703 lpwpi->proxyBypass = szProxy;
705 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi->proxyBypass));
707 else
709 heap_free( lpwpi->proxyBypass );
710 lpwpi->proxyBypass = NULL;
712 TRACE("No proxy bypass server settings in registry.\n");
715 else
717 WCHAR *envproxyW;
719 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
720 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
722 RegCloseKey( key );
723 return ERROR_OUTOFMEMORY;
725 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
727 heap_free( lpwpi->proxyBypass );
728 lpwpi->proxyBypass = envproxyW;
730 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
733 else TRACE("Proxy is disabled.\n");
735 RegCloseKey( key );
736 return ERROR_SUCCESS;
739 /***********************************************************************
740 * INTERNET_ConfigureProxy
742 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
744 proxyinfo_t wpi;
746 if (INTERNET_LoadProxySettings( &wpi ))
747 return FALSE;
749 if (wpi.proxyEnabled)
751 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi.proxy), debugstr_w(wpi.proxyBypass));
753 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
754 lpwai->proxy = wpi.proxy;
755 lpwai->proxyBypass = wpi.proxyBypass;
756 lpwai->proxyUsername = wpi.proxyUsername;
757 lpwai->proxyPassword = wpi.proxyPassword;
758 return TRUE;
761 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
762 FreeProxyInfo(&wpi);
763 return FALSE;
766 /***********************************************************************
767 * dump_INTERNET_FLAGS
769 * Helper function to TRACE the internet flags.
771 * RETURNS
772 * None
775 static void dump_INTERNET_FLAGS(DWORD dwFlags)
777 #define FE(x) { x, #x }
778 static const wininet_flag_info flag[] = {
779 FE(INTERNET_FLAG_RELOAD),
780 FE(INTERNET_FLAG_RAW_DATA),
781 FE(INTERNET_FLAG_EXISTING_CONNECT),
782 FE(INTERNET_FLAG_ASYNC),
783 FE(INTERNET_FLAG_PASSIVE),
784 FE(INTERNET_FLAG_NO_CACHE_WRITE),
785 FE(INTERNET_FLAG_MAKE_PERSISTENT),
786 FE(INTERNET_FLAG_FROM_CACHE),
787 FE(INTERNET_FLAG_SECURE),
788 FE(INTERNET_FLAG_KEEP_CONNECTION),
789 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
790 FE(INTERNET_FLAG_READ_PREFETCH),
791 FE(INTERNET_FLAG_NO_COOKIES),
792 FE(INTERNET_FLAG_NO_AUTH),
793 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
794 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
795 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
796 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
797 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
798 FE(INTERNET_FLAG_RESYNCHRONIZE),
799 FE(INTERNET_FLAG_HYPERLINK),
800 FE(INTERNET_FLAG_NO_UI),
801 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
802 FE(INTERNET_FLAG_CACHE_ASYNC),
803 FE(INTERNET_FLAG_FORMS_SUBMIT),
804 FE(INTERNET_FLAG_NEED_FILE),
805 FE(INTERNET_FLAG_TRANSFER_ASCII),
806 FE(INTERNET_FLAG_TRANSFER_BINARY)
808 #undef FE
809 unsigned int i;
811 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
812 if (flag[i].val & dwFlags) {
813 TRACE(" %s", flag[i].name);
814 dwFlags &= ~flag[i].val;
817 if (dwFlags)
818 TRACE(" Unknown flags (%08x)\n", dwFlags);
819 else
820 TRACE("\n");
823 /***********************************************************************
824 * INTERNET_CloseHandle (internal)
826 * Close internet handle
829 static VOID APPINFO_Destroy(object_header_t *hdr)
831 appinfo_t *lpwai = (appinfo_t*)hdr;
833 TRACE("%p\n",lpwai);
835 heap_free(lpwai->agent);
836 heap_free(lpwai->proxy);
837 heap_free(lpwai->proxyBypass);
838 heap_free(lpwai->proxyUsername);
839 heap_free(lpwai->proxyPassword);
842 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
844 appinfo_t *ai = (appinfo_t*)hdr;
846 switch(option) {
847 case INTERNET_OPTION_HANDLE_TYPE:
848 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
850 if (*size < sizeof(ULONG))
851 return ERROR_INSUFFICIENT_BUFFER;
853 *size = sizeof(DWORD);
854 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
855 return ERROR_SUCCESS;
857 case INTERNET_OPTION_USER_AGENT: {
858 DWORD bufsize;
860 TRACE("INTERNET_OPTION_USER_AGENT\n");
862 bufsize = *size;
864 if (unicode) {
865 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
867 *size = (len + 1) * sizeof(WCHAR);
868 if(!buffer || bufsize < *size)
869 return ERROR_INSUFFICIENT_BUFFER;
871 if (ai->agent)
872 strcpyW(buffer, ai->agent);
873 else
874 *(WCHAR *)buffer = 0;
875 /* If the buffer is copied, the returned length doesn't include
876 * the NULL terminator.
878 *size = len;
879 }else {
880 if (ai->agent)
881 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
882 else
883 *size = 1;
884 if(!buffer || bufsize < *size)
885 return ERROR_INSUFFICIENT_BUFFER;
887 if (ai->agent)
888 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
889 else
890 *(char *)buffer = 0;
891 /* If the buffer is copied, the returned length doesn't include
892 * the NULL terminator.
894 *size -= 1;
897 return ERROR_SUCCESS;
900 case INTERNET_OPTION_PROXY:
901 if(!size) return ERROR_INVALID_PARAMETER;
902 if (unicode) {
903 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
904 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
905 LPWSTR proxy, proxy_bypass;
907 if (ai->proxy)
908 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
909 if (ai->proxyBypass)
910 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
911 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
913 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
914 return ERROR_INSUFFICIENT_BUFFER;
916 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
917 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
919 pi->dwAccessType = ai->accessType;
920 pi->lpszProxy = NULL;
921 pi->lpszProxyBypass = NULL;
922 if (ai->proxy) {
923 lstrcpyW(proxy, ai->proxy);
924 pi->lpszProxy = proxy;
927 if (ai->proxyBypass) {
928 lstrcpyW(proxy_bypass, ai->proxyBypass);
929 pi->lpszProxyBypass = proxy_bypass;
932 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
933 return ERROR_SUCCESS;
934 }else {
935 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
936 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
937 LPSTR proxy, proxy_bypass;
939 if (ai->proxy)
940 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
941 if (ai->proxyBypass)
942 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
943 NULL, 0, NULL, NULL);
944 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
946 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
947 return ERROR_INSUFFICIENT_BUFFER;
949 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
950 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
952 pi->dwAccessType = ai->accessType;
953 pi->lpszProxy = NULL;
954 pi->lpszProxyBypass = NULL;
955 if (ai->proxy) {
956 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
957 pi->lpszProxy = proxy;
960 if (ai->proxyBypass) {
961 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
962 proxyBypassBytesRequired, NULL, NULL);
963 pi->lpszProxyBypass = proxy_bypass;
966 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
967 return ERROR_SUCCESS;
970 case INTERNET_OPTION_CONNECT_TIMEOUT:
971 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
973 if (*size < sizeof(ULONG))
974 return ERROR_INSUFFICIENT_BUFFER;
976 *(ULONG*)buffer = ai->connect_timeout;
977 *size = sizeof(ULONG);
979 return ERROR_SUCCESS;
982 return INET_QueryOption(hdr, option, buffer, size, unicode);
985 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
987 appinfo_t *ai = (appinfo_t*)hdr;
989 switch(option) {
990 case INTERNET_OPTION_CONNECT_TIMEOUT:
991 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
993 if(size != sizeof(connect_timeout))
994 return ERROR_INTERNET_BAD_OPTION_LENGTH;
995 if(!*(ULONG*)buf)
996 return ERROR_BAD_ARGUMENTS;
998 ai->connect_timeout = *(ULONG*)buf;
999 return ERROR_SUCCESS;
1000 case INTERNET_OPTION_USER_AGENT:
1001 heap_free(ai->agent);
1002 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
1003 return ERROR_SUCCESS;
1006 return INET_SetOption(hdr, option, buf, size);
1009 static const object_vtbl_t APPINFOVtbl = {
1010 APPINFO_Destroy,
1011 NULL,
1012 APPINFO_QueryOption,
1013 APPINFO_SetOption,
1014 NULL,
1015 NULL,
1016 NULL,
1017 NULL
1021 /***********************************************************************
1022 * InternetOpenW (WININET.@)
1024 * Per-application initialization of wininet
1026 * RETURNS
1027 * HINTERNET on success
1028 * NULL on failure
1031 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
1032 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
1034 appinfo_t *lpwai = NULL;
1036 if (TRACE_ON(wininet)) {
1037 #define FE(x) { x, #x }
1038 static const wininet_flag_info access_type[] = {
1039 FE(INTERNET_OPEN_TYPE_PRECONFIG),
1040 FE(INTERNET_OPEN_TYPE_DIRECT),
1041 FE(INTERNET_OPEN_TYPE_PROXY),
1042 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
1044 #undef FE
1045 DWORD i;
1046 const char *access_type_str = "Unknown";
1048 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
1049 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
1050 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
1051 if (access_type[i].val == dwAccessType) {
1052 access_type_str = access_type[i].name;
1053 break;
1056 TRACE(" access type : %s\n", access_type_str);
1057 TRACE(" flags :");
1058 dump_INTERNET_FLAGS(dwFlags);
1061 /* Clear any error information */
1062 INTERNET_SetLastError(0);
1064 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1065 SetLastError(ERROR_INVALID_PARAMETER);
1066 return NULL;
1069 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1070 if (!lpwai) {
1071 SetLastError(ERROR_OUTOFMEMORY);
1072 return NULL;
1075 lpwai->hdr.htype = WH_HINIT;
1076 lpwai->hdr.dwFlags = dwFlags;
1077 lpwai->accessType = dwAccessType;
1078 lpwai->proxyUsername = NULL;
1079 lpwai->proxyPassword = NULL;
1080 lpwai->connect_timeout = connect_timeout;
1082 lpwai->agent = heap_strdupW(lpszAgent);
1083 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1084 INTERNET_ConfigureProxy( lpwai );
1085 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1086 lpwai->proxy = heap_strdupW(lpszProxy);
1087 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1090 TRACE("returning %p\n", lpwai);
1092 return lpwai->hdr.hInternet;
1096 /***********************************************************************
1097 * InternetOpenA (WININET.@)
1099 * Per-application initialization of wininet
1101 * RETURNS
1102 * HINTERNET on success
1103 * NULL on failure
1106 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1107 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1109 WCHAR *szAgent, *szProxy, *szBypass;
1110 HINTERNET rc;
1112 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1113 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1115 szAgent = heap_strdupAtoW(lpszAgent);
1116 szProxy = heap_strdupAtoW(lpszProxy);
1117 szBypass = heap_strdupAtoW(lpszProxyBypass);
1119 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1121 heap_free(szAgent);
1122 heap_free(szProxy);
1123 heap_free(szBypass);
1124 return rc;
1127 /***********************************************************************
1128 * InternetGetLastResponseInfoA (WININET.@)
1130 * Return last wininet error description on the calling thread
1132 * RETURNS
1133 * TRUE on success of writing to buffer
1134 * FALSE on failure
1137 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1138 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1140 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1142 TRACE("\n");
1144 if (lpwite)
1146 *lpdwError = lpwite->dwError;
1147 if (lpwite->dwError)
1149 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1150 *lpdwBufferLength = strlen(lpszBuffer);
1152 else
1153 *lpdwBufferLength = 0;
1155 else
1157 *lpdwError = 0;
1158 *lpdwBufferLength = 0;
1161 return TRUE;
1164 /***********************************************************************
1165 * InternetGetLastResponseInfoW (WININET.@)
1167 * Return last wininet error description on the calling thread
1169 * RETURNS
1170 * TRUE on success of writing to buffer
1171 * FALSE on failure
1174 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1175 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1177 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1179 TRACE("\n");
1181 if (lpwite)
1183 *lpdwError = lpwite->dwError;
1184 if (lpwite->dwError)
1186 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1187 *lpdwBufferLength = lstrlenW(lpszBuffer);
1189 else
1190 *lpdwBufferLength = 0;
1192 else
1194 *lpdwError = 0;
1195 *lpdwBufferLength = 0;
1198 return TRUE;
1201 /***********************************************************************
1202 * InternetGetConnectedState (WININET.@)
1204 * Return connected state
1206 * RETURNS
1207 * TRUE if connected
1208 * if lpdwStatus is not null, return the status (off line,
1209 * modem, lan...) in it.
1210 * FALSE if not connected
1212 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1214 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1216 if (lpdwStatus) {
1217 WARN("always returning LAN connection.\n");
1218 *lpdwStatus = INTERNET_CONNECTION_LAN;
1220 return TRUE;
1224 /***********************************************************************
1225 * InternetGetConnectedStateExW (WININET.@)
1227 * Return connected state
1229 * PARAMS
1231 * lpdwStatus [O] Flags specifying the status of the internet connection.
1232 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1233 * dwNameLen [I] Size of the buffer, in characters.
1234 * dwReserved [I] Reserved. Must be set to 0.
1236 * RETURNS
1237 * TRUE if connected
1238 * if lpdwStatus is not null, return the status (off line,
1239 * modem, lan...) in it.
1240 * FALSE if not connected
1242 * NOTES
1243 * If the system has no available network connections, an empty string is
1244 * stored in lpszConnectionName. If there is a LAN connection, a localized
1245 * "LAN Connection" string is stored. Presumably, if only a dial-up
1246 * connection is available then the name of the dial-up connection is
1247 * returned. Why any application, other than the "Internet Settings" CPL,
1248 * would want to use this function instead of the simpler InternetGetConnectedStateW
1249 * function is beyond me.
1251 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1252 DWORD dwNameLen, DWORD dwReserved)
1254 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1256 /* Must be zero */
1257 if(dwReserved)
1258 return FALSE;
1260 if (lpdwStatus) {
1261 WARN("always returning LAN connection.\n");
1262 *lpdwStatus = INTERNET_CONNECTION_LAN;
1265 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1266 * the resource, avoid it as we must not change the buffer in this case */
1267 if(lpszConnectionName && dwNameLen) {
1268 *lpszConnectionName = '\0';
1269 LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1272 return TRUE;
1276 /***********************************************************************
1277 * InternetGetConnectedStateExA (WININET.@)
1279 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1280 DWORD dwNameLen, DWORD dwReserved)
1282 LPWSTR lpwszConnectionName = NULL;
1283 BOOL rc;
1285 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1287 if (lpszConnectionName && dwNameLen > 0)
1288 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1290 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1291 dwReserved);
1292 if (rc && lpwszConnectionName)
1293 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1294 dwNameLen, NULL, NULL);
1296 heap_free(lpwszConnectionName);
1297 return rc;
1301 /***********************************************************************
1302 * InternetConnectW (WININET.@)
1304 * Open a ftp, gopher or http session
1306 * RETURNS
1307 * HINTERNET a session handle on success
1308 * NULL on failure
1311 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1312 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1313 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1314 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1316 appinfo_t *hIC;
1317 HINTERNET rc = NULL;
1318 DWORD res = ERROR_SUCCESS;
1320 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1321 nServerPort, debugstr_w(lpszUserName), lpszPassword, dwService, dwFlags, dwContext);
1323 if (!lpszServerName)
1325 SetLastError(ERROR_INVALID_PARAMETER);
1326 return NULL;
1329 hIC = (appinfo_t*)get_handle_object( hInternet );
1330 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1332 res = ERROR_INVALID_HANDLE;
1333 goto lend;
1336 switch (dwService)
1338 case INTERNET_SERVICE_FTP:
1339 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1340 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1341 if(!rc)
1342 res = INTERNET_GetLastError();
1343 break;
1345 case INTERNET_SERVICE_HTTP:
1346 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1347 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1348 break;
1350 case INTERNET_SERVICE_GOPHER:
1351 default:
1352 break;
1354 lend:
1355 if( hIC )
1356 WININET_Release( &hIC->hdr );
1358 TRACE("returning %p\n", rc);
1359 SetLastError(res);
1360 return rc;
1364 /***********************************************************************
1365 * InternetConnectA (WININET.@)
1367 * Open a ftp, gopher or http session
1369 * RETURNS
1370 * HINTERNET a session handle on success
1371 * NULL on failure
1374 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1375 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1376 LPCSTR lpszUserName, LPCSTR lpszPassword,
1377 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1379 HINTERNET rc = NULL;
1380 LPWSTR szServerName;
1381 LPWSTR szUserName;
1382 LPWSTR szPassword;
1384 szServerName = heap_strdupAtoW(lpszServerName);
1385 szUserName = heap_strdupAtoW(lpszUserName);
1386 szPassword = heap_strdupAtoW(lpszPassword);
1388 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1389 szUserName, szPassword, dwService, dwFlags, dwContext);
1391 heap_free(szServerName);
1392 heap_free(szUserName);
1393 heap_free(szPassword);
1394 return rc;
1398 /***********************************************************************
1399 * InternetFindNextFileA (WININET.@)
1401 * Continues a file search from a previous call to FindFirstFile
1403 * RETURNS
1404 * TRUE on success
1405 * FALSE on failure
1408 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1410 BOOL ret;
1411 WIN32_FIND_DATAW fd;
1413 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1414 if(lpvFindData)
1415 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1416 return ret;
1419 /***********************************************************************
1420 * InternetFindNextFileW (WININET.@)
1422 * Continues a file search from a previous call to FindFirstFile
1424 * RETURNS
1425 * TRUE on success
1426 * FALSE on failure
1429 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1431 object_header_t *hdr;
1432 DWORD res;
1434 TRACE("\n");
1436 hdr = get_handle_object(hFind);
1437 if(!hdr) {
1438 WARN("Invalid handle\n");
1439 SetLastError(ERROR_INVALID_HANDLE);
1440 return FALSE;
1443 if(hdr->vtbl->FindNextFileW) {
1444 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1445 }else {
1446 WARN("Handle doesn't support NextFile\n");
1447 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1450 WININET_Release(hdr);
1452 if(res != ERROR_SUCCESS)
1453 SetLastError(res);
1454 return res == ERROR_SUCCESS;
1457 /***********************************************************************
1458 * InternetCloseHandle (WININET.@)
1460 * Generic close handle function
1462 * RETURNS
1463 * TRUE on success
1464 * FALSE on failure
1467 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1469 object_header_t *obj;
1471 TRACE("%p\n", hInternet);
1473 obj = get_handle_object( hInternet );
1474 if (!obj) {
1475 SetLastError(ERROR_INVALID_HANDLE);
1476 return FALSE;
1479 invalidate_handle(obj);
1480 WININET_Release(obj);
1482 return TRUE;
1486 /***********************************************************************
1487 * ConvertUrlComponentValue (Internal)
1489 * Helper function for InternetCrackUrlA
1492 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1493 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1494 LPCSTR lpszStart, LPCWSTR lpwszStart)
1496 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1497 if (*dwComponentLen != 0)
1499 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1500 if (*lppszComponent == NULL)
1502 if (lpwszComponent)
1504 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1505 *lppszComponent = (LPSTR)lpszStart + offset;
1507 else
1508 *lppszComponent = NULL;
1510 *dwComponentLen = nASCIILength;
1512 else
1514 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1515 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1516 (*lppszComponent)[ncpylen]=0;
1517 *dwComponentLen = ncpylen;
1523 /***********************************************************************
1524 * InternetCrackUrlA (WININET.@)
1526 * See InternetCrackUrlW.
1528 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1529 LPURL_COMPONENTSA lpUrlComponents)
1531 DWORD nLength;
1532 URL_COMPONENTSW UCW;
1533 BOOL ret = FALSE;
1534 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1535 *scheme = NULL, *extra = NULL;
1537 TRACE("(%s %u %x %p)\n",
1538 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1539 dwUrlLength, dwFlags, lpUrlComponents);
1541 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1542 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1544 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1545 return FALSE;
1548 if(dwUrlLength<=0)
1549 dwUrlLength=-1;
1550 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1552 /* if dwUrlLength=-1 then nLength includes null but length to
1553 InternetCrackUrlW should not include it */
1554 if (dwUrlLength == -1) nLength--;
1556 lpwszUrl = heap_alloc((nLength + 1) * sizeof(WCHAR));
1557 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1558 lpwszUrl[nLength] = '\0';
1560 memset(&UCW,0,sizeof(UCW));
1561 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1562 if (lpUrlComponents->dwHostNameLength)
1564 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1565 if (lpUrlComponents->lpszHostName)
1567 hostname = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1568 UCW.lpszHostName = hostname;
1571 if (lpUrlComponents->dwUserNameLength)
1573 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1574 if (lpUrlComponents->lpszUserName)
1576 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1577 UCW.lpszUserName = username;
1580 if (lpUrlComponents->dwPasswordLength)
1582 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1583 if (lpUrlComponents->lpszPassword)
1585 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1586 UCW.lpszPassword = password;
1589 if (lpUrlComponents->dwUrlPathLength)
1591 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1592 if (lpUrlComponents->lpszUrlPath)
1594 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1595 UCW.lpszUrlPath = path;
1598 if (lpUrlComponents->dwSchemeLength)
1600 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1601 if (lpUrlComponents->lpszScheme)
1603 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1604 UCW.lpszScheme = scheme;
1607 if (lpUrlComponents->dwExtraInfoLength)
1609 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1610 if (lpUrlComponents->lpszExtraInfo)
1612 extra = heap_alloc(UCW.dwExtraInfoLength * sizeof(WCHAR));
1613 UCW.lpszExtraInfo = extra;
1616 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1618 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1619 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1620 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1621 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1622 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1623 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1624 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1625 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1626 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1627 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1628 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1629 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1631 lpUrlComponents->nScheme = UCW.nScheme;
1632 lpUrlComponents->nPort = UCW.nPort;
1634 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1635 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1636 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1637 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1638 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1640 heap_free(lpwszUrl);
1641 heap_free(hostname);
1642 heap_free(username);
1643 heap_free(password);
1644 heap_free(path);
1645 heap_free(scheme);
1646 heap_free(extra);
1647 return ret;
1650 static const WCHAR url_schemes[][7] =
1652 {'f','t','p',0},
1653 {'g','o','p','h','e','r',0},
1654 {'h','t','t','p',0},
1655 {'h','t','t','p','s',0},
1656 {'f','i','l','e',0},
1657 {'n','e','w','s',0},
1658 {'m','a','i','l','t','o',0},
1659 {'r','e','s',0},
1662 /***********************************************************************
1663 * GetInternetSchemeW (internal)
1665 * Get scheme of url
1667 * RETURNS
1668 * scheme on success
1669 * INTERNET_SCHEME_UNKNOWN on failure
1672 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1674 int i;
1676 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1678 if(lpszScheme==NULL)
1679 return INTERNET_SCHEME_UNKNOWN;
1681 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1682 if (!strncmpiW(lpszScheme, url_schemes[i], nMaxCmp))
1683 return INTERNET_SCHEME_FIRST + i;
1685 return INTERNET_SCHEME_UNKNOWN;
1688 /***********************************************************************
1689 * SetUrlComponentValueW (Internal)
1691 * Helper function for InternetCrackUrlW
1693 * PARAMS
1694 * lppszComponent [O] Holds the returned string
1695 * dwComponentLen [I] Holds the size of lppszComponent
1696 * [O] Holds the length of the string in lppszComponent without '\0'
1697 * lpszStart [I] Holds the string to copy from
1698 * len [I] Holds the length of lpszStart without '\0'
1700 * RETURNS
1701 * TRUE on success
1702 * FALSE on failure
1705 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1707 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1709 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1710 return FALSE;
1712 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1714 if (*lppszComponent == NULL)
1716 *lppszComponent = (LPWSTR)lpszStart;
1717 *dwComponentLen = len;
1719 else
1721 DWORD ncpylen = min((*dwComponentLen)-1, len);
1722 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1723 (*lppszComponent)[ncpylen] = '\0';
1724 *dwComponentLen = ncpylen;
1728 return TRUE;
1731 /***********************************************************************
1732 * InternetCrackUrlW (WININET.@)
1734 * Break up URL into its components
1736 * RETURNS
1737 * TRUE on success
1738 * FALSE on failure
1740 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1741 LPURL_COMPONENTSW lpUC)
1744 * RFC 1808
1745 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1748 LPCWSTR lpszParam = NULL;
1749 BOOL found_colon = FALSE;
1750 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1751 LPCWSTR lpszcp = NULL, lpszNetLoc;
1752 LPWSTR lpszUrl_decode = NULL;
1753 DWORD dwUrlLength = dwUrlLength_orig;
1755 TRACE("(%s %u %x %p)\n",
1756 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1757 dwUrlLength, dwFlags, lpUC);
1759 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1761 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1762 return FALSE;
1764 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1766 if (dwFlags & ICU_DECODE)
1768 WCHAR *url_tmp;
1769 DWORD len = dwUrlLength + 1;
1771 if (!(url_tmp = heap_alloc(len * sizeof(WCHAR))))
1773 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1774 return FALSE;
1776 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1777 url_tmp[dwUrlLength] = 0;
1778 if (!(lpszUrl_decode = heap_alloc(len * sizeof(WCHAR))))
1780 heap_free(url_tmp);
1781 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1782 return FALSE;
1784 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1786 dwUrlLength = len;
1787 lpszUrl = lpszUrl_decode;
1789 heap_free(url_tmp);
1791 lpszap = lpszUrl;
1793 /* Determine if the URI is absolute. */
1794 while (lpszap - lpszUrl < dwUrlLength)
1796 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1798 lpszap++;
1799 continue;
1801 if (*lpszap == ':')
1803 found_colon = TRUE;
1804 lpszcp = lpszap;
1806 else
1808 lpszcp = lpszUrl; /* Relative url */
1811 break;
1814 if(!found_colon){
1815 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1816 return FALSE;
1819 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1820 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1822 /* Parse <params> */
1823 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1824 if(!lpszParam)
1825 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1827 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1828 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1831 /* Get scheme first. */
1832 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1833 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1834 lpszUrl, lpszcp - lpszUrl);
1836 /* Eat ':' in protocol. */
1837 lpszcp++;
1839 /* double slash indicates the net_loc portion is present */
1840 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1842 lpszcp += 2;
1844 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1845 if (lpszParam)
1847 if (lpszNetLoc)
1848 lpszNetLoc = min(lpszNetLoc, lpszParam);
1849 else
1850 lpszNetLoc = lpszParam;
1852 else if (!lpszNetLoc)
1853 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1855 /* Parse net-loc */
1856 if (lpszNetLoc)
1858 LPCWSTR lpszHost;
1859 LPCWSTR lpszPort;
1861 /* [<user>[<:password>]@]<host>[:<port>] */
1862 /* First find the user and password if they exist */
1864 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1865 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1867 /* username and password not specified. */
1868 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1869 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1871 else /* Parse out username and password */
1873 LPCWSTR lpszUser = lpszcp;
1874 LPCWSTR lpszPasswd = lpszHost;
1876 while (lpszcp < lpszHost)
1878 if (*lpszcp == ':')
1879 lpszPasswd = lpszcp;
1881 lpszcp++;
1884 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1885 lpszUser, lpszPasswd - lpszUser);
1887 if (lpszPasswd != lpszHost)
1888 lpszPasswd++;
1889 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1890 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1891 lpszHost - lpszPasswd);
1893 lpszcp++; /* Advance to beginning of host */
1896 /* Parse <host><:port> */
1898 lpszHost = lpszcp;
1899 lpszPort = lpszNetLoc;
1901 /* special case for res:// URLs: there is no port here, so the host is the
1902 entire string up to the first '/' */
1903 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1905 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1906 lpszHost, lpszPort - lpszHost);
1907 lpszcp=lpszNetLoc;
1909 else
1911 while (lpszcp < lpszNetLoc)
1913 if (*lpszcp == ':')
1914 lpszPort = lpszcp;
1916 lpszcp++;
1919 /* If the scheme is "file" and the host is just one letter, it's not a host */
1920 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1922 lpszcp=lpszHost;
1923 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1924 NULL, 0);
1926 else
1928 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1929 lpszHost, lpszPort - lpszHost);
1930 if (lpszPort != lpszNetLoc)
1931 lpUC->nPort = atoiW(++lpszPort);
1932 else switch (lpUC->nScheme)
1934 case INTERNET_SCHEME_HTTP:
1935 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1936 break;
1937 case INTERNET_SCHEME_HTTPS:
1938 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1939 break;
1940 case INTERNET_SCHEME_FTP:
1941 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1942 break;
1943 case INTERNET_SCHEME_GOPHER:
1944 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1945 break;
1946 default:
1947 break;
1953 else
1955 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1956 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1957 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1960 /* Here lpszcp points to:
1962 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1963 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1965 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1967 DWORD len;
1969 /* Only truncate the parameter list if it's already been saved
1970 * in lpUC->lpszExtraInfo.
1972 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1973 len = lpszParam - lpszcp;
1974 else
1976 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1977 * newlines if necessary.
1979 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1980 if (lpsznewline != NULL)
1981 len = lpsznewline - lpszcp;
1982 else
1983 len = dwUrlLength-(lpszcp-lpszUrl);
1985 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1986 lpUC->nScheme == INTERNET_SCHEME_FILE)
1988 WCHAR tmppath[MAX_PATH];
1989 if (*lpszcp == '/')
1991 len = MAX_PATH;
1992 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
1994 else
1996 WCHAR *iter;
1997 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1998 tmppath[len] = '\0';
2000 iter = tmppath;
2001 while (*iter) {
2002 if (*iter == '/')
2003 *iter = '\\';
2004 ++iter;
2007 /* if ends in \. or \.. append a backslash */
2008 if (tmppath[len - 1] == '.' &&
2009 (tmppath[len - 2] == '\\' ||
2010 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
2012 if (len < MAX_PATH - 1)
2014 tmppath[len] = '\\';
2015 tmppath[len+1] = '\0';
2016 ++len;
2019 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
2020 tmppath, len);
2022 else
2023 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
2024 lpszcp, len);
2026 else
2028 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
2029 lpUC->lpszUrlPath[0] = 0;
2030 lpUC->dwUrlPathLength = 0;
2033 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
2034 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
2035 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
2036 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
2037 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
2039 heap_free( lpszUrl_decode );
2040 return TRUE;
2043 /***********************************************************************
2044 * InternetAttemptConnect (WININET.@)
2046 * Attempt to make a connection to the internet
2048 * RETURNS
2049 * ERROR_SUCCESS on success
2050 * Error value on failure
2053 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
2055 FIXME("Stub\n");
2056 return ERROR_SUCCESS;
2060 /***********************************************************************
2061 * convert_url_canonicalization_flags
2063 * Helper for InternetCanonicalizeUrl
2065 * PARAMS
2066 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
2068 * RETURNS
2069 * Flags suitable for UrlCanonicalize
2071 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
2073 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
2075 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
2076 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
2077 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
2078 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
2079 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2080 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
2081 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
2083 return dwUrlFlags;
2086 /***********************************************************************
2087 * InternetCanonicalizeUrlA (WININET.@)
2089 * Escape unsafe characters and spaces
2091 * RETURNS
2092 * TRUE on success
2093 * FALSE on failure
2096 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
2097 LPDWORD lpdwBufferLength, DWORD dwFlags)
2099 HRESULT hr;
2101 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl), lpszBuffer,
2102 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2104 dwFlags = convert_url_canonicalization_flags(dwFlags);
2105 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2106 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2107 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2109 return hr == S_OK;
2112 /***********************************************************************
2113 * InternetCanonicalizeUrlW (WININET.@)
2115 * Escape unsafe characters and spaces
2117 * RETURNS
2118 * TRUE on success
2119 * FALSE on failure
2122 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
2123 LPDWORD lpdwBufferLength, DWORD dwFlags)
2125 HRESULT hr;
2127 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2128 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2130 dwFlags = convert_url_canonicalization_flags(dwFlags);
2131 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2132 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2133 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2135 return hr == S_OK;
2138 /* #################################################### */
2140 static INTERNET_STATUS_CALLBACK set_status_callback(
2141 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2143 INTERNET_STATUS_CALLBACK ret;
2145 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2146 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2148 ret = lpwh->lpfnStatusCB;
2149 lpwh->lpfnStatusCB = callback;
2151 return ret;
2154 /***********************************************************************
2155 * InternetSetStatusCallbackA (WININET.@)
2157 * Sets up a callback function which is called as progress is made
2158 * during an operation.
2160 * RETURNS
2161 * Previous callback or NULL on success
2162 * INTERNET_INVALID_STATUS_CALLBACK on failure
2165 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2166 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2168 INTERNET_STATUS_CALLBACK retVal;
2169 object_header_t *lpwh;
2171 TRACE("%p\n", hInternet);
2173 if (!(lpwh = get_handle_object(hInternet)))
2174 return INTERNET_INVALID_STATUS_CALLBACK;
2176 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2178 WININET_Release( lpwh );
2179 return retVal;
2182 /***********************************************************************
2183 * InternetSetStatusCallbackW (WININET.@)
2185 * Sets up a callback function which is called as progress is made
2186 * during an operation.
2188 * RETURNS
2189 * Previous callback or NULL on success
2190 * INTERNET_INVALID_STATUS_CALLBACK on failure
2193 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2194 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2196 INTERNET_STATUS_CALLBACK retVal;
2197 object_header_t *lpwh;
2199 TRACE("%p\n", hInternet);
2201 if (!(lpwh = get_handle_object(hInternet)))
2202 return INTERNET_INVALID_STATUS_CALLBACK;
2204 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2206 WININET_Release( lpwh );
2207 return retVal;
2210 /***********************************************************************
2211 * InternetSetFilePointer (WININET.@)
2213 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2214 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2216 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2217 return FALSE;
2220 /***********************************************************************
2221 * InternetWriteFile (WININET.@)
2223 * Write data to an open internet file
2225 * RETURNS
2226 * TRUE on success
2227 * FALSE on failure
2230 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2231 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2233 object_header_t *lpwh;
2234 BOOL res;
2236 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2238 lpwh = get_handle_object( hFile );
2239 if (!lpwh) {
2240 WARN("Invalid handle\n");
2241 SetLastError(ERROR_INVALID_HANDLE);
2242 return FALSE;
2245 if(lpwh->vtbl->WriteFile) {
2246 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2247 }else {
2248 WARN("No Writefile method.\n");
2249 res = ERROR_INVALID_HANDLE;
2252 WININET_Release( lpwh );
2254 if(res != ERROR_SUCCESS)
2255 SetLastError(res);
2256 return res == ERROR_SUCCESS;
2260 /***********************************************************************
2261 * InternetReadFile (WININET.@)
2263 * Read data from an open internet file
2265 * RETURNS
2266 * TRUE on success
2267 * FALSE on failure
2270 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2271 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2273 object_header_t *hdr;
2274 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2276 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2278 hdr = get_handle_object(hFile);
2279 if (!hdr) {
2280 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2281 return FALSE;
2284 if(hdr->vtbl->ReadFile)
2285 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2287 WININET_Release(hdr);
2289 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2290 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2292 if(res != ERROR_SUCCESS)
2293 SetLastError(res);
2294 return res == ERROR_SUCCESS;
2297 /***********************************************************************
2298 * InternetReadFileExA (WININET.@)
2300 * Read data from an open internet file
2302 * PARAMS
2303 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2304 * lpBuffersOut [I/O] Buffer.
2305 * dwFlags [I] Flags. See notes.
2306 * dwContext [I] Context for callbacks.
2308 * RETURNS
2309 * TRUE on success
2310 * FALSE on failure
2312 * NOTES
2313 * The parameter dwFlags include zero or more of the following flags:
2314 *|IRF_ASYNC - Makes the call asynchronous.
2315 *|IRF_SYNC - Makes the call synchronous.
2316 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2317 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2319 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2321 * SEE
2322 * InternetOpenUrlA(), HttpOpenRequestA()
2324 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2325 DWORD dwFlags, DWORD_PTR dwContext)
2327 object_header_t *hdr;
2328 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2330 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2332 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2333 SetLastError(ERROR_INVALID_PARAMETER);
2334 return FALSE;
2337 hdr = get_handle_object(hFile);
2338 if (!hdr) {
2339 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2340 return FALSE;
2343 if(hdr->vtbl->ReadFileEx)
2344 res = hdr->vtbl->ReadFileEx(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2345 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2347 WININET_Release(hdr);
2349 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2350 res, lpBuffersOut->dwBufferLength);
2352 if(res != ERROR_SUCCESS)
2353 SetLastError(res);
2354 return res == ERROR_SUCCESS;
2357 /***********************************************************************
2358 * InternetReadFileExW (WININET.@)
2359 * SEE
2360 * InternetReadFileExA()
2362 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2363 DWORD dwFlags, DWORD_PTR dwContext)
2365 object_header_t *hdr;
2366 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2368 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2370 if (lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2371 SetLastError(ERROR_INVALID_PARAMETER);
2372 return FALSE;
2375 hdr = get_handle_object(hFile);
2376 if (!hdr) {
2377 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2378 return FALSE;
2381 if(hdr->vtbl->ReadFileEx)
2382 res = hdr->vtbl->ReadFileEx(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2383 dwFlags, dwContext);
2385 WININET_Release(hdr);
2387 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2388 res, lpBuffer->dwBufferLength);
2390 if(res != ERROR_SUCCESS)
2391 SetLastError(res);
2392 return res == ERROR_SUCCESS;
2395 static BOOL get_proxy_autoconfig_url( char *buf, DWORD buflen )
2397 #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
2399 CFDictionaryRef settings = CFNetworkCopySystemProxySettings();
2400 const void *ref;
2401 BOOL ret = FALSE;
2403 if (!settings) return FALSE;
2405 if (!(ref = CFDictionaryGetValue( settings, kCFNetworkProxiesProxyAutoConfigURLString )))
2407 CFRelease( settings );
2408 return FALSE;
2410 if (CFStringGetCString( ref, buf, buflen, kCFStringEncodingASCII ))
2412 TRACE( "returning %s\n", debugstr_a(buf) );
2413 ret = TRUE;
2415 CFRelease( settings );
2416 return ret;
2417 #else
2418 FIXME( "no support on this platform\n" );
2419 return FALSE;
2420 #endif
2423 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2425 /* FIXME: This function currently handles more options than it should. Options requiring
2426 * proper handles should be moved to proper functions */
2427 switch(option) {
2428 case INTERNET_OPTION_HTTP_VERSION:
2429 if (*size < sizeof(HTTP_VERSION_INFO))
2430 return ERROR_INSUFFICIENT_BUFFER;
2433 * Presently hardcoded to 1.1
2435 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2436 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2437 *size = sizeof(HTTP_VERSION_INFO);
2439 return ERROR_SUCCESS;
2441 case INTERNET_OPTION_CONNECTED_STATE:
2442 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2444 if (*size < sizeof(ULONG))
2445 return ERROR_INSUFFICIENT_BUFFER;
2447 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2448 *size = sizeof(ULONG);
2450 return ERROR_SUCCESS;
2452 case INTERNET_OPTION_PROXY: {
2453 appinfo_t ai;
2454 BOOL ret;
2456 TRACE("Getting global proxy info\n");
2457 memset(&ai, 0, sizeof(appinfo_t));
2458 INTERNET_ConfigureProxy(&ai);
2460 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2461 APPINFO_Destroy(&ai.hdr);
2462 return ret;
2465 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2466 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2468 if (*size < sizeof(ULONG))
2469 return ERROR_INSUFFICIENT_BUFFER;
2471 *(ULONG*)buffer = max_conns;
2472 *size = sizeof(ULONG);
2474 return ERROR_SUCCESS;
2476 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2477 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2479 if (*size < sizeof(ULONG))
2480 return ERROR_INSUFFICIENT_BUFFER;
2482 *(ULONG*)buffer = max_1_0_conns;
2483 *size = sizeof(ULONG);
2485 return ERROR_SUCCESS;
2487 case INTERNET_OPTION_SECURITY_FLAGS:
2488 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2489 return ERROR_SUCCESS;
2491 case INTERNET_OPTION_VERSION: {
2492 static const INTERNET_VERSION_INFO info = { 1, 2 };
2494 TRACE("INTERNET_OPTION_VERSION\n");
2496 if (*size < sizeof(INTERNET_VERSION_INFO))
2497 return ERROR_INSUFFICIENT_BUFFER;
2499 memcpy(buffer, &info, sizeof(info));
2500 *size = sizeof(info);
2502 return ERROR_SUCCESS;
2505 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2506 char url[INTERNET_MAX_URL_LENGTH + 1];
2507 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2508 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2509 DWORD res = ERROR_SUCCESS, i;
2510 proxyinfo_t pi;
2511 BOOL have_url;
2512 LONG ret;
2514 TRACE("Getting global proxy info\n");
2515 if((ret = INTERNET_LoadProxySettings(&pi)))
2516 return ret;
2518 have_url = get_proxy_autoconfig_url(url, sizeof(url));
2520 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2522 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2523 FreeProxyInfo(&pi);
2524 return ERROR_INSUFFICIENT_BUFFER;
2527 for (i = 0; i < con->dwOptionCount; i++) {
2528 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2529 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2531 switch (optionW->dwOption) {
2532 case INTERNET_PER_CONN_FLAGS:
2533 if(pi.proxyEnabled)
2534 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2535 else
2536 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2537 if (have_url)
2538 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2539 optionW->Value.dwValue |= PROXY_TYPE_DIRECT|PROXY_TYPE_AUTO_PROXY_URL;
2540 break;
2542 case INTERNET_PER_CONN_PROXY_SERVER:
2543 if (unicode)
2544 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2545 else
2546 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2547 break;
2549 case INTERNET_PER_CONN_PROXY_BYPASS:
2550 if (unicode)
2551 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2552 else
2553 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2554 break;
2556 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2557 if (!have_url)
2558 optionW->Value.pszValue = NULL;
2559 else if (unicode)
2560 optionW->Value.pszValue = heap_strdupAtoW(url);
2561 else
2562 optionA->Value.pszValue = heap_strdupA(url);
2563 break;
2565 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2566 optionW->Value.dwValue = AUTO_PROXY_FLAG_ALWAYS_DETECT;
2567 break;
2569 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2570 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2571 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2572 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2573 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2574 memset(&optionW->Value, 0, sizeof(optionW->Value));
2575 break;
2577 default:
2578 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2579 res = ERROR_INVALID_PARAMETER;
2580 break;
2583 FreeProxyInfo(&pi);
2585 return res;
2587 case INTERNET_OPTION_REQUEST_FLAGS:
2588 case INTERNET_OPTION_USER_AGENT:
2589 *size = 0;
2590 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2591 case INTERNET_OPTION_POLICY:
2592 return ERROR_INVALID_PARAMETER;
2593 case INTERNET_OPTION_CONNECT_TIMEOUT:
2594 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2596 if (*size < sizeof(ULONG))
2597 return ERROR_INSUFFICIENT_BUFFER;
2599 *(ULONG*)buffer = connect_timeout;
2600 *size = sizeof(ULONG);
2602 return ERROR_SUCCESS;
2605 FIXME("Stub for %d\n", option);
2606 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2609 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2611 switch(option) {
2612 case INTERNET_OPTION_CONTEXT_VALUE:
2613 if (!size)
2614 return ERROR_INVALID_PARAMETER;
2616 if (*size < sizeof(DWORD_PTR)) {
2617 *size = sizeof(DWORD_PTR);
2618 return ERROR_INSUFFICIENT_BUFFER;
2620 if (!buffer)
2621 return ERROR_INVALID_PARAMETER;
2623 *(DWORD_PTR *)buffer = hdr->dwContext;
2624 *size = sizeof(DWORD_PTR);
2625 return ERROR_SUCCESS;
2627 case INTERNET_OPTION_REQUEST_FLAGS:
2628 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2629 *size = sizeof(DWORD);
2630 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2632 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2633 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2634 WARN("Called on global option %u\n", option);
2635 return ERROR_INTERNET_INVALID_OPERATION;
2638 /* FIXME: we shouldn't call it here */
2639 return query_global_option(option, buffer, size, unicode);
2642 /***********************************************************************
2643 * InternetQueryOptionW (WININET.@)
2645 * Queries an options on the specified handle
2647 * RETURNS
2648 * TRUE on success
2649 * FALSE on failure
2652 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2653 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2655 object_header_t *hdr;
2656 DWORD res = ERROR_INVALID_HANDLE;
2658 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2660 if(hInternet) {
2661 hdr = get_handle_object(hInternet);
2662 if (hdr) {
2663 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2664 WININET_Release(hdr);
2666 }else {
2667 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2670 if(res != ERROR_SUCCESS)
2671 SetLastError(res);
2672 return res == ERROR_SUCCESS;
2675 /***********************************************************************
2676 * InternetQueryOptionA (WININET.@)
2678 * Queries an options on the specified handle
2680 * RETURNS
2681 * TRUE on success
2682 * FALSE on failure
2685 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2686 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2688 object_header_t *hdr;
2689 DWORD res = ERROR_INVALID_HANDLE;
2691 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2693 if(hInternet) {
2694 hdr = get_handle_object(hInternet);
2695 if (hdr) {
2696 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2697 WININET_Release(hdr);
2699 }else {
2700 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2703 if(res != ERROR_SUCCESS)
2704 SetLastError(res);
2705 return res == ERROR_SUCCESS;
2708 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2710 switch(option) {
2711 case INTERNET_OPTION_CALLBACK:
2712 WARN("Not settable option %u\n", option);
2713 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2714 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2715 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2716 WARN("Called on global option %u\n", option);
2717 return ERROR_INTERNET_INVALID_OPERATION;
2720 return ERROR_INTERNET_INVALID_OPTION;
2723 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2725 switch(option) {
2726 case INTERNET_OPTION_CALLBACK:
2727 WARN("Not global option %u\n", option);
2728 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2730 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2731 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2733 if(size != sizeof(max_conns))
2734 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2735 if(!*(ULONG*)buf)
2736 return ERROR_BAD_ARGUMENTS;
2738 max_conns = *(ULONG*)buf;
2739 return ERROR_SUCCESS;
2741 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2742 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2744 if(size != sizeof(max_1_0_conns))
2745 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2746 if(!*(ULONG*)buf)
2747 return ERROR_BAD_ARGUMENTS;
2749 max_1_0_conns = *(ULONG*)buf;
2750 return ERROR_SUCCESS;
2752 case INTERNET_OPTION_CONNECT_TIMEOUT:
2753 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2755 if(size != sizeof(connect_timeout))
2756 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2757 if(!*(ULONG*)buf)
2758 return ERROR_BAD_ARGUMENTS;
2760 connect_timeout = *(ULONG*)buf;
2761 return ERROR_SUCCESS;
2763 case INTERNET_OPTION_SETTINGS_CHANGED:
2764 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2765 collect_connections(COLLECT_CONNECTIONS);
2766 return ERROR_SUCCESS;
2768 case INTERNET_OPTION_SUPPRESS_BEHAVIOR:
2769 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2771 if(size != sizeof(ULONG))
2772 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2774 FIXME("%08x\n", *(ULONG*)buf);
2775 return ERROR_SUCCESS;
2778 return ERROR_INTERNET_INVALID_OPTION;
2781 /***********************************************************************
2782 * InternetSetOptionW (WININET.@)
2784 * Sets an options on the specified handle
2786 * RETURNS
2787 * TRUE on success
2788 * FALSE on failure
2791 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2792 LPVOID lpBuffer, DWORD dwBufferLength)
2794 object_header_t *lpwhh;
2795 BOOL ret = TRUE;
2796 DWORD res;
2798 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2800 lpwhh = (object_header_t*) get_handle_object( hInternet );
2801 if(lpwhh)
2802 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2803 else
2804 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2806 if(res != ERROR_INTERNET_INVALID_OPTION) {
2807 if(lpwhh)
2808 WININET_Release(lpwhh);
2810 if(res != ERROR_SUCCESS)
2811 SetLastError(res);
2813 return res == ERROR_SUCCESS;
2816 switch (dwOption)
2818 case INTERNET_OPTION_HTTP_VERSION:
2820 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2821 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2823 break;
2824 case INTERNET_OPTION_ERROR_MASK:
2826 if(!lpwhh) {
2827 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2828 return FALSE;
2829 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2830 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2831 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2832 SetLastError(ERROR_INVALID_PARAMETER);
2833 ret = FALSE;
2834 } else if(dwBufferLength != sizeof(ULONG)) {
2835 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2836 ret = FALSE;
2837 } else
2838 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2839 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2841 break;
2842 case INTERNET_OPTION_PROXY:
2844 INTERNET_PROXY_INFOW *info = lpBuffer;
2846 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2848 SetLastError(ERROR_INVALID_PARAMETER);
2849 return FALSE;
2851 if (!hInternet)
2853 EnterCriticalSection( &WININET_cs );
2854 free_global_proxy();
2855 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2856 if (global_proxy)
2858 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2860 global_proxy->proxyEnabled = 1;
2861 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2862 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2864 else
2866 global_proxy->proxyEnabled = 0;
2867 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2870 LeaveCriticalSection( &WININET_cs );
2872 else
2874 /* In general, each type of object should handle
2875 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2876 * get silently dropped.
2878 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2879 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2880 ret = FALSE;
2882 break;
2884 case INTERNET_OPTION_CODEPAGE:
2886 ULONG codepage = *(ULONG *)lpBuffer;
2887 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2889 break;
2890 case INTERNET_OPTION_REQUEST_PRIORITY:
2892 ULONG priority = *(ULONG *)lpBuffer;
2893 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2895 break;
2896 case INTERNET_OPTION_CONNECT_TIMEOUT:
2898 ULONG connecttimeout = *(ULONG *)lpBuffer;
2899 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2901 break;
2902 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2904 ULONG receivetimeout = *(ULONG *)lpBuffer;
2905 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2907 break;
2908 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2909 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2910 break;
2911 case INTERNET_OPTION_END_BROWSER_SESSION:
2912 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2913 break;
2914 case INTERNET_OPTION_CONNECTED_STATE:
2915 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2916 break;
2917 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2918 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2919 break;
2920 case INTERNET_OPTION_SEND_TIMEOUT:
2921 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2922 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2924 ULONG timeout = *(ULONG *)lpBuffer;
2925 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2926 break;
2928 case INTERNET_OPTION_CONNECT_RETRIES:
2930 ULONG retries = *(ULONG *)lpBuffer;
2931 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2932 break;
2934 case INTERNET_OPTION_CONTEXT_VALUE:
2936 if (!lpwhh)
2938 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2939 return FALSE;
2941 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2943 SetLastError(ERROR_INVALID_PARAMETER);
2944 ret = FALSE;
2946 else
2947 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2948 break;
2950 case INTERNET_OPTION_SECURITY_FLAGS:
2951 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2952 break;
2953 case INTERNET_OPTION_DISABLE_AUTODIAL:
2954 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2955 break;
2956 case INTERNET_OPTION_HTTP_DECODING:
2957 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2958 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2959 ret = FALSE;
2960 break;
2961 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2962 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2963 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2964 ret = FALSE;
2965 break;
2966 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2967 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2968 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2969 ret = FALSE;
2970 break;
2971 case INTERNET_OPTION_CODEPAGE_PATH:
2972 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2973 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2974 ret = FALSE;
2975 break;
2976 case INTERNET_OPTION_CODEPAGE_EXTRA:
2977 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2978 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2979 ret = FALSE;
2980 break;
2981 case INTERNET_OPTION_IDN:
2982 FIXME("INTERNET_OPTION_IDN; STUB\n");
2983 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2984 ret = FALSE;
2985 break;
2986 case INTERNET_OPTION_POLICY:
2987 SetLastError(ERROR_INVALID_PARAMETER);
2988 ret = FALSE;
2989 break;
2990 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2991 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2992 LONG res;
2993 unsigned int i;
2994 proxyinfo_t pi;
2996 if (INTERNET_LoadProxySettings(&pi)) return FALSE;
2998 for (i = 0; i < con->dwOptionCount; i++) {
2999 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
3001 switch (option->dwOption) {
3002 case INTERNET_PER_CONN_PROXY_SERVER:
3003 heap_free(pi.proxy);
3004 pi.proxy = heap_strdupW(option->Value.pszValue);
3005 break;
3007 case INTERNET_PER_CONN_FLAGS:
3008 if(option->Value.dwValue & PROXY_TYPE_PROXY)
3009 pi.proxyEnabled = 1;
3010 else
3012 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
3013 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
3014 pi.proxyEnabled = 0;
3016 break;
3018 case INTERNET_PER_CONN_PROXY_BYPASS:
3019 heap_free(pi.proxyBypass);
3020 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
3021 break;
3023 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3024 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3025 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3026 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3027 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3028 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3029 FIXME("Unhandled dwOption %d\n", option->dwOption);
3030 break;
3032 default:
3033 FIXME("Unknown dwOption %d\n", option->dwOption);
3034 SetLastError(ERROR_INVALID_PARAMETER);
3035 break;
3039 if ((res = INTERNET_SaveProxySettings(&pi)))
3040 SetLastError(res);
3042 FreeProxyInfo(&pi);
3044 ret = (res == ERROR_SUCCESS);
3045 break;
3047 default:
3048 FIXME("Option %d STUB\n",dwOption);
3049 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3050 ret = FALSE;
3051 break;
3054 if(lpwhh)
3055 WININET_Release( lpwhh );
3057 return ret;
3061 /***********************************************************************
3062 * InternetSetOptionA (WININET.@)
3064 * Sets an options on the specified handle.
3066 * RETURNS
3067 * TRUE on success
3068 * FALSE on failure
3071 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
3072 LPVOID lpBuffer, DWORD dwBufferLength)
3074 LPVOID wbuffer;
3075 DWORD wlen;
3076 BOOL r;
3078 switch( dwOption )
3080 case INTERNET_OPTION_PROXY:
3082 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
3083 LPINTERNET_PROXY_INFOW piw;
3084 DWORD proxlen, prbylen;
3085 LPWSTR prox, prby;
3087 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
3088 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
3089 wlen = sizeof(*piw) + proxlen + prbylen;
3090 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
3091 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
3092 piw->dwAccessType = pi->dwAccessType;
3093 prox = (LPWSTR) &piw[1];
3094 prby = &prox[proxlen+1];
3095 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
3096 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
3097 piw->lpszProxy = prox;
3098 piw->lpszProxyBypass = prby;
3100 break;
3101 case INTERNET_OPTION_USER_AGENT:
3102 case INTERNET_OPTION_USERNAME:
3103 case INTERNET_OPTION_PASSWORD:
3104 case INTERNET_OPTION_PROXY_USERNAME:
3105 case INTERNET_OPTION_PROXY_PASSWORD:
3106 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3107 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3108 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3109 break;
3110 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3111 unsigned int i;
3112 INTERNET_PER_CONN_OPTION_LISTW *listW;
3113 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3114 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3115 wbuffer = heap_alloc(wlen);
3116 listW = wbuffer;
3118 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3119 if (listA->pszConnection)
3121 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3122 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3123 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3125 else
3126 listW->pszConnection = NULL;
3127 listW->dwOptionCount = listA->dwOptionCount;
3128 listW->dwOptionError = listA->dwOptionError;
3129 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3131 for (i = 0; i < listA->dwOptionCount; ++i) {
3132 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3133 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3135 optW->dwOption = optA->dwOption;
3137 switch (optA->dwOption) {
3138 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3139 case INTERNET_PER_CONN_PROXY_BYPASS:
3140 case INTERNET_PER_CONN_PROXY_SERVER:
3141 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3142 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3143 if (optA->Value.pszValue)
3145 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3146 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3147 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3149 else
3150 optW->Value.pszValue = NULL;
3151 break;
3152 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3153 case INTERNET_PER_CONN_FLAGS:
3154 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3155 optW->Value.dwValue = optA->Value.dwValue;
3156 break;
3157 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3158 optW->Value.ftValue = optA->Value.ftValue;
3159 break;
3160 default:
3161 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3162 optW->Value.dwValue = optA->Value.dwValue;
3163 break;
3167 break;
3168 default:
3169 wbuffer = lpBuffer;
3170 wlen = dwBufferLength;
3173 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3175 if( lpBuffer != wbuffer )
3177 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3179 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3180 unsigned int i;
3181 for (i = 0; i < list->dwOptionCount; ++i) {
3182 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3183 switch (opt->dwOption) {
3184 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3185 case INTERNET_PER_CONN_PROXY_BYPASS:
3186 case INTERNET_PER_CONN_PROXY_SERVER:
3187 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3188 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3189 heap_free( opt->Value.pszValue );
3190 break;
3191 default:
3192 break;
3195 heap_free( list->pOptions );
3197 heap_free( wbuffer );
3200 return r;
3204 /***********************************************************************
3205 * InternetSetOptionExA (WININET.@)
3207 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3208 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3210 FIXME("Flags %08x ignored\n", dwFlags);
3211 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3214 /***********************************************************************
3215 * InternetSetOptionExW (WININET.@)
3217 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3218 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3220 FIXME("Flags %08x ignored\n", dwFlags);
3221 if( dwFlags & ~ISO_VALID_FLAGS )
3223 SetLastError( ERROR_INVALID_PARAMETER );
3224 return FALSE;
3226 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3229 static const WCHAR WININET_wkday[7][4] =
3230 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3231 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3232 static const WCHAR WININET_month[12][4] =
3233 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3234 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3235 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3237 /***********************************************************************
3238 * InternetTimeFromSystemTimeA (WININET.@)
3240 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3242 BOOL ret;
3243 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3245 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3247 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3249 SetLastError(ERROR_INVALID_PARAMETER);
3250 return FALSE;
3253 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3255 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3256 return FALSE;
3259 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3260 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3262 return ret;
3265 /***********************************************************************
3266 * InternetTimeFromSystemTimeW (WININET.@)
3268 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3270 static const WCHAR date[] =
3271 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3272 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3274 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3276 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3278 SetLastError(ERROR_INVALID_PARAMETER);
3279 return FALSE;
3282 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3284 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3285 return FALSE;
3288 sprintfW( string, date,
3289 WININET_wkday[time->wDayOfWeek],
3290 time->wDay,
3291 WININET_month[time->wMonth - 1],
3292 time->wYear,
3293 time->wHour,
3294 time->wMinute,
3295 time->wSecond );
3297 return TRUE;
3300 /***********************************************************************
3301 * InternetTimeToSystemTimeA (WININET.@)
3303 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3305 BOOL ret = FALSE;
3306 WCHAR *stringW;
3308 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3310 stringW = heap_strdupAtoW(string);
3311 if (stringW)
3313 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3314 heap_free( stringW );
3316 return ret;
3319 /***********************************************************************
3320 * InternetTimeToSystemTimeW (WININET.@)
3322 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3324 unsigned int i;
3325 const WCHAR *s = string;
3326 WCHAR *end;
3328 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3330 if (!string || !time) return FALSE;
3332 /* Windows does this too */
3333 GetSystemTime( time );
3335 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3336 * a SYSTEMTIME structure.
3339 while (*s && !isalphaW( *s )) s++;
3340 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3341 time->wDayOfWeek = 7;
3343 for (i = 0; i < 7; i++)
3345 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3346 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3347 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3349 time->wDayOfWeek = i;
3350 break;
3354 if (time->wDayOfWeek > 6) return TRUE;
3355 while (*s && !isdigitW( *s )) s++;
3356 time->wDay = strtolW( s, &end, 10 );
3357 s = end;
3359 while (*s && !isalphaW( *s )) s++;
3360 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3361 time->wMonth = 0;
3363 for (i = 0; i < 12; i++)
3365 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3366 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3367 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3369 time->wMonth = i + 1;
3370 break;
3373 if (time->wMonth == 0) return TRUE;
3375 while (*s && !isdigitW( *s )) s++;
3376 if (*s == '\0') return TRUE;
3377 time->wYear = strtolW( s, &end, 10 );
3378 s = end;
3380 while (*s && !isdigitW( *s )) s++;
3381 if (*s == '\0') return TRUE;
3382 time->wHour = strtolW( s, &end, 10 );
3383 s = end;
3385 while (*s && !isdigitW( *s )) s++;
3386 if (*s == '\0') return TRUE;
3387 time->wMinute = strtolW( s, &end, 10 );
3388 s = end;
3390 while (*s && !isdigitW( *s )) s++;
3391 if (*s == '\0') return TRUE;
3392 time->wSecond = strtolW( s, &end, 10 );
3393 s = end;
3395 time->wMilliseconds = 0;
3396 return TRUE;
3399 /***********************************************************************
3400 * InternetCheckConnectionW (WININET.@)
3402 * Pings a requested host to check internet connection
3404 * RETURNS
3405 * TRUE on success and FALSE on failure. If a failure then
3406 * ERROR_NOT_CONNECTED is placed into GetLastError
3409 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3412 * this is a kludge which runs the resident ping program and reads the output.
3414 * Anyone have a better idea?
3417 BOOL rc = FALSE;
3418 static const CHAR ping[] = "ping -c 1 ";
3419 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3420 CHAR *command = NULL;
3421 WCHAR hostW[INTERNET_MAX_HOST_NAME_LENGTH];
3422 DWORD len;
3423 INTERNET_PORT port;
3424 int status = -1;
3426 FIXME("\n");
3429 * Crack or set the Address
3431 if (lpszUrl == NULL)
3434 * According to the doc we are supposed to use the ip for the next
3435 * server in the WnInet internal server database. I have
3436 * no idea what that is or how to get it.
3438 * So someone needs to implement this.
3440 FIXME("Unimplemented with URL of NULL\n");
3441 return TRUE;
3443 else
3445 URL_COMPONENTSW components;
3447 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3448 components.lpszHostName = (LPWSTR)hostW;
3449 components.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3451 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3452 goto End;
3454 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3455 port = components.nPort;
3456 TRACE("port: %d\n", port);
3459 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3461 struct sockaddr_storage saddr;
3462 socklen_t sa_len = sizeof(saddr);
3463 int fd;
3465 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len, NULL))
3466 goto End;
3467 init_winsock();
3468 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3469 if (fd != -1)
3471 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3472 rc = TRUE;
3473 closesocket(fd);
3476 else
3479 * Build our ping command
3481 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3482 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3483 strcpy(command,ping);
3484 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3485 strcat(command,redirect);
3487 TRACE("Ping command is : %s\n",command);
3489 status = system(command);
3491 TRACE("Ping returned a code of %i\n",status);
3493 /* Ping return code of 0 indicates success */
3494 if (status == 0)
3495 rc = TRUE;
3498 End:
3499 heap_free( command );
3500 if (rc == FALSE)
3501 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3503 return rc;
3507 /***********************************************************************
3508 * InternetCheckConnectionA (WININET.@)
3510 * Pings a requested host to check internet connection
3512 * RETURNS
3513 * TRUE on success and FALSE on failure. If a failure then
3514 * ERROR_NOT_CONNECTED is placed into GetLastError
3517 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3519 WCHAR *url = NULL;
3520 BOOL rc;
3522 if(lpszUrl) {
3523 url = heap_strdupAtoW(lpszUrl);
3524 if(!url)
3525 return FALSE;
3528 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3530 heap_free(url);
3531 return rc;
3535 /**********************************************************
3536 * INTERNET_InternetOpenUrlW (internal)
3538 * Opens an URL
3540 * RETURNS
3541 * handle of connection or NULL on failure
3543 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3544 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3546 URL_COMPONENTSW urlComponents;
3547 WCHAR protocol[INTERNET_MAX_SCHEME_LENGTH];
3548 WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH];
3549 WCHAR userName[INTERNET_MAX_USER_NAME_LENGTH];
3550 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
3551 WCHAR path[INTERNET_MAX_PATH_LENGTH];
3552 WCHAR extra[1024];
3553 HINTERNET client = NULL, client1 = NULL;
3554 DWORD res;
3556 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3557 dwHeadersLength, dwFlags, dwContext);
3559 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3560 urlComponents.lpszScheme = protocol;
3561 urlComponents.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH;
3562 urlComponents.lpszHostName = hostName;
3563 urlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3564 urlComponents.lpszUserName = userName;
3565 urlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
3566 urlComponents.lpszPassword = password;
3567 urlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
3568 urlComponents.lpszUrlPath = path;
3569 urlComponents.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
3570 urlComponents.lpszExtraInfo = extra;
3571 urlComponents.dwExtraInfoLength = 1024;
3572 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3573 return NULL;
3574 switch(urlComponents.nScheme) {
3575 case INTERNET_SCHEME_FTP:
3576 if(urlComponents.nPort == 0)
3577 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3578 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3579 userName, password, dwFlags, dwContext, INET_OPENURL);
3580 if(client == NULL)
3581 break;
3582 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3583 if(client1 == NULL) {
3584 InternetCloseHandle(client);
3585 break;
3587 break;
3589 case INTERNET_SCHEME_HTTP:
3590 case INTERNET_SCHEME_HTTPS: {
3591 static const WCHAR szStars[] = { '*','/','*', 0 };
3592 LPCWSTR accept[2] = { szStars, NULL };
3593 if(urlComponents.nPort == 0) {
3594 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3595 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3596 else
3597 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3599 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3601 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3602 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3603 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3604 if(res != ERROR_SUCCESS) {
3605 INTERNET_SetLastError(res);
3606 break;
3609 if (urlComponents.dwExtraInfoLength) {
3610 WCHAR *path_extra;
3611 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3613 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3615 InternetCloseHandle(client);
3616 break;
3618 strcpyW(path_extra, urlComponents.lpszUrlPath);
3619 strcatW(path_extra, urlComponents.lpszExtraInfo);
3620 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3621 heap_free(path_extra);
3623 else
3624 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3626 if(client1 == NULL) {
3627 InternetCloseHandle(client);
3628 break;
3630 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3631 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3632 GetLastError() != ERROR_IO_PENDING) {
3633 InternetCloseHandle(client1);
3634 client1 = NULL;
3635 break;
3638 case INTERNET_SCHEME_GOPHER:
3639 /* gopher doesn't seem to be implemented in wine, but it's supposed
3640 * to be supported by InternetOpenUrlA. */
3641 default:
3642 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3643 break;
3646 TRACE(" %p <--\n", client1);
3648 return client1;
3651 /**********************************************************
3652 * InternetOpenUrlW (WININET.@)
3654 * Opens an URL
3656 * RETURNS
3657 * handle of connection or NULL on failure
3659 typedef struct {
3660 task_header_t hdr;
3661 WCHAR *url;
3662 WCHAR *headers;
3663 DWORD headers_len;
3664 DWORD flags;
3665 DWORD_PTR context;
3666 } open_url_task_t;
3668 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3670 open_url_task_t *task = (open_url_task_t*)hdr;
3672 TRACE("%p\n", task->hdr.hdr);
3674 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3675 task->headers_len, task->flags, task->context);
3676 heap_free(task->url);
3677 heap_free(task->headers);
3680 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3681 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3683 HINTERNET ret = NULL;
3684 appinfo_t *hIC = NULL;
3686 if (TRACE_ON(wininet)) {
3687 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3688 dwHeadersLength, dwFlags, dwContext);
3689 TRACE(" flags :");
3690 dump_INTERNET_FLAGS(dwFlags);
3693 if (!lpszUrl)
3695 SetLastError(ERROR_INVALID_PARAMETER);
3696 goto lend;
3699 hIC = (appinfo_t*)get_handle_object( hInternet );
3700 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3701 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3702 goto lend;
3705 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3706 open_url_task_t *task;
3708 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3709 task->url = heap_strdupW(lpszUrl);
3710 task->headers = heap_strdupW(lpszHeaders);
3711 task->headers_len = dwHeadersLength;
3712 task->flags = dwFlags;
3713 task->context = dwContext;
3715 INTERNET_AsyncCall(&task->hdr);
3716 SetLastError(ERROR_IO_PENDING);
3717 } else {
3718 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3721 lend:
3722 if( hIC )
3723 WININET_Release( &hIC->hdr );
3724 TRACE(" %p <--\n", ret);
3726 return ret;
3729 /**********************************************************
3730 * InternetOpenUrlA (WININET.@)
3732 * Opens an URL
3734 * RETURNS
3735 * handle of connection or NULL on failure
3737 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3738 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3740 HINTERNET rc = NULL;
3741 DWORD lenHeaders = 0;
3742 LPWSTR szUrl = NULL;
3743 LPWSTR szHeaders = NULL;
3745 TRACE("\n");
3747 if(lpszUrl) {
3748 szUrl = heap_strdupAtoW(lpszUrl);
3749 if(!szUrl)
3750 return NULL;
3753 if(lpszHeaders) {
3754 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3755 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3756 if(!szHeaders) {
3757 heap_free(szUrl);
3758 return NULL;
3760 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3763 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3764 lenHeaders, dwFlags, dwContext);
3766 heap_free(szUrl);
3767 heap_free(szHeaders);
3768 return rc;
3772 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3774 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3776 if (lpwite)
3778 lpwite->dwError = 0;
3779 lpwite->response[0] = '\0';
3782 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3784 heap_free(lpwite);
3785 return NULL;
3787 return lpwite;
3791 /***********************************************************************
3792 * INTERNET_SetLastError (internal)
3794 * Set last thread specific error
3796 * RETURNS
3799 void INTERNET_SetLastError(DWORD dwError)
3801 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3803 if (!lpwite)
3804 lpwite = INTERNET_AllocThreadError();
3806 SetLastError(dwError);
3807 if(lpwite)
3808 lpwite->dwError = dwError;
3812 /***********************************************************************
3813 * INTERNET_GetLastError (internal)
3815 * Get last thread specific error
3817 * RETURNS
3820 DWORD INTERNET_GetLastError(void)
3822 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3823 if (!lpwite) return 0;
3824 /* TlsGetValue clears last error, so set it again here */
3825 SetLastError(lpwite->dwError);
3826 return lpwite->dwError;
3830 /***********************************************************************
3831 * INTERNET_WorkerThreadFunc (internal)
3833 * Worker thread execution function
3835 * RETURNS
3838 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3840 task_header_t *task = lpvParam;
3842 TRACE("\n");
3844 task->proc(task);
3845 WININET_Release(task->hdr);
3846 heap_free(task);
3848 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3850 heap_free(TlsGetValue(g_dwTlsErrIndex));
3851 TlsSetValue(g_dwTlsErrIndex, NULL);
3853 return TRUE;
3856 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3858 task_header_t *task;
3860 task = heap_alloc(size);
3861 if(!task)
3862 return NULL;
3864 task->hdr = WININET_AddRef(hdr);
3865 task->proc = proc;
3866 return task;
3869 /***********************************************************************
3870 * INTERNET_AsyncCall (internal)
3872 * Retrieves work request from queue
3874 * RETURNS
3877 DWORD INTERNET_AsyncCall(task_header_t *task)
3879 BOOL bSuccess;
3881 TRACE("\n");
3883 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3884 if (!bSuccess)
3886 heap_free(task);
3887 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3889 return ERROR_SUCCESS;
3893 /***********************************************************************
3894 * INTERNET_GetResponseBuffer (internal)
3896 * RETURNS
3899 LPSTR INTERNET_GetResponseBuffer(void)
3901 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3902 if (!lpwite)
3903 lpwite = INTERNET_AllocThreadError();
3904 TRACE("\n");
3905 return lpwite->response;
3908 /**********************************************************
3909 * InternetQueryDataAvailable (WININET.@)
3911 * Determines how much data is available to be read.
3913 * RETURNS
3914 * TRUE on success, FALSE if an error occurred. If
3915 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3916 * no data is presently available, FALSE is returned with
3917 * the last error ERROR_IO_PENDING; a callback with status
3918 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3919 * data is available.
3921 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3922 LPDWORD lpdwNumberOfBytesAvailable,
3923 DWORD dwFlags, DWORD_PTR dwContext)
3925 object_header_t *hdr;
3926 DWORD res;
3928 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3930 hdr = get_handle_object( hFile );
3931 if (!hdr) {
3932 SetLastError(ERROR_INVALID_HANDLE);
3933 return FALSE;
3936 if(hdr->vtbl->QueryDataAvailable) {
3937 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3938 }else {
3939 WARN("wrong handle\n");
3940 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3943 WININET_Release(hdr);
3945 if(res != ERROR_SUCCESS)
3946 SetLastError(res);
3947 return res == ERROR_SUCCESS;
3950 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
3952 req_file_t *req_file;
3954 req_file = heap_alloc_zero(sizeof(*req_file));
3955 if(!req_file)
3956 return ERROR_NOT_ENOUGH_MEMORY;
3958 req_file->ref = 1;
3960 req_file->file_name = heap_strdupW(file_name);
3961 if(!req_file->file_name) {
3962 heap_free(req_file);
3963 return ERROR_NOT_ENOUGH_MEMORY;
3966 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
3967 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3968 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
3969 req_file_release(req_file);
3970 return GetLastError();
3973 *ret = req_file;
3974 return ERROR_SUCCESS;
3977 void req_file_release(req_file_t *req_file)
3979 if(InterlockedDecrement(&req_file->ref))
3980 return;
3982 if(!req_file->is_committed)
3983 DeleteFileW(req_file->file_name);
3984 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
3985 CloseHandle(req_file->file_handle);
3986 heap_free(req_file->file_name);
3987 heap_free(req_file);
3990 /***********************************************************************
3991 * InternetLockRequestFile (WININET.@)
3993 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
3995 req_file_t *req_file = NULL;
3996 object_header_t *hdr;
3997 DWORD res;
3999 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
4001 hdr = get_handle_object(hInternet);
4002 if (!hdr) {
4003 SetLastError(ERROR_INVALID_HANDLE);
4004 return FALSE;
4007 if(hdr->vtbl->LockRequestFile) {
4008 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
4009 }else {
4010 WARN("wrong handle\n");
4011 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4014 WININET_Release(hdr);
4016 *lphLockReqHandle = req_file;
4017 if(res != ERROR_SUCCESS)
4018 SetLastError(res);
4019 return res == ERROR_SUCCESS;
4022 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
4024 TRACE("(%p)\n", hLockHandle);
4026 req_file_release(hLockHandle);
4027 return TRUE;
4031 /***********************************************************************
4032 * InternetAutodial (WININET.@)
4034 * On windows this function is supposed to dial the default internet
4035 * connection. We don't want to have Wine dial out to the internet so
4036 * we return TRUE by default. It might be nice to check if we are connected.
4038 * RETURNS
4039 * TRUE on success
4040 * FALSE on failure
4043 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4045 FIXME("STUB\n");
4047 /* Tell that we are connected to the internet. */
4048 return TRUE;
4051 /***********************************************************************
4052 * InternetAutodialHangup (WININET.@)
4054 * Hangs up a connection made with InternetAutodial
4056 * PARAM
4057 * dwReserved
4058 * RETURNS
4059 * TRUE on success
4060 * FALSE on failure
4063 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4065 FIXME("STUB\n");
4067 /* we didn't dial, we don't disconnect */
4068 return TRUE;
4071 /***********************************************************************
4072 * InternetCombineUrlA (WININET.@)
4074 * Combine a base URL with a relative URL
4076 * RETURNS
4077 * TRUE on success
4078 * FALSE on failure
4082 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4083 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4084 DWORD dwFlags)
4086 HRESULT hr=S_OK;
4088 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4090 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4091 dwFlags ^= ICU_NO_ENCODE;
4092 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4094 return (hr==S_OK);
4097 /***********************************************************************
4098 * InternetCombineUrlW (WININET.@)
4100 * Combine a base URL with a relative URL
4102 * RETURNS
4103 * TRUE on success
4104 * FALSE on failure
4108 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4109 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4110 DWORD dwFlags)
4112 HRESULT hr=S_OK;
4114 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4116 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4117 dwFlags ^= ICU_NO_ENCODE;
4118 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4120 return (hr==S_OK);
4123 /* max port num is 65535 => 5 digits */
4124 #define MAX_WORD_DIGITS 5
4126 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4127 (url)->dw##component##Length : strlenW((url)->lpsz##component))
4128 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4129 (url)->dw##component##Length : strlen((url)->lpsz##component))
4131 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4133 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4134 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4135 return TRUE;
4136 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4137 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4138 return TRUE;
4139 if ((nScheme == INTERNET_SCHEME_FTP) &&
4140 (nPort == INTERNET_DEFAULT_FTP_PORT))
4141 return TRUE;
4142 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4143 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4144 return TRUE;
4146 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4147 return TRUE;
4149 return FALSE;
4152 /* opaque urls do not fit into the standard url hierarchy and don't have
4153 * two following slashes */
4154 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4156 return (nScheme != INTERNET_SCHEME_FTP) &&
4157 (nScheme != INTERNET_SCHEME_GOPHER) &&
4158 (nScheme != INTERNET_SCHEME_HTTP) &&
4159 (nScheme != INTERNET_SCHEME_HTTPS) &&
4160 (nScheme != INTERNET_SCHEME_FILE);
4163 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4165 int index;
4166 if (scheme < INTERNET_SCHEME_FIRST)
4167 return NULL;
4168 index = scheme - INTERNET_SCHEME_FIRST;
4169 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
4170 return NULL;
4171 return (LPCWSTR)url_schemes[index];
4174 /* we can calculate using ansi strings because we're just
4175 * calculating string length, not size
4177 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4178 LPDWORD lpdwUrlLength)
4180 INTERNET_SCHEME nScheme;
4182 *lpdwUrlLength = 0;
4184 if (lpUrlComponents->lpszScheme)
4186 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4187 *lpdwUrlLength += dwLen;
4188 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4190 else
4192 LPCWSTR scheme;
4194 nScheme = lpUrlComponents->nScheme;
4196 if (nScheme == INTERNET_SCHEME_DEFAULT)
4197 nScheme = INTERNET_SCHEME_HTTP;
4198 scheme = INTERNET_GetSchemeString(nScheme);
4199 *lpdwUrlLength += strlenW(scheme);
4202 (*lpdwUrlLength)++; /* ':' */
4203 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4204 *lpdwUrlLength += strlen("//");
4206 if (lpUrlComponents->lpszUserName)
4208 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4209 *lpdwUrlLength += strlen("@");
4211 else
4213 if (lpUrlComponents->lpszPassword)
4215 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4216 return FALSE;
4220 if (lpUrlComponents->lpszPassword)
4222 *lpdwUrlLength += strlen(":");
4223 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4226 if (lpUrlComponents->lpszHostName)
4228 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4230 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4232 char szPort[MAX_WORD_DIGITS+1];
4234 sprintf(szPort, "%d", lpUrlComponents->nPort);
4235 *lpdwUrlLength += strlen(szPort);
4236 *lpdwUrlLength += strlen(":");
4239 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4240 (*lpdwUrlLength)++; /* '/' */
4243 if (lpUrlComponents->lpszUrlPath)
4244 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4246 if (lpUrlComponents->lpszExtraInfo)
4247 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4249 return TRUE;
4252 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4254 INT len;
4256 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4258 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4259 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4260 urlCompW->nScheme = lpUrlComponents->nScheme;
4261 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4262 urlCompW->nPort = lpUrlComponents->nPort;
4263 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4264 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4265 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4266 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4268 if (lpUrlComponents->lpszScheme)
4270 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4271 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4272 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4273 -1, urlCompW->lpszScheme, len);
4276 if (lpUrlComponents->lpszHostName)
4278 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4279 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4280 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4281 -1, urlCompW->lpszHostName, len);
4284 if (lpUrlComponents->lpszUserName)
4286 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4287 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4288 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4289 -1, urlCompW->lpszUserName, len);
4292 if (lpUrlComponents->lpszPassword)
4294 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4295 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4296 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4297 -1, urlCompW->lpszPassword, len);
4300 if (lpUrlComponents->lpszUrlPath)
4302 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4303 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4304 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4305 -1, urlCompW->lpszUrlPath, len);
4308 if (lpUrlComponents->lpszExtraInfo)
4310 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4311 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4312 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4313 -1, urlCompW->lpszExtraInfo, len);
4317 /***********************************************************************
4318 * InternetCreateUrlA (WININET.@)
4320 * See InternetCreateUrlW.
4322 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4323 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4325 BOOL ret;
4326 LPWSTR urlW = NULL;
4327 URL_COMPONENTSW urlCompW;
4329 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4331 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4333 SetLastError(ERROR_INVALID_PARAMETER);
4334 return FALSE;
4337 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4339 if (lpszUrl)
4340 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4342 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4344 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4345 *lpdwUrlLength /= sizeof(WCHAR);
4347 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4348 * minus one, so add one to leave room for NULL terminator
4350 if (ret)
4351 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4353 heap_free(urlCompW.lpszScheme);
4354 heap_free(urlCompW.lpszHostName);
4355 heap_free(urlCompW.lpszUserName);
4356 heap_free(urlCompW.lpszPassword);
4357 heap_free(urlCompW.lpszUrlPath);
4358 heap_free(urlCompW.lpszExtraInfo);
4359 heap_free(urlW);
4360 return ret;
4363 /***********************************************************************
4364 * InternetCreateUrlW (WININET.@)
4366 * Creates a URL from its component parts.
4368 * PARAMS
4369 * lpUrlComponents [I] URL Components.
4370 * dwFlags [I] Flags. See notes.
4371 * lpszUrl [I] Buffer in which to store the created URL.
4372 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4373 * lpszUrl in characters. On output, the number of bytes
4374 * required to store the URL including terminator.
4376 * NOTES
4378 * The dwFlags parameter can be zero or more of the following:
4379 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4381 * RETURNS
4382 * TRUE on success
4383 * FALSE on failure
4386 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4387 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4389 DWORD dwLen;
4390 INTERNET_SCHEME nScheme;
4392 static const WCHAR slashSlashW[] = {'/','/'};
4393 static const WCHAR fmtW[] = {'%','u',0};
4395 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4397 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4399 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4400 return FALSE;
4403 if (!calc_url_length(lpUrlComponents, &dwLen))
4404 return FALSE;
4406 if (!lpszUrl || *lpdwUrlLength < dwLen)
4408 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4409 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4410 return FALSE;
4413 *lpdwUrlLength = dwLen;
4414 lpszUrl[0] = 0x00;
4416 dwLen = 0;
4418 if (lpUrlComponents->lpszScheme)
4420 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4421 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4422 lpszUrl += dwLen;
4424 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4426 else
4428 LPCWSTR scheme;
4429 nScheme = lpUrlComponents->nScheme;
4431 if (nScheme == INTERNET_SCHEME_DEFAULT)
4432 nScheme = INTERNET_SCHEME_HTTP;
4434 scheme = INTERNET_GetSchemeString(nScheme);
4435 dwLen = strlenW(scheme);
4436 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4437 lpszUrl += dwLen;
4440 /* all schemes are followed by at least a colon */
4441 *lpszUrl = ':';
4442 lpszUrl++;
4444 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4446 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4447 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4450 if (lpUrlComponents->lpszUserName)
4452 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4453 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4454 lpszUrl += dwLen;
4456 if (lpUrlComponents->lpszPassword)
4458 *lpszUrl = ':';
4459 lpszUrl++;
4461 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4462 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4463 lpszUrl += dwLen;
4466 *lpszUrl = '@';
4467 lpszUrl++;
4470 if (lpUrlComponents->lpszHostName)
4472 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4473 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4474 lpszUrl += dwLen;
4476 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4478 WCHAR szPort[MAX_WORD_DIGITS+1];
4480 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4481 *lpszUrl = ':';
4482 lpszUrl++;
4483 dwLen = strlenW(szPort);
4484 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4485 lpszUrl += dwLen;
4488 /* add slash between hostname and path if necessary */
4489 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4491 *lpszUrl = '/';
4492 lpszUrl++;
4496 if (lpUrlComponents->lpszUrlPath)
4498 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4499 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4500 lpszUrl += dwLen;
4503 if (lpUrlComponents->lpszExtraInfo)
4505 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4506 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4507 lpszUrl += dwLen;
4510 *lpszUrl = '\0';
4512 return TRUE;
4515 /***********************************************************************
4516 * InternetConfirmZoneCrossingA (WININET.@)
4519 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4521 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4522 return ERROR_SUCCESS;
4525 /***********************************************************************
4526 * InternetConfirmZoneCrossingW (WININET.@)
4529 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4531 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4532 return ERROR_SUCCESS;
4535 static DWORD zone_preference = 3;
4537 /***********************************************************************
4538 * PrivacySetZonePreferenceW (WININET.@)
4540 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4542 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4544 zone_preference = template;
4545 return 0;
4548 /***********************************************************************
4549 * PrivacyGetZonePreferenceW (WININET.@)
4551 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4552 LPWSTR preference, LPDWORD length )
4554 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4556 if (template) *template = zone_preference;
4557 return 0;
4560 /***********************************************************************
4561 * InternetGetSecurityInfoByURLA (WININET.@)
4563 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4565 WCHAR *url;
4566 BOOL res;
4568 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4570 url = heap_strdupAtoW(lpszURL);
4571 if(!url)
4572 return FALSE;
4574 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4575 heap_free(url);
4576 return res;
4579 /***********************************************************************
4580 * InternetGetSecurityInfoByURLW (WININET.@)
4582 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4584 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
4585 URL_COMPONENTSW url = {sizeof(url)};
4586 server_t *server;
4587 BOOL res = FALSE;
4589 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4591 url.lpszHostName = hostname;
4592 url.dwHostNameLength = sizeof(hostname)/sizeof(WCHAR);
4594 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4595 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4596 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4597 return FALSE;
4600 server = get_server(hostname, url.nPort, TRUE, FALSE);
4601 if(!server) {
4602 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4603 return FALSE;
4606 if(server->cert_chain) {
4607 const CERT_CHAIN_CONTEXT *chain_dup;
4609 chain_dup = CertDuplicateCertificateChain(server->cert_chain);
4610 if(chain_dup) {
4611 *ppCertChain = chain_dup;
4612 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4613 }else {
4614 res = FALSE;
4616 }else {
4617 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4618 res = FALSE;
4621 server_release(server);
4622 return res;
4625 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4626 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4628 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4629 lpdwConnection, dwReserved);
4630 return ERROR_SUCCESS;
4633 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4634 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4636 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4637 lpdwConnection, dwReserved);
4638 return ERROR_SUCCESS;
4641 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4643 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4644 return TRUE;
4647 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4649 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4650 return TRUE;
4653 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4655 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4656 return ERROR_SUCCESS;
4659 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4660 PBYTE pbHexHash )
4662 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4663 debugstr_w(pwszTarget), pbHexHash);
4664 return FALSE;
4667 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4669 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4670 return FALSE;
4673 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4675 FIXME("(%p, %08lx) stub\n", a, b);
4676 return FALSE;
4679 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4681 FIXME("%p: stub\n", parent);
4682 return 0;