user32/tests: Fix test_listbox_messages() message sequences to support WinEvents.
[wine.git] / dlls / wininet / internet.c
blobcef151c7bf2766c4d3dcbbd8714da3ad3db34c29
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 "wine/exception.h"
57 #include "internet.h"
58 #include "resource.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
62 typedef struct
64 DWORD dwError;
65 CHAR response[MAX_REPLY_LEN];
66 } WITHREADERROR, *LPWITHREADERROR;
68 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
69 HMODULE WININET_hModule;
71 static CRITICAL_SECTION WININET_cs;
72 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
74 0, 0, &WININET_cs,
75 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
76 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
78 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
80 static object_header_t **handle_table;
81 static UINT_PTR next_handle;
82 static UINT_PTR handle_table_size;
84 typedef struct
86 DWORD proxyEnabled;
87 LPWSTR proxy;
88 LPWSTR proxyBypass;
89 LPWSTR proxyUsername;
90 LPWSTR proxyPassword;
91 } proxyinfo_t;
93 static ULONG max_conns = 2, max_1_0_conns = 4;
94 static ULONG connect_timeout = 60000;
96 static const WCHAR szInternetSettings[] =
97 L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
99 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
101 UINT_PTR handle = 0, num;
102 object_header_t *ret;
103 object_header_t **p;
104 BOOL res = TRUE;
106 ret = heap_alloc_zero(size);
107 if(!ret)
108 return NULL;
110 list_init(&ret->children);
112 EnterCriticalSection( &WININET_cs );
114 if(!handle_table_size) {
115 num = 16;
116 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
117 if(p) {
118 handle_table = p;
119 handle_table_size = num;
120 next_handle = 1;
121 }else {
122 res = FALSE;
124 }else if(next_handle == handle_table_size) {
125 num = handle_table_size * 2;
126 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
127 if(p) {
128 handle_table = p;
129 handle_table_size = num;
130 }else {
131 res = FALSE;
135 if(res) {
136 handle = next_handle;
137 if(handle_table[handle])
138 ERR("handle isn't free but should be\n");
139 handle_table[handle] = ret;
140 ret->valid_handle = TRUE;
142 while(next_handle < handle_table_size && handle_table[next_handle])
143 next_handle++;
146 LeaveCriticalSection( &WININET_cs );
148 if(!res) {
149 heap_free(ret);
150 return NULL;
153 ret->vtbl = vtbl;
154 ret->refs = 1;
155 ret->hInternet = (HINTERNET)handle;
157 if(parent) {
158 ret->lpfnStatusCB = parent->lpfnStatusCB;
159 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
162 return ret;
165 object_header_t *WININET_AddRef( object_header_t *info )
167 ULONG refs = InterlockedIncrement(&info->refs);
168 TRACE("%p -> refcount = %d\n", info, refs );
169 return info;
172 object_header_t *get_handle_object( HINTERNET hinternet )
174 object_header_t *info = NULL;
175 UINT_PTR handle = (UINT_PTR) hinternet;
177 EnterCriticalSection( &WININET_cs );
179 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
180 info = WININET_AddRef(handle_table[handle]);
182 LeaveCriticalSection( &WININET_cs );
184 TRACE("handle %ld -> %p\n", handle, info);
186 return info;
189 static void invalidate_handle(object_header_t *info)
191 object_header_t *child, *next;
193 if(!info->valid_handle)
194 return;
195 info->valid_handle = FALSE;
197 /* Free all children as native does */
198 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
200 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
201 invalidate_handle( child );
204 WININET_Release(info);
207 BOOL WININET_Release( object_header_t *info )
209 ULONG refs = InterlockedDecrement(&info->refs);
210 TRACE( "object %p refcount = %d\n", info, refs );
211 if( !refs )
213 invalidate_handle(info);
214 if ( info->vtbl->CloseConnection )
216 TRACE( "closing connection %p\n", info);
217 info->vtbl->CloseConnection( info );
219 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
220 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
221 || !(info->dwInternalFlags & INET_OPENURL))
223 INTERNET_SendCallback(info, info->dwContext,
224 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
225 sizeof(HINTERNET));
227 TRACE( "destroying object %p\n", info);
228 if ( info->htype != WH_HINIT )
229 list_remove( &info->entry );
230 info->vtbl->Destroy( info );
232 if(info->hInternet) {
233 UINT_PTR handle = (UINT_PTR)info->hInternet;
235 EnterCriticalSection( &WININET_cs );
237 handle_table[handle] = NULL;
238 if(next_handle > handle)
239 next_handle = handle;
241 LeaveCriticalSection( &WININET_cs );
244 heap_free(info);
246 return TRUE;
249 /***********************************************************************
250 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
252 * PARAMS
253 * hinstDLL [I] handle to the DLL's instance
254 * fdwReason [I]
255 * lpvReserved [I] reserved, must be NULL
257 * RETURNS
258 * Success: TRUE
259 * Failure: FALSE
262 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
264 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
266 switch (fdwReason) {
267 case DLL_PROCESS_ATTACH:
269 g_dwTlsErrIndex = TlsAlloc();
271 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
272 return FALSE;
274 if(!init_urlcache())
276 TlsFree(g_dwTlsErrIndex);
277 return FALSE;
280 WININET_hModule = hinstDLL;
281 break;
283 case DLL_THREAD_ATTACH:
284 break;
286 case DLL_THREAD_DETACH:
287 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
289 heap_free(TlsGetValue(g_dwTlsErrIndex));
291 break;
293 case DLL_PROCESS_DETACH:
294 if (lpvReserved) break;
295 collect_connections(COLLECT_CLEANUP);
296 NETCON_unload();
297 free_urlcache();
298 free_cookie();
300 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
302 heap_free(TlsGetValue(g_dwTlsErrIndex));
303 TlsFree(g_dwTlsErrIndex);
305 break;
307 return TRUE;
310 /***********************************************************************
311 * DllInstall (WININET.@)
313 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
315 FIXME("(%x %s): stub\n", bInstall, debugstr_w(cmdline));
316 return S_OK;
319 /***********************************************************************
320 * INTERNET_SaveProxySettings
322 * Stores the proxy settings given by lpwai into the registry
324 * RETURNS
325 * ERROR_SUCCESS if no error, or error code on fail
327 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
329 HKEY key;
330 LONG ret;
332 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
333 return ret;
335 if ((ret = RegSetValueExW( key, L"ProxyEnable", 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
337 RegCloseKey( key );
338 return ret;
341 if (lpwpi->proxy)
343 if ((ret = RegSetValueExW( key, L"ProxyServer", 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
345 RegCloseKey( key );
346 return ret;
349 else
351 if ((ret = RegDeleteValueW( key, L"ProxyServer" )) && ret != ERROR_FILE_NOT_FOUND)
353 RegCloseKey( key );
354 return ret;
358 RegCloseKey(key);
359 return ERROR_SUCCESS;
362 /***********************************************************************
363 * INTERNET_FindProxyForProtocol
365 * Searches the proxy string for a proxy of the given protocol.
366 * Returns the found proxy, or the default proxy if none of the given
367 * protocol is found.
369 * PARAMETERS
370 * szProxy [In] proxy string to search
371 * proto [In] protocol to search for, e.g. "http"
372 * foundProxy [Out] found proxy
373 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
375 * RETURNS
376 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
377 * *foundProxyLen is set to the required size in WCHARs, including the
378 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
380 WCHAR *INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto)
382 WCHAR *ret = NULL;
383 const WCHAR *ptr;
385 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
387 /* First, look for the specified protocol (proto=scheme://host:port) */
388 for (ptr = szProxy; ptr && *ptr; )
390 LPCWSTR end, equal;
392 if (!(end = wcschr(ptr, ' ')))
393 end = ptr + lstrlenW(ptr);
394 if ((equal = wcschr(ptr, '=')) && equal < end &&
395 equal - ptr == lstrlenW(proto) &&
396 !wcsnicmp(proto, ptr, lstrlenW(proto)))
398 ret = heap_strndupW(equal + 1, end - equal - 1);
399 TRACE("found proxy for %s: %s\n", debugstr_w(proto), debugstr_w(ret));
400 return ret;
402 if (*end == ' ')
403 ptr = end + 1;
404 else
405 ptr = end;
408 /* It wasn't found: look for no protocol */
409 for (ptr = szProxy; ptr && *ptr; )
411 LPCWSTR end;
413 if (!(end = wcschr(ptr, ' ')))
414 end = ptr + lstrlenW(ptr);
415 if (!wcschr(ptr, '='))
417 ret = heap_strndupW(ptr, end - ptr);
418 TRACE("found proxy for %s: %s\n", debugstr_w(proto), debugstr_w(ret));
419 return ret;
421 if (*end == ' ')
422 ptr = end + 1;
423 else
424 ptr = end;
427 return NULL;
430 /***********************************************************************
431 * InternetInitializeAutoProxyDll (WININET.@)
433 * Setup the internal proxy
435 * PARAMETERS
436 * dwReserved
438 * RETURNS
439 * FALSE on failure
442 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
444 FIXME("STUB\n");
445 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
446 return FALSE;
449 /***********************************************************************
450 * DetectAutoProxyUrl (WININET.@)
452 * Auto detect the proxy url
454 * RETURNS
455 * FALSE on failure
458 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
459 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
461 FIXME("STUB\n");
462 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
463 return FALSE;
466 static void FreeProxyInfo( proxyinfo_t *lpwpi )
468 heap_free(lpwpi->proxy);
469 heap_free(lpwpi->proxyBypass);
470 heap_free(lpwpi->proxyUsername);
471 heap_free(lpwpi->proxyPassword);
474 static proxyinfo_t *global_proxy;
476 static void free_global_proxy( void )
478 EnterCriticalSection( &WININET_cs );
479 if (global_proxy)
481 FreeProxyInfo( global_proxy );
482 heap_free( global_proxy );
484 LeaveCriticalSection( &WININET_cs );
487 static BOOL parse_proxy_url( proxyinfo_t *info, const WCHAR *url )
489 URL_COMPONENTSW uc = {sizeof(uc)};
491 uc.dwHostNameLength = 1;
492 uc.dwUserNameLength = 1;
493 uc.dwPasswordLength = 1;
495 if (!InternetCrackUrlW( url, 0, 0, &uc )) return FALSE;
496 if (!uc.dwHostNameLength)
498 if (!(info->proxy = heap_strdupW( url ))) return FALSE;
499 info->proxyUsername = NULL;
500 info->proxyPassword = NULL;
501 return TRUE;
503 if (!(info->proxy = heap_alloc( (uc.dwHostNameLength + 12) * sizeof(WCHAR) ))) return FALSE;
504 swprintf( info->proxy, uc.dwHostNameLength + 12, L"%.*s:%u", uc.dwHostNameLength, uc.lpszHostName, uc.nPort );
506 if (!uc.dwUserNameLength) info->proxyUsername = NULL;
507 else if (!(info->proxyUsername = heap_strndupW( uc.lpszUserName, uc.dwUserNameLength )))
509 heap_free( info->proxy );
510 return FALSE;
512 if (!uc.dwPasswordLength) info->proxyPassword = NULL;
513 else if (!(info->proxyPassword = heap_strndupW( uc.lpszPassword, uc.dwPasswordLength )))
515 heap_free( info->proxyUsername );
516 heap_free( info->proxy );
517 return FALSE;
519 return TRUE;
522 /***********************************************************************
523 * INTERNET_LoadProxySettings
525 * Loads proxy information from process-wide global settings, the registry,
526 * or the environment into lpwpi.
528 * The caller should call FreeProxyInfo when done with lpwpi.
530 * FIXME:
531 * The proxy may be specified in the form 'http=proxy.my.org'
532 * Presumably that means there can be ftp=ftpproxy.my.org too.
534 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
536 HKEY key;
537 DWORD type, len;
538 const WCHAR *envproxy;
539 LONG ret;
541 memset( lpwpi, 0, sizeof(*lpwpi) );
543 EnterCriticalSection( &WININET_cs );
544 if (global_proxy)
546 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
547 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
548 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
550 LeaveCriticalSection( &WININET_cs );
552 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
554 FreeProxyInfo( lpwpi );
555 return ret;
558 len = sizeof(DWORD);
559 if (RegQueryValueExW( key, L"ProxyEnable", NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
561 lpwpi->proxyEnabled = 0;
562 if((ret = RegSetValueExW( key, L"ProxyEnable", 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
564 FreeProxyInfo( lpwpi );
565 RegCloseKey( key );
566 return ret;
570 if (!(envproxy = _wgetenv( L"http_proxy" )) || lpwpi->proxyEnabled)
572 /* figure out how much memory the proxy setting takes */
573 if (!RegQueryValueExW( key, L"ProxyServer", NULL, &type, NULL, &len ) && len && (type == REG_SZ))
575 LPWSTR szProxy, p;
577 if (!(szProxy = heap_alloc(len)))
579 RegCloseKey( key );
580 FreeProxyInfo( lpwpi );
581 return ERROR_OUTOFMEMORY;
583 RegQueryValueExW( key, L"ProxyServer", NULL, &type, (BYTE*)szProxy, &len );
585 /* find the http proxy, and strip away everything else */
586 p = wcsstr( szProxy, L"http=" );
587 if (p)
589 p += lstrlenW( L"http=" );
590 lstrcpyW( szProxy, p );
592 p = wcschr( szProxy, ';' );
593 if (p) *p = 0;
595 FreeProxyInfo( lpwpi );
596 lpwpi->proxy = szProxy;
597 lpwpi->proxyBypass = NULL;
599 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi->proxy));
601 else
603 TRACE("No proxy server settings in registry.\n");
604 FreeProxyInfo( lpwpi );
605 lpwpi->proxy = NULL;
606 lpwpi->proxyBypass = NULL;
609 else if (envproxy)
611 FreeProxyInfo( lpwpi );
612 if (parse_proxy_url( lpwpi, envproxy ))
614 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
615 lpwpi->proxyEnabled = 1;
616 lpwpi->proxyBypass = NULL;
618 else
620 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxy));
621 lpwpi->proxyEnabled = 0;
622 lpwpi->proxy = NULL;
623 lpwpi->proxyBypass = NULL;
627 if (lpwpi->proxyEnabled)
629 TRACE("Proxy is enabled.\n");
631 if (!(envproxy = _wgetenv( L"no_proxy" )))
633 /* figure out how much memory the proxy setting takes */
634 if (!RegQueryValueExW( key, L"ProxyOverride", NULL, &type, NULL, &len ) && len && (type == REG_SZ))
636 LPWSTR szProxy;
638 if (!(szProxy = heap_alloc(len)))
640 RegCloseKey( key );
641 return ERROR_OUTOFMEMORY;
643 RegQueryValueExW( key, L"ProxyOverride", NULL, &type, (BYTE*)szProxy, &len );
645 heap_free( lpwpi->proxyBypass );
646 lpwpi->proxyBypass = szProxy;
648 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi->proxyBypass));
650 else
652 heap_free( lpwpi->proxyBypass );
653 lpwpi->proxyBypass = NULL;
655 TRACE("No proxy bypass server settings in registry.\n");
658 else
660 WCHAR *envproxyW;
662 if (!(envproxyW = heap_alloc(lstrlenW(envproxy) * sizeof(WCHAR))))
664 RegCloseKey( key );
665 return ERROR_OUTOFMEMORY;
667 lstrcpyW( envproxyW, envproxy );
669 heap_free( lpwpi->proxyBypass );
670 lpwpi->proxyBypass = envproxyW;
672 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
675 else TRACE("Proxy is disabled.\n");
677 RegCloseKey( key );
678 return ERROR_SUCCESS;
681 /***********************************************************************
682 * INTERNET_ConfigureProxy
684 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
686 proxyinfo_t wpi;
688 if (INTERNET_LoadProxySettings( &wpi ))
689 return FALSE;
691 if (wpi.proxyEnabled)
693 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi.proxy), debugstr_w(wpi.proxyBypass));
695 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
696 lpwai->proxy = wpi.proxy;
697 lpwai->proxyBypass = wpi.proxyBypass;
698 lpwai->proxyUsername = wpi.proxyUsername;
699 lpwai->proxyPassword = wpi.proxyPassword;
700 return TRUE;
703 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
704 FreeProxyInfo(&wpi);
705 return FALSE;
708 /***********************************************************************
709 * dump_INTERNET_FLAGS
711 * Helper function to TRACE the internet flags.
713 * RETURNS
714 * None
717 static void dump_INTERNET_FLAGS(DWORD dwFlags)
719 #define FE(x) { x, #x }
720 static const wininet_flag_info flag[] = {
721 FE(INTERNET_FLAG_RELOAD),
722 FE(INTERNET_FLAG_RAW_DATA),
723 FE(INTERNET_FLAG_EXISTING_CONNECT),
724 FE(INTERNET_FLAG_ASYNC),
725 FE(INTERNET_FLAG_PASSIVE),
726 FE(INTERNET_FLAG_NO_CACHE_WRITE),
727 FE(INTERNET_FLAG_MAKE_PERSISTENT),
728 FE(INTERNET_FLAG_FROM_CACHE),
729 FE(INTERNET_FLAG_SECURE),
730 FE(INTERNET_FLAG_KEEP_CONNECTION),
731 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
732 FE(INTERNET_FLAG_READ_PREFETCH),
733 FE(INTERNET_FLAG_NO_COOKIES),
734 FE(INTERNET_FLAG_NO_AUTH),
735 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
736 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
737 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
738 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
739 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
740 FE(INTERNET_FLAG_RESYNCHRONIZE),
741 FE(INTERNET_FLAG_HYPERLINK),
742 FE(INTERNET_FLAG_NO_UI),
743 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
744 FE(INTERNET_FLAG_CACHE_ASYNC),
745 FE(INTERNET_FLAG_FORMS_SUBMIT),
746 FE(INTERNET_FLAG_NEED_FILE),
747 FE(INTERNET_FLAG_TRANSFER_ASCII),
748 FE(INTERNET_FLAG_TRANSFER_BINARY)
750 #undef FE
751 unsigned int i;
753 for (i = 0; i < ARRAY_SIZE(flag); i++) {
754 if (flag[i].val & dwFlags) {
755 TRACE(" %s", flag[i].name);
756 dwFlags &= ~flag[i].val;
759 if (dwFlags)
760 TRACE(" Unknown flags (%08x)\n", dwFlags);
761 else
762 TRACE("\n");
765 /***********************************************************************
766 * INTERNET_CloseHandle (internal)
768 * Close internet handle
771 static VOID APPINFO_Destroy(object_header_t *hdr)
773 appinfo_t *lpwai = (appinfo_t*)hdr;
775 TRACE("%p\n",lpwai);
777 heap_free(lpwai->agent);
778 heap_free(lpwai->proxy);
779 heap_free(lpwai->proxyBypass);
780 heap_free(lpwai->proxyUsername);
781 heap_free(lpwai->proxyPassword);
784 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
786 appinfo_t *ai = (appinfo_t*)hdr;
788 switch(option) {
789 case INTERNET_OPTION_HANDLE_TYPE:
790 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
792 if (*size < sizeof(ULONG))
793 return ERROR_INSUFFICIENT_BUFFER;
795 *size = sizeof(DWORD);
796 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
797 return ERROR_SUCCESS;
799 case INTERNET_OPTION_USER_AGENT: {
800 DWORD bufsize;
802 TRACE("INTERNET_OPTION_USER_AGENT\n");
804 bufsize = *size;
806 if (unicode) {
807 DWORD len = ai->agent ? lstrlenW(ai->agent) : 0;
809 *size = (len + 1) * sizeof(WCHAR);
810 if(!buffer || bufsize < *size)
811 return ERROR_INSUFFICIENT_BUFFER;
813 if (ai->agent)
814 lstrcpyW(buffer, ai->agent);
815 else
816 *(WCHAR *)buffer = 0;
817 /* If the buffer is copied, the returned length doesn't include
818 * the NULL terminator.
820 *size = len;
821 }else {
822 if (ai->agent)
823 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
824 else
825 *size = 1;
826 if(!buffer || bufsize < *size)
827 return ERROR_INSUFFICIENT_BUFFER;
829 if (ai->agent)
830 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
831 else
832 *(char *)buffer = 0;
833 /* If the buffer is copied, the returned length doesn't include
834 * the NULL terminator.
836 *size -= 1;
839 return ERROR_SUCCESS;
842 case INTERNET_OPTION_PROXY:
843 if(!size) return ERROR_INVALID_PARAMETER;
844 if (unicode) {
845 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
846 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
847 LPWSTR proxy, proxy_bypass;
849 if (ai->proxy)
850 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
851 if (ai->proxyBypass)
852 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
853 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
855 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
856 return ERROR_INSUFFICIENT_BUFFER;
858 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
859 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
861 pi->dwAccessType = ai->accessType;
862 pi->lpszProxy = NULL;
863 pi->lpszProxyBypass = NULL;
864 if (ai->proxy) {
865 lstrcpyW(proxy, ai->proxy);
866 pi->lpszProxy = proxy;
869 if (ai->proxyBypass) {
870 lstrcpyW(proxy_bypass, ai->proxyBypass);
871 pi->lpszProxyBypass = proxy_bypass;
874 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
875 return ERROR_SUCCESS;
876 }else {
877 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
878 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
879 LPSTR proxy, proxy_bypass;
881 if (ai->proxy)
882 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
883 if (ai->proxyBypass)
884 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
885 NULL, 0, NULL, NULL);
886 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
888 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
889 return ERROR_INSUFFICIENT_BUFFER;
891 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
892 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
894 pi->dwAccessType = ai->accessType;
895 pi->lpszProxy = NULL;
896 pi->lpszProxyBypass = NULL;
897 if (ai->proxy) {
898 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
899 pi->lpszProxy = proxy;
902 if (ai->proxyBypass) {
903 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
904 proxyBypassBytesRequired, NULL, NULL);
905 pi->lpszProxyBypass = proxy_bypass;
908 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
909 return ERROR_SUCCESS;
912 case INTERNET_OPTION_CONNECT_TIMEOUT:
913 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
915 if (*size < sizeof(ULONG))
916 return ERROR_INSUFFICIENT_BUFFER;
918 *(ULONG*)buffer = ai->connect_timeout;
919 *size = sizeof(ULONG);
921 return ERROR_SUCCESS;
924 return INET_QueryOption(hdr, option, buffer, size, unicode);
927 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
929 appinfo_t *ai = (appinfo_t*)hdr;
931 switch(option) {
932 case INTERNET_OPTION_CONNECT_TIMEOUT:
933 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
935 if(size != sizeof(connect_timeout))
936 return ERROR_INTERNET_BAD_OPTION_LENGTH;
937 if(!*(ULONG*)buf)
938 return ERROR_BAD_ARGUMENTS;
940 ai->connect_timeout = *(ULONG*)buf;
941 return ERROR_SUCCESS;
942 case INTERNET_OPTION_USER_AGENT:
943 heap_free(ai->agent);
944 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
945 return ERROR_SUCCESS;
946 case INTERNET_OPTION_REFRESH:
947 FIXME("INTERNET_OPTION_REFRESH\n");
948 return ERROR_SUCCESS;
951 return INET_SetOption(hdr, option, buf, size);
954 static const object_vtbl_t APPINFOVtbl = {
955 APPINFO_Destroy,
956 NULL,
957 APPINFO_QueryOption,
958 APPINFO_SetOption,
959 NULL,
960 NULL,
961 NULL
965 /***********************************************************************
966 * InternetOpenW (WININET.@)
968 * Per-application initialization of wininet
970 * RETURNS
971 * HINTERNET on success
972 * NULL on failure
975 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
976 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
978 appinfo_t *lpwai = NULL;
980 if (TRACE_ON(wininet)) {
981 #define FE(x) { x, #x }
982 static const wininet_flag_info access_type[] = {
983 FE(INTERNET_OPEN_TYPE_PRECONFIG),
984 FE(INTERNET_OPEN_TYPE_DIRECT),
985 FE(INTERNET_OPEN_TYPE_PROXY),
986 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
988 #undef FE
989 DWORD i;
990 const char *access_type_str = "Unknown";
992 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
993 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
994 for (i = 0; i < ARRAY_SIZE(access_type); i++) {
995 if (access_type[i].val == dwAccessType) {
996 access_type_str = access_type[i].name;
997 break;
1000 TRACE(" access type : %s\n", access_type_str);
1001 TRACE(" flags :");
1002 dump_INTERNET_FLAGS(dwFlags);
1005 /* Clear any error information */
1006 INTERNET_SetLastError(0);
1008 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1009 SetLastError(ERROR_INVALID_PARAMETER);
1010 return NULL;
1013 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1014 if (!lpwai) {
1015 SetLastError(ERROR_OUTOFMEMORY);
1016 return NULL;
1019 lpwai->hdr.htype = WH_HINIT;
1020 lpwai->hdr.dwFlags = dwFlags;
1021 lpwai->accessType = dwAccessType;
1022 lpwai->proxyUsername = NULL;
1023 lpwai->proxyPassword = NULL;
1024 lpwai->connect_timeout = connect_timeout;
1026 lpwai->agent = heap_strdupW(lpszAgent);
1027 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1028 INTERNET_ConfigureProxy( lpwai );
1029 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1030 lpwai->proxy = heap_strdupW(lpszProxy);
1031 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1034 TRACE("returning %p\n", lpwai);
1036 return lpwai->hdr.hInternet;
1040 /***********************************************************************
1041 * InternetOpenA (WININET.@)
1043 * Per-application initialization of wininet
1045 * RETURNS
1046 * HINTERNET on success
1047 * NULL on failure
1050 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1051 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1053 WCHAR *szAgent, *szProxy, *szBypass;
1054 HINTERNET rc;
1056 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1057 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1059 szAgent = heap_strdupAtoW(lpszAgent);
1060 szProxy = heap_strdupAtoW(lpszProxy);
1061 szBypass = heap_strdupAtoW(lpszProxyBypass);
1063 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1065 heap_free(szAgent);
1066 heap_free(szProxy);
1067 heap_free(szBypass);
1068 return rc;
1071 /***********************************************************************
1072 * InternetGetLastResponseInfoA (WININET.@)
1074 * Return last wininet error description on the calling thread
1076 * RETURNS
1077 * TRUE on success of writing to buffer
1078 * FALSE on failure
1081 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1082 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1084 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1086 TRACE("(%p, %p, %p)\n", lpdwError, lpszBuffer, lpdwBufferLength);
1088 if (!lpdwError || !lpdwBufferLength)
1090 SetLastError(ERROR_INVALID_PARAMETER);
1091 return FALSE;
1093 if (lpwite)
1095 if (lpszBuffer == NULL || *lpdwBufferLength < strlen(lpwite->response))
1097 *lpdwBufferLength = strlen(lpwite->response);
1098 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1099 return FALSE;
1101 *lpdwError = lpwite->dwError;
1102 if (*lpdwBufferLength)
1104 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1105 lpszBuffer[*lpdwBufferLength - 1] = 0;
1106 *lpdwBufferLength = strlen(lpszBuffer);
1109 else
1111 *lpdwError = 0;
1112 *lpdwBufferLength = 0;
1115 return TRUE;
1118 /***********************************************************************
1119 * InternetGetLastResponseInfoW (WININET.@)
1121 * Return last wininet error description on the calling thread
1123 * RETURNS
1124 * TRUE on success of writing to buffer
1125 * FALSE on failure
1128 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1129 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1131 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1133 TRACE("(%p, %p, %p)\n", lpdwError, lpszBuffer, lpdwBufferLength);
1135 if (!lpdwError || !lpdwBufferLength)
1137 SetLastError(ERROR_INVALID_PARAMETER);
1138 return FALSE;
1140 if (lpwite)
1142 int required_size = MultiByteToWideChar(CP_ACP, 0, lpwite->response, -1, NULL, 0) - 1;
1143 if (lpszBuffer == NULL || *lpdwBufferLength < required_size)
1145 *lpdwBufferLength = required_size;
1146 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1147 return FALSE;
1149 *lpdwError = lpwite->dwError;
1150 if (*lpdwBufferLength)
1151 *lpdwBufferLength = MultiByteToWideChar(CP_ACP, 0, lpwite->response, -1, lpszBuffer, *lpdwBufferLength);
1153 else
1155 *lpdwError = 0;
1156 *lpdwBufferLength = 0;
1159 return TRUE;
1162 /***********************************************************************
1163 * InternetGetConnectedState (WININET.@)
1165 * Return connected state
1167 * RETURNS
1168 * TRUE if connected
1169 * if lpdwStatus is not null, return the status (off line,
1170 * modem, lan...) in it.
1171 * FALSE if not connected
1173 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1175 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1177 return InternetGetConnectedStateExW(lpdwStatus, NULL, 0, dwReserved);
1181 /***********************************************************************
1182 * InternetGetConnectedStateExW (WININET.@)
1184 * Return connected state
1186 * PARAMS
1188 * lpdwStatus [O] Flags specifying the status of the internet connection.
1189 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1190 * dwNameLen [I] Size of the buffer, in characters.
1191 * dwReserved [I] Reserved. Must be set to 0.
1193 * RETURNS
1194 * TRUE if connected
1195 * if lpdwStatus is not null, return the status (off line,
1196 * modem, lan...) in it.
1197 * FALSE if not connected
1199 * NOTES
1200 * If the system has no available network connections, an empty string is
1201 * stored in lpszConnectionName. If there is a LAN connection, a localized
1202 * "LAN Connection" string is stored. Presumably, if only a dial-up
1203 * connection is available then the name of the dial-up connection is
1204 * returned. Why any application, other than the "Internet Settings" CPL,
1205 * would want to use this function instead of the simpler InternetGetConnectedStateW
1206 * function is beyond me.
1208 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1209 DWORD dwNameLen, DWORD dwReserved)
1211 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1213 /* Must be zero */
1214 if(dwReserved)
1215 return FALSE;
1217 if (lpdwStatus) {
1218 WARN("always returning LAN connection.\n");
1219 *lpdwStatus = INTERNET_CONNECTION_LAN;
1222 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1223 * the resource, avoid it as we must not change the buffer in this case */
1224 if(lpszConnectionName && dwNameLen) {
1225 *lpszConnectionName = '\0';
1226 LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1229 return TRUE;
1233 /***********************************************************************
1234 * InternetGetConnectedStateExA (WININET.@)
1236 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1237 DWORD dwNameLen, DWORD dwReserved)
1239 LPWSTR lpwszConnectionName = NULL;
1240 BOOL rc;
1242 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1244 if (lpszConnectionName && dwNameLen > 0)
1245 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1247 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1248 dwReserved);
1249 if (rc && lpwszConnectionName)
1250 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1251 dwNameLen, NULL, NULL);
1253 heap_free(lpwszConnectionName);
1254 return rc;
1258 /***********************************************************************
1259 * InternetConnectW (WININET.@)
1261 * Open a ftp, gopher or http session
1263 * RETURNS
1264 * HINTERNET a session handle on success
1265 * NULL on failure
1268 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1269 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1270 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1271 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1273 appinfo_t *hIC;
1274 HINTERNET rc = NULL;
1275 DWORD res = ERROR_SUCCESS;
1277 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1278 nServerPort, debugstr_w(lpszUserName), lpszPassword, dwService, dwFlags, dwContext);
1280 if (!lpszServerName)
1282 SetLastError(ERROR_INVALID_PARAMETER);
1283 return NULL;
1286 hIC = (appinfo_t*)get_handle_object( hInternet );
1287 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1289 res = ERROR_INVALID_HANDLE;
1290 goto lend;
1293 switch (dwService)
1295 case INTERNET_SERVICE_FTP:
1296 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1297 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1298 if(!rc)
1299 res = INTERNET_GetLastError();
1300 break;
1302 case INTERNET_SERVICE_HTTP:
1303 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1304 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1305 break;
1307 case INTERNET_SERVICE_GOPHER:
1308 default:
1309 break;
1311 lend:
1312 if( hIC )
1313 WININET_Release( &hIC->hdr );
1315 TRACE("returning %p\n", rc);
1316 SetLastError(res);
1317 return rc;
1321 /***********************************************************************
1322 * InternetConnectA (WININET.@)
1324 * Open a ftp, gopher or http session
1326 * RETURNS
1327 * HINTERNET a session handle on success
1328 * NULL on failure
1331 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1332 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1333 LPCSTR lpszUserName, LPCSTR lpszPassword,
1334 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1336 HINTERNET rc = NULL;
1337 LPWSTR szServerName;
1338 LPWSTR szUserName;
1339 LPWSTR szPassword;
1341 szServerName = heap_strdupAtoW(lpszServerName);
1342 szUserName = heap_strdupAtoW(lpszUserName);
1343 szPassword = heap_strdupAtoW(lpszPassword);
1345 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1346 szUserName, szPassword, dwService, dwFlags, dwContext);
1348 heap_free(szServerName);
1349 heap_free(szUserName);
1350 heap_free(szPassword);
1351 return rc;
1355 /***********************************************************************
1356 * InternetFindNextFileA (WININET.@)
1358 * Continues a file search from a previous call to FindFirstFile
1360 * RETURNS
1361 * TRUE on success
1362 * FALSE on failure
1365 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1367 BOOL ret;
1368 WIN32_FIND_DATAW fd;
1370 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1371 if(lpvFindData)
1372 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1373 return ret;
1376 /***********************************************************************
1377 * InternetFindNextFileW (WININET.@)
1379 * Continues a file search from a previous call to FindFirstFile
1381 * RETURNS
1382 * TRUE on success
1383 * FALSE on failure
1386 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1388 object_header_t *hdr;
1389 DWORD res;
1391 TRACE("\n");
1393 hdr = get_handle_object(hFind);
1394 if(!hdr) {
1395 WARN("Invalid handle\n");
1396 SetLastError(ERROR_INVALID_HANDLE);
1397 return FALSE;
1400 if(hdr->vtbl->FindNextFileW) {
1401 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1402 }else {
1403 WARN("Handle doesn't support NextFile\n");
1404 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1407 WININET_Release(hdr);
1409 if(res != ERROR_SUCCESS)
1410 SetLastError(res);
1411 return res == ERROR_SUCCESS;
1414 /***********************************************************************
1415 * InternetCloseHandle (WININET.@)
1417 * Generic close handle function
1419 * RETURNS
1420 * TRUE on success
1421 * FALSE on failure
1424 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1426 object_header_t *obj;
1428 TRACE("%p\n", hInternet);
1430 obj = get_handle_object( hInternet );
1431 if (!obj) {
1432 SetLastError(ERROR_INVALID_HANDLE);
1433 return FALSE;
1436 invalidate_handle(obj);
1437 WININET_Release(obj);
1439 return TRUE;
1442 static BOOL set_url_component(WCHAR **component, DWORD *component_length, const WCHAR *value, DWORD len)
1444 TRACE("%s (%d)\n", debugstr_wn(value, len), len);
1446 if (!*component_length)
1447 return TRUE;
1449 if (!*component) {
1450 *(const WCHAR**)component = value;
1451 *component_length = len;
1452 return TRUE;
1455 if (*component_length < len+1) {
1456 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1457 return FALSE;
1460 *component_length = len;
1461 if(len)
1462 memcpy(*component, value, len*sizeof(WCHAR));
1463 (*component)[len] = 0;
1464 return TRUE;
1467 static BOOL set_url_component_WtoA(const WCHAR *comp_w, DWORD length, const WCHAR *url_w, char **comp, DWORD *ret_length,
1468 const char *url_a)
1470 size_t size, ret_size = *ret_length;
1472 if (!*ret_length)
1473 return TRUE;
1474 size = WideCharToMultiByte(CP_ACP, 0, comp_w, length, NULL, 0, NULL, NULL);
1476 if (!*comp) {
1477 *comp = comp_w ? (char*)url_a + WideCharToMultiByte(CP_ACP, 0, url_w, comp_w-url_w, NULL, 0, NULL, NULL) : NULL;
1478 *ret_length = size;
1479 return TRUE;
1482 if (size+1 > ret_size) {
1483 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1484 *ret_length = size+1;
1485 return FALSE;
1488 *ret_length = size;
1489 WideCharToMultiByte(CP_ACP, 0, comp_w, length, *comp, ret_size-1, NULL, NULL);
1490 (*comp)[size] = 0;
1491 return TRUE;
1494 static BOOL set_url_component_AtoW(const char *comp_a, DWORD len_a, WCHAR **comp_w, DWORD *len_w, WCHAR **buf)
1496 *len_w = len_a;
1498 if(!comp_a) {
1499 *comp_w = NULL;
1500 return TRUE;
1503 if(!(*comp_w = *buf = heap_alloc(len_a*sizeof(WCHAR)))) {
1504 SetLastError(ERROR_OUTOFMEMORY);
1505 return FALSE;
1508 return TRUE;
1511 /***********************************************************************
1512 * InternetCrackUrlA (WININET.@)
1514 * See InternetCrackUrlW.
1516 BOOL WINAPI InternetCrackUrlA(const char *url, DWORD url_length, DWORD flags, URL_COMPONENTSA *ret_comp)
1518 WCHAR *host = NULL, *user = NULL, *pass = NULL, *path = NULL, *scheme = NULL, *extra = NULL;
1519 URL_COMPONENTSW comp;
1520 WCHAR *url_w = NULL;
1521 BOOL ret;
1523 TRACE("(%s %u %x %p)\n", url_length ? debugstr_an(url, url_length) : debugstr_a(url), url_length, flags, ret_comp);
1525 if (!url || !*url || !ret_comp || ret_comp->dwStructSize != sizeof(URL_COMPONENTSA)) {
1526 SetLastError(ERROR_INVALID_PARAMETER);
1527 return FALSE;
1530 comp.dwStructSize = sizeof(comp);
1532 ret = set_url_component_AtoW(ret_comp->lpszHostName, ret_comp->dwHostNameLength,
1533 &comp.lpszHostName, &comp.dwHostNameLength, &host)
1534 && set_url_component_AtoW(ret_comp->lpszUserName, ret_comp->dwUserNameLength,
1535 &comp.lpszUserName, &comp.dwUserNameLength, &user)
1536 && set_url_component_AtoW(ret_comp->lpszPassword, ret_comp->dwPasswordLength,
1537 &comp.lpszPassword, &comp.dwPasswordLength, &pass)
1538 && set_url_component_AtoW(ret_comp->lpszUrlPath, ret_comp->dwUrlPathLength,
1539 &comp.lpszUrlPath, &comp.dwUrlPathLength, &path)
1540 && set_url_component_AtoW(ret_comp->lpszScheme, ret_comp->dwSchemeLength,
1541 &comp.lpszScheme, &comp.dwSchemeLength, &scheme)
1542 && set_url_component_AtoW(ret_comp->lpszExtraInfo, ret_comp->dwExtraInfoLength,
1543 &comp.lpszExtraInfo, &comp.dwExtraInfoLength, &extra);
1545 if(ret && !(url_w = heap_strndupAtoW(url, url_length ? url_length : -1, &url_length))) {
1546 SetLastError(ERROR_OUTOFMEMORY);
1547 ret = FALSE;
1550 if (ret && (ret = InternetCrackUrlW(url_w, url_length, flags, &comp))) {
1551 ret_comp->nScheme = comp.nScheme;
1552 ret_comp->nPort = comp.nPort;
1554 ret = set_url_component_WtoA(comp.lpszHostName, comp.dwHostNameLength, url_w,
1555 &ret_comp->lpszHostName, &ret_comp->dwHostNameLength, url)
1556 && set_url_component_WtoA(comp.lpszUserName, comp.dwUserNameLength, url_w,
1557 &ret_comp->lpszUserName, &ret_comp->dwUserNameLength, url)
1558 && set_url_component_WtoA(comp.lpszPassword, comp.dwPasswordLength, url_w,
1559 &ret_comp->lpszPassword, &ret_comp->dwPasswordLength, url)
1560 && set_url_component_WtoA(comp.lpszUrlPath, comp.dwUrlPathLength, url_w,
1561 &ret_comp->lpszUrlPath, &ret_comp->dwUrlPathLength, url)
1562 && set_url_component_WtoA(comp.lpszScheme, comp.dwSchemeLength, url_w,
1563 &ret_comp->lpszScheme, &ret_comp->dwSchemeLength, url)
1564 && set_url_component_WtoA(comp.lpszExtraInfo, comp.dwExtraInfoLength, url_w,
1565 &ret_comp->lpszExtraInfo, &ret_comp->dwExtraInfoLength, url);
1567 if(ret)
1568 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url),
1569 debugstr_an(ret_comp->lpszScheme, ret_comp->dwSchemeLength),
1570 debugstr_an(ret_comp->lpszHostName, ret_comp->dwHostNameLength),
1571 debugstr_an(ret_comp->lpszUrlPath, ret_comp->dwUrlPathLength),
1572 debugstr_an(ret_comp->lpszExtraInfo, ret_comp->dwExtraInfoLength));
1575 heap_free(host);
1576 heap_free(user);
1577 heap_free(pass);
1578 heap_free(path);
1579 heap_free(scheme);
1580 heap_free(extra);
1581 heap_free(url_w);
1582 return ret;
1585 static const WCHAR *url_schemes[] =
1587 L"ftp",
1588 L"gopher",
1589 L"http",
1590 L"https",
1591 L"file",
1592 L"news",
1593 L"mailto",
1594 L"socks",
1595 L"javascript",
1596 L"vbscript",
1597 L"res"
1600 /***********************************************************************
1601 * GetInternetSchemeW (internal)
1603 * Get scheme of url
1605 * RETURNS
1606 * scheme on success
1607 * INTERNET_SCHEME_UNKNOWN on failure
1610 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1612 int i;
1614 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1616 if(lpszScheme==NULL)
1617 return INTERNET_SCHEME_UNKNOWN;
1619 for (i = 0; i < ARRAY_SIZE(url_schemes); i++)
1620 if (!wcsnicmp(lpszScheme, url_schemes[i], nMaxCmp))
1621 return INTERNET_SCHEME_FIRST + i;
1623 return INTERNET_SCHEME_UNKNOWN;
1626 /***********************************************************************
1627 * InternetCrackUrlW (WININET.@)
1629 * Break up URL into its components
1631 * RETURNS
1632 * TRUE on success
1633 * FALSE on failure
1635 BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
1638 * RFC 1808
1639 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1642 LPCWSTR lpszParam = NULL;
1643 BOOL found_colon = FALSE;
1644 LPCWSTR lpszap;
1645 LPCWSTR lpszcp = NULL, lpszNetLoc;
1647 TRACE("(%s %u %x %p)\n",
1648 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : lstrlenW(lpszUrl)) : "(null)",
1649 dwUrlLength, dwFlags, lpUC);
1651 if (!lpszUrl || !*lpszUrl || !lpUC)
1653 SetLastError(ERROR_INVALID_PARAMETER);
1654 return FALSE;
1657 if (!dwUrlLength)
1658 dwUrlLength = lstrlenW(lpszUrl);
1659 else {
1660 /* Windows stops at a null, regardless of what dwUrlLength says. */
1661 dwUrlLength = wcsnlen(lpszUrl, dwUrlLength);
1664 if (dwFlags & ICU_DECODE)
1666 WCHAR *url_tmp, *buffer;
1667 DWORD len = dwUrlLength + 1;
1668 BOOL ret;
1670 if (!(url_tmp = heap_strndupW(lpszUrl, dwUrlLength)))
1672 SetLastError(ERROR_OUTOFMEMORY);
1673 return FALSE;
1676 buffer = url_tmp;
1677 ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
1678 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1680 buffer = heap_alloc(len * sizeof(WCHAR));
1681 if (!buffer)
1683 SetLastError(ERROR_OUTOFMEMORY);
1684 heap_free(url_tmp);
1685 return FALSE;
1687 ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
1689 if (ret)
1690 ret = InternetCrackUrlW(buffer, len, dwFlags & ~ICU_DECODE, lpUC);
1692 if (buffer != url_tmp) heap_free(buffer);
1693 heap_free(url_tmp);
1694 return ret;
1696 lpszap = lpszUrl;
1698 /* Determine if the URI is absolute. */
1699 while (lpszap - lpszUrl < dwUrlLength)
1701 if (iswalnum(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1703 lpszap++;
1704 continue;
1706 if (*lpszap == ':')
1708 found_colon = TRUE;
1709 lpszcp = lpszap;
1711 else
1713 lpszcp = lpszUrl; /* Relative url */
1716 break;
1719 if(!found_colon){
1720 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1721 return FALSE;
1724 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1725 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1727 /* Parse <params> */
1728 lpszParam = wmemchr(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1729 if(!lpszParam)
1730 lpszParam = wmemchr(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1732 if(!set_url_component(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1733 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0))
1734 return FALSE;
1737 /* Get scheme first. */
1738 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1739 if(!set_url_component(&lpUC->lpszScheme, &lpUC->dwSchemeLength, lpszUrl, lpszcp - lpszUrl))
1740 return FALSE;
1742 /* Eat ':' in protocol. */
1743 lpszcp++;
1745 /* double slash indicates the net_loc portion is present */
1746 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1748 lpszcp += 2;
1750 lpszNetLoc = wmemchr(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1751 if (lpszParam)
1753 if (lpszNetLoc)
1754 lpszNetLoc = min(lpszNetLoc, lpszParam);
1755 else
1756 lpszNetLoc = lpszParam;
1758 else if (!lpszNetLoc)
1759 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1761 /* Parse net-loc */
1762 if (lpszNetLoc)
1764 LPCWSTR lpszHost;
1765 LPCWSTR lpszPort;
1767 /* [<user>[<:password>]@]<host>[:<port>] */
1768 /* First find the user and password if they exist */
1770 lpszHost = wmemchr(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1771 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1773 /* username and password not specified. */
1774 set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1775 set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1777 else /* Parse out username and password */
1779 LPCWSTR lpszUser = lpszcp;
1780 LPCWSTR lpszPasswd = lpszHost;
1782 while (lpszcp < lpszHost)
1784 if (*lpszcp == ':')
1785 lpszPasswd = lpszcp;
1787 lpszcp++;
1790 if(!set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, lpszUser, lpszPasswd - lpszUser))
1791 return FALSE;
1793 if (lpszPasswd != lpszHost)
1794 lpszPasswd++;
1795 if(!set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1796 lpszPasswd == lpszHost ? NULL : lpszPasswd, lpszHost - lpszPasswd))
1797 return FALSE;
1799 lpszcp++; /* Advance to beginning of host */
1802 /* Parse <host><:port> */
1804 lpszHost = lpszcp;
1805 lpszPort = lpszNetLoc;
1807 /* special case for res:// URLs: there is no port here, so the host is the
1808 entire string up to the first '/' */
1809 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1811 if(!set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost))
1812 return FALSE;
1813 lpszcp=lpszNetLoc;
1815 else
1817 while (lpszcp < lpszNetLoc)
1819 if (*lpszcp == ':')
1820 lpszPort = lpszcp;
1822 lpszcp++;
1825 /* If the scheme is "file" and the host is just one letter, it's not a host */
1826 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1828 lpszcp=lpszHost;
1829 set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1831 else
1833 if(!set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost))
1834 return FALSE;
1835 if (lpszPort != lpszNetLoc)
1836 lpUC->nPort = wcstol(++lpszPort, NULL, 10);
1837 else switch (lpUC->nScheme)
1839 case INTERNET_SCHEME_HTTP:
1840 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1841 break;
1842 case INTERNET_SCHEME_HTTPS:
1843 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1844 break;
1845 case INTERNET_SCHEME_FTP:
1846 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1847 break;
1848 default:
1849 break;
1855 else
1857 set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1858 set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1859 set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1862 /* Here lpszcp points to:
1864 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1865 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1867 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1869 DWORD len;
1871 /* Only truncate the parameter list if it's already been saved
1872 * in lpUC->lpszExtraInfo.
1874 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1875 len = lpszParam - lpszcp;
1876 else
1878 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1879 * newlines if necessary.
1881 LPWSTR lpsznewline = wmemchr(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1882 if (lpsznewline != NULL)
1883 len = lpsznewline - lpszcp;
1884 else
1885 len = dwUrlLength-(lpszcp-lpszUrl);
1887 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1888 lpUC->nScheme == INTERNET_SCHEME_FILE)
1890 WCHAR tmppath[MAX_PATH];
1891 if (*lpszcp == '/')
1893 len = MAX_PATH;
1894 PathCreateFromUrlW(lpszUrl, tmppath, &len, 0);
1896 else
1898 WCHAR *iter;
1899 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1900 tmppath[len] = '\0';
1902 iter = tmppath;
1903 while (*iter) {
1904 if (*iter == '/')
1905 *iter = '\\';
1906 ++iter;
1909 /* if ends in \. or \.. append a backslash */
1910 if (tmppath[len - 1] == '.' &&
1911 (tmppath[len - 2] == '\\' ||
1912 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1914 if (len < MAX_PATH - 1)
1916 tmppath[len] = '\\';
1917 tmppath[len+1] = '\0';
1918 ++len;
1921 if(!set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, tmppath, len))
1922 return FALSE;
1924 else if(!set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, lpszcp, len))
1925 return FALSE;
1927 else
1929 set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, lpszcp, 0);
1932 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1933 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1934 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1935 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1936 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1938 return TRUE;
1941 /***********************************************************************
1942 * InternetAttemptConnect (WININET.@)
1944 * Attempt to make a connection to the internet
1946 * RETURNS
1947 * ERROR_SUCCESS on success
1948 * Error value on failure
1951 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1953 FIXME("Stub\n");
1954 return ERROR_SUCCESS;
1958 /***********************************************************************
1959 * convert_url_canonicalization_flags
1961 * Helper for InternetCanonicalizeUrl
1963 * PARAMS
1964 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1966 * RETURNS
1967 * Flags suitable for UrlCanonicalize
1969 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
1971 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1973 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
1974 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
1975 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
1976 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
1977 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1978 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
1979 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
1981 return dwUrlFlags;
1984 /***********************************************************************
1985 * InternetCanonicalizeUrlA (WININET.@)
1987 * Escape unsafe characters and spaces
1989 * RETURNS
1990 * TRUE on success
1991 * FALSE on failure
1994 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1995 LPDWORD lpdwBufferLength, DWORD dwFlags)
1997 HRESULT hr;
1999 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl), lpszBuffer,
2000 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2002 dwFlags = convert_url_canonicalization_flags(dwFlags);
2003 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2004 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2005 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2007 return hr == S_OK;
2010 /***********************************************************************
2011 * InternetCanonicalizeUrlW (WININET.@)
2013 * Escape unsafe characters and spaces
2015 * RETURNS
2016 * TRUE on success
2017 * FALSE on failure
2020 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
2021 LPDWORD lpdwBufferLength, DWORD dwFlags)
2023 HRESULT hr;
2025 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2026 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2028 dwFlags = convert_url_canonicalization_flags(dwFlags);
2029 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2030 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2031 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2033 return hr == S_OK;
2036 /* #################################################### */
2038 static INTERNET_STATUS_CALLBACK set_status_callback(
2039 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2041 INTERNET_STATUS_CALLBACK ret;
2043 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2044 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2046 ret = lpwh->lpfnStatusCB;
2047 lpwh->lpfnStatusCB = callback;
2049 return ret;
2052 /***********************************************************************
2053 * InternetSetStatusCallbackA (WININET.@)
2055 * Sets up a callback function which is called as progress is made
2056 * during an operation.
2058 * RETURNS
2059 * Previous callback or NULL on success
2060 * INTERNET_INVALID_STATUS_CALLBACK on failure
2063 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2064 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2066 INTERNET_STATUS_CALLBACK retVal;
2067 object_header_t *lpwh;
2069 TRACE("%p\n", hInternet);
2071 if (!(lpwh = get_handle_object(hInternet)))
2072 return INTERNET_INVALID_STATUS_CALLBACK;
2074 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2076 WININET_Release( lpwh );
2077 return retVal;
2080 /***********************************************************************
2081 * InternetSetStatusCallbackW (WININET.@)
2083 * Sets up a callback function which is called as progress is made
2084 * during an operation.
2086 * RETURNS
2087 * Previous callback or NULL on success
2088 * INTERNET_INVALID_STATUS_CALLBACK on failure
2091 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2092 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2094 INTERNET_STATUS_CALLBACK retVal;
2095 object_header_t *lpwh;
2097 TRACE("%p\n", hInternet);
2099 if (!(lpwh = get_handle_object(hInternet)))
2100 return INTERNET_INVALID_STATUS_CALLBACK;
2102 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2104 WININET_Release( lpwh );
2105 return retVal;
2108 /***********************************************************************
2109 * InternetSetFilePointer (WININET.@)
2111 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2112 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2114 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2116 SetLastError(ERROR_INTERNET_INVALID_OPERATION);
2117 return INVALID_SET_FILE_POINTER;
2120 /***********************************************************************
2121 * InternetWriteFile (WININET.@)
2123 * Write data to an open internet file
2125 * RETURNS
2126 * TRUE on success
2127 * FALSE on failure
2130 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2131 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2133 object_header_t *lpwh;
2134 BOOL res;
2136 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2138 lpwh = get_handle_object( hFile );
2139 if (!lpwh) {
2140 WARN("Invalid handle\n");
2141 SetLastError(ERROR_INVALID_HANDLE);
2142 return FALSE;
2145 if(lpwh->vtbl->WriteFile) {
2146 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2147 }else {
2148 WARN("No Writefile method.\n");
2149 res = ERROR_INVALID_HANDLE;
2152 WININET_Release( lpwh );
2154 if(res != ERROR_SUCCESS)
2155 SetLastError(res);
2156 return res == ERROR_SUCCESS;
2160 /***********************************************************************
2161 * InternetReadFile (WININET.@)
2163 * Read data from an open internet file
2165 * RETURNS
2166 * TRUE on success
2167 * FALSE on failure
2170 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2171 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2173 object_header_t *hdr;
2174 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2176 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2178 hdr = get_handle_object(hFile);
2179 if (!hdr) {
2180 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2181 return FALSE;
2184 if(hdr->vtbl->ReadFile) {
2185 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, 0, 0);
2186 if(res == ERROR_IO_PENDING)
2187 *pdwNumOfBytesRead = 0;
2190 WININET_Release(hdr);
2192 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2193 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2195 SetLastError(res);
2196 return res == ERROR_SUCCESS;
2199 /***********************************************************************
2200 * InternetReadFileExA (WININET.@)
2202 * Read data from an open internet file
2204 * PARAMS
2205 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2206 * lpBuffersOut [I/O] Buffer.
2207 * dwFlags [I] Flags. See notes.
2208 * dwContext [I] Context for callbacks.
2210 * RETURNS
2211 * TRUE on success
2212 * FALSE on failure
2214 * NOTES
2215 * The parameter dwFlags include zero or more of the following flags:
2216 *|IRF_ASYNC - Makes the call asynchronous.
2217 *|IRF_SYNC - Makes the call synchronous.
2218 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2219 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2221 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2223 * SEE
2224 * InternetOpenUrlA(), HttpOpenRequestA()
2226 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2227 DWORD dwFlags, DWORD_PTR dwContext)
2229 object_header_t *hdr;
2230 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2232 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2234 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2235 SetLastError(ERROR_INVALID_PARAMETER);
2236 return FALSE;
2239 hdr = get_handle_object(hFile);
2240 if (!hdr) {
2241 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2242 return FALSE;
2245 if(hdr->vtbl->ReadFile)
2246 res = hdr->vtbl->ReadFile(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2247 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2249 WININET_Release(hdr);
2251 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2252 res, lpBuffersOut->dwBufferLength);
2254 if(res != ERROR_SUCCESS)
2255 SetLastError(res);
2256 return res == ERROR_SUCCESS;
2259 /***********************************************************************
2260 * InternetReadFileExW (WININET.@)
2261 * SEE
2262 * InternetReadFileExA()
2264 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2265 DWORD dwFlags, DWORD_PTR dwContext)
2267 object_header_t *hdr;
2268 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2270 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2272 if (!lpBuffer || lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2273 SetLastError(ERROR_INVALID_PARAMETER);
2274 return FALSE;
2277 hdr = get_handle_object(hFile);
2278 if (!hdr) {
2279 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2280 return FALSE;
2283 if(hdr->vtbl->ReadFile)
2284 res = hdr->vtbl->ReadFile(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2285 dwFlags, dwContext);
2287 WININET_Release(hdr);
2289 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2290 res, lpBuffer->dwBufferLength);
2292 if(res != ERROR_SUCCESS)
2293 SetLastError(res);
2294 return res == ERROR_SUCCESS;
2297 static IP_ADAPTER_ADDRESSES *get_adapters(void)
2299 ULONG err, size = 1024, flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
2300 GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME;
2301 IP_ADAPTER_ADDRESSES *tmp, *ret;
2303 if (!(ret = heap_alloc( size ))) return NULL;
2304 err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
2305 while (err == ERROR_BUFFER_OVERFLOW)
2307 if (!(tmp = heap_realloc( ret, size ))) break;
2308 ret = tmp;
2309 err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
2311 if (err == ERROR_SUCCESS) return ret;
2312 heap_free( ret );
2313 return NULL;
2316 static WCHAR *detect_proxy_autoconfig_url_dhcp(void)
2318 IP_ADAPTER_ADDRESSES *adapters, *ptr;
2319 DHCPCAPI_PARAMS_ARRAY send_params, recv_params;
2320 DHCPCAPI_PARAMS param;
2321 WCHAR name[MAX_ADAPTER_NAME_LENGTH + 1], *ret = NULL;
2322 DWORD err, size;
2323 BYTE *tmp, *buf = NULL;
2325 if (!(adapters = get_adapters())) return NULL;
2327 memset( &send_params, 0, sizeof(send_params) );
2328 memset( &param, 0, sizeof(param) );
2329 param.OptionId = OPTION_MSFT_IE_PROXY;
2330 recv_params.nParams = 1;
2331 recv_params.Params = &param;
2333 for (ptr = adapters; ptr; ptr = ptr->Next)
2335 MultiByteToWideChar( CP_ACP, 0, ptr->AdapterName, -1, name, ARRAY_SIZE(name) );
2336 TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name), ptr->IfType, ptr->Dhcpv4Enabled );
2338 if (ptr->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2339 /* FIXME: also skip adapters where DHCP is disabled */
2341 size = 256;
2342 if (!(buf = heap_alloc( size ))) goto done;
2343 err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
2344 buf, &size, NULL );
2345 while (err == ERROR_MORE_DATA)
2347 if (!(tmp = heap_realloc( buf, size ))) goto done;
2348 buf = tmp;
2349 err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
2350 buf, &size, NULL );
2352 if (err == ERROR_SUCCESS && param.nBytesData)
2354 int len = MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, NULL, 0 );
2355 if ((ret = heap_alloc( (len + 1) * sizeof(WCHAR) )))
2357 MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, ret, len );
2358 ret[len] = 0;
2360 TRACE("returning %s\n", debugstr_w(ret));
2361 break;
2365 done:
2366 heap_free( buf );
2367 heap_free( adapters );
2368 return ret;
2371 static char *get_computer_name( COMPUTER_NAME_FORMAT format )
2373 char *ret;
2374 DWORD size = 0;
2376 GetComputerNameExA( format, NULL, &size );
2377 if (GetLastError() != ERROR_MORE_DATA) return NULL;
2378 if (!(ret = heap_alloc( size ))) return NULL;
2379 if (!GetComputerNameExA( format, ret, &size ))
2381 heap_free( ret );
2382 return NULL;
2384 return ret;
2387 static BOOL is_domain_suffix( const char *domain, const char *suffix )
2389 int len_domain = strlen( domain ), len_suffix = strlen( suffix );
2391 if (len_suffix > len_domain) return FALSE;
2392 if (!stricmp( domain + len_domain - len_suffix, suffix )) return TRUE;
2393 return FALSE;
2396 static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len )
2398 return getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 );
2401 static WCHAR *build_wpad_url( const char *hostname, const struct addrinfo *ai )
2403 char name[NI_MAXHOST];
2404 WCHAR *ret, *p;
2405 int len;
2407 while (ai && ai->ai_family != AF_INET && ai->ai_family != AF_INET6) ai = ai->ai_next;
2408 if (!ai) return NULL;
2410 if (!reverse_lookup( ai, name, sizeof(name) )) hostname = name;
2412 len = lstrlenW( L"http://" ) + strlen( hostname ) + lstrlenW( L"/wpad.dat" );
2413 if (!(ret = p = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
2414 lstrcpyW( p, L"http://" );
2415 p += lstrlenW( L"http://" );
2416 while (*hostname) { *p++ = *hostname++; }
2417 lstrcpyW( p, L"/wpad.dat" );
2418 return ret;
2421 static WCHAR *detect_proxy_autoconfig_url_dns(void)
2423 char *fqdn, *domain, *p;
2424 WCHAR *ret;
2426 if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return NULL;
2427 if (!(domain = get_computer_name( ComputerNamePhysicalDnsDomain )))
2429 heap_free( fqdn );
2430 return NULL;
2432 p = fqdn;
2433 while ((p = strchr( p, '.' )) && is_domain_suffix( p + 1, domain ))
2435 char *name;
2436 struct addrinfo *ai;
2437 int res;
2439 if (!(name = heap_alloc( sizeof("wpad") + strlen(p) )))
2441 heap_free( fqdn );
2442 heap_free( domain );
2443 return NULL;
2445 strcpy( name, "wpad" );
2446 strcat( name, p );
2447 res = getaddrinfo( name, NULL, NULL, &ai );
2448 if (!res)
2450 ret = build_wpad_url( name, ai );
2451 freeaddrinfo( ai );
2452 if (ret)
2454 TRACE("returning %s\n", debugstr_w(ret));
2455 heap_free( name );
2456 break;
2459 heap_free( name );
2460 p++;
2462 heap_free( domain );
2463 heap_free( fqdn );
2464 return ret;
2467 static WCHAR *get_proxy_autoconfig_url(void)
2469 WCHAR *ret = detect_proxy_autoconfig_url_dhcp();
2470 if (!ret) ret = detect_proxy_autoconfig_url_dns();
2471 return ret;
2474 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2476 /* FIXME: This function currently handles more options than it should. Options requiring
2477 * proper handles should be moved to proper functions */
2478 switch(option) {
2479 case INTERNET_OPTION_HTTP_VERSION:
2480 if (*size < sizeof(HTTP_VERSION_INFO))
2481 return ERROR_INSUFFICIENT_BUFFER;
2484 * Presently hardcoded to 1.1
2486 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2487 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2488 *size = sizeof(HTTP_VERSION_INFO);
2490 return ERROR_SUCCESS;
2492 case INTERNET_OPTION_CONNECTED_STATE:
2493 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2495 if (*size < sizeof(ULONG))
2496 return ERROR_INSUFFICIENT_BUFFER;
2498 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2499 *size = sizeof(ULONG);
2501 return ERROR_SUCCESS;
2503 case INTERNET_OPTION_PROXY: {
2504 appinfo_t ai;
2505 BOOL ret;
2507 TRACE("Getting global proxy info\n");
2508 memset(&ai, 0, sizeof(appinfo_t));
2509 INTERNET_ConfigureProxy(&ai);
2511 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2512 APPINFO_Destroy(&ai.hdr);
2513 return ret;
2516 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2517 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2519 if (*size < sizeof(ULONG))
2520 return ERROR_INSUFFICIENT_BUFFER;
2522 *(ULONG*)buffer = max_conns;
2523 *size = sizeof(ULONG);
2525 return ERROR_SUCCESS;
2527 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2528 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2530 if (*size < sizeof(ULONG))
2531 return ERROR_INSUFFICIENT_BUFFER;
2533 *(ULONG*)buffer = max_1_0_conns;
2534 *size = sizeof(ULONG);
2536 return ERROR_SUCCESS;
2538 case INTERNET_OPTION_SECURITY_FLAGS:
2539 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2540 return ERROR_SUCCESS;
2542 case INTERNET_OPTION_VERSION: {
2543 static const INTERNET_VERSION_INFO info = { 1, 2 };
2545 TRACE("INTERNET_OPTION_VERSION\n");
2547 if (*size < sizeof(INTERNET_VERSION_INFO))
2548 return ERROR_INSUFFICIENT_BUFFER;
2550 memcpy(buffer, &info, sizeof(info));
2551 *size = sizeof(info);
2553 return ERROR_SUCCESS;
2556 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2557 WCHAR *url;
2558 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2559 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2560 DWORD res = ERROR_SUCCESS, i;
2561 proxyinfo_t pi;
2562 LONG ret;
2564 TRACE("Getting global proxy info\n");
2565 if((ret = INTERNET_LoadProxySettings(&pi)))
2566 return ret;
2568 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2570 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2571 FreeProxyInfo(&pi);
2572 return ERROR_INSUFFICIENT_BUFFER;
2575 url = get_proxy_autoconfig_url();
2577 for (i = 0; i < con->dwOptionCount; i++) {
2578 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2579 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2581 switch (optionW->dwOption) {
2582 case INTERNET_PER_CONN_FLAGS:
2583 if(pi.proxyEnabled)
2584 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2585 else
2586 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2587 if (url)
2588 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2589 optionW->Value.dwValue |= PROXY_TYPE_DIRECT|PROXY_TYPE_AUTO_PROXY_URL;
2590 break;
2592 case INTERNET_PER_CONN_PROXY_SERVER:
2593 if (unicode)
2594 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2595 else
2596 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2597 break;
2599 case INTERNET_PER_CONN_PROXY_BYPASS:
2600 if (unicode)
2601 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2602 else
2603 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2604 break;
2606 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2607 if (!url)
2608 optionW->Value.pszValue = NULL;
2609 else if (unicode)
2610 optionW->Value.pszValue = heap_strdupW(url);
2611 else
2612 optionA->Value.pszValue = heap_strdupWtoA(url);
2613 break;
2615 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2616 optionW->Value.dwValue = AUTO_PROXY_FLAG_ALWAYS_DETECT;
2617 break;
2619 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2620 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2621 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2622 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2623 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2624 memset(&optionW->Value, 0, sizeof(optionW->Value));
2625 break;
2627 default:
2628 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2629 res = ERROR_INVALID_PARAMETER;
2630 break;
2633 heap_free(url);
2634 FreeProxyInfo(&pi);
2636 return res;
2638 case INTERNET_OPTION_REQUEST_FLAGS:
2639 case INTERNET_OPTION_USER_AGENT:
2640 *size = 0;
2641 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2642 case INTERNET_OPTION_POLICY:
2643 return ERROR_INVALID_PARAMETER;
2644 case INTERNET_OPTION_CONNECT_TIMEOUT:
2645 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2647 if (*size < sizeof(ULONG))
2648 return ERROR_INSUFFICIENT_BUFFER;
2650 *(ULONG*)buffer = connect_timeout;
2651 *size = sizeof(ULONG);
2653 return ERROR_SUCCESS;
2656 FIXME("Stub for %d\n", option);
2657 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2660 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2662 switch(option) {
2663 case INTERNET_OPTION_CONTEXT_VALUE:
2664 if (!size)
2665 return ERROR_INVALID_PARAMETER;
2667 if (*size < sizeof(DWORD_PTR)) {
2668 *size = sizeof(DWORD_PTR);
2669 return ERROR_INSUFFICIENT_BUFFER;
2671 if (!buffer)
2672 return ERROR_INVALID_PARAMETER;
2674 *(DWORD_PTR *)buffer = hdr->dwContext;
2675 *size = sizeof(DWORD_PTR);
2676 return ERROR_SUCCESS;
2678 case INTERNET_OPTION_REQUEST_FLAGS:
2679 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2680 *size = sizeof(DWORD);
2681 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2683 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2684 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2685 WARN("Called on global option %u\n", option);
2686 return ERROR_INTERNET_INVALID_OPERATION;
2689 /* FIXME: we shouldn't call it here */
2690 return query_global_option(option, buffer, size, unicode);
2693 /***********************************************************************
2694 * InternetQueryOptionW (WININET.@)
2696 * Queries an options on the specified handle
2698 * RETURNS
2699 * TRUE on success
2700 * FALSE on failure
2703 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2704 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2706 object_header_t *hdr;
2707 DWORD res = ERROR_INVALID_HANDLE;
2709 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2711 if(hInternet) {
2712 hdr = get_handle_object(hInternet);
2713 if (hdr) {
2714 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2715 WININET_Release(hdr);
2717 }else {
2718 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2721 if(res != ERROR_SUCCESS)
2722 SetLastError(res);
2723 return res == ERROR_SUCCESS;
2726 /***********************************************************************
2727 * InternetQueryOptionA (WININET.@)
2729 * Queries an options on the specified handle
2731 * RETURNS
2732 * TRUE on success
2733 * FALSE on failure
2736 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2737 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2739 object_header_t *hdr;
2740 DWORD res = ERROR_INVALID_HANDLE;
2742 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2744 if(hInternet) {
2745 hdr = get_handle_object(hInternet);
2746 if (hdr) {
2747 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2748 WININET_Release(hdr);
2750 }else {
2751 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2754 if(res != ERROR_SUCCESS)
2755 SetLastError(res);
2756 return res == ERROR_SUCCESS;
2759 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2761 switch(option) {
2762 case INTERNET_OPTION_SETTINGS_CHANGED:
2763 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2764 collect_connections(COLLECT_CONNECTIONS);
2765 return ERROR_SUCCESS;
2766 case INTERNET_OPTION_CALLBACK:
2767 WARN("Not settable option %u\n", option);
2768 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2769 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2770 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2771 WARN("Called on global option %u\n", option);
2772 return ERROR_INTERNET_INVALID_OPERATION;
2773 case INTERNET_OPTION_REFRESH:
2774 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2777 return ERROR_INTERNET_INVALID_OPTION;
2780 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2782 switch(option) {
2783 case INTERNET_OPTION_CALLBACK:
2784 WARN("Not global option %u\n", option);
2785 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2787 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2788 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2790 if(size != sizeof(max_conns))
2791 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2792 if(!*(ULONG*)buf)
2793 return ERROR_BAD_ARGUMENTS;
2795 max_conns = *(ULONG*)buf;
2796 return ERROR_SUCCESS;
2798 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2799 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2801 if(size != sizeof(max_1_0_conns))
2802 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2803 if(!*(ULONG*)buf)
2804 return ERROR_BAD_ARGUMENTS;
2806 max_1_0_conns = *(ULONG*)buf;
2807 return ERROR_SUCCESS;
2809 case INTERNET_OPTION_CONNECT_TIMEOUT:
2810 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2812 if(size != sizeof(connect_timeout))
2813 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2814 if(!*(ULONG*)buf)
2815 return ERROR_BAD_ARGUMENTS;
2817 connect_timeout = *(ULONG*)buf;
2818 return ERROR_SUCCESS;
2820 case INTERNET_OPTION_SUPPRESS_BEHAVIOR:
2821 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2823 if(size != sizeof(ULONG))
2824 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2826 FIXME("%08x\n", *(ULONG*)buf);
2827 return ERROR_SUCCESS;
2830 return INET_SetOption(NULL, option, buf, size);
2833 /***********************************************************************
2834 * InternetSetOptionW (WININET.@)
2836 * Sets an options on the specified handle
2838 * RETURNS
2839 * TRUE on success
2840 * FALSE on failure
2843 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2844 LPVOID lpBuffer, DWORD dwBufferLength)
2846 object_header_t *lpwhh;
2847 BOOL ret = TRUE;
2848 DWORD res;
2850 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2852 lpwhh = (object_header_t*) get_handle_object( hInternet );
2853 if(lpwhh)
2854 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2855 else
2856 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2858 if(res != ERROR_INTERNET_INVALID_OPTION) {
2859 if(lpwhh)
2860 WININET_Release(lpwhh);
2862 if(res != ERROR_SUCCESS)
2863 SetLastError(res);
2865 return res == ERROR_SUCCESS;
2868 switch (dwOption)
2870 case INTERNET_OPTION_HTTP_VERSION:
2872 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2873 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2875 break;
2876 case INTERNET_OPTION_ERROR_MASK:
2878 if(!lpwhh) {
2879 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2880 return FALSE;
2881 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2882 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2883 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2884 SetLastError(ERROR_INVALID_PARAMETER);
2885 ret = FALSE;
2886 } else if(dwBufferLength != sizeof(ULONG)) {
2887 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2888 ret = FALSE;
2889 } else
2890 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2891 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2893 break;
2894 case INTERNET_OPTION_PROXY:
2896 INTERNET_PROXY_INFOW *info = lpBuffer;
2898 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2900 SetLastError(ERROR_INVALID_PARAMETER);
2901 return FALSE;
2903 if (!hInternet)
2905 EnterCriticalSection( &WININET_cs );
2906 free_global_proxy();
2907 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2908 if (global_proxy)
2910 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2912 global_proxy->proxyEnabled = 1;
2913 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2914 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2916 else
2918 global_proxy->proxyEnabled = 0;
2919 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2922 LeaveCriticalSection( &WININET_cs );
2924 else
2926 /* In general, each type of object should handle
2927 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2928 * get silently dropped.
2930 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2931 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2932 ret = FALSE;
2934 break;
2936 case INTERNET_OPTION_CODEPAGE:
2938 ULONG codepage = *(ULONG *)lpBuffer;
2939 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2941 break;
2942 case INTERNET_OPTION_REQUEST_PRIORITY:
2944 ULONG priority = *(ULONG *)lpBuffer;
2945 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2947 break;
2948 case INTERNET_OPTION_CONNECT_TIMEOUT:
2950 ULONG connecttimeout = *(ULONG *)lpBuffer;
2951 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2953 break;
2954 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2956 ULONG receivetimeout = *(ULONG *)lpBuffer;
2957 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2959 break;
2960 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2961 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2962 break;
2963 case INTERNET_OPTION_END_BROWSER_SESSION:
2964 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2965 free_cookie();
2966 free_authorization_cache();
2967 break;
2968 case INTERNET_OPTION_CONNECTED_STATE:
2969 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2970 break;
2971 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2972 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2973 break;
2974 case INTERNET_OPTION_IGNORE_OFFLINE:
2975 FIXME("Option INTERNET_OPTION_IGNORE_OFFLINE: STUB\n");
2976 break;
2977 case INTERNET_OPTION_SEND_TIMEOUT:
2978 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2979 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2981 ULONG timeout = *(ULONG *)lpBuffer;
2982 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2983 break;
2985 case INTERNET_OPTION_CONNECT_RETRIES:
2987 ULONG retries = *(ULONG *)lpBuffer;
2988 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2989 break;
2991 case INTERNET_OPTION_CONTEXT_VALUE:
2993 if (!lpwhh)
2995 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2996 return FALSE;
2998 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
3000 SetLastError(ERROR_INVALID_PARAMETER);
3001 ret = FALSE;
3003 else
3004 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
3005 break;
3007 case INTERNET_OPTION_SECURITY_FLAGS:
3008 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
3009 break;
3010 case INTERNET_OPTION_DISABLE_AUTODIAL:
3011 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
3012 break;
3013 case INTERNET_OPTION_HTTP_DECODING:
3014 if (!lpwhh)
3016 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3017 return FALSE;
3019 if (!lpBuffer || dwBufferLength != sizeof(BOOL))
3021 SetLastError(ERROR_INVALID_PARAMETER);
3022 ret = FALSE;
3024 else
3025 lpwhh->decoding = *(BOOL *)lpBuffer;
3026 break;
3027 case INTERNET_OPTION_COOKIES_3RD_PARTY:
3028 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
3029 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3030 ret = FALSE;
3031 break;
3032 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
3033 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
3034 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3035 ret = FALSE;
3036 break;
3037 case INTERNET_OPTION_CODEPAGE_PATH:
3038 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
3039 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3040 ret = FALSE;
3041 break;
3042 case INTERNET_OPTION_CODEPAGE_EXTRA:
3043 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
3044 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3045 ret = FALSE;
3046 break;
3047 case INTERNET_OPTION_IDN:
3048 FIXME("INTERNET_OPTION_IDN; STUB\n");
3049 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3050 ret = FALSE;
3051 break;
3052 case INTERNET_OPTION_POLICY:
3053 SetLastError(ERROR_INVALID_PARAMETER);
3054 ret = FALSE;
3055 break;
3056 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3057 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
3058 LONG res;
3059 unsigned int i;
3060 proxyinfo_t pi;
3062 if (INTERNET_LoadProxySettings(&pi)) return FALSE;
3064 for (i = 0; i < con->dwOptionCount; i++) {
3065 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
3067 switch (option->dwOption) {
3068 case INTERNET_PER_CONN_PROXY_SERVER:
3069 heap_free(pi.proxy);
3070 pi.proxy = heap_strdupW(option->Value.pszValue);
3071 break;
3073 case INTERNET_PER_CONN_FLAGS:
3074 if(option->Value.dwValue & PROXY_TYPE_PROXY)
3075 pi.proxyEnabled = 1;
3076 else
3078 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
3079 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
3080 pi.proxyEnabled = 0;
3082 break;
3084 case INTERNET_PER_CONN_PROXY_BYPASS:
3085 heap_free(pi.proxyBypass);
3086 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
3087 break;
3089 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3090 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3091 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3092 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3093 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3094 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3095 FIXME("Unhandled dwOption %d\n", option->dwOption);
3096 break;
3098 default:
3099 FIXME("Unknown dwOption %d\n", option->dwOption);
3100 SetLastError(ERROR_INVALID_PARAMETER);
3101 break;
3105 if ((res = INTERNET_SaveProxySettings(&pi)))
3106 SetLastError(res);
3108 FreeProxyInfo(&pi);
3110 ret = (res == ERROR_SUCCESS);
3111 break;
3113 default:
3114 FIXME("Option %d STUB\n",dwOption);
3115 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3116 ret = FALSE;
3117 break;
3120 if(lpwhh)
3121 WININET_Release( lpwhh );
3123 return ret;
3127 /***********************************************************************
3128 * InternetSetOptionA (WININET.@)
3130 * Sets an options on the specified handle.
3132 * RETURNS
3133 * TRUE on success
3134 * FALSE on failure
3137 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
3138 LPVOID lpBuffer, DWORD dwBufferLength)
3140 LPVOID wbuffer;
3141 DWORD wlen;
3142 BOOL r;
3144 switch( dwOption )
3146 case INTERNET_OPTION_PROXY:
3148 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
3149 LPINTERNET_PROXY_INFOW piw;
3150 DWORD proxlen, prbylen;
3151 LPWSTR prox, prby;
3153 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
3154 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
3155 wlen = sizeof(*piw) + proxlen + prbylen;
3156 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
3157 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
3158 piw->dwAccessType = pi->dwAccessType;
3159 prox = (LPWSTR) &piw[1];
3160 prby = &prox[proxlen+1];
3161 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
3162 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
3163 piw->lpszProxy = prox;
3164 piw->lpszProxyBypass = prby;
3166 break;
3167 case INTERNET_OPTION_USER_AGENT:
3168 case INTERNET_OPTION_USERNAME:
3169 case INTERNET_OPTION_PASSWORD:
3170 case INTERNET_OPTION_PROXY_USERNAME:
3171 case INTERNET_OPTION_PROXY_PASSWORD:
3172 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3173 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3174 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3175 break;
3176 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3177 unsigned int i;
3178 INTERNET_PER_CONN_OPTION_LISTW *listW;
3179 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3180 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3181 wbuffer = heap_alloc(wlen);
3182 listW = wbuffer;
3184 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3185 if (listA->pszConnection)
3187 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3188 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3189 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3191 else
3192 listW->pszConnection = NULL;
3193 listW->dwOptionCount = listA->dwOptionCount;
3194 listW->dwOptionError = listA->dwOptionError;
3195 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3197 for (i = 0; i < listA->dwOptionCount; ++i) {
3198 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3199 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3201 optW->dwOption = optA->dwOption;
3203 switch (optA->dwOption) {
3204 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3205 case INTERNET_PER_CONN_PROXY_BYPASS:
3206 case INTERNET_PER_CONN_PROXY_SERVER:
3207 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3208 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3209 if (optA->Value.pszValue)
3211 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3212 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3213 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3215 else
3216 optW->Value.pszValue = NULL;
3217 break;
3218 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3219 case INTERNET_PER_CONN_FLAGS:
3220 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3221 optW->Value.dwValue = optA->Value.dwValue;
3222 break;
3223 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3224 optW->Value.ftValue = optA->Value.ftValue;
3225 break;
3226 default:
3227 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3228 optW->Value.dwValue = optA->Value.dwValue;
3229 break;
3233 break;
3234 default:
3235 wbuffer = lpBuffer;
3236 wlen = dwBufferLength;
3239 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3241 if( lpBuffer != wbuffer )
3243 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3245 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3246 unsigned int i;
3247 for (i = 0; i < list->dwOptionCount; ++i) {
3248 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3249 switch (opt->dwOption) {
3250 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3251 case INTERNET_PER_CONN_PROXY_BYPASS:
3252 case INTERNET_PER_CONN_PROXY_SERVER:
3253 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3254 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3255 heap_free( opt->Value.pszValue );
3256 break;
3257 default:
3258 break;
3261 heap_free( list->pOptions );
3263 heap_free( wbuffer );
3266 return r;
3270 /***********************************************************************
3271 * InternetSetOptionExA (WININET.@)
3273 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3274 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3276 FIXME("Flags %08x ignored\n", dwFlags);
3277 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3280 /***********************************************************************
3281 * InternetSetOptionExW (WININET.@)
3283 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3284 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3286 FIXME("Flags %08x ignored\n", dwFlags);
3287 if( dwFlags & ~ISO_VALID_FLAGS )
3289 SetLastError( ERROR_INVALID_PARAMETER );
3290 return FALSE;
3292 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3295 static const WCHAR WININET_wkday[7][4] =
3296 { L"Sun", L"Mon", L"Tue", L"Wed",
3297 L"Thu", L"Fri", L"Sat"};
3298 static const WCHAR WININET_month[12][4] =
3299 { L"Jan", L"Feb", L"Mar", L"Apr",
3300 L"May", L"Jun", L"Jul", L"Aug",
3301 L"Sep", L"Oct", L"Nov", L"Dec"};
3303 /***********************************************************************
3304 * InternetTimeFromSystemTimeA (WININET.@)
3306 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3308 BOOL ret;
3309 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3311 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3313 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3315 SetLastError(ERROR_INVALID_PARAMETER);
3316 return FALSE;
3319 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3321 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3322 return FALSE;
3325 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3326 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3328 return ret;
3331 /***********************************************************************
3332 * InternetTimeFromSystemTimeW (WININET.@)
3334 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3336 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3338 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3340 SetLastError(ERROR_INVALID_PARAMETER);
3341 return FALSE;
3344 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3346 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3347 return FALSE;
3350 swprintf( string, size, L"%s, %02d %s %4d %02d:%02d:%02d GMT",
3351 WININET_wkday[time->wDayOfWeek],
3352 time->wDay,
3353 WININET_month[time->wMonth - 1],
3354 time->wYear,
3355 time->wHour,
3356 time->wMinute,
3357 time->wSecond );
3359 return TRUE;
3362 /***********************************************************************
3363 * InternetTimeToSystemTimeA (WININET.@)
3365 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3367 BOOL ret = FALSE;
3368 WCHAR *stringW;
3370 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3372 stringW = heap_strdupAtoW(string);
3373 if (stringW)
3375 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3376 heap_free( stringW );
3378 return ret;
3381 /***********************************************************************
3382 * InternetTimeToSystemTimeW (WININET.@)
3384 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3386 unsigned int i;
3387 const WCHAR *s = string;
3388 WCHAR *end;
3390 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3392 if (!string || !time) return FALSE;
3394 /* Windows does this too */
3395 GetSystemTime( time );
3397 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3398 * a SYSTEMTIME structure.
3401 while (*s && !iswalpha( *s )) s++;
3402 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3403 time->wDayOfWeek = 7;
3405 for (i = 0; i < 7; i++)
3407 if (!wcsnicmp( WININET_wkday[i], s, 3 ))
3409 time->wDayOfWeek = i;
3410 break;
3414 if (time->wDayOfWeek > 6) return TRUE;
3415 while (*s && !iswdigit( *s )) s++;
3416 time->wDay = wcstol( s, &end, 10 );
3417 s = end;
3419 while (*s && !iswalpha( *s )) s++;
3420 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3421 time->wMonth = 0;
3423 for (i = 0; i < 12; i++)
3425 if (!wcsnicmp( WININET_month[i], s, 3 ))
3427 time->wMonth = i + 1;
3428 break;
3431 if (time->wMonth == 0) return TRUE;
3433 while (*s && !iswdigit( *s )) s++;
3434 if (*s == '\0') return TRUE;
3435 time->wYear = wcstol( s, &end, 10 );
3436 s = end;
3438 while (*s && !iswdigit( *s )) s++;
3439 if (*s == '\0') return TRUE;
3440 time->wHour = wcstol( s, &end, 10 );
3441 s = end;
3443 while (*s && !iswdigit( *s )) s++;
3444 if (*s == '\0') return TRUE;
3445 time->wMinute = wcstol( s, &end, 10 );
3446 s = end;
3448 while (*s && !iswdigit( *s )) s++;
3449 if (*s == '\0') return TRUE;
3450 time->wSecond = wcstol( s, &end, 10 );
3451 s = end;
3453 time->wMilliseconds = 0;
3454 return TRUE;
3457 /***********************************************************************
3458 * InternetCheckConnectionW (WININET.@)
3460 * Pings a requested host to check internet connection
3462 * RETURNS
3463 * TRUE on success and FALSE on failure. If a failure then
3464 * ERROR_NOT_CONNECTED is placed into GetLastError
3467 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3470 * this is a kludge which runs the resident ping program and reads the output.
3472 * Anyone have a better idea?
3475 BOOL rc = FALSE;
3476 static const CHAR ping[] = "ping -c 1 ";
3477 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3478 WCHAR *host;
3479 DWORD len, host_len;
3480 INTERNET_PORT port;
3481 int status = -1;
3483 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl), dwFlags, dwReserved);
3486 * Crack or set the Address
3488 if (lpszUrl == NULL)
3491 * According to the doc we are supposed to use the ip for the next
3492 * server in the WnInet internal server database. I have
3493 * no idea what that is or how to get it.
3495 * So someone needs to implement this.
3497 FIXME("Unimplemented with URL of NULL\n");
3498 return TRUE;
3500 else
3502 URL_COMPONENTSW components = {sizeof(components)};
3504 components.dwHostNameLength = 1;
3506 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3507 goto End;
3509 host = components.lpszHostName;
3510 host_len = components.dwHostNameLength;
3511 port = components.nPort;
3512 TRACE("host name: %s port: %d\n",debugstr_wn(host, host_len), port);
3515 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3517 struct sockaddr_storage saddr;
3518 int sa_len = sizeof(saddr);
3519 WCHAR *host_z;
3520 int fd;
3521 BOOL b;
3523 host_z = heap_strndupW(host, host_len);
3524 if (!host_z)
3525 return FALSE;
3527 b = GetAddress(host_z, port, (struct sockaddr *)&saddr, &sa_len, NULL);
3528 heap_free(host_z);
3529 if(!b)
3530 goto End;
3531 init_winsock();
3532 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3533 if (fd != -1)
3535 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3536 rc = TRUE;
3537 closesocket(fd);
3540 else
3543 * Build our ping command
3545 char *command;
3547 len = WideCharToMultiByte(CP_UNIXCP, 0, host, host_len, NULL, 0, NULL, NULL);
3548 command = heap_alloc(strlen(ping)+len+strlen(redirect)+1);
3549 strcpy(command, ping);
3550 WideCharToMultiByte(CP_UNIXCP, 0, host, host_len, command+sizeof(ping)-1, len, NULL, NULL);
3551 strcpy(command+sizeof(ping)-1+len, redirect);
3553 TRACE("Ping command is : %s\n",command);
3555 status = system(command);
3556 heap_free( command );
3558 TRACE("Ping returned a code of %i\n",status);
3560 /* Ping return code of 0 indicates success */
3561 if (status == 0)
3562 rc = TRUE;
3565 End:
3566 if (rc == FALSE)
3567 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3569 return rc;
3573 /***********************************************************************
3574 * InternetCheckConnectionA (WININET.@)
3576 * Pings a requested host to check internet connection
3578 * RETURNS
3579 * TRUE on success and FALSE on failure. If a failure then
3580 * ERROR_NOT_CONNECTED is placed into GetLastError
3583 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3585 WCHAR *url = NULL;
3586 BOOL rc;
3588 if(lpszUrl) {
3589 url = heap_strdupAtoW(lpszUrl);
3590 if(!url)
3591 return FALSE;
3594 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3596 heap_free(url);
3597 return rc;
3601 /**********************************************************
3602 * INTERNET_InternetOpenUrlW (internal)
3604 * Opens an URL
3606 * RETURNS
3607 * handle of connection or NULL on failure
3609 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3610 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3612 URL_COMPONENTSW urlComponents = { sizeof(urlComponents) };
3613 WCHAR *host, *user = NULL, *pass = NULL, *path;
3614 HINTERNET client = NULL, client1 = NULL;
3615 DWORD res;
3617 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3618 dwHeadersLength, dwFlags, dwContext);
3620 urlComponents.dwHostNameLength = 1;
3621 urlComponents.dwUserNameLength = 1;
3622 urlComponents.dwPasswordLength = 1;
3623 urlComponents.dwUrlPathLength = 1;
3624 urlComponents.dwExtraInfoLength = 1;
3625 if(!InternetCrackUrlW(lpszUrl, lstrlenW(lpszUrl), 0, &urlComponents))
3626 return NULL;
3628 if ((urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS) &&
3629 urlComponents.dwExtraInfoLength)
3631 assert(urlComponents.lpszUrlPath + urlComponents.dwUrlPathLength == urlComponents.lpszExtraInfo);
3632 urlComponents.dwUrlPathLength += urlComponents.dwExtraInfoLength;
3635 host = heap_strndupW(urlComponents.lpszHostName, urlComponents.dwHostNameLength);
3636 path = heap_strndupW(urlComponents.lpszUrlPath, urlComponents.dwUrlPathLength);
3637 if(urlComponents.dwUserNameLength)
3638 user = heap_strndupW(urlComponents.lpszUserName, urlComponents.dwUserNameLength);
3639 if(urlComponents.dwPasswordLength)
3640 pass = heap_strndupW(urlComponents.lpszPassword, urlComponents.dwPasswordLength);
3642 switch(urlComponents.nScheme) {
3643 case INTERNET_SCHEME_FTP:
3644 client = FTP_Connect(hIC, host, urlComponents.nPort,
3645 user, pass, dwFlags, dwContext, INET_OPENURL);
3646 if(client == NULL)
3647 break;
3648 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3649 if(client1 == NULL) {
3650 InternetCloseHandle(client);
3651 break;
3653 break;
3655 case INTERNET_SCHEME_HTTP:
3656 case INTERNET_SCHEME_HTTPS: {
3657 LPCWSTR accept[2] = { L"*/*", NULL };
3659 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3661 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3662 res = HTTP_Connect(hIC, host, urlComponents.nPort,
3663 user, pass, dwFlags, dwContext, INET_OPENURL, &client);
3664 if(res != ERROR_SUCCESS) {
3665 INTERNET_SetLastError(res);
3666 break;
3669 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3670 if(client1 == NULL) {
3671 InternetCloseHandle(client);
3672 break;
3674 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3675 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3676 GetLastError() != ERROR_IO_PENDING) {
3677 InternetCloseHandle(client1);
3678 client1 = NULL;
3679 break;
3682 case INTERNET_SCHEME_GOPHER:
3683 /* gopher doesn't seem to be implemented in wine, but it's supposed
3684 * to be supported by InternetOpenUrlA. */
3685 default:
3686 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3687 break;
3690 TRACE(" %p <--\n", client1);
3692 heap_free(host);
3693 heap_free(path);
3694 heap_free(user);
3695 heap_free(pass);
3696 return client1;
3699 /**********************************************************
3700 * InternetOpenUrlW (WININET.@)
3702 * Opens an URL
3704 * RETURNS
3705 * handle of connection or NULL on failure
3707 typedef struct {
3708 task_header_t hdr;
3709 WCHAR *url;
3710 WCHAR *headers;
3711 DWORD headers_len;
3712 DWORD flags;
3713 DWORD_PTR context;
3714 } open_url_task_t;
3716 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3718 open_url_task_t *task = (open_url_task_t*)hdr;
3720 TRACE("%p\n", task->hdr.hdr);
3722 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3723 task->headers_len, task->flags, task->context);
3724 heap_free(task->url);
3725 heap_free(task->headers);
3728 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3729 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3731 HINTERNET ret = NULL;
3732 appinfo_t *hIC = NULL;
3734 if (TRACE_ON(wininet)) {
3735 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3736 dwHeadersLength, dwFlags, dwContext);
3737 TRACE(" flags :");
3738 dump_INTERNET_FLAGS(dwFlags);
3741 if (!lpszUrl)
3743 SetLastError(ERROR_INVALID_PARAMETER);
3744 goto lend;
3747 hIC = (appinfo_t*)get_handle_object( hInternet );
3748 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3749 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3750 goto lend;
3753 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3754 open_url_task_t *task;
3756 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3757 task->url = heap_strdupW(lpszUrl);
3758 task->headers = heap_strdupW(lpszHeaders);
3759 task->headers_len = dwHeadersLength;
3760 task->flags = dwFlags;
3761 task->context = dwContext;
3763 INTERNET_AsyncCall(&task->hdr);
3764 SetLastError(ERROR_IO_PENDING);
3765 } else {
3766 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3769 lend:
3770 if( hIC )
3771 WININET_Release( &hIC->hdr );
3772 TRACE(" %p <--\n", ret);
3774 return ret;
3777 /**********************************************************
3778 * InternetOpenUrlA (WININET.@)
3780 * Opens an URL
3782 * RETURNS
3783 * handle of connection or NULL on failure
3785 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3786 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3788 HINTERNET rc = NULL;
3789 LPWSTR szUrl = NULL;
3790 WCHAR *headers = NULL;
3792 TRACE("\n");
3794 if(lpszUrl) {
3795 szUrl = heap_strdupAtoW(lpszUrl);
3796 if(!szUrl)
3797 return NULL;
3800 if(lpszHeaders) {
3801 headers = heap_strndupAtoW(lpszHeaders, dwHeadersLength, &dwHeadersLength);
3802 if(!headers) {
3803 heap_free(szUrl);
3804 return NULL;
3808 rc = InternetOpenUrlW(hInternet, szUrl, headers, dwHeadersLength, dwFlags, dwContext);
3810 heap_free(szUrl);
3811 heap_free(headers);
3812 return rc;
3816 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3818 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3820 if (lpwite)
3822 lpwite->dwError = 0;
3823 lpwite->response[0] = '\0';
3826 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3828 heap_free(lpwite);
3829 return NULL;
3831 return lpwite;
3835 /***********************************************************************
3836 * INTERNET_SetLastError (internal)
3838 * Set last thread specific error
3840 * RETURNS
3843 void INTERNET_SetLastError(DWORD dwError)
3845 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3847 if (!lpwite)
3848 lpwite = INTERNET_AllocThreadError();
3850 SetLastError(dwError);
3851 if(lpwite)
3852 lpwite->dwError = dwError;
3856 /***********************************************************************
3857 * INTERNET_GetLastError (internal)
3859 * Get last thread specific error
3861 * RETURNS
3864 DWORD INTERNET_GetLastError(void)
3866 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3867 if (!lpwite) return 0;
3868 /* TlsGetValue clears last error, so set it again here */
3869 SetLastError(lpwite->dwError);
3870 return lpwite->dwError;
3874 /***********************************************************************
3875 * INTERNET_WorkerThreadFunc (internal)
3877 * Worker thread execution function
3879 * RETURNS
3882 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3884 task_header_t *task = lpvParam;
3886 TRACE("\n");
3888 task->proc(task);
3889 WININET_Release(task->hdr);
3890 heap_free(task);
3892 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3894 heap_free(TlsGetValue(g_dwTlsErrIndex));
3895 TlsSetValue(g_dwTlsErrIndex, NULL);
3897 return TRUE;
3900 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3902 task_header_t *task;
3904 task = heap_alloc(size);
3905 if(!task)
3906 return NULL;
3908 task->hdr = WININET_AddRef(hdr);
3909 task->proc = proc;
3910 return task;
3913 /***********************************************************************
3914 * INTERNET_AsyncCall (internal)
3916 * Retrieves work request from queue
3918 * RETURNS
3921 DWORD INTERNET_AsyncCall(task_header_t *task)
3923 BOOL bSuccess;
3925 TRACE("\n");
3927 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3928 if (!bSuccess)
3930 heap_free(task);
3931 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3933 return ERROR_SUCCESS;
3937 /***********************************************************************
3938 * INTERNET_GetResponseBuffer (internal)
3940 * RETURNS
3943 LPSTR INTERNET_GetResponseBuffer(void)
3945 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3946 if (!lpwite)
3947 lpwite = INTERNET_AllocThreadError();
3948 TRACE("\n");
3949 return lpwite->response;
3952 /**********************************************************
3953 * InternetQueryDataAvailable (WININET.@)
3955 * Determines how much data is available to be read.
3957 * RETURNS
3958 * TRUE on success, FALSE if an error occurred. If
3959 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3960 * no data is presently available, FALSE is returned with
3961 * the last error ERROR_IO_PENDING; a callback with status
3962 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3963 * data is available.
3965 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3966 LPDWORD lpdwNumberOfBytesAvailable,
3967 DWORD dwFlags, DWORD_PTR dwContext)
3969 object_header_t *hdr;
3970 DWORD res;
3972 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3974 hdr = get_handle_object( hFile );
3975 if (!hdr) {
3976 SetLastError(ERROR_INVALID_HANDLE);
3977 return FALSE;
3980 if(hdr->vtbl->QueryDataAvailable) {
3981 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3982 }else {
3983 WARN("wrong handle\n");
3984 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3987 WININET_Release(hdr);
3989 if(res != ERROR_SUCCESS)
3990 SetLastError(res);
3991 return res == ERROR_SUCCESS;
3994 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
3996 req_file_t *req_file;
3998 req_file = heap_alloc_zero(sizeof(*req_file));
3999 if(!req_file)
4000 return ERROR_NOT_ENOUGH_MEMORY;
4002 req_file->ref = 1;
4004 req_file->file_name = heap_strdupW(file_name);
4005 if(!req_file->file_name) {
4006 heap_free(req_file);
4007 return ERROR_NOT_ENOUGH_MEMORY;
4010 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
4011 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
4012 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
4013 req_file_release(req_file);
4014 return GetLastError();
4017 *ret = req_file;
4018 return ERROR_SUCCESS;
4021 void req_file_release(req_file_t *req_file)
4023 if(InterlockedDecrement(&req_file->ref))
4024 return;
4026 if(!req_file->is_committed)
4027 DeleteFileW(req_file->file_name);
4028 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
4029 CloseHandle(req_file->file_handle);
4030 heap_free(req_file->file_name);
4031 heap_free(req_file->url);
4032 heap_free(req_file);
4035 /***********************************************************************
4036 * InternetLockRequestFile (WININET.@)
4038 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
4040 req_file_t *req_file = NULL;
4041 object_header_t *hdr;
4042 DWORD res;
4044 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
4046 hdr = get_handle_object(hInternet);
4047 if (!hdr) {
4048 SetLastError(ERROR_INVALID_HANDLE);
4049 return FALSE;
4052 if(hdr->vtbl->LockRequestFile) {
4053 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
4054 }else {
4055 WARN("wrong handle\n");
4056 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4059 WININET_Release(hdr);
4061 *lphLockReqHandle = req_file;
4062 if(res != ERROR_SUCCESS)
4063 SetLastError(res);
4064 return res == ERROR_SUCCESS;
4067 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
4069 TRACE("(%p)\n", hLockHandle);
4071 req_file_release(hLockHandle);
4072 return TRUE;
4076 /***********************************************************************
4077 * InternetAutodial (WININET.@)
4079 * On windows this function is supposed to dial the default internet
4080 * connection. We don't want to have Wine dial out to the internet so
4081 * we return TRUE by default. It might be nice to check if we are connected.
4083 * RETURNS
4084 * TRUE on success
4085 * FALSE on failure
4088 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4090 FIXME("STUB\n");
4092 /* Tell that we are connected to the internet. */
4093 return TRUE;
4096 /***********************************************************************
4097 * InternetAutodialHangup (WININET.@)
4099 * Hangs up a connection made with InternetAutodial
4101 * PARAM
4102 * dwReserved
4103 * RETURNS
4104 * TRUE on success
4105 * FALSE on failure
4108 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4110 FIXME("STUB\n");
4112 /* we didn't dial, we don't disconnect */
4113 return TRUE;
4116 /***********************************************************************
4117 * InternetCombineUrlA (WININET.@)
4119 * Combine a base URL with a relative URL
4121 * RETURNS
4122 * TRUE on success
4123 * FALSE on failure
4127 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4128 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4129 DWORD dwFlags)
4131 HRESULT hr=S_OK;
4133 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4135 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4136 dwFlags ^= ICU_NO_ENCODE;
4137 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4139 return (hr==S_OK);
4142 /***********************************************************************
4143 * InternetCombineUrlW (WININET.@)
4145 * Combine a base URL with a relative URL
4147 * RETURNS
4148 * TRUE on success
4149 * FALSE on failure
4153 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4154 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4155 DWORD dwFlags)
4157 HRESULT hr=S_OK;
4159 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4161 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4162 dwFlags ^= ICU_NO_ENCODE;
4163 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4165 return (hr==S_OK);
4168 /* max port num is 65535 => 5 digits */
4169 #define MAX_WORD_DIGITS 5
4171 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4172 (url)->dw##component##Length : lstrlenW((url)->lpsz##component))
4173 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4174 (url)->dw##component##Length : strlen((url)->lpsz##component))
4176 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4178 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4179 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4180 return TRUE;
4181 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4182 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4183 return TRUE;
4184 if ((nScheme == INTERNET_SCHEME_FTP) &&
4185 (nPort == INTERNET_DEFAULT_FTP_PORT))
4186 return TRUE;
4187 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4188 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4189 return TRUE;
4191 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4192 return TRUE;
4194 return FALSE;
4197 /* opaque urls do not fit into the standard url hierarchy and don't have
4198 * two following slashes */
4199 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4201 return (nScheme != INTERNET_SCHEME_FTP) &&
4202 (nScheme != INTERNET_SCHEME_GOPHER) &&
4203 (nScheme != INTERNET_SCHEME_HTTP) &&
4204 (nScheme != INTERNET_SCHEME_HTTPS) &&
4205 (nScheme != INTERNET_SCHEME_FILE);
4208 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4210 int index;
4211 if (scheme < INTERNET_SCHEME_FIRST)
4212 return NULL;
4213 index = scheme - INTERNET_SCHEME_FIRST;
4214 if (index >= ARRAY_SIZE(url_schemes))
4215 return NULL;
4216 return url_schemes[index];
4219 /* we can calculate using ansi strings because we're just
4220 * calculating string length, not size
4222 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4223 LPDWORD lpdwUrlLength)
4225 INTERNET_SCHEME nScheme;
4227 *lpdwUrlLength = 0;
4229 if (lpUrlComponents->lpszScheme)
4231 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4232 *lpdwUrlLength += dwLen;
4233 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4235 else
4237 LPCWSTR scheme;
4239 nScheme = lpUrlComponents->nScheme;
4241 if (nScheme == INTERNET_SCHEME_DEFAULT)
4242 nScheme = INTERNET_SCHEME_HTTP;
4243 scheme = INTERNET_GetSchemeString(nScheme);
4244 *lpdwUrlLength += lstrlenW(scheme);
4247 (*lpdwUrlLength)++; /* ':' */
4248 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4249 *lpdwUrlLength += strlen("//");
4251 if (lpUrlComponents->lpszUserName)
4253 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4254 *lpdwUrlLength += strlen("@");
4256 else
4258 if (lpUrlComponents->lpszPassword)
4260 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4261 return FALSE;
4265 if (lpUrlComponents->lpszPassword)
4267 *lpdwUrlLength += strlen(":");
4268 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4271 if (lpUrlComponents->lpszHostName)
4273 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4275 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4277 WCHAR port[MAX_WORD_DIGITS + 1];
4279 _ltow(lpUrlComponents->nPort, port, 10);
4280 *lpdwUrlLength += lstrlenW(port);
4281 *lpdwUrlLength += strlen(":");
4284 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4285 (*lpdwUrlLength)++; /* '/' */
4288 if (lpUrlComponents->lpszUrlPath)
4289 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4291 if (lpUrlComponents->lpszExtraInfo)
4292 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4294 return TRUE;
4297 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4299 INT len;
4301 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4303 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4304 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4305 urlCompW->nScheme = lpUrlComponents->nScheme;
4306 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4307 urlCompW->nPort = lpUrlComponents->nPort;
4308 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4309 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4310 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4311 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4313 if (lpUrlComponents->lpszScheme)
4315 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4316 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4317 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4318 -1, urlCompW->lpszScheme, len);
4321 if (lpUrlComponents->lpszHostName)
4323 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4324 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4325 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4326 -1, urlCompW->lpszHostName, len);
4329 if (lpUrlComponents->lpszUserName)
4331 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4332 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4333 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4334 -1, urlCompW->lpszUserName, len);
4337 if (lpUrlComponents->lpszPassword)
4339 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4340 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4341 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4342 -1, urlCompW->lpszPassword, len);
4345 if (lpUrlComponents->lpszUrlPath)
4347 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4348 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4349 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4350 -1, urlCompW->lpszUrlPath, len);
4353 if (lpUrlComponents->lpszExtraInfo)
4355 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4356 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4357 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4358 -1, urlCompW->lpszExtraInfo, len);
4362 /***********************************************************************
4363 * InternetCreateUrlA (WININET.@)
4365 * See InternetCreateUrlW.
4367 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4368 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4370 BOOL ret;
4371 LPWSTR urlW = NULL;
4372 URL_COMPONENTSW urlCompW;
4374 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4376 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4378 SetLastError(ERROR_INVALID_PARAMETER);
4379 return FALSE;
4382 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4384 if (lpszUrl)
4385 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4387 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4389 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4390 *lpdwUrlLength /= sizeof(WCHAR);
4392 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4393 * minus one, so add one to leave room for NULL terminator
4395 if (ret)
4396 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4398 heap_free(urlCompW.lpszScheme);
4399 heap_free(urlCompW.lpszHostName);
4400 heap_free(urlCompW.lpszUserName);
4401 heap_free(urlCompW.lpszPassword);
4402 heap_free(urlCompW.lpszUrlPath);
4403 heap_free(urlCompW.lpszExtraInfo);
4404 heap_free(urlW);
4405 return ret;
4408 /***********************************************************************
4409 * InternetCreateUrlW (WININET.@)
4411 * Creates a URL from its component parts.
4413 * PARAMS
4414 * lpUrlComponents [I] URL Components.
4415 * dwFlags [I] Flags. See notes.
4416 * lpszUrl [I] Buffer in which to store the created URL.
4417 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4418 * lpszUrl in characters. On output, the number of bytes
4419 * required to store the URL including terminator.
4421 * NOTES
4423 * The dwFlags parameter can be zero or more of the following:
4424 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4426 * RETURNS
4427 * TRUE on success
4428 * FALSE on failure
4431 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4432 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4434 DWORD dwLen;
4435 INTERNET_SCHEME nScheme;
4437 static const WCHAR slashSlashW[] = {'/','/'};
4439 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4441 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4443 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4444 return FALSE;
4447 if (!calc_url_length(lpUrlComponents, &dwLen))
4448 return FALSE;
4450 if (!lpszUrl || *lpdwUrlLength < dwLen)
4452 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4453 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4454 return FALSE;
4457 *lpdwUrlLength = dwLen;
4458 lpszUrl[0] = 0x00;
4460 dwLen = 0;
4462 if (lpUrlComponents->lpszScheme)
4464 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4465 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4466 lpszUrl += dwLen;
4468 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4470 else
4472 LPCWSTR scheme;
4473 nScheme = lpUrlComponents->nScheme;
4475 if (nScheme == INTERNET_SCHEME_DEFAULT)
4476 nScheme = INTERNET_SCHEME_HTTP;
4478 scheme = INTERNET_GetSchemeString(nScheme);
4479 dwLen = lstrlenW(scheme);
4480 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4481 lpszUrl += dwLen;
4484 /* all schemes are followed by at least a colon */
4485 *lpszUrl = ':';
4486 lpszUrl++;
4488 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4490 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4491 lpszUrl += ARRAY_SIZE(slashSlashW);
4494 if (lpUrlComponents->lpszUserName)
4496 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4497 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4498 lpszUrl += dwLen;
4500 if (lpUrlComponents->lpszPassword)
4502 *lpszUrl = ':';
4503 lpszUrl++;
4505 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4506 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4507 lpszUrl += dwLen;
4510 *lpszUrl = '@';
4511 lpszUrl++;
4514 if (lpUrlComponents->lpszHostName)
4516 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4517 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4518 lpszUrl += dwLen;
4520 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4522 *lpszUrl++ = ':';
4523 _ltow(lpUrlComponents->nPort, lpszUrl, 10);
4524 lpszUrl += lstrlenW(lpszUrl);
4527 /* add slash between hostname and path if necessary */
4528 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4530 *lpszUrl = '/';
4531 lpszUrl++;
4535 if (lpUrlComponents->lpszUrlPath)
4537 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4538 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4539 lpszUrl += dwLen;
4542 if (lpUrlComponents->lpszExtraInfo)
4544 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4545 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4546 lpszUrl += dwLen;
4549 *lpszUrl = '\0';
4551 return TRUE;
4554 /***********************************************************************
4555 * InternetConfirmZoneCrossingA (WININET.@)
4558 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4560 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4561 return ERROR_SUCCESS;
4564 /***********************************************************************
4565 * InternetConfirmZoneCrossingW (WININET.@)
4568 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4570 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4571 return ERROR_SUCCESS;
4574 static DWORD zone_preference = 3;
4576 /***********************************************************************
4577 * PrivacySetZonePreferenceW (WININET.@)
4579 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4581 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4583 zone_preference = template;
4584 return 0;
4587 /***********************************************************************
4588 * PrivacyGetZonePreferenceW (WININET.@)
4590 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4591 LPWSTR preference, LPDWORD length )
4593 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4595 if (template) *template = zone_preference;
4596 return 0;
4599 /***********************************************************************
4600 * InternetGetSecurityInfoByURLA (WININET.@)
4602 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4604 WCHAR *url;
4605 BOOL res;
4607 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4609 url = heap_strdupAtoW(lpszURL);
4610 if(!url)
4611 return FALSE;
4613 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4614 heap_free(url);
4615 return res;
4618 /***********************************************************************
4619 * InternetGetSecurityInfoByURLW (WININET.@)
4621 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4623 URL_COMPONENTSW url = {sizeof(url)};
4624 server_t *server;
4625 BOOL res;
4627 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4629 if (!ppCertChain && !pdwSecureFlags) {
4630 SetLastError(ERROR_INVALID_PARAMETER);
4631 return FALSE;
4634 url.dwHostNameLength = 1;
4635 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4636 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4637 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4638 return FALSE;
4641 server = get_server(substr(url.lpszHostName, url.dwHostNameLength), url.nPort, TRUE, FALSE);
4642 if(!server) {
4643 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4644 return FALSE;
4647 if(server->cert_chain) {
4648 if(pdwSecureFlags)
4649 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4651 if(ppCertChain && !(*ppCertChain = CertDuplicateCertificateChain(server->cert_chain)))
4652 res = FALSE;
4653 }else {
4654 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4655 res = FALSE;
4658 server_release(server);
4659 return res;
4662 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4663 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4665 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4666 lpdwConnection, dwReserved);
4667 return ERROR_SUCCESS;
4670 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4671 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4673 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4674 lpdwConnection, dwReserved);
4675 return ERROR_SUCCESS;
4678 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4680 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4681 return TRUE;
4684 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4686 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4687 return TRUE;
4690 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4692 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4693 return ERROR_SUCCESS;
4696 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4697 PBYTE pbHexHash )
4699 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4700 debugstr_w(pwszTarget), pbHexHash);
4701 return FALSE;
4704 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4706 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4707 return FALSE;
4710 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4712 FIXME("(%p, %08lx) stub\n", a, b);
4713 return FALSE;
4716 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4718 FIXME("%p: stub\n", parent);
4719 return 0;