wined3d: Respect the BO memory offset in wined3d_context_gl_map_bo_address().
[wine.git] / dlls / wininet / internet.c
blobb0fe8a5e3fb82dc06ce0f323ca4cf35eff4d4ae3
1 /*
2 * Wininet
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
10 * Ulrich Czekalla
11 * Aric Stewart
12 * David Hammerton
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "winsock2.h"
30 #include "ws2ipdef.h"
32 #include <string.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37 #include <assert.h>
38 #include <wchar.h>
40 #include "windef.h"
41 #include "winbase.h"
42 #include "winreg.h"
43 #include "winuser.h"
44 #include "wininet.h"
45 #include "winnls.h"
46 #include "wine/debug.h"
47 #include "winerror.h"
48 #define NO_SHLWAPI_STREAM
49 #include "shlwapi.h"
50 #include "ws2tcpip.h"
51 #include "winternl.h"
52 #include "iphlpapi.h"
53 #include "dhcpcsdk.h"
55 #include "internet.h"
56 #include "resource.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
60 typedef struct
62 DWORD dwError;
63 CHAR response[MAX_REPLY_LEN];
64 } WITHREADERROR, *LPWITHREADERROR;
66 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
67 HMODULE WININET_hModule;
69 static CRITICAL_SECTION WININET_cs;
70 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
72 0, 0, &WININET_cs,
73 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
74 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
76 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
78 static object_header_t **handle_table;
79 static UINT_PTR next_handle;
80 static UINT_PTR handle_table_size;
82 typedef struct
84 DWORD proxyEnabled;
85 LPWSTR proxy;
86 LPWSTR proxyBypass;
87 LPWSTR proxyUsername;
88 LPWSTR proxyPassword;
89 } proxyinfo_t;
91 static ULONG max_conns = 2, max_1_0_conns = 4;
92 static ULONG connect_timeout = 60000;
94 static const WCHAR szInternetSettings[] =
95 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
97 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
99 UINT_PTR handle = 0, num;
100 object_header_t *ret;
101 object_header_t **p;
102 BOOL res = TRUE;
104 ret = heap_alloc_zero(size);
105 if(!ret)
106 return NULL;
108 list_init(&ret->children);
110 EnterCriticalSection( &WININET_cs );
112 if(!handle_table_size) {
113 num = 16;
114 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
115 if(p) {
116 handle_table = p;
117 handle_table_size = num;
118 next_handle = 1;
119 }else {
120 res = FALSE;
122 }else if(next_handle == handle_table_size) {
123 num = handle_table_size * 2;
124 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
125 if(p) {
126 handle_table = p;
127 handle_table_size = num;
128 }else {
129 res = FALSE;
133 if(res) {
134 handle = next_handle;
135 if(handle_table[handle])
136 ERR("handle isn't free but should be\n");
137 handle_table[handle] = ret;
138 ret->valid_handle = TRUE;
140 while(next_handle < handle_table_size && handle_table[next_handle])
141 next_handle++;
144 LeaveCriticalSection( &WININET_cs );
146 if(!res) {
147 heap_free(ret);
148 return NULL;
151 ret->vtbl = vtbl;
152 ret->refs = 1;
153 ret->hInternet = (HINTERNET)handle;
155 if(parent) {
156 ret->lpfnStatusCB = parent->lpfnStatusCB;
157 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
160 return ret;
163 object_header_t *WININET_AddRef( object_header_t *info )
165 ULONG refs = InterlockedIncrement(&info->refs);
166 TRACE("%p -> refcount = %d\n", info, refs );
167 return info;
170 object_header_t *get_handle_object( HINTERNET hinternet )
172 object_header_t *info = NULL;
173 UINT_PTR handle = (UINT_PTR) hinternet;
175 EnterCriticalSection( &WININET_cs );
177 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
178 info = WININET_AddRef(handle_table[handle]);
180 LeaveCriticalSection( &WININET_cs );
182 TRACE("handle %ld -> %p\n", handle, info);
184 return info;
187 static void invalidate_handle(object_header_t *info)
189 object_header_t *child, *next;
191 if(!info->valid_handle)
192 return;
193 info->valid_handle = FALSE;
195 /* Free all children as native does */
196 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
198 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
199 invalidate_handle( child );
202 WININET_Release(info);
205 BOOL WININET_Release( object_header_t *info )
207 ULONG refs = InterlockedDecrement(&info->refs);
208 TRACE( "object %p refcount = %d\n", info, refs );
209 if( !refs )
211 invalidate_handle(info);
212 if ( info->vtbl->CloseConnection )
214 TRACE( "closing connection %p\n", info);
215 info->vtbl->CloseConnection( info );
217 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
218 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
219 || !(info->dwInternalFlags & INET_OPENURL))
221 INTERNET_SendCallback(info, info->dwContext,
222 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
223 sizeof(HINTERNET));
225 TRACE( "destroying object %p\n", info);
226 if ( info->htype != WH_HINIT )
227 list_remove( &info->entry );
228 info->vtbl->Destroy( info );
230 if(info->hInternet) {
231 UINT_PTR handle = (UINT_PTR)info->hInternet;
233 EnterCriticalSection( &WININET_cs );
235 handle_table[handle] = NULL;
236 if(next_handle > handle)
237 next_handle = handle;
239 LeaveCriticalSection( &WININET_cs );
242 heap_free(info);
244 return TRUE;
247 /***********************************************************************
248 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
250 * PARAMS
251 * hinstDLL [I] handle to the DLL's instance
252 * fdwReason [I]
253 * lpvReserved [I] reserved, must be NULL
255 * RETURNS
256 * Success: TRUE
257 * Failure: FALSE
260 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
262 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
264 switch (fdwReason) {
265 case DLL_PROCESS_ATTACH:
267 g_dwTlsErrIndex = TlsAlloc();
269 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
270 return FALSE;
272 if(!init_urlcache())
274 TlsFree(g_dwTlsErrIndex);
275 return FALSE;
278 WININET_hModule = hinstDLL;
279 break;
281 case DLL_THREAD_ATTACH:
282 break;
284 case DLL_THREAD_DETACH:
285 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
287 heap_free(TlsGetValue(g_dwTlsErrIndex));
289 break;
291 case DLL_PROCESS_DETACH:
292 if (lpvReserved) break;
293 collect_connections(COLLECT_CLEANUP);
294 NETCON_unload();
295 free_urlcache();
296 free_cookie();
298 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
300 heap_free(TlsGetValue(g_dwTlsErrIndex));
301 TlsFree(g_dwTlsErrIndex);
303 break;
305 return TRUE;
308 /***********************************************************************
309 * DllInstall (WININET.@)
311 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
313 FIXME("(%x %s): stub\n", bInstall, debugstr_w(cmdline));
314 return S_OK;
317 /***********************************************************************
318 * INTERNET_SaveProxySettings
320 * Stores the proxy settings given by lpwai into the registry
322 * RETURNS
323 * ERROR_SUCCESS if no error, or error code on fail
325 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
327 HKEY key;
328 LONG ret;
330 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
331 return ret;
333 if ((ret = RegSetValueExW( key, L"ProxyEnable", 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
335 RegCloseKey( key );
336 return ret;
339 if (lpwpi->proxy)
341 if ((ret = RegSetValueExW( key, L"ProxyServer", 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
343 RegCloseKey( key );
344 return ret;
347 else
349 if ((ret = RegDeleteValueW( key, L"ProxyServer" )) && ret != ERROR_FILE_NOT_FOUND)
351 RegCloseKey( key );
352 return ret;
356 RegCloseKey(key);
357 return ERROR_SUCCESS;
360 /***********************************************************************
361 * INTERNET_FindProxyForProtocol
363 * Searches the proxy string for a proxy of the given protocol.
364 * Returns the found proxy, or the default proxy if none of the given
365 * protocol is found.
367 * PARAMETERS
368 * szProxy [In] proxy string to search
369 * proto [In] protocol to search for, e.g. "http"
370 * foundProxy [Out] found proxy
371 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
373 * RETURNS
374 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
375 * *foundProxyLen is set to the required size in WCHARs, including the
376 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
378 WCHAR *INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto)
380 WCHAR *ret = NULL;
381 const WCHAR *ptr;
383 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
385 /* First, look for the specified protocol (proto=scheme://host:port) */
386 for (ptr = szProxy; ptr && *ptr; )
388 LPCWSTR end, equal;
390 if (!(end = wcschr(ptr, ' ')))
391 end = ptr + lstrlenW(ptr);
392 if ((equal = wcschr(ptr, '=')) && equal < end &&
393 equal - ptr == lstrlenW(proto) &&
394 !wcsnicmp(proto, ptr, lstrlenW(proto)))
396 ret = heap_strndupW(equal + 1, end - equal - 1);
397 TRACE("found proxy for %s: %s\n", debugstr_w(proto), debugstr_w(ret));
398 return ret;
400 if (*end == ' ')
401 ptr = end + 1;
402 else
403 ptr = end;
406 /* It wasn't found: look for no protocol */
407 for (ptr = szProxy; ptr && *ptr; )
409 LPCWSTR end;
411 if (!(end = wcschr(ptr, ' ')))
412 end = ptr + lstrlenW(ptr);
413 if (!wcschr(ptr, '='))
415 ret = heap_strndupW(ptr, end - ptr);
416 TRACE("found proxy for %s: %s\n", debugstr_w(proto), debugstr_w(ret));
417 return ret;
419 if (*end == ' ')
420 ptr = end + 1;
421 else
422 ptr = end;
425 return NULL;
428 /***********************************************************************
429 * InternetInitializeAutoProxyDll (WININET.@)
431 * Setup the internal proxy
433 * PARAMETERS
434 * dwReserved
436 * RETURNS
437 * FALSE on failure
440 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
442 FIXME("STUB\n");
443 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
444 return FALSE;
447 /***********************************************************************
448 * DetectAutoProxyUrl (WININET.@)
450 * Auto detect the proxy url
452 * RETURNS
453 * FALSE on failure
456 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
457 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
459 FIXME("STUB\n");
460 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
461 return FALSE;
464 static void FreeProxyInfo( proxyinfo_t *lpwpi )
466 heap_free(lpwpi->proxy);
467 heap_free(lpwpi->proxyBypass);
468 heap_free(lpwpi->proxyUsername);
469 heap_free(lpwpi->proxyPassword);
472 static proxyinfo_t *global_proxy;
474 static void free_global_proxy( void )
476 EnterCriticalSection( &WININET_cs );
477 if (global_proxy)
479 FreeProxyInfo( global_proxy );
480 heap_free( global_proxy );
482 LeaveCriticalSection( &WININET_cs );
485 static BOOL parse_proxy_url( proxyinfo_t *info, const WCHAR *url )
487 URL_COMPONENTSW uc = {sizeof(uc)};
489 uc.dwHostNameLength = 1;
490 uc.dwUserNameLength = 1;
491 uc.dwPasswordLength = 1;
493 if (!InternetCrackUrlW( url, 0, 0, &uc )) return FALSE;
494 if (!uc.dwHostNameLength)
496 if (!(info->proxy = heap_strdupW( url ))) return FALSE;
497 info->proxyUsername = NULL;
498 info->proxyPassword = NULL;
499 return TRUE;
501 if (!(info->proxy = heap_alloc( (uc.dwHostNameLength + 12) * sizeof(WCHAR) ))) return FALSE;
502 swprintf( info->proxy, uc.dwHostNameLength + 12, L"%.*s:%u", uc.dwHostNameLength, uc.lpszHostName, uc.nPort );
504 if (!uc.dwUserNameLength) info->proxyUsername = NULL;
505 else if (!(info->proxyUsername = heap_strndupW( uc.lpszUserName, uc.dwUserNameLength )))
507 heap_free( info->proxy );
508 return FALSE;
510 if (!uc.dwPasswordLength) info->proxyPassword = NULL;
511 else if (!(info->proxyPassword = heap_strndupW( uc.lpszPassword, uc.dwPasswordLength )))
513 heap_free( info->proxyUsername );
514 heap_free( info->proxy );
515 return FALSE;
517 return TRUE;
520 /***********************************************************************
521 * INTERNET_LoadProxySettings
523 * Loads proxy information from process-wide global settings, the registry,
524 * or the environment into lpwpi.
526 * The caller should call FreeProxyInfo when done with lpwpi.
528 * FIXME:
529 * The proxy may be specified in the form 'http=proxy.my.org'
530 * Presumably that means there can be ftp=ftpproxy.my.org too.
532 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
534 HKEY key;
535 DWORD type, len;
536 const WCHAR *envproxy;
537 LONG ret;
539 memset( lpwpi, 0, sizeof(*lpwpi) );
541 EnterCriticalSection( &WININET_cs );
542 if (global_proxy)
544 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
545 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
546 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
548 LeaveCriticalSection( &WININET_cs );
550 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
552 FreeProxyInfo( lpwpi );
553 return ret;
556 len = sizeof(DWORD);
557 if (RegQueryValueExW( key, L"ProxyEnable", NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
559 lpwpi->proxyEnabled = 0;
560 if((ret = RegSetValueExW( key, L"ProxyEnable", 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
562 FreeProxyInfo( lpwpi );
563 RegCloseKey( key );
564 return ret;
568 if (!(envproxy = _wgetenv( L"http_proxy" )) || lpwpi->proxyEnabled)
570 /* figure out how much memory the proxy setting takes */
571 if (!RegQueryValueExW( key, L"ProxyServer", NULL, &type, NULL, &len ) && len && (type == REG_SZ))
573 LPWSTR szProxy, p;
575 if (!(szProxy = heap_alloc(len)))
577 RegCloseKey( key );
578 FreeProxyInfo( lpwpi );
579 return ERROR_OUTOFMEMORY;
581 RegQueryValueExW( key, L"ProxyServer", NULL, &type, (BYTE*)szProxy, &len );
583 /* find the http proxy, and strip away everything else */
584 p = wcsstr( szProxy, L"http=" );
585 if (p)
587 p += lstrlenW( L"http=" );
588 lstrcpyW( szProxy, p );
590 p = wcschr( szProxy, ';' );
591 if (p) *p = 0;
593 FreeProxyInfo( lpwpi );
594 lpwpi->proxy = szProxy;
595 lpwpi->proxyBypass = NULL;
597 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi->proxy));
599 else
601 TRACE("No proxy server settings in registry.\n");
602 FreeProxyInfo( lpwpi );
603 lpwpi->proxy = NULL;
604 lpwpi->proxyBypass = NULL;
607 else if (envproxy)
609 FreeProxyInfo( lpwpi );
610 if (parse_proxy_url( lpwpi, envproxy ))
612 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
613 lpwpi->proxyEnabled = 1;
614 lpwpi->proxyBypass = NULL;
616 else
618 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxy));
619 lpwpi->proxyEnabled = 0;
620 lpwpi->proxy = NULL;
621 lpwpi->proxyBypass = NULL;
625 if (lpwpi->proxyEnabled)
627 TRACE("Proxy is enabled.\n");
629 if (!(envproxy = _wgetenv( L"no_proxy" )))
631 /* figure out how much memory the proxy setting takes */
632 if (!RegQueryValueExW( key, L"ProxyOverride", NULL, &type, NULL, &len ) && len && (type == REG_SZ))
634 LPWSTR szProxy;
636 if (!(szProxy = heap_alloc(len)))
638 RegCloseKey( key );
639 return ERROR_OUTOFMEMORY;
641 RegQueryValueExW( key, L"ProxyOverride", NULL, &type, (BYTE*)szProxy, &len );
643 heap_free( lpwpi->proxyBypass );
644 lpwpi->proxyBypass = szProxy;
646 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi->proxyBypass));
648 else
650 heap_free( lpwpi->proxyBypass );
651 lpwpi->proxyBypass = NULL;
653 TRACE("No proxy bypass server settings in registry.\n");
656 else
658 WCHAR *envproxyW;
660 if (!(envproxyW = heap_alloc(lstrlenW(envproxy) * sizeof(WCHAR))))
662 RegCloseKey( key );
663 return ERROR_OUTOFMEMORY;
665 lstrcpyW( envproxyW, envproxy );
667 heap_free( lpwpi->proxyBypass );
668 lpwpi->proxyBypass = envproxyW;
670 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
673 else TRACE("Proxy is disabled.\n");
675 RegCloseKey( key );
676 return ERROR_SUCCESS;
679 /***********************************************************************
680 * INTERNET_ConfigureProxy
682 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
684 proxyinfo_t wpi;
686 if (INTERNET_LoadProxySettings( &wpi ))
687 return FALSE;
689 if (wpi.proxyEnabled)
691 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi.proxy), debugstr_w(wpi.proxyBypass));
693 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
694 lpwai->proxy = wpi.proxy;
695 lpwai->proxyBypass = wpi.proxyBypass;
696 lpwai->proxyUsername = wpi.proxyUsername;
697 lpwai->proxyPassword = wpi.proxyPassword;
698 return TRUE;
701 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
702 FreeProxyInfo(&wpi);
703 return FALSE;
706 /***********************************************************************
707 * dump_INTERNET_FLAGS
709 * Helper function to TRACE the internet flags.
711 * RETURNS
712 * None
715 static void dump_INTERNET_FLAGS(DWORD dwFlags)
717 #define FE(x) { x, #x }
718 static const wininet_flag_info flag[] = {
719 FE(INTERNET_FLAG_RELOAD),
720 FE(INTERNET_FLAG_RAW_DATA),
721 FE(INTERNET_FLAG_EXISTING_CONNECT),
722 FE(INTERNET_FLAG_ASYNC),
723 FE(INTERNET_FLAG_PASSIVE),
724 FE(INTERNET_FLAG_NO_CACHE_WRITE),
725 FE(INTERNET_FLAG_MAKE_PERSISTENT),
726 FE(INTERNET_FLAG_FROM_CACHE),
727 FE(INTERNET_FLAG_SECURE),
728 FE(INTERNET_FLAG_KEEP_CONNECTION),
729 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
730 FE(INTERNET_FLAG_READ_PREFETCH),
731 FE(INTERNET_FLAG_NO_COOKIES),
732 FE(INTERNET_FLAG_NO_AUTH),
733 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
734 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
735 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
736 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
737 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
738 FE(INTERNET_FLAG_RESYNCHRONIZE),
739 FE(INTERNET_FLAG_HYPERLINK),
740 FE(INTERNET_FLAG_NO_UI),
741 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
742 FE(INTERNET_FLAG_CACHE_ASYNC),
743 FE(INTERNET_FLAG_FORMS_SUBMIT),
744 FE(INTERNET_FLAG_NEED_FILE),
745 FE(INTERNET_FLAG_TRANSFER_ASCII),
746 FE(INTERNET_FLAG_TRANSFER_BINARY)
748 #undef FE
749 unsigned int i;
751 for (i = 0; i < ARRAY_SIZE(flag); i++) {
752 if (flag[i].val & dwFlags) {
753 TRACE(" %s", flag[i].name);
754 dwFlags &= ~flag[i].val;
757 if (dwFlags)
758 TRACE(" Unknown flags (%08x)\n", dwFlags);
759 else
760 TRACE("\n");
763 /***********************************************************************
764 * INTERNET_CloseHandle (internal)
766 * Close internet handle
769 static VOID APPINFO_Destroy(object_header_t *hdr)
771 appinfo_t *lpwai = (appinfo_t*)hdr;
773 TRACE("%p\n",lpwai);
775 heap_free(lpwai->agent);
776 heap_free(lpwai->proxy);
777 heap_free(lpwai->proxyBypass);
778 heap_free(lpwai->proxyUsername);
779 heap_free(lpwai->proxyPassword);
782 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
784 appinfo_t *ai = (appinfo_t*)hdr;
786 switch(option) {
787 case INTERNET_OPTION_HANDLE_TYPE:
788 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
790 if (*size < sizeof(ULONG))
791 return ERROR_INSUFFICIENT_BUFFER;
793 *size = sizeof(DWORD);
794 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
795 return ERROR_SUCCESS;
797 case INTERNET_OPTION_USER_AGENT: {
798 DWORD bufsize;
800 TRACE("INTERNET_OPTION_USER_AGENT\n");
802 bufsize = *size;
804 if (unicode) {
805 DWORD len = ai->agent ? lstrlenW(ai->agent) : 0;
807 *size = (len + 1) * sizeof(WCHAR);
808 if(!buffer || bufsize < *size)
809 return ERROR_INSUFFICIENT_BUFFER;
811 if (ai->agent)
812 lstrcpyW(buffer, ai->agent);
813 else
814 *(WCHAR *)buffer = 0;
815 /* If the buffer is copied, the returned length doesn't include
816 * the NULL terminator.
818 *size = len;
819 }else {
820 if (ai->agent)
821 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
822 else
823 *size = 1;
824 if(!buffer || bufsize < *size)
825 return ERROR_INSUFFICIENT_BUFFER;
827 if (ai->agent)
828 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
829 else
830 *(char *)buffer = 0;
831 /* If the buffer is copied, the returned length doesn't include
832 * the NULL terminator.
834 *size -= 1;
837 return ERROR_SUCCESS;
840 case INTERNET_OPTION_PROXY:
841 if(!size) return ERROR_INVALID_PARAMETER;
842 if (unicode) {
843 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
844 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
845 LPWSTR proxy, proxy_bypass;
847 if (ai->proxy)
848 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
849 if (ai->proxyBypass)
850 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
851 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
853 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
854 return ERROR_INSUFFICIENT_BUFFER;
856 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
857 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
859 pi->dwAccessType = ai->accessType;
860 pi->lpszProxy = NULL;
861 pi->lpszProxyBypass = NULL;
862 if (ai->proxy) {
863 lstrcpyW(proxy, ai->proxy);
864 pi->lpszProxy = proxy;
867 if (ai->proxyBypass) {
868 lstrcpyW(proxy_bypass, ai->proxyBypass);
869 pi->lpszProxyBypass = proxy_bypass;
872 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
873 return ERROR_SUCCESS;
874 }else {
875 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
876 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
877 LPSTR proxy, proxy_bypass;
879 if (ai->proxy)
880 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
881 if (ai->proxyBypass)
882 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
883 NULL, 0, NULL, NULL);
884 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
886 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
887 return ERROR_INSUFFICIENT_BUFFER;
889 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
890 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
892 pi->dwAccessType = ai->accessType;
893 pi->lpszProxy = NULL;
894 pi->lpszProxyBypass = NULL;
895 if (ai->proxy) {
896 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
897 pi->lpszProxy = proxy;
900 if (ai->proxyBypass) {
901 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
902 proxyBypassBytesRequired, NULL, NULL);
903 pi->lpszProxyBypass = proxy_bypass;
906 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
907 return ERROR_SUCCESS;
910 case INTERNET_OPTION_CONNECT_TIMEOUT:
911 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
913 if (*size < sizeof(ULONG))
914 return ERROR_INSUFFICIENT_BUFFER;
916 *(ULONG*)buffer = ai->connect_timeout;
917 *size = sizeof(ULONG);
919 return ERROR_SUCCESS;
922 return INET_QueryOption(hdr, option, buffer, size, unicode);
925 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
927 appinfo_t *ai = (appinfo_t*)hdr;
929 switch(option) {
930 case INTERNET_OPTION_CONNECT_TIMEOUT:
931 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
933 if(size != sizeof(connect_timeout))
934 return ERROR_INTERNET_BAD_OPTION_LENGTH;
935 if(!*(ULONG*)buf)
936 return ERROR_BAD_ARGUMENTS;
938 ai->connect_timeout = *(ULONG*)buf;
939 return ERROR_SUCCESS;
940 case INTERNET_OPTION_USER_AGENT:
941 heap_free(ai->agent);
942 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
943 return ERROR_SUCCESS;
944 case INTERNET_OPTION_REFRESH:
945 FIXME("INTERNET_OPTION_REFRESH\n");
946 return ERROR_SUCCESS;
949 return INET_SetOption(hdr, option, buf, size);
952 static const object_vtbl_t APPINFOVtbl = {
953 APPINFO_Destroy,
954 NULL,
955 APPINFO_QueryOption,
956 APPINFO_SetOption,
957 NULL,
958 NULL,
959 NULL
963 /***********************************************************************
964 * InternetOpenW (WININET.@)
966 * Per-application initialization of wininet
968 * RETURNS
969 * HINTERNET on success
970 * NULL on failure
973 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
974 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
976 appinfo_t *lpwai = NULL;
978 if (TRACE_ON(wininet)) {
979 #define FE(x) { x, #x }
980 static const wininet_flag_info access_type[] = {
981 FE(INTERNET_OPEN_TYPE_PRECONFIG),
982 FE(INTERNET_OPEN_TYPE_DIRECT),
983 FE(INTERNET_OPEN_TYPE_PROXY),
984 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
986 #undef FE
987 DWORD i;
988 const char *access_type_str = "Unknown";
990 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
991 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
992 for (i = 0; i < ARRAY_SIZE(access_type); i++) {
993 if (access_type[i].val == dwAccessType) {
994 access_type_str = access_type[i].name;
995 break;
998 TRACE(" access type : %s\n", access_type_str);
999 TRACE(" flags :");
1000 dump_INTERNET_FLAGS(dwFlags);
1003 /* Clear any error information */
1004 INTERNET_SetLastError(0);
1006 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1007 SetLastError(ERROR_INVALID_PARAMETER);
1008 return NULL;
1011 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1012 if (!lpwai) {
1013 SetLastError(ERROR_OUTOFMEMORY);
1014 return NULL;
1017 lpwai->hdr.htype = WH_HINIT;
1018 lpwai->hdr.dwFlags = dwFlags;
1019 lpwai->accessType = dwAccessType;
1020 lpwai->proxyUsername = NULL;
1021 lpwai->proxyPassword = NULL;
1022 lpwai->connect_timeout = connect_timeout;
1024 lpwai->agent = heap_strdupW(lpszAgent);
1025 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1026 INTERNET_ConfigureProxy( lpwai );
1027 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1028 lpwai->proxy = heap_strdupW(lpszProxy);
1029 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1032 TRACE("returning %p\n", lpwai);
1034 return lpwai->hdr.hInternet;
1038 /***********************************************************************
1039 * InternetOpenA (WININET.@)
1041 * Per-application initialization of wininet
1043 * RETURNS
1044 * HINTERNET on success
1045 * NULL on failure
1048 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1049 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1051 WCHAR *szAgent, *szProxy, *szBypass;
1052 HINTERNET rc;
1054 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1055 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1057 szAgent = heap_strdupAtoW(lpszAgent);
1058 szProxy = heap_strdupAtoW(lpszProxy);
1059 szBypass = heap_strdupAtoW(lpszProxyBypass);
1061 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1063 heap_free(szAgent);
1064 heap_free(szProxy);
1065 heap_free(szBypass);
1066 return rc;
1069 /***********************************************************************
1070 * InternetGetLastResponseInfoA (WININET.@)
1072 * Return last wininet error description on the calling thread
1074 * RETURNS
1075 * TRUE on success of writing to buffer
1076 * FALSE on failure
1079 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1080 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1082 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1084 TRACE("(%p, %p, %p)\n", lpdwError, lpszBuffer, lpdwBufferLength);
1086 if (!lpdwError || !lpdwBufferLength)
1088 SetLastError(ERROR_INVALID_PARAMETER);
1089 return FALSE;
1091 if (lpwite)
1093 if (lpszBuffer == NULL || *lpdwBufferLength < strlen(lpwite->response))
1095 *lpdwBufferLength = strlen(lpwite->response);
1096 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1097 return FALSE;
1099 *lpdwError = lpwite->dwError;
1100 if (*lpdwBufferLength)
1102 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1103 lpszBuffer[*lpdwBufferLength - 1] = 0;
1104 *lpdwBufferLength = strlen(lpszBuffer);
1107 else
1109 *lpdwError = 0;
1110 *lpdwBufferLength = 0;
1113 return TRUE;
1116 /***********************************************************************
1117 * InternetGetLastResponseInfoW (WININET.@)
1119 * Return last wininet error description on the calling thread
1121 * RETURNS
1122 * TRUE on success of writing to buffer
1123 * FALSE on failure
1126 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1127 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1129 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1131 TRACE("(%p, %p, %p)\n", lpdwError, lpszBuffer, lpdwBufferLength);
1133 if (!lpdwError || !lpdwBufferLength)
1135 SetLastError(ERROR_INVALID_PARAMETER);
1136 return FALSE;
1138 if (lpwite)
1140 int required_size = MultiByteToWideChar(CP_ACP, 0, lpwite->response, -1, NULL, 0) - 1;
1141 if (lpszBuffer == NULL || *lpdwBufferLength < required_size)
1143 *lpdwBufferLength = required_size;
1144 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1145 return FALSE;
1147 *lpdwError = lpwite->dwError;
1148 if (*lpdwBufferLength)
1149 *lpdwBufferLength = MultiByteToWideChar(CP_ACP, 0, lpwite->response, -1, lpszBuffer, *lpdwBufferLength);
1151 else
1153 *lpdwError = 0;
1154 *lpdwBufferLength = 0;
1157 return TRUE;
1160 /***********************************************************************
1161 * InternetGetConnectedState (WININET.@)
1163 * Return connected state
1165 * RETURNS
1166 * TRUE if connected
1167 * if lpdwStatus is not null, return the status (off line,
1168 * modem, lan...) in it.
1169 * FALSE if not connected
1171 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1173 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1175 return InternetGetConnectedStateExW(lpdwStatus, NULL, 0, dwReserved);
1179 /***********************************************************************
1180 * InternetGetConnectedStateExW (WININET.@)
1182 * Return connected state
1184 * PARAMS
1186 * lpdwStatus [O] Flags specifying the status of the internet connection.
1187 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1188 * dwNameLen [I] Size of the buffer, in characters.
1189 * dwReserved [I] Reserved. Must be set to 0.
1191 * RETURNS
1192 * TRUE if connected
1193 * if lpdwStatus is not null, return the status (off line,
1194 * modem, lan...) in it.
1195 * FALSE if not connected
1197 * NOTES
1198 * If the system has no available network connections, an empty string is
1199 * stored in lpszConnectionName. If there is a LAN connection, a localized
1200 * "LAN Connection" string is stored. Presumably, if only a dial-up
1201 * connection is available then the name of the dial-up connection is
1202 * returned. Why any application, other than the "Internet Settings" CPL,
1203 * would want to use this function instead of the simpler InternetGetConnectedStateW
1204 * function is beyond me.
1206 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1207 DWORD dwNameLen, DWORD dwReserved)
1209 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1211 /* Must be zero */
1212 if(dwReserved)
1213 return FALSE;
1215 if (lpdwStatus) {
1216 WARN("always returning LAN connection.\n");
1217 *lpdwStatus = INTERNET_CONNECTION_LAN;
1220 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1221 * the resource, avoid it as we must not change the buffer in this case */
1222 if(lpszConnectionName && dwNameLen) {
1223 *lpszConnectionName = '\0';
1224 LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1227 return TRUE;
1231 /***********************************************************************
1232 * InternetGetConnectedStateExA (WININET.@)
1234 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1235 DWORD dwNameLen, DWORD dwReserved)
1237 LPWSTR lpwszConnectionName = NULL;
1238 BOOL rc;
1240 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1242 if (lpszConnectionName && dwNameLen > 0)
1243 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1245 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1246 dwReserved);
1247 if (rc && lpwszConnectionName)
1248 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1249 dwNameLen, NULL, NULL);
1251 heap_free(lpwszConnectionName);
1252 return rc;
1256 /***********************************************************************
1257 * InternetConnectW (WININET.@)
1259 * Open a ftp, gopher or http session
1261 * RETURNS
1262 * HINTERNET a session handle on success
1263 * NULL on failure
1266 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1267 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1268 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1269 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1271 appinfo_t *hIC;
1272 HINTERNET rc = NULL;
1273 DWORD res = ERROR_SUCCESS;
1275 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1276 nServerPort, debugstr_w(lpszUserName), lpszPassword, dwService, dwFlags, dwContext);
1278 if (!lpszServerName)
1280 SetLastError(ERROR_INVALID_PARAMETER);
1281 return NULL;
1284 hIC = (appinfo_t*)get_handle_object( hInternet );
1285 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1287 res = ERROR_INVALID_HANDLE;
1288 goto lend;
1291 switch (dwService)
1293 case INTERNET_SERVICE_FTP:
1294 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1295 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1296 if(!rc)
1297 res = INTERNET_GetLastError();
1298 break;
1300 case INTERNET_SERVICE_HTTP:
1301 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1302 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1303 break;
1305 case INTERNET_SERVICE_GOPHER:
1306 default:
1307 break;
1309 lend:
1310 if( hIC )
1311 WININET_Release( &hIC->hdr );
1313 TRACE("returning %p\n", rc);
1314 SetLastError(res);
1315 return rc;
1319 /***********************************************************************
1320 * InternetConnectA (WININET.@)
1322 * Open a ftp, gopher or http session
1324 * RETURNS
1325 * HINTERNET a session handle on success
1326 * NULL on failure
1329 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1330 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1331 LPCSTR lpszUserName, LPCSTR lpszPassword,
1332 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1334 HINTERNET rc = NULL;
1335 LPWSTR szServerName;
1336 LPWSTR szUserName;
1337 LPWSTR szPassword;
1339 szServerName = heap_strdupAtoW(lpszServerName);
1340 szUserName = heap_strdupAtoW(lpszUserName);
1341 szPassword = heap_strdupAtoW(lpszPassword);
1343 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1344 szUserName, szPassword, dwService, dwFlags, dwContext);
1346 heap_free(szServerName);
1347 heap_free(szUserName);
1348 heap_free(szPassword);
1349 return rc;
1353 /***********************************************************************
1354 * InternetFindNextFileA (WININET.@)
1356 * Continues a file search from a previous call to FindFirstFile
1358 * RETURNS
1359 * TRUE on success
1360 * FALSE on failure
1363 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1365 BOOL ret;
1366 WIN32_FIND_DATAW fd;
1368 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1369 if(lpvFindData)
1370 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1371 return ret;
1374 /***********************************************************************
1375 * InternetFindNextFileW (WININET.@)
1377 * Continues a file search from a previous call to FindFirstFile
1379 * RETURNS
1380 * TRUE on success
1381 * FALSE on failure
1384 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1386 object_header_t *hdr;
1387 DWORD res;
1389 TRACE("\n");
1391 hdr = get_handle_object(hFind);
1392 if(!hdr) {
1393 WARN("Invalid handle\n");
1394 SetLastError(ERROR_INVALID_HANDLE);
1395 return FALSE;
1398 if(hdr->vtbl->FindNextFileW) {
1399 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1400 }else {
1401 WARN("Handle doesn't support NextFile\n");
1402 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1405 WININET_Release(hdr);
1407 if(res != ERROR_SUCCESS)
1408 SetLastError(res);
1409 return res == ERROR_SUCCESS;
1412 /***********************************************************************
1413 * InternetCloseHandle (WININET.@)
1415 * Generic close handle function
1417 * RETURNS
1418 * TRUE on success
1419 * FALSE on failure
1422 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1424 object_header_t *obj;
1426 TRACE("%p\n", hInternet);
1428 obj = get_handle_object( hInternet );
1429 if (!obj) {
1430 SetLastError(ERROR_INVALID_HANDLE);
1431 return FALSE;
1434 invalidate_handle(obj);
1435 WININET_Release(obj);
1437 return TRUE;
1440 static BOOL set_url_component(WCHAR **component, DWORD *component_length, const WCHAR *value, DWORD len)
1442 TRACE("%s (%d)\n", debugstr_wn(value, len), len);
1444 if (!*component_length)
1445 return TRUE;
1447 if (!*component) {
1448 *(const WCHAR**)component = value;
1449 *component_length = len;
1450 return TRUE;
1453 if (*component_length < len+1) {
1454 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1455 return FALSE;
1458 *component_length = len;
1459 if(len)
1460 memcpy(*component, value, len*sizeof(WCHAR));
1461 (*component)[len] = 0;
1462 return TRUE;
1465 static BOOL set_url_component_WtoA(const WCHAR *comp_w, DWORD length, const WCHAR *url_w, char **comp, DWORD *ret_length,
1466 const char *url_a)
1468 size_t size, ret_size = *ret_length;
1470 if (!*ret_length)
1471 return TRUE;
1472 size = WideCharToMultiByte(CP_ACP, 0, comp_w, length, NULL, 0, NULL, NULL);
1474 if (!*comp) {
1475 *comp = comp_w ? (char*)url_a + WideCharToMultiByte(CP_ACP, 0, url_w, comp_w-url_w, NULL, 0, NULL, NULL) : NULL;
1476 *ret_length = size;
1477 return TRUE;
1480 if (size+1 > ret_size) {
1481 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1482 *ret_length = size+1;
1483 return FALSE;
1486 *ret_length = size;
1487 WideCharToMultiByte(CP_ACP, 0, comp_w, length, *comp, ret_size-1, NULL, NULL);
1488 (*comp)[size] = 0;
1489 return TRUE;
1492 static BOOL set_url_component_AtoW(const char *comp_a, DWORD len_a, WCHAR **comp_w, DWORD *len_w, WCHAR **buf)
1494 *len_w = len_a;
1496 if(!comp_a) {
1497 *comp_w = NULL;
1498 return TRUE;
1501 if(!(*comp_w = *buf = heap_alloc(len_a*sizeof(WCHAR)))) {
1502 SetLastError(ERROR_OUTOFMEMORY);
1503 return FALSE;
1506 return TRUE;
1509 /***********************************************************************
1510 * InternetCrackUrlA (WININET.@)
1512 * See InternetCrackUrlW.
1514 BOOL WINAPI InternetCrackUrlA(const char *url, DWORD url_length, DWORD flags, URL_COMPONENTSA *ret_comp)
1516 WCHAR *host = NULL, *user = NULL, *pass = NULL, *path = NULL, *scheme = NULL, *extra = NULL;
1517 URL_COMPONENTSW comp;
1518 WCHAR *url_w = NULL;
1519 BOOL ret;
1521 TRACE("(%s %u %x %p)\n", url_length ? debugstr_an(url, url_length) : debugstr_a(url), url_length, flags, ret_comp);
1523 if (!url || !*url || !ret_comp || ret_comp->dwStructSize != sizeof(URL_COMPONENTSA)) {
1524 SetLastError(ERROR_INVALID_PARAMETER);
1525 return FALSE;
1528 comp.dwStructSize = sizeof(comp);
1530 ret = set_url_component_AtoW(ret_comp->lpszHostName, ret_comp->dwHostNameLength,
1531 &comp.lpszHostName, &comp.dwHostNameLength, &host)
1532 && set_url_component_AtoW(ret_comp->lpszUserName, ret_comp->dwUserNameLength,
1533 &comp.lpszUserName, &comp.dwUserNameLength, &user)
1534 && set_url_component_AtoW(ret_comp->lpszPassword, ret_comp->dwPasswordLength,
1535 &comp.lpszPassword, &comp.dwPasswordLength, &pass)
1536 && set_url_component_AtoW(ret_comp->lpszUrlPath, ret_comp->dwUrlPathLength,
1537 &comp.lpszUrlPath, &comp.dwUrlPathLength, &path)
1538 && set_url_component_AtoW(ret_comp->lpszScheme, ret_comp->dwSchemeLength,
1539 &comp.lpszScheme, &comp.dwSchemeLength, &scheme)
1540 && set_url_component_AtoW(ret_comp->lpszExtraInfo, ret_comp->dwExtraInfoLength,
1541 &comp.lpszExtraInfo, &comp.dwExtraInfoLength, &extra);
1543 if(ret && !(url_w = heap_strndupAtoW(url, url_length ? url_length : -1, &url_length))) {
1544 SetLastError(ERROR_OUTOFMEMORY);
1545 ret = FALSE;
1548 if (ret && (ret = InternetCrackUrlW(url_w, url_length, flags, &comp))) {
1549 ret_comp->nScheme = comp.nScheme;
1550 ret_comp->nPort = comp.nPort;
1552 ret = set_url_component_WtoA(comp.lpszHostName, comp.dwHostNameLength, url_w,
1553 &ret_comp->lpszHostName, &ret_comp->dwHostNameLength, url)
1554 && set_url_component_WtoA(comp.lpszUserName, comp.dwUserNameLength, url_w,
1555 &ret_comp->lpszUserName, &ret_comp->dwUserNameLength, url)
1556 && set_url_component_WtoA(comp.lpszPassword, comp.dwPasswordLength, url_w,
1557 &ret_comp->lpszPassword, &ret_comp->dwPasswordLength, url)
1558 && set_url_component_WtoA(comp.lpszUrlPath, comp.dwUrlPathLength, url_w,
1559 &ret_comp->lpszUrlPath, &ret_comp->dwUrlPathLength, url)
1560 && set_url_component_WtoA(comp.lpszScheme, comp.dwSchemeLength, url_w,
1561 &ret_comp->lpszScheme, &ret_comp->dwSchemeLength, url)
1562 && set_url_component_WtoA(comp.lpszExtraInfo, comp.dwExtraInfoLength, url_w,
1563 &ret_comp->lpszExtraInfo, &ret_comp->dwExtraInfoLength, url);
1565 if(ret)
1566 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url),
1567 debugstr_an(ret_comp->lpszScheme, ret_comp->dwSchemeLength),
1568 debugstr_an(ret_comp->lpszHostName, ret_comp->dwHostNameLength),
1569 debugstr_an(ret_comp->lpszUrlPath, ret_comp->dwUrlPathLength),
1570 debugstr_an(ret_comp->lpszExtraInfo, ret_comp->dwExtraInfoLength));
1573 heap_free(host);
1574 heap_free(user);
1575 heap_free(pass);
1576 heap_free(path);
1577 heap_free(scheme);
1578 heap_free(extra);
1579 heap_free(url_w);
1580 return ret;
1583 static const WCHAR *url_schemes[] =
1585 L"ftp",
1586 L"gopher",
1587 L"http",
1588 L"https",
1589 L"file",
1590 L"news",
1591 L"mailto",
1592 L"socks",
1593 L"javascript",
1594 L"vbscript",
1595 L"res"
1598 /***********************************************************************
1599 * GetInternetSchemeW (internal)
1601 * Get scheme of url
1603 * RETURNS
1604 * scheme on success
1605 * INTERNET_SCHEME_UNKNOWN on failure
1608 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1610 int i;
1612 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1614 if(lpszScheme==NULL)
1615 return INTERNET_SCHEME_UNKNOWN;
1617 for (i = 0; i < ARRAY_SIZE(url_schemes); i++)
1618 if (!wcsnicmp(lpszScheme, url_schemes[i], nMaxCmp))
1619 return INTERNET_SCHEME_FIRST + i;
1621 return INTERNET_SCHEME_UNKNOWN;
1624 /***********************************************************************
1625 * InternetCrackUrlW (WININET.@)
1627 * Break up URL into its components
1629 * RETURNS
1630 * TRUE on success
1631 * FALSE on failure
1633 BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
1636 * RFC 1808
1637 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1640 LPCWSTR lpszParam = NULL;
1641 BOOL found_colon = FALSE;
1642 LPCWSTR lpszap;
1643 LPCWSTR lpszcp = NULL, lpszNetLoc;
1645 TRACE("(%s %u %x %p)\n",
1646 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : lstrlenW(lpszUrl)) : "(null)",
1647 dwUrlLength, dwFlags, lpUC);
1649 if (!lpszUrl || !*lpszUrl || !lpUC)
1651 SetLastError(ERROR_INVALID_PARAMETER);
1652 return FALSE;
1655 if (!dwUrlLength)
1656 dwUrlLength = lstrlenW(lpszUrl);
1657 else {
1658 /* Windows stops at a null, regardless of what dwUrlLength says. */
1659 dwUrlLength = wcsnlen(lpszUrl, dwUrlLength);
1662 if (dwFlags & ICU_DECODE)
1664 WCHAR *url_tmp, *buffer;
1665 DWORD len = dwUrlLength + 1;
1666 BOOL ret;
1668 if (!(url_tmp = heap_strndupW(lpszUrl, dwUrlLength)))
1670 SetLastError(ERROR_OUTOFMEMORY);
1671 return FALSE;
1674 buffer = url_tmp;
1675 ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
1676 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1678 buffer = heap_alloc(len * sizeof(WCHAR));
1679 if (!buffer)
1681 SetLastError(ERROR_OUTOFMEMORY);
1682 heap_free(url_tmp);
1683 return FALSE;
1685 ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
1687 if (ret)
1688 ret = InternetCrackUrlW(buffer, len, dwFlags & ~ICU_DECODE, lpUC);
1690 if (buffer != url_tmp) heap_free(buffer);
1691 heap_free(url_tmp);
1692 return ret;
1694 lpszap = lpszUrl;
1696 /* Determine if the URI is absolute. */
1697 while (lpszap - lpszUrl < dwUrlLength)
1699 if (iswalnum(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1701 lpszap++;
1702 continue;
1704 if (*lpszap == ':')
1706 found_colon = TRUE;
1707 lpszcp = lpszap;
1709 else
1711 lpszcp = lpszUrl; /* Relative url */
1714 break;
1717 if(!found_colon){
1718 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1719 return FALSE;
1722 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1723 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1725 /* Parse <params> */
1726 lpszParam = wmemchr(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1727 if(!lpszParam)
1728 lpszParam = wmemchr(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1730 if(!set_url_component(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1731 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0))
1732 return FALSE;
1735 /* Get scheme first. */
1736 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1737 if(!set_url_component(&lpUC->lpszScheme, &lpUC->dwSchemeLength, lpszUrl, lpszcp - lpszUrl))
1738 return FALSE;
1740 /* Eat ':' in protocol. */
1741 lpszcp++;
1743 /* double slash indicates the net_loc portion is present */
1744 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1746 lpszcp += 2;
1748 lpszNetLoc = wmemchr(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1749 if (lpszParam)
1751 if (lpszNetLoc)
1752 lpszNetLoc = min(lpszNetLoc, lpszParam);
1753 else
1754 lpszNetLoc = lpszParam;
1756 else if (!lpszNetLoc)
1757 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1759 /* Parse net-loc */
1760 if (lpszNetLoc)
1762 LPCWSTR lpszHost;
1763 LPCWSTR lpszPort;
1765 /* [<user>[<:password>]@]<host>[:<port>] */
1766 /* First find the user and password if they exist */
1768 lpszHost = wmemchr(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1769 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1771 /* username and password not specified. */
1772 set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1773 set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1775 else /* Parse out username and password */
1777 LPCWSTR lpszUser = lpszcp;
1778 LPCWSTR lpszPasswd = lpszHost;
1780 while (lpszcp < lpszHost)
1782 if (*lpszcp == ':')
1783 lpszPasswd = lpszcp;
1785 lpszcp++;
1788 if(!set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, lpszUser, lpszPasswd - lpszUser))
1789 return FALSE;
1791 if (lpszPasswd != lpszHost)
1792 lpszPasswd++;
1793 if(!set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1794 lpszPasswd == lpszHost ? NULL : lpszPasswd, lpszHost - lpszPasswd))
1795 return FALSE;
1797 lpszcp++; /* Advance to beginning of host */
1800 /* Parse <host><:port> */
1802 lpszHost = lpszcp;
1803 lpszPort = lpszNetLoc;
1805 /* special case for res:// URLs: there is no port here, so the host is the
1806 entire string up to the first '/' */
1807 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1809 if(!set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost))
1810 return FALSE;
1811 lpszcp=lpszNetLoc;
1813 else
1815 while (lpszcp < lpszNetLoc)
1817 if (*lpszcp == ':')
1818 lpszPort = lpszcp;
1820 lpszcp++;
1823 /* If the scheme is "file" and the host is just one letter, it's not a host */
1824 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1826 lpszcp=lpszHost;
1827 set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1829 else
1831 if(!set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost))
1832 return FALSE;
1833 if (lpszPort != lpszNetLoc)
1834 lpUC->nPort = wcstol(++lpszPort, NULL, 10);
1835 else switch (lpUC->nScheme)
1837 case INTERNET_SCHEME_HTTP:
1838 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1839 break;
1840 case INTERNET_SCHEME_HTTPS:
1841 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1842 break;
1843 case INTERNET_SCHEME_FTP:
1844 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1845 break;
1846 default:
1847 break;
1853 else
1855 set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1856 set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1857 set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1860 /* Here lpszcp points to:
1862 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1863 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1865 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1867 DWORD len;
1869 /* Only truncate the parameter list if it's already been saved
1870 * in lpUC->lpszExtraInfo.
1872 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1873 len = lpszParam - lpszcp;
1874 else
1876 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1877 * newlines if necessary.
1879 LPWSTR lpsznewline = wmemchr(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1880 if (lpsznewline != NULL)
1881 len = lpsznewline - lpszcp;
1882 else
1883 len = dwUrlLength-(lpszcp-lpszUrl);
1885 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1886 lpUC->nScheme == INTERNET_SCHEME_FILE)
1888 WCHAR tmppath[MAX_PATH];
1889 if (*lpszcp == '/')
1891 len = MAX_PATH;
1892 PathCreateFromUrlW(lpszUrl, tmppath, &len, 0);
1894 else
1896 WCHAR *iter;
1897 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1898 tmppath[len] = '\0';
1900 iter = tmppath;
1901 while (*iter) {
1902 if (*iter == '/')
1903 *iter = '\\';
1904 ++iter;
1907 /* if ends in \. or \.. append a backslash */
1908 if (tmppath[len - 1] == '.' &&
1909 (tmppath[len - 2] == '\\' ||
1910 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1912 if (len < MAX_PATH - 1)
1914 tmppath[len] = '\\';
1915 tmppath[len+1] = '\0';
1916 ++len;
1919 if(!set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, tmppath, len))
1920 return FALSE;
1922 else if(!set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, lpszcp, len))
1923 return FALSE;
1925 else
1927 set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, lpszcp, 0);
1930 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1931 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1932 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1933 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1934 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1936 return TRUE;
1939 /***********************************************************************
1940 * InternetAttemptConnect (WININET.@)
1942 * Attempt to make a connection to the internet
1944 * RETURNS
1945 * ERROR_SUCCESS on success
1946 * Error value on failure
1949 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1951 FIXME("Stub\n");
1952 return ERROR_SUCCESS;
1956 /***********************************************************************
1957 * convert_url_canonicalization_flags
1959 * Helper for InternetCanonicalizeUrl
1961 * PARAMS
1962 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1964 * RETURNS
1965 * Flags suitable for UrlCanonicalize
1967 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
1969 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1971 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
1972 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
1973 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
1974 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
1975 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1976 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
1977 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
1979 return dwUrlFlags;
1982 /***********************************************************************
1983 * InternetCanonicalizeUrlA (WININET.@)
1985 * Escape unsafe characters and spaces
1987 * RETURNS
1988 * TRUE on success
1989 * FALSE on failure
1992 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1993 LPDWORD lpdwBufferLength, DWORD dwFlags)
1995 HRESULT hr;
1997 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1998 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2000 dwFlags = convert_url_canonicalization_flags(dwFlags);
2001 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2002 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2003 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2005 return hr == S_OK;
2008 /***********************************************************************
2009 * InternetCanonicalizeUrlW (WININET.@)
2011 * Escape unsafe characters and spaces
2013 * RETURNS
2014 * TRUE on success
2015 * FALSE on failure
2018 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
2019 LPDWORD lpdwBufferLength, DWORD dwFlags)
2021 HRESULT hr;
2023 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2024 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2026 dwFlags = convert_url_canonicalization_flags(dwFlags);
2027 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2028 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2029 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2031 return hr == S_OK;
2034 /* #################################################### */
2036 static INTERNET_STATUS_CALLBACK set_status_callback(
2037 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2039 INTERNET_STATUS_CALLBACK ret;
2041 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2042 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2044 ret = lpwh->lpfnStatusCB;
2045 lpwh->lpfnStatusCB = callback;
2047 return ret;
2050 /***********************************************************************
2051 * InternetSetStatusCallbackA (WININET.@)
2053 * Sets up a callback function which is called as progress is made
2054 * during an operation.
2056 * RETURNS
2057 * Previous callback or NULL on success
2058 * INTERNET_INVALID_STATUS_CALLBACK on failure
2061 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2062 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2064 INTERNET_STATUS_CALLBACK retVal;
2065 object_header_t *lpwh;
2067 TRACE("%p\n", hInternet);
2069 if (!(lpwh = get_handle_object(hInternet)))
2070 return INTERNET_INVALID_STATUS_CALLBACK;
2072 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2074 WININET_Release( lpwh );
2075 return retVal;
2078 /***********************************************************************
2079 * InternetSetStatusCallbackW (WININET.@)
2081 * Sets up a callback function which is called as progress is made
2082 * during an operation.
2084 * RETURNS
2085 * Previous callback or NULL on success
2086 * INTERNET_INVALID_STATUS_CALLBACK on failure
2089 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2090 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2092 INTERNET_STATUS_CALLBACK retVal;
2093 object_header_t *lpwh;
2095 TRACE("%p\n", hInternet);
2097 if (!(lpwh = get_handle_object(hInternet)))
2098 return INTERNET_INVALID_STATUS_CALLBACK;
2100 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2102 WININET_Release( lpwh );
2103 return retVal;
2106 /***********************************************************************
2107 * InternetSetFilePointer (WININET.@)
2109 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2110 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2112 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2114 SetLastError(ERROR_INTERNET_INVALID_OPERATION);
2115 return INVALID_SET_FILE_POINTER;
2118 /***********************************************************************
2119 * InternetWriteFile (WININET.@)
2121 * Write data to an open internet file
2123 * RETURNS
2124 * TRUE on success
2125 * FALSE on failure
2128 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2129 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2131 object_header_t *lpwh;
2132 BOOL res;
2134 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2136 lpwh = get_handle_object( hFile );
2137 if (!lpwh) {
2138 WARN("Invalid handle\n");
2139 SetLastError(ERROR_INVALID_HANDLE);
2140 return FALSE;
2143 if(lpwh->vtbl->WriteFile) {
2144 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2145 }else {
2146 WARN("No Writefile method.\n");
2147 res = ERROR_INVALID_HANDLE;
2150 WININET_Release( lpwh );
2152 if(res != ERROR_SUCCESS)
2153 SetLastError(res);
2154 return res == ERROR_SUCCESS;
2158 /***********************************************************************
2159 * InternetReadFile (WININET.@)
2161 * Read data from an open internet file
2163 * RETURNS
2164 * TRUE on success
2165 * FALSE on failure
2168 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2169 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2171 object_header_t *hdr;
2172 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2174 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2176 hdr = get_handle_object(hFile);
2177 if (!hdr) {
2178 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2179 return FALSE;
2182 if(hdr->vtbl->ReadFile) {
2183 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, 0, 0);
2184 if(res == ERROR_IO_PENDING)
2185 *pdwNumOfBytesRead = 0;
2188 WININET_Release(hdr);
2190 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2191 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2193 SetLastError(res);
2194 return res == ERROR_SUCCESS;
2197 /***********************************************************************
2198 * InternetReadFileExA (WININET.@)
2200 * Read data from an open internet file
2202 * PARAMS
2203 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2204 * lpBuffersOut [I/O] Buffer.
2205 * dwFlags [I] Flags. See notes.
2206 * dwContext [I] Context for callbacks.
2208 * RETURNS
2209 * TRUE on success
2210 * FALSE on failure
2212 * NOTES
2213 * The parameter dwFlags include zero or more of the following flags:
2214 *|IRF_ASYNC - Makes the call asynchronous.
2215 *|IRF_SYNC - Makes the call synchronous.
2216 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2217 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2219 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2221 * SEE
2222 * InternetOpenUrlA(), HttpOpenRequestA()
2224 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2225 DWORD dwFlags, DWORD_PTR dwContext)
2227 object_header_t *hdr;
2228 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2230 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2232 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2233 SetLastError(ERROR_INVALID_PARAMETER);
2234 return FALSE;
2237 hdr = get_handle_object(hFile);
2238 if (!hdr) {
2239 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2240 return FALSE;
2243 if(hdr->vtbl->ReadFile)
2244 res = hdr->vtbl->ReadFile(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2245 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2247 WININET_Release(hdr);
2249 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2250 res, lpBuffersOut->dwBufferLength);
2252 if(res != ERROR_SUCCESS)
2253 SetLastError(res);
2254 return res == ERROR_SUCCESS;
2257 /***********************************************************************
2258 * InternetReadFileExW (WININET.@)
2259 * SEE
2260 * InternetReadFileExA()
2262 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2263 DWORD dwFlags, DWORD_PTR dwContext)
2265 object_header_t *hdr;
2266 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2268 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2270 if (!lpBuffer || lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2271 SetLastError(ERROR_INVALID_PARAMETER);
2272 return FALSE;
2275 hdr = get_handle_object(hFile);
2276 if (!hdr) {
2277 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2278 return FALSE;
2281 if(hdr->vtbl->ReadFile)
2282 res = hdr->vtbl->ReadFile(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2283 dwFlags, dwContext);
2285 WININET_Release(hdr);
2287 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2288 res, lpBuffer->dwBufferLength);
2290 if(res != ERROR_SUCCESS)
2291 SetLastError(res);
2292 return res == ERROR_SUCCESS;
2295 static IP_ADAPTER_ADDRESSES *get_adapters(void)
2297 ULONG err, size = 1024, flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
2298 GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME;
2299 IP_ADAPTER_ADDRESSES *tmp, *ret;
2301 if (!(ret = heap_alloc( size ))) return NULL;
2302 err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
2303 while (err == ERROR_BUFFER_OVERFLOW)
2305 if (!(tmp = heap_realloc( ret, size ))) break;
2306 ret = tmp;
2307 err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
2309 if (err == ERROR_SUCCESS) return ret;
2310 heap_free( ret );
2311 return NULL;
2314 static WCHAR *detect_proxy_autoconfig_url_dhcp(void)
2316 IP_ADAPTER_ADDRESSES *adapters, *ptr;
2317 DHCPCAPI_PARAMS_ARRAY send_params, recv_params;
2318 DHCPCAPI_PARAMS param;
2319 WCHAR name[MAX_ADAPTER_NAME_LENGTH + 1], *ret = NULL;
2320 DWORD err, size;
2321 BYTE *tmp, *buf = NULL;
2323 if (!(adapters = get_adapters())) return NULL;
2325 memset( &send_params, 0, sizeof(send_params) );
2326 memset( &param, 0, sizeof(param) );
2327 param.OptionId = OPTION_MSFT_IE_PROXY;
2328 recv_params.nParams = 1;
2329 recv_params.Params = &param;
2331 for (ptr = adapters; ptr; ptr = ptr->Next)
2333 MultiByteToWideChar( CP_ACP, 0, ptr->AdapterName, -1, name, ARRAY_SIZE(name) );
2334 TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name), ptr->IfType, ptr->Dhcpv4Enabled );
2336 if (ptr->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2337 /* FIXME: also skip adapters where DHCP is disabled */
2339 size = 256;
2340 if (!(buf = heap_alloc( size ))) goto done;
2341 err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
2342 buf, &size, NULL );
2343 while (err == ERROR_MORE_DATA)
2345 if (!(tmp = heap_realloc( buf, size ))) goto done;
2346 buf = tmp;
2347 err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
2348 buf, &size, NULL );
2350 if (err == ERROR_SUCCESS && param.nBytesData)
2352 int len = MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, NULL, 0 );
2353 if ((ret = heap_alloc( (len + 1) * sizeof(WCHAR) )))
2355 MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, ret, len );
2356 ret[len] = 0;
2358 TRACE("returning %s\n", debugstr_w(ret));
2359 break;
2363 done:
2364 heap_free( buf );
2365 heap_free( adapters );
2366 return ret;
2369 static char *get_computer_name( COMPUTER_NAME_FORMAT format )
2371 char *ret;
2372 DWORD size = 0;
2374 GetComputerNameExA( format, NULL, &size );
2375 if (GetLastError() != ERROR_MORE_DATA) return NULL;
2376 if (!(ret = heap_alloc( size ))) return NULL;
2377 if (!GetComputerNameExA( format, ret, &size ))
2379 heap_free( ret );
2380 return NULL;
2382 return ret;
2385 static BOOL is_domain_suffix( const char *domain, const char *suffix )
2387 int len_domain = strlen( domain ), len_suffix = strlen( suffix );
2389 if (len_suffix > len_domain) return FALSE;
2390 if (!stricmp( domain + len_domain - len_suffix, suffix )) return TRUE;
2391 return FALSE;
2394 static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len )
2396 return getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 );
2399 static WCHAR *build_wpad_url( const char *hostname, const struct addrinfo *ai )
2401 char name[NI_MAXHOST];
2402 WCHAR *ret, *p;
2403 int len;
2405 while (ai && ai->ai_family != AF_INET && ai->ai_family != AF_INET6) ai = ai->ai_next;
2406 if (!ai) return NULL;
2408 if (!reverse_lookup( ai, name, sizeof(name) )) hostname = name;
2410 len = lstrlenW( L"http://" ) + strlen( hostname ) + lstrlenW( L"/wpad.dat" );
2411 if (!(ret = p = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
2412 lstrcpyW( p, L"http://" );
2413 p += lstrlenW( L"http://" );
2414 while (*hostname) { *p++ = *hostname++; }
2415 lstrcpyW( p, L"/wpad.dat" );
2416 return ret;
2419 static WCHAR *detect_proxy_autoconfig_url_dns(void)
2421 char *fqdn, *domain, *p;
2422 WCHAR *ret;
2424 if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return NULL;
2425 if (!(domain = get_computer_name( ComputerNamePhysicalDnsDomain )))
2427 heap_free( fqdn );
2428 return NULL;
2430 p = fqdn;
2431 while ((p = strchr( p, '.' )) && is_domain_suffix( p + 1, domain ))
2433 char *name;
2434 struct addrinfo *ai, hints;
2435 int res;
2437 if (!(name = heap_alloc( sizeof("wpad") + strlen(p) )))
2439 heap_free( fqdn );
2440 heap_free( domain );
2441 return NULL;
2443 strcpy( name, "wpad" );
2444 strcat( name, p );
2445 memset( &hints, 0, sizeof(hints) );
2446 hints.ai_flags = AI_ALL | AI_DNS_ONLY;
2447 hints.ai_family = AF_UNSPEC;
2448 res = getaddrinfo( name, NULL, &hints, &ai );
2449 if (!res)
2451 ret = build_wpad_url( name, ai );
2452 freeaddrinfo( ai );
2453 if (ret)
2455 TRACE("returning %s\n", debugstr_w(ret));
2456 heap_free( name );
2457 break;
2460 heap_free( name );
2461 p++;
2463 heap_free( domain );
2464 heap_free( fqdn );
2465 return ret;
2468 static WCHAR *get_proxy_autoconfig_url(void)
2470 WCHAR *ret = detect_proxy_autoconfig_url_dhcp();
2471 if (!ret) ret = detect_proxy_autoconfig_url_dns();
2472 return ret;
2475 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2477 /* FIXME: This function currently handles more options than it should. Options requiring
2478 * proper handles should be moved to proper functions */
2479 switch(option) {
2480 case INTERNET_OPTION_HTTP_VERSION:
2481 if (*size < sizeof(HTTP_VERSION_INFO))
2482 return ERROR_INSUFFICIENT_BUFFER;
2485 * Presently hardcoded to 1.1
2487 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2488 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2489 *size = sizeof(HTTP_VERSION_INFO);
2491 return ERROR_SUCCESS;
2493 case INTERNET_OPTION_CONNECTED_STATE:
2494 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2496 if (*size < sizeof(ULONG))
2497 return ERROR_INSUFFICIENT_BUFFER;
2499 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2500 *size = sizeof(ULONG);
2502 return ERROR_SUCCESS;
2504 case INTERNET_OPTION_PROXY: {
2505 appinfo_t ai;
2506 BOOL ret;
2508 TRACE("Getting global proxy info\n");
2509 memset(&ai, 0, sizeof(appinfo_t));
2510 INTERNET_ConfigureProxy(&ai);
2512 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2513 APPINFO_Destroy(&ai.hdr);
2514 return ret;
2517 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2518 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2520 if (*size < sizeof(ULONG))
2521 return ERROR_INSUFFICIENT_BUFFER;
2523 *(ULONG*)buffer = max_conns;
2524 *size = sizeof(ULONG);
2526 return ERROR_SUCCESS;
2528 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2529 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2531 if (*size < sizeof(ULONG))
2532 return ERROR_INSUFFICIENT_BUFFER;
2534 *(ULONG*)buffer = max_1_0_conns;
2535 *size = sizeof(ULONG);
2537 return ERROR_SUCCESS;
2539 case INTERNET_OPTION_SECURITY_FLAGS:
2540 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2541 return ERROR_SUCCESS;
2543 case INTERNET_OPTION_VERSION: {
2544 static const INTERNET_VERSION_INFO info = { 1, 2 };
2546 TRACE("INTERNET_OPTION_VERSION\n");
2548 if (*size < sizeof(INTERNET_VERSION_INFO))
2549 return ERROR_INSUFFICIENT_BUFFER;
2551 memcpy(buffer, &info, sizeof(info));
2552 *size = sizeof(info);
2554 return ERROR_SUCCESS;
2557 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2558 WCHAR *url;
2559 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2560 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2561 DWORD res = ERROR_SUCCESS, i;
2562 proxyinfo_t pi;
2563 LONG ret;
2565 TRACE("Getting global proxy info\n");
2566 if((ret = INTERNET_LoadProxySettings(&pi)))
2567 return ret;
2569 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2571 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2572 FreeProxyInfo(&pi);
2573 return ERROR_INSUFFICIENT_BUFFER;
2576 url = get_proxy_autoconfig_url();
2578 for (i = 0; i < con->dwOptionCount; i++) {
2579 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2580 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2582 switch (optionW->dwOption) {
2583 case INTERNET_PER_CONN_FLAGS:
2584 if(pi.proxyEnabled)
2585 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2586 else
2587 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2588 if (url)
2589 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2590 optionW->Value.dwValue |= PROXY_TYPE_DIRECT|PROXY_TYPE_AUTO_PROXY_URL;
2591 break;
2593 case INTERNET_PER_CONN_PROXY_SERVER:
2594 if (unicode)
2595 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2596 else
2597 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2598 break;
2600 case INTERNET_PER_CONN_PROXY_BYPASS:
2601 if (unicode)
2602 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2603 else
2604 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2605 break;
2607 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2608 if (!url)
2609 optionW->Value.pszValue = NULL;
2610 else if (unicode)
2611 optionW->Value.pszValue = heap_strdupW(url);
2612 else
2613 optionA->Value.pszValue = heap_strdupWtoA(url);
2614 break;
2616 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2617 optionW->Value.dwValue = AUTO_PROXY_FLAG_ALWAYS_DETECT;
2618 break;
2620 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2621 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2622 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2623 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2624 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2625 memset(&optionW->Value, 0, sizeof(optionW->Value));
2626 break;
2628 default:
2629 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2630 res = ERROR_INVALID_PARAMETER;
2631 break;
2634 heap_free(url);
2635 FreeProxyInfo(&pi);
2637 return res;
2639 case INTERNET_OPTION_REQUEST_FLAGS:
2640 case INTERNET_OPTION_USER_AGENT:
2641 *size = 0;
2642 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2643 case INTERNET_OPTION_POLICY:
2644 return ERROR_INVALID_PARAMETER;
2645 case INTERNET_OPTION_CONNECT_TIMEOUT:
2646 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2648 if (*size < sizeof(ULONG))
2649 return ERROR_INSUFFICIENT_BUFFER;
2651 *(ULONG*)buffer = connect_timeout;
2652 *size = sizeof(ULONG);
2654 return ERROR_SUCCESS;
2657 FIXME("Stub for %d\n", option);
2658 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2661 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2663 switch(option) {
2664 case INTERNET_OPTION_CONTEXT_VALUE:
2665 if (!size)
2666 return ERROR_INVALID_PARAMETER;
2668 if (*size < sizeof(DWORD_PTR)) {
2669 *size = sizeof(DWORD_PTR);
2670 return ERROR_INSUFFICIENT_BUFFER;
2672 if (!buffer)
2673 return ERROR_INVALID_PARAMETER;
2675 *(DWORD_PTR *)buffer = hdr->dwContext;
2676 *size = sizeof(DWORD_PTR);
2677 return ERROR_SUCCESS;
2679 case INTERNET_OPTION_REQUEST_FLAGS:
2680 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2681 *size = sizeof(DWORD);
2682 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2684 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2685 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2686 WARN("Called on global option %u\n", option);
2687 return ERROR_INTERNET_INVALID_OPERATION;
2690 /* FIXME: we shouldn't call it here */
2691 return query_global_option(option, buffer, size, unicode);
2694 /***********************************************************************
2695 * InternetQueryOptionW (WININET.@)
2697 * Queries an options on the specified handle
2699 * RETURNS
2700 * TRUE on success
2701 * FALSE on failure
2704 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2705 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2707 object_header_t *hdr;
2708 DWORD res = ERROR_INVALID_HANDLE;
2710 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2712 if(hInternet) {
2713 hdr = get_handle_object(hInternet);
2714 if (hdr) {
2715 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2716 WININET_Release(hdr);
2718 }else {
2719 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2722 if(res != ERROR_SUCCESS)
2723 SetLastError(res);
2724 return res == ERROR_SUCCESS;
2727 /***********************************************************************
2728 * InternetQueryOptionA (WININET.@)
2730 * Queries an options on the specified handle
2732 * RETURNS
2733 * TRUE on success
2734 * FALSE on failure
2737 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2738 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2740 object_header_t *hdr;
2741 DWORD res = ERROR_INVALID_HANDLE;
2743 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2745 if(hInternet) {
2746 hdr = get_handle_object(hInternet);
2747 if (hdr) {
2748 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2749 WININET_Release(hdr);
2751 }else {
2752 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2755 if(res != ERROR_SUCCESS)
2756 SetLastError(res);
2757 return res == ERROR_SUCCESS;
2760 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2762 switch(option) {
2763 case INTERNET_OPTION_SETTINGS_CHANGED:
2764 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2765 collect_connections(COLLECT_CONNECTIONS);
2766 return ERROR_SUCCESS;
2767 case INTERNET_OPTION_CALLBACK:
2768 WARN("Not settable option %u\n", option);
2769 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2770 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2771 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2772 WARN("Called on global option %u\n", option);
2773 return ERROR_INTERNET_INVALID_OPERATION;
2774 case INTERNET_OPTION_REFRESH:
2775 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2778 return ERROR_INTERNET_INVALID_OPTION;
2781 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2783 switch(option) {
2784 case INTERNET_OPTION_CALLBACK:
2785 WARN("Not global option %u\n", option);
2786 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2788 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2789 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2791 if(size != sizeof(max_conns))
2792 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2793 if(!*(ULONG*)buf)
2794 return ERROR_BAD_ARGUMENTS;
2796 max_conns = *(ULONG*)buf;
2797 return ERROR_SUCCESS;
2799 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2800 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2802 if(size != sizeof(max_1_0_conns))
2803 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2804 if(!*(ULONG*)buf)
2805 return ERROR_BAD_ARGUMENTS;
2807 max_1_0_conns = *(ULONG*)buf;
2808 return ERROR_SUCCESS;
2810 case INTERNET_OPTION_CONNECT_TIMEOUT:
2811 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2813 if(size != sizeof(connect_timeout))
2814 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2815 if(!*(ULONG*)buf)
2816 return ERROR_BAD_ARGUMENTS;
2818 connect_timeout = *(ULONG*)buf;
2819 return ERROR_SUCCESS;
2821 case INTERNET_OPTION_SUPPRESS_BEHAVIOR:
2822 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2824 if(size != sizeof(ULONG))
2825 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2827 FIXME("%08x\n", *(ULONG*)buf);
2828 return ERROR_SUCCESS;
2831 return INET_SetOption(NULL, option, buf, size);
2834 /***********************************************************************
2835 * InternetSetOptionW (WININET.@)
2837 * Sets an options on the specified handle
2839 * RETURNS
2840 * TRUE on success
2841 * FALSE on failure
2844 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2845 LPVOID lpBuffer, DWORD dwBufferLength)
2847 object_header_t *lpwhh;
2848 BOOL ret = TRUE;
2849 DWORD res;
2851 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2853 lpwhh = (object_header_t*) get_handle_object( hInternet );
2854 if(lpwhh)
2855 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2856 else
2857 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2859 if(res != ERROR_INTERNET_INVALID_OPTION) {
2860 if(lpwhh)
2861 WININET_Release(lpwhh);
2863 if(res != ERROR_SUCCESS)
2864 SetLastError(res);
2866 return res == ERROR_SUCCESS;
2869 switch (dwOption)
2871 case INTERNET_OPTION_HTTP_VERSION:
2873 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2874 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2876 break;
2877 case INTERNET_OPTION_ERROR_MASK:
2879 if(!lpwhh) {
2880 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2881 return FALSE;
2882 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2883 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2884 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2885 SetLastError(ERROR_INVALID_PARAMETER);
2886 ret = FALSE;
2887 } else if(dwBufferLength != sizeof(ULONG)) {
2888 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2889 ret = FALSE;
2890 } else
2891 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2892 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2894 break;
2895 case INTERNET_OPTION_PROXY:
2897 INTERNET_PROXY_INFOW *info = lpBuffer;
2899 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2901 SetLastError(ERROR_INVALID_PARAMETER);
2902 return FALSE;
2904 if (!hInternet)
2906 EnterCriticalSection( &WININET_cs );
2907 free_global_proxy();
2908 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2909 if (global_proxy)
2911 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2913 global_proxy->proxyEnabled = 1;
2914 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2915 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2917 else
2919 global_proxy->proxyEnabled = 0;
2920 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2923 LeaveCriticalSection( &WININET_cs );
2925 else
2927 /* In general, each type of object should handle
2928 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2929 * get silently dropped.
2931 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2932 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2933 ret = FALSE;
2935 break;
2937 case INTERNET_OPTION_CODEPAGE:
2939 ULONG codepage = *(ULONG *)lpBuffer;
2940 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2942 break;
2943 case INTERNET_OPTION_REQUEST_PRIORITY:
2945 ULONG priority = *(ULONG *)lpBuffer;
2946 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2948 break;
2949 case INTERNET_OPTION_CONNECT_TIMEOUT:
2951 ULONG connecttimeout = *(ULONG *)lpBuffer;
2952 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2954 break;
2955 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2957 ULONG receivetimeout = *(ULONG *)lpBuffer;
2958 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2960 break;
2961 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2962 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2963 break;
2964 case INTERNET_OPTION_END_BROWSER_SESSION:
2965 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2966 free_cookie();
2967 free_authorization_cache();
2968 break;
2969 case INTERNET_OPTION_CONNECTED_STATE:
2970 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2971 break;
2972 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2973 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2974 break;
2975 case INTERNET_OPTION_IGNORE_OFFLINE:
2976 FIXME("Option INTERNET_OPTION_IGNORE_OFFLINE: STUB\n");
2977 break;
2978 case INTERNET_OPTION_SEND_TIMEOUT:
2979 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2980 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2982 ULONG timeout = *(ULONG *)lpBuffer;
2983 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2984 break;
2986 case INTERNET_OPTION_CONNECT_RETRIES:
2988 ULONG retries = *(ULONG *)lpBuffer;
2989 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2990 break;
2992 case INTERNET_OPTION_CONTEXT_VALUE:
2994 if (!lpwhh)
2996 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2997 return FALSE;
2999 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
3001 SetLastError(ERROR_INVALID_PARAMETER);
3002 ret = FALSE;
3004 else
3005 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
3006 break;
3008 case INTERNET_OPTION_SECURITY_FLAGS:
3009 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
3010 break;
3011 case INTERNET_OPTION_DISABLE_AUTODIAL:
3012 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
3013 break;
3014 case INTERNET_OPTION_HTTP_DECODING:
3015 if (!lpwhh)
3017 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3018 return FALSE;
3020 if (!lpBuffer || dwBufferLength != sizeof(BOOL))
3022 SetLastError(ERROR_INVALID_PARAMETER);
3023 ret = FALSE;
3025 else
3026 lpwhh->decoding = *(BOOL *)lpBuffer;
3027 break;
3028 case INTERNET_OPTION_COOKIES_3RD_PARTY:
3029 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
3030 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3031 ret = FALSE;
3032 break;
3033 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
3034 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
3035 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3036 ret = FALSE;
3037 break;
3038 case INTERNET_OPTION_CODEPAGE_PATH:
3039 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
3040 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3041 ret = FALSE;
3042 break;
3043 case INTERNET_OPTION_CODEPAGE_EXTRA:
3044 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
3045 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3046 ret = FALSE;
3047 break;
3048 case INTERNET_OPTION_IDN:
3049 FIXME("INTERNET_OPTION_IDN; STUB\n");
3050 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3051 ret = FALSE;
3052 break;
3053 case INTERNET_OPTION_POLICY:
3054 SetLastError(ERROR_INVALID_PARAMETER);
3055 ret = FALSE;
3056 break;
3057 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3058 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
3059 LONG res;
3060 unsigned int i;
3061 proxyinfo_t pi;
3063 if (INTERNET_LoadProxySettings(&pi)) return FALSE;
3065 for (i = 0; i < con->dwOptionCount; i++) {
3066 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
3068 switch (option->dwOption) {
3069 case INTERNET_PER_CONN_PROXY_SERVER:
3070 heap_free(pi.proxy);
3071 pi.proxy = heap_strdupW(option->Value.pszValue);
3072 break;
3074 case INTERNET_PER_CONN_FLAGS:
3075 if(option->Value.dwValue & PROXY_TYPE_PROXY)
3076 pi.proxyEnabled = 1;
3077 else
3079 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
3080 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
3081 pi.proxyEnabled = 0;
3083 break;
3085 case INTERNET_PER_CONN_PROXY_BYPASS:
3086 heap_free(pi.proxyBypass);
3087 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
3088 break;
3090 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3091 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3092 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3093 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3094 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3095 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3096 FIXME("Unhandled dwOption %d\n", option->dwOption);
3097 break;
3099 default:
3100 FIXME("Unknown dwOption %d\n", option->dwOption);
3101 SetLastError(ERROR_INVALID_PARAMETER);
3102 break;
3106 if ((res = INTERNET_SaveProxySettings(&pi)))
3107 SetLastError(res);
3109 FreeProxyInfo(&pi);
3111 ret = (res == ERROR_SUCCESS);
3112 break;
3114 default:
3115 FIXME("Option %d STUB\n",dwOption);
3116 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3117 ret = FALSE;
3118 break;
3121 if(lpwhh)
3122 WININET_Release( lpwhh );
3124 return ret;
3128 /***********************************************************************
3129 * InternetSetOptionA (WININET.@)
3131 * Sets an options on the specified handle.
3133 * RETURNS
3134 * TRUE on success
3135 * FALSE on failure
3138 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
3139 LPVOID lpBuffer, DWORD dwBufferLength)
3141 LPVOID wbuffer;
3142 DWORD wlen;
3143 BOOL r;
3145 switch( dwOption )
3147 case INTERNET_OPTION_PROXY:
3149 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
3150 LPINTERNET_PROXY_INFOW piw;
3151 DWORD proxlen, prbylen;
3152 LPWSTR prox, prby;
3154 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
3155 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
3156 wlen = sizeof(*piw) + proxlen + prbylen;
3157 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
3158 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
3159 piw->dwAccessType = pi->dwAccessType;
3160 prox = (LPWSTR) &piw[1];
3161 prby = &prox[proxlen+1];
3162 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
3163 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
3164 piw->lpszProxy = prox;
3165 piw->lpszProxyBypass = prby;
3167 break;
3168 case INTERNET_OPTION_USER_AGENT:
3169 case INTERNET_OPTION_USERNAME:
3170 case INTERNET_OPTION_PASSWORD:
3171 case INTERNET_OPTION_PROXY_USERNAME:
3172 case INTERNET_OPTION_PROXY_PASSWORD:
3173 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3174 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3175 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3176 break;
3177 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3178 unsigned int i;
3179 INTERNET_PER_CONN_OPTION_LISTW *listW;
3180 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3181 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3182 wbuffer = heap_alloc(wlen);
3183 listW = wbuffer;
3185 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3186 if (listA->pszConnection)
3188 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3189 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3190 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3192 else
3193 listW->pszConnection = NULL;
3194 listW->dwOptionCount = listA->dwOptionCount;
3195 listW->dwOptionError = listA->dwOptionError;
3196 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3198 for (i = 0; i < listA->dwOptionCount; ++i) {
3199 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3200 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3202 optW->dwOption = optA->dwOption;
3204 switch (optA->dwOption) {
3205 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3206 case INTERNET_PER_CONN_PROXY_BYPASS:
3207 case INTERNET_PER_CONN_PROXY_SERVER:
3208 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3209 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3210 if (optA->Value.pszValue)
3212 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3213 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3214 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3216 else
3217 optW->Value.pszValue = NULL;
3218 break;
3219 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3220 case INTERNET_PER_CONN_FLAGS:
3221 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3222 optW->Value.dwValue = optA->Value.dwValue;
3223 break;
3224 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3225 optW->Value.ftValue = optA->Value.ftValue;
3226 break;
3227 default:
3228 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3229 optW->Value.dwValue = optA->Value.dwValue;
3230 break;
3234 break;
3235 default:
3236 wbuffer = lpBuffer;
3237 wlen = dwBufferLength;
3240 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3242 if( lpBuffer != wbuffer )
3244 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3246 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3247 unsigned int i;
3248 for (i = 0; i < list->dwOptionCount; ++i) {
3249 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3250 switch (opt->dwOption) {
3251 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3252 case INTERNET_PER_CONN_PROXY_BYPASS:
3253 case INTERNET_PER_CONN_PROXY_SERVER:
3254 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3255 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3256 heap_free( opt->Value.pszValue );
3257 break;
3258 default:
3259 break;
3262 heap_free( list->pOptions );
3264 heap_free( wbuffer );
3267 return r;
3271 /***********************************************************************
3272 * InternetSetOptionExA (WININET.@)
3274 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3275 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3277 FIXME("Flags %08x ignored\n", dwFlags);
3278 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3281 /***********************************************************************
3282 * InternetSetOptionExW (WININET.@)
3284 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3285 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3287 FIXME("Flags %08x ignored\n", dwFlags);
3288 if( dwFlags & ~ISO_VALID_FLAGS )
3290 SetLastError( ERROR_INVALID_PARAMETER );
3291 return FALSE;
3293 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3296 static const WCHAR WININET_wkday[7][4] =
3297 { L"Sun", L"Mon", L"Tue", L"Wed",
3298 L"Thu", L"Fri", L"Sat"};
3299 static const WCHAR WININET_month[12][4] =
3300 { L"Jan", L"Feb", L"Mar", L"Apr",
3301 L"May", L"Jun", L"Jul", L"Aug",
3302 L"Sep", L"Oct", L"Nov", L"Dec"};
3304 /***********************************************************************
3305 * InternetTimeFromSystemTimeA (WININET.@)
3307 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3309 BOOL ret;
3310 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3312 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3314 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3316 SetLastError(ERROR_INVALID_PARAMETER);
3317 return FALSE;
3320 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3322 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3323 return FALSE;
3326 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3327 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3329 return ret;
3332 /***********************************************************************
3333 * InternetTimeFromSystemTimeW (WININET.@)
3335 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3337 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3339 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3341 SetLastError(ERROR_INVALID_PARAMETER);
3342 return FALSE;
3345 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3347 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3348 return FALSE;
3351 swprintf( string, size, L"%s, %02d %s %4d %02d:%02d:%02d GMT",
3352 WININET_wkday[time->wDayOfWeek],
3353 time->wDay,
3354 WININET_month[time->wMonth - 1],
3355 time->wYear,
3356 time->wHour,
3357 time->wMinute,
3358 time->wSecond );
3360 return TRUE;
3363 /***********************************************************************
3364 * InternetTimeToSystemTimeA (WININET.@)
3366 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3368 BOOL ret = FALSE;
3369 WCHAR *stringW;
3371 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3373 stringW = heap_strdupAtoW(string);
3374 if (stringW)
3376 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3377 heap_free( stringW );
3379 return ret;
3382 /***********************************************************************
3383 * InternetTimeToSystemTimeW (WININET.@)
3385 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3387 unsigned int i;
3388 const WCHAR *s = string;
3389 WCHAR *end;
3391 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3393 if (!string || !time) return FALSE;
3395 /* Windows does this too */
3396 GetSystemTime( time );
3398 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3399 * a SYSTEMTIME structure.
3402 while (*s && !iswalpha( *s )) s++;
3403 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3404 time->wDayOfWeek = 7;
3406 for (i = 0; i < 7; i++)
3408 if (!wcsnicmp( WININET_wkday[i], s, 3 ))
3410 time->wDayOfWeek = i;
3411 break;
3415 if (time->wDayOfWeek > 6) return TRUE;
3416 while (*s && !iswdigit( *s )) s++;
3417 time->wDay = wcstol( s, &end, 10 );
3418 s = end;
3420 while (*s && !iswalpha( *s )) s++;
3421 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3422 time->wMonth = 0;
3424 for (i = 0; i < 12; i++)
3426 if (!wcsnicmp( WININET_month[i], s, 3 ))
3428 time->wMonth = i + 1;
3429 break;
3432 if (time->wMonth == 0) return TRUE;
3434 while (*s && !iswdigit( *s )) s++;
3435 if (*s == '\0') return TRUE;
3436 time->wYear = wcstol( s, &end, 10 );
3437 s = end;
3439 while (*s && !iswdigit( *s )) s++;
3440 if (*s == '\0') return TRUE;
3441 time->wHour = wcstol( s, &end, 10 );
3442 s = end;
3444 while (*s && !iswdigit( *s )) s++;
3445 if (*s == '\0') return TRUE;
3446 time->wMinute = wcstol( s, &end, 10 );
3447 s = end;
3449 while (*s && !iswdigit( *s )) s++;
3450 if (*s == '\0') return TRUE;
3451 time->wSecond = wcstol( s, &end, 10 );
3452 s = end;
3454 time->wMilliseconds = 0;
3455 return TRUE;
3458 /***********************************************************************
3459 * InternetCheckConnectionW (WININET.@)
3461 * Pings a requested host to check internet connection
3463 * RETURNS
3464 * TRUE on success and FALSE on failure. If a failure then
3465 * ERROR_NOT_CONNECTED is placed into GetLastError
3468 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3471 * this is a kludge which runs the resident ping program and reads the output.
3473 * Anyone have a better idea?
3476 BOOL rc = FALSE;
3477 static const CHAR ping[] = "ping -c 1 ";
3478 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3479 WCHAR *host;
3480 DWORD len, host_len;
3481 INTERNET_PORT port;
3482 int status = -1;
3484 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl), dwFlags, dwReserved);
3487 * Crack or set the Address
3489 if (lpszUrl == NULL)
3492 * According to the doc we are supposed to use the ip for the next
3493 * server in the WnInet internal server database. I have
3494 * no idea what that is or how to get it.
3496 * So someone needs to implement this.
3498 FIXME("Unimplemented with URL of NULL\n");
3499 return TRUE;
3501 else
3503 URL_COMPONENTSW components = {sizeof(components)};
3505 components.dwHostNameLength = 1;
3507 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3508 goto End;
3510 host = components.lpszHostName;
3511 host_len = components.dwHostNameLength;
3512 port = components.nPort;
3513 TRACE("host name: %s port: %d\n",debugstr_wn(host, host_len), port);
3516 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3518 struct sockaddr_storage saddr;
3519 int sa_len = sizeof(saddr);
3520 WCHAR *host_z;
3521 int fd;
3522 BOOL b;
3524 host_z = heap_strndupW(host, host_len);
3525 if (!host_z)
3526 return FALSE;
3528 b = GetAddress(host_z, port, (struct sockaddr *)&saddr, &sa_len, NULL);
3529 heap_free(host_z);
3530 if(!b)
3531 goto End;
3532 init_winsock();
3533 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3534 if (fd != -1)
3536 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3537 rc = TRUE;
3538 closesocket(fd);
3541 else
3544 * Build our ping command
3546 char *command;
3548 len = WideCharToMultiByte(CP_UNIXCP, 0, host, host_len, NULL, 0, NULL, NULL);
3549 command = heap_alloc(strlen(ping)+len+strlen(redirect)+1);
3550 strcpy(command, ping);
3551 WideCharToMultiByte(CP_UNIXCP, 0, host, host_len, command+sizeof(ping)-1, len, NULL, NULL);
3552 strcpy(command+sizeof(ping)-1+len, redirect);
3554 TRACE("Ping command is : %s\n",command);
3556 status = system(command);
3557 heap_free( command );
3559 TRACE("Ping returned a code of %i\n",status);
3561 /* Ping return code of 0 indicates success */
3562 if (status == 0)
3563 rc = TRUE;
3566 End:
3567 if (rc == FALSE)
3568 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3570 return rc;
3574 /***********************************************************************
3575 * InternetCheckConnectionA (WININET.@)
3577 * Pings a requested host to check internet connection
3579 * RETURNS
3580 * TRUE on success and FALSE on failure. If a failure then
3581 * ERROR_NOT_CONNECTED is placed into GetLastError
3584 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3586 WCHAR *url = NULL;
3587 BOOL rc;
3589 if(lpszUrl) {
3590 url = heap_strdupAtoW(lpszUrl);
3591 if(!url)
3592 return FALSE;
3595 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3597 heap_free(url);
3598 return rc;
3602 /**********************************************************
3603 * INTERNET_InternetOpenUrlW (internal)
3605 * Opens an URL
3607 * RETURNS
3608 * handle of connection or NULL on failure
3610 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3611 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3613 URL_COMPONENTSW urlComponents = { sizeof(urlComponents) };
3614 WCHAR *host, *user = NULL, *pass = NULL, *path;
3615 HINTERNET client = NULL, client1 = NULL;
3616 DWORD res;
3618 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3619 dwHeadersLength, dwFlags, dwContext);
3621 urlComponents.dwHostNameLength = 1;
3622 urlComponents.dwUserNameLength = 1;
3623 urlComponents.dwPasswordLength = 1;
3624 urlComponents.dwUrlPathLength = 1;
3625 urlComponents.dwExtraInfoLength = 1;
3626 if(!InternetCrackUrlW(lpszUrl, lstrlenW(lpszUrl), 0, &urlComponents))
3627 return NULL;
3629 if ((urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS) &&
3630 urlComponents.dwExtraInfoLength)
3632 assert(urlComponents.lpszUrlPath + urlComponents.dwUrlPathLength == urlComponents.lpszExtraInfo);
3633 urlComponents.dwUrlPathLength += urlComponents.dwExtraInfoLength;
3636 host = heap_strndupW(urlComponents.lpszHostName, urlComponents.dwHostNameLength);
3637 path = heap_strndupW(urlComponents.lpszUrlPath, urlComponents.dwUrlPathLength);
3638 if(urlComponents.dwUserNameLength)
3639 user = heap_strndupW(urlComponents.lpszUserName, urlComponents.dwUserNameLength);
3640 if(urlComponents.dwPasswordLength)
3641 pass = heap_strndupW(urlComponents.lpszPassword, urlComponents.dwPasswordLength);
3643 switch(urlComponents.nScheme) {
3644 case INTERNET_SCHEME_FTP:
3645 client = FTP_Connect(hIC, host, urlComponents.nPort,
3646 user, pass, dwFlags, dwContext, INET_OPENURL);
3647 if(client == NULL)
3648 break;
3649 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3650 if(client1 == NULL) {
3651 InternetCloseHandle(client);
3652 break;
3654 break;
3656 case INTERNET_SCHEME_HTTP:
3657 case INTERNET_SCHEME_HTTPS: {
3658 LPCWSTR accept[2] = { L"*/*", NULL };
3660 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3662 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3663 res = HTTP_Connect(hIC, host, urlComponents.nPort,
3664 user, pass, dwFlags, dwContext, INET_OPENURL, &client);
3665 if(res != ERROR_SUCCESS) {
3666 INTERNET_SetLastError(res);
3667 break;
3670 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3671 if(client1 == NULL) {
3672 InternetCloseHandle(client);
3673 break;
3675 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3676 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3677 GetLastError() != ERROR_IO_PENDING) {
3678 InternetCloseHandle(client1);
3679 client1 = NULL;
3680 break;
3683 case INTERNET_SCHEME_GOPHER:
3684 /* gopher doesn't seem to be implemented in wine, but it's supposed
3685 * to be supported by InternetOpenUrlA. */
3686 default:
3687 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3688 break;
3691 TRACE(" %p <--\n", client1);
3693 heap_free(host);
3694 heap_free(path);
3695 heap_free(user);
3696 heap_free(pass);
3697 return client1;
3700 /**********************************************************
3701 * InternetOpenUrlW (WININET.@)
3703 * Opens an URL
3705 * RETURNS
3706 * handle of connection or NULL on failure
3708 typedef struct {
3709 task_header_t hdr;
3710 WCHAR *url;
3711 WCHAR *headers;
3712 DWORD headers_len;
3713 DWORD flags;
3714 DWORD_PTR context;
3715 } open_url_task_t;
3717 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3719 open_url_task_t *task = (open_url_task_t*)hdr;
3721 TRACE("%p\n", task->hdr.hdr);
3723 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3724 task->headers_len, task->flags, task->context);
3725 heap_free(task->url);
3726 heap_free(task->headers);
3729 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3730 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3732 HINTERNET ret = NULL;
3733 appinfo_t *hIC = NULL;
3735 if (TRACE_ON(wininet)) {
3736 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3737 dwHeadersLength, dwFlags, dwContext);
3738 TRACE(" flags :");
3739 dump_INTERNET_FLAGS(dwFlags);
3742 if (!lpszUrl)
3744 SetLastError(ERROR_INVALID_PARAMETER);
3745 goto lend;
3748 hIC = (appinfo_t*)get_handle_object( hInternet );
3749 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3750 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3751 goto lend;
3754 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3755 open_url_task_t *task;
3757 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3758 task->url = heap_strdupW(lpszUrl);
3759 task->headers = heap_strdupW(lpszHeaders);
3760 task->headers_len = dwHeadersLength;
3761 task->flags = dwFlags;
3762 task->context = dwContext;
3764 INTERNET_AsyncCall(&task->hdr);
3765 SetLastError(ERROR_IO_PENDING);
3766 } else {
3767 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3770 lend:
3771 if( hIC )
3772 WININET_Release( &hIC->hdr );
3773 TRACE(" %p <--\n", ret);
3775 return ret;
3778 /**********************************************************
3779 * InternetOpenUrlA (WININET.@)
3781 * Opens an URL
3783 * RETURNS
3784 * handle of connection or NULL on failure
3786 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3787 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3789 HINTERNET rc = NULL;
3790 LPWSTR szUrl = NULL;
3791 WCHAR *headers = NULL;
3793 TRACE("\n");
3795 if(lpszUrl) {
3796 szUrl = heap_strdupAtoW(lpszUrl);
3797 if(!szUrl)
3798 return NULL;
3801 if(lpszHeaders) {
3802 headers = heap_strndupAtoW(lpszHeaders, dwHeadersLength, &dwHeadersLength);
3803 if(!headers) {
3804 heap_free(szUrl);
3805 return NULL;
3809 rc = InternetOpenUrlW(hInternet, szUrl, headers, dwHeadersLength, dwFlags, dwContext);
3811 heap_free(szUrl);
3812 heap_free(headers);
3813 return rc;
3817 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3819 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3821 if (lpwite)
3823 lpwite->dwError = 0;
3824 lpwite->response[0] = '\0';
3827 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3829 heap_free(lpwite);
3830 return NULL;
3832 return lpwite;
3836 /***********************************************************************
3837 * INTERNET_SetLastError (internal)
3839 * Set last thread specific error
3841 * RETURNS
3844 void INTERNET_SetLastError(DWORD dwError)
3846 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3848 if (!lpwite)
3849 lpwite = INTERNET_AllocThreadError();
3851 SetLastError(dwError);
3852 if(lpwite)
3853 lpwite->dwError = dwError;
3857 /***********************************************************************
3858 * INTERNET_GetLastError (internal)
3860 * Get last thread specific error
3862 * RETURNS
3865 DWORD INTERNET_GetLastError(void)
3867 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3868 if (!lpwite) return 0;
3869 /* TlsGetValue clears last error, so set it again here */
3870 SetLastError(lpwite->dwError);
3871 return lpwite->dwError;
3875 /***********************************************************************
3876 * INTERNET_WorkerThreadFunc (internal)
3878 * Worker thread execution function
3880 * RETURNS
3883 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3885 task_header_t *task = lpvParam;
3887 TRACE("\n");
3889 task->proc(task);
3890 WININET_Release(task->hdr);
3891 heap_free(task);
3893 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3895 heap_free(TlsGetValue(g_dwTlsErrIndex));
3896 TlsSetValue(g_dwTlsErrIndex, NULL);
3898 return TRUE;
3901 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3903 task_header_t *task;
3905 task = heap_alloc(size);
3906 if(!task)
3907 return NULL;
3909 task->hdr = WININET_AddRef(hdr);
3910 task->proc = proc;
3911 return task;
3914 /***********************************************************************
3915 * INTERNET_AsyncCall (internal)
3917 * Retrieves work request from queue
3919 * RETURNS
3922 DWORD INTERNET_AsyncCall(task_header_t *task)
3924 BOOL bSuccess;
3926 TRACE("\n");
3928 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3929 if (!bSuccess)
3931 heap_free(task);
3932 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3934 return ERROR_SUCCESS;
3938 /***********************************************************************
3939 * INTERNET_GetResponseBuffer (internal)
3941 * RETURNS
3944 LPSTR INTERNET_GetResponseBuffer(void)
3946 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3947 if (!lpwite)
3948 lpwite = INTERNET_AllocThreadError();
3949 TRACE("\n");
3950 return lpwite->response;
3953 /**********************************************************
3954 * InternetQueryDataAvailable (WININET.@)
3956 * Determines how much data is available to be read.
3958 * RETURNS
3959 * TRUE on success, FALSE if an error occurred. If
3960 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3961 * no data is presently available, FALSE is returned with
3962 * the last error ERROR_IO_PENDING; a callback with status
3963 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3964 * data is available.
3966 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3967 LPDWORD lpdwNumberOfBytesAvailable,
3968 DWORD dwFlags, DWORD_PTR dwContext)
3970 object_header_t *hdr;
3971 DWORD res;
3973 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3975 hdr = get_handle_object( hFile );
3976 if (!hdr) {
3977 SetLastError(ERROR_INVALID_HANDLE);
3978 return FALSE;
3981 if(hdr->vtbl->QueryDataAvailable) {
3982 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3983 }else {
3984 WARN("wrong handle\n");
3985 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3988 WININET_Release(hdr);
3990 if(res != ERROR_SUCCESS)
3991 SetLastError(res);
3992 return res == ERROR_SUCCESS;
3995 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
3997 req_file_t *req_file;
3999 req_file = heap_alloc_zero(sizeof(*req_file));
4000 if(!req_file)
4001 return ERROR_NOT_ENOUGH_MEMORY;
4003 req_file->ref = 1;
4005 req_file->file_name = heap_strdupW(file_name);
4006 if(!req_file->file_name) {
4007 heap_free(req_file);
4008 return ERROR_NOT_ENOUGH_MEMORY;
4011 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
4012 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
4013 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
4014 req_file_release(req_file);
4015 return GetLastError();
4018 *ret = req_file;
4019 return ERROR_SUCCESS;
4022 void req_file_release(req_file_t *req_file)
4024 if(InterlockedDecrement(&req_file->ref))
4025 return;
4027 if(!req_file->is_committed)
4028 DeleteFileW(req_file->file_name);
4029 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
4030 CloseHandle(req_file->file_handle);
4031 heap_free(req_file->file_name);
4032 heap_free(req_file->url);
4033 heap_free(req_file);
4036 /***********************************************************************
4037 * InternetLockRequestFile (WININET.@)
4039 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
4041 req_file_t *req_file = NULL;
4042 object_header_t *hdr;
4043 DWORD res;
4045 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
4047 hdr = get_handle_object(hInternet);
4048 if (!hdr) {
4049 SetLastError(ERROR_INVALID_HANDLE);
4050 return FALSE;
4053 if(hdr->vtbl->LockRequestFile) {
4054 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
4055 }else {
4056 WARN("wrong handle\n");
4057 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4060 WININET_Release(hdr);
4062 *lphLockReqHandle = req_file;
4063 if(res != ERROR_SUCCESS)
4064 SetLastError(res);
4065 return res == ERROR_SUCCESS;
4068 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
4070 TRACE("(%p)\n", hLockHandle);
4072 req_file_release(hLockHandle);
4073 return TRUE;
4077 /***********************************************************************
4078 * InternetAutodial (WININET.@)
4080 * On windows this function is supposed to dial the default internet
4081 * connection. We don't want to have Wine dial out to the internet so
4082 * we return TRUE by default. It might be nice to check if we are connected.
4084 * RETURNS
4085 * TRUE on success
4086 * FALSE on failure
4089 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4091 FIXME("STUB\n");
4093 /* Tell that we are connected to the internet. */
4094 return TRUE;
4097 /***********************************************************************
4098 * InternetAutodialHangup (WININET.@)
4100 * Hangs up a connection made with InternetAutodial
4102 * PARAM
4103 * dwReserved
4104 * RETURNS
4105 * TRUE on success
4106 * FALSE on failure
4109 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4111 FIXME("STUB\n");
4113 /* we didn't dial, we don't disconnect */
4114 return TRUE;
4117 /***********************************************************************
4118 * InternetCombineUrlA (WININET.@)
4120 * Combine a base URL with a relative URL
4122 * RETURNS
4123 * TRUE on success
4124 * FALSE on failure
4128 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4129 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4130 DWORD dwFlags)
4132 HRESULT hr=S_OK;
4134 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4136 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4137 dwFlags ^= ICU_NO_ENCODE;
4138 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4140 return (hr==S_OK);
4143 /***********************************************************************
4144 * InternetCombineUrlW (WININET.@)
4146 * Combine a base URL with a relative URL
4148 * RETURNS
4149 * TRUE on success
4150 * FALSE on failure
4154 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4155 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4156 DWORD dwFlags)
4158 HRESULT hr=S_OK;
4160 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4162 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4163 dwFlags ^= ICU_NO_ENCODE;
4164 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4166 return (hr==S_OK);
4169 /* max port num is 65535 => 5 digits */
4170 #define MAX_WORD_DIGITS 5
4172 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4173 (url)->dw##component##Length : lstrlenW((url)->lpsz##component))
4174 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4175 (url)->dw##component##Length : strlen((url)->lpsz##component))
4177 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4179 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4180 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4181 return TRUE;
4182 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4183 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4184 return TRUE;
4185 if ((nScheme == INTERNET_SCHEME_FTP) &&
4186 (nPort == INTERNET_DEFAULT_FTP_PORT))
4187 return TRUE;
4188 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4189 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4190 return TRUE;
4192 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4193 return TRUE;
4195 return FALSE;
4198 /* opaque urls do not fit into the standard url hierarchy and don't have
4199 * two following slashes */
4200 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4202 return (nScheme != INTERNET_SCHEME_FTP) &&
4203 (nScheme != INTERNET_SCHEME_GOPHER) &&
4204 (nScheme != INTERNET_SCHEME_HTTP) &&
4205 (nScheme != INTERNET_SCHEME_HTTPS) &&
4206 (nScheme != INTERNET_SCHEME_FILE);
4209 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4211 int index;
4212 if (scheme < INTERNET_SCHEME_FIRST)
4213 return NULL;
4214 index = scheme - INTERNET_SCHEME_FIRST;
4215 if (index >= ARRAY_SIZE(url_schemes))
4216 return NULL;
4217 return url_schemes[index];
4220 /* we can calculate using ansi strings because we're just
4221 * calculating string length, not size
4223 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4224 LPDWORD lpdwUrlLength)
4226 INTERNET_SCHEME nScheme;
4228 *lpdwUrlLength = 0;
4230 if (lpUrlComponents->lpszScheme)
4232 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4233 *lpdwUrlLength += dwLen;
4234 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4236 else
4238 LPCWSTR scheme;
4240 nScheme = lpUrlComponents->nScheme;
4242 if (nScheme == INTERNET_SCHEME_DEFAULT)
4243 nScheme = INTERNET_SCHEME_HTTP;
4244 scheme = INTERNET_GetSchemeString(nScheme);
4245 *lpdwUrlLength += lstrlenW(scheme);
4248 (*lpdwUrlLength)++; /* ':' */
4249 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4250 *lpdwUrlLength += strlen("//");
4252 if (lpUrlComponents->lpszUserName)
4254 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4255 *lpdwUrlLength += strlen("@");
4257 else
4259 if (lpUrlComponents->lpszPassword)
4261 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4262 return FALSE;
4266 if (lpUrlComponents->lpszPassword)
4268 *lpdwUrlLength += strlen(":");
4269 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4272 if (lpUrlComponents->lpszHostName)
4274 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4276 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4278 WCHAR port[MAX_WORD_DIGITS + 1];
4280 _ltow(lpUrlComponents->nPort, port, 10);
4281 *lpdwUrlLength += lstrlenW(port);
4282 *lpdwUrlLength += strlen(":");
4285 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4286 (*lpdwUrlLength)++; /* '/' */
4289 if (lpUrlComponents->lpszUrlPath)
4290 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4292 if (lpUrlComponents->lpszExtraInfo)
4293 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4295 return TRUE;
4298 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4300 INT len;
4302 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4304 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4305 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4306 urlCompW->nScheme = lpUrlComponents->nScheme;
4307 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4308 urlCompW->nPort = lpUrlComponents->nPort;
4309 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4310 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4311 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4312 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4314 if (lpUrlComponents->lpszScheme)
4316 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4317 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4318 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4319 -1, urlCompW->lpszScheme, len);
4322 if (lpUrlComponents->lpszHostName)
4324 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4325 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4326 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4327 -1, urlCompW->lpszHostName, len);
4330 if (lpUrlComponents->lpszUserName)
4332 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4333 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4334 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4335 -1, urlCompW->lpszUserName, len);
4338 if (lpUrlComponents->lpszPassword)
4340 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4341 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4342 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4343 -1, urlCompW->lpszPassword, len);
4346 if (lpUrlComponents->lpszUrlPath)
4348 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4349 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4350 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4351 -1, urlCompW->lpszUrlPath, len);
4354 if (lpUrlComponents->lpszExtraInfo)
4356 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4357 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4358 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4359 -1, urlCompW->lpszExtraInfo, len);
4363 /***********************************************************************
4364 * InternetCreateUrlA (WININET.@)
4366 * See InternetCreateUrlW.
4368 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4369 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4371 BOOL ret;
4372 LPWSTR urlW = NULL;
4373 URL_COMPONENTSW urlCompW;
4375 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4377 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4379 SetLastError(ERROR_INVALID_PARAMETER);
4380 return FALSE;
4383 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4385 if (lpszUrl)
4386 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4388 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4390 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4391 *lpdwUrlLength /= sizeof(WCHAR);
4393 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4394 * minus one, so add one to leave room for NULL terminator
4396 if (ret)
4397 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4399 heap_free(urlCompW.lpszScheme);
4400 heap_free(urlCompW.lpszHostName);
4401 heap_free(urlCompW.lpszUserName);
4402 heap_free(urlCompW.lpszPassword);
4403 heap_free(urlCompW.lpszUrlPath);
4404 heap_free(urlCompW.lpszExtraInfo);
4405 heap_free(urlW);
4406 return ret;
4409 /***********************************************************************
4410 * InternetCreateUrlW (WININET.@)
4412 * Creates a URL from its component parts.
4414 * PARAMS
4415 * lpUrlComponents [I] URL Components.
4416 * dwFlags [I] Flags. See notes.
4417 * lpszUrl [I] Buffer in which to store the created URL.
4418 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4419 * lpszUrl in characters. On output, the number of bytes
4420 * required to store the URL including terminator.
4422 * NOTES
4424 * The dwFlags parameter can be zero or more of the following:
4425 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4427 * RETURNS
4428 * TRUE on success
4429 * FALSE on failure
4432 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4433 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4435 DWORD dwLen;
4436 INTERNET_SCHEME nScheme;
4438 static const WCHAR slashSlashW[] = {'/','/'};
4440 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4442 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4444 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4445 return FALSE;
4448 if (!calc_url_length(lpUrlComponents, &dwLen))
4449 return FALSE;
4451 if (!lpszUrl || *lpdwUrlLength < dwLen)
4453 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4454 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4455 return FALSE;
4458 *lpdwUrlLength = dwLen;
4459 lpszUrl[0] = 0x00;
4461 dwLen = 0;
4463 if (lpUrlComponents->lpszScheme)
4465 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4466 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4467 lpszUrl += dwLen;
4469 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4471 else
4473 LPCWSTR scheme;
4474 nScheme = lpUrlComponents->nScheme;
4476 if (nScheme == INTERNET_SCHEME_DEFAULT)
4477 nScheme = INTERNET_SCHEME_HTTP;
4479 scheme = INTERNET_GetSchemeString(nScheme);
4480 dwLen = lstrlenW(scheme);
4481 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4482 lpszUrl += dwLen;
4485 /* all schemes are followed by at least a colon */
4486 *lpszUrl = ':';
4487 lpszUrl++;
4489 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4491 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4492 lpszUrl += ARRAY_SIZE(slashSlashW);
4495 if (lpUrlComponents->lpszUserName)
4497 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4498 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4499 lpszUrl += dwLen;
4501 if (lpUrlComponents->lpszPassword)
4503 *lpszUrl = ':';
4504 lpszUrl++;
4506 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4507 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4508 lpszUrl += dwLen;
4511 *lpszUrl = '@';
4512 lpszUrl++;
4515 if (lpUrlComponents->lpszHostName)
4517 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4518 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4519 lpszUrl += dwLen;
4521 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4523 *lpszUrl++ = ':';
4524 _ltow(lpUrlComponents->nPort, lpszUrl, 10);
4525 lpszUrl += lstrlenW(lpszUrl);
4528 /* add slash between hostname and path if necessary */
4529 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4531 *lpszUrl = '/';
4532 lpszUrl++;
4536 if (lpUrlComponents->lpszUrlPath)
4538 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4539 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4540 lpszUrl += dwLen;
4543 if (lpUrlComponents->lpszExtraInfo)
4545 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4546 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4547 lpszUrl += dwLen;
4550 *lpszUrl = '\0';
4552 return TRUE;
4555 /***********************************************************************
4556 * InternetConfirmZoneCrossingA (WININET.@)
4559 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4561 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4562 return ERROR_SUCCESS;
4565 /***********************************************************************
4566 * InternetConfirmZoneCrossingW (WININET.@)
4569 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4571 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4572 return ERROR_SUCCESS;
4575 static DWORD zone_preference = 3;
4577 /***********************************************************************
4578 * PrivacySetZonePreferenceW (WININET.@)
4580 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4582 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4584 zone_preference = template;
4585 return 0;
4588 /***********************************************************************
4589 * PrivacyGetZonePreferenceW (WININET.@)
4591 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4592 LPWSTR preference, LPDWORD length )
4594 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4596 if (template) *template = zone_preference;
4597 return 0;
4600 /***********************************************************************
4601 * InternetGetSecurityInfoByURLA (WININET.@)
4603 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4605 WCHAR *url;
4606 BOOL res;
4608 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4610 url = heap_strdupAtoW(lpszURL);
4611 if(!url)
4612 return FALSE;
4614 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4615 heap_free(url);
4616 return res;
4619 /***********************************************************************
4620 * InternetGetSecurityInfoByURLW (WININET.@)
4622 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4624 URL_COMPONENTSW url = {sizeof(url)};
4625 server_t *server;
4626 BOOL res;
4628 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4630 if (!ppCertChain && !pdwSecureFlags) {
4631 SetLastError(ERROR_INVALID_PARAMETER);
4632 return FALSE;
4635 url.dwHostNameLength = 1;
4636 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4637 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4638 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4639 return FALSE;
4642 server = get_server(substr(url.lpszHostName, url.dwHostNameLength), url.nPort, TRUE, FALSE);
4643 if(!server) {
4644 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4645 return FALSE;
4648 if(server->cert_chain) {
4649 if(pdwSecureFlags)
4650 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4652 if(ppCertChain && !(*ppCertChain = CertDuplicateCertificateChain(server->cert_chain)))
4653 res = FALSE;
4654 }else {
4655 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4656 res = FALSE;
4659 server_release(server);
4660 return res;
4663 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4664 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4666 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4667 lpdwConnection, dwReserved);
4668 return ERROR_SUCCESS;
4671 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4672 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4674 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4675 lpdwConnection, dwReserved);
4676 return ERROR_SUCCESS;
4679 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4681 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4682 return TRUE;
4685 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4687 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4688 return TRUE;
4691 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4693 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4694 return ERROR_SUCCESS;
4697 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4698 PBYTE pbHexHash )
4700 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4701 debugstr_w(pwszTarget), pbHexHash);
4702 return FALSE;
4705 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4707 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4708 return FALSE;
4711 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4713 FIXME("(%p, %08lx) stub\n", a, b);
4714 return FALSE;
4717 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4719 FIXME("%p: stub\n", parent);
4720 return 0;