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
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #if defined(__MINGW32__) || defined (_MSC_VER)
39 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 # include <sys/socket.h>
46 #ifdef HAVE_SYS_POLL_H
47 # include <sys/poll.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
66 #include "wine/debug.h"
68 #define NO_SHLWAPI_STREAM
71 #include "wine/exception.h"
76 #include "wine/unicode.h"
78 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
80 #define RESPONSE_TIMEOUT 30
85 CHAR response[MAX_REPLY_LEN];
86 } WITHREADERROR, *LPWITHREADERROR;
88 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
89 HMODULE WININET_hModule;
91 static CRITICAL_SECTION WININET_cs;
92 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
95 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
96 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
98 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
100 static object_header_t **handle_table;
101 static UINT_PTR next_handle;
102 static UINT_PTR handle_table_size;
111 static const WCHAR szInternetSettings[] =
112 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
113 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
114 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
115 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
116 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
118 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
120 UINT_PTR handle = 0, num;
121 object_header_t *ret;
125 ret = heap_alloc_zero(size);
129 list_init(&ret->children);
131 EnterCriticalSection( &WININET_cs );
133 if(!handle_table_size) {
135 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
138 handle_table_size = num;
143 }else if(next_handle == handle_table_size) {
144 num = handle_table_size * 2;
145 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
148 handle_table_size = num;
155 handle = next_handle;
156 if(handle_table[handle])
157 ERR("handle isn't free but should be\n");
158 handle_table[handle] = ret;
159 ret->valid_handle = TRUE;
161 while(handle_table[next_handle] && next_handle < handle_table_size)
165 LeaveCriticalSection( &WININET_cs );
174 ret->hInternet = (HINTERNET)handle;
177 ret->lpfnStatusCB = parent->lpfnStatusCB;
178 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
184 object_header_t *WININET_AddRef( object_header_t *info )
186 ULONG refs = InterlockedIncrement(&info->refs);
187 TRACE("%p -> refcount = %d\n", info, refs );
191 object_header_t *get_handle_object( HINTERNET hinternet )
193 object_header_t *info = NULL;
194 UINT_PTR handle = (UINT_PTR) hinternet;
196 EnterCriticalSection( &WININET_cs );
198 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
199 info = WININET_AddRef(handle_table[handle]);
201 LeaveCriticalSection( &WININET_cs );
203 TRACE("handle %ld -> %p\n", handle, info);
208 static void invalidate_handle(object_header_t *info)
210 object_header_t *child, *next;
212 if(!info->valid_handle)
214 info->valid_handle = FALSE;
216 /* Free all children as native does */
217 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
219 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
220 invalidate_handle( child );
223 WININET_Release(info);
226 BOOL WININET_Release( object_header_t *info )
228 ULONG refs = InterlockedDecrement(&info->refs);
229 TRACE( "object %p refcount = %d\n", info, refs );
232 invalidate_handle(info);
233 if ( info->vtbl->CloseConnection )
235 TRACE( "closing connection %p\n", info);
236 info->vtbl->CloseConnection( info );
238 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
239 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
240 || !(info->dwInternalFlags & INET_OPENURL))
242 INTERNET_SendCallback(info, info->dwContext,
243 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
246 TRACE( "destroying object %p\n", info);
247 if ( info->htype != WH_HINIT )
248 list_remove( &info->entry );
249 info->vtbl->Destroy( info );
251 if(info->hInternet) {
252 UINT_PTR handle = (UINT_PTR)info->hInternet;
254 EnterCriticalSection( &WININET_cs );
256 handle_table[handle] = NULL;
257 if(next_handle > handle)
258 next_handle = handle;
260 LeaveCriticalSection( &WININET_cs );
268 /***********************************************************************
269 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
272 * hinstDLL [I] handle to the DLL's instance
274 * lpvReserved [I] reserved, must be NULL
281 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
283 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
286 case DLL_PROCESS_ATTACH:
288 g_dwTlsErrIndex = TlsAlloc();
290 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
293 URLCacheContainers_CreateDefaults();
295 WININET_hModule = hinstDLL;
297 case DLL_THREAD_ATTACH:
300 case DLL_THREAD_DETACH:
301 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
303 heap_free(TlsGetValue(g_dwTlsErrIndex));
307 case DLL_PROCESS_DETACH:
308 collect_connections(TRUE);
310 URLCacheContainers_DeleteAll();
312 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
314 heap_free(TlsGetValue(g_dwTlsErrIndex));
315 TlsFree(g_dwTlsErrIndex);
322 /***********************************************************************
323 * INTERNET_SaveProxySettings
325 * Stores the proxy settings given by lpwai into the registry
328 * ERROR_SUCCESS if no error, or error code on fail
330 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
335 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
338 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
346 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
354 if ((ret = RegDeleteValueW( key, szProxyServer )))
362 return ERROR_SUCCESS;
365 /***********************************************************************
366 * INTERNET_FindProxyForProtocol
368 * Searches the proxy string for a proxy of the given protocol.
369 * Returns the found proxy, or the default proxy if none of the given
373 * szProxy [In] proxy string to search
374 * proto [In] protocol to search for, e.g. "http"
375 * foundProxy [Out] found proxy
376 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
379 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
380 * *foundProxyLen is set to the required size in WCHARs, including the
381 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
383 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
388 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
390 /* First, look for the specified protocol (proto=scheme://host:port) */
391 for (ptr = szProxy; !ret && ptr && *ptr; )
395 if (!(end = strchrW(ptr, ' ')))
396 end = ptr + strlenW(ptr);
397 if ((equal = strchrW(ptr, '=')) && equal < end &&
398 equal - ptr == strlenW(proto) &&
399 !strncmpiW(proto, ptr, strlenW(proto)))
401 if (end - equal > *foundProxyLen)
403 WARN("buffer too short for %s\n",
404 debugstr_wn(equal + 1, end - equal - 1));
405 *foundProxyLen = end - equal;
406 SetLastError(ERROR_INSUFFICIENT_BUFFER);
410 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
411 foundProxy[end - equal] = 0;
422 /* It wasn't found: look for no protocol */
423 for (ptr = szProxy; !ret && ptr && *ptr; )
427 if (!(end = strchrW(ptr, ' ')))
428 end = ptr + strlenW(ptr);
429 if (!(equal = strchrW(ptr, '=')))
431 if (end - ptr + 1 > *foundProxyLen)
433 WARN("buffer too short for %s\n",
434 debugstr_wn(ptr, end - ptr));
435 *foundProxyLen = end - ptr + 1;
436 SetLastError(ERROR_INSUFFICIENT_BUFFER);
440 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
441 foundProxy[end - ptr] = 0;
452 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
453 debugstr_w(foundProxy));
457 /***********************************************************************
458 * InternetInitializeAutoProxyDll (WININET.@)
460 * Setup the internal proxy
469 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
472 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
476 /***********************************************************************
477 * DetectAutoProxyUrl (WININET.@)
479 * Auto detect the proxy url
485 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
486 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
489 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
493 static void FreeProxyInfo( proxyinfo_t *lpwpi )
495 heap_free(lpwpi->proxy);
496 heap_free(lpwpi->proxyBypass);
499 static proxyinfo_t *global_proxy;
501 static void free_global_proxy( void )
503 EnterCriticalSection( &WININET_cs );
506 FreeProxyInfo( global_proxy );
507 heap_free( global_proxy );
509 LeaveCriticalSection( &WININET_cs );
512 /***********************************************************************
513 * INTERNET_LoadProxySettings
515 * Loads proxy information from process-wide global settings, the registry,
516 * or the environment into lpwpi.
518 * The caller should call FreeProxyInfo when done with lpwpi.
521 * The proxy may be specified in the form 'http=proxy.my.org'
522 * Presumably that means there can be ftp=ftpproxy.my.org too.
524 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
531 EnterCriticalSection( &WININET_cs );
534 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
535 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
536 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
538 LeaveCriticalSection( &WININET_cs );
540 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
544 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
546 lpwpi->proxyEnabled = 0;
547 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
554 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->proxyEnabled)
556 TRACE("Proxy is enabled.\n");
558 /* figure out how much memory the proxy setting takes */
559 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
562 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
564 if (!(szProxy = heap_alloc(len)))
567 return ERROR_OUTOFMEMORY;
569 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
571 /* find the http proxy, and strip away everything else */
572 p = strstrW( szProxy, szHttp );
575 p += lstrlenW( szHttp );
576 lstrcpyW( szProxy, p );
578 p = strchrW( szProxy, ' ' );
581 lpwpi->proxy = szProxy;
583 TRACE("http proxy = %s\n", debugstr_w(lpwpi->proxy));
587 TRACE("No proxy server settings in registry.\n");
595 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
596 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
597 return ERROR_OUTOFMEMORY;
598 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
600 lpwpi->proxyEnabled = 1;
601 lpwpi->proxy = envproxyW;
603 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
607 lpwpi->proxyBypass = NULL;
609 return ERROR_SUCCESS;
612 /***********************************************************************
613 * INTERNET_ConfigureProxy
615 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
619 if (INTERNET_LoadProxySettings( &wpi ))
622 if (wpi.proxyEnabled)
624 WCHAR proxyurl[INTERNET_MAX_URL_LENGTH];
625 WCHAR username[INTERNET_MAX_USER_NAME_LENGTH];
626 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
627 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
628 URL_COMPONENTSW UrlComponents;
630 UrlComponents.dwStructSize = sizeof UrlComponents;
631 UrlComponents.dwSchemeLength = 0;
632 UrlComponents.lpszHostName = hostname;
633 UrlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
634 UrlComponents.lpszUserName = username;
635 UrlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
636 UrlComponents.lpszPassword = password;
637 UrlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
638 UrlComponents.dwExtraInfoLength = 0;
640 if(InternetCrackUrlW(wpi.proxy, 0, 0, &UrlComponents))
642 static const WCHAR szFormat[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
644 if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
645 UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
646 sprintfW(proxyurl, szFormat, hostname, UrlComponents.nPort);
648 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
649 lpwai->proxy = heap_strdupW(proxyurl);
650 if (UrlComponents.dwUserNameLength)
652 lpwai->proxyUsername = heap_strdupW(UrlComponents.lpszUserName);
653 lpwai->proxyPassword = heap_strdupW(UrlComponents.lpszPassword);
656 TRACE("http proxy = %s\n", debugstr_w(lpwai->proxy));
661 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi.proxy));
666 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
670 /***********************************************************************
671 * dump_INTERNET_FLAGS
673 * Helper function to TRACE the internet flags.
679 static void dump_INTERNET_FLAGS(DWORD dwFlags)
681 #define FE(x) { x, #x }
682 static const wininet_flag_info flag[] = {
683 FE(INTERNET_FLAG_RELOAD),
684 FE(INTERNET_FLAG_RAW_DATA),
685 FE(INTERNET_FLAG_EXISTING_CONNECT),
686 FE(INTERNET_FLAG_ASYNC),
687 FE(INTERNET_FLAG_PASSIVE),
688 FE(INTERNET_FLAG_NO_CACHE_WRITE),
689 FE(INTERNET_FLAG_MAKE_PERSISTENT),
690 FE(INTERNET_FLAG_FROM_CACHE),
691 FE(INTERNET_FLAG_SECURE),
692 FE(INTERNET_FLAG_KEEP_CONNECTION),
693 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
694 FE(INTERNET_FLAG_READ_PREFETCH),
695 FE(INTERNET_FLAG_NO_COOKIES),
696 FE(INTERNET_FLAG_NO_AUTH),
697 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
698 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
699 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
700 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
701 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
702 FE(INTERNET_FLAG_RESYNCHRONIZE),
703 FE(INTERNET_FLAG_HYPERLINK),
704 FE(INTERNET_FLAG_NO_UI),
705 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
706 FE(INTERNET_FLAG_CACHE_ASYNC),
707 FE(INTERNET_FLAG_FORMS_SUBMIT),
708 FE(INTERNET_FLAG_NEED_FILE),
709 FE(INTERNET_FLAG_TRANSFER_ASCII),
710 FE(INTERNET_FLAG_TRANSFER_BINARY)
715 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
716 if (flag[i].val & dwFlags) {
717 TRACE(" %s", flag[i].name);
718 dwFlags &= ~flag[i].val;
722 TRACE(" Unknown flags (%08x)\n", dwFlags);
727 /***********************************************************************
728 * INTERNET_CloseHandle (internal)
730 * Close internet handle
733 static VOID APPINFO_Destroy(object_header_t *hdr)
735 appinfo_t *lpwai = (appinfo_t*)hdr;
739 heap_free(lpwai->agent);
740 heap_free(lpwai->proxy);
741 heap_free(lpwai->proxyBypass);
742 heap_free(lpwai->proxyUsername);
743 heap_free(lpwai->proxyPassword);
746 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
748 appinfo_t *ai = (appinfo_t*)hdr;
751 case INTERNET_OPTION_HANDLE_TYPE:
752 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
754 if (*size < sizeof(ULONG))
755 return ERROR_INSUFFICIENT_BUFFER;
757 *size = sizeof(DWORD);
758 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
759 return ERROR_SUCCESS;
761 case INTERNET_OPTION_USER_AGENT: {
764 TRACE("INTERNET_OPTION_USER_AGENT\n");
769 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
771 *size = (len + 1) * sizeof(WCHAR);
772 if(!buffer || bufsize < *size)
773 return ERROR_INSUFFICIENT_BUFFER;
776 strcpyW(buffer, ai->agent);
778 *(WCHAR *)buffer = 0;
779 /* If the buffer is copied, the returned length doesn't include
780 * the NULL terminator.
782 *size = len * sizeof(WCHAR);
785 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
788 if(!buffer || bufsize < *size)
789 return ERROR_INSUFFICIENT_BUFFER;
792 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
795 /* If the buffer is copied, the returned length doesn't include
796 * the NULL terminator.
801 return ERROR_SUCCESS;
804 case INTERNET_OPTION_PROXY:
805 if(!size) return ERROR_INVALID_PARAMETER;
807 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
808 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
809 LPWSTR proxy, proxy_bypass;
812 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
814 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
815 if (*size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
817 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
818 return ERROR_INSUFFICIENT_BUFFER;
820 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
821 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
823 pi->dwAccessType = ai->accessType;
824 pi->lpszProxy = NULL;
825 pi->lpszProxyBypass = NULL;
827 lstrcpyW(proxy, ai->proxy);
828 pi->lpszProxy = proxy;
831 if (ai->proxyBypass) {
832 lstrcpyW(proxy_bypass, ai->proxyBypass);
833 pi->lpszProxyBypass = proxy_bypass;
836 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
837 return ERROR_SUCCESS;
839 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
840 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
841 LPSTR proxy, proxy_bypass;
844 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
846 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
847 NULL, 0, NULL, NULL);
848 if (*size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
850 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
851 return ERROR_INSUFFICIENT_BUFFER;
853 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
854 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
856 pi->dwAccessType = ai->accessType;
857 pi->lpszProxy = NULL;
858 pi->lpszProxyBypass = NULL;
860 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
861 pi->lpszProxy = proxy;
864 if (ai->proxyBypass) {
865 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
866 proxyBypassBytesRequired, NULL, NULL);
867 pi->lpszProxyBypass = proxy_bypass;
870 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
871 return ERROR_SUCCESS;
875 return INET_QueryOption(hdr, option, buffer, size, unicode);
878 static const object_vtbl_t APPINFOVtbl = {
891 /***********************************************************************
892 * InternetOpenW (WININET.@)
894 * Per-application initialization of wininet
897 * HINTERNET on success
901 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
902 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
904 appinfo_t *lpwai = NULL;
906 if (TRACE_ON(wininet)) {
907 #define FE(x) { x, #x }
908 static const wininet_flag_info access_type[] = {
909 FE(INTERNET_OPEN_TYPE_PRECONFIG),
910 FE(INTERNET_OPEN_TYPE_DIRECT),
911 FE(INTERNET_OPEN_TYPE_PROXY),
912 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
916 const char *access_type_str = "Unknown";
918 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
919 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
920 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
921 if (access_type[i].val == dwAccessType) {
922 access_type_str = access_type[i].name;
926 TRACE(" access type : %s\n", access_type_str);
928 dump_INTERNET_FLAGS(dwFlags);
931 /* Clear any error information */
932 INTERNET_SetLastError(0);
934 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
936 SetLastError(ERROR_OUTOFMEMORY);
940 lpwai->hdr.htype = WH_HINIT;
941 lpwai->hdr.dwFlags = dwFlags;
942 lpwai->accessType = dwAccessType;
943 lpwai->proxyUsername = NULL;
944 lpwai->proxyPassword = NULL;
946 lpwai->agent = heap_strdupW(lpszAgent);
947 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
948 INTERNET_ConfigureProxy( lpwai );
950 lpwai->proxy = heap_strdupW(lpszProxy);
951 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
953 TRACE("returning %p\n", lpwai);
955 return lpwai->hdr.hInternet;
959 /***********************************************************************
960 * InternetOpenA (WININET.@)
962 * Per-application initialization of wininet
965 * HINTERNET on success
969 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
970 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
972 WCHAR *szAgent, *szProxy, *szBypass;
975 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
976 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
978 szAgent = heap_strdupAtoW(lpszAgent);
979 szProxy = heap_strdupAtoW(lpszProxy);
980 szBypass = heap_strdupAtoW(lpszProxyBypass);
982 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
990 /***********************************************************************
991 * InternetGetLastResponseInfoA (WININET.@)
993 * Return last wininet error description on the calling thread
996 * TRUE on success of writing to buffer
1000 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1001 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1003 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1009 *lpdwError = lpwite->dwError;
1010 if (lpwite->dwError)
1012 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1013 *lpdwBufferLength = strlen(lpszBuffer);
1016 *lpdwBufferLength = 0;
1021 *lpdwBufferLength = 0;
1027 /***********************************************************************
1028 * InternetGetLastResponseInfoW (WININET.@)
1030 * Return last wininet error description on the calling thread
1033 * TRUE on success of writing to buffer
1037 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1038 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1040 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1046 *lpdwError = lpwite->dwError;
1047 if (lpwite->dwError)
1049 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1050 *lpdwBufferLength = lstrlenW(lpszBuffer);
1053 *lpdwBufferLength = 0;
1058 *lpdwBufferLength = 0;
1064 /***********************************************************************
1065 * InternetGetConnectedState (WININET.@)
1067 * Return connected state
1071 * if lpdwStatus is not null, return the status (off line,
1072 * modem, lan...) in it.
1073 * FALSE if not connected
1075 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1077 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1080 WARN("always returning LAN connection.\n");
1081 *lpdwStatus = INTERNET_CONNECTION_LAN;
1087 /***********************************************************************
1088 * InternetGetConnectedStateExW (WININET.@)
1090 * Return connected state
1094 * lpdwStatus [O] Flags specifying the status of the internet connection.
1095 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1096 * dwNameLen [I] Size of the buffer, in characters.
1097 * dwReserved [I] Reserved. Must be set to 0.
1101 * if lpdwStatus is not null, return the status (off line,
1102 * modem, lan...) in it.
1103 * FALSE if not connected
1106 * If the system has no available network connections, an empty string is
1107 * stored in lpszConnectionName. If there is a LAN connection, a localized
1108 * "LAN Connection" string is stored. Presumably, if only a dial-up
1109 * connection is available then the name of the dial-up connection is
1110 * returned. Why any application, other than the "Internet Settings" CPL,
1111 * would want to use this function instead of the simpler InternetGetConnectedStateW
1112 * function is beyond me.
1114 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1115 DWORD dwNameLen, DWORD dwReserved)
1117 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1124 WARN("always returning LAN connection.\n");
1125 *lpdwStatus = INTERNET_CONNECTION_LAN;
1127 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1131 /***********************************************************************
1132 * InternetGetConnectedStateExA (WININET.@)
1134 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1135 DWORD dwNameLen, DWORD dwReserved)
1137 LPWSTR lpwszConnectionName = NULL;
1140 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1142 if (lpszConnectionName && dwNameLen > 0)
1143 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1145 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1147 if (rc && lpwszConnectionName)
1149 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1150 dwNameLen, NULL, NULL);
1151 heap_free(lpwszConnectionName);
1157 /***********************************************************************
1158 * InternetConnectW (WININET.@)
1160 * Open a ftp, gopher or http session
1163 * HINTERNET a session handle on success
1167 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1168 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1169 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1170 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1173 HINTERNET rc = NULL;
1174 DWORD res = ERROR_SUCCESS;
1176 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
1177 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1178 dwService, dwFlags, dwContext);
1180 if (!lpszServerName)
1182 SetLastError(ERROR_INVALID_PARAMETER);
1186 hIC = (appinfo_t*)get_handle_object( hInternet );
1187 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1189 res = ERROR_INVALID_HANDLE;
1195 case INTERNET_SERVICE_FTP:
1196 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1197 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1199 res = INTERNET_GetLastError();
1202 case INTERNET_SERVICE_HTTP:
1203 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1204 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1207 case INTERNET_SERVICE_GOPHER:
1213 WININET_Release( &hIC->hdr );
1215 TRACE("returning %p\n", rc);
1221 /***********************************************************************
1222 * InternetConnectA (WININET.@)
1224 * Open a ftp, gopher or http session
1227 * HINTERNET a session handle on success
1231 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1232 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1233 LPCSTR lpszUserName, LPCSTR lpszPassword,
1234 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1236 HINTERNET rc = NULL;
1237 LPWSTR szServerName;
1241 szServerName = heap_strdupAtoW(lpszServerName);
1242 szUserName = heap_strdupAtoW(lpszUserName);
1243 szPassword = heap_strdupAtoW(lpszPassword);
1245 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1246 szUserName, szPassword, dwService, dwFlags, dwContext);
1248 heap_free(szServerName);
1249 heap_free(szUserName);
1250 heap_free(szPassword);
1255 /***********************************************************************
1256 * InternetFindNextFileA (WININET.@)
1258 * Continues a file search from a previous call to FindFirstFile
1265 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1268 WIN32_FIND_DATAW fd;
1270 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1272 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1276 /***********************************************************************
1277 * InternetFindNextFileW (WININET.@)
1279 * Continues a file search from a previous call to FindFirstFile
1286 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1288 object_header_t *hdr;
1293 hdr = get_handle_object(hFind);
1295 WARN("Invalid handle\n");
1296 SetLastError(ERROR_INVALID_HANDLE);
1300 if(hdr->vtbl->FindNextFileW) {
1301 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1303 WARN("Handle doesn't support NextFile\n");
1304 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1307 WININET_Release(hdr);
1309 if(res != ERROR_SUCCESS)
1311 return res == ERROR_SUCCESS;
1314 /***********************************************************************
1315 * InternetCloseHandle (WININET.@)
1317 * Generic close handle function
1324 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1326 object_header_t *obj;
1328 TRACE("%p\n", hInternet);
1330 obj = get_handle_object( hInternet );
1332 SetLastError(ERROR_INVALID_HANDLE);
1336 invalidate_handle(obj);
1337 WININET_Release(obj);
1343 /***********************************************************************
1344 * ConvertUrlComponentValue (Internal)
1346 * Helper function for InternetCrackUrlA
1349 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1350 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1351 LPCSTR lpszStart, LPCWSTR lpwszStart)
1353 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1354 if (*dwComponentLen != 0)
1356 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1357 if (*lppszComponent == NULL)
1361 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1362 *lppszComponent = (LPSTR)lpszStart + offset;
1365 *lppszComponent = NULL;
1367 *dwComponentLen = nASCIILength;
1371 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1372 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1373 (*lppszComponent)[ncpylen]=0;
1374 *dwComponentLen = ncpylen;
1380 /***********************************************************************
1381 * InternetCrackUrlA (WININET.@)
1383 * See InternetCrackUrlW.
1385 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1386 LPURL_COMPONENTSA lpUrlComponents)
1389 URL_COMPONENTSW UCW;
1391 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1392 *scheme = NULL, *extra = NULL;
1394 TRACE("(%s %u %x %p)\n",
1395 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1396 dwUrlLength, dwFlags, lpUrlComponents);
1398 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1399 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1401 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1407 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1409 /* if dwUrlLength=-1 then nLength includes null but length to
1410 InternetCrackUrlW should not include it */
1411 if (dwUrlLength == -1) nLength--;
1413 lpwszUrl = heap_alloc((nLength + 1) * sizeof(WCHAR));
1414 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1415 lpwszUrl[nLength] = '\0';
1417 memset(&UCW,0,sizeof(UCW));
1418 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1419 if (lpUrlComponents->dwHostNameLength)
1421 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1422 if (lpUrlComponents->lpszHostName)
1424 hostname = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1425 UCW.lpszHostName = hostname;
1428 if (lpUrlComponents->dwUserNameLength)
1430 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1431 if (lpUrlComponents->lpszUserName)
1433 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1434 UCW.lpszUserName = username;
1437 if (lpUrlComponents->dwPasswordLength)
1439 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1440 if (lpUrlComponents->lpszPassword)
1442 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1443 UCW.lpszPassword = password;
1446 if (lpUrlComponents->dwUrlPathLength)
1448 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1449 if (lpUrlComponents->lpszUrlPath)
1451 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1452 UCW.lpszUrlPath = path;
1455 if (lpUrlComponents->dwSchemeLength)
1457 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1458 if (lpUrlComponents->lpszScheme)
1460 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1461 UCW.lpszScheme = scheme;
1464 if (lpUrlComponents->dwExtraInfoLength)
1466 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1467 if (lpUrlComponents->lpszExtraInfo)
1469 extra = heap_alloc(UCW.dwExtraInfoLength * sizeof(WCHAR));
1470 UCW.lpszExtraInfo = extra;
1473 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1475 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1476 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1477 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1478 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1479 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1480 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1481 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1482 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1483 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1484 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1485 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1486 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1488 lpUrlComponents->nScheme = UCW.nScheme;
1489 lpUrlComponents->nPort = UCW.nPort;
1491 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1492 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1493 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1494 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1495 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1497 heap_free(lpwszUrl);
1498 heap_free(hostname);
1499 heap_free(username);
1500 heap_free(password);
1507 static const WCHAR url_schemes[][7] =
1510 {'g','o','p','h','e','r',0},
1511 {'h','t','t','p',0},
1512 {'h','t','t','p','s',0},
1513 {'f','i','l','e',0},
1514 {'n','e','w','s',0},
1515 {'m','a','i','l','t','o',0},
1519 /***********************************************************************
1520 * GetInternetSchemeW (internal)
1526 * INTERNET_SCHEME_UNKNOWN on failure
1529 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1533 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1535 if(lpszScheme==NULL)
1536 return INTERNET_SCHEME_UNKNOWN;
1538 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1539 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1540 return INTERNET_SCHEME_FIRST + i;
1542 return INTERNET_SCHEME_UNKNOWN;
1545 /***********************************************************************
1546 * SetUrlComponentValueW (Internal)
1548 * Helper function for InternetCrackUrlW
1551 * lppszComponent [O] Holds the returned string
1552 * dwComponentLen [I] Holds the size of lppszComponent
1553 * [O] Holds the length of the string in lppszComponent without '\0'
1554 * lpszStart [I] Holds the string to copy from
1555 * len [I] Holds the length of lpszStart without '\0'
1562 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1564 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1566 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1569 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1571 if (*lppszComponent == NULL)
1573 *lppszComponent = (LPWSTR)lpszStart;
1574 *dwComponentLen = len;
1578 DWORD ncpylen = min((*dwComponentLen)-1, len);
1579 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1580 (*lppszComponent)[ncpylen] = '\0';
1581 *dwComponentLen = ncpylen;
1588 /***********************************************************************
1589 * InternetCrackUrlW (WININET.@)
1591 * Break up URL into its components
1597 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1598 LPURL_COMPONENTSW lpUC)
1602 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1605 LPCWSTR lpszParam = NULL;
1606 BOOL bIsAbsolute = FALSE;
1607 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1608 LPCWSTR lpszcp = NULL;
1609 LPWSTR lpszUrl_decode = NULL;
1610 DWORD dwUrlLength = dwUrlLength_orig;
1612 TRACE("(%s %u %x %p)\n",
1613 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1614 dwUrlLength, dwFlags, lpUC);
1616 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1618 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1621 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1623 if (dwFlags & ICU_DECODE)
1626 DWORD len = dwUrlLength + 1;
1628 if (!(url_tmp = heap_alloc(len * sizeof(WCHAR))))
1630 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1633 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1634 url_tmp[dwUrlLength] = 0;
1635 if (!(lpszUrl_decode = heap_alloc(len * sizeof(WCHAR))))
1638 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1641 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1644 lpszUrl = lpszUrl_decode;
1650 /* Determine if the URI is absolute. */
1651 while (lpszap - lpszUrl < dwUrlLength)
1653 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1658 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1665 lpszcp = lpszUrl; /* Relative url */
1671 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1672 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1674 /* Parse <params> */
1675 lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl));
1677 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1679 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1681 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1682 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1684 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1688 /* Get scheme first. */
1689 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1690 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1691 lpszUrl, lpszcp - lpszUrl);
1693 /* Eat ':' in protocol. */
1696 /* double slash indicates the net_loc portion is present */
1697 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1701 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1705 lpszNetLoc = min(lpszNetLoc, lpszParam);
1707 lpszNetLoc = lpszParam;
1709 else if (!lpszNetLoc)
1710 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1718 /* [<user>[<:password>]@]<host>[:<port>] */
1719 /* First find the user and password if they exist */
1721 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1722 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1724 /* username and password not specified. */
1725 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1726 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1728 else /* Parse out username and password */
1730 LPCWSTR lpszUser = lpszcp;
1731 LPCWSTR lpszPasswd = lpszHost;
1733 while (lpszcp < lpszHost)
1736 lpszPasswd = lpszcp;
1741 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1742 lpszUser, lpszPasswd - lpszUser);
1744 if (lpszPasswd != lpszHost)
1746 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1747 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1748 lpszHost - lpszPasswd);
1750 lpszcp++; /* Advance to beginning of host */
1753 /* Parse <host><:port> */
1756 lpszPort = lpszNetLoc;
1758 /* special case for res:// URLs: there is no port here, so the host is the
1759 entire string up to the first '/' */
1760 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1762 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1763 lpszHost, lpszPort - lpszHost);
1768 while (lpszcp < lpszNetLoc)
1776 /* If the scheme is "file" and the host is just one letter, it's not a host */
1777 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1780 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1785 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1786 lpszHost, lpszPort - lpszHost);
1787 if (lpszPort != lpszNetLoc)
1788 lpUC->nPort = atoiW(++lpszPort);
1789 else switch (lpUC->nScheme)
1791 case INTERNET_SCHEME_HTTP:
1792 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1794 case INTERNET_SCHEME_HTTPS:
1795 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1797 case INTERNET_SCHEME_FTP:
1798 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1800 case INTERNET_SCHEME_GOPHER:
1801 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1812 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1813 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1814 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1819 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1820 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1821 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1822 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1825 /* Here lpszcp points to:
1827 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1828 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1830 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1834 /* Only truncate the parameter list if it's already been saved
1835 * in lpUC->lpszExtraInfo.
1837 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1838 len = lpszParam - lpszcp;
1841 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1842 * newlines if necessary.
1844 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1845 if (lpsznewline != NULL)
1846 len = lpsznewline - lpszcp;
1848 len = dwUrlLength-(lpszcp-lpszUrl);
1850 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1851 lpUC->nScheme == INTERNET_SCHEME_FILE)
1853 WCHAR tmppath[MAX_PATH];
1857 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
1862 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1863 tmppath[len] = '\0';
1872 /* if ends in \. or \.. append a backslash */
1873 if (tmppath[len - 1] == '.' &&
1874 (tmppath[len - 2] == '\\' ||
1875 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1877 if (len < MAX_PATH - 1)
1879 tmppath[len] = '\\';
1880 tmppath[len+1] = '\0';
1884 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1888 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1893 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1894 lpUC->lpszUrlPath[0] = 0;
1895 lpUC->dwUrlPathLength = 0;
1898 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1899 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1900 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1901 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1902 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1904 heap_free( lpszUrl_decode );
1908 /***********************************************************************
1909 * InternetAttemptConnect (WININET.@)
1911 * Attempt to make a connection to the internet
1914 * ERROR_SUCCESS on success
1915 * Error value on failure
1918 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1921 return ERROR_SUCCESS;
1925 /***********************************************************************
1926 * InternetCanonicalizeUrlA (WININET.@)
1928 * Escape unsafe characters and spaces
1935 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1936 LPDWORD lpdwBufferLength, DWORD dwFlags)
1939 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1941 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1942 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1944 if(dwFlags & ICU_DECODE)
1946 dwURLFlags |= URL_UNESCAPE;
1947 dwFlags &= ~ICU_DECODE;
1950 if(dwFlags & ICU_ESCAPE)
1952 dwURLFlags |= URL_UNESCAPE;
1953 dwFlags &= ~ICU_ESCAPE;
1956 if(dwFlags & ICU_BROWSER_MODE)
1958 dwURLFlags |= URL_BROWSER_MODE;
1959 dwFlags &= ~ICU_BROWSER_MODE;
1962 if(dwFlags & ICU_NO_ENCODE)
1964 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1965 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1966 dwFlags &= ~ICU_NO_ENCODE;
1969 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1971 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1972 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1973 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1975 return (hr == S_OK) ? TRUE : FALSE;
1978 /***********************************************************************
1979 * InternetCanonicalizeUrlW (WININET.@)
1981 * Escape unsafe characters and spaces
1988 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1989 LPDWORD lpdwBufferLength, DWORD dwFlags)
1992 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1994 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1995 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1997 if(dwFlags & ICU_DECODE)
1999 dwURLFlags |= URL_UNESCAPE;
2000 dwFlags &= ~ICU_DECODE;
2003 if(dwFlags & ICU_ESCAPE)
2005 dwURLFlags |= URL_UNESCAPE;
2006 dwFlags &= ~ICU_ESCAPE;
2009 if(dwFlags & ICU_BROWSER_MODE)
2011 dwURLFlags |= URL_BROWSER_MODE;
2012 dwFlags &= ~ICU_BROWSER_MODE;
2015 if(dwFlags & ICU_NO_ENCODE)
2017 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2018 dwURLFlags ^= URL_ESCAPE_UNSAFE;
2019 dwFlags &= ~ICU_NO_ENCODE;
2022 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
2024 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
2025 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2026 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2028 return (hr == S_OK) ? TRUE : FALSE;
2031 /* #################################################### */
2033 static INTERNET_STATUS_CALLBACK set_status_callback(
2034 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2036 INTERNET_STATUS_CALLBACK ret;
2038 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2039 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2041 ret = lpwh->lpfnStatusCB;
2042 lpwh->lpfnStatusCB = callback;
2047 /***********************************************************************
2048 * InternetSetStatusCallbackA (WININET.@)
2050 * Sets up a callback function which is called as progress is made
2051 * during an operation.
2054 * Previous callback or NULL on success
2055 * INTERNET_INVALID_STATUS_CALLBACK on failure
2058 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2059 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2061 INTERNET_STATUS_CALLBACK retVal;
2062 object_header_t *lpwh;
2064 TRACE("%p\n", hInternet);
2066 if (!(lpwh = get_handle_object(hInternet)))
2067 return INTERNET_INVALID_STATUS_CALLBACK;
2069 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2071 WININET_Release( lpwh );
2075 /***********************************************************************
2076 * InternetSetStatusCallbackW (WININET.@)
2078 * Sets up a callback function which is called as progress is made
2079 * during an operation.
2082 * Previous callback or NULL on success
2083 * INTERNET_INVALID_STATUS_CALLBACK on failure
2086 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2087 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2089 INTERNET_STATUS_CALLBACK retVal;
2090 object_header_t *lpwh;
2092 TRACE("%p\n", hInternet);
2094 if (!(lpwh = get_handle_object(hInternet)))
2095 return INTERNET_INVALID_STATUS_CALLBACK;
2097 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2099 WININET_Release( lpwh );
2103 /***********************************************************************
2104 * InternetSetFilePointer (WININET.@)
2106 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2107 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2113 /***********************************************************************
2114 * InternetWriteFile (WININET.@)
2116 * Write data to an open internet file
2123 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2124 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2126 object_header_t *lpwh;
2129 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2131 lpwh = get_handle_object( hFile );
2133 WARN("Invalid handle\n");
2134 SetLastError(ERROR_INVALID_HANDLE);
2138 if(lpwh->vtbl->WriteFile) {
2139 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2141 WARN("No Writefile method.\n");
2142 res = ERROR_INVALID_HANDLE;
2145 WININET_Release( lpwh );
2147 if(res != ERROR_SUCCESS)
2149 return res == ERROR_SUCCESS;
2153 /***********************************************************************
2154 * InternetReadFile (WININET.@)
2156 * Read data from an open internet file
2163 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2164 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2166 object_header_t *hdr;
2167 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2169 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2171 hdr = get_handle_object(hFile);
2173 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2177 if(hdr->vtbl->ReadFile)
2178 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2180 WININET_Release(hdr);
2182 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2183 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2185 if(res != ERROR_SUCCESS)
2187 return res == ERROR_SUCCESS;
2190 /***********************************************************************
2191 * InternetReadFileExA (WININET.@)
2193 * Read data from an open internet file
2196 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2197 * lpBuffersOut [I/O] Buffer.
2198 * dwFlags [I] Flags. See notes.
2199 * dwContext [I] Context for callbacks.
2206 * The parameter dwFlags include zero or more of the following flags:
2207 *|IRF_ASYNC - Makes the call asynchronous.
2208 *|IRF_SYNC - Makes the call synchronous.
2209 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2210 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2212 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2215 * InternetOpenUrlA(), HttpOpenRequestA()
2217 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2218 DWORD dwFlags, DWORD_PTR dwContext)
2220 object_header_t *hdr;
2221 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2223 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2225 hdr = get_handle_object(hFile);
2227 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2231 if(hdr->vtbl->ReadFileExA)
2232 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
2234 WININET_Release(hdr);
2236 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2237 res, lpBuffersOut->dwBufferLength);
2239 if(res != ERROR_SUCCESS)
2241 return res == ERROR_SUCCESS;
2244 /***********************************************************************
2245 * InternetReadFileExW (WININET.@)
2247 * InternetReadFileExA()
2249 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2250 DWORD dwFlags, DWORD_PTR dwContext)
2252 object_header_t *hdr;
2253 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2255 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2257 hdr = get_handle_object(hFile);
2259 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2263 if(hdr->vtbl->ReadFileExW)
2264 res = hdr->vtbl->ReadFileExW(hdr, lpBuffer, dwFlags, dwContext);
2266 WININET_Release(hdr);
2268 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2269 res, lpBuffer->dwBufferLength);
2271 if(res != ERROR_SUCCESS)
2273 return res == ERROR_SUCCESS;
2276 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2278 static BOOL warn = TRUE;
2281 case INTERNET_OPTION_REQUEST_FLAGS:
2282 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2284 if (*size < sizeof(ULONG))
2285 return ERROR_INSUFFICIENT_BUFFER;
2287 *(ULONG*)buffer = 4;
2288 *size = sizeof(ULONG);
2290 return ERROR_SUCCESS;
2292 case INTERNET_OPTION_HTTP_VERSION:
2293 if (*size < sizeof(HTTP_VERSION_INFO))
2294 return ERROR_INSUFFICIENT_BUFFER;
2297 * Presently hardcoded to 1.1
2299 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2300 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2301 *size = sizeof(HTTP_VERSION_INFO);
2303 return ERROR_SUCCESS;
2305 case INTERNET_OPTION_CONNECTED_STATE:
2307 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2310 if (*size < sizeof(ULONG))
2311 return ERROR_INSUFFICIENT_BUFFER;
2313 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2314 *size = sizeof(ULONG);
2316 return ERROR_SUCCESS;
2318 case INTERNET_OPTION_PROXY: {
2322 TRACE("Getting global proxy info\n");
2323 memset(&ai, 0, sizeof(appinfo_t));
2324 INTERNET_ConfigureProxy(&ai);
2326 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2327 APPINFO_Destroy(&ai.hdr);
2331 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2332 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2334 if (*size < sizeof(ULONG))
2335 return ERROR_INSUFFICIENT_BUFFER;
2337 *(ULONG*)buffer = 2;
2338 *size = sizeof(ULONG);
2340 return ERROR_SUCCESS;
2342 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2343 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2345 if (*size < sizeof(ULONG))
2346 return ERROR_INSUFFICIENT_BUFFER;
2348 *(ULONG*)buffer = 4;
2349 *size = sizeof(ULONG);
2351 return ERROR_SUCCESS;
2353 case INTERNET_OPTION_SECURITY_FLAGS:
2354 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2355 return ERROR_SUCCESS;
2357 case INTERNET_OPTION_VERSION: {
2358 static const INTERNET_VERSION_INFO info = { 1, 2 };
2360 TRACE("INTERNET_OPTION_VERSION\n");
2362 if (*size < sizeof(INTERNET_VERSION_INFO))
2363 return ERROR_INSUFFICIENT_BUFFER;
2365 memcpy(buffer, &info, sizeof(info));
2366 *size = sizeof(info);
2368 return ERROR_SUCCESS;
2371 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2372 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2373 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2374 DWORD res = ERROR_SUCCESS, i;
2378 TRACE("Getting global proxy info\n");
2379 if((ret = INTERNET_LoadProxySettings(&pi)))
2382 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2384 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2386 return ERROR_INSUFFICIENT_BUFFER;
2389 for (i = 0; i < con->dwOptionCount; i++) {
2390 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2391 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2393 switch (optionW->dwOption) {
2394 case INTERNET_PER_CONN_FLAGS:
2396 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2398 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2401 case INTERNET_PER_CONN_PROXY_SERVER:
2403 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2405 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2408 case INTERNET_PER_CONN_PROXY_BYPASS:
2410 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2412 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2415 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2416 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2417 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2418 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2419 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2420 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2421 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2422 memset(&optionW->Value, 0, sizeof(optionW->Value));
2426 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2427 res = ERROR_INVALID_PARAMETER;
2435 case INTERNET_OPTION_USER_AGENT:
2436 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2437 case INTERNET_OPTION_POLICY:
2438 return ERROR_INVALID_PARAMETER;
2439 case INTERNET_OPTION_CONTEXT_VALUE:
2442 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2444 return ERROR_INVALID_PARAMETER;
2446 if (*size < sizeof(DWORD_PTR))
2448 *size = sizeof(DWORD_PTR);
2449 return ERROR_INSUFFICIENT_BUFFER;
2452 return ERROR_INVALID_PARAMETER;
2454 *(DWORD_PTR *)buffer = hdr->dwContext;
2455 *size = sizeof(DWORD_PTR);
2456 return ERROR_SUCCESS;
2460 FIXME("Stub for %d\n", option);
2461 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2464 /***********************************************************************
2465 * InternetQueryOptionW (WININET.@)
2467 * Queries an options on the specified handle
2474 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2475 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2477 object_header_t *hdr;
2478 DWORD res = ERROR_INVALID_HANDLE;
2480 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2483 hdr = get_handle_object(hInternet);
2485 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2486 WININET_Release(hdr);
2489 res = INET_QueryOption(NULL, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2492 if(res != ERROR_SUCCESS)
2494 return res == ERROR_SUCCESS;
2497 /***********************************************************************
2498 * InternetQueryOptionA (WININET.@)
2500 * Queries an options on the specified handle
2507 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2508 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2510 object_header_t *hdr;
2511 DWORD res = ERROR_INVALID_HANDLE;
2513 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2516 hdr = get_handle_object(hInternet);
2518 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2519 WININET_Release(hdr);
2522 res = INET_QueryOption(NULL, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2525 if(res != ERROR_SUCCESS)
2527 return res == ERROR_SUCCESS;
2531 /***********************************************************************
2532 * InternetSetOptionW (WININET.@)
2534 * Sets an options on the specified handle
2541 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2542 LPVOID lpBuffer, DWORD dwBufferLength)
2544 object_header_t *lpwhh;
2547 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2549 lpwhh = (object_header_t*) get_handle_object( hInternet );
2550 if(lpwhh && lpwhh->vtbl->SetOption) {
2553 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2554 if(res != ERROR_INTERNET_INVALID_OPTION) {
2555 WININET_Release( lpwhh );
2557 if(res != ERROR_SUCCESS)
2560 return res == ERROR_SUCCESS;
2566 case INTERNET_OPTION_CALLBACK:
2570 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2573 WININET_Release(lpwhh);
2574 SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2577 case INTERNET_OPTION_HTTP_VERSION:
2579 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2580 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2583 case INTERNET_OPTION_ERROR_MASK:
2586 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2588 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2589 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2590 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2591 SetLastError(ERROR_INVALID_PARAMETER);
2593 } else if(dwBufferLength != sizeof(ULONG)) {
2594 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2597 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2600 case INTERNET_OPTION_PROXY:
2602 INTERNET_PROXY_INFOW *info = lpBuffer;
2604 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2606 SetLastError(ERROR_INVALID_PARAMETER);
2611 EnterCriticalSection( &WININET_cs );
2612 free_global_proxy();
2613 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2616 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2618 global_proxy->proxyEnabled = 1;
2619 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2620 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2624 global_proxy->proxyEnabled = 0;
2625 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2628 LeaveCriticalSection( &WININET_cs );
2632 /* In general, each type of object should handle
2633 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2634 * get silently dropped.
2636 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2637 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2642 case INTERNET_OPTION_CODEPAGE:
2644 ULONG codepage = *(ULONG *)lpBuffer;
2645 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2648 case INTERNET_OPTION_REQUEST_PRIORITY:
2650 ULONG priority = *(ULONG *)lpBuffer;
2651 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2654 case INTERNET_OPTION_CONNECT_TIMEOUT:
2656 ULONG connecttimeout = *(ULONG *)lpBuffer;
2657 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2660 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2662 ULONG receivetimeout = *(ULONG *)lpBuffer;
2663 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2666 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2668 ULONG conns = *(ULONG *)lpBuffer;
2669 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2672 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2674 ULONG conns = *(ULONG *)lpBuffer;
2675 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2678 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2679 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2681 case INTERNET_OPTION_END_BROWSER_SESSION:
2682 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2684 case INTERNET_OPTION_CONNECTED_STATE:
2685 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2687 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2688 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2690 case INTERNET_OPTION_SEND_TIMEOUT:
2691 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2692 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2694 ULONG timeout = *(ULONG *)lpBuffer;
2695 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2698 case INTERNET_OPTION_CONNECT_RETRIES:
2700 ULONG retries = *(ULONG *)lpBuffer;
2701 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2704 case INTERNET_OPTION_CONTEXT_VALUE:
2708 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2711 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2713 SetLastError(ERROR_INVALID_PARAMETER);
2717 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2720 case INTERNET_OPTION_SECURITY_FLAGS:
2721 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2723 case INTERNET_OPTION_DISABLE_AUTODIAL:
2724 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2726 case INTERNET_OPTION_HTTP_DECODING:
2727 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2728 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2731 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2732 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2733 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2736 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2737 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2738 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2741 case INTERNET_OPTION_CODEPAGE_PATH:
2742 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2743 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2746 case INTERNET_OPTION_CODEPAGE_EXTRA:
2747 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2748 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2751 case INTERNET_OPTION_IDN:
2752 FIXME("INTERNET_OPTION_IDN; STUB\n");
2753 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2756 case INTERNET_OPTION_POLICY:
2757 SetLastError(ERROR_INVALID_PARAMETER);
2760 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2761 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2766 INTERNET_LoadProxySettings(&pi);
2768 for (i = 0; i < con->dwOptionCount; i++) {
2769 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2771 switch (option->dwOption) {
2772 case INTERNET_PER_CONN_PROXY_SERVER:
2773 heap_free(pi.proxy);
2774 pi.proxy = heap_strdupW(option->Value.pszValue);
2777 case INTERNET_PER_CONN_FLAGS:
2778 if(option->Value.dwValue & PROXY_TYPE_PROXY)
2779 pi.proxyEnabled = 1;
2782 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
2783 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
2784 pi.proxyEnabled = 0;
2788 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2789 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2790 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2791 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2792 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2793 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2794 case INTERNET_PER_CONN_PROXY_BYPASS:
2795 FIXME("Unhandled dwOption %d\n", option->dwOption);
2799 FIXME("Unknown dwOption %d\n", option->dwOption);
2800 SetLastError(ERROR_INVALID_PARAMETER);
2805 if ((res = INTERNET_SaveProxySettings(&pi)))
2810 ret = (res == ERROR_SUCCESS);
2814 FIXME("Option %d STUB\n",dwOption);
2815 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2821 WININET_Release( lpwhh );
2827 /***********************************************************************
2828 * InternetSetOptionA (WININET.@)
2830 * Sets an options on the specified handle.
2837 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2838 LPVOID lpBuffer, DWORD dwBufferLength)
2846 case INTERNET_OPTION_CALLBACK:
2848 object_header_t *lpwh;
2850 if (!(lpwh = get_handle_object(hInternet)))
2852 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2855 WININET_Release(lpwh);
2856 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2859 case INTERNET_OPTION_PROXY:
2861 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2862 LPINTERNET_PROXY_INFOW piw;
2863 DWORD proxlen, prbylen;
2866 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2867 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2868 wlen = sizeof(*piw) + proxlen + prbylen;
2869 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2870 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2871 piw->dwAccessType = pi->dwAccessType;
2872 prox = (LPWSTR) &piw[1];
2873 prby = &prox[proxlen+1];
2874 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2875 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2876 piw->lpszProxy = prox;
2877 piw->lpszProxyBypass = prby;
2880 case INTERNET_OPTION_USER_AGENT:
2881 case INTERNET_OPTION_USERNAME:
2882 case INTERNET_OPTION_PASSWORD:
2883 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2885 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2886 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2889 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2891 INTERNET_PER_CONN_OPTION_LISTW *listW;
2892 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
2893 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2894 wbuffer = heap_alloc(wlen);
2897 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2898 if (listA->pszConnection)
2900 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
2901 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
2902 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
2905 listW->pszConnection = NULL;
2906 listW->dwOptionCount = listA->dwOptionCount;
2907 listW->dwOptionError = listA->dwOptionError;
2908 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
2910 for (i = 0; i < listA->dwOptionCount; ++i) {
2911 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
2912 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
2914 optW->dwOption = optA->dwOption;
2916 switch (optA->dwOption) {
2917 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2918 case INTERNET_PER_CONN_PROXY_BYPASS:
2919 case INTERNET_PER_CONN_PROXY_SERVER:
2920 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2921 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2922 if (optA->Value.pszValue)
2924 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
2925 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
2926 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
2929 optW->Value.pszValue = NULL;
2931 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2932 case INTERNET_PER_CONN_FLAGS:
2933 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2934 optW->Value.dwValue = optA->Value.dwValue;
2936 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2937 optW->Value.ftValue = optA->Value.ftValue;
2940 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
2941 optW->Value.dwValue = optA->Value.dwValue;
2949 wlen = dwBufferLength;
2952 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2954 if( lpBuffer != wbuffer )
2956 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
2958 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
2960 for (i = 0; i < list->dwOptionCount; ++i) {
2961 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
2962 switch (opt->dwOption) {
2963 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2964 case INTERNET_PER_CONN_PROXY_BYPASS:
2965 case INTERNET_PER_CONN_PROXY_SERVER:
2966 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2967 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2968 heap_free( opt->Value.pszValue );
2974 heap_free( list->pOptions );
2976 heap_free( wbuffer );
2983 /***********************************************************************
2984 * InternetSetOptionExA (WININET.@)
2986 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2987 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2989 FIXME("Flags %08x ignored\n", dwFlags);
2990 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2993 /***********************************************************************
2994 * InternetSetOptionExW (WININET.@)
2996 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2997 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2999 FIXME("Flags %08x ignored\n", dwFlags);
3000 if( dwFlags & ~ISO_VALID_FLAGS )
3002 SetLastError( ERROR_INVALID_PARAMETER );
3005 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3008 static const WCHAR WININET_wkday[7][4] =
3009 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3010 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3011 static const WCHAR WININET_month[12][4] =
3012 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3013 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3014 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3016 /***********************************************************************
3017 * InternetTimeFromSystemTimeA (WININET.@)
3019 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3022 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3024 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3026 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3028 SetLastError(ERROR_INVALID_PARAMETER);
3032 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3034 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3038 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3039 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3044 /***********************************************************************
3045 * InternetTimeFromSystemTimeW (WININET.@)
3047 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3049 static const WCHAR date[] =
3050 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3051 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3053 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3055 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3057 SetLastError(ERROR_INVALID_PARAMETER);
3061 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3063 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3067 sprintfW( string, date,
3068 WININET_wkday[time->wDayOfWeek],
3070 WININET_month[time->wMonth - 1],
3079 /***********************************************************************
3080 * InternetTimeToSystemTimeA (WININET.@)
3082 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3087 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3089 stringW = heap_strdupAtoW(string);
3092 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3093 heap_free( stringW );
3098 /***********************************************************************
3099 * InternetTimeToSystemTimeW (WININET.@)
3101 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3104 const WCHAR *s = string;
3107 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3109 if (!string || !time) return FALSE;
3111 /* Windows does this too */
3112 GetSystemTime( time );
3114 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3115 * a SYSTEMTIME structure.
3118 while (*s && !isalphaW( *s )) s++;
3119 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3120 time->wDayOfWeek = 7;
3122 for (i = 0; i < 7; i++)
3124 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3125 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3126 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3128 time->wDayOfWeek = i;
3133 if (time->wDayOfWeek > 6) return TRUE;
3134 while (*s && !isdigitW( *s )) s++;
3135 time->wDay = strtolW( s, &end, 10 );
3138 while (*s && !isalphaW( *s )) s++;
3139 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3142 for (i = 0; i < 12; i++)
3144 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3145 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3146 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3148 time->wMonth = i + 1;
3152 if (time->wMonth == 0) return TRUE;
3154 while (*s && !isdigitW( *s )) s++;
3155 if (*s == '\0') return TRUE;
3156 time->wYear = strtolW( s, &end, 10 );
3159 while (*s && !isdigitW( *s )) s++;
3160 if (*s == '\0') return TRUE;
3161 time->wHour = strtolW( s, &end, 10 );
3164 while (*s && !isdigitW( *s )) s++;
3165 if (*s == '\0') return TRUE;
3166 time->wMinute = strtolW( s, &end, 10 );
3169 while (*s && !isdigitW( *s )) s++;
3170 if (*s == '\0') return TRUE;
3171 time->wSecond = strtolW( s, &end, 10 );
3174 time->wMilliseconds = 0;
3178 /***********************************************************************
3179 * InternetCheckConnectionW (WININET.@)
3181 * Pings a requested host to check internet connection
3184 * TRUE on success and FALSE on failure. If a failure then
3185 * ERROR_NOT_CONNECTED is placed into GetLastError
3188 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3191 * this is a kludge which runs the resident ping program and reads the output.
3193 * Anyone have a better idea?
3197 static const CHAR ping[] = "ping -c 1 ";
3198 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3199 CHAR *command = NULL;
3200 WCHAR hostW[INTERNET_MAX_HOST_NAME_LENGTH];
3208 * Crack or set the Address
3210 if (lpszUrl == NULL)
3213 * According to the doc we are supposed to use the ip for the next
3214 * server in the WnInet internal server database. I have
3215 * no idea what that is or how to get it.
3217 * So someone needs to implement this.
3219 FIXME("Unimplemented with URL of NULL\n");
3224 URL_COMPONENTSW components;
3226 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3227 components.lpszHostName = (LPWSTR)hostW;
3228 components.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3230 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3233 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3234 port = components.nPort;
3235 TRACE("port: %d\n", port);
3238 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3240 struct sockaddr_storage saddr;
3241 socklen_t sa_len = sizeof(saddr);
3244 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3246 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3249 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3257 * Build our ping command
3259 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3260 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3261 strcpy(command,ping);
3262 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3263 strcat(command,redirect);
3265 TRACE("Ping command is : %s\n",command);
3267 status = system(command);
3269 TRACE("Ping returned a code of %i\n",status);
3271 /* Ping return code of 0 indicates success */
3277 heap_free( command );
3279 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3285 /***********************************************************************
3286 * InternetCheckConnectionA (WININET.@)
3288 * Pings a requested host to check internet connection
3291 * TRUE on success and FALSE on failure. If a failure then
3292 * ERROR_NOT_CONNECTED is placed into GetLastError
3295 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3301 url = heap_strdupAtoW(lpszUrl);
3306 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3313 /**********************************************************
3314 * INTERNET_InternetOpenUrlW (internal)
3319 * handle of connection or NULL on failure
3321 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3322 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3324 URL_COMPONENTSW urlComponents;
3325 WCHAR protocol[INTERNET_MAX_SCHEME_LENGTH];
3326 WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH];
3327 WCHAR userName[INTERNET_MAX_USER_NAME_LENGTH];
3328 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
3329 WCHAR path[INTERNET_MAX_PATH_LENGTH];
3331 HINTERNET client = NULL, client1 = NULL;
3334 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3335 dwHeadersLength, dwFlags, dwContext);
3337 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3338 urlComponents.lpszScheme = protocol;
3339 urlComponents.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH;
3340 urlComponents.lpszHostName = hostName;
3341 urlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3342 urlComponents.lpszUserName = userName;
3343 urlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
3344 urlComponents.lpszPassword = password;
3345 urlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
3346 urlComponents.lpszUrlPath = path;
3347 urlComponents.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
3348 urlComponents.lpszExtraInfo = extra;
3349 urlComponents.dwExtraInfoLength = 1024;
3350 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3352 switch(urlComponents.nScheme) {
3353 case INTERNET_SCHEME_FTP:
3354 if(urlComponents.nPort == 0)
3355 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3356 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3357 userName, password, dwFlags, dwContext, INET_OPENURL);
3360 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3361 if(client1 == NULL) {
3362 InternetCloseHandle(client);
3367 case INTERNET_SCHEME_HTTP:
3368 case INTERNET_SCHEME_HTTPS: {
3369 static const WCHAR szStars[] = { '*','/','*', 0 };
3370 LPCWSTR accept[2] = { szStars, NULL };
3371 if(urlComponents.nPort == 0) {
3372 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3373 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3375 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3377 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3379 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3380 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3381 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3382 if(res != ERROR_SUCCESS) {
3383 INTERNET_SetLastError(res);
3387 if (urlComponents.dwExtraInfoLength) {
3389 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3391 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3393 InternetCloseHandle(client);
3396 strcpyW(path_extra, urlComponents.lpszUrlPath);
3397 strcatW(path_extra, urlComponents.lpszExtraInfo);
3398 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3399 heap_free(path_extra);
3402 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3404 if(client1 == NULL) {
3405 InternetCloseHandle(client);
3408 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3409 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3410 GetLastError() != ERROR_IO_PENDING) {
3411 InternetCloseHandle(client1);
3416 case INTERNET_SCHEME_GOPHER:
3417 /* gopher doesn't seem to be implemented in wine, but it's supposed
3418 * to be supported by InternetOpenUrlA. */
3420 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3424 TRACE(" %p <--\n", client1);
3429 /**********************************************************
3430 * InternetOpenUrlW (WININET.@)
3435 * handle of connection or NULL on failure
3437 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3439 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3440 appinfo_t *hIC = (appinfo_t*) workRequest->hdr;
3444 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3445 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3446 heap_free(req->lpszUrl);
3447 heap_free(req->lpszHeaders);
3450 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3451 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3453 HINTERNET ret = NULL;
3454 appinfo_t *hIC = NULL;
3456 if (TRACE_ON(wininet)) {
3457 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3458 dwHeadersLength, dwFlags, dwContext);
3460 dump_INTERNET_FLAGS(dwFlags);
3465 SetLastError(ERROR_INVALID_PARAMETER);
3469 hIC = (appinfo_t*)get_handle_object( hInternet );
3470 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3471 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3475 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3476 WORKREQUEST workRequest;
3477 struct WORKREQ_INTERNETOPENURLW *req;
3479 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3480 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3481 req = &workRequest.u.InternetOpenUrlW;
3482 req->lpszUrl = heap_strdupW(lpszUrl);
3483 req->lpszHeaders = heap_strdupW(lpszHeaders);
3484 req->dwHeadersLength = dwHeadersLength;
3485 req->dwFlags = dwFlags;
3486 req->dwContext = dwContext;
3488 INTERNET_AsyncCall(&workRequest);
3490 * This is from windows.
3492 SetLastError(ERROR_IO_PENDING);
3494 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3499 WININET_Release( &hIC->hdr );
3500 TRACE(" %p <--\n", ret);
3505 /**********************************************************
3506 * InternetOpenUrlA (WININET.@)
3511 * handle of connection or NULL on failure
3513 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3514 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3516 HINTERNET rc = NULL;
3517 DWORD lenHeaders = 0;
3518 LPWSTR szUrl = NULL;
3519 LPWSTR szHeaders = NULL;
3524 szUrl = heap_strdupAtoW(lpszUrl);
3530 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3531 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3536 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3539 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3540 lenHeaders, dwFlags, dwContext);
3543 heap_free(szHeaders);
3548 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3550 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3554 lpwite->dwError = 0;
3555 lpwite->response[0] = '\0';
3558 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3567 /***********************************************************************
3568 * INTERNET_SetLastError (internal)
3570 * Set last thread specific error
3575 void INTERNET_SetLastError(DWORD dwError)
3577 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3580 lpwite = INTERNET_AllocThreadError();
3582 SetLastError(dwError);
3584 lpwite->dwError = dwError;
3588 /***********************************************************************
3589 * INTERNET_GetLastError (internal)
3591 * Get last thread specific error
3596 DWORD INTERNET_GetLastError(void)
3598 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3599 if (!lpwite) return 0;
3600 /* TlsGetValue clears last error, so set it again here */
3601 SetLastError(lpwite->dwError);
3602 return lpwite->dwError;
3606 /***********************************************************************
3607 * INTERNET_WorkerThreadFunc (internal)
3609 * Worker thread execution function
3614 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3616 LPWORKREQUEST lpRequest = lpvParam;
3617 WORKREQUEST workRequest;
3621 workRequest = *lpRequest;
3622 heap_free(lpRequest);
3624 workRequest.asyncproc(&workRequest);
3625 WININET_Release( workRequest.hdr );
3627 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3629 heap_free(TlsGetValue(g_dwTlsErrIndex));
3630 TlsSetValue(g_dwTlsErrIndex, NULL);
3636 /***********************************************************************
3637 * INTERNET_AsyncCall (internal)
3639 * Retrieves work request from queue
3644 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3647 LPWORKREQUEST lpNewRequest;
3651 lpNewRequest = heap_alloc(sizeof(WORKREQUEST));
3653 return ERROR_OUTOFMEMORY;
3655 *lpNewRequest = *lpWorkRequest;
3657 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3660 heap_free(lpNewRequest);
3661 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3663 return ERROR_SUCCESS;
3667 /***********************************************************************
3668 * INTERNET_GetResponseBuffer (internal)
3673 LPSTR INTERNET_GetResponseBuffer(void)
3675 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3677 lpwite = INTERNET_AllocThreadError();
3679 return lpwite->response;
3682 /***********************************************************************
3683 * INTERNET_GetNextLine (internal)
3685 * Parse next line in directory string listing
3688 * Pointer to beginning of next line
3693 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3696 BOOL bSuccess = FALSE;
3698 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3703 pfd.events = POLLIN;
3705 while (nRecv < MAX_REPLY_LEN)
3707 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3709 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3711 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3715 if (lpszBuffer[nRecv] == '\n')
3720 if (lpszBuffer[nRecv] != '\r')
3725 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3733 lpszBuffer[nRecv] = '\0';
3735 TRACE(":%d %s\n", nRecv, lpszBuffer);
3744 /**********************************************************
3745 * InternetQueryDataAvailable (WININET.@)
3747 * Determines how much data is available to be read.
3750 * TRUE on success, FALSE if an error occurred. If
3751 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3752 * no data is presently available, FALSE is returned with
3753 * the last error ERROR_IO_PENDING; a callback with status
3754 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3755 * data is available.
3757 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3758 LPDWORD lpdwNumberOfBytesAvailble,
3759 DWORD dwFlags, DWORD_PTR dwContext)
3761 object_header_t *hdr;
3764 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3766 hdr = get_handle_object( hFile );
3768 SetLastError(ERROR_INVALID_HANDLE);
3772 if(hdr->vtbl->QueryDataAvailable) {
3773 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3775 WARN("wrong handle\n");
3776 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3779 WININET_Release(hdr);
3781 if(res != ERROR_SUCCESS)
3783 return res == ERROR_SUCCESS;
3787 /***********************************************************************
3788 * InternetLockRequestFile (WININET.@)
3790 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3797 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3804 /***********************************************************************
3805 * InternetAutodial (WININET.@)
3807 * On windows this function is supposed to dial the default internet
3808 * connection. We don't want to have Wine dial out to the internet so
3809 * we return TRUE by default. It might be nice to check if we are connected.
3816 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3820 /* Tell that we are connected to the internet. */
3824 /***********************************************************************
3825 * InternetAutodialHangup (WININET.@)
3827 * Hangs up a connection made with InternetAutodial
3836 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3840 /* we didn't dial, we don't disconnect */
3844 /***********************************************************************
3845 * InternetCombineUrlA (WININET.@)
3847 * Combine a base URL with a relative URL
3855 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3856 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3861 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3863 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3864 dwFlags ^= ICU_NO_ENCODE;
3865 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3870 /***********************************************************************
3871 * InternetCombineUrlW (WININET.@)
3873 * Combine a base URL with a relative URL
3881 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3882 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3887 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3889 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3890 dwFlags ^= ICU_NO_ENCODE;
3891 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3896 /* max port num is 65535 => 5 digits */
3897 #define MAX_WORD_DIGITS 5
3899 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3900 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3901 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3902 (url)->dw##component##Length : strlen((url)->lpsz##component))
3904 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3906 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3907 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3909 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3910 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3912 if ((nScheme == INTERNET_SCHEME_FTP) &&
3913 (nPort == INTERNET_DEFAULT_FTP_PORT))
3915 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3916 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3919 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3925 /* opaque urls do not fit into the standard url hierarchy and don't have
3926 * two following slashes */
3927 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3929 return (nScheme != INTERNET_SCHEME_FTP) &&
3930 (nScheme != INTERNET_SCHEME_GOPHER) &&
3931 (nScheme != INTERNET_SCHEME_HTTP) &&
3932 (nScheme != INTERNET_SCHEME_HTTPS) &&
3933 (nScheme != INTERNET_SCHEME_FILE);
3936 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3939 if (scheme < INTERNET_SCHEME_FIRST)
3941 index = scheme - INTERNET_SCHEME_FIRST;
3942 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3944 return (LPCWSTR)url_schemes[index];
3947 /* we can calculate using ansi strings because we're just
3948 * calculating string length, not size
3950 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3951 LPDWORD lpdwUrlLength)
3953 INTERNET_SCHEME nScheme;
3957 if (lpUrlComponents->lpszScheme)
3959 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3960 *lpdwUrlLength += dwLen;
3961 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3967 nScheme = lpUrlComponents->nScheme;
3969 if (nScheme == INTERNET_SCHEME_DEFAULT)
3970 nScheme = INTERNET_SCHEME_HTTP;
3971 scheme = INTERNET_GetSchemeString(nScheme);
3972 *lpdwUrlLength += strlenW(scheme);
3975 (*lpdwUrlLength)++; /* ':' */
3976 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3977 *lpdwUrlLength += strlen("//");
3979 if (lpUrlComponents->lpszUserName)
3981 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3982 *lpdwUrlLength += strlen("@");
3986 if (lpUrlComponents->lpszPassword)
3988 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3993 if (lpUrlComponents->lpszPassword)
3995 *lpdwUrlLength += strlen(":");
3996 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3999 if (lpUrlComponents->lpszHostName)
4001 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4003 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4005 char szPort[MAX_WORD_DIGITS+1];
4007 sprintf(szPort, "%d", lpUrlComponents->nPort);
4008 *lpdwUrlLength += strlen(szPort);
4009 *lpdwUrlLength += strlen(":");
4012 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4013 (*lpdwUrlLength)++; /* '/' */
4016 if (lpUrlComponents->lpszUrlPath)
4017 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4019 if (lpUrlComponents->lpszExtraInfo)
4020 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4025 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4029 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4031 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4032 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4033 urlCompW->nScheme = lpUrlComponents->nScheme;
4034 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4035 urlCompW->nPort = lpUrlComponents->nPort;
4036 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4037 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4038 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4039 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4041 if (lpUrlComponents->lpszScheme)
4043 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4044 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4045 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4046 -1, urlCompW->lpszScheme, len);
4049 if (lpUrlComponents->lpszHostName)
4051 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4052 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4053 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4054 -1, urlCompW->lpszHostName, len);
4057 if (lpUrlComponents->lpszUserName)
4059 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4060 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4061 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4062 -1, urlCompW->lpszUserName, len);
4065 if (lpUrlComponents->lpszPassword)
4067 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4068 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4069 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4070 -1, urlCompW->lpszPassword, len);
4073 if (lpUrlComponents->lpszUrlPath)
4075 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4076 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4077 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4078 -1, urlCompW->lpszUrlPath, len);
4081 if (lpUrlComponents->lpszExtraInfo)
4083 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4084 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4085 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4086 -1, urlCompW->lpszExtraInfo, len);
4090 /***********************************************************************
4091 * InternetCreateUrlA (WININET.@)
4093 * See InternetCreateUrlW.
4095 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4096 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4100 URL_COMPONENTSW urlCompW;
4102 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4104 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4106 SetLastError(ERROR_INVALID_PARAMETER);
4110 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4113 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4115 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4117 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4118 *lpdwUrlLength /= sizeof(WCHAR);
4120 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4121 * minus one, so add one to leave room for NULL terminator
4124 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4126 heap_free(urlCompW.lpszScheme);
4127 heap_free(urlCompW.lpszHostName);
4128 heap_free(urlCompW.lpszUserName);
4129 heap_free(urlCompW.lpszPassword);
4130 heap_free(urlCompW.lpszUrlPath);
4131 heap_free(urlCompW.lpszExtraInfo);
4136 /***********************************************************************
4137 * InternetCreateUrlW (WININET.@)
4139 * Creates a URL from its component parts.
4142 * lpUrlComponents [I] URL Components.
4143 * dwFlags [I] Flags. See notes.
4144 * lpszUrl [I] Buffer in which to store the created URL.
4145 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4146 * lpszUrl in characters. On output, the number of bytes
4147 * required to store the URL including terminator.
4151 * The dwFlags parameter can be zero or more of the following:
4152 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4159 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4160 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4163 INTERNET_SCHEME nScheme;
4165 static const WCHAR slashSlashW[] = {'/','/'};
4166 static const WCHAR fmtW[] = {'%','u',0};
4168 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4170 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4172 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4176 if (!calc_url_length(lpUrlComponents, &dwLen))
4179 if (!lpszUrl || *lpdwUrlLength < dwLen)
4181 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4182 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4186 *lpdwUrlLength = dwLen;
4191 if (lpUrlComponents->lpszScheme)
4193 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4194 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4197 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4202 nScheme = lpUrlComponents->nScheme;
4204 if (nScheme == INTERNET_SCHEME_DEFAULT)
4205 nScheme = INTERNET_SCHEME_HTTP;
4207 scheme = INTERNET_GetSchemeString(nScheme);
4208 dwLen = strlenW(scheme);
4209 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4213 /* all schemes are followed by at least a colon */
4217 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4219 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4220 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4223 if (lpUrlComponents->lpszUserName)
4225 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4226 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4229 if (lpUrlComponents->lpszPassword)
4234 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4235 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4243 if (lpUrlComponents->lpszHostName)
4245 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4246 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4249 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4251 WCHAR szPort[MAX_WORD_DIGITS+1];
4253 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4256 dwLen = strlenW(szPort);
4257 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4261 /* add slash between hostname and path if necessary */
4262 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4269 if (lpUrlComponents->lpszUrlPath)
4271 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4272 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4276 if (lpUrlComponents->lpszExtraInfo)
4278 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4279 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4288 /***********************************************************************
4289 * InternetConfirmZoneCrossingA (WININET.@)
4292 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4294 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4295 return ERROR_SUCCESS;
4298 /***********************************************************************
4299 * InternetConfirmZoneCrossingW (WININET.@)
4302 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4304 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4305 return ERROR_SUCCESS;
4308 static DWORD zone_preference = 3;
4310 /***********************************************************************
4311 * PrivacySetZonePreferenceW (WININET.@)
4313 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4315 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4317 zone_preference = template;
4321 /***********************************************************************
4322 * PrivacyGetZonePreferenceW (WININET.@)
4324 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4325 LPWSTR preference, LPDWORD length )
4327 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4329 if (template) *template = zone_preference;
4333 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4334 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4336 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4337 lpdwConnection, dwReserved);
4338 return ERROR_SUCCESS;
4341 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4342 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4344 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4345 lpdwConnection, dwReserved);
4346 return ERROR_SUCCESS;
4349 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4351 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4355 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4357 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4361 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4363 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4364 return ERROR_SUCCESS;
4367 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4370 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4371 debugstr_w(pwszTarget), pbHexHash);
4375 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4377 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4381 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4383 FIXME("(%p, %08lx) stub\n", a, b);