po: Update Lithuanian translation.
[wine.git] / dlls / wininet / internet.c
blob16dc200c1371f1eecb95c7f98946f2f14a2aa716
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 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
98 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
99 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
100 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
101 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
102 static const WCHAR szProxyOverride[] = { 'P','r','o','x','y','O','v','e','r','r','i','d','e', 0 };
104 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
106 UINT_PTR handle = 0, num;
107 object_header_t *ret;
108 object_header_t **p;
109 BOOL res = TRUE;
111 ret = heap_alloc_zero(size);
112 if(!ret)
113 return NULL;
115 list_init(&ret->children);
117 EnterCriticalSection( &WININET_cs );
119 if(!handle_table_size) {
120 num = 16;
121 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
122 if(p) {
123 handle_table = p;
124 handle_table_size = num;
125 next_handle = 1;
126 }else {
127 res = FALSE;
129 }else if(next_handle == handle_table_size) {
130 num = handle_table_size * 2;
131 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
132 if(p) {
133 handle_table = p;
134 handle_table_size = num;
135 }else {
136 res = FALSE;
140 if(res) {
141 handle = next_handle;
142 if(handle_table[handle])
143 ERR("handle isn't free but should be\n");
144 handle_table[handle] = ret;
145 ret->valid_handle = TRUE;
147 while(next_handle < handle_table_size && handle_table[next_handle])
148 next_handle++;
151 LeaveCriticalSection( &WININET_cs );
153 if(!res) {
154 heap_free(ret);
155 return NULL;
158 ret->vtbl = vtbl;
159 ret->refs = 1;
160 ret->hInternet = (HINTERNET)handle;
162 if(parent) {
163 ret->lpfnStatusCB = parent->lpfnStatusCB;
164 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
167 return ret;
170 object_header_t *WININET_AddRef( object_header_t *info )
172 ULONG refs = InterlockedIncrement(&info->refs);
173 TRACE("%p -> refcount = %d\n", info, refs );
174 return info;
177 object_header_t *get_handle_object( HINTERNET hinternet )
179 object_header_t *info = NULL;
180 UINT_PTR handle = (UINT_PTR) hinternet;
182 EnterCriticalSection( &WININET_cs );
184 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
185 info = WININET_AddRef(handle_table[handle]);
187 LeaveCriticalSection( &WININET_cs );
189 TRACE("handle %ld -> %p\n", handle, info);
191 return info;
194 static void invalidate_handle(object_header_t *info)
196 object_header_t *child, *next;
198 if(!info->valid_handle)
199 return;
200 info->valid_handle = FALSE;
202 /* Free all children as native does */
203 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
205 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
206 invalidate_handle( child );
209 WININET_Release(info);
212 BOOL WININET_Release( object_header_t *info )
214 ULONG refs = InterlockedDecrement(&info->refs);
215 TRACE( "object %p refcount = %d\n", info, refs );
216 if( !refs )
218 invalidate_handle(info);
219 if ( info->vtbl->CloseConnection )
221 TRACE( "closing connection %p\n", info);
222 info->vtbl->CloseConnection( info );
224 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
225 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
226 || !(info->dwInternalFlags & INET_OPENURL))
228 INTERNET_SendCallback(info, info->dwContext,
229 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
230 sizeof(HINTERNET));
232 TRACE( "destroying object %p\n", info);
233 if ( info->htype != WH_HINIT )
234 list_remove( &info->entry );
235 info->vtbl->Destroy( info );
237 if(info->hInternet) {
238 UINT_PTR handle = (UINT_PTR)info->hInternet;
240 EnterCriticalSection( &WININET_cs );
242 handle_table[handle] = NULL;
243 if(next_handle > handle)
244 next_handle = handle;
246 LeaveCriticalSection( &WININET_cs );
249 heap_free(info);
251 return TRUE;
254 /***********************************************************************
255 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
257 * PARAMS
258 * hinstDLL [I] handle to the DLL's instance
259 * fdwReason [I]
260 * lpvReserved [I] reserved, must be NULL
262 * RETURNS
263 * Success: TRUE
264 * Failure: FALSE
267 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
269 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
271 switch (fdwReason) {
272 case DLL_PROCESS_ATTACH:
274 g_dwTlsErrIndex = TlsAlloc();
276 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
277 return FALSE;
279 if(!init_urlcache())
281 TlsFree(g_dwTlsErrIndex);
282 return FALSE;
285 WININET_hModule = hinstDLL;
286 break;
288 case DLL_THREAD_ATTACH:
289 break;
291 case DLL_THREAD_DETACH:
292 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
294 heap_free(TlsGetValue(g_dwTlsErrIndex));
296 break;
298 case DLL_PROCESS_DETACH:
299 if (lpvReserved) break;
300 collect_connections(COLLECT_CLEANUP);
301 NETCON_unload();
302 free_urlcache();
303 free_cookie();
305 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
307 heap_free(TlsGetValue(g_dwTlsErrIndex));
308 TlsFree(g_dwTlsErrIndex);
310 break;
312 return TRUE;
315 /***********************************************************************
316 * DllInstall (WININET.@)
318 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
320 FIXME("(%x %s): stub\n", bInstall, debugstr_w(cmdline));
321 return S_OK;
324 /***********************************************************************
325 * INTERNET_SaveProxySettings
327 * Stores the proxy settings given by lpwai into the registry
329 * RETURNS
330 * ERROR_SUCCESS if no error, or error code on fail
332 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
334 HKEY key;
335 LONG ret;
337 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
338 return ret;
340 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
342 RegCloseKey( key );
343 return ret;
346 if (lpwpi->proxy)
348 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
350 RegCloseKey( key );
351 return ret;
354 else
356 if ((ret = RegDeleteValueW( key, szProxyServer )) && ret != ERROR_FILE_NOT_FOUND)
358 RegCloseKey( key );
359 return ret;
363 RegCloseKey(key);
364 return ERROR_SUCCESS;
367 /***********************************************************************
368 * INTERNET_FindProxyForProtocol
370 * Searches the proxy string for a proxy of the given protocol.
371 * Returns the found proxy, or the default proxy if none of the given
372 * protocol is found.
374 * PARAMETERS
375 * szProxy [In] proxy string to search
376 * proto [In] protocol to search for, e.g. "http"
377 * foundProxy [Out] found proxy
378 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
380 * RETURNS
381 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
382 * *foundProxyLen is set to the required size in WCHARs, including the
383 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
385 WCHAR *INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto)
387 WCHAR *ret = NULL;
388 const WCHAR *ptr;
390 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
392 /* First, look for the specified protocol (proto=scheme://host:port) */
393 for (ptr = szProxy; ptr && *ptr; )
395 LPCWSTR end, equal;
397 if (!(end = wcschr(ptr, ' ')))
398 end = ptr + lstrlenW(ptr);
399 if ((equal = wcschr(ptr, '=')) && equal < end &&
400 equal - ptr == lstrlenW(proto) &&
401 !wcsnicmp(proto, ptr, lstrlenW(proto)))
403 ret = heap_strndupW(equal + 1, end - equal - 1);
404 TRACE("found proxy for %s: %s\n", debugstr_w(proto), debugstr_w(ret));
405 return ret;
407 if (*end == ' ')
408 ptr = end + 1;
409 else
410 ptr = end;
413 /* It wasn't found: look for no protocol */
414 for (ptr = szProxy; ptr && *ptr; )
416 LPCWSTR end;
418 if (!(end = wcschr(ptr, ' ')))
419 end = ptr + lstrlenW(ptr);
420 if (!wcschr(ptr, '='))
422 ret = heap_strndupW(ptr, end - ptr);
423 TRACE("found proxy for %s: %s\n", debugstr_w(proto), debugstr_w(ret));
424 return ret;
426 if (*end == ' ')
427 ptr = end + 1;
428 else
429 ptr = end;
432 return NULL;
435 /***********************************************************************
436 * InternetInitializeAutoProxyDll (WININET.@)
438 * Setup the internal proxy
440 * PARAMETERS
441 * dwReserved
443 * RETURNS
444 * FALSE on failure
447 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
449 FIXME("STUB\n");
450 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
451 return FALSE;
454 /***********************************************************************
455 * DetectAutoProxyUrl (WININET.@)
457 * Auto detect the proxy url
459 * RETURNS
460 * FALSE on failure
463 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
464 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
466 FIXME("STUB\n");
467 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
468 return FALSE;
471 static void FreeProxyInfo( proxyinfo_t *lpwpi )
473 heap_free(lpwpi->proxy);
474 heap_free(lpwpi->proxyBypass);
475 heap_free(lpwpi->proxyUsername);
476 heap_free(lpwpi->proxyPassword);
479 static proxyinfo_t *global_proxy;
481 static void free_global_proxy( void )
483 EnterCriticalSection( &WININET_cs );
484 if (global_proxy)
486 FreeProxyInfo( global_proxy );
487 heap_free( global_proxy );
489 LeaveCriticalSection( &WININET_cs );
492 static BOOL parse_proxy_url( proxyinfo_t *info, const WCHAR *url )
494 static const WCHAR fmt[] = {'%','.','*','s',':','%','u',0};
495 URL_COMPONENTSW uc = {sizeof(uc)};
497 uc.dwHostNameLength = 1;
498 uc.dwUserNameLength = 1;
499 uc.dwPasswordLength = 1;
501 if (!InternetCrackUrlW( url, 0, 0, &uc )) return FALSE;
502 if (!uc.dwHostNameLength)
504 if (!(info->proxy = heap_strdupW( url ))) return FALSE;
505 info->proxyUsername = NULL;
506 info->proxyPassword = NULL;
507 return TRUE;
509 if (!(info->proxy = heap_alloc( (uc.dwHostNameLength + 12) * sizeof(WCHAR) ))) return FALSE;
510 swprintf( info->proxy, uc.dwHostNameLength + 12, fmt, uc.dwHostNameLength, uc.lpszHostName, uc.nPort );
512 if (!uc.dwUserNameLength) info->proxyUsername = NULL;
513 else if (!(info->proxyUsername = heap_strndupW( uc.lpszUserName, uc.dwUserNameLength )))
515 heap_free( info->proxy );
516 return FALSE;
518 if (!uc.dwPasswordLength) info->proxyPassword = NULL;
519 else if (!(info->proxyPassword = heap_strndupW( uc.lpszPassword, uc.dwPasswordLength )))
521 heap_free( info->proxyUsername );
522 heap_free( info->proxy );
523 return FALSE;
525 return TRUE;
528 /***********************************************************************
529 * INTERNET_LoadProxySettings
531 * Loads proxy information from process-wide global settings, the registry,
532 * or the environment into lpwpi.
534 * The caller should call FreeProxyInfo when done with lpwpi.
536 * FIXME:
537 * The proxy may be specified in the form 'http=proxy.my.org'
538 * Presumably that means there can be ftp=ftpproxy.my.org too.
540 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
542 HKEY key;
543 DWORD type, len;
544 const WCHAR *envproxy;
545 LONG ret;
547 memset( lpwpi, 0, sizeof(*lpwpi) );
549 EnterCriticalSection( &WININET_cs );
550 if (global_proxy)
552 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
553 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
554 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
556 LeaveCriticalSection( &WININET_cs );
558 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
560 FreeProxyInfo( lpwpi );
561 return ret;
564 len = sizeof(DWORD);
565 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
567 lpwpi->proxyEnabled = 0;
568 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
570 FreeProxyInfo( lpwpi );
571 RegCloseKey( key );
572 return ret;
576 if (!(envproxy = _wgetenv( L"http_proxy" )) || lpwpi->proxyEnabled)
578 /* figure out how much memory the proxy setting takes */
579 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
581 LPWSTR szProxy, p;
582 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
584 if (!(szProxy = heap_alloc(len)))
586 RegCloseKey( key );
587 FreeProxyInfo( lpwpi );
588 return ERROR_OUTOFMEMORY;
590 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
592 /* find the http proxy, and strip away everything else */
593 p = wcsstr( szProxy, szHttp );
594 if (p)
596 p += lstrlenW( szHttp );
597 lstrcpyW( szProxy, p );
599 p = wcschr( szProxy, ';' );
600 if (p) *p = 0;
602 FreeProxyInfo( lpwpi );
603 lpwpi->proxy = szProxy;
604 lpwpi->proxyBypass = NULL;
606 TRACE("http proxy (from registry) = %s\n", debugstr_w(lpwpi->proxy));
608 else
610 TRACE("No proxy server settings in registry.\n");
611 FreeProxyInfo( lpwpi );
612 lpwpi->proxy = NULL;
613 lpwpi->proxyBypass = NULL;
616 else if (envproxy)
618 FreeProxyInfo( lpwpi );
619 if (parse_proxy_url( lpwpi, envproxy ))
621 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
622 lpwpi->proxyEnabled = 1;
623 lpwpi->proxyBypass = NULL;
625 else
627 WARN("failed to parse http_proxy value %s\n", debugstr_w(envproxy));
628 lpwpi->proxyEnabled = 0;
629 lpwpi->proxy = NULL;
630 lpwpi->proxyBypass = NULL;
634 if (lpwpi->proxyEnabled)
636 TRACE("Proxy is enabled.\n");
638 if (!(envproxy = _wgetenv( L"no_proxy" )))
640 /* figure out how much memory the proxy setting takes */
641 if (!RegQueryValueExW( key, szProxyOverride, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
643 LPWSTR szProxy;
645 if (!(szProxy = heap_alloc(len)))
647 RegCloseKey( key );
648 return ERROR_OUTOFMEMORY;
650 RegQueryValueExW( key, szProxyOverride, NULL, &type, (BYTE*)szProxy, &len );
652 heap_free( lpwpi->proxyBypass );
653 lpwpi->proxyBypass = szProxy;
655 TRACE("http proxy bypass (from registry) = %s\n", debugstr_w(lpwpi->proxyBypass));
657 else
659 heap_free( lpwpi->proxyBypass );
660 lpwpi->proxyBypass = NULL;
662 TRACE("No proxy bypass server settings in registry.\n");
665 else
667 WCHAR *envproxyW;
669 if (!(envproxyW = heap_alloc(lstrlenW(envproxy) * sizeof(WCHAR))))
671 RegCloseKey( key );
672 return ERROR_OUTOFMEMORY;
674 lstrcpyW( envproxyW, envproxy );
676 heap_free( lpwpi->proxyBypass );
677 lpwpi->proxyBypass = envproxyW;
679 TRACE("http proxy bypass (from environment) = %s\n", debugstr_w(lpwpi->proxyBypass));
682 else TRACE("Proxy is disabled.\n");
684 RegCloseKey( key );
685 return ERROR_SUCCESS;
688 /***********************************************************************
689 * INTERNET_ConfigureProxy
691 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
693 proxyinfo_t wpi;
695 if (INTERNET_LoadProxySettings( &wpi ))
696 return FALSE;
698 if (wpi.proxyEnabled)
700 TRACE("http proxy = %s bypass = %s\n", debugstr_w(wpi.proxy), debugstr_w(wpi.proxyBypass));
702 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
703 lpwai->proxy = wpi.proxy;
704 lpwai->proxyBypass = wpi.proxyBypass;
705 lpwai->proxyUsername = wpi.proxyUsername;
706 lpwai->proxyPassword = wpi.proxyPassword;
707 return TRUE;
710 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
711 FreeProxyInfo(&wpi);
712 return FALSE;
715 /***********************************************************************
716 * dump_INTERNET_FLAGS
718 * Helper function to TRACE the internet flags.
720 * RETURNS
721 * None
724 static void dump_INTERNET_FLAGS(DWORD dwFlags)
726 #define FE(x) { x, #x }
727 static const wininet_flag_info flag[] = {
728 FE(INTERNET_FLAG_RELOAD),
729 FE(INTERNET_FLAG_RAW_DATA),
730 FE(INTERNET_FLAG_EXISTING_CONNECT),
731 FE(INTERNET_FLAG_ASYNC),
732 FE(INTERNET_FLAG_PASSIVE),
733 FE(INTERNET_FLAG_NO_CACHE_WRITE),
734 FE(INTERNET_FLAG_MAKE_PERSISTENT),
735 FE(INTERNET_FLAG_FROM_CACHE),
736 FE(INTERNET_FLAG_SECURE),
737 FE(INTERNET_FLAG_KEEP_CONNECTION),
738 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
739 FE(INTERNET_FLAG_READ_PREFETCH),
740 FE(INTERNET_FLAG_NO_COOKIES),
741 FE(INTERNET_FLAG_NO_AUTH),
742 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
743 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
744 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
745 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
746 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
747 FE(INTERNET_FLAG_RESYNCHRONIZE),
748 FE(INTERNET_FLAG_HYPERLINK),
749 FE(INTERNET_FLAG_NO_UI),
750 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
751 FE(INTERNET_FLAG_CACHE_ASYNC),
752 FE(INTERNET_FLAG_FORMS_SUBMIT),
753 FE(INTERNET_FLAG_NEED_FILE),
754 FE(INTERNET_FLAG_TRANSFER_ASCII),
755 FE(INTERNET_FLAG_TRANSFER_BINARY)
757 #undef FE
758 unsigned int i;
760 for (i = 0; i < ARRAY_SIZE(flag); i++) {
761 if (flag[i].val & dwFlags) {
762 TRACE(" %s", flag[i].name);
763 dwFlags &= ~flag[i].val;
766 if (dwFlags)
767 TRACE(" Unknown flags (%08x)\n", dwFlags);
768 else
769 TRACE("\n");
772 /***********************************************************************
773 * INTERNET_CloseHandle (internal)
775 * Close internet handle
778 static VOID APPINFO_Destroy(object_header_t *hdr)
780 appinfo_t *lpwai = (appinfo_t*)hdr;
782 TRACE("%p\n",lpwai);
784 heap_free(lpwai->agent);
785 heap_free(lpwai->proxy);
786 heap_free(lpwai->proxyBypass);
787 heap_free(lpwai->proxyUsername);
788 heap_free(lpwai->proxyPassword);
791 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
793 appinfo_t *ai = (appinfo_t*)hdr;
795 switch(option) {
796 case INTERNET_OPTION_HANDLE_TYPE:
797 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
799 if (*size < sizeof(ULONG))
800 return ERROR_INSUFFICIENT_BUFFER;
802 *size = sizeof(DWORD);
803 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
804 return ERROR_SUCCESS;
806 case INTERNET_OPTION_USER_AGENT: {
807 DWORD bufsize;
809 TRACE("INTERNET_OPTION_USER_AGENT\n");
811 bufsize = *size;
813 if (unicode) {
814 DWORD len = ai->agent ? lstrlenW(ai->agent) : 0;
816 *size = (len + 1) * sizeof(WCHAR);
817 if(!buffer || bufsize < *size)
818 return ERROR_INSUFFICIENT_BUFFER;
820 if (ai->agent)
821 lstrcpyW(buffer, ai->agent);
822 else
823 *(WCHAR *)buffer = 0;
824 /* If the buffer is copied, the returned length doesn't include
825 * the NULL terminator.
827 *size = len;
828 }else {
829 if (ai->agent)
830 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
831 else
832 *size = 1;
833 if(!buffer || bufsize < *size)
834 return ERROR_INSUFFICIENT_BUFFER;
836 if (ai->agent)
837 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
838 else
839 *(char *)buffer = 0;
840 /* If the buffer is copied, the returned length doesn't include
841 * the NULL terminator.
843 *size -= 1;
846 return ERROR_SUCCESS;
849 case INTERNET_OPTION_PROXY:
850 if(!size) return ERROR_INVALID_PARAMETER;
851 if (unicode) {
852 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
853 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
854 LPWSTR proxy, proxy_bypass;
856 if (ai->proxy)
857 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
858 if (ai->proxyBypass)
859 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
860 if (!pi || *size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
862 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
863 return ERROR_INSUFFICIENT_BUFFER;
865 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
866 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
868 pi->dwAccessType = ai->accessType;
869 pi->lpszProxy = NULL;
870 pi->lpszProxyBypass = NULL;
871 if (ai->proxy) {
872 lstrcpyW(proxy, ai->proxy);
873 pi->lpszProxy = proxy;
876 if (ai->proxyBypass) {
877 lstrcpyW(proxy_bypass, ai->proxyBypass);
878 pi->lpszProxyBypass = proxy_bypass;
881 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
882 return ERROR_SUCCESS;
883 }else {
884 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
885 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
886 LPSTR proxy, proxy_bypass;
888 if (ai->proxy)
889 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
890 if (ai->proxyBypass)
891 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
892 NULL, 0, NULL, NULL);
893 if (!pi || *size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
895 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
896 return ERROR_INSUFFICIENT_BUFFER;
898 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
899 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
901 pi->dwAccessType = ai->accessType;
902 pi->lpszProxy = NULL;
903 pi->lpszProxyBypass = NULL;
904 if (ai->proxy) {
905 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
906 pi->lpszProxy = proxy;
909 if (ai->proxyBypass) {
910 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
911 proxyBypassBytesRequired, NULL, NULL);
912 pi->lpszProxyBypass = proxy_bypass;
915 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
916 return ERROR_SUCCESS;
919 case INTERNET_OPTION_CONNECT_TIMEOUT:
920 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
922 if (*size < sizeof(ULONG))
923 return ERROR_INSUFFICIENT_BUFFER;
925 *(ULONG*)buffer = ai->connect_timeout;
926 *size = sizeof(ULONG);
928 return ERROR_SUCCESS;
931 return INET_QueryOption(hdr, option, buffer, size, unicode);
934 static DWORD APPINFO_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
936 appinfo_t *ai = (appinfo_t*)hdr;
938 switch(option) {
939 case INTERNET_OPTION_CONNECT_TIMEOUT:
940 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
942 if(size != sizeof(connect_timeout))
943 return ERROR_INTERNET_BAD_OPTION_LENGTH;
944 if(!*(ULONG*)buf)
945 return ERROR_BAD_ARGUMENTS;
947 ai->connect_timeout = *(ULONG*)buf;
948 return ERROR_SUCCESS;
949 case INTERNET_OPTION_USER_AGENT:
950 heap_free(ai->agent);
951 if (!(ai->agent = heap_strdupW(buf))) return ERROR_OUTOFMEMORY;
952 return ERROR_SUCCESS;
953 case INTERNET_OPTION_REFRESH:
954 FIXME("INTERNET_OPTION_REFRESH\n");
955 return ERROR_SUCCESS;
958 return INET_SetOption(hdr, option, buf, size);
961 static const object_vtbl_t APPINFOVtbl = {
962 APPINFO_Destroy,
963 NULL,
964 APPINFO_QueryOption,
965 APPINFO_SetOption,
966 NULL,
967 NULL,
968 NULL
972 /***********************************************************************
973 * InternetOpenW (WININET.@)
975 * Per-application initialization of wininet
977 * RETURNS
978 * HINTERNET on success
979 * NULL on failure
982 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
983 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
985 appinfo_t *lpwai = NULL;
987 if (TRACE_ON(wininet)) {
988 #define FE(x) { x, #x }
989 static const wininet_flag_info access_type[] = {
990 FE(INTERNET_OPEN_TYPE_PRECONFIG),
991 FE(INTERNET_OPEN_TYPE_DIRECT),
992 FE(INTERNET_OPEN_TYPE_PROXY),
993 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
995 #undef FE
996 DWORD i;
997 const char *access_type_str = "Unknown";
999 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
1000 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
1001 for (i = 0; i < ARRAY_SIZE(access_type); i++) {
1002 if (access_type[i].val == dwAccessType) {
1003 access_type_str = access_type[i].name;
1004 break;
1007 TRACE(" access type : %s\n", access_type_str);
1008 TRACE(" flags :");
1009 dump_INTERNET_FLAGS(dwFlags);
1012 /* Clear any error information */
1013 INTERNET_SetLastError(0);
1015 if((dwAccessType == INTERNET_OPEN_TYPE_PROXY) && !lpszProxy) {
1016 SetLastError(ERROR_INVALID_PARAMETER);
1017 return NULL;
1020 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
1021 if (!lpwai) {
1022 SetLastError(ERROR_OUTOFMEMORY);
1023 return NULL;
1026 lpwai->hdr.htype = WH_HINIT;
1027 lpwai->hdr.dwFlags = dwFlags;
1028 lpwai->accessType = dwAccessType;
1029 lpwai->proxyUsername = NULL;
1030 lpwai->proxyPassword = NULL;
1031 lpwai->connect_timeout = connect_timeout;
1033 lpwai->agent = heap_strdupW(lpszAgent);
1034 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
1035 INTERNET_ConfigureProxy( lpwai );
1036 else if(dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
1037 lpwai->proxy = heap_strdupW(lpszProxy);
1038 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
1041 TRACE("returning %p\n", lpwai);
1043 return lpwai->hdr.hInternet;
1047 /***********************************************************************
1048 * InternetOpenA (WININET.@)
1050 * Per-application initialization of wininet
1052 * RETURNS
1053 * HINTERNET on success
1054 * NULL on failure
1057 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
1058 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
1060 WCHAR *szAgent, *szProxy, *szBypass;
1061 HINTERNET rc;
1063 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
1064 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
1066 szAgent = heap_strdupAtoW(lpszAgent);
1067 szProxy = heap_strdupAtoW(lpszProxy);
1068 szBypass = heap_strdupAtoW(lpszProxyBypass);
1070 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
1072 heap_free(szAgent);
1073 heap_free(szProxy);
1074 heap_free(szBypass);
1075 return rc;
1078 /***********************************************************************
1079 * InternetGetLastResponseInfoA (WININET.@)
1081 * Return last wininet error description on the calling thread
1083 * RETURNS
1084 * TRUE on success of writing to buffer
1085 * FALSE on failure
1088 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1089 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1091 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1093 TRACE("\n");
1095 if (lpwite)
1097 *lpdwError = lpwite->dwError;
1098 if (lpwite->dwError)
1100 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1101 *lpdwBufferLength = strlen(lpszBuffer);
1103 else
1104 *lpdwBufferLength = 0;
1106 else
1108 *lpdwError = 0;
1109 *lpdwBufferLength = 0;
1112 return TRUE;
1115 /***********************************************************************
1116 * InternetGetLastResponseInfoW (WININET.@)
1118 * Return last wininet error description on the calling thread
1120 * RETURNS
1121 * TRUE on success of writing to buffer
1122 * FALSE on failure
1125 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1126 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1128 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1130 TRACE("\n");
1132 if (lpwite)
1134 *lpdwError = lpwite->dwError;
1135 if (lpwite->dwError)
1137 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1138 *lpdwBufferLength = lstrlenW(lpszBuffer);
1140 else
1141 *lpdwBufferLength = 0;
1143 else
1145 *lpdwError = 0;
1146 *lpdwBufferLength = 0;
1149 return TRUE;
1152 /***********************************************************************
1153 * InternetGetConnectedState (WININET.@)
1155 * Return connected state
1157 * RETURNS
1158 * TRUE if connected
1159 * if lpdwStatus is not null, return the status (off line,
1160 * modem, lan...) in it.
1161 * FALSE if not connected
1163 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1165 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1167 return InternetGetConnectedStateExW(lpdwStatus, NULL, 0, dwReserved);
1171 /***********************************************************************
1172 * InternetGetConnectedStateExW (WININET.@)
1174 * Return connected state
1176 * PARAMS
1178 * lpdwStatus [O] Flags specifying the status of the internet connection.
1179 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1180 * dwNameLen [I] Size of the buffer, in characters.
1181 * dwReserved [I] Reserved. Must be set to 0.
1183 * RETURNS
1184 * TRUE if connected
1185 * if lpdwStatus is not null, return the status (off line,
1186 * modem, lan...) in it.
1187 * FALSE if not connected
1189 * NOTES
1190 * If the system has no available network connections, an empty string is
1191 * stored in lpszConnectionName. If there is a LAN connection, a localized
1192 * "LAN Connection" string is stored. Presumably, if only a dial-up
1193 * connection is available then the name of the dial-up connection is
1194 * returned. Why any application, other than the "Internet Settings" CPL,
1195 * would want to use this function instead of the simpler InternetGetConnectedStateW
1196 * function is beyond me.
1198 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1199 DWORD dwNameLen, DWORD dwReserved)
1201 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1203 /* Must be zero */
1204 if(dwReserved)
1205 return FALSE;
1207 if (lpdwStatus) {
1208 WARN("always returning LAN connection.\n");
1209 *lpdwStatus = INTERNET_CONNECTION_LAN;
1212 /* When the buffer size is zero LoadStringW fills the buffer with a pointer to
1213 * the resource, avoid it as we must not change the buffer in this case */
1214 if(lpszConnectionName && dwNameLen) {
1215 *lpszConnectionName = '\0';
1216 LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1219 return TRUE;
1223 /***********************************************************************
1224 * InternetGetConnectedStateExA (WININET.@)
1226 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1227 DWORD dwNameLen, DWORD dwReserved)
1229 LPWSTR lpwszConnectionName = NULL;
1230 BOOL rc;
1232 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1234 if (lpszConnectionName && dwNameLen > 0)
1235 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1237 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1238 dwReserved);
1239 if (rc && lpwszConnectionName)
1240 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1241 dwNameLen, NULL, NULL);
1243 heap_free(lpwszConnectionName);
1244 return rc;
1248 /***********************************************************************
1249 * InternetConnectW (WININET.@)
1251 * Open a ftp, gopher or http session
1253 * RETURNS
1254 * HINTERNET a session handle on success
1255 * NULL on failure
1258 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1259 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1260 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1261 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1263 appinfo_t *hIC;
1264 HINTERNET rc = NULL;
1265 DWORD res = ERROR_SUCCESS;
1267 TRACE("(%p, %s, %u, %s, %p, %u, %x, %lx)\n", hInternet, debugstr_w(lpszServerName),
1268 nServerPort, debugstr_w(lpszUserName), lpszPassword, dwService, dwFlags, dwContext);
1270 if (!lpszServerName)
1272 SetLastError(ERROR_INVALID_PARAMETER);
1273 return NULL;
1276 hIC = (appinfo_t*)get_handle_object( hInternet );
1277 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1279 res = ERROR_INVALID_HANDLE;
1280 goto lend;
1283 switch (dwService)
1285 case INTERNET_SERVICE_FTP:
1286 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1287 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1288 if(!rc)
1289 res = INTERNET_GetLastError();
1290 break;
1292 case INTERNET_SERVICE_HTTP:
1293 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1294 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1295 break;
1297 case INTERNET_SERVICE_GOPHER:
1298 default:
1299 break;
1301 lend:
1302 if( hIC )
1303 WININET_Release( &hIC->hdr );
1305 TRACE("returning %p\n", rc);
1306 SetLastError(res);
1307 return rc;
1311 /***********************************************************************
1312 * InternetConnectA (WININET.@)
1314 * Open a ftp, gopher or http session
1316 * RETURNS
1317 * HINTERNET a session handle on success
1318 * NULL on failure
1321 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1322 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1323 LPCSTR lpszUserName, LPCSTR lpszPassword,
1324 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1326 HINTERNET rc = NULL;
1327 LPWSTR szServerName;
1328 LPWSTR szUserName;
1329 LPWSTR szPassword;
1331 szServerName = heap_strdupAtoW(lpszServerName);
1332 szUserName = heap_strdupAtoW(lpszUserName);
1333 szPassword = heap_strdupAtoW(lpszPassword);
1335 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1336 szUserName, szPassword, dwService, dwFlags, dwContext);
1338 heap_free(szServerName);
1339 heap_free(szUserName);
1340 heap_free(szPassword);
1341 return rc;
1345 /***********************************************************************
1346 * InternetFindNextFileA (WININET.@)
1348 * Continues a file search from a previous call to FindFirstFile
1350 * RETURNS
1351 * TRUE on success
1352 * FALSE on failure
1355 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1357 BOOL ret;
1358 WIN32_FIND_DATAW fd;
1360 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1361 if(lpvFindData)
1362 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1363 return ret;
1366 /***********************************************************************
1367 * InternetFindNextFileW (WININET.@)
1369 * Continues a file search from a previous call to FindFirstFile
1371 * RETURNS
1372 * TRUE on success
1373 * FALSE on failure
1376 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1378 object_header_t *hdr;
1379 DWORD res;
1381 TRACE("\n");
1383 hdr = get_handle_object(hFind);
1384 if(!hdr) {
1385 WARN("Invalid handle\n");
1386 SetLastError(ERROR_INVALID_HANDLE);
1387 return FALSE;
1390 if(hdr->vtbl->FindNextFileW) {
1391 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1392 }else {
1393 WARN("Handle doesn't support NextFile\n");
1394 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1397 WININET_Release(hdr);
1399 if(res != ERROR_SUCCESS)
1400 SetLastError(res);
1401 return res == ERROR_SUCCESS;
1404 /***********************************************************************
1405 * InternetCloseHandle (WININET.@)
1407 * Generic close handle function
1409 * RETURNS
1410 * TRUE on success
1411 * FALSE on failure
1414 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1416 object_header_t *obj;
1418 TRACE("%p\n", hInternet);
1420 obj = get_handle_object( hInternet );
1421 if (!obj) {
1422 SetLastError(ERROR_INVALID_HANDLE);
1423 return FALSE;
1426 invalidate_handle(obj);
1427 WININET_Release(obj);
1429 return TRUE;
1432 static BOOL set_url_component(WCHAR **component, DWORD *component_length, const WCHAR *value, DWORD len)
1434 TRACE("%s (%d)\n", debugstr_wn(value, len), len);
1436 if (!*component_length)
1437 return TRUE;
1439 if (!*component) {
1440 *(const WCHAR**)component = value;
1441 *component_length = len;
1442 return TRUE;
1445 if (*component_length < len+1) {
1446 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1447 return FALSE;
1450 *component_length = len;
1451 if(len)
1452 memcpy(*component, value, len*sizeof(WCHAR));
1453 (*component)[len] = 0;
1454 return TRUE;
1457 static BOOL set_url_component_WtoA(const WCHAR *comp_w, DWORD length, const WCHAR *url_w, char **comp, DWORD *ret_length,
1458 const char *url_a)
1460 size_t size, ret_size = *ret_length;
1462 if (!*ret_length)
1463 return TRUE;
1464 size = WideCharToMultiByte(CP_ACP, 0, comp_w, length, NULL, 0, NULL, NULL);
1466 if (!*comp) {
1467 *comp = comp_w ? (char*)url_a + WideCharToMultiByte(CP_ACP, 0, url_w, comp_w-url_w, NULL, 0, NULL, NULL) : NULL;
1468 *ret_length = size;
1469 return TRUE;
1472 if (size+1 > ret_size) {
1473 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1474 *ret_length = size+1;
1475 return FALSE;
1478 *ret_length = size;
1479 WideCharToMultiByte(CP_ACP, 0, comp_w, length, *comp, ret_size-1, NULL, NULL);
1480 (*comp)[size] = 0;
1481 return TRUE;
1484 static BOOL set_url_component_AtoW(const char *comp_a, DWORD len_a, WCHAR **comp_w, DWORD *len_w, WCHAR **buf)
1486 *len_w = len_a;
1488 if(!comp_a) {
1489 *comp_w = NULL;
1490 return TRUE;
1493 if(!(*comp_w = *buf = heap_alloc(len_a*sizeof(WCHAR)))) {
1494 SetLastError(ERROR_OUTOFMEMORY);
1495 return FALSE;
1498 return TRUE;
1501 /***********************************************************************
1502 * InternetCrackUrlA (WININET.@)
1504 * See InternetCrackUrlW.
1506 BOOL WINAPI InternetCrackUrlA(const char *url, DWORD url_length, DWORD flags, URL_COMPONENTSA *ret_comp)
1508 WCHAR *host = NULL, *user = NULL, *pass = NULL, *path = NULL, *scheme = NULL, *extra = NULL;
1509 URL_COMPONENTSW comp;
1510 WCHAR *url_w = NULL;
1511 BOOL ret;
1513 TRACE("(%s %u %x %p)\n", url_length ? debugstr_an(url, url_length) : debugstr_a(url), url_length, flags, ret_comp);
1515 if (!url || !*url || !ret_comp || ret_comp->dwStructSize != sizeof(URL_COMPONENTSA)) {
1516 SetLastError(ERROR_INVALID_PARAMETER);
1517 return FALSE;
1520 comp.dwStructSize = sizeof(comp);
1522 ret = set_url_component_AtoW(ret_comp->lpszHostName, ret_comp->dwHostNameLength,
1523 &comp.lpszHostName, &comp.dwHostNameLength, &host)
1524 && set_url_component_AtoW(ret_comp->lpszUserName, ret_comp->dwUserNameLength,
1525 &comp.lpszUserName, &comp.dwUserNameLength, &user)
1526 && set_url_component_AtoW(ret_comp->lpszPassword, ret_comp->dwPasswordLength,
1527 &comp.lpszPassword, &comp.dwPasswordLength, &pass)
1528 && set_url_component_AtoW(ret_comp->lpszUrlPath, ret_comp->dwUrlPathLength,
1529 &comp.lpszUrlPath, &comp.dwUrlPathLength, &path)
1530 && set_url_component_AtoW(ret_comp->lpszScheme, ret_comp->dwSchemeLength,
1531 &comp.lpszScheme, &comp.dwSchemeLength, &scheme)
1532 && set_url_component_AtoW(ret_comp->lpszExtraInfo, ret_comp->dwExtraInfoLength,
1533 &comp.lpszExtraInfo, &comp.dwExtraInfoLength, &extra);
1535 if(ret && !(url_w = heap_strndupAtoW(url, url_length ? url_length : -1, &url_length))) {
1536 SetLastError(ERROR_OUTOFMEMORY);
1537 ret = FALSE;
1540 if (ret && (ret = InternetCrackUrlW(url_w, url_length, flags, &comp))) {
1541 ret_comp->nScheme = comp.nScheme;
1542 ret_comp->nPort = comp.nPort;
1544 ret = set_url_component_WtoA(comp.lpszHostName, comp.dwHostNameLength, url_w,
1545 &ret_comp->lpszHostName, &ret_comp->dwHostNameLength, url)
1546 && set_url_component_WtoA(comp.lpszUserName, comp.dwUserNameLength, url_w,
1547 &ret_comp->lpszUserName, &ret_comp->dwUserNameLength, url)
1548 && set_url_component_WtoA(comp.lpszPassword, comp.dwPasswordLength, url_w,
1549 &ret_comp->lpszPassword, &ret_comp->dwPasswordLength, url)
1550 && set_url_component_WtoA(comp.lpszUrlPath, comp.dwUrlPathLength, url_w,
1551 &ret_comp->lpszUrlPath, &ret_comp->dwUrlPathLength, url)
1552 && set_url_component_WtoA(comp.lpszScheme, comp.dwSchemeLength, url_w,
1553 &ret_comp->lpszScheme, &ret_comp->dwSchemeLength, url)
1554 && set_url_component_WtoA(comp.lpszExtraInfo, comp.dwExtraInfoLength, url_w,
1555 &ret_comp->lpszExtraInfo, &ret_comp->dwExtraInfoLength, url);
1557 if(ret)
1558 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(url),
1559 debugstr_an(ret_comp->lpszScheme, ret_comp->dwSchemeLength),
1560 debugstr_an(ret_comp->lpszHostName, ret_comp->dwHostNameLength),
1561 debugstr_an(ret_comp->lpszUrlPath, ret_comp->dwUrlPathLength),
1562 debugstr_an(ret_comp->lpszExtraInfo, ret_comp->dwExtraInfoLength));
1565 heap_free(host);
1566 heap_free(user);
1567 heap_free(pass);
1568 heap_free(path);
1569 heap_free(scheme);
1570 heap_free(extra);
1571 heap_free(url_w);
1572 return ret;
1575 static const WCHAR url_schemes[][7] =
1577 {'f','t','p',0},
1578 {'g','o','p','h','e','r',0},
1579 {'h','t','t','p',0},
1580 {'h','t','t','p','s',0},
1581 {'f','i','l','e',0},
1582 {'n','e','w','s',0},
1583 {'m','a','i','l','t','o',0},
1584 {'r','e','s',0},
1587 /***********************************************************************
1588 * GetInternetSchemeW (internal)
1590 * Get scheme of url
1592 * RETURNS
1593 * scheme on success
1594 * INTERNET_SCHEME_UNKNOWN on failure
1597 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1599 int i;
1601 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1603 if(lpszScheme==NULL)
1604 return INTERNET_SCHEME_UNKNOWN;
1606 for (i = 0; i < ARRAY_SIZE(url_schemes); i++)
1607 if (!wcsnicmp(lpszScheme, url_schemes[i], nMaxCmp))
1608 return INTERNET_SCHEME_FIRST + i;
1610 return INTERNET_SCHEME_UNKNOWN;
1613 /***********************************************************************
1614 * InternetCrackUrlW (WININET.@)
1616 * Break up URL into its components
1618 * RETURNS
1619 * TRUE on success
1620 * FALSE on failure
1622 BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
1625 * RFC 1808
1626 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1629 LPCWSTR lpszParam = NULL;
1630 BOOL found_colon = FALSE;
1631 LPCWSTR lpszap;
1632 LPCWSTR lpszcp = NULL, lpszNetLoc;
1634 TRACE("(%s %u %x %p)\n",
1635 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : lstrlenW(lpszUrl)) : "(null)",
1636 dwUrlLength, dwFlags, lpUC);
1638 if (!lpszUrl || !*lpszUrl || !lpUC)
1640 SetLastError(ERROR_INVALID_PARAMETER);
1641 return FALSE;
1643 if (!dwUrlLength) dwUrlLength = lstrlenW(lpszUrl);
1645 if (dwFlags & ICU_DECODE)
1647 WCHAR *url_tmp, *buffer;
1648 DWORD len = dwUrlLength + 1;
1649 BOOL ret;
1651 if (!(url_tmp = heap_strndupW(lpszUrl, dwUrlLength)))
1653 SetLastError(ERROR_OUTOFMEMORY);
1654 return FALSE;
1657 buffer = url_tmp;
1658 ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
1659 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1661 buffer = heap_alloc(len * sizeof(WCHAR));
1662 if (!buffer)
1664 SetLastError(ERROR_OUTOFMEMORY);
1665 heap_free(url_tmp);
1666 return FALSE;
1668 ret = InternetCanonicalizeUrlW(url_tmp, buffer, &len, ICU_DECODE | ICU_NO_ENCODE);
1670 if (ret)
1671 ret = InternetCrackUrlW(buffer, len, dwFlags & ~ICU_DECODE, lpUC);
1673 if (buffer != url_tmp) heap_free(buffer);
1674 heap_free(url_tmp);
1675 return ret;
1677 lpszap = lpszUrl;
1679 /* Determine if the URI is absolute. */
1680 while (lpszap - lpszUrl < dwUrlLength)
1682 if (iswalnum(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1684 lpszap++;
1685 continue;
1687 if (*lpszap == ':')
1689 found_colon = TRUE;
1690 lpszcp = lpszap;
1692 else
1694 lpszcp = lpszUrl; /* Relative url */
1697 break;
1700 if(!found_colon){
1701 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
1702 return FALSE;
1705 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1706 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1708 /* Parse <params> */
1709 lpszParam = wmemchr(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1710 if(!lpszParam)
1711 lpszParam = wmemchr(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1713 if(!set_url_component(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1714 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0))
1715 return FALSE;
1718 /* Get scheme first. */
1719 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1720 if(!set_url_component(&lpUC->lpszScheme, &lpUC->dwSchemeLength, lpszUrl, lpszcp - lpszUrl))
1721 return FALSE;
1723 /* Eat ':' in protocol. */
1724 lpszcp++;
1726 /* double slash indicates the net_loc portion is present */
1727 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1729 lpszcp += 2;
1731 lpszNetLoc = wmemchr(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1732 if (lpszParam)
1734 if (lpszNetLoc)
1735 lpszNetLoc = min(lpszNetLoc, lpszParam);
1736 else
1737 lpszNetLoc = lpszParam;
1739 else if (!lpszNetLoc)
1740 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1742 /* Parse net-loc */
1743 if (lpszNetLoc)
1745 LPCWSTR lpszHost;
1746 LPCWSTR lpszPort;
1748 /* [<user>[<:password>]@]<host>[:<port>] */
1749 /* First find the user and password if they exist */
1751 lpszHost = wmemchr(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1752 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1754 /* username and password not specified. */
1755 set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1756 set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1758 else /* Parse out username and password */
1760 LPCWSTR lpszUser = lpszcp;
1761 LPCWSTR lpszPasswd = lpszHost;
1763 while (lpszcp < lpszHost)
1765 if (*lpszcp == ':')
1766 lpszPasswd = lpszcp;
1768 lpszcp++;
1771 if(!set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, lpszUser, lpszPasswd - lpszUser))
1772 return FALSE;
1774 if (lpszPasswd != lpszHost)
1775 lpszPasswd++;
1776 if(!set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1777 lpszPasswd == lpszHost ? NULL : lpszPasswd, lpszHost - lpszPasswd))
1778 return FALSE;
1780 lpszcp++; /* Advance to beginning of host */
1783 /* Parse <host><:port> */
1785 lpszHost = lpszcp;
1786 lpszPort = lpszNetLoc;
1788 /* special case for res:// URLs: there is no port here, so the host is the
1789 entire string up to the first '/' */
1790 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1792 if(!set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost))
1793 return FALSE;
1794 lpszcp=lpszNetLoc;
1796 else
1798 while (lpszcp < lpszNetLoc)
1800 if (*lpszcp == ':')
1801 lpszPort = lpszcp;
1803 lpszcp++;
1806 /* If the scheme is "file" and the host is just one letter, it's not a host */
1807 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1809 lpszcp=lpszHost;
1810 set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1812 else
1814 if(!set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, lpszHost, lpszPort - lpszHost))
1815 return FALSE;
1816 if (lpszPort != lpszNetLoc)
1817 lpUC->nPort = wcstol(++lpszPort, NULL, 10);
1818 else switch (lpUC->nScheme)
1820 case INTERNET_SCHEME_HTTP:
1821 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1822 break;
1823 case INTERNET_SCHEME_HTTPS:
1824 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1825 break;
1826 case INTERNET_SCHEME_FTP:
1827 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1828 break;
1829 case INTERNET_SCHEME_GOPHER:
1830 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1831 break;
1832 default:
1833 break;
1839 else
1841 set_url_component(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1842 set_url_component(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1843 set_url_component(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1846 /* Here lpszcp points to:
1848 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1849 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1851 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1853 DWORD len;
1855 /* Only truncate the parameter list if it's already been saved
1856 * in lpUC->lpszExtraInfo.
1858 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1859 len = lpszParam - lpszcp;
1860 else
1862 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1863 * newlines if necessary.
1865 LPWSTR lpsznewline = wmemchr(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1866 if (lpsznewline != NULL)
1867 len = lpsznewline - lpszcp;
1868 else
1869 len = dwUrlLength-(lpszcp-lpszUrl);
1871 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1872 lpUC->nScheme == INTERNET_SCHEME_FILE)
1874 WCHAR tmppath[MAX_PATH];
1875 if (*lpszcp == '/')
1877 len = MAX_PATH;
1878 PathCreateFromUrlW(lpszUrl, tmppath, &len, 0);
1880 else
1882 WCHAR *iter;
1883 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1884 tmppath[len] = '\0';
1886 iter = tmppath;
1887 while (*iter) {
1888 if (*iter == '/')
1889 *iter = '\\';
1890 ++iter;
1893 /* if ends in \. or \.. append a backslash */
1894 if (tmppath[len - 1] == '.' &&
1895 (tmppath[len - 2] == '\\' ||
1896 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1898 if (len < MAX_PATH - 1)
1900 tmppath[len] = '\\';
1901 tmppath[len+1] = '\0';
1902 ++len;
1905 if(!set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, tmppath, len))
1906 return FALSE;
1908 else if(!set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, lpszcp, len))
1909 return FALSE;
1911 else
1913 set_url_component(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength, lpszcp, 0);
1916 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1917 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1918 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1919 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1920 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1922 return TRUE;
1925 /***********************************************************************
1926 * InternetAttemptConnect (WININET.@)
1928 * Attempt to make a connection to the internet
1930 * RETURNS
1931 * ERROR_SUCCESS on success
1932 * Error value on failure
1935 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1937 FIXME("Stub\n");
1938 return ERROR_SUCCESS;
1942 /***********************************************************************
1943 * convert_url_canonicalization_flags
1945 * Helper for InternetCanonicalizeUrl
1947 * PARAMS
1948 * dwFlags [I] Flags suitable for InternetCanonicalizeUrl
1950 * RETURNS
1951 * Flags suitable for UrlCanonicalize
1953 static DWORD convert_url_canonicalization_flags(DWORD dwFlags)
1955 DWORD dwUrlFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1957 if (dwFlags & ICU_BROWSER_MODE) dwUrlFlags |= URL_BROWSER_MODE;
1958 if (dwFlags & ICU_DECODE) dwUrlFlags |= URL_UNESCAPE;
1959 if (dwFlags & ICU_ENCODE_PERCENT) dwUrlFlags |= URL_ESCAPE_PERCENT;
1960 if (dwFlags & ICU_ENCODE_SPACES_ONLY) dwUrlFlags |= URL_ESCAPE_SPACES_ONLY;
1961 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1962 if (dwFlags & ICU_NO_ENCODE) dwUrlFlags ^= URL_ESCAPE_UNSAFE;
1963 if (dwFlags & ICU_NO_META) dwUrlFlags |= URL_NO_META;
1965 return dwUrlFlags;
1968 /***********************************************************************
1969 * InternetCanonicalizeUrlA (WININET.@)
1971 * Escape unsafe characters and spaces
1973 * RETURNS
1974 * TRUE on success
1975 * FALSE on failure
1978 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1979 LPDWORD lpdwBufferLength, DWORD dwFlags)
1981 HRESULT hr;
1983 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1984 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1986 dwFlags = convert_url_canonicalization_flags(dwFlags);
1987 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
1988 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1989 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1991 return hr == S_OK;
1994 /***********************************************************************
1995 * InternetCanonicalizeUrlW (WININET.@)
1997 * Escape unsafe characters and spaces
1999 * RETURNS
2000 * TRUE on success
2001 * FALSE on failure
2004 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
2005 LPDWORD lpdwBufferLength, DWORD dwFlags)
2007 HRESULT hr;
2009 TRACE("(%s, %p, %p, 0x%08x) buffer length: %d\n", debugstr_w(lpszUrl), lpszBuffer,
2010 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
2012 dwFlags = convert_url_canonicalization_flags(dwFlags);
2013 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwFlags);
2014 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2015 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2017 return hr == S_OK;
2020 /* #################################################### */
2022 static INTERNET_STATUS_CALLBACK set_status_callback(
2023 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2025 INTERNET_STATUS_CALLBACK ret;
2027 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2028 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2030 ret = lpwh->lpfnStatusCB;
2031 lpwh->lpfnStatusCB = callback;
2033 return ret;
2036 /***********************************************************************
2037 * InternetSetStatusCallbackA (WININET.@)
2039 * Sets up a callback function which is called as progress is made
2040 * during an operation.
2042 * RETURNS
2043 * Previous callback or NULL on success
2044 * INTERNET_INVALID_STATUS_CALLBACK on failure
2047 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2048 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2050 INTERNET_STATUS_CALLBACK retVal;
2051 object_header_t *lpwh;
2053 TRACE("%p\n", hInternet);
2055 if (!(lpwh = get_handle_object(hInternet)))
2056 return INTERNET_INVALID_STATUS_CALLBACK;
2058 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2060 WININET_Release( lpwh );
2061 return retVal;
2064 /***********************************************************************
2065 * InternetSetStatusCallbackW (WININET.@)
2067 * Sets up a callback function which is called as progress is made
2068 * during an operation.
2070 * RETURNS
2071 * Previous callback or NULL on success
2072 * INTERNET_INVALID_STATUS_CALLBACK on failure
2075 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2076 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2078 INTERNET_STATUS_CALLBACK retVal;
2079 object_header_t *lpwh;
2081 TRACE("%p\n", hInternet);
2083 if (!(lpwh = get_handle_object(hInternet)))
2084 return INTERNET_INVALID_STATUS_CALLBACK;
2086 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2088 WININET_Release( lpwh );
2089 return retVal;
2092 /***********************************************************************
2093 * InternetSetFilePointer (WININET.@)
2095 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2096 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2098 FIXME("(%p %d %p %d %lx): stub\n", hFile, lDistanceToMove, pReserved, dwMoveContext, dwContext);
2099 return FALSE;
2102 /***********************************************************************
2103 * InternetWriteFile (WININET.@)
2105 * Write data to an open internet file
2107 * RETURNS
2108 * TRUE on success
2109 * FALSE on failure
2112 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2113 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2115 object_header_t *lpwh;
2116 BOOL res;
2118 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2120 lpwh = get_handle_object( hFile );
2121 if (!lpwh) {
2122 WARN("Invalid handle\n");
2123 SetLastError(ERROR_INVALID_HANDLE);
2124 return FALSE;
2127 if(lpwh->vtbl->WriteFile) {
2128 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2129 }else {
2130 WARN("No Writefile method.\n");
2131 res = ERROR_INVALID_HANDLE;
2134 WININET_Release( lpwh );
2136 if(res != ERROR_SUCCESS)
2137 SetLastError(res);
2138 return res == ERROR_SUCCESS;
2142 /***********************************************************************
2143 * InternetReadFile (WININET.@)
2145 * Read data from an open internet file
2147 * RETURNS
2148 * TRUE on success
2149 * FALSE on failure
2152 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2153 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2155 object_header_t *hdr;
2156 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2158 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2160 hdr = get_handle_object(hFile);
2161 if (!hdr) {
2162 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2163 return FALSE;
2166 if(hdr->vtbl->ReadFile) {
2167 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, 0, 0);
2168 if(res == ERROR_IO_PENDING)
2169 *pdwNumOfBytesRead = 0;
2172 WININET_Release(hdr);
2174 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2175 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2177 SetLastError(res);
2178 return res == ERROR_SUCCESS;
2181 /***********************************************************************
2182 * InternetReadFileExA (WININET.@)
2184 * Read data from an open internet file
2186 * PARAMS
2187 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2188 * lpBuffersOut [I/O] Buffer.
2189 * dwFlags [I] Flags. See notes.
2190 * dwContext [I] Context for callbacks.
2192 * RETURNS
2193 * TRUE on success
2194 * FALSE on failure
2196 * NOTES
2197 * The parameter dwFlags include zero or more of the following flags:
2198 *|IRF_ASYNC - Makes the call asynchronous.
2199 *|IRF_SYNC - Makes the call synchronous.
2200 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2201 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2203 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2205 * SEE
2206 * InternetOpenUrlA(), HttpOpenRequestA()
2208 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2209 DWORD dwFlags, DWORD_PTR dwContext)
2211 object_header_t *hdr;
2212 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2214 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2216 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut)) {
2217 SetLastError(ERROR_INVALID_PARAMETER);
2218 return FALSE;
2221 hdr = get_handle_object(hFile);
2222 if (!hdr) {
2223 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2224 return FALSE;
2227 if(hdr->vtbl->ReadFile)
2228 res = hdr->vtbl->ReadFile(hdr, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength,
2229 &lpBuffersOut->dwBufferLength, dwFlags, dwContext);
2231 WININET_Release(hdr);
2233 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2234 res, lpBuffersOut->dwBufferLength);
2236 if(res != ERROR_SUCCESS)
2237 SetLastError(res);
2238 return res == ERROR_SUCCESS;
2241 /***********************************************************************
2242 * InternetReadFileExW (WININET.@)
2243 * SEE
2244 * InternetReadFileExA()
2246 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2247 DWORD dwFlags, DWORD_PTR dwContext)
2249 object_header_t *hdr;
2250 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2252 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2254 if (!lpBuffer || lpBuffer->dwStructSize != sizeof(*lpBuffer)) {
2255 SetLastError(ERROR_INVALID_PARAMETER);
2256 return FALSE;
2259 hdr = get_handle_object(hFile);
2260 if (!hdr) {
2261 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2262 return FALSE;
2265 if(hdr->vtbl->ReadFile)
2266 res = hdr->vtbl->ReadFile(hdr, lpBuffer->lpvBuffer, lpBuffer->dwBufferLength, &lpBuffer->dwBufferLength,
2267 dwFlags, dwContext);
2269 WININET_Release(hdr);
2271 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2272 res, lpBuffer->dwBufferLength);
2274 if(res != ERROR_SUCCESS)
2275 SetLastError(res);
2276 return res == ERROR_SUCCESS;
2279 static IP_ADAPTER_ADDRESSES *get_adapters(void)
2281 ULONG err, size = 1024, flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
2282 GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME;
2283 IP_ADAPTER_ADDRESSES *tmp, *ret;
2285 if (!(ret = heap_alloc( size ))) return NULL;
2286 err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
2287 while (err == ERROR_BUFFER_OVERFLOW)
2289 if (!(tmp = heap_realloc( ret, size ))) break;
2290 ret = tmp;
2291 err = GetAdaptersAddresses( AF_UNSPEC, flags, NULL, ret, &size );
2293 if (err == ERROR_SUCCESS) return ret;
2294 heap_free( ret );
2295 return NULL;
2298 static WCHAR *detect_proxy_autoconfig_url_dhcp(void)
2300 IP_ADAPTER_ADDRESSES *adapters, *ptr;
2301 DHCPCAPI_PARAMS_ARRAY send_params, recv_params;
2302 DHCPCAPI_PARAMS param;
2303 WCHAR name[MAX_ADAPTER_NAME_LENGTH + 1], *ret = NULL;
2304 DWORD err, size;
2305 BYTE *tmp, *buf = NULL;
2307 if (!(adapters = get_adapters())) return NULL;
2309 memset( &send_params, 0, sizeof(send_params) );
2310 memset( &param, 0, sizeof(param) );
2311 param.OptionId = OPTION_MSFT_IE_PROXY;
2312 recv_params.nParams = 1;
2313 recv_params.Params = &param;
2315 for (ptr = adapters; ptr; ptr = ptr->Next)
2317 MultiByteToWideChar( CP_ACP, 0, ptr->AdapterName, -1, name, ARRAY_SIZE(name) );
2318 TRACE( "adapter '%s' type %u dhcpv4 enabled %d\n", wine_dbgstr_w(name), ptr->IfType, ptr->Dhcpv4Enabled );
2320 if (ptr->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
2321 /* FIXME: also skip adapters where DHCP is disabled */
2323 size = 256;
2324 if (!(buf = heap_alloc( size ))) goto done;
2325 err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
2326 buf, &size, NULL );
2327 while (err == ERROR_MORE_DATA)
2329 if (!(tmp = heap_realloc( buf, size ))) goto done;
2330 buf = tmp;
2331 err = DhcpRequestParams( DHCPCAPI_REQUEST_SYNCHRONOUS, NULL, name, NULL, send_params, recv_params,
2332 buf, &size, NULL );
2334 if (err == ERROR_SUCCESS && param.nBytesData)
2336 int len = MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, NULL, 0 );
2337 if ((ret = heap_alloc( (len + 1) * sizeof(WCHAR) )))
2339 MultiByteToWideChar( CP_ACP, 0, (const char *)param.Data, param.nBytesData, ret, len );
2340 ret[len] = 0;
2342 TRACE("returning %s\n", debugstr_w(ret));
2343 break;
2347 done:
2348 heap_free( buf );
2349 heap_free( adapters );
2350 return ret;
2353 static char *get_computer_name( COMPUTER_NAME_FORMAT format )
2355 char *ret;
2356 DWORD size = 0;
2358 GetComputerNameExA( format, NULL, &size );
2359 if (GetLastError() != ERROR_MORE_DATA) return NULL;
2360 if (!(ret = heap_alloc( size ))) return NULL;
2361 if (!GetComputerNameExA( format, ret, &size ))
2363 heap_free( ret );
2364 return NULL;
2366 return ret;
2369 static BOOL is_domain_suffix( const char *domain, const char *suffix )
2371 int len_domain = strlen( domain ), len_suffix = strlen( suffix );
2373 if (len_suffix > len_domain) return FALSE;
2374 if (!_strnicmp( domain + len_domain - len_suffix, suffix, -1 )) return TRUE;
2375 return FALSE;
2378 static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len )
2380 return getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 );
2383 static WCHAR *build_wpad_url( const char *hostname, const struct addrinfo *ai )
2385 static const WCHAR httpW[] = {'h','t','t','p',':','/','/',0};
2386 static const WCHAR wpadW[] = {'/','w','p','a','d','.','d','a','t',0};
2387 char name[NI_MAXHOST];
2388 WCHAR *ret, *p;
2389 int len;
2391 while (ai && ai->ai_family != AF_INET && ai->ai_family != AF_INET6) ai = ai->ai_next;
2392 if (!ai) return NULL;
2394 if (!reverse_lookup( ai, name, sizeof(name) )) hostname = name;
2396 len = lstrlenW( httpW ) + strlen( hostname ) + lstrlenW( wpadW );
2397 if (!(ret = p = GlobalAlloc( 0, (len + 1) * sizeof(WCHAR) ))) return NULL;
2398 lstrcpyW( p, httpW );
2399 p += lstrlenW( httpW );
2400 while (*hostname) { *p++ = *hostname++; }
2401 lstrcpyW( p, wpadW );
2402 return ret;
2405 static WCHAR *detect_proxy_autoconfig_url_dns(void)
2407 char *fqdn, *domain, *p;
2408 WCHAR *ret;
2410 if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return NULL;
2411 if (!(domain = get_computer_name( ComputerNamePhysicalDnsDomain )))
2413 heap_free( fqdn );
2414 return NULL;
2416 p = fqdn;
2417 while ((p = strchr( p, '.' )) && is_domain_suffix( p + 1, domain ))
2419 char *name;
2420 struct addrinfo *ai;
2421 int res;
2423 if (!(name = heap_alloc( sizeof("wpad") + strlen(p) )))
2425 heap_free( fqdn );
2426 heap_free( domain );
2427 return NULL;
2429 strcpy( name, "wpad" );
2430 strcat( name, p );
2431 res = getaddrinfo( name, NULL, NULL, &ai );
2432 if (!res)
2434 ret = build_wpad_url( name, ai );
2435 freeaddrinfo( ai );
2436 if (ret)
2438 TRACE("returning %s\n", debugstr_w(ret));
2439 heap_free( name );
2440 break;
2443 heap_free( name );
2444 p++;
2446 heap_free( domain );
2447 heap_free( fqdn );
2448 return ret;
2451 static WCHAR *get_proxy_autoconfig_url(void)
2453 WCHAR *ret = detect_proxy_autoconfig_url_dhcp();
2454 if (!ret) ret = detect_proxy_autoconfig_url_dns();
2455 return ret;
2458 static DWORD query_global_option(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2460 /* FIXME: This function currently handles more options than it should. Options requiring
2461 * proper handles should be moved to proper functions */
2462 switch(option) {
2463 case INTERNET_OPTION_HTTP_VERSION:
2464 if (*size < sizeof(HTTP_VERSION_INFO))
2465 return ERROR_INSUFFICIENT_BUFFER;
2468 * Presently hardcoded to 1.1
2470 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2471 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2472 *size = sizeof(HTTP_VERSION_INFO);
2474 return ERROR_SUCCESS;
2476 case INTERNET_OPTION_CONNECTED_STATE:
2477 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2479 if (*size < sizeof(ULONG))
2480 return ERROR_INSUFFICIENT_BUFFER;
2482 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2483 *size = sizeof(ULONG);
2485 return ERROR_SUCCESS;
2487 case INTERNET_OPTION_PROXY: {
2488 appinfo_t ai;
2489 BOOL ret;
2491 TRACE("Getting global proxy info\n");
2492 memset(&ai, 0, sizeof(appinfo_t));
2493 INTERNET_ConfigureProxy(&ai);
2495 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2496 APPINFO_Destroy(&ai.hdr);
2497 return ret;
2500 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2501 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2503 if (*size < sizeof(ULONG))
2504 return ERROR_INSUFFICIENT_BUFFER;
2506 *(ULONG*)buffer = max_conns;
2507 *size = sizeof(ULONG);
2509 return ERROR_SUCCESS;
2511 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2512 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2514 if (*size < sizeof(ULONG))
2515 return ERROR_INSUFFICIENT_BUFFER;
2517 *(ULONG*)buffer = max_1_0_conns;
2518 *size = sizeof(ULONG);
2520 return ERROR_SUCCESS;
2522 case INTERNET_OPTION_SECURITY_FLAGS:
2523 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2524 return ERROR_SUCCESS;
2526 case INTERNET_OPTION_VERSION: {
2527 static const INTERNET_VERSION_INFO info = { 1, 2 };
2529 TRACE("INTERNET_OPTION_VERSION\n");
2531 if (*size < sizeof(INTERNET_VERSION_INFO))
2532 return ERROR_INSUFFICIENT_BUFFER;
2534 memcpy(buffer, &info, sizeof(info));
2535 *size = sizeof(info);
2537 return ERROR_SUCCESS;
2540 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2541 WCHAR *url;
2542 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2543 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2544 DWORD res = ERROR_SUCCESS, i;
2545 proxyinfo_t pi;
2546 LONG ret;
2548 TRACE("Getting global proxy info\n");
2549 if((ret = INTERNET_LoadProxySettings(&pi)))
2550 return ret;
2552 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2554 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2555 FreeProxyInfo(&pi);
2556 return ERROR_INSUFFICIENT_BUFFER;
2559 url = get_proxy_autoconfig_url();
2561 for (i = 0; i < con->dwOptionCount; i++) {
2562 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2563 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2565 switch (optionW->dwOption) {
2566 case INTERNET_PER_CONN_FLAGS:
2567 if(pi.proxyEnabled)
2568 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2569 else
2570 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2571 if (url)
2572 /* native includes PROXY_TYPE_DIRECT even if PROXY_TYPE_PROXY is set */
2573 optionW->Value.dwValue |= PROXY_TYPE_DIRECT|PROXY_TYPE_AUTO_PROXY_URL;
2574 break;
2576 case INTERNET_PER_CONN_PROXY_SERVER:
2577 if (unicode)
2578 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2579 else
2580 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2581 break;
2583 case INTERNET_PER_CONN_PROXY_BYPASS:
2584 if (unicode)
2585 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2586 else
2587 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2588 break;
2590 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2591 if (!url)
2592 optionW->Value.pszValue = NULL;
2593 else if (unicode)
2594 optionW->Value.pszValue = heap_strdupW(url);
2595 else
2596 optionA->Value.pszValue = heap_strdupWtoA(url);
2597 break;
2599 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2600 optionW->Value.dwValue = AUTO_PROXY_FLAG_ALWAYS_DETECT;
2601 break;
2603 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2604 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2605 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2606 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2607 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2608 memset(&optionW->Value, 0, sizeof(optionW->Value));
2609 break;
2611 default:
2612 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2613 res = ERROR_INVALID_PARAMETER;
2614 break;
2617 heap_free(url);
2618 FreeProxyInfo(&pi);
2620 return res;
2622 case INTERNET_OPTION_REQUEST_FLAGS:
2623 case INTERNET_OPTION_USER_AGENT:
2624 *size = 0;
2625 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2626 case INTERNET_OPTION_POLICY:
2627 return ERROR_INVALID_PARAMETER;
2628 case INTERNET_OPTION_CONNECT_TIMEOUT:
2629 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2631 if (*size < sizeof(ULONG))
2632 return ERROR_INSUFFICIENT_BUFFER;
2634 *(ULONG*)buffer = connect_timeout;
2635 *size = sizeof(ULONG);
2637 return ERROR_SUCCESS;
2640 FIXME("Stub for %d\n", option);
2641 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2644 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2646 switch(option) {
2647 case INTERNET_OPTION_CONTEXT_VALUE:
2648 if (!size)
2649 return ERROR_INVALID_PARAMETER;
2651 if (*size < sizeof(DWORD_PTR)) {
2652 *size = sizeof(DWORD_PTR);
2653 return ERROR_INSUFFICIENT_BUFFER;
2655 if (!buffer)
2656 return ERROR_INVALID_PARAMETER;
2658 *(DWORD_PTR *)buffer = hdr->dwContext;
2659 *size = sizeof(DWORD_PTR);
2660 return ERROR_SUCCESS;
2662 case INTERNET_OPTION_REQUEST_FLAGS:
2663 WARN("INTERNET_OPTION_REQUEST_FLAGS\n");
2664 *size = sizeof(DWORD);
2665 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2667 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2668 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2669 WARN("Called on global option %u\n", option);
2670 return ERROR_INTERNET_INVALID_OPERATION;
2673 /* FIXME: we shouldn't call it here */
2674 return query_global_option(option, buffer, size, unicode);
2677 /***********************************************************************
2678 * InternetQueryOptionW (WININET.@)
2680 * Queries an options on the specified handle
2682 * RETURNS
2683 * TRUE on success
2684 * FALSE on failure
2687 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2688 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2690 object_header_t *hdr;
2691 DWORD res = ERROR_INVALID_HANDLE;
2693 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2695 if(hInternet) {
2696 hdr = get_handle_object(hInternet);
2697 if (hdr) {
2698 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2699 WININET_Release(hdr);
2701 }else {
2702 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2705 if(res != ERROR_SUCCESS)
2706 SetLastError(res);
2707 return res == ERROR_SUCCESS;
2710 /***********************************************************************
2711 * InternetQueryOptionA (WININET.@)
2713 * Queries an options on the specified handle
2715 * RETURNS
2716 * TRUE on success
2717 * FALSE on failure
2720 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2721 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2723 object_header_t *hdr;
2724 DWORD res = ERROR_INVALID_HANDLE;
2726 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2728 if(hInternet) {
2729 hdr = get_handle_object(hInternet);
2730 if (hdr) {
2731 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2732 WININET_Release(hdr);
2734 }else {
2735 res = query_global_option(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2738 if(res != ERROR_SUCCESS)
2739 SetLastError(res);
2740 return res == ERROR_SUCCESS;
2743 DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
2745 switch(option) {
2746 case INTERNET_OPTION_SETTINGS_CHANGED:
2747 FIXME("INTERNETOPTION_SETTINGS_CHANGED semi-stub\n");
2748 collect_connections(COLLECT_CONNECTIONS);
2749 return ERROR_SUCCESS;
2750 case INTERNET_OPTION_CALLBACK:
2751 WARN("Not settable option %u\n", option);
2752 return ERROR_INTERNET_OPTION_NOT_SETTABLE;
2753 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2754 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2755 WARN("Called on global option %u\n", option);
2756 return ERROR_INTERNET_INVALID_OPERATION;
2757 case INTERNET_OPTION_REFRESH:
2758 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2761 return ERROR_INTERNET_INVALID_OPTION;
2764 static DWORD set_global_option(DWORD option, void *buf, DWORD size)
2766 switch(option) {
2767 case INTERNET_OPTION_CALLBACK:
2768 WARN("Not global option %u\n", option);
2769 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2771 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2772 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2774 if(size != sizeof(max_conns))
2775 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2776 if(!*(ULONG*)buf)
2777 return ERROR_BAD_ARGUMENTS;
2779 max_conns = *(ULONG*)buf;
2780 return ERROR_SUCCESS;
2782 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2783 TRACE("INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER\n");
2785 if(size != sizeof(max_1_0_conns))
2786 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2787 if(!*(ULONG*)buf)
2788 return ERROR_BAD_ARGUMENTS;
2790 max_1_0_conns = *(ULONG*)buf;
2791 return ERROR_SUCCESS;
2793 case INTERNET_OPTION_CONNECT_TIMEOUT:
2794 TRACE("INTERNET_OPTION_CONNECT_TIMEOUT\n");
2796 if(size != sizeof(connect_timeout))
2797 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2798 if(!*(ULONG*)buf)
2799 return ERROR_BAD_ARGUMENTS;
2801 connect_timeout = *(ULONG*)buf;
2802 return ERROR_SUCCESS;
2804 case INTERNET_OPTION_SUPPRESS_BEHAVIOR:
2805 FIXME("INTERNET_OPTION_SUPPRESS_BEHAVIOR stub\n");
2807 if(size != sizeof(ULONG))
2808 return ERROR_INTERNET_BAD_OPTION_LENGTH;
2810 FIXME("%08x\n", *(ULONG*)buf);
2811 return ERROR_SUCCESS;
2814 return INET_SetOption(NULL, option, buf, size);
2817 /***********************************************************************
2818 * InternetSetOptionW (WININET.@)
2820 * Sets an options on the specified handle
2822 * RETURNS
2823 * TRUE on success
2824 * FALSE on failure
2827 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2828 LPVOID lpBuffer, DWORD dwBufferLength)
2830 object_header_t *lpwhh;
2831 BOOL ret = TRUE;
2832 DWORD res;
2834 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2836 lpwhh = (object_header_t*) get_handle_object( hInternet );
2837 if(lpwhh)
2838 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2839 else
2840 res = set_global_option(dwOption, lpBuffer, dwBufferLength);
2842 if(res != ERROR_INTERNET_INVALID_OPTION) {
2843 if(lpwhh)
2844 WININET_Release(lpwhh);
2846 if(res != ERROR_SUCCESS)
2847 SetLastError(res);
2849 return res == ERROR_SUCCESS;
2852 switch (dwOption)
2854 case INTERNET_OPTION_HTTP_VERSION:
2856 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2857 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2859 break;
2860 case INTERNET_OPTION_ERROR_MASK:
2862 if(!lpwhh) {
2863 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2864 return FALSE;
2865 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2866 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2867 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2868 SetLastError(ERROR_INVALID_PARAMETER);
2869 ret = FALSE;
2870 } else if(dwBufferLength != sizeof(ULONG)) {
2871 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2872 ret = FALSE;
2873 } else
2874 TRACE("INTERNET_OPTION_ERROR_MASK: %x\n", *(ULONG*)lpBuffer);
2875 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2877 break;
2878 case INTERNET_OPTION_PROXY:
2880 INTERNET_PROXY_INFOW *info = lpBuffer;
2882 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2884 SetLastError(ERROR_INVALID_PARAMETER);
2885 return FALSE;
2887 if (!hInternet)
2889 EnterCriticalSection( &WININET_cs );
2890 free_global_proxy();
2891 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2892 if (global_proxy)
2894 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2896 global_proxy->proxyEnabled = 1;
2897 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2898 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2900 else
2902 global_proxy->proxyEnabled = 0;
2903 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2906 LeaveCriticalSection( &WININET_cs );
2908 else
2910 /* In general, each type of object should handle
2911 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2912 * get silently dropped.
2914 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2915 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2916 ret = FALSE;
2918 break;
2920 case INTERNET_OPTION_CODEPAGE:
2922 ULONG codepage = *(ULONG *)lpBuffer;
2923 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2925 break;
2926 case INTERNET_OPTION_REQUEST_PRIORITY:
2928 ULONG priority = *(ULONG *)lpBuffer;
2929 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2931 break;
2932 case INTERNET_OPTION_CONNECT_TIMEOUT:
2934 ULONG connecttimeout = *(ULONG *)lpBuffer;
2935 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2937 break;
2938 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2940 ULONG receivetimeout = *(ULONG *)lpBuffer;
2941 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2943 break;
2944 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2945 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2946 break;
2947 case INTERNET_OPTION_END_BROWSER_SESSION:
2948 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n");
2949 free_cookie();
2950 free_authorization_cache();
2951 break;
2952 case INTERNET_OPTION_CONNECTED_STATE:
2953 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2954 break;
2955 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2956 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2957 break;
2958 case INTERNET_OPTION_SEND_TIMEOUT:
2959 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2960 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2962 ULONG timeout = *(ULONG *)lpBuffer;
2963 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2964 break;
2966 case INTERNET_OPTION_CONNECT_RETRIES:
2968 ULONG retries = *(ULONG *)lpBuffer;
2969 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2970 break;
2972 case INTERNET_OPTION_CONTEXT_VALUE:
2974 if (!lpwhh)
2976 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2977 return FALSE;
2979 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2981 SetLastError(ERROR_INVALID_PARAMETER);
2982 ret = FALSE;
2984 else
2985 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2986 break;
2988 case INTERNET_OPTION_SECURITY_FLAGS:
2989 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2990 break;
2991 case INTERNET_OPTION_DISABLE_AUTODIAL:
2992 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2993 break;
2994 case INTERNET_OPTION_HTTP_DECODING:
2995 if (!lpwhh)
2997 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2998 return FALSE;
3000 if (!lpBuffer || dwBufferLength != sizeof(BOOL))
3002 SetLastError(ERROR_INVALID_PARAMETER);
3003 ret = FALSE;
3005 else
3006 lpwhh->decoding = *(BOOL *)lpBuffer;
3007 break;
3008 case INTERNET_OPTION_COOKIES_3RD_PARTY:
3009 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
3010 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3011 ret = FALSE;
3012 break;
3013 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
3014 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
3015 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3016 ret = FALSE;
3017 break;
3018 case INTERNET_OPTION_CODEPAGE_PATH:
3019 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
3020 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3021 ret = FALSE;
3022 break;
3023 case INTERNET_OPTION_CODEPAGE_EXTRA:
3024 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
3025 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3026 ret = FALSE;
3027 break;
3028 case INTERNET_OPTION_IDN:
3029 FIXME("INTERNET_OPTION_IDN; STUB\n");
3030 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3031 ret = FALSE;
3032 break;
3033 case INTERNET_OPTION_POLICY:
3034 SetLastError(ERROR_INVALID_PARAMETER);
3035 ret = FALSE;
3036 break;
3037 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3038 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
3039 LONG res;
3040 unsigned int i;
3041 proxyinfo_t pi;
3043 if (INTERNET_LoadProxySettings(&pi)) return FALSE;
3045 for (i = 0; i < con->dwOptionCount; i++) {
3046 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
3048 switch (option->dwOption) {
3049 case INTERNET_PER_CONN_PROXY_SERVER:
3050 heap_free(pi.proxy);
3051 pi.proxy = heap_strdupW(option->Value.pszValue);
3052 break;
3054 case INTERNET_PER_CONN_FLAGS:
3055 if(option->Value.dwValue & PROXY_TYPE_PROXY)
3056 pi.proxyEnabled = 1;
3057 else
3059 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
3060 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
3061 pi.proxyEnabled = 0;
3063 break;
3065 case INTERNET_PER_CONN_PROXY_BYPASS:
3066 heap_free(pi.proxyBypass);
3067 pi.proxyBypass = heap_strdupW(option->Value.pszValue);
3068 break;
3070 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3071 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3072 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3073 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3074 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3075 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3076 FIXME("Unhandled dwOption %d\n", option->dwOption);
3077 break;
3079 default:
3080 FIXME("Unknown dwOption %d\n", option->dwOption);
3081 SetLastError(ERROR_INVALID_PARAMETER);
3082 break;
3086 if ((res = INTERNET_SaveProxySettings(&pi)))
3087 SetLastError(res);
3089 FreeProxyInfo(&pi);
3091 ret = (res == ERROR_SUCCESS);
3092 break;
3094 default:
3095 FIXME("Option %d STUB\n",dwOption);
3096 SetLastError(ERROR_INTERNET_INVALID_OPTION);
3097 ret = FALSE;
3098 break;
3101 if(lpwhh)
3102 WININET_Release( lpwhh );
3104 return ret;
3108 /***********************************************************************
3109 * InternetSetOptionA (WININET.@)
3111 * Sets an options on the specified handle.
3113 * RETURNS
3114 * TRUE on success
3115 * FALSE on failure
3118 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
3119 LPVOID lpBuffer, DWORD dwBufferLength)
3121 LPVOID wbuffer;
3122 DWORD wlen;
3123 BOOL r;
3125 switch( dwOption )
3127 case INTERNET_OPTION_PROXY:
3129 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
3130 LPINTERNET_PROXY_INFOW piw;
3131 DWORD proxlen, prbylen;
3132 LPWSTR prox, prby;
3134 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
3135 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
3136 wlen = sizeof(*piw) + proxlen + prbylen;
3137 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
3138 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
3139 piw->dwAccessType = pi->dwAccessType;
3140 prox = (LPWSTR) &piw[1];
3141 prby = &prox[proxlen+1];
3142 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
3143 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
3144 piw->lpszProxy = prox;
3145 piw->lpszProxyBypass = prby;
3147 break;
3148 case INTERNET_OPTION_USER_AGENT:
3149 case INTERNET_OPTION_USERNAME:
3150 case INTERNET_OPTION_PASSWORD:
3151 case INTERNET_OPTION_PROXY_USERNAME:
3152 case INTERNET_OPTION_PROXY_PASSWORD:
3153 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, NULL, 0 );
3154 if (!(wbuffer = heap_alloc( wlen * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
3155 MultiByteToWideChar( CP_ACP, 0, lpBuffer, -1, wbuffer, wlen );
3156 break;
3157 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
3158 unsigned int i;
3159 INTERNET_PER_CONN_OPTION_LISTW *listW;
3160 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
3161 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3162 wbuffer = heap_alloc(wlen);
3163 listW = wbuffer;
3165 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
3166 if (listA->pszConnection)
3168 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
3169 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
3170 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
3172 else
3173 listW->pszConnection = NULL;
3174 listW->dwOptionCount = listA->dwOptionCount;
3175 listW->dwOptionError = listA->dwOptionError;
3176 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
3178 for (i = 0; i < listA->dwOptionCount; ++i) {
3179 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
3180 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
3182 optW->dwOption = optA->dwOption;
3184 switch (optA->dwOption) {
3185 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3186 case INTERNET_PER_CONN_PROXY_BYPASS:
3187 case INTERNET_PER_CONN_PROXY_SERVER:
3188 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3189 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3190 if (optA->Value.pszValue)
3192 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
3193 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
3194 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
3196 else
3197 optW->Value.pszValue = NULL;
3198 break;
3199 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
3200 case INTERNET_PER_CONN_FLAGS:
3201 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
3202 optW->Value.dwValue = optA->Value.dwValue;
3203 break;
3204 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
3205 optW->Value.ftValue = optA->Value.ftValue;
3206 break;
3207 default:
3208 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
3209 optW->Value.dwValue = optA->Value.dwValue;
3210 break;
3214 break;
3215 default:
3216 wbuffer = lpBuffer;
3217 wlen = dwBufferLength;
3220 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
3222 if( lpBuffer != wbuffer )
3224 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
3226 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
3227 unsigned int i;
3228 for (i = 0; i < list->dwOptionCount; ++i) {
3229 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
3230 switch (opt->dwOption) {
3231 case INTERNET_PER_CONN_AUTOCONFIG_URL:
3232 case INTERNET_PER_CONN_PROXY_BYPASS:
3233 case INTERNET_PER_CONN_PROXY_SERVER:
3234 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
3235 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
3236 heap_free( opt->Value.pszValue );
3237 break;
3238 default:
3239 break;
3242 heap_free( list->pOptions );
3244 heap_free( wbuffer );
3247 return r;
3251 /***********************************************************************
3252 * InternetSetOptionExA (WININET.@)
3254 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
3255 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3257 FIXME("Flags %08x ignored\n", dwFlags);
3258 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
3261 /***********************************************************************
3262 * InternetSetOptionExW (WININET.@)
3264 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
3265 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3267 FIXME("Flags %08x ignored\n", dwFlags);
3268 if( dwFlags & ~ISO_VALID_FLAGS )
3270 SetLastError( ERROR_INVALID_PARAMETER );
3271 return FALSE;
3273 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3276 static const WCHAR WININET_wkday[7][4] =
3277 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3278 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3279 static const WCHAR WININET_month[12][4] =
3280 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3281 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3282 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3284 /***********************************************************************
3285 * InternetTimeFromSystemTimeA (WININET.@)
3287 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3289 BOOL ret;
3290 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3292 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3294 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3296 SetLastError(ERROR_INVALID_PARAMETER);
3297 return FALSE;
3300 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3302 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3303 return FALSE;
3306 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3307 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3309 return ret;
3312 /***********************************************************************
3313 * InternetTimeFromSystemTimeW (WININET.@)
3315 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3317 static const WCHAR date[] =
3318 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3319 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3321 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3323 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3325 SetLastError(ERROR_INVALID_PARAMETER);
3326 return FALSE;
3329 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3331 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3332 return FALSE;
3335 swprintf( string, size, date,
3336 WININET_wkday[time->wDayOfWeek],
3337 time->wDay,
3338 WININET_month[time->wMonth - 1],
3339 time->wYear,
3340 time->wHour,
3341 time->wMinute,
3342 time->wSecond );
3344 return TRUE;
3347 /***********************************************************************
3348 * InternetTimeToSystemTimeA (WININET.@)
3350 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3352 BOOL ret = FALSE;
3353 WCHAR *stringW;
3355 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3357 stringW = heap_strdupAtoW(string);
3358 if (stringW)
3360 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3361 heap_free( stringW );
3363 return ret;
3366 /***********************************************************************
3367 * InternetTimeToSystemTimeW (WININET.@)
3369 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3371 unsigned int i;
3372 const WCHAR *s = string;
3373 WCHAR *end;
3375 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3377 if (!string || !time) return FALSE;
3379 /* Windows does this too */
3380 GetSystemTime( time );
3382 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3383 * a SYSTEMTIME structure.
3386 while (*s && !iswalpha( *s )) s++;
3387 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3388 time->wDayOfWeek = 7;
3390 for (i = 0; i < 7; i++)
3392 if (!wcsnicmp( WININET_wkday[i], s, 3 ))
3394 time->wDayOfWeek = i;
3395 break;
3399 if (time->wDayOfWeek > 6) return TRUE;
3400 while (*s && !iswdigit( *s )) s++;
3401 time->wDay = wcstol( s, &end, 10 );
3402 s = end;
3404 while (*s && !iswalpha( *s )) s++;
3405 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3406 time->wMonth = 0;
3408 for (i = 0; i < 12; i++)
3410 if (!wcsnicmp( WININET_month[i], s, 3 ))
3412 time->wMonth = i + 1;
3413 break;
3416 if (time->wMonth == 0) return TRUE;
3418 while (*s && !iswdigit( *s )) s++;
3419 if (*s == '\0') return TRUE;
3420 time->wYear = wcstol( s, &end, 10 );
3421 s = end;
3423 while (*s && !iswdigit( *s )) s++;
3424 if (*s == '\0') return TRUE;
3425 time->wHour = wcstol( s, &end, 10 );
3426 s = end;
3428 while (*s && !iswdigit( *s )) s++;
3429 if (*s == '\0') return TRUE;
3430 time->wMinute = wcstol( s, &end, 10 );
3431 s = end;
3433 while (*s && !iswdigit( *s )) s++;
3434 if (*s == '\0') return TRUE;
3435 time->wSecond = wcstol( s, &end, 10 );
3436 s = end;
3438 time->wMilliseconds = 0;
3439 return TRUE;
3442 /***********************************************************************
3443 * InternetCheckConnectionW (WININET.@)
3445 * Pings a requested host to check internet connection
3447 * RETURNS
3448 * TRUE on success and FALSE on failure. If a failure then
3449 * ERROR_NOT_CONNECTED is placed into GetLastError
3452 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3455 * this is a kludge which runs the resident ping program and reads the output.
3457 * Anyone have a better idea?
3460 BOOL rc = FALSE;
3461 static const CHAR ping[] = "ping -c 1 ";
3462 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3463 WCHAR *host;
3464 DWORD len, host_len;
3465 INTERNET_PORT port;
3466 int status = -1;
3468 FIXME("(%s %x %x)\n", debugstr_w(lpszUrl), dwFlags, dwReserved);
3471 * Crack or set the Address
3473 if (lpszUrl == NULL)
3476 * According to the doc we are supposed to use the ip for the next
3477 * server in the WnInet internal server database. I have
3478 * no idea what that is or how to get it.
3480 * So someone needs to implement this.
3482 FIXME("Unimplemented with URL of NULL\n");
3483 return TRUE;
3485 else
3487 URL_COMPONENTSW components = {sizeof(components)};
3489 components.dwHostNameLength = 1;
3491 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3492 goto End;
3494 host = components.lpszHostName;
3495 host_len = components.dwHostNameLength;
3496 port = components.nPort;
3497 TRACE("host name: %s port: %d\n",debugstr_wn(host, host_len), port);
3500 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3502 struct sockaddr_storage saddr;
3503 int sa_len = sizeof(saddr);
3504 WCHAR *host_z;
3505 int fd;
3506 BOOL b;
3508 host_z = heap_strndupW(host, host_len);
3509 if (!host_z)
3510 return FALSE;
3512 b = GetAddress(host_z, port, (struct sockaddr *)&saddr, &sa_len, NULL);
3513 heap_free(host_z);
3514 if(!b)
3515 goto End;
3516 init_winsock();
3517 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3518 if (fd != -1)
3520 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3521 rc = TRUE;
3522 closesocket(fd);
3525 else
3528 * Build our ping command
3530 char *command;
3532 len = WideCharToMultiByte(CP_UNIXCP, 0, host, host_len, NULL, 0, NULL, NULL);
3533 command = heap_alloc(strlen(ping)+len+strlen(redirect)+1);
3534 strcpy(command, ping);
3535 WideCharToMultiByte(CP_UNIXCP, 0, host, host_len, command+sizeof(ping)-1, len, NULL, NULL);
3536 strcpy(command+sizeof(ping)-1+len, redirect);
3538 TRACE("Ping command is : %s\n",command);
3540 status = system(command);
3541 heap_free( command );
3543 TRACE("Ping returned a code of %i\n",status);
3545 /* Ping return code of 0 indicates success */
3546 if (status == 0)
3547 rc = TRUE;
3550 End:
3551 if (rc == FALSE)
3552 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3554 return rc;
3558 /***********************************************************************
3559 * InternetCheckConnectionA (WININET.@)
3561 * Pings a requested host to check internet connection
3563 * RETURNS
3564 * TRUE on success and FALSE on failure. If a failure then
3565 * ERROR_NOT_CONNECTED is placed into GetLastError
3568 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3570 WCHAR *url = NULL;
3571 BOOL rc;
3573 if(lpszUrl) {
3574 url = heap_strdupAtoW(lpszUrl);
3575 if(!url)
3576 return FALSE;
3579 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3581 heap_free(url);
3582 return rc;
3586 /**********************************************************
3587 * INTERNET_InternetOpenUrlW (internal)
3589 * Opens an URL
3591 * RETURNS
3592 * handle of connection or NULL on failure
3594 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3595 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3597 URL_COMPONENTSW urlComponents = { sizeof(urlComponents) };
3598 WCHAR *host, *user = NULL, *pass = NULL, *path;
3599 HINTERNET client = NULL, client1 = NULL;
3600 DWORD res;
3602 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3603 dwHeadersLength, dwFlags, dwContext);
3605 urlComponents.dwHostNameLength = 1;
3606 urlComponents.dwUserNameLength = 1;
3607 urlComponents.dwPasswordLength = 1;
3608 urlComponents.dwUrlPathLength = 1;
3609 urlComponents.dwExtraInfoLength = 1;
3610 if(!InternetCrackUrlW(lpszUrl, lstrlenW(lpszUrl), 0, &urlComponents))
3611 return NULL;
3613 if ((urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS) &&
3614 urlComponents.dwExtraInfoLength)
3616 assert(urlComponents.lpszUrlPath + urlComponents.dwUrlPathLength == urlComponents.lpszExtraInfo);
3617 urlComponents.dwUrlPathLength += urlComponents.dwExtraInfoLength;
3620 host = heap_strndupW(urlComponents.lpszHostName, urlComponents.dwHostNameLength);
3621 path = heap_strndupW(urlComponents.lpszUrlPath, urlComponents.dwUrlPathLength);
3622 if(urlComponents.dwUserNameLength)
3623 user = heap_strndupW(urlComponents.lpszUserName, urlComponents.dwUserNameLength);
3624 if(urlComponents.dwPasswordLength)
3625 pass = heap_strndupW(urlComponents.lpszPassword, urlComponents.dwPasswordLength);
3627 switch(urlComponents.nScheme) {
3628 case INTERNET_SCHEME_FTP:
3629 client = FTP_Connect(hIC, host, urlComponents.nPort,
3630 user, pass, dwFlags, dwContext, INET_OPENURL);
3631 if(client == NULL)
3632 break;
3633 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3634 if(client1 == NULL) {
3635 InternetCloseHandle(client);
3636 break;
3638 break;
3640 case INTERNET_SCHEME_HTTP:
3641 case INTERNET_SCHEME_HTTPS: {
3642 static const WCHAR szStars[] = { '*','/','*', 0 };
3643 LPCWSTR accept[2] = { szStars, NULL };
3645 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3647 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3648 res = HTTP_Connect(hIC, host, urlComponents.nPort,
3649 user, pass, dwFlags, dwContext, INET_OPENURL, &client);
3650 if(res != ERROR_SUCCESS) {
3651 INTERNET_SetLastError(res);
3652 break;
3655 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3656 if(client1 == NULL) {
3657 InternetCloseHandle(client);
3658 break;
3660 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3661 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3662 GetLastError() != ERROR_IO_PENDING) {
3663 InternetCloseHandle(client1);
3664 client1 = NULL;
3665 break;
3668 case INTERNET_SCHEME_GOPHER:
3669 /* gopher doesn't seem to be implemented in wine, but it's supposed
3670 * to be supported by InternetOpenUrlA. */
3671 default:
3672 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3673 break;
3676 TRACE(" %p <--\n", client1);
3678 heap_free(host);
3679 heap_free(path);
3680 heap_free(user);
3681 heap_free(pass);
3682 return client1;
3685 /**********************************************************
3686 * InternetOpenUrlW (WININET.@)
3688 * Opens an URL
3690 * RETURNS
3691 * handle of connection or NULL on failure
3693 typedef struct {
3694 task_header_t hdr;
3695 WCHAR *url;
3696 WCHAR *headers;
3697 DWORD headers_len;
3698 DWORD flags;
3699 DWORD_PTR context;
3700 } open_url_task_t;
3702 static void AsyncInternetOpenUrlProc(task_header_t *hdr)
3704 open_url_task_t *task = (open_url_task_t*)hdr;
3706 TRACE("%p\n", task->hdr.hdr);
3708 INTERNET_InternetOpenUrlW((appinfo_t*)task->hdr.hdr, task->url, task->headers,
3709 task->headers_len, task->flags, task->context);
3710 heap_free(task->url);
3711 heap_free(task->headers);
3714 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3715 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3717 HINTERNET ret = NULL;
3718 appinfo_t *hIC = NULL;
3720 if (TRACE_ON(wininet)) {
3721 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3722 dwHeadersLength, dwFlags, dwContext);
3723 TRACE(" flags :");
3724 dump_INTERNET_FLAGS(dwFlags);
3727 if (!lpszUrl)
3729 SetLastError(ERROR_INVALID_PARAMETER);
3730 goto lend;
3733 hIC = (appinfo_t*)get_handle_object( hInternet );
3734 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3735 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3736 goto lend;
3739 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3740 open_url_task_t *task;
3742 task = alloc_async_task(&hIC->hdr, AsyncInternetOpenUrlProc, sizeof(*task));
3743 task->url = heap_strdupW(lpszUrl);
3744 task->headers = heap_strdupW(lpszHeaders);
3745 task->headers_len = dwHeadersLength;
3746 task->flags = dwFlags;
3747 task->context = dwContext;
3749 INTERNET_AsyncCall(&task->hdr);
3750 SetLastError(ERROR_IO_PENDING);
3751 } else {
3752 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3755 lend:
3756 if( hIC )
3757 WININET_Release( &hIC->hdr );
3758 TRACE(" %p <--\n", ret);
3760 return ret;
3763 /**********************************************************
3764 * InternetOpenUrlA (WININET.@)
3766 * Opens an URL
3768 * RETURNS
3769 * handle of connection or NULL on failure
3771 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3772 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3774 HINTERNET rc = NULL;
3775 LPWSTR szUrl = NULL;
3776 WCHAR *headers = NULL;
3778 TRACE("\n");
3780 if(lpszUrl) {
3781 szUrl = heap_strdupAtoW(lpszUrl);
3782 if(!szUrl)
3783 return NULL;
3786 if(lpszHeaders) {
3787 headers = heap_strndupAtoW(lpszHeaders, dwHeadersLength, &dwHeadersLength);
3788 if(!headers) {
3789 heap_free(szUrl);
3790 return NULL;
3794 rc = InternetOpenUrlW(hInternet, szUrl, headers, dwHeadersLength, dwFlags, dwContext);
3796 heap_free(szUrl);
3797 heap_free(headers);
3798 return rc;
3802 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3804 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3806 if (lpwite)
3808 lpwite->dwError = 0;
3809 lpwite->response[0] = '\0';
3812 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3814 heap_free(lpwite);
3815 return NULL;
3817 return lpwite;
3821 /***********************************************************************
3822 * INTERNET_SetLastError (internal)
3824 * Set last thread specific error
3826 * RETURNS
3829 void INTERNET_SetLastError(DWORD dwError)
3831 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3833 if (!lpwite)
3834 lpwite = INTERNET_AllocThreadError();
3836 SetLastError(dwError);
3837 if(lpwite)
3838 lpwite->dwError = dwError;
3842 /***********************************************************************
3843 * INTERNET_GetLastError (internal)
3845 * Get last thread specific error
3847 * RETURNS
3850 DWORD INTERNET_GetLastError(void)
3852 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3853 if (!lpwite) return 0;
3854 /* TlsGetValue clears last error, so set it again here */
3855 SetLastError(lpwite->dwError);
3856 return lpwite->dwError;
3860 /***********************************************************************
3861 * INTERNET_WorkerThreadFunc (internal)
3863 * Worker thread execution function
3865 * RETURNS
3868 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3870 task_header_t *task = lpvParam;
3872 TRACE("\n");
3874 task->proc(task);
3875 WININET_Release(task->hdr);
3876 heap_free(task);
3878 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3880 heap_free(TlsGetValue(g_dwTlsErrIndex));
3881 TlsSetValue(g_dwTlsErrIndex, NULL);
3883 return TRUE;
3886 void *alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
3888 task_header_t *task;
3890 task = heap_alloc(size);
3891 if(!task)
3892 return NULL;
3894 task->hdr = WININET_AddRef(hdr);
3895 task->proc = proc;
3896 return task;
3899 /***********************************************************************
3900 * INTERNET_AsyncCall (internal)
3902 * Retrieves work request from queue
3904 * RETURNS
3907 DWORD INTERNET_AsyncCall(task_header_t *task)
3909 BOOL bSuccess;
3911 TRACE("\n");
3913 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, task, WT_EXECUTELONGFUNCTION);
3914 if (!bSuccess)
3916 heap_free(task);
3917 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3919 return ERROR_SUCCESS;
3923 /***********************************************************************
3924 * INTERNET_GetResponseBuffer (internal)
3926 * RETURNS
3929 LPSTR INTERNET_GetResponseBuffer(void)
3931 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3932 if (!lpwite)
3933 lpwite = INTERNET_AllocThreadError();
3934 TRACE("\n");
3935 return lpwite->response;
3938 /**********************************************************
3939 * InternetQueryDataAvailable (WININET.@)
3941 * Determines how much data is available to be read.
3943 * RETURNS
3944 * TRUE on success, FALSE if an error occurred. If
3945 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3946 * no data is presently available, FALSE is returned with
3947 * the last error ERROR_IO_PENDING; a callback with status
3948 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3949 * data is available.
3951 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3952 LPDWORD lpdwNumberOfBytesAvailable,
3953 DWORD dwFlags, DWORD_PTR dwContext)
3955 object_header_t *hdr;
3956 DWORD res;
3958 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3960 hdr = get_handle_object( hFile );
3961 if (!hdr) {
3962 SetLastError(ERROR_INVALID_HANDLE);
3963 return FALSE;
3966 if(hdr->vtbl->QueryDataAvailable) {
3967 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailable, dwFlags, dwContext);
3968 }else {
3969 WARN("wrong handle\n");
3970 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3973 WININET_Release(hdr);
3975 if(res != ERROR_SUCCESS)
3976 SetLastError(res);
3977 return res == ERROR_SUCCESS;
3980 DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
3982 req_file_t *req_file;
3984 req_file = heap_alloc_zero(sizeof(*req_file));
3985 if(!req_file)
3986 return ERROR_NOT_ENOUGH_MEMORY;
3988 req_file->ref = 1;
3990 req_file->file_name = heap_strdupW(file_name);
3991 if(!req_file->file_name) {
3992 heap_free(req_file);
3993 return ERROR_NOT_ENOUGH_MEMORY;
3996 req_file->file_handle = CreateFileW(req_file->file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
3997 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3998 if(req_file->file_handle == INVALID_HANDLE_VALUE) {
3999 req_file_release(req_file);
4000 return GetLastError();
4003 *ret = req_file;
4004 return ERROR_SUCCESS;
4007 void req_file_release(req_file_t *req_file)
4009 if(InterlockedDecrement(&req_file->ref))
4010 return;
4012 if(!req_file->is_committed)
4013 DeleteFileW(req_file->file_name);
4014 if(req_file->file_handle && req_file->file_handle != INVALID_HANDLE_VALUE)
4015 CloseHandle(req_file->file_handle);
4016 heap_free(req_file->file_name);
4017 heap_free(req_file->url);
4018 heap_free(req_file);
4021 /***********************************************************************
4022 * InternetLockRequestFile (WININET.@)
4024 BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
4026 req_file_t *req_file = NULL;
4027 object_header_t *hdr;
4028 DWORD res;
4030 TRACE("(%p %p)\n", hInternet, lphLockReqHandle);
4032 hdr = get_handle_object(hInternet);
4033 if (!hdr) {
4034 SetLastError(ERROR_INVALID_HANDLE);
4035 return FALSE;
4038 if(hdr->vtbl->LockRequestFile) {
4039 res = hdr->vtbl->LockRequestFile(hdr, &req_file);
4040 }else {
4041 WARN("wrong handle\n");
4042 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
4045 WININET_Release(hdr);
4047 *lphLockReqHandle = req_file;
4048 if(res != ERROR_SUCCESS)
4049 SetLastError(res);
4050 return res == ERROR_SUCCESS;
4053 BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
4055 TRACE("(%p)\n", hLockHandle);
4057 req_file_release(hLockHandle);
4058 return TRUE;
4062 /***********************************************************************
4063 * InternetAutodial (WININET.@)
4065 * On windows this function is supposed to dial the default internet
4066 * connection. We don't want to have Wine dial out to the internet so
4067 * we return TRUE by default. It might be nice to check if we are connected.
4069 * RETURNS
4070 * TRUE on success
4071 * FALSE on failure
4074 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
4076 FIXME("STUB\n");
4078 /* Tell that we are connected to the internet. */
4079 return TRUE;
4082 /***********************************************************************
4083 * InternetAutodialHangup (WININET.@)
4085 * Hangs up a connection made with InternetAutodial
4087 * PARAM
4088 * dwReserved
4089 * RETURNS
4090 * TRUE on success
4091 * FALSE on failure
4094 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
4096 FIXME("STUB\n");
4098 /* we didn't dial, we don't disconnect */
4099 return TRUE;
4102 /***********************************************************************
4103 * InternetCombineUrlA (WININET.@)
4105 * Combine a base URL with a relative URL
4107 * RETURNS
4108 * TRUE on success
4109 * FALSE on failure
4113 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
4114 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
4115 DWORD dwFlags)
4117 HRESULT hr=S_OK;
4119 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4121 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4122 dwFlags ^= ICU_NO_ENCODE;
4123 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4125 return (hr==S_OK);
4128 /***********************************************************************
4129 * InternetCombineUrlW (WININET.@)
4131 * Combine a base URL with a relative URL
4133 * RETURNS
4134 * TRUE on success
4135 * FALSE on failure
4139 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
4140 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
4141 DWORD dwFlags)
4143 HRESULT hr=S_OK;
4145 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
4147 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
4148 dwFlags ^= ICU_NO_ENCODE;
4149 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
4151 return (hr==S_OK);
4154 /* max port num is 65535 => 5 digits */
4155 #define MAX_WORD_DIGITS 5
4157 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
4158 (url)->dw##component##Length : lstrlenW((url)->lpsz##component))
4159 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
4160 (url)->dw##component##Length : strlen((url)->lpsz##component))
4162 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
4164 if ((nScheme == INTERNET_SCHEME_HTTP) &&
4165 (nPort == INTERNET_DEFAULT_HTTP_PORT))
4166 return TRUE;
4167 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
4168 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
4169 return TRUE;
4170 if ((nScheme == INTERNET_SCHEME_FTP) &&
4171 (nPort == INTERNET_DEFAULT_FTP_PORT))
4172 return TRUE;
4173 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
4174 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
4175 return TRUE;
4177 if (nPort == INTERNET_INVALID_PORT_NUMBER)
4178 return TRUE;
4180 return FALSE;
4183 /* opaque urls do not fit into the standard url hierarchy and don't have
4184 * two following slashes */
4185 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
4187 return (nScheme != INTERNET_SCHEME_FTP) &&
4188 (nScheme != INTERNET_SCHEME_GOPHER) &&
4189 (nScheme != INTERNET_SCHEME_HTTP) &&
4190 (nScheme != INTERNET_SCHEME_HTTPS) &&
4191 (nScheme != INTERNET_SCHEME_FILE);
4194 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
4196 int index;
4197 if (scheme < INTERNET_SCHEME_FIRST)
4198 return NULL;
4199 index = scheme - INTERNET_SCHEME_FIRST;
4200 if (index >= ARRAY_SIZE(url_schemes))
4201 return NULL;
4202 return (LPCWSTR)url_schemes[index];
4205 /* we can calculate using ansi strings because we're just
4206 * calculating string length, not size
4208 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
4209 LPDWORD lpdwUrlLength)
4211 INTERNET_SCHEME nScheme;
4213 *lpdwUrlLength = 0;
4215 if (lpUrlComponents->lpszScheme)
4217 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4218 *lpdwUrlLength += dwLen;
4219 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4221 else
4223 LPCWSTR scheme;
4225 nScheme = lpUrlComponents->nScheme;
4227 if (nScheme == INTERNET_SCHEME_DEFAULT)
4228 nScheme = INTERNET_SCHEME_HTTP;
4229 scheme = INTERNET_GetSchemeString(nScheme);
4230 *lpdwUrlLength += lstrlenW(scheme);
4233 (*lpdwUrlLength)++; /* ':' */
4234 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4235 *lpdwUrlLength += strlen("//");
4237 if (lpUrlComponents->lpszUserName)
4239 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4240 *lpdwUrlLength += strlen("@");
4242 else
4244 if (lpUrlComponents->lpszPassword)
4246 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4247 return FALSE;
4251 if (lpUrlComponents->lpszPassword)
4253 *lpdwUrlLength += strlen(":");
4254 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4257 if (lpUrlComponents->lpszHostName)
4259 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4261 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4263 char szPort[MAX_WORD_DIGITS+1];
4265 *lpdwUrlLength += sprintf(szPort, "%d", lpUrlComponents->nPort);
4266 *lpdwUrlLength += strlen(":");
4269 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4270 (*lpdwUrlLength)++; /* '/' */
4273 if (lpUrlComponents->lpszUrlPath)
4274 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4276 if (lpUrlComponents->lpszExtraInfo)
4277 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4279 return TRUE;
4282 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4284 INT len;
4286 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4288 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4289 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4290 urlCompW->nScheme = lpUrlComponents->nScheme;
4291 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4292 urlCompW->nPort = lpUrlComponents->nPort;
4293 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4294 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4295 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4296 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4298 if (lpUrlComponents->lpszScheme)
4300 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4301 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4302 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4303 -1, urlCompW->lpszScheme, len);
4306 if (lpUrlComponents->lpszHostName)
4308 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4309 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4310 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4311 -1, urlCompW->lpszHostName, len);
4314 if (lpUrlComponents->lpszUserName)
4316 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4317 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4318 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4319 -1, urlCompW->lpszUserName, len);
4322 if (lpUrlComponents->lpszPassword)
4324 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4325 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4326 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4327 -1, urlCompW->lpszPassword, len);
4330 if (lpUrlComponents->lpszUrlPath)
4332 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4333 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4334 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4335 -1, urlCompW->lpszUrlPath, len);
4338 if (lpUrlComponents->lpszExtraInfo)
4340 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4341 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4342 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4343 -1, urlCompW->lpszExtraInfo, len);
4347 /***********************************************************************
4348 * InternetCreateUrlA (WININET.@)
4350 * See InternetCreateUrlW.
4352 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4353 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4355 BOOL ret;
4356 LPWSTR urlW = NULL;
4357 URL_COMPONENTSW urlCompW;
4359 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4361 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4363 SetLastError(ERROR_INVALID_PARAMETER);
4364 return FALSE;
4367 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4369 if (lpszUrl)
4370 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4372 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4374 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4375 *lpdwUrlLength /= sizeof(WCHAR);
4377 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4378 * minus one, so add one to leave room for NULL terminator
4380 if (ret)
4381 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4383 heap_free(urlCompW.lpszScheme);
4384 heap_free(urlCompW.lpszHostName);
4385 heap_free(urlCompW.lpszUserName);
4386 heap_free(urlCompW.lpszPassword);
4387 heap_free(urlCompW.lpszUrlPath);
4388 heap_free(urlCompW.lpszExtraInfo);
4389 heap_free(urlW);
4390 return ret;
4393 /***********************************************************************
4394 * InternetCreateUrlW (WININET.@)
4396 * Creates a URL from its component parts.
4398 * PARAMS
4399 * lpUrlComponents [I] URL Components.
4400 * dwFlags [I] Flags. See notes.
4401 * lpszUrl [I] Buffer in which to store the created URL.
4402 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4403 * lpszUrl in characters. On output, the number of bytes
4404 * required to store the URL including terminator.
4406 * NOTES
4408 * The dwFlags parameter can be zero or more of the following:
4409 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4411 * RETURNS
4412 * TRUE on success
4413 * FALSE on failure
4416 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4417 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4419 DWORD dwLen;
4420 INTERNET_SCHEME nScheme;
4421 WCHAR *start = lpszUrl;
4423 static const WCHAR slashSlashW[] = {'/','/'};
4424 static const WCHAR fmtW[] = {'%','u',0};
4426 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4428 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4430 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4431 return FALSE;
4434 if (!calc_url_length(lpUrlComponents, &dwLen))
4435 return FALSE;
4437 if (!lpszUrl || *lpdwUrlLength < dwLen)
4439 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4440 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4441 return FALSE;
4444 *lpdwUrlLength = dwLen;
4445 lpszUrl[0] = 0x00;
4447 dwLen = 0;
4449 if (lpUrlComponents->lpszScheme)
4451 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4452 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4453 lpszUrl += dwLen;
4455 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4457 else
4459 LPCWSTR scheme;
4460 nScheme = lpUrlComponents->nScheme;
4462 if (nScheme == INTERNET_SCHEME_DEFAULT)
4463 nScheme = INTERNET_SCHEME_HTTP;
4465 scheme = INTERNET_GetSchemeString(nScheme);
4466 dwLen = lstrlenW(scheme);
4467 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4468 lpszUrl += dwLen;
4471 /* all schemes are followed by at least a colon */
4472 *lpszUrl = ':';
4473 lpszUrl++;
4475 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4477 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4478 lpszUrl += ARRAY_SIZE(slashSlashW);
4481 if (lpUrlComponents->lpszUserName)
4483 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4484 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4485 lpszUrl += dwLen;
4487 if (lpUrlComponents->lpszPassword)
4489 *lpszUrl = ':';
4490 lpszUrl++;
4492 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4493 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4494 lpszUrl += dwLen;
4497 *lpszUrl = '@';
4498 lpszUrl++;
4501 if (lpUrlComponents->lpszHostName)
4503 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4504 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4505 lpszUrl += dwLen;
4507 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4509 *lpszUrl = ':';
4510 lpszUrl++;
4511 lpszUrl += swprintf(lpszUrl, *lpdwUrlLength - (lpszUrl - start), fmtW, lpUrlComponents->nPort);
4514 /* add slash between hostname and path if necessary */
4515 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4517 *lpszUrl = '/';
4518 lpszUrl++;
4522 if (lpUrlComponents->lpszUrlPath)
4524 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4525 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4526 lpszUrl += dwLen;
4529 if (lpUrlComponents->lpszExtraInfo)
4531 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4532 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4533 lpszUrl += dwLen;
4536 *lpszUrl = '\0';
4538 return TRUE;
4541 /***********************************************************************
4542 * InternetConfirmZoneCrossingA (WININET.@)
4545 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4547 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4548 return ERROR_SUCCESS;
4551 /***********************************************************************
4552 * InternetConfirmZoneCrossingW (WININET.@)
4555 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4557 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4558 return ERROR_SUCCESS;
4561 static DWORD zone_preference = 3;
4563 /***********************************************************************
4564 * PrivacySetZonePreferenceW (WININET.@)
4566 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4568 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4570 zone_preference = template;
4571 return 0;
4574 /***********************************************************************
4575 * PrivacyGetZonePreferenceW (WININET.@)
4577 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4578 LPWSTR preference, LPDWORD length )
4580 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4582 if (template) *template = zone_preference;
4583 return 0;
4586 /***********************************************************************
4587 * InternetGetSecurityInfoByURLA (WININET.@)
4589 BOOL WINAPI InternetGetSecurityInfoByURLA(LPSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4591 WCHAR *url;
4592 BOOL res;
4594 TRACE("(%s %p %p)\n", debugstr_a(lpszURL), ppCertChain, pdwSecureFlags);
4596 url = heap_strdupAtoW(lpszURL);
4597 if(!url)
4598 return FALSE;
4600 res = InternetGetSecurityInfoByURLW(url, ppCertChain, pdwSecureFlags);
4601 heap_free(url);
4602 return res;
4605 /***********************************************************************
4606 * InternetGetSecurityInfoByURLW (WININET.@)
4608 BOOL WINAPI InternetGetSecurityInfoByURLW(LPCWSTR lpszURL, PCCERT_CHAIN_CONTEXT *ppCertChain, DWORD *pdwSecureFlags)
4610 URL_COMPONENTSW url = {sizeof(url)};
4611 server_t *server;
4612 BOOL res;
4614 TRACE("(%s %p %p)\n", debugstr_w(lpszURL), ppCertChain, pdwSecureFlags);
4616 if (!ppCertChain && !pdwSecureFlags) {
4617 SetLastError(ERROR_INVALID_PARAMETER);
4618 return FALSE;
4621 url.dwHostNameLength = 1;
4622 res = InternetCrackUrlW(lpszURL, 0, 0, &url);
4623 if(!res || url.nScheme != INTERNET_SCHEME_HTTPS) {
4624 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4625 return FALSE;
4628 server = get_server(substr(url.lpszHostName, url.dwHostNameLength), url.nPort, TRUE, FALSE);
4629 if(!server) {
4630 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4631 return FALSE;
4634 if(server->cert_chain) {
4635 if(pdwSecureFlags)
4636 *pdwSecureFlags = server->security_flags & _SECURITY_ERROR_FLAGS_MASK;
4638 if(ppCertChain && !(*ppCertChain = CertDuplicateCertificateChain(server->cert_chain)))
4639 res = FALSE;
4640 }else {
4641 SetLastError(ERROR_INTERNET_ITEM_NOT_FOUND);
4642 res = FALSE;
4645 server_release(server);
4646 return res;
4649 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4650 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4652 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4653 lpdwConnection, dwReserved);
4654 return ERROR_SUCCESS;
4657 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4658 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4660 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4661 lpdwConnection, dwReserved);
4662 return ERROR_SUCCESS;
4665 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4667 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4668 return TRUE;
4671 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4673 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4674 return TRUE;
4677 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4679 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4680 return ERROR_SUCCESS;
4683 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4684 PBYTE pbHexHash )
4686 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4687 debugstr_w(pwszTarget), pbHexHash);
4688 return FALSE;
4691 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4693 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4694 return FALSE;
4697 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4699 FIXME("(%p, %08lx) stub\n", a, b);
4700 return FALSE;
4703 DWORD WINAPI ShowClientAuthCerts(HWND parent)
4705 FIXME("%p: stub\n", parent);
4706 return 0;