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;
298 case DLL_THREAD_ATTACH:
301 case DLL_THREAD_DETACH:
302 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
304 heap_free(TlsGetValue(g_dwTlsErrIndex));
308 case DLL_PROCESS_DETACH:
309 collect_connections(TRUE);
311 URLCacheContainers_DeleteAll();
313 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
315 heap_free(TlsGetValue(g_dwTlsErrIndex));
316 TlsFree(g_dwTlsErrIndex);
323 /***********************************************************************
324 * INTERNET_SaveProxySettings
326 * Stores the proxy settings given by lpwai into the registry
329 * ERROR_SUCCESS if no error, or error code on fail
331 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
336 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
339 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->proxyEnabled, sizeof(DWORD))))
347 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->proxy, sizeof(WCHAR) * (lstrlenW(lpwpi->proxy) + 1))))
355 if ((ret = RegDeleteValueW( key, szProxyServer )))
363 return ERROR_SUCCESS;
366 /***********************************************************************
367 * INTERNET_FindProxyForProtocol
369 * Searches the proxy string for a proxy of the given protocol.
370 * Returns the found proxy, or the default proxy if none of the given
374 * szProxy [In] proxy string to search
375 * proto [In] protocol to search for, e.g. "http"
376 * foundProxy [Out] found proxy
377 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
380 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
381 * *foundProxyLen is set to the required size in WCHARs, including the
382 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
384 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
389 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
391 /* First, look for the specified protocol (proto=scheme://host:port) */
392 for (ptr = szProxy; !ret && ptr && *ptr; )
396 if (!(end = strchrW(ptr, ' ')))
397 end = ptr + strlenW(ptr);
398 if ((equal = strchrW(ptr, '=')) && equal < end &&
399 equal - ptr == strlenW(proto) &&
400 !strncmpiW(proto, ptr, strlenW(proto)))
402 if (end - equal > *foundProxyLen)
404 WARN("buffer too short for %s\n",
405 debugstr_wn(equal + 1, end - equal - 1));
406 *foundProxyLen = end - equal;
407 SetLastError(ERROR_INSUFFICIENT_BUFFER);
411 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
412 foundProxy[end - equal] = 0;
423 /* It wasn't found: look for no protocol */
424 for (ptr = szProxy; !ret && ptr && *ptr; )
428 if (!(end = strchrW(ptr, ' ')))
429 end = ptr + strlenW(ptr);
430 if (!(equal = strchrW(ptr, '=')))
432 if (end - ptr + 1 > *foundProxyLen)
434 WARN("buffer too short for %s\n",
435 debugstr_wn(ptr, end - ptr));
436 *foundProxyLen = end - ptr + 1;
437 SetLastError(ERROR_INSUFFICIENT_BUFFER);
441 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
442 foundProxy[end - ptr] = 0;
453 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
454 debugstr_w(foundProxy));
458 /***********************************************************************
459 * InternetInitializeAutoProxyDll (WININET.@)
461 * Setup the internal proxy
470 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
473 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
477 /***********************************************************************
478 * DetectAutoProxyUrl (WININET.@)
480 * Auto detect the proxy url
486 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
487 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
490 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
494 static void FreeProxyInfo( proxyinfo_t *lpwpi )
496 heap_free(lpwpi->proxy);
497 heap_free(lpwpi->proxyBypass);
500 static proxyinfo_t *global_proxy;
502 static void free_global_proxy( void )
504 EnterCriticalSection( &WININET_cs );
507 FreeProxyInfo( global_proxy );
508 heap_free( global_proxy );
510 LeaveCriticalSection( &WININET_cs );
513 /***********************************************************************
514 * INTERNET_LoadProxySettings
516 * Loads proxy information from process-wide global settings, the registry,
517 * or the environment into lpwpi.
519 * The caller should call FreeProxyInfo when done with lpwpi.
522 * The proxy may be specified in the form 'http=proxy.my.org'
523 * Presumably that means there can be ftp=ftpproxy.my.org too.
525 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
532 EnterCriticalSection( &WININET_cs );
535 lpwpi->proxyEnabled = global_proxy->proxyEnabled;
536 lpwpi->proxy = heap_strdupW( global_proxy->proxy );
537 lpwpi->proxyBypass = heap_strdupW( global_proxy->proxyBypass );
539 LeaveCriticalSection( &WININET_cs );
541 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
545 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->proxyEnabled, &len ) || type != REG_DWORD)
547 lpwpi->proxyEnabled = 0;
548 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->proxyEnabled, sizeof(DWORD) )))
555 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->proxyEnabled)
557 TRACE("Proxy is enabled.\n");
559 /* figure out how much memory the proxy setting takes */
560 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
563 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
565 if (!(szProxy = heap_alloc(len)))
568 return ERROR_OUTOFMEMORY;
570 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
572 /* find the http proxy, and strip away everything else */
573 p = strstrW( szProxy, szHttp );
576 p += lstrlenW( szHttp );
577 lstrcpyW( szProxy, p );
579 p = strchrW( szProxy, ' ' );
582 lpwpi->proxy = szProxy;
584 TRACE("http proxy = %s\n", debugstr_w(lpwpi->proxy));
588 TRACE("No proxy server settings in registry.\n");
596 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
597 if (!(envproxyW = heap_alloc(len * sizeof(WCHAR))))
598 return ERROR_OUTOFMEMORY;
599 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
601 lpwpi->proxyEnabled = 1;
602 lpwpi->proxy = envproxyW;
604 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->proxy));
608 lpwpi->proxyBypass = NULL;
610 return ERROR_SUCCESS;
613 /***********************************************************************
614 * INTERNET_ConfigureProxy
616 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
620 if (INTERNET_LoadProxySettings( &wpi ))
623 if (wpi.proxyEnabled)
625 WCHAR proxyurl[INTERNET_MAX_URL_LENGTH];
626 WCHAR username[INTERNET_MAX_USER_NAME_LENGTH];
627 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
628 WCHAR hostname[INTERNET_MAX_HOST_NAME_LENGTH];
629 URL_COMPONENTSW UrlComponents;
631 UrlComponents.dwStructSize = sizeof UrlComponents;
632 UrlComponents.dwSchemeLength = 0;
633 UrlComponents.lpszHostName = hostname;
634 UrlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
635 UrlComponents.lpszUserName = username;
636 UrlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
637 UrlComponents.lpszPassword = password;
638 UrlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
639 UrlComponents.dwUrlPathLength = 0;
640 UrlComponents.dwExtraInfoLength = 0;
642 if(InternetCrackUrlW(wpi.proxy, 0, 0, &UrlComponents))
644 static const WCHAR szFormat[] = { 'h','t','t','p',':','/','/','%','s',':','%','u',0 };
646 if(UrlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
647 UrlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
648 sprintfW(proxyurl, szFormat, hostname, UrlComponents.nPort);
650 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
651 lpwai->proxy = heap_strdupW(proxyurl);
652 if (UrlComponents.dwUserNameLength)
654 lpwai->proxyUsername = heap_strdupW(UrlComponents.lpszUserName);
655 lpwai->proxyPassword = heap_strdupW(UrlComponents.lpszPassword);
658 TRACE("http proxy = %s\n", debugstr_w(lpwai->proxy));
663 TRACE("Failed to parse proxy: %s\n", debugstr_w(wpi.proxy));
668 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
672 /***********************************************************************
673 * dump_INTERNET_FLAGS
675 * Helper function to TRACE the internet flags.
681 static void dump_INTERNET_FLAGS(DWORD dwFlags)
683 #define FE(x) { x, #x }
684 static const wininet_flag_info flag[] = {
685 FE(INTERNET_FLAG_RELOAD),
686 FE(INTERNET_FLAG_RAW_DATA),
687 FE(INTERNET_FLAG_EXISTING_CONNECT),
688 FE(INTERNET_FLAG_ASYNC),
689 FE(INTERNET_FLAG_PASSIVE),
690 FE(INTERNET_FLAG_NO_CACHE_WRITE),
691 FE(INTERNET_FLAG_MAKE_PERSISTENT),
692 FE(INTERNET_FLAG_FROM_CACHE),
693 FE(INTERNET_FLAG_SECURE),
694 FE(INTERNET_FLAG_KEEP_CONNECTION),
695 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
696 FE(INTERNET_FLAG_READ_PREFETCH),
697 FE(INTERNET_FLAG_NO_COOKIES),
698 FE(INTERNET_FLAG_NO_AUTH),
699 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
700 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
701 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
702 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
703 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
704 FE(INTERNET_FLAG_RESYNCHRONIZE),
705 FE(INTERNET_FLAG_HYPERLINK),
706 FE(INTERNET_FLAG_NO_UI),
707 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
708 FE(INTERNET_FLAG_CACHE_ASYNC),
709 FE(INTERNET_FLAG_FORMS_SUBMIT),
710 FE(INTERNET_FLAG_NEED_FILE),
711 FE(INTERNET_FLAG_TRANSFER_ASCII),
712 FE(INTERNET_FLAG_TRANSFER_BINARY)
717 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
718 if (flag[i].val & dwFlags) {
719 TRACE(" %s", flag[i].name);
720 dwFlags &= ~flag[i].val;
724 TRACE(" Unknown flags (%08x)\n", dwFlags);
729 /***********************************************************************
730 * INTERNET_CloseHandle (internal)
732 * Close internet handle
735 static VOID APPINFO_Destroy(object_header_t *hdr)
737 appinfo_t *lpwai = (appinfo_t*)hdr;
741 heap_free(lpwai->agent);
742 heap_free(lpwai->proxy);
743 heap_free(lpwai->proxyBypass);
744 heap_free(lpwai->proxyUsername);
745 heap_free(lpwai->proxyPassword);
748 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
750 appinfo_t *ai = (appinfo_t*)hdr;
753 case INTERNET_OPTION_HANDLE_TYPE:
754 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
756 if (*size < sizeof(ULONG))
757 return ERROR_INSUFFICIENT_BUFFER;
759 *size = sizeof(DWORD);
760 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
761 return ERROR_SUCCESS;
763 case INTERNET_OPTION_USER_AGENT: {
766 TRACE("INTERNET_OPTION_USER_AGENT\n");
771 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
773 *size = (len + 1) * sizeof(WCHAR);
774 if(!buffer || bufsize < *size)
775 return ERROR_INSUFFICIENT_BUFFER;
778 strcpyW(buffer, ai->agent);
780 *(WCHAR *)buffer = 0;
781 /* If the buffer is copied, the returned length doesn't include
782 * the NULL terminator.
784 *size = len * sizeof(WCHAR);
787 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
790 if(!buffer || bufsize < *size)
791 return ERROR_INSUFFICIENT_BUFFER;
794 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
797 /* If the buffer is copied, the returned length doesn't include
798 * the NULL terminator.
803 return ERROR_SUCCESS;
806 case INTERNET_OPTION_PROXY:
807 if(!size) return ERROR_INVALID_PARAMETER;
809 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
810 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
811 LPWSTR proxy, proxy_bypass;
814 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
816 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
817 if (*size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
819 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
820 return ERROR_INSUFFICIENT_BUFFER;
822 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
823 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
825 pi->dwAccessType = ai->accessType;
826 pi->lpszProxy = NULL;
827 pi->lpszProxyBypass = NULL;
829 lstrcpyW(proxy, ai->proxy);
830 pi->lpszProxy = proxy;
833 if (ai->proxyBypass) {
834 lstrcpyW(proxy_bypass, ai->proxyBypass);
835 pi->lpszProxyBypass = proxy_bypass;
838 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
839 return ERROR_SUCCESS;
841 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
842 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
843 LPSTR proxy, proxy_bypass;
846 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
848 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
849 NULL, 0, NULL, NULL);
850 if (*size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
852 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
853 return ERROR_INSUFFICIENT_BUFFER;
855 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
856 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
858 pi->dwAccessType = ai->accessType;
859 pi->lpszProxy = NULL;
860 pi->lpszProxyBypass = NULL;
862 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
863 pi->lpszProxy = proxy;
866 if (ai->proxyBypass) {
867 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
868 proxyBypassBytesRequired, NULL, NULL);
869 pi->lpszProxyBypass = proxy_bypass;
872 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
873 return ERROR_SUCCESS;
877 return INET_QueryOption(hdr, option, buffer, size, unicode);
880 static const object_vtbl_t APPINFOVtbl = {
893 /***********************************************************************
894 * InternetOpenW (WININET.@)
896 * Per-application initialization of wininet
899 * HINTERNET on success
903 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
904 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
906 appinfo_t *lpwai = NULL;
908 if (TRACE_ON(wininet)) {
909 #define FE(x) { x, #x }
910 static const wininet_flag_info access_type[] = {
911 FE(INTERNET_OPEN_TYPE_PRECONFIG),
912 FE(INTERNET_OPEN_TYPE_DIRECT),
913 FE(INTERNET_OPEN_TYPE_PROXY),
914 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
918 const char *access_type_str = "Unknown";
920 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
921 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
922 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
923 if (access_type[i].val == dwAccessType) {
924 access_type_str = access_type[i].name;
928 TRACE(" access type : %s\n", access_type_str);
930 dump_INTERNET_FLAGS(dwFlags);
933 /* Clear any error information */
934 INTERNET_SetLastError(0);
936 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
938 SetLastError(ERROR_OUTOFMEMORY);
942 lpwai->hdr.htype = WH_HINIT;
943 lpwai->hdr.dwFlags = dwFlags;
944 lpwai->accessType = dwAccessType;
945 lpwai->proxyUsername = NULL;
946 lpwai->proxyPassword = NULL;
948 lpwai->agent = heap_strdupW(lpszAgent);
949 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
950 INTERNET_ConfigureProxy( lpwai );
952 lpwai->proxy = heap_strdupW(lpszProxy);
953 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
955 TRACE("returning %p\n", lpwai);
957 return lpwai->hdr.hInternet;
961 /***********************************************************************
962 * InternetOpenA (WININET.@)
964 * Per-application initialization of wininet
967 * HINTERNET on success
971 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
972 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
974 WCHAR *szAgent, *szProxy, *szBypass;
977 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
978 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
980 szAgent = heap_strdupAtoW(lpszAgent);
981 szProxy = heap_strdupAtoW(lpszProxy);
982 szBypass = heap_strdupAtoW(lpszProxyBypass);
984 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
992 /***********************************************************************
993 * InternetGetLastResponseInfoA (WININET.@)
995 * Return last wininet error description on the calling thread
998 * TRUE on success of writing to buffer
1002 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
1003 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
1005 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1011 *lpdwError = lpwite->dwError;
1012 if (lpwite->dwError)
1014 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1015 *lpdwBufferLength = strlen(lpszBuffer);
1018 *lpdwBufferLength = 0;
1023 *lpdwBufferLength = 0;
1029 /***********************************************************************
1030 * InternetGetLastResponseInfoW (WININET.@)
1032 * Return last wininet error description on the calling thread
1035 * TRUE on success of writing to buffer
1039 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
1040 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
1042 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1048 *lpdwError = lpwite->dwError;
1049 if (lpwite->dwError)
1051 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1052 *lpdwBufferLength = lstrlenW(lpszBuffer);
1055 *lpdwBufferLength = 0;
1060 *lpdwBufferLength = 0;
1066 /***********************************************************************
1067 * InternetGetConnectedState (WININET.@)
1069 * Return connected state
1073 * if lpdwStatus is not null, return the status (off line,
1074 * modem, lan...) in it.
1075 * FALSE if not connected
1077 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1079 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1082 WARN("always returning LAN connection.\n");
1083 *lpdwStatus = INTERNET_CONNECTION_LAN;
1089 /***********************************************************************
1090 * InternetGetConnectedStateExW (WININET.@)
1092 * Return connected state
1096 * lpdwStatus [O] Flags specifying the status of the internet connection.
1097 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1098 * dwNameLen [I] Size of the buffer, in characters.
1099 * dwReserved [I] Reserved. Must be set to 0.
1103 * if lpdwStatus is not null, return the status (off line,
1104 * modem, lan...) in it.
1105 * FALSE if not connected
1108 * If the system has no available network connections, an empty string is
1109 * stored in lpszConnectionName. If there is a LAN connection, a localized
1110 * "LAN Connection" string is stored. Presumably, if only a dial-up
1111 * connection is available then the name of the dial-up connection is
1112 * returned. Why any application, other than the "Internet Settings" CPL,
1113 * would want to use this function instead of the simpler InternetGetConnectedStateW
1114 * function is beyond me.
1116 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1117 DWORD dwNameLen, DWORD dwReserved)
1119 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1126 WARN("always returning LAN connection.\n");
1127 *lpdwStatus = INTERNET_CONNECTION_LAN;
1129 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1133 /***********************************************************************
1134 * InternetGetConnectedStateExA (WININET.@)
1136 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1137 DWORD dwNameLen, DWORD dwReserved)
1139 LPWSTR lpwszConnectionName = NULL;
1142 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1144 if (lpszConnectionName && dwNameLen > 0)
1145 lpwszConnectionName = heap_alloc(dwNameLen * sizeof(WCHAR));
1147 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1149 if (rc && lpwszConnectionName)
1151 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1152 dwNameLen, NULL, NULL);
1153 heap_free(lpwszConnectionName);
1159 /***********************************************************************
1160 * InternetConnectW (WININET.@)
1162 * Open a ftp, gopher or http session
1165 * HINTERNET a session handle on success
1169 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1170 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1171 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1172 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1175 HINTERNET rc = NULL;
1176 DWORD res = ERROR_SUCCESS;
1178 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
1179 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1180 dwService, dwFlags, dwContext);
1182 if (!lpszServerName)
1184 SetLastError(ERROR_INVALID_PARAMETER);
1188 hIC = (appinfo_t*)get_handle_object( hInternet );
1189 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1191 res = ERROR_INVALID_HANDLE;
1197 case INTERNET_SERVICE_FTP:
1198 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1199 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1201 res = INTERNET_GetLastError();
1204 case INTERNET_SERVICE_HTTP:
1205 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1206 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1209 case INTERNET_SERVICE_GOPHER:
1215 WININET_Release( &hIC->hdr );
1217 TRACE("returning %p\n", rc);
1223 /***********************************************************************
1224 * InternetConnectA (WININET.@)
1226 * Open a ftp, gopher or http session
1229 * HINTERNET a session handle on success
1233 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1234 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1235 LPCSTR lpszUserName, LPCSTR lpszPassword,
1236 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1238 HINTERNET rc = NULL;
1239 LPWSTR szServerName;
1243 szServerName = heap_strdupAtoW(lpszServerName);
1244 szUserName = heap_strdupAtoW(lpszUserName);
1245 szPassword = heap_strdupAtoW(lpszPassword);
1247 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1248 szUserName, szPassword, dwService, dwFlags, dwContext);
1250 heap_free(szServerName);
1251 heap_free(szUserName);
1252 heap_free(szPassword);
1257 /***********************************************************************
1258 * InternetFindNextFileA (WININET.@)
1260 * Continues a file search from a previous call to FindFirstFile
1267 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1270 WIN32_FIND_DATAW fd;
1272 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1274 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1278 /***********************************************************************
1279 * InternetFindNextFileW (WININET.@)
1281 * Continues a file search from a previous call to FindFirstFile
1288 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1290 object_header_t *hdr;
1295 hdr = get_handle_object(hFind);
1297 WARN("Invalid handle\n");
1298 SetLastError(ERROR_INVALID_HANDLE);
1302 if(hdr->vtbl->FindNextFileW) {
1303 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1305 WARN("Handle doesn't support NextFile\n");
1306 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1309 WININET_Release(hdr);
1311 if(res != ERROR_SUCCESS)
1313 return res == ERROR_SUCCESS;
1316 /***********************************************************************
1317 * InternetCloseHandle (WININET.@)
1319 * Generic close handle function
1326 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1328 object_header_t *obj;
1330 TRACE("%p\n", hInternet);
1332 obj = get_handle_object( hInternet );
1334 SetLastError(ERROR_INVALID_HANDLE);
1338 invalidate_handle(obj);
1339 WININET_Release(obj);
1345 /***********************************************************************
1346 * ConvertUrlComponentValue (Internal)
1348 * Helper function for InternetCrackUrlA
1351 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1352 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1353 LPCSTR lpszStart, LPCWSTR lpwszStart)
1355 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1356 if (*dwComponentLen != 0)
1358 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1359 if (*lppszComponent == NULL)
1363 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1364 *lppszComponent = (LPSTR)lpszStart + offset;
1367 *lppszComponent = NULL;
1369 *dwComponentLen = nASCIILength;
1373 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1374 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1375 (*lppszComponent)[ncpylen]=0;
1376 *dwComponentLen = ncpylen;
1382 /***********************************************************************
1383 * InternetCrackUrlA (WININET.@)
1385 * See InternetCrackUrlW.
1387 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1388 LPURL_COMPONENTSA lpUrlComponents)
1391 URL_COMPONENTSW UCW;
1393 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1394 *scheme = NULL, *extra = NULL;
1396 TRACE("(%s %u %x %p)\n",
1397 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1398 dwUrlLength, dwFlags, lpUrlComponents);
1400 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1401 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1403 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1409 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1411 /* if dwUrlLength=-1 then nLength includes null but length to
1412 InternetCrackUrlW should not include it */
1413 if (dwUrlLength == -1) nLength--;
1415 lpwszUrl = heap_alloc((nLength + 1) * sizeof(WCHAR));
1416 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1417 lpwszUrl[nLength] = '\0';
1419 memset(&UCW,0,sizeof(UCW));
1420 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1421 if (lpUrlComponents->dwHostNameLength)
1423 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1424 if (lpUrlComponents->lpszHostName)
1426 hostname = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1427 UCW.lpszHostName = hostname;
1430 if (lpUrlComponents->dwUserNameLength)
1432 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1433 if (lpUrlComponents->lpszUserName)
1435 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1436 UCW.lpszUserName = username;
1439 if (lpUrlComponents->dwPasswordLength)
1441 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1442 if (lpUrlComponents->lpszPassword)
1444 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1445 UCW.lpszPassword = password;
1448 if (lpUrlComponents->dwUrlPathLength)
1450 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1451 if (lpUrlComponents->lpszUrlPath)
1453 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1454 UCW.lpszUrlPath = path;
1457 if (lpUrlComponents->dwSchemeLength)
1459 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1460 if (lpUrlComponents->lpszScheme)
1462 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1463 UCW.lpszScheme = scheme;
1466 if (lpUrlComponents->dwExtraInfoLength)
1468 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1469 if (lpUrlComponents->lpszExtraInfo)
1471 extra = heap_alloc(UCW.dwExtraInfoLength * sizeof(WCHAR));
1472 UCW.lpszExtraInfo = extra;
1475 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1477 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1478 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1479 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1480 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1481 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1482 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1483 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1484 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1485 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1486 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1487 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1488 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1490 lpUrlComponents->nScheme = UCW.nScheme;
1491 lpUrlComponents->nPort = UCW.nPort;
1493 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1494 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1495 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1496 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1497 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1499 heap_free(lpwszUrl);
1500 heap_free(hostname);
1501 heap_free(username);
1502 heap_free(password);
1509 static const WCHAR url_schemes[][7] =
1512 {'g','o','p','h','e','r',0},
1513 {'h','t','t','p',0},
1514 {'h','t','t','p','s',0},
1515 {'f','i','l','e',0},
1516 {'n','e','w','s',0},
1517 {'m','a','i','l','t','o',0},
1521 /***********************************************************************
1522 * GetInternetSchemeW (internal)
1528 * INTERNET_SCHEME_UNKNOWN on failure
1531 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1535 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1537 if(lpszScheme==NULL)
1538 return INTERNET_SCHEME_UNKNOWN;
1540 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1541 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1542 return INTERNET_SCHEME_FIRST + i;
1544 return INTERNET_SCHEME_UNKNOWN;
1547 /***********************************************************************
1548 * SetUrlComponentValueW (Internal)
1550 * Helper function for InternetCrackUrlW
1553 * lppszComponent [O] Holds the returned string
1554 * dwComponentLen [I] Holds the size of lppszComponent
1555 * [O] Holds the length of the string in lppszComponent without '\0'
1556 * lpszStart [I] Holds the string to copy from
1557 * len [I] Holds the length of lpszStart without '\0'
1564 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1566 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1568 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1571 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1573 if (*lppszComponent == NULL)
1575 *lppszComponent = (LPWSTR)lpszStart;
1576 *dwComponentLen = len;
1580 DWORD ncpylen = min((*dwComponentLen)-1, len);
1581 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1582 (*lppszComponent)[ncpylen] = '\0';
1583 *dwComponentLen = ncpylen;
1590 /***********************************************************************
1591 * InternetCrackUrlW (WININET.@)
1593 * Break up URL into its components
1599 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1600 LPURL_COMPONENTSW lpUC)
1604 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1607 LPCWSTR lpszParam = NULL;
1608 BOOL bIsAbsolute = FALSE;
1609 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1610 LPCWSTR lpszcp = NULL;
1611 LPWSTR lpszUrl_decode = NULL;
1612 DWORD dwUrlLength = dwUrlLength_orig;
1614 TRACE("(%s %u %x %p)\n",
1615 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1616 dwUrlLength, dwFlags, lpUC);
1618 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1620 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1623 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1625 if (dwFlags & ICU_DECODE)
1628 DWORD len = dwUrlLength + 1;
1630 if (!(url_tmp = heap_alloc(len * sizeof(WCHAR))))
1632 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1635 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1636 url_tmp[dwUrlLength] = 0;
1637 if (!(lpszUrl_decode = heap_alloc(len * sizeof(WCHAR))))
1640 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1643 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1646 lpszUrl = lpszUrl_decode;
1652 /* Determine if the URI is absolute. */
1653 while (lpszap - lpszUrl < dwUrlLength)
1655 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1660 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1667 lpszcp = lpszUrl; /* Relative url */
1673 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1674 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1676 /* Parse <params> */
1677 lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl));
1679 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1681 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1683 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1684 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1686 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1690 /* Get scheme first. */
1691 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1692 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1693 lpszUrl, lpszcp - lpszUrl);
1695 /* Eat ':' in protocol. */
1698 /* double slash indicates the net_loc portion is present */
1699 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1703 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1707 lpszNetLoc = min(lpszNetLoc, lpszParam);
1709 lpszNetLoc = lpszParam;
1711 else if (!lpszNetLoc)
1712 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1720 /* [<user>[<:password>]@]<host>[:<port>] */
1721 /* First find the user and password if they exist */
1723 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1724 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1726 /* username and password not specified. */
1727 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1728 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1730 else /* Parse out username and password */
1732 LPCWSTR lpszUser = lpszcp;
1733 LPCWSTR lpszPasswd = lpszHost;
1735 while (lpszcp < lpszHost)
1738 lpszPasswd = lpszcp;
1743 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1744 lpszUser, lpszPasswd - lpszUser);
1746 if (lpszPasswd != lpszHost)
1748 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1749 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1750 lpszHost - lpszPasswd);
1752 lpszcp++; /* Advance to beginning of host */
1755 /* Parse <host><:port> */
1758 lpszPort = lpszNetLoc;
1760 /* special case for res:// URLs: there is no port here, so the host is the
1761 entire string up to the first '/' */
1762 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1764 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1765 lpszHost, lpszPort - lpszHost);
1770 while (lpszcp < lpszNetLoc)
1778 /* If the scheme is "file" and the host is just one letter, it's not a host */
1779 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1782 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1787 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1788 lpszHost, lpszPort - lpszHost);
1789 if (lpszPort != lpszNetLoc)
1790 lpUC->nPort = atoiW(++lpszPort);
1791 else switch (lpUC->nScheme)
1793 case INTERNET_SCHEME_HTTP:
1794 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1796 case INTERNET_SCHEME_HTTPS:
1797 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1799 case INTERNET_SCHEME_FTP:
1800 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1802 case INTERNET_SCHEME_GOPHER:
1803 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1814 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1815 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1816 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1821 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1822 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1823 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1824 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1827 /* Here lpszcp points to:
1829 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1830 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1832 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1836 /* Only truncate the parameter list if it's already been saved
1837 * in lpUC->lpszExtraInfo.
1839 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1840 len = lpszParam - lpszcp;
1843 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1844 * newlines if necessary.
1846 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1847 if (lpsznewline != NULL)
1848 len = lpsznewline - lpszcp;
1850 len = dwUrlLength-(lpszcp-lpszUrl);
1852 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1853 lpUC->nScheme == INTERNET_SCHEME_FILE)
1855 WCHAR tmppath[MAX_PATH];
1859 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
1864 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1865 tmppath[len] = '\0';
1874 /* if ends in \. or \.. append a backslash */
1875 if (tmppath[len - 1] == '.' &&
1876 (tmppath[len - 2] == '\\' ||
1877 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1879 if (len < MAX_PATH - 1)
1881 tmppath[len] = '\\';
1882 tmppath[len+1] = '\0';
1886 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1890 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1895 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1896 lpUC->lpszUrlPath[0] = 0;
1897 lpUC->dwUrlPathLength = 0;
1900 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1901 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1902 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1903 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1904 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1906 heap_free( lpszUrl_decode );
1910 /***********************************************************************
1911 * InternetAttemptConnect (WININET.@)
1913 * Attempt to make a connection to the internet
1916 * ERROR_SUCCESS on success
1917 * Error value on failure
1920 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1923 return ERROR_SUCCESS;
1927 /***********************************************************************
1928 * InternetCanonicalizeUrlA (WININET.@)
1930 * Escape unsafe characters and spaces
1937 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1938 LPDWORD lpdwBufferLength, DWORD dwFlags)
1941 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1943 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1944 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1946 if(dwFlags & ICU_DECODE)
1948 dwURLFlags |= URL_UNESCAPE;
1949 dwFlags &= ~ICU_DECODE;
1952 if(dwFlags & ICU_ESCAPE)
1954 dwURLFlags |= URL_UNESCAPE;
1955 dwFlags &= ~ICU_ESCAPE;
1958 if(dwFlags & ICU_BROWSER_MODE)
1960 dwURLFlags |= URL_BROWSER_MODE;
1961 dwFlags &= ~ICU_BROWSER_MODE;
1964 if(dwFlags & ICU_NO_ENCODE)
1966 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1967 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1968 dwFlags &= ~ICU_NO_ENCODE;
1971 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1973 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1974 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1975 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1977 return (hr == S_OK) ? TRUE : FALSE;
1980 /***********************************************************************
1981 * InternetCanonicalizeUrlW (WININET.@)
1983 * Escape unsafe characters and spaces
1990 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1991 LPDWORD lpdwBufferLength, DWORD dwFlags)
1994 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1996 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1997 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1999 if(dwFlags & ICU_DECODE)
2001 dwURLFlags |= URL_UNESCAPE;
2002 dwFlags &= ~ICU_DECODE;
2005 if(dwFlags & ICU_ESCAPE)
2007 dwURLFlags |= URL_UNESCAPE;
2008 dwFlags &= ~ICU_ESCAPE;
2011 if(dwFlags & ICU_BROWSER_MODE)
2013 dwURLFlags |= URL_BROWSER_MODE;
2014 dwFlags &= ~ICU_BROWSER_MODE;
2017 if(dwFlags & ICU_NO_ENCODE)
2019 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
2020 dwURLFlags ^= URL_ESCAPE_UNSAFE;
2021 dwFlags &= ~ICU_NO_ENCODE;
2024 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
2026 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
2027 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
2028 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
2030 return (hr == S_OK) ? TRUE : FALSE;
2033 /* #################################################### */
2035 static INTERNET_STATUS_CALLBACK set_status_callback(
2036 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
2038 INTERNET_STATUS_CALLBACK ret;
2040 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
2041 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
2043 ret = lpwh->lpfnStatusCB;
2044 lpwh->lpfnStatusCB = callback;
2049 /***********************************************************************
2050 * InternetSetStatusCallbackA (WININET.@)
2052 * Sets up a callback function which is called as progress is made
2053 * during an operation.
2056 * Previous callback or NULL on success
2057 * INTERNET_INVALID_STATUS_CALLBACK on failure
2060 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2061 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2063 INTERNET_STATUS_CALLBACK retVal;
2064 object_header_t *lpwh;
2066 TRACE("%p\n", hInternet);
2068 if (!(lpwh = get_handle_object(hInternet)))
2069 return INTERNET_INVALID_STATUS_CALLBACK;
2071 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2073 WININET_Release( lpwh );
2077 /***********************************************************************
2078 * InternetSetStatusCallbackW (WININET.@)
2080 * Sets up a callback function which is called as progress is made
2081 * during an operation.
2084 * Previous callback or NULL on success
2085 * INTERNET_INVALID_STATUS_CALLBACK on failure
2088 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2089 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2091 INTERNET_STATUS_CALLBACK retVal;
2092 object_header_t *lpwh;
2094 TRACE("%p\n", hInternet);
2096 if (!(lpwh = get_handle_object(hInternet)))
2097 return INTERNET_INVALID_STATUS_CALLBACK;
2099 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2101 WININET_Release( lpwh );
2105 /***********************************************************************
2106 * InternetSetFilePointer (WININET.@)
2108 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2109 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2115 /***********************************************************************
2116 * InternetWriteFile (WININET.@)
2118 * Write data to an open internet file
2125 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2126 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2128 object_header_t *lpwh;
2131 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2133 lpwh = get_handle_object( hFile );
2135 WARN("Invalid handle\n");
2136 SetLastError(ERROR_INVALID_HANDLE);
2140 if(lpwh->vtbl->WriteFile) {
2141 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2143 WARN("No Writefile method.\n");
2144 res = ERROR_INVALID_HANDLE;
2147 WININET_Release( lpwh );
2149 if(res != ERROR_SUCCESS)
2151 return res == ERROR_SUCCESS;
2155 /***********************************************************************
2156 * InternetReadFile (WININET.@)
2158 * Read data from an open internet file
2165 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2166 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2168 object_header_t *hdr;
2169 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2171 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2173 hdr = get_handle_object(hFile);
2175 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2179 if(hdr->vtbl->ReadFile)
2180 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2182 WININET_Release(hdr);
2184 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2185 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2187 if(res != ERROR_SUCCESS)
2189 return res == ERROR_SUCCESS;
2192 /***********************************************************************
2193 * InternetReadFileExA (WININET.@)
2195 * Read data from an open internet file
2198 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2199 * lpBuffersOut [I/O] Buffer.
2200 * dwFlags [I] Flags. See notes.
2201 * dwContext [I] Context for callbacks.
2208 * The parameter dwFlags include zero or more of the following flags:
2209 *|IRF_ASYNC - Makes the call asynchronous.
2210 *|IRF_SYNC - Makes the call synchronous.
2211 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2212 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2214 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2217 * InternetOpenUrlA(), HttpOpenRequestA()
2219 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2220 DWORD dwFlags, DWORD_PTR dwContext)
2222 object_header_t *hdr;
2223 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2225 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2227 hdr = get_handle_object(hFile);
2229 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2233 if(hdr->vtbl->ReadFileExA)
2234 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
2236 WININET_Release(hdr);
2238 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2239 res, lpBuffersOut->dwBufferLength);
2241 if(res != ERROR_SUCCESS)
2243 return res == ERROR_SUCCESS;
2246 /***********************************************************************
2247 * InternetReadFileExW (WININET.@)
2249 * InternetReadFileExA()
2251 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2252 DWORD dwFlags, DWORD_PTR dwContext)
2254 object_header_t *hdr;
2255 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2257 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2259 hdr = get_handle_object(hFile);
2261 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2265 if(hdr->vtbl->ReadFileExW)
2266 res = hdr->vtbl->ReadFileExW(hdr, lpBuffer, dwFlags, dwContext);
2268 WININET_Release(hdr);
2270 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2271 res, lpBuffer->dwBufferLength);
2273 if(res != ERROR_SUCCESS)
2275 return res == ERROR_SUCCESS;
2278 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2280 static BOOL warn = TRUE;
2283 case INTERNET_OPTION_REQUEST_FLAGS:
2284 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2286 if (*size < sizeof(ULONG))
2287 return ERROR_INSUFFICIENT_BUFFER;
2289 *(ULONG*)buffer = 4;
2290 *size = sizeof(ULONG);
2292 return ERROR_SUCCESS;
2294 case INTERNET_OPTION_HTTP_VERSION:
2295 if (*size < sizeof(HTTP_VERSION_INFO))
2296 return ERROR_INSUFFICIENT_BUFFER;
2299 * Presently hardcoded to 1.1
2301 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2302 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2303 *size = sizeof(HTTP_VERSION_INFO);
2305 return ERROR_SUCCESS;
2307 case INTERNET_OPTION_CONNECTED_STATE:
2309 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2312 if (*size < sizeof(ULONG))
2313 return ERROR_INSUFFICIENT_BUFFER;
2315 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2316 *size = sizeof(ULONG);
2318 return ERROR_SUCCESS;
2320 case INTERNET_OPTION_PROXY: {
2324 TRACE("Getting global proxy info\n");
2325 memset(&ai, 0, sizeof(appinfo_t));
2326 INTERNET_ConfigureProxy(&ai);
2328 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2329 APPINFO_Destroy(&ai.hdr);
2333 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2334 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2336 if (*size < sizeof(ULONG))
2337 return ERROR_INSUFFICIENT_BUFFER;
2339 *(ULONG*)buffer = 2;
2340 *size = sizeof(ULONG);
2342 return ERROR_SUCCESS;
2344 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2345 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2347 if (*size < sizeof(ULONG))
2348 return ERROR_INSUFFICIENT_BUFFER;
2350 *(ULONG*)buffer = 4;
2351 *size = sizeof(ULONG);
2353 return ERROR_SUCCESS;
2355 case INTERNET_OPTION_SECURITY_FLAGS:
2356 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2357 return ERROR_SUCCESS;
2359 case INTERNET_OPTION_VERSION: {
2360 static const INTERNET_VERSION_INFO info = { 1, 2 };
2362 TRACE("INTERNET_OPTION_VERSION\n");
2364 if (*size < sizeof(INTERNET_VERSION_INFO))
2365 return ERROR_INSUFFICIENT_BUFFER;
2367 memcpy(buffer, &info, sizeof(info));
2368 *size = sizeof(info);
2370 return ERROR_SUCCESS;
2373 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2374 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2375 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2376 DWORD res = ERROR_SUCCESS, i;
2380 TRACE("Getting global proxy info\n");
2381 if((ret = INTERNET_LoadProxySettings(&pi)))
2384 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2386 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2388 return ERROR_INSUFFICIENT_BUFFER;
2391 for (i = 0; i < con->dwOptionCount; i++) {
2392 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2393 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2395 switch (optionW->dwOption) {
2396 case INTERNET_PER_CONN_FLAGS:
2398 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2400 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2403 case INTERNET_PER_CONN_PROXY_SERVER:
2405 optionW->Value.pszValue = heap_strdupW(pi.proxy);
2407 optionA->Value.pszValue = heap_strdupWtoA(pi.proxy);
2410 case INTERNET_PER_CONN_PROXY_BYPASS:
2412 optionW->Value.pszValue = heap_strdupW(pi.proxyBypass);
2414 optionA->Value.pszValue = heap_strdupWtoA(pi.proxyBypass);
2417 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2418 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2419 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2420 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2421 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2422 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2423 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2424 memset(&optionW->Value, 0, sizeof(optionW->Value));
2428 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2429 res = ERROR_INVALID_PARAMETER;
2437 case INTERNET_OPTION_USER_AGENT:
2438 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2439 case INTERNET_OPTION_POLICY:
2440 return ERROR_INVALID_PARAMETER;
2441 case INTERNET_OPTION_CONTEXT_VALUE:
2444 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2446 return ERROR_INVALID_PARAMETER;
2448 if (*size < sizeof(DWORD_PTR))
2450 *size = sizeof(DWORD_PTR);
2451 return ERROR_INSUFFICIENT_BUFFER;
2454 return ERROR_INVALID_PARAMETER;
2456 *(DWORD_PTR *)buffer = hdr->dwContext;
2457 *size = sizeof(DWORD_PTR);
2458 return ERROR_SUCCESS;
2462 FIXME("Stub for %d\n", option);
2463 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2466 /***********************************************************************
2467 * InternetQueryOptionW (WININET.@)
2469 * Queries an options on the specified handle
2476 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2477 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2479 object_header_t *hdr;
2480 DWORD res = ERROR_INVALID_HANDLE;
2482 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2485 hdr = get_handle_object(hInternet);
2487 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2488 WININET_Release(hdr);
2491 res = INET_QueryOption(NULL, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2494 if(res != ERROR_SUCCESS)
2496 return res == ERROR_SUCCESS;
2499 /***********************************************************************
2500 * InternetQueryOptionA (WININET.@)
2502 * Queries an options on the specified handle
2509 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2510 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2512 object_header_t *hdr;
2513 DWORD res = ERROR_INVALID_HANDLE;
2515 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2518 hdr = get_handle_object(hInternet);
2520 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2521 WININET_Release(hdr);
2524 res = INET_QueryOption(NULL, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2527 if(res != ERROR_SUCCESS)
2529 return res == ERROR_SUCCESS;
2533 /***********************************************************************
2534 * InternetSetOptionW (WININET.@)
2536 * Sets an options on the specified handle
2543 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2544 LPVOID lpBuffer, DWORD dwBufferLength)
2546 object_header_t *lpwhh;
2549 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2551 lpwhh = (object_header_t*) get_handle_object( hInternet );
2552 if(lpwhh && lpwhh->vtbl->SetOption) {
2555 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2556 if(res != ERROR_INTERNET_INVALID_OPTION) {
2557 WININET_Release( lpwhh );
2559 if(res != ERROR_SUCCESS)
2562 return res == ERROR_SUCCESS;
2568 case INTERNET_OPTION_CALLBACK:
2572 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2575 WININET_Release(lpwhh);
2576 SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2579 case INTERNET_OPTION_HTTP_VERSION:
2581 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2582 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2585 case INTERNET_OPTION_ERROR_MASK:
2588 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2590 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2591 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2592 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2593 SetLastError(ERROR_INVALID_PARAMETER);
2595 } else if(dwBufferLength != sizeof(ULONG)) {
2596 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2599 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2602 case INTERNET_OPTION_PROXY:
2604 INTERNET_PROXY_INFOW *info = lpBuffer;
2606 if (!lpBuffer || dwBufferLength < sizeof(INTERNET_PROXY_INFOW))
2608 SetLastError(ERROR_INVALID_PARAMETER);
2613 EnterCriticalSection( &WININET_cs );
2614 free_global_proxy();
2615 global_proxy = heap_alloc( sizeof(proxyinfo_t) );
2618 if (info->dwAccessType == INTERNET_OPEN_TYPE_PROXY)
2620 global_proxy->proxyEnabled = 1;
2621 global_proxy->proxy = heap_strdupW( info->lpszProxy );
2622 global_proxy->proxyBypass = heap_strdupW( info->lpszProxyBypass );
2626 global_proxy->proxyEnabled = 0;
2627 global_proxy->proxy = global_proxy->proxyBypass = NULL;
2630 LeaveCriticalSection( &WININET_cs );
2634 /* In general, each type of object should handle
2635 * INTERNET_OPTION_PROXY directly. This FIXME ensures it doesn't
2636 * get silently dropped.
2638 FIXME("INTERNET_OPTION_PROXY unimplemented\n");
2639 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2644 case INTERNET_OPTION_CODEPAGE:
2646 ULONG codepage = *(ULONG *)lpBuffer;
2647 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2650 case INTERNET_OPTION_REQUEST_PRIORITY:
2652 ULONG priority = *(ULONG *)lpBuffer;
2653 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2656 case INTERNET_OPTION_CONNECT_TIMEOUT:
2658 ULONG connecttimeout = *(ULONG *)lpBuffer;
2659 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2662 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2664 ULONG receivetimeout = *(ULONG *)lpBuffer;
2665 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2668 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2670 ULONG conns = *(ULONG *)lpBuffer;
2671 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2674 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2676 ULONG conns = *(ULONG *)lpBuffer;
2677 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2680 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2681 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2683 case INTERNET_OPTION_END_BROWSER_SESSION:
2684 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2686 case INTERNET_OPTION_CONNECTED_STATE:
2687 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2689 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2690 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2692 case INTERNET_OPTION_SEND_TIMEOUT:
2693 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2694 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2696 ULONG timeout = *(ULONG *)lpBuffer;
2697 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2700 case INTERNET_OPTION_CONNECT_RETRIES:
2702 ULONG retries = *(ULONG *)lpBuffer;
2703 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2706 case INTERNET_OPTION_CONTEXT_VALUE:
2710 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2713 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2715 SetLastError(ERROR_INVALID_PARAMETER);
2719 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2722 case INTERNET_OPTION_SECURITY_FLAGS:
2723 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2725 case INTERNET_OPTION_DISABLE_AUTODIAL:
2726 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2728 case INTERNET_OPTION_HTTP_DECODING:
2729 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2730 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2733 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2734 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2735 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2738 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2739 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2740 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2743 case INTERNET_OPTION_CODEPAGE_PATH:
2744 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2745 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2748 case INTERNET_OPTION_CODEPAGE_EXTRA:
2749 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2750 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2753 case INTERNET_OPTION_IDN:
2754 FIXME("INTERNET_OPTION_IDN; STUB\n");
2755 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2758 case INTERNET_OPTION_POLICY:
2759 SetLastError(ERROR_INVALID_PARAMETER);
2762 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2763 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2768 INTERNET_LoadProxySettings(&pi);
2770 for (i = 0; i < con->dwOptionCount; i++) {
2771 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2773 switch (option->dwOption) {
2774 case INTERNET_PER_CONN_PROXY_SERVER:
2775 heap_free(pi.proxy);
2776 pi.proxy = heap_strdupW(option->Value.pszValue);
2779 case INTERNET_PER_CONN_FLAGS:
2780 if(option->Value.dwValue & PROXY_TYPE_PROXY)
2781 pi.proxyEnabled = 1;
2784 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
2785 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
2786 pi.proxyEnabled = 0;
2790 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2791 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2792 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2793 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2794 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2795 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2796 case INTERNET_PER_CONN_PROXY_BYPASS:
2797 FIXME("Unhandled dwOption %d\n", option->dwOption);
2801 FIXME("Unknown dwOption %d\n", option->dwOption);
2802 SetLastError(ERROR_INVALID_PARAMETER);
2807 if ((res = INTERNET_SaveProxySettings(&pi)))
2812 ret = (res == ERROR_SUCCESS);
2816 FIXME("Option %d STUB\n",dwOption);
2817 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2823 WININET_Release( lpwhh );
2829 /***********************************************************************
2830 * InternetSetOptionA (WININET.@)
2832 * Sets an options on the specified handle.
2839 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2840 LPVOID lpBuffer, DWORD dwBufferLength)
2848 case INTERNET_OPTION_CALLBACK:
2850 object_header_t *lpwh;
2852 if (!(lpwh = get_handle_object(hInternet)))
2854 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2857 WININET_Release(lpwh);
2858 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2861 case INTERNET_OPTION_PROXY:
2863 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2864 LPINTERNET_PROXY_INFOW piw;
2865 DWORD proxlen, prbylen;
2868 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2869 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2870 wlen = sizeof(*piw) + proxlen + prbylen;
2871 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2872 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2873 piw->dwAccessType = pi->dwAccessType;
2874 prox = (LPWSTR) &piw[1];
2875 prby = &prox[proxlen+1];
2876 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2877 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2878 piw->lpszProxy = prox;
2879 piw->lpszProxyBypass = prby;
2882 case INTERNET_OPTION_USER_AGENT:
2883 case INTERNET_OPTION_USERNAME:
2884 case INTERNET_OPTION_PASSWORD:
2885 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2887 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2888 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2891 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2893 INTERNET_PER_CONN_OPTION_LISTW *listW;
2894 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
2895 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2896 wbuffer = heap_alloc(wlen);
2899 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2900 if (listA->pszConnection)
2902 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
2903 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
2904 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
2907 listW->pszConnection = NULL;
2908 listW->dwOptionCount = listA->dwOptionCount;
2909 listW->dwOptionError = listA->dwOptionError;
2910 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
2912 for (i = 0; i < listA->dwOptionCount; ++i) {
2913 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
2914 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
2916 optW->dwOption = optA->dwOption;
2918 switch (optA->dwOption) {
2919 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2920 case INTERNET_PER_CONN_PROXY_BYPASS:
2921 case INTERNET_PER_CONN_PROXY_SERVER:
2922 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2923 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2924 if (optA->Value.pszValue)
2926 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
2927 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
2928 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
2931 optW->Value.pszValue = NULL;
2933 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2934 case INTERNET_PER_CONN_FLAGS:
2935 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2936 optW->Value.dwValue = optA->Value.dwValue;
2938 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2939 optW->Value.ftValue = optA->Value.ftValue;
2942 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
2943 optW->Value.dwValue = optA->Value.dwValue;
2951 wlen = dwBufferLength;
2954 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2956 if( lpBuffer != wbuffer )
2958 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
2960 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
2962 for (i = 0; i < list->dwOptionCount; ++i) {
2963 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
2964 switch (opt->dwOption) {
2965 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2966 case INTERNET_PER_CONN_PROXY_BYPASS:
2967 case INTERNET_PER_CONN_PROXY_SERVER:
2968 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2969 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2970 heap_free( opt->Value.pszValue );
2976 heap_free( list->pOptions );
2978 heap_free( wbuffer );
2985 /***********************************************************************
2986 * InternetSetOptionExA (WININET.@)
2988 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2989 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2991 FIXME("Flags %08x ignored\n", dwFlags);
2992 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2995 /***********************************************************************
2996 * InternetSetOptionExW (WININET.@)
2998 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2999 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
3001 FIXME("Flags %08x ignored\n", dwFlags);
3002 if( dwFlags & ~ISO_VALID_FLAGS )
3004 SetLastError( ERROR_INVALID_PARAMETER );
3007 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
3010 static const WCHAR WININET_wkday[7][4] =
3011 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
3012 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
3013 static const WCHAR WININET_month[12][4] =
3014 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
3015 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
3016 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
3018 /***********************************************************************
3019 * InternetTimeFromSystemTimeA (WININET.@)
3021 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
3024 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
3026 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3028 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3030 SetLastError(ERROR_INVALID_PARAMETER);
3034 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3036 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3040 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
3041 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
3046 /***********************************************************************
3047 * InternetTimeFromSystemTimeW (WININET.@)
3049 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
3051 static const WCHAR date[] =
3052 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
3053 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
3055 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
3057 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
3059 SetLastError(ERROR_INVALID_PARAMETER);
3063 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
3065 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3069 sprintfW( string, date,
3070 WININET_wkday[time->wDayOfWeek],
3072 WININET_month[time->wMonth - 1],
3081 /***********************************************************************
3082 * InternetTimeToSystemTimeA (WININET.@)
3084 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
3089 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
3091 stringW = heap_strdupAtoW(string);
3094 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
3095 heap_free( stringW );
3100 /***********************************************************************
3101 * InternetTimeToSystemTimeW (WININET.@)
3103 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3106 const WCHAR *s = string;
3109 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3111 if (!string || !time) return FALSE;
3113 /* Windows does this too */
3114 GetSystemTime( time );
3116 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3117 * a SYSTEMTIME structure.
3120 while (*s && !isalphaW( *s )) s++;
3121 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3122 time->wDayOfWeek = 7;
3124 for (i = 0; i < 7; i++)
3126 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3127 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3128 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3130 time->wDayOfWeek = i;
3135 if (time->wDayOfWeek > 6) return TRUE;
3136 while (*s && !isdigitW( *s )) s++;
3137 time->wDay = strtolW( s, &end, 10 );
3140 while (*s && !isalphaW( *s )) s++;
3141 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3144 for (i = 0; i < 12; i++)
3146 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3147 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3148 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3150 time->wMonth = i + 1;
3154 if (time->wMonth == 0) return TRUE;
3156 while (*s && !isdigitW( *s )) s++;
3157 if (*s == '\0') return TRUE;
3158 time->wYear = strtolW( s, &end, 10 );
3161 while (*s && !isdigitW( *s )) s++;
3162 if (*s == '\0') return TRUE;
3163 time->wHour = strtolW( s, &end, 10 );
3166 while (*s && !isdigitW( *s )) s++;
3167 if (*s == '\0') return TRUE;
3168 time->wMinute = strtolW( s, &end, 10 );
3171 while (*s && !isdigitW( *s )) s++;
3172 if (*s == '\0') return TRUE;
3173 time->wSecond = strtolW( s, &end, 10 );
3176 time->wMilliseconds = 0;
3180 /***********************************************************************
3181 * InternetCheckConnectionW (WININET.@)
3183 * Pings a requested host to check internet connection
3186 * TRUE on success and FALSE on failure. If a failure then
3187 * ERROR_NOT_CONNECTED is placed into GetLastError
3190 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3193 * this is a kludge which runs the resident ping program and reads the output.
3195 * Anyone have a better idea?
3199 static const CHAR ping[] = "ping -c 1 ";
3200 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3201 CHAR *command = NULL;
3202 WCHAR hostW[INTERNET_MAX_HOST_NAME_LENGTH];
3210 * Crack or set the Address
3212 if (lpszUrl == NULL)
3215 * According to the doc we are supposed to use the ip for the next
3216 * server in the WnInet internal server database. I have
3217 * no idea what that is or how to get it.
3219 * So someone needs to implement this.
3221 FIXME("Unimplemented with URL of NULL\n");
3226 URL_COMPONENTSW components;
3228 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3229 components.lpszHostName = (LPWSTR)hostW;
3230 components.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3232 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3235 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3236 port = components.nPort;
3237 TRACE("port: %d\n", port);
3240 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3242 struct sockaddr_storage saddr;
3243 socklen_t sa_len = sizeof(saddr);
3246 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3248 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3251 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3259 * Build our ping command
3261 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3262 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3263 strcpy(command,ping);
3264 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3265 strcat(command,redirect);
3267 TRACE("Ping command is : %s\n",command);
3269 status = system(command);
3271 TRACE("Ping returned a code of %i\n",status);
3273 /* Ping return code of 0 indicates success */
3279 heap_free( command );
3281 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3287 /***********************************************************************
3288 * InternetCheckConnectionA (WININET.@)
3290 * Pings a requested host to check internet connection
3293 * TRUE on success and FALSE on failure. If a failure then
3294 * ERROR_NOT_CONNECTED is placed into GetLastError
3297 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3303 url = heap_strdupAtoW(lpszUrl);
3308 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3315 /**********************************************************
3316 * INTERNET_InternetOpenUrlW (internal)
3321 * handle of connection or NULL on failure
3323 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3324 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3326 URL_COMPONENTSW urlComponents;
3327 WCHAR protocol[INTERNET_MAX_SCHEME_LENGTH];
3328 WCHAR hostName[INTERNET_MAX_HOST_NAME_LENGTH];
3329 WCHAR userName[INTERNET_MAX_USER_NAME_LENGTH];
3330 WCHAR password[INTERNET_MAX_PASSWORD_LENGTH];
3331 WCHAR path[INTERNET_MAX_PATH_LENGTH];
3333 HINTERNET client = NULL, client1 = NULL;
3336 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3337 dwHeadersLength, dwFlags, dwContext);
3339 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3340 urlComponents.lpszScheme = protocol;
3341 urlComponents.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH;
3342 urlComponents.lpszHostName = hostName;
3343 urlComponents.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH;
3344 urlComponents.lpszUserName = userName;
3345 urlComponents.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH;
3346 urlComponents.lpszPassword = password;
3347 urlComponents.dwPasswordLength = INTERNET_MAX_PASSWORD_LENGTH;
3348 urlComponents.lpszUrlPath = path;
3349 urlComponents.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH;
3350 urlComponents.lpszExtraInfo = extra;
3351 urlComponents.dwExtraInfoLength = 1024;
3352 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3354 switch(urlComponents.nScheme) {
3355 case INTERNET_SCHEME_FTP:
3356 if(urlComponents.nPort == 0)
3357 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3358 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3359 userName, password, dwFlags, dwContext, INET_OPENURL);
3362 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3363 if(client1 == NULL) {
3364 InternetCloseHandle(client);
3369 case INTERNET_SCHEME_HTTP:
3370 case INTERNET_SCHEME_HTTPS: {
3371 static const WCHAR szStars[] = { '*','/','*', 0 };
3372 LPCWSTR accept[2] = { szStars, NULL };
3373 if(urlComponents.nPort == 0) {
3374 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3375 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3377 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3379 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3381 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3382 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3383 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3384 if(res != ERROR_SUCCESS) {
3385 INTERNET_SetLastError(res);
3389 if (urlComponents.dwExtraInfoLength) {
3391 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3393 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3395 InternetCloseHandle(client);
3398 strcpyW(path_extra, urlComponents.lpszUrlPath);
3399 strcatW(path_extra, urlComponents.lpszExtraInfo);
3400 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3401 heap_free(path_extra);
3404 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3406 if(client1 == NULL) {
3407 InternetCloseHandle(client);
3410 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3411 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3412 GetLastError() != ERROR_IO_PENDING) {
3413 InternetCloseHandle(client1);
3418 case INTERNET_SCHEME_GOPHER:
3419 /* gopher doesn't seem to be implemented in wine, but it's supposed
3420 * to be supported by InternetOpenUrlA. */
3422 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3426 TRACE(" %p <--\n", client1);
3431 /**********************************************************
3432 * InternetOpenUrlW (WININET.@)
3437 * handle of connection or NULL on failure
3439 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3441 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3442 appinfo_t *hIC = (appinfo_t*) workRequest->hdr;
3446 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3447 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3448 heap_free(req->lpszUrl);
3449 heap_free(req->lpszHeaders);
3452 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3453 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3455 HINTERNET ret = NULL;
3456 appinfo_t *hIC = NULL;
3458 if (TRACE_ON(wininet)) {
3459 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3460 dwHeadersLength, dwFlags, dwContext);
3462 dump_INTERNET_FLAGS(dwFlags);
3467 SetLastError(ERROR_INVALID_PARAMETER);
3471 hIC = (appinfo_t*)get_handle_object( hInternet );
3472 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3473 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3477 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3478 WORKREQUEST workRequest;
3479 struct WORKREQ_INTERNETOPENURLW *req;
3481 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3482 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3483 req = &workRequest.u.InternetOpenUrlW;
3484 req->lpszUrl = heap_strdupW(lpszUrl);
3485 req->lpszHeaders = heap_strdupW(lpszHeaders);
3486 req->dwHeadersLength = dwHeadersLength;
3487 req->dwFlags = dwFlags;
3488 req->dwContext = dwContext;
3490 INTERNET_AsyncCall(&workRequest);
3492 * This is from windows.
3494 SetLastError(ERROR_IO_PENDING);
3496 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3501 WININET_Release( &hIC->hdr );
3502 TRACE(" %p <--\n", ret);
3507 /**********************************************************
3508 * InternetOpenUrlA (WININET.@)
3513 * handle of connection or NULL on failure
3515 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3516 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3518 HINTERNET rc = NULL;
3519 DWORD lenHeaders = 0;
3520 LPWSTR szUrl = NULL;
3521 LPWSTR szHeaders = NULL;
3526 szUrl = heap_strdupAtoW(lpszUrl);
3532 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3533 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3538 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3541 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3542 lenHeaders, dwFlags, dwContext);
3545 heap_free(szHeaders);
3550 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3552 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3556 lpwite->dwError = 0;
3557 lpwite->response[0] = '\0';
3560 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3569 /***********************************************************************
3570 * INTERNET_SetLastError (internal)
3572 * Set last thread specific error
3577 void INTERNET_SetLastError(DWORD dwError)
3579 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3582 lpwite = INTERNET_AllocThreadError();
3584 SetLastError(dwError);
3586 lpwite->dwError = dwError;
3590 /***********************************************************************
3591 * INTERNET_GetLastError (internal)
3593 * Get last thread specific error
3598 DWORD INTERNET_GetLastError(void)
3600 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3601 if (!lpwite) return 0;
3602 /* TlsGetValue clears last error, so set it again here */
3603 SetLastError(lpwite->dwError);
3604 return lpwite->dwError;
3608 /***********************************************************************
3609 * INTERNET_WorkerThreadFunc (internal)
3611 * Worker thread execution function
3616 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3618 LPWORKREQUEST lpRequest = lpvParam;
3619 WORKREQUEST workRequest;
3623 workRequest = *lpRequest;
3624 heap_free(lpRequest);
3626 workRequest.asyncproc(&workRequest);
3627 WININET_Release( workRequest.hdr );
3629 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3631 heap_free(TlsGetValue(g_dwTlsErrIndex));
3632 TlsSetValue(g_dwTlsErrIndex, NULL);
3638 /***********************************************************************
3639 * INTERNET_AsyncCall (internal)
3641 * Retrieves work request from queue
3646 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3649 LPWORKREQUEST lpNewRequest;
3653 lpNewRequest = heap_alloc(sizeof(WORKREQUEST));
3655 return ERROR_OUTOFMEMORY;
3657 *lpNewRequest = *lpWorkRequest;
3659 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3662 heap_free(lpNewRequest);
3663 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3665 return ERROR_SUCCESS;
3669 /***********************************************************************
3670 * INTERNET_GetResponseBuffer (internal)
3675 LPSTR INTERNET_GetResponseBuffer(void)
3677 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3679 lpwite = INTERNET_AllocThreadError();
3681 return lpwite->response;
3684 /***********************************************************************
3685 * INTERNET_GetNextLine (internal)
3687 * Parse next line in directory string listing
3690 * Pointer to beginning of next line
3695 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3698 BOOL bSuccess = FALSE;
3700 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3705 pfd.events = POLLIN;
3707 while (nRecv < MAX_REPLY_LEN)
3709 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3711 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3713 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3717 if (lpszBuffer[nRecv] == '\n')
3722 if (lpszBuffer[nRecv] != '\r')
3727 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3735 lpszBuffer[nRecv] = '\0';
3737 TRACE(":%d %s\n", nRecv, lpszBuffer);
3746 /**********************************************************
3747 * InternetQueryDataAvailable (WININET.@)
3749 * Determines how much data is available to be read.
3752 * TRUE on success, FALSE if an error occurred. If
3753 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3754 * no data is presently available, FALSE is returned with
3755 * the last error ERROR_IO_PENDING; a callback with status
3756 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3757 * data is available.
3759 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3760 LPDWORD lpdwNumberOfBytesAvailble,
3761 DWORD dwFlags, DWORD_PTR dwContext)
3763 object_header_t *hdr;
3766 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3768 hdr = get_handle_object( hFile );
3770 SetLastError(ERROR_INVALID_HANDLE);
3774 if(hdr->vtbl->QueryDataAvailable) {
3775 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3777 WARN("wrong handle\n");
3778 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3781 WININET_Release(hdr);
3783 if(res != ERROR_SUCCESS)
3785 return res == ERROR_SUCCESS;
3789 /***********************************************************************
3790 * InternetLockRequestFile (WININET.@)
3792 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3799 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3806 /***********************************************************************
3807 * InternetAutodial (WININET.@)
3809 * On windows this function is supposed to dial the default internet
3810 * connection. We don't want to have Wine dial out to the internet so
3811 * we return TRUE by default. It might be nice to check if we are connected.
3818 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3822 /* Tell that we are connected to the internet. */
3826 /***********************************************************************
3827 * InternetAutodialHangup (WININET.@)
3829 * Hangs up a connection made with InternetAutodial
3838 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3842 /* we didn't dial, we don't disconnect */
3846 /***********************************************************************
3847 * InternetCombineUrlA (WININET.@)
3849 * Combine a base URL with a relative URL
3857 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3858 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3863 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3865 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3866 dwFlags ^= ICU_NO_ENCODE;
3867 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3872 /***********************************************************************
3873 * InternetCombineUrlW (WININET.@)
3875 * Combine a base URL with a relative URL
3883 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3884 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3889 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3891 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3892 dwFlags ^= ICU_NO_ENCODE;
3893 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3898 /* max port num is 65535 => 5 digits */
3899 #define MAX_WORD_DIGITS 5
3901 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3902 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3903 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3904 (url)->dw##component##Length : strlen((url)->lpsz##component))
3906 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3908 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3909 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3911 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3912 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3914 if ((nScheme == INTERNET_SCHEME_FTP) &&
3915 (nPort == INTERNET_DEFAULT_FTP_PORT))
3917 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3918 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3921 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3927 /* opaque urls do not fit into the standard url hierarchy and don't have
3928 * two following slashes */
3929 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3931 return (nScheme != INTERNET_SCHEME_FTP) &&
3932 (nScheme != INTERNET_SCHEME_GOPHER) &&
3933 (nScheme != INTERNET_SCHEME_HTTP) &&
3934 (nScheme != INTERNET_SCHEME_HTTPS) &&
3935 (nScheme != INTERNET_SCHEME_FILE);
3938 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3941 if (scheme < INTERNET_SCHEME_FIRST)
3943 index = scheme - INTERNET_SCHEME_FIRST;
3944 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3946 return (LPCWSTR)url_schemes[index];
3949 /* we can calculate using ansi strings because we're just
3950 * calculating string length, not size
3952 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3953 LPDWORD lpdwUrlLength)
3955 INTERNET_SCHEME nScheme;
3959 if (lpUrlComponents->lpszScheme)
3961 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3962 *lpdwUrlLength += dwLen;
3963 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3969 nScheme = lpUrlComponents->nScheme;
3971 if (nScheme == INTERNET_SCHEME_DEFAULT)
3972 nScheme = INTERNET_SCHEME_HTTP;
3973 scheme = INTERNET_GetSchemeString(nScheme);
3974 *lpdwUrlLength += strlenW(scheme);
3977 (*lpdwUrlLength)++; /* ':' */
3978 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3979 *lpdwUrlLength += strlen("//");
3981 if (lpUrlComponents->lpszUserName)
3983 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3984 *lpdwUrlLength += strlen("@");
3988 if (lpUrlComponents->lpszPassword)
3990 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3995 if (lpUrlComponents->lpszPassword)
3997 *lpdwUrlLength += strlen(":");
3998 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4001 if (lpUrlComponents->lpszHostName)
4003 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4005 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4007 char szPort[MAX_WORD_DIGITS+1];
4009 sprintf(szPort, "%d", lpUrlComponents->nPort);
4010 *lpdwUrlLength += strlen(szPort);
4011 *lpdwUrlLength += strlen(":");
4014 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4015 (*lpdwUrlLength)++; /* '/' */
4018 if (lpUrlComponents->lpszUrlPath)
4019 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4021 if (lpUrlComponents->lpszExtraInfo)
4022 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4027 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
4031 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
4033 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
4034 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
4035 urlCompW->nScheme = lpUrlComponents->nScheme;
4036 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
4037 urlCompW->nPort = lpUrlComponents->nPort;
4038 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
4039 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
4040 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
4041 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
4043 if (lpUrlComponents->lpszScheme)
4045 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
4046 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
4047 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
4048 -1, urlCompW->lpszScheme, len);
4051 if (lpUrlComponents->lpszHostName)
4053 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
4054 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
4055 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
4056 -1, urlCompW->lpszHostName, len);
4059 if (lpUrlComponents->lpszUserName)
4061 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
4062 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
4063 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
4064 -1, urlCompW->lpszUserName, len);
4067 if (lpUrlComponents->lpszPassword)
4069 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
4070 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
4071 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
4072 -1, urlCompW->lpszPassword, len);
4075 if (lpUrlComponents->lpszUrlPath)
4077 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
4078 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
4079 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
4080 -1, urlCompW->lpszUrlPath, len);
4083 if (lpUrlComponents->lpszExtraInfo)
4085 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
4086 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
4087 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
4088 -1, urlCompW->lpszExtraInfo, len);
4092 /***********************************************************************
4093 * InternetCreateUrlA (WININET.@)
4095 * See InternetCreateUrlW.
4097 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4098 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4102 URL_COMPONENTSW urlCompW;
4104 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4106 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4108 SetLastError(ERROR_INVALID_PARAMETER);
4112 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4115 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4117 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4119 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4120 *lpdwUrlLength /= sizeof(WCHAR);
4122 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4123 * minus one, so add one to leave room for NULL terminator
4126 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4128 heap_free(urlCompW.lpszScheme);
4129 heap_free(urlCompW.lpszHostName);
4130 heap_free(urlCompW.lpszUserName);
4131 heap_free(urlCompW.lpszPassword);
4132 heap_free(urlCompW.lpszUrlPath);
4133 heap_free(urlCompW.lpszExtraInfo);
4138 /***********************************************************************
4139 * InternetCreateUrlW (WININET.@)
4141 * Creates a URL from its component parts.
4144 * lpUrlComponents [I] URL Components.
4145 * dwFlags [I] Flags. See notes.
4146 * lpszUrl [I] Buffer in which to store the created URL.
4147 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4148 * lpszUrl in characters. On output, the number of bytes
4149 * required to store the URL including terminator.
4153 * The dwFlags parameter can be zero or more of the following:
4154 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4161 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4162 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4165 INTERNET_SCHEME nScheme;
4167 static const WCHAR slashSlashW[] = {'/','/'};
4168 static const WCHAR fmtW[] = {'%','u',0};
4170 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4172 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4174 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4178 if (!calc_url_length(lpUrlComponents, &dwLen))
4181 if (!lpszUrl || *lpdwUrlLength < dwLen)
4183 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4184 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4188 *lpdwUrlLength = dwLen;
4193 if (lpUrlComponents->lpszScheme)
4195 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4196 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4199 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4204 nScheme = lpUrlComponents->nScheme;
4206 if (nScheme == INTERNET_SCHEME_DEFAULT)
4207 nScheme = INTERNET_SCHEME_HTTP;
4209 scheme = INTERNET_GetSchemeString(nScheme);
4210 dwLen = strlenW(scheme);
4211 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4215 /* all schemes are followed by at least a colon */
4219 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4221 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4222 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4225 if (lpUrlComponents->lpszUserName)
4227 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4228 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4231 if (lpUrlComponents->lpszPassword)
4236 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4237 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4245 if (lpUrlComponents->lpszHostName)
4247 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4248 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4251 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4253 WCHAR szPort[MAX_WORD_DIGITS+1];
4255 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4258 dwLen = strlenW(szPort);
4259 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4263 /* add slash between hostname and path if necessary */
4264 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4271 if (lpUrlComponents->lpszUrlPath)
4273 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4274 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4278 if (lpUrlComponents->lpszExtraInfo)
4280 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4281 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4290 /***********************************************************************
4291 * InternetConfirmZoneCrossingA (WININET.@)
4294 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4296 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4297 return ERROR_SUCCESS;
4300 /***********************************************************************
4301 * InternetConfirmZoneCrossingW (WININET.@)
4304 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4306 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4307 return ERROR_SUCCESS;
4310 static DWORD zone_preference = 3;
4312 /***********************************************************************
4313 * PrivacySetZonePreferenceW (WININET.@)
4315 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4317 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4319 zone_preference = template;
4323 /***********************************************************************
4324 * PrivacyGetZonePreferenceW (WININET.@)
4326 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4327 LPWSTR preference, LPDWORD length )
4329 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4331 if (template) *template = zone_preference;
4335 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4336 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4338 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4339 lpdwConnection, dwReserved);
4340 return ERROR_SUCCESS;
4343 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4344 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4346 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4347 lpdwConnection, dwReserved);
4348 return ERROR_SUCCESS;
4351 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4353 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4357 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4359 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4363 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4365 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4366 return ERROR_SUCCESS;
4369 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4372 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4373 debugstr_w(pwszTarget), pbHexHash);
4377 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4379 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4383 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4385 FIXME("(%p, %08lx) stub\n", a, b);