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 #define MAXHOSTNAME 100 /* from http.c */
34 #if defined(__MINGW32__) || defined (_MSC_VER)
41 #include <sys/types.h>
42 #ifdef HAVE_SYS_SOCKET_H
43 # include <sys/socket.h>
48 #ifdef HAVE_SYS_POLL_H
49 # include <sys/poll.h>
51 #ifdef HAVE_SYS_TIME_H
52 # include <sys/time.h>
68 #include "wine/debug.h"
70 #define NO_SHLWAPI_STREAM
73 #include "wine/exception.h"
78 #include "wine/unicode.h"
80 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
82 #define RESPONSE_TIMEOUT 30
87 CHAR response[MAX_REPLY_LEN];
88 } WITHREADERROR, *LPWITHREADERROR;
90 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
91 static HMODULE WININET_hModule;
93 #define HANDLE_CHUNK_SIZE 0x10
95 static CRITICAL_SECTION WININET_cs;
96 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
99 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
100 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
102 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
104 static object_header_t **WININET_Handles;
105 static UINT_PTR WININET_dwNextHandle;
106 static UINT_PTR WININET_dwMaxHandles;
110 DWORD dwProxyEnabled;
111 LPWSTR lpszProxyServer;
112 LPWSTR lpszProxyBypass;
115 static const WCHAR szInternetSettings[] =
116 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
117 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
118 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
119 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
120 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
122 HINTERNET WININET_AllocHandle( object_header_t *info )
125 UINT_PTR handle = 0, num;
127 list_init( &info->children );
129 EnterCriticalSection( &WININET_cs );
130 if( !WININET_dwMaxHandles )
132 num = HANDLE_CHUNK_SIZE;
133 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
134 sizeof (*WININET_Handles)* num);
138 WININET_dwMaxHandles = num;
140 if( WININET_dwMaxHandles == WININET_dwNextHandle )
142 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
143 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
144 WININET_Handles, sizeof (*WININET_Handles)* num);
148 WININET_dwMaxHandles = num;
151 handle = WININET_dwNextHandle;
152 if( WININET_Handles[handle] )
153 ERR("handle isn't free but should be\n");
154 WININET_Handles[handle] = WININET_AddRef( info );
156 while( WININET_Handles[WININET_dwNextHandle] &&
157 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
158 WININET_dwNextHandle++;
161 LeaveCriticalSection( &WININET_cs );
163 return info->hInternet = (HINTERNET) (handle+1);
166 object_header_t *WININET_AddRef( object_header_t *info )
168 ULONG refs = InterlockedIncrement(&info->refs);
169 TRACE("%p -> refcount = %d\n", info, refs );
173 object_header_t *WININET_GetObject( HINTERNET hinternet )
175 object_header_t *info = NULL;
176 UINT_PTR handle = (UINT_PTR) hinternet;
178 EnterCriticalSection( &WININET_cs );
180 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
181 WININET_Handles[handle-1] )
182 info = WININET_AddRef( WININET_Handles[handle-1] );
184 LeaveCriticalSection( &WININET_cs );
186 TRACE("handle %ld -> %p\n", handle, info);
191 BOOL WININET_Release( object_header_t *info )
193 ULONG refs = InterlockedDecrement(&info->refs);
194 TRACE( "object %p refcount = %d\n", info, refs );
197 if ( info->vtbl->CloseConnection )
199 TRACE( "closing connection %p\n", info);
200 info->vtbl->CloseConnection( info );
202 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
203 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
204 || !(info->dwInternalFlags & INET_OPENURL))
206 INTERNET_SendCallback(info, info->dwContext,
207 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
210 TRACE( "destroying object %p\n", info);
211 if ( info->htype != WH_HINIT )
212 list_remove( &info->entry );
213 info->vtbl->Destroy( info );
218 BOOL WININET_FreeHandle( HINTERNET hinternet )
221 UINT_PTR handle = (UINT_PTR) hinternet;
222 object_header_t *info = NULL, *child, *next;
224 EnterCriticalSection( &WININET_cs );
226 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
229 if( WININET_Handles[handle] )
231 info = WININET_Handles[handle];
232 TRACE( "destroying handle %ld for object %p\n", handle+1, info);
233 WININET_Handles[handle] = NULL;
238 LeaveCriticalSection( &WININET_cs );
240 /* As on native when the equivalent of WININET_Release is called, the handle
241 * is already invalid, but if a new handle is created at this time it does
242 * not yet get assigned the freed handle number */
245 /* Free all children as native does */
246 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
248 TRACE( "freeing child handle %ld for parent handle %ld\n",
249 (UINT_PTR)child->hInternet, handle+1);
250 WININET_FreeHandle( child->hInternet );
252 WININET_Release( info );
255 EnterCriticalSection( &WININET_cs );
257 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
258 WININET_dwNextHandle = handle;
260 LeaveCriticalSection( &WININET_cs );
265 /***********************************************************************
266 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
269 * hinstDLL [I] handle to the DLL's instance
271 * lpvReserved [I] reserved, must be NULL
278 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
280 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
283 case DLL_PROCESS_ATTACH:
285 g_dwTlsErrIndex = TlsAlloc();
287 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
290 URLCacheContainers_CreateDefaults();
292 WININET_hModule = hinstDLL;
294 case DLL_THREAD_ATTACH:
297 case DLL_THREAD_DETACH:
298 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
300 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
301 HeapFree(GetProcessHeap(), 0, lpwite);
305 case DLL_PROCESS_DETACH:
309 URLCacheContainers_DeleteAll();
311 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
313 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
314 TlsFree(g_dwTlsErrIndex);
322 /***********************************************************************
323 * INTERNET_SaveProxySettings
325 * Stores the proxy settings given by lpwai into the registry
328 * ERROR_SUCCESS if no error, or error code on fail
330 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
335 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
338 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->dwProxyEnabled, sizeof(DWORD))))
344 if (lpwpi->lpszProxyServer)
346 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->lpszProxyServer, sizeof(WCHAR) * (lstrlenW(lpwpi->lpszProxyServer) + 1))))
354 if ((ret = RegDeleteValueW( key, szProxyServer )))
362 return ERROR_SUCCESS;
365 /***********************************************************************
366 * INTERNET_FindProxyForProtocol
368 * Searches the proxy string for a proxy of the given protocol.
369 * Returns the found proxy, or the default proxy if none of the given
373 * szProxy [In] proxy string to search
374 * proto [In] protocol to search for, e.g. "http"
375 * foundProxy [Out] found proxy
376 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
379 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
380 * *foundProxyLen is set to the required size in WCHARs, including the
381 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
383 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
388 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
390 /* First, look for the specified protocol (proto=scheme://host:port) */
391 for (ptr = szProxy; !ret && ptr && *ptr; )
395 if (!(end = strchrW(ptr, ' ')))
396 end = ptr + strlenW(ptr);
397 if ((equal = strchrW(ptr, '=')) && equal < end &&
398 equal - ptr == strlenW(proto) &&
399 !strncmpiW(proto, ptr, strlenW(proto)))
401 if (end - equal > *foundProxyLen)
403 WARN("buffer too short for %s\n",
404 debugstr_wn(equal + 1, end - equal - 1));
405 *foundProxyLen = end - equal;
406 SetLastError(ERROR_INSUFFICIENT_BUFFER);
410 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
411 foundProxy[end - equal] = 0;
422 /* It wasn't found: look for no protocol */
423 for (ptr = szProxy; !ret && ptr && *ptr; )
427 if (!(end = strchrW(ptr, ' ')))
428 end = ptr + strlenW(ptr);
429 if (!(equal = strchrW(ptr, '=')))
431 if (end - ptr + 1 > *foundProxyLen)
433 WARN("buffer too short for %s\n",
434 debugstr_wn(ptr, end - ptr));
435 *foundProxyLen = end - ptr + 1;
436 SetLastError(ERROR_INSUFFICIENT_BUFFER);
440 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
441 foundProxy[end - ptr] = 0;
452 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
453 debugstr_w(foundProxy));
457 /***********************************************************************
458 * InternetInitializeAutoProxyDll (WININET.@)
460 * Setup the internal proxy
469 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
472 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
476 /***********************************************************************
477 * DetectAutoProxyUrl (WININET.@)
479 * Auto detect the proxy url
485 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
486 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
489 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
493 static void FreeProxyInfo( proxyinfo_t *lpwpi )
495 HeapFree(GetProcessHeap(), 0, lpwpi->lpszProxyServer);
496 HeapFree(GetProcessHeap(), 0, lpwpi->lpszProxyBypass);
499 /***********************************************************************
500 * INTERNET_LoadProxySettings
502 * Loads proxy information from the registry or environment into lpwpi.
504 * The caller should call FreeProxyInfo when done with lpwpi.
507 * The proxy may be specified in the form 'http=proxy.my.org'
508 * Presumably that means there can be ftp=ftpproxy.my.org too.
510 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
517 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
521 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->dwProxyEnabled, &len ) || type != REG_DWORD)
523 lpwpi->dwProxyEnabled = 0;
524 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->dwProxyEnabled, sizeof(DWORD) )))
531 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->dwProxyEnabled)
533 TRACE("Proxy is enabled.\n");
535 /* figure out how much memory the proxy setting takes */
536 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
539 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
541 if (!(szProxy = HeapAlloc( GetProcessHeap(), 0, len )))
544 return ERROR_OUTOFMEMORY;
546 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
548 /* find the http proxy, and strip away everything else */
549 p = strstrW( szProxy, szHttp );
552 p += lstrlenW( szHttp );
553 lstrcpyW( szProxy, p );
555 p = strchrW( szProxy, ' ' );
558 lpwpi->lpszProxyServer = szProxy;
560 TRACE("http proxy = %s\n", debugstr_w(lpwpi->lpszProxyServer));
564 TRACE("No proxy server settings in registry.\n");
565 lpwpi->lpszProxyServer = NULL;
572 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
573 if (!(envproxyW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR))))
574 return ERROR_OUTOFMEMORY;
575 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
577 lpwpi->dwProxyEnabled = 1;
578 lpwpi->lpszProxyServer = envproxyW;
580 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->lpszProxyServer));
584 lpwpi->lpszProxyBypass = NULL;
586 return ERROR_SUCCESS;
589 /***********************************************************************
590 * INTERNET_ConfigureProxy
592 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
596 if (INTERNET_LoadProxySettings( &wpi ))
599 if (wpi.dwProxyEnabled)
601 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
602 lpwai->lpszProxy = wpi.lpszProxyServer;
606 lpwai->dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
610 /***********************************************************************
611 * dump_INTERNET_FLAGS
613 * Helper function to TRACE the internet flags.
619 static void dump_INTERNET_FLAGS(DWORD dwFlags)
621 #define FE(x) { x, #x }
622 static const wininet_flag_info flag[] = {
623 FE(INTERNET_FLAG_RELOAD),
624 FE(INTERNET_FLAG_RAW_DATA),
625 FE(INTERNET_FLAG_EXISTING_CONNECT),
626 FE(INTERNET_FLAG_ASYNC),
627 FE(INTERNET_FLAG_PASSIVE),
628 FE(INTERNET_FLAG_NO_CACHE_WRITE),
629 FE(INTERNET_FLAG_MAKE_PERSISTENT),
630 FE(INTERNET_FLAG_FROM_CACHE),
631 FE(INTERNET_FLAG_SECURE),
632 FE(INTERNET_FLAG_KEEP_CONNECTION),
633 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
634 FE(INTERNET_FLAG_READ_PREFETCH),
635 FE(INTERNET_FLAG_NO_COOKIES),
636 FE(INTERNET_FLAG_NO_AUTH),
637 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
638 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
639 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
640 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
641 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
642 FE(INTERNET_FLAG_RESYNCHRONIZE),
643 FE(INTERNET_FLAG_HYPERLINK),
644 FE(INTERNET_FLAG_NO_UI),
645 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
646 FE(INTERNET_FLAG_CACHE_ASYNC),
647 FE(INTERNET_FLAG_FORMS_SUBMIT),
648 FE(INTERNET_FLAG_NEED_FILE),
649 FE(INTERNET_FLAG_TRANSFER_ASCII),
650 FE(INTERNET_FLAG_TRANSFER_BINARY)
655 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
656 if (flag[i].val & dwFlags) {
657 TRACE(" %s", flag[i].name);
658 dwFlags &= ~flag[i].val;
662 TRACE(" Unknown flags (%08x)\n", dwFlags);
667 /***********************************************************************
668 * INTERNET_CloseHandle (internal)
670 * Close internet handle
673 static VOID APPINFO_Destroy(object_header_t *hdr)
675 appinfo_t *lpwai = (appinfo_t*)hdr;
679 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
680 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
681 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
682 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
683 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
684 HeapFree(GetProcessHeap(), 0, lpwai);
687 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
689 appinfo_t *ai = (appinfo_t*)hdr;
692 case INTERNET_OPTION_HANDLE_TYPE:
693 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
695 if (*size < sizeof(ULONG))
696 return ERROR_INSUFFICIENT_BUFFER;
698 *size = sizeof(DWORD);
699 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
700 return ERROR_SUCCESS;
702 case INTERNET_OPTION_USER_AGENT: {
705 TRACE("INTERNET_OPTION_USER_AGENT\n");
710 DWORD len = ai->lpszAgent ? strlenW(ai->lpszAgent) : 0;
712 *size = (len + 1) * sizeof(WCHAR);
713 if(!buffer || bufsize < *size)
714 return ERROR_INSUFFICIENT_BUFFER;
717 strcpyW(buffer, ai->lpszAgent);
719 *(WCHAR *)buffer = 0;
720 /* If the buffer is copied, the returned length doesn't include
721 * the NULL terminator.
723 *size = len * sizeof(WCHAR);
726 *size = WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, NULL, 0, NULL, NULL);
729 if(!buffer || bufsize < *size)
730 return ERROR_INSUFFICIENT_BUFFER;
733 WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, buffer, *size, NULL, NULL);
736 /* If the buffer is copied, the returned length doesn't include
737 * the NULL terminator.
742 return ERROR_SUCCESS;
745 case INTERNET_OPTION_PROXY:
747 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
748 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
749 LPWSTR proxy, proxy_bypass;
752 proxyBytesRequired = (lstrlenW(ai->lpszProxy) + 1) * sizeof(WCHAR);
753 if (ai->lpszProxyBypass)
754 proxyBypassBytesRequired = (lstrlenW(ai->lpszProxyBypass) + 1) * sizeof(WCHAR);
755 if (*size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
757 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
758 return ERROR_INSUFFICIENT_BUFFER;
760 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
761 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
763 pi->dwAccessType = ai->dwAccessType;
764 pi->lpszProxy = NULL;
765 pi->lpszProxyBypass = NULL;
767 lstrcpyW(proxy, ai->lpszProxy);
768 pi->lpszProxy = proxy;
771 if (ai->lpszProxyBypass) {
772 lstrcpyW(proxy_bypass, ai->lpszProxyBypass);
773 pi->lpszProxyBypass = proxy_bypass;
776 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
777 return ERROR_SUCCESS;
779 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
780 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
781 LPSTR proxy, proxy_bypass;
784 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->lpszProxy, -1, NULL, 0, NULL, NULL);
785 if (ai->lpszProxyBypass)
786 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->lpszProxyBypass, -1,
787 NULL, 0, NULL, NULL);
788 if (*size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
790 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
791 return ERROR_INSUFFICIENT_BUFFER;
793 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
794 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
796 pi->dwAccessType = ai->dwAccessType;
797 pi->lpszProxy = NULL;
798 pi->lpszProxyBypass = NULL;
800 WideCharToMultiByte(CP_ACP, 0, ai->lpszProxy, -1, proxy, proxyBytesRequired, NULL, NULL);
801 pi->lpszProxy = proxy;
804 if (ai->lpszProxyBypass) {
805 WideCharToMultiByte(CP_ACP, 0, ai->lpszProxyBypass, -1, proxy_bypass,
806 proxyBypassBytesRequired, NULL, NULL);
807 pi->lpszProxyBypass = proxy_bypass;
810 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
811 return ERROR_SUCCESS;
815 return INET_QueryOption(option, buffer, size, unicode);
818 static const object_vtbl_t APPINFOVtbl = {
831 /***********************************************************************
832 * InternetOpenW (WININET.@)
834 * Per-application initialization of wininet
837 * HINTERNET on success
841 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
842 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
844 appinfo_t *lpwai = NULL;
845 HINTERNET handle = NULL;
847 if (TRACE_ON(wininet)) {
848 #define FE(x) { x, #x }
849 static const wininet_flag_info access_type[] = {
850 FE(INTERNET_OPEN_TYPE_PRECONFIG),
851 FE(INTERNET_OPEN_TYPE_DIRECT),
852 FE(INTERNET_OPEN_TYPE_PROXY),
853 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
857 const char *access_type_str = "Unknown";
859 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
860 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
861 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
862 if (access_type[i].val == dwAccessType) {
863 access_type_str = access_type[i].name;
867 TRACE(" access type : %s\n", access_type_str);
869 dump_INTERNET_FLAGS(dwFlags);
872 /* Clear any error information */
873 INTERNET_SetLastError(0);
875 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(appinfo_t));
878 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
882 lpwai->hdr.htype = WH_HINIT;
883 lpwai->hdr.vtbl = &APPINFOVtbl;
884 lpwai->hdr.dwFlags = dwFlags;
886 lpwai->dwAccessType = dwAccessType;
887 lpwai->lpszProxyUsername = NULL;
888 lpwai->lpszProxyPassword = NULL;
890 handle = WININET_AllocHandle( &lpwai->hdr );
893 HeapFree( GetProcessHeap(), 0, lpwai );
894 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
898 lpwai->lpszAgent = heap_strdupW(lpszAgent);
899 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
900 INTERNET_ConfigureProxy( lpwai );
902 lpwai->lpszProxy = heap_strdupW(lpszProxy);
903 lpwai->lpszProxyBypass = heap_strdupW(lpszProxyBypass);
907 WININET_Release( &lpwai->hdr );
909 TRACE("returning %p\n", lpwai);
915 /***********************************************************************
916 * InternetOpenA (WININET.@)
918 * Per-application initialization of wininet
921 * HINTERNET on success
925 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
926 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
928 WCHAR *szAgent, *szProxy, *szBypass;
931 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
932 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
934 szAgent = heap_strdupAtoW(lpszAgent);
935 szProxy = heap_strdupAtoW(lpszProxy);
936 szBypass = heap_strdupAtoW(lpszProxyBypass);
938 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
940 HeapFree(GetProcessHeap(), 0, szAgent);
941 HeapFree(GetProcessHeap(), 0, szProxy);
942 HeapFree(GetProcessHeap(), 0, szBypass);
947 /***********************************************************************
948 * InternetGetLastResponseInfoA (WININET.@)
950 * Return last wininet error description on the calling thread
953 * TRUE on success of writing to buffer
957 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
958 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
960 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
966 *lpdwError = lpwite->dwError;
969 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
970 *lpdwBufferLength = strlen(lpszBuffer);
973 *lpdwBufferLength = 0;
978 *lpdwBufferLength = 0;
984 /***********************************************************************
985 * InternetGetLastResponseInfoW (WININET.@)
987 * Return last wininet error description on the calling thread
990 * TRUE on success of writing to buffer
994 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
995 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
997 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
1003 *lpdwError = lpwite->dwError;
1004 if (lpwite->dwError)
1006 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
1007 *lpdwBufferLength = lstrlenW(lpszBuffer);
1010 *lpdwBufferLength = 0;
1015 *lpdwBufferLength = 0;
1021 /***********************************************************************
1022 * InternetGetConnectedState (WININET.@)
1024 * Return connected state
1028 * if lpdwStatus is not null, return the status (off line,
1029 * modem, lan...) in it.
1030 * FALSE if not connected
1032 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1034 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1037 WARN("always returning LAN connection.\n");
1038 *lpdwStatus = INTERNET_CONNECTION_LAN;
1044 /***********************************************************************
1045 * InternetGetConnectedStateExW (WININET.@)
1047 * Return connected state
1051 * lpdwStatus [O] Flags specifying the status of the internet connection.
1052 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1053 * dwNameLen [I] Size of the buffer, in characters.
1054 * dwReserved [I] Reserved. Must be set to 0.
1058 * if lpdwStatus is not null, return the status (off line,
1059 * modem, lan...) in it.
1060 * FALSE if not connected
1063 * If the system has no available network connections, an empty string is
1064 * stored in lpszConnectionName. If there is a LAN connection, a localized
1065 * "LAN Connection" string is stored. Presumably, if only a dial-up
1066 * connection is available then the name of the dial-up connection is
1067 * returned. Why any application, other than the "Internet Settings" CPL,
1068 * would want to use this function instead of the simpler InternetGetConnectedStateW
1069 * function is beyond me.
1071 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1072 DWORD dwNameLen, DWORD dwReserved)
1074 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1081 WARN("always returning LAN connection.\n");
1082 *lpdwStatus = INTERNET_CONNECTION_LAN;
1084 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1088 /***********************************************************************
1089 * InternetGetConnectedStateExA (WININET.@)
1091 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1092 DWORD dwNameLen, DWORD dwReserved)
1094 LPWSTR lpwszConnectionName = NULL;
1097 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1099 if (lpszConnectionName && dwNameLen > 0)
1100 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
1102 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1104 if (rc && lpwszConnectionName)
1106 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1107 dwNameLen, NULL, NULL);
1109 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
1116 /***********************************************************************
1117 * InternetConnectW (WININET.@)
1119 * Open a ftp, gopher or http session
1122 * HINTERNET a session handle on success
1126 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1127 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1128 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1129 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1132 HINTERNET rc = NULL;
1133 DWORD res = ERROR_SUCCESS;
1135 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
1136 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1137 dwService, dwFlags, dwContext);
1139 if (!lpszServerName)
1141 SetLastError(ERROR_INVALID_PARAMETER);
1145 hIC = (appinfo_t*)WININET_GetObject( hInternet );
1146 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1148 res = ERROR_INVALID_HANDLE;
1154 case INTERNET_SERVICE_FTP:
1155 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1156 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1158 res = INTERNET_GetLastError();
1161 case INTERNET_SERVICE_HTTP:
1162 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1163 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1166 case INTERNET_SERVICE_GOPHER:
1172 WININET_Release( &hIC->hdr );
1174 TRACE("returning %p\n", rc);
1180 /***********************************************************************
1181 * InternetConnectA (WININET.@)
1183 * Open a ftp, gopher or http session
1186 * HINTERNET a session handle on success
1190 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1191 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1192 LPCSTR lpszUserName, LPCSTR lpszPassword,
1193 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1195 HINTERNET rc = NULL;
1196 LPWSTR szServerName;
1200 szServerName = heap_strdupAtoW(lpszServerName);
1201 szUserName = heap_strdupAtoW(lpszUserName);
1202 szPassword = heap_strdupAtoW(lpszPassword);
1204 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1205 szUserName, szPassword, dwService, dwFlags, dwContext);
1207 HeapFree(GetProcessHeap(), 0, szServerName);
1208 HeapFree(GetProcessHeap(), 0, szUserName);
1209 HeapFree(GetProcessHeap(), 0, szPassword);
1214 /***********************************************************************
1215 * InternetFindNextFileA (WININET.@)
1217 * Continues a file search from a previous call to FindFirstFile
1224 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1227 WIN32_FIND_DATAW fd;
1229 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1231 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1235 /***********************************************************************
1236 * InternetFindNextFileW (WININET.@)
1238 * Continues a file search from a previous call to FindFirstFile
1245 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1247 object_header_t *hdr;
1252 hdr = WININET_GetObject(hFind);
1254 WARN("Invalid handle\n");
1255 SetLastError(ERROR_INVALID_HANDLE);
1259 if(hdr->vtbl->FindNextFileW) {
1260 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1262 WARN("Handle doesn't support NextFile\n");
1263 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1266 WININET_Release(hdr);
1268 if(res != ERROR_SUCCESS)
1270 return res == ERROR_SUCCESS;
1273 /***********************************************************************
1274 * InternetCloseHandle (WININET.@)
1276 * Generic close handle function
1283 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1285 object_header_t *lpwh;
1287 TRACE("%p\n",hInternet);
1289 lpwh = WININET_GetObject( hInternet );
1292 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1296 WININET_Release( lpwh );
1297 WININET_FreeHandle( hInternet );
1303 /***********************************************************************
1304 * ConvertUrlComponentValue (Internal)
1306 * Helper function for InternetCrackUrlA
1309 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1310 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1311 LPCSTR lpszStart, LPCWSTR lpwszStart)
1313 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1314 if (*dwComponentLen != 0)
1316 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1317 if (*lppszComponent == NULL)
1321 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1322 *lppszComponent = (LPSTR)lpszStart + offset;
1325 *lppszComponent = NULL;
1327 *dwComponentLen = nASCIILength;
1331 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1332 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1333 (*lppszComponent)[ncpylen]=0;
1334 *dwComponentLen = ncpylen;
1340 /***********************************************************************
1341 * InternetCrackUrlA (WININET.@)
1343 * See InternetCrackUrlW.
1345 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1346 LPURL_COMPONENTSA lpUrlComponents)
1349 URL_COMPONENTSW UCW;
1351 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1352 *scheme = NULL, *extra = NULL;
1354 TRACE("(%s %u %x %p)\n",
1355 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1356 dwUrlLength, dwFlags, lpUrlComponents);
1358 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1359 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1361 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1367 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1369 /* if dwUrlLength=-1 then nLength includes null but length to
1370 InternetCrackUrlW should not include it */
1371 if (dwUrlLength == -1) nLength--;
1373 lpwszUrl = HeapAlloc(GetProcessHeap(), 0, nLength * sizeof(WCHAR));
1374 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1376 memset(&UCW,0,sizeof(UCW));
1377 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1378 if (lpUrlComponents->dwHostNameLength)
1380 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1381 if (lpUrlComponents->lpszHostName)
1383 hostname = HeapAlloc(GetProcessHeap(), 0, UCW.dwHostNameLength * sizeof(WCHAR));
1384 UCW.lpszHostName = hostname;
1387 if (lpUrlComponents->dwUserNameLength)
1389 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1390 if (lpUrlComponents->lpszUserName)
1392 username = HeapAlloc(GetProcessHeap(), 0, UCW.dwUserNameLength * sizeof(WCHAR));
1393 UCW.lpszUserName = username;
1396 if (lpUrlComponents->dwPasswordLength)
1398 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1399 if (lpUrlComponents->lpszPassword)
1401 password = HeapAlloc(GetProcessHeap(), 0, UCW.dwPasswordLength * sizeof(WCHAR));
1402 UCW.lpszPassword = password;
1405 if (lpUrlComponents->dwUrlPathLength)
1407 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1408 if (lpUrlComponents->lpszUrlPath)
1410 path = HeapAlloc(GetProcessHeap(), 0, UCW.dwUrlPathLength * sizeof(WCHAR));
1411 UCW.lpszUrlPath = path;
1414 if (lpUrlComponents->dwSchemeLength)
1416 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1417 if (lpUrlComponents->lpszScheme)
1419 scheme = HeapAlloc(GetProcessHeap(), 0, UCW.dwSchemeLength * sizeof(WCHAR));
1420 UCW.lpszScheme = scheme;
1423 if (lpUrlComponents->dwExtraInfoLength)
1425 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1426 if (lpUrlComponents->lpszExtraInfo)
1428 extra = HeapAlloc(GetProcessHeap(), 0, UCW.dwExtraInfoLength * sizeof(WCHAR));
1429 UCW.lpszExtraInfo = extra;
1432 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1434 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1435 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1436 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1437 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1438 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1439 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1440 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1441 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1442 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1443 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1444 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1445 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1447 lpUrlComponents->nScheme = UCW.nScheme;
1448 lpUrlComponents->nPort = UCW.nPort;
1450 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1451 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1452 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1453 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1454 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1456 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1457 HeapFree(GetProcessHeap(), 0, hostname);
1458 HeapFree(GetProcessHeap(), 0, username);
1459 HeapFree(GetProcessHeap(), 0, password);
1460 HeapFree(GetProcessHeap(), 0, path);
1461 HeapFree(GetProcessHeap(), 0, scheme);
1462 HeapFree(GetProcessHeap(), 0, extra);
1466 static const WCHAR url_schemes[][7] =
1469 {'g','o','p','h','e','r',0},
1470 {'h','t','t','p',0},
1471 {'h','t','t','p','s',0},
1472 {'f','i','l','e',0},
1473 {'n','e','w','s',0},
1474 {'m','a','i','l','t','o',0},
1478 /***********************************************************************
1479 * GetInternetSchemeW (internal)
1485 * INTERNET_SCHEME_UNKNOWN on failure
1488 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1492 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1494 if(lpszScheme==NULL)
1495 return INTERNET_SCHEME_UNKNOWN;
1497 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1498 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1499 return INTERNET_SCHEME_FIRST + i;
1501 return INTERNET_SCHEME_UNKNOWN;
1504 /***********************************************************************
1505 * SetUrlComponentValueW (Internal)
1507 * Helper function for InternetCrackUrlW
1510 * lppszComponent [O] Holds the returned string
1511 * dwComponentLen [I] Holds the size of lppszComponent
1512 * [O] Holds the length of the string in lppszComponent without '\0'
1513 * lpszStart [I] Holds the string to copy from
1514 * len [I] Holds the length of lpszStart without '\0'
1521 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1523 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1525 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1528 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1530 if (*lppszComponent == NULL)
1532 *lppszComponent = (LPWSTR)lpszStart;
1533 *dwComponentLen = len;
1537 DWORD ncpylen = min((*dwComponentLen)-1, len);
1538 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1539 (*lppszComponent)[ncpylen] = '\0';
1540 *dwComponentLen = ncpylen;
1547 /***********************************************************************
1548 * InternetCrackUrlW (WININET.@)
1550 * Break up URL into its components
1556 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1557 LPURL_COMPONENTSW lpUC)
1561 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1564 LPCWSTR lpszParam = NULL;
1565 BOOL bIsAbsolute = FALSE;
1566 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1567 LPCWSTR lpszcp = NULL;
1568 LPWSTR lpszUrl_decode = NULL;
1569 DWORD dwUrlLength = dwUrlLength_orig;
1571 TRACE("(%s %u %x %p)\n",
1572 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1573 dwUrlLength, dwFlags, lpUC);
1575 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1577 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1580 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1582 if (dwFlags & ICU_DECODE)
1585 DWORD len = dwUrlLength + 1;
1587 if (!(url_tmp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1589 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1592 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1593 url_tmp[dwUrlLength] = 0;
1594 if (!(lpszUrl_decode = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1596 HeapFree(GetProcessHeap(), 0, url_tmp);
1597 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1600 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1603 lpszUrl = lpszUrl_decode;
1605 HeapFree(GetProcessHeap(), 0, url_tmp);
1609 /* Determine if the URI is absolute. */
1610 while (lpszap - lpszUrl < dwUrlLength)
1612 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1617 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1624 lpszcp = lpszUrl; /* Relative url */
1630 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1631 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1633 /* Parse <params> */
1634 lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl));
1636 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1638 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1640 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1641 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1643 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1647 /* Get scheme first. */
1648 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1649 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1650 lpszUrl, lpszcp - lpszUrl);
1652 /* Eat ':' in protocol. */
1655 /* double slash indicates the net_loc portion is present */
1656 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1660 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1664 lpszNetLoc = min(lpszNetLoc, lpszParam);
1666 lpszNetLoc = lpszParam;
1668 else if (!lpszNetLoc)
1669 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1677 /* [<user>[<:password>]@]<host>[:<port>] */
1678 /* First find the user and password if they exist */
1680 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1681 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1683 /* username and password not specified. */
1684 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1685 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1687 else /* Parse out username and password */
1689 LPCWSTR lpszUser = lpszcp;
1690 LPCWSTR lpszPasswd = lpszHost;
1692 while (lpszcp < lpszHost)
1695 lpszPasswd = lpszcp;
1700 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1701 lpszUser, lpszPasswd - lpszUser);
1703 if (lpszPasswd != lpszHost)
1705 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1706 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1707 lpszHost - lpszPasswd);
1709 lpszcp++; /* Advance to beginning of host */
1712 /* Parse <host><:port> */
1715 lpszPort = lpszNetLoc;
1717 /* special case for res:// URLs: there is no port here, so the host is the
1718 entire string up to the first '/' */
1719 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1721 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1722 lpszHost, lpszPort - lpszHost);
1727 while (lpszcp < lpszNetLoc)
1735 /* If the scheme is "file" and the host is just one letter, it's not a host */
1736 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1739 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1744 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1745 lpszHost, lpszPort - lpszHost);
1746 if (lpszPort != lpszNetLoc)
1747 lpUC->nPort = atoiW(++lpszPort);
1748 else switch (lpUC->nScheme)
1750 case INTERNET_SCHEME_HTTP:
1751 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1753 case INTERNET_SCHEME_HTTPS:
1754 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1756 case INTERNET_SCHEME_FTP:
1757 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1759 case INTERNET_SCHEME_GOPHER:
1760 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1771 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1772 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1773 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1778 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1779 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1780 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1781 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1784 /* Here lpszcp points to:
1786 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1787 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1789 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1793 /* Only truncate the parameter list if it's already been saved
1794 * in lpUC->lpszExtraInfo.
1796 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1797 len = lpszParam - lpszcp;
1800 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1801 * newlines if necessary.
1803 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1804 if (lpsznewline != NULL)
1805 len = lpsznewline - lpszcp;
1807 len = dwUrlLength-(lpszcp-lpszUrl);
1809 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1814 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1815 lpUC->lpszUrlPath[0] = 0;
1816 lpUC->dwUrlPathLength = 0;
1819 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1820 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1821 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1822 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1823 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1825 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1829 /***********************************************************************
1830 * InternetAttemptConnect (WININET.@)
1832 * Attempt to make a connection to the internet
1835 * ERROR_SUCCESS on success
1836 * Error value on failure
1839 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1842 return ERROR_SUCCESS;
1846 /***********************************************************************
1847 * InternetCanonicalizeUrlA (WININET.@)
1849 * Escape unsafe characters and spaces
1856 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1857 LPDWORD lpdwBufferLength, DWORD dwFlags)
1860 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1862 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1863 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1865 if(dwFlags & ICU_DECODE)
1867 dwURLFlags |= URL_UNESCAPE;
1868 dwFlags &= ~ICU_DECODE;
1871 if(dwFlags & ICU_ESCAPE)
1873 dwURLFlags |= URL_UNESCAPE;
1874 dwFlags &= ~ICU_ESCAPE;
1877 if(dwFlags & ICU_BROWSER_MODE)
1879 dwURLFlags |= URL_BROWSER_MODE;
1880 dwFlags &= ~ICU_BROWSER_MODE;
1883 if(dwFlags & ICU_NO_ENCODE)
1885 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1886 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1887 dwFlags &= ~ICU_NO_ENCODE;
1890 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1892 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1893 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1894 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1896 return (hr == S_OK) ? TRUE : FALSE;
1899 /***********************************************************************
1900 * InternetCanonicalizeUrlW (WININET.@)
1902 * Escape unsafe characters and spaces
1909 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1910 LPDWORD lpdwBufferLength, DWORD dwFlags)
1913 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1915 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1916 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1918 if(dwFlags & ICU_DECODE)
1920 dwURLFlags |= URL_UNESCAPE;
1921 dwFlags &= ~ICU_DECODE;
1924 if(dwFlags & ICU_ESCAPE)
1926 dwURLFlags |= URL_UNESCAPE;
1927 dwFlags &= ~ICU_ESCAPE;
1930 if(dwFlags & ICU_BROWSER_MODE)
1932 dwURLFlags |= URL_BROWSER_MODE;
1933 dwFlags &= ~ICU_BROWSER_MODE;
1936 if(dwFlags & ICU_NO_ENCODE)
1938 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1939 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1940 dwFlags &= ~ICU_NO_ENCODE;
1943 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1945 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1946 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1947 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1949 return (hr == S_OK) ? TRUE : FALSE;
1952 /* #################################################### */
1954 static INTERNET_STATUS_CALLBACK set_status_callback(
1955 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1957 INTERNET_STATUS_CALLBACK ret;
1959 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1960 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1962 ret = lpwh->lpfnStatusCB;
1963 lpwh->lpfnStatusCB = callback;
1968 /***********************************************************************
1969 * InternetSetStatusCallbackA (WININET.@)
1971 * Sets up a callback function which is called as progress is made
1972 * during an operation.
1975 * Previous callback or NULL on success
1976 * INTERNET_INVALID_STATUS_CALLBACK on failure
1979 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1980 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1982 INTERNET_STATUS_CALLBACK retVal;
1983 object_header_t *lpwh;
1985 TRACE("%p\n", hInternet);
1987 if (!(lpwh = WININET_GetObject(hInternet)))
1988 return INTERNET_INVALID_STATUS_CALLBACK;
1990 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1992 WININET_Release( lpwh );
1996 /***********************************************************************
1997 * InternetSetStatusCallbackW (WININET.@)
1999 * Sets up a callback function which is called as progress is made
2000 * during an operation.
2003 * Previous callback or NULL on success
2004 * INTERNET_INVALID_STATUS_CALLBACK on failure
2007 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2008 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2010 INTERNET_STATUS_CALLBACK retVal;
2011 object_header_t *lpwh;
2013 TRACE("%p\n", hInternet);
2015 if (!(lpwh = WININET_GetObject(hInternet)))
2016 return INTERNET_INVALID_STATUS_CALLBACK;
2018 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2020 WININET_Release( lpwh );
2024 /***********************************************************************
2025 * InternetSetFilePointer (WININET.@)
2027 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2028 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2034 /***********************************************************************
2035 * InternetWriteFile (WININET.@)
2037 * Write data to an open internet file
2044 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2045 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2047 object_header_t *lpwh;
2050 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2052 lpwh = WININET_GetObject( hFile );
2054 WARN("Invalid handle\n");
2055 SetLastError(ERROR_INVALID_HANDLE);
2059 if(lpwh->vtbl->WriteFile) {
2060 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2062 WARN("No Writefile method.\n");
2063 res = ERROR_INVALID_HANDLE;
2066 WININET_Release( lpwh );
2068 if(res != ERROR_SUCCESS)
2070 return res == ERROR_SUCCESS;
2074 /***********************************************************************
2075 * InternetReadFile (WININET.@)
2077 * Read data from an open internet file
2084 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2085 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2087 object_header_t *hdr;
2088 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2090 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2092 hdr = WININET_GetObject(hFile);
2094 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2098 if(hdr->vtbl->ReadFile)
2099 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2101 WININET_Release(hdr);
2103 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2104 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2106 if(res != ERROR_SUCCESS)
2108 return res == ERROR_SUCCESS;
2111 /***********************************************************************
2112 * InternetReadFileExA (WININET.@)
2114 * Read data from an open internet file
2117 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2118 * lpBuffersOut [I/O] Buffer.
2119 * dwFlags [I] Flags. See notes.
2120 * dwContext [I] Context for callbacks.
2127 * The parameter dwFlags include zero or more of the following flags:
2128 *|IRF_ASYNC - Makes the call asynchronous.
2129 *|IRF_SYNC - Makes the call synchronous.
2130 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2131 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2133 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2136 * InternetOpenUrlA(), HttpOpenRequestA()
2138 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2139 DWORD dwFlags, DWORD_PTR dwContext)
2141 object_header_t *hdr;
2142 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2144 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2146 hdr = WININET_GetObject(hFile);
2148 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2152 if(hdr->vtbl->ReadFileExA)
2153 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
2155 WININET_Release(hdr);
2157 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2158 res, lpBuffersOut->dwBufferLength);
2160 if(res != ERROR_SUCCESS)
2162 return res == ERROR_SUCCESS;
2165 /***********************************************************************
2166 * InternetReadFileExW (WININET.@)
2168 * InternetReadFileExA()
2170 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2171 DWORD dwFlags, DWORD_PTR dwContext)
2173 object_header_t *hdr;
2174 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2176 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2178 hdr = WININET_GetObject(hFile);
2180 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2184 if(hdr->vtbl->ReadFileExW)
2185 res = hdr->vtbl->ReadFileExW(hdr, lpBuffer, dwFlags, dwContext);
2187 WININET_Release(hdr);
2189 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2190 res, lpBuffer->dwBufferLength);
2192 if(res != ERROR_SUCCESS)
2194 return res == ERROR_SUCCESS;
2197 DWORD INET_QueryOption(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2199 static BOOL warn = TRUE;
2202 case INTERNET_OPTION_REQUEST_FLAGS:
2203 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2205 if (*size < sizeof(ULONG))
2206 return ERROR_INSUFFICIENT_BUFFER;
2208 *(ULONG*)buffer = 4;
2209 *size = sizeof(ULONG);
2211 return ERROR_SUCCESS;
2213 case INTERNET_OPTION_HTTP_VERSION:
2214 if (*size < sizeof(HTTP_VERSION_INFO))
2215 return ERROR_INSUFFICIENT_BUFFER;
2218 * Presently hardcoded to 1.1
2220 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2221 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2222 *size = sizeof(HTTP_VERSION_INFO);
2224 return ERROR_SUCCESS;
2226 case INTERNET_OPTION_CONNECTED_STATE:
2228 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2231 if (*size < sizeof(ULONG))
2232 return ERROR_INSUFFICIENT_BUFFER;
2234 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2235 *size = sizeof(ULONG);
2237 return ERROR_SUCCESS;
2239 case INTERNET_OPTION_PROXY: {
2243 TRACE("Getting global proxy info\n");
2244 memset(&ai, 0, sizeof(appinfo_t));
2245 INTERNET_ConfigureProxy(&ai);
2247 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2248 APPINFO_Destroy(&ai.hdr);
2252 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2253 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2255 if (*size < sizeof(ULONG))
2256 return ERROR_INSUFFICIENT_BUFFER;
2258 *(ULONG*)buffer = 2;
2259 *size = sizeof(ULONG);
2261 return ERROR_SUCCESS;
2263 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2264 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2266 if (*size < sizeof(ULONG))
2267 return ERROR_INSUFFICIENT_BUFFER;
2270 *size = sizeof(ULONG);
2272 return ERROR_SUCCESS;
2274 case INTERNET_OPTION_SECURITY_FLAGS:
2275 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2276 return ERROR_SUCCESS;
2278 case INTERNET_OPTION_VERSION: {
2279 static const INTERNET_VERSION_INFO info = { 1, 2 };
2281 TRACE("INTERNET_OPTION_VERSION\n");
2283 if (*size < sizeof(INTERNET_VERSION_INFO))
2284 return ERROR_INSUFFICIENT_BUFFER;
2286 memcpy(buffer, &info, sizeof(info));
2287 *size = sizeof(info);
2289 return ERROR_SUCCESS;
2292 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2293 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2294 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2295 DWORD res = ERROR_SUCCESS, i;
2299 TRACE("Getting global proxy info\n");
2300 if((ret = INTERNET_LoadProxySettings(&pi)))
2303 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2305 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2307 return ERROR_INSUFFICIENT_BUFFER;
2310 for (i = 0; i < con->dwOptionCount; i++) {
2311 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2312 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2314 switch (option->dwOption) {
2315 case INTERNET_PER_CONN_FLAGS:
2316 if(pi.dwProxyEnabled)
2317 option->Value.dwValue = PROXY_TYPE_PROXY;
2319 option->Value.dwValue = PROXY_TYPE_DIRECT;
2322 case INTERNET_PER_CONN_PROXY_SERVER:
2324 option->Value.pszValue = heap_strdupW(pi.lpszProxyServer);
2326 optionA->Value.pszValue = heap_strdupWtoA(pi.lpszProxyServer);
2329 case INTERNET_PER_CONN_PROXY_BYPASS:
2331 option->Value.pszValue = heap_strdupW(pi.lpszProxyBypass);
2333 optionA->Value.pszValue = heap_strdupWtoA(pi.lpszProxyBypass);
2336 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2337 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2338 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2339 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2340 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2341 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2342 FIXME("Unhandled dwOption %d\n", option->dwOption);
2343 memset(&option->Value, 0, sizeof(option->Value));
2347 FIXME("Unknown dwOption %d\n", option->dwOption);
2348 res = ERROR_INVALID_PARAMETER;
2356 case INTERNET_OPTION_USER_AGENT:
2357 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2358 case INTERNET_OPTION_POLICY:
2359 return ERROR_INVALID_PARAMETER;
2362 FIXME("Stub for %d\n", option);
2363 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2366 /***********************************************************************
2367 * InternetQueryOptionW (WININET.@)
2369 * Queries an options on the specified handle
2376 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2377 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2379 object_header_t *hdr;
2380 DWORD res = ERROR_INVALID_HANDLE;
2382 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2385 hdr = WININET_GetObject(hInternet);
2387 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2388 WININET_Release(hdr);
2391 res = INET_QueryOption(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2394 if(res != ERROR_SUCCESS)
2396 return res == ERROR_SUCCESS;
2399 /***********************************************************************
2400 * InternetQueryOptionA (WININET.@)
2402 * Queries an options on the specified handle
2409 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2410 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2412 object_header_t *hdr;
2413 DWORD res = ERROR_INVALID_HANDLE;
2415 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2418 hdr = WININET_GetObject(hInternet);
2420 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2421 WININET_Release(hdr);
2424 res = INET_QueryOption(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2427 if(res != ERROR_SUCCESS)
2429 return res == ERROR_SUCCESS;
2433 /***********************************************************************
2434 * InternetSetOptionW (WININET.@)
2436 * Sets an options on the specified handle
2443 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2444 LPVOID lpBuffer, DWORD dwBufferLength)
2446 object_header_t *lpwhh;
2449 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2451 lpwhh = (object_header_t*) WININET_GetObject( hInternet );
2452 if(lpwhh && lpwhh->vtbl->SetOption) {
2455 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2456 if(res != ERROR_INTERNET_INVALID_OPTION) {
2457 WININET_Release( lpwhh );
2459 if(res != ERROR_SUCCESS)
2462 return res == ERROR_SUCCESS;
2468 case INTERNET_OPTION_CALLBACK:
2472 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2475 WININET_Release(lpwhh);
2476 SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2479 case INTERNET_OPTION_HTTP_VERSION:
2481 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2482 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2485 case INTERNET_OPTION_ERROR_MASK:
2488 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2490 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2491 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2492 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2493 SetLastError(ERROR_INVALID_PARAMETER);
2495 } else if(dwBufferLength != sizeof(ULONG)) {
2496 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2499 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2502 case INTERNET_OPTION_CODEPAGE:
2504 ULONG codepage = *(ULONG *)lpBuffer;
2505 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2508 case INTERNET_OPTION_REQUEST_PRIORITY:
2510 ULONG priority = *(ULONG *)lpBuffer;
2511 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2514 case INTERNET_OPTION_CONNECT_TIMEOUT:
2516 ULONG connecttimeout = *(ULONG *)lpBuffer;
2517 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2520 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2522 ULONG receivetimeout = *(ULONG *)lpBuffer;
2523 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2526 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2528 ULONG conns = *(ULONG *)lpBuffer;
2529 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2532 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2534 ULONG conns = *(ULONG *)lpBuffer;
2535 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2538 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2539 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2541 case INTERNET_OPTION_END_BROWSER_SESSION:
2542 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2544 case INTERNET_OPTION_CONNECTED_STATE:
2545 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2547 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2548 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2550 case INTERNET_OPTION_SEND_TIMEOUT:
2551 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2553 ULONG timeout = *(ULONG *)lpBuffer;
2554 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout);
2557 case INTERNET_OPTION_CONNECT_RETRIES:
2559 ULONG retries = *(ULONG *)lpBuffer;
2560 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2563 case INTERNET_OPTION_CONTEXT_VALUE:
2564 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2566 case INTERNET_OPTION_SECURITY_FLAGS:
2567 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2569 case INTERNET_OPTION_DISABLE_AUTODIAL:
2570 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2572 case INTERNET_OPTION_HTTP_DECODING:
2573 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2574 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2577 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2578 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2579 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2582 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2583 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2584 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2587 case INTERNET_OPTION_CODEPAGE_PATH:
2588 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2589 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2592 case INTERNET_OPTION_CODEPAGE_EXTRA:
2593 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2594 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2597 case INTERNET_OPTION_IDN:
2598 FIXME("INTERNET_OPTION_IDN; STUB\n");
2599 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2602 case INTERNET_OPTION_POLICY:
2603 SetLastError(ERROR_INVALID_PARAMETER);
2606 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2607 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2612 INTERNET_LoadProxySettings(&pi);
2614 for (i = 0; i < con->dwOptionCount; i++) {
2615 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2617 switch (option->dwOption) {
2618 case INTERNET_PER_CONN_PROXY_SERVER:
2619 HeapFree(GetProcessHeap(), 0, pi.lpszProxyServer);
2620 pi.lpszProxyServer = heap_strdupW(option->Value.pszValue);
2623 case INTERNET_PER_CONN_FLAGS:
2624 if(option->Value.dwValue & PROXY_TYPE_PROXY)
2625 pi.dwProxyEnabled = 1;
2628 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
2629 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
2630 pi.dwProxyEnabled = 0;
2634 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2635 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2636 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2637 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2638 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2639 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2640 case INTERNET_PER_CONN_PROXY_BYPASS:
2641 FIXME("Unhandled dwOption %d\n", option->dwOption);
2645 FIXME("Unknown dwOption %d\n", option->dwOption);
2646 SetLastError(ERROR_INVALID_PARAMETER);
2651 if ((res = INTERNET_SaveProxySettings(&pi)))
2656 ret = (res == ERROR_SUCCESS);
2660 FIXME("Option %d STUB\n",dwOption);
2661 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2667 WININET_Release( lpwhh );
2673 /***********************************************************************
2674 * InternetSetOptionA (WININET.@)
2676 * Sets an options on the specified handle.
2683 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2684 LPVOID lpBuffer, DWORD dwBufferLength)
2692 case INTERNET_OPTION_CALLBACK:
2694 object_header_t *lpwh;
2696 if (!(lpwh = WININET_GetObject(hInternet)))
2698 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2701 WININET_Release(lpwh);
2702 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2705 case INTERNET_OPTION_PROXY:
2707 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2708 LPINTERNET_PROXY_INFOW piw;
2709 DWORD proxlen, prbylen;
2712 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2713 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2714 wlen = sizeof(*piw) + proxlen + prbylen;
2715 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2716 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2717 piw->dwAccessType = pi->dwAccessType;
2718 prox = (LPWSTR) &piw[1];
2719 prby = &prox[proxlen+1];
2720 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2721 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2722 piw->lpszProxy = prox;
2723 piw->lpszProxyBypass = prby;
2726 case INTERNET_OPTION_USER_AGENT:
2727 case INTERNET_OPTION_USERNAME:
2728 case INTERNET_OPTION_PASSWORD:
2729 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2731 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2732 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2735 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2737 INTERNET_PER_CONN_OPTION_LISTW *listW;
2738 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
2739 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2740 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen );
2743 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2744 if (listA->pszConnection)
2746 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
2747 listW->pszConnection = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2748 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
2751 listW->pszConnection = NULL;
2752 listW->dwOptionCount = listA->dwOptionCount;
2753 listW->dwOptionError = listA->dwOptionError;
2754 listW->pOptions = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount );
2756 for (i = 0; i < listA->dwOptionCount; ++i) {
2757 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
2758 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
2760 optW->dwOption = optA->dwOption;
2762 switch (optA->dwOption) {
2763 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2764 case INTERNET_PER_CONN_PROXY_BYPASS:
2765 case INTERNET_PER_CONN_PROXY_SERVER:
2766 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2767 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2768 if (optA->Value.pszValue)
2770 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
2771 optW->Value.pszValue = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2772 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
2775 optW->Value.pszValue = NULL;
2777 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2778 case INTERNET_PER_CONN_FLAGS:
2779 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2780 optW->Value.dwValue = optA->Value.dwValue;
2782 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2783 optW->Value.ftValue = optA->Value.ftValue;
2785 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
2786 optW->Value.dwValue = optA->Value.dwValue;
2794 wlen = dwBufferLength;
2797 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2799 if( lpBuffer != wbuffer )
2801 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
2803 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
2805 for (i = 0; i < list->dwOptionCount; ++i) {
2806 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
2807 switch (opt->dwOption) {
2808 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2809 case INTERNET_PER_CONN_PROXY_BYPASS:
2810 case INTERNET_PER_CONN_PROXY_SERVER:
2811 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2812 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2813 HeapFree( GetProcessHeap(), 0, opt->Value.pszValue );
2819 HeapFree( GetProcessHeap(), 0, list->pOptions );
2821 HeapFree( GetProcessHeap(), 0, wbuffer );
2828 /***********************************************************************
2829 * InternetSetOptionExA (WININET.@)
2831 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2832 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2834 FIXME("Flags %08x ignored\n", dwFlags);
2835 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2838 /***********************************************************************
2839 * InternetSetOptionExW (WININET.@)
2841 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2842 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2844 FIXME("Flags %08x ignored\n", dwFlags);
2845 if( dwFlags & ~ISO_VALID_FLAGS )
2847 SetLastError( ERROR_INVALID_PARAMETER );
2850 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2853 static const WCHAR WININET_wkday[7][4] =
2854 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2855 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2856 static const WCHAR WININET_month[12][4] =
2857 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2858 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2859 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2861 /***********************************************************************
2862 * InternetTimeFromSystemTimeA (WININET.@)
2864 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2867 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2869 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2871 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2873 SetLastError(ERROR_INVALID_PARAMETER);
2877 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2879 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2883 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2884 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2889 /***********************************************************************
2890 * InternetTimeFromSystemTimeW (WININET.@)
2892 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2894 static const WCHAR date[] =
2895 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2896 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2898 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2900 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2902 SetLastError(ERROR_INVALID_PARAMETER);
2906 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2908 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2912 sprintfW( string, date,
2913 WININET_wkday[time->wDayOfWeek],
2915 WININET_month[time->wMonth - 1],
2924 /***********************************************************************
2925 * InternetTimeToSystemTimeA (WININET.@)
2927 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2932 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2934 stringW = heap_strdupAtoW(string);
2937 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2938 HeapFree( GetProcessHeap(), 0, stringW );
2943 /***********************************************************************
2944 * InternetTimeToSystemTimeW (WININET.@)
2946 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2949 const WCHAR *s = string;
2952 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2954 if (!string || !time) return FALSE;
2956 /* Windows does this too */
2957 GetSystemTime( time );
2959 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2960 * a SYSTEMTIME structure.
2963 while (*s && !isalphaW( *s )) s++;
2964 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2965 time->wDayOfWeek = 7;
2967 for (i = 0; i < 7; i++)
2969 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2970 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2971 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2973 time->wDayOfWeek = i;
2978 if (time->wDayOfWeek > 6) return TRUE;
2979 while (*s && !isdigitW( *s )) s++;
2980 time->wDay = strtolW( s, &end, 10 );
2983 while (*s && !isalphaW( *s )) s++;
2984 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2987 for (i = 0; i < 12; i++)
2989 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2990 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2991 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2993 time->wMonth = i + 1;
2997 if (time->wMonth == 0) return TRUE;
2999 while (*s && !isdigitW( *s )) s++;
3000 if (*s == '\0') return TRUE;
3001 time->wYear = strtolW( s, &end, 10 );
3004 while (*s && !isdigitW( *s )) s++;
3005 if (*s == '\0') return TRUE;
3006 time->wHour = strtolW( s, &end, 10 );
3009 while (*s && !isdigitW( *s )) s++;
3010 if (*s == '\0') return TRUE;
3011 time->wMinute = strtolW( s, &end, 10 );
3014 while (*s && !isdigitW( *s )) s++;
3015 if (*s == '\0') return TRUE;
3016 time->wSecond = strtolW( s, &end, 10 );
3019 time->wMilliseconds = 0;
3023 /***********************************************************************
3024 * InternetCheckConnectionW (WININET.@)
3026 * Pings a requested host to check internet connection
3029 * TRUE on success and FALSE on failure. If a failure then
3030 * ERROR_NOT_CONNECTED is placed into GetLastError
3033 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3036 * this is a kludge which runs the resident ping program and reads the output.
3038 * Anyone have a better idea?
3042 static const CHAR ping[] = "ping -c 1 ";
3043 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3044 CHAR *command = NULL;
3053 * Crack or set the Address
3055 if (lpszUrl == NULL)
3058 * According to the doc we are supposed to use the ip for the next
3059 * server in the WnInet internal server database. I have
3060 * no idea what that is or how to get it.
3062 * So someone needs to implement this.
3064 FIXME("Unimplemented with URL of NULL\n");
3069 URL_COMPONENTSW components;
3071 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3072 components.lpszHostName = (LPWSTR)hostW;
3073 components.dwHostNameLength = 1024;
3075 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3078 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3079 port = components.nPort;
3080 TRACE("port: %d\n", port);
3083 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3085 struct sockaddr_storage saddr;
3086 socklen_t sa_len = sizeof(saddr);
3089 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3091 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3094 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3102 * Build our ping command
3104 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3105 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
3106 strcpy(command,ping);
3107 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3108 strcat(command,redirect);
3110 TRACE("Ping command is : %s\n",command);
3112 status = system(command);
3114 TRACE("Ping returned a code of %i\n",status);
3116 /* Ping return code of 0 indicates success */
3123 HeapFree( GetProcessHeap(), 0, command );
3125 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3131 /***********************************************************************
3132 * InternetCheckConnectionA (WININET.@)
3134 * Pings a requested host to check internet connection
3137 * TRUE on success and FALSE on failure. If a failure then
3138 * ERROR_NOT_CONNECTED is placed into GetLastError
3141 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3147 url = heap_strdupAtoW(lpszUrl);
3152 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3154 HeapFree(GetProcessHeap(), 0, url);
3159 /**********************************************************
3160 * INTERNET_InternetOpenUrlW (internal)
3165 * handle of connection or NULL on failure
3167 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3168 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3170 URL_COMPONENTSW urlComponents;
3171 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
3172 WCHAR password[1024], path[2048], extra[1024];
3173 HINTERNET client = NULL, client1 = NULL;
3176 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3177 dwHeadersLength, dwFlags, dwContext);
3179 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3180 urlComponents.lpszScheme = protocol;
3181 urlComponents.dwSchemeLength = 32;
3182 urlComponents.lpszHostName = hostName;
3183 urlComponents.dwHostNameLength = MAXHOSTNAME;
3184 urlComponents.lpszUserName = userName;
3185 urlComponents.dwUserNameLength = 1024;
3186 urlComponents.lpszPassword = password;
3187 urlComponents.dwPasswordLength = 1024;
3188 urlComponents.lpszUrlPath = path;
3189 urlComponents.dwUrlPathLength = 2048;
3190 urlComponents.lpszExtraInfo = extra;
3191 urlComponents.dwExtraInfoLength = 1024;
3192 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3194 switch(urlComponents.nScheme) {
3195 case INTERNET_SCHEME_FTP:
3196 if(urlComponents.nPort == 0)
3197 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3198 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3199 userName, password, dwFlags, dwContext, INET_OPENURL);
3202 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3203 if(client1 == NULL) {
3204 InternetCloseHandle(client);
3209 case INTERNET_SCHEME_HTTP:
3210 case INTERNET_SCHEME_HTTPS: {
3211 static const WCHAR szStars[] = { '*','/','*', 0 };
3212 LPCWSTR accept[2] = { szStars, NULL };
3213 if(urlComponents.nPort == 0) {
3214 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3215 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3217 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3219 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3221 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3222 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3223 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3224 if(res != ERROR_SUCCESS) {
3225 INTERNET_SetLastError(res);
3229 if (urlComponents.dwExtraInfoLength) {
3231 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3233 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
3235 InternetCloseHandle(client);
3238 strcpyW(path_extra, urlComponents.lpszUrlPath);
3239 strcatW(path_extra, urlComponents.lpszExtraInfo);
3240 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3241 HeapFree(GetProcessHeap(), 0, path_extra);
3244 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3246 if(client1 == NULL) {
3247 InternetCloseHandle(client);
3250 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3251 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3252 GetLastError() != ERROR_IO_PENDING) {
3253 InternetCloseHandle(client1);
3258 case INTERNET_SCHEME_GOPHER:
3259 /* gopher doesn't seem to be implemented in wine, but it's supposed
3260 * to be supported by InternetOpenUrlA. */
3262 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3266 TRACE(" %p <--\n", client1);
3271 /**********************************************************
3272 * InternetOpenUrlW (WININET.@)
3277 * handle of connection or NULL on failure
3279 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3281 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3282 appinfo_t *hIC = (appinfo_t*) workRequest->hdr;
3286 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3287 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3288 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3289 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3292 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3293 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3295 HINTERNET ret = NULL;
3296 appinfo_t *hIC = NULL;
3298 if (TRACE_ON(wininet)) {
3299 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3300 dwHeadersLength, dwFlags, dwContext);
3302 dump_INTERNET_FLAGS(dwFlags);
3307 SetLastError(ERROR_INVALID_PARAMETER);
3311 hIC = (appinfo_t*)WININET_GetObject( hInternet );
3312 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3313 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3317 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3318 WORKREQUEST workRequest;
3319 struct WORKREQ_INTERNETOPENURLW *req;
3321 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3322 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3323 req = &workRequest.u.InternetOpenUrlW;
3324 req->lpszUrl = heap_strdupW(lpszUrl);
3325 req->lpszHeaders = heap_strdupW(lpszHeaders);
3326 req->dwHeadersLength = dwHeadersLength;
3327 req->dwFlags = dwFlags;
3328 req->dwContext = dwContext;
3330 INTERNET_AsyncCall(&workRequest);
3332 * This is from windows.
3334 SetLastError(ERROR_IO_PENDING);
3336 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3341 WININET_Release( &hIC->hdr );
3342 TRACE(" %p <--\n", ret);
3347 /**********************************************************
3348 * InternetOpenUrlA (WININET.@)
3353 * handle of connection or NULL on failure
3355 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3356 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3358 HINTERNET rc = NULL;
3359 DWORD lenHeaders = 0;
3360 LPWSTR szUrl = NULL;
3361 LPWSTR szHeaders = NULL;
3366 szUrl = heap_strdupAtoW(lpszUrl);
3372 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3373 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3375 HeapFree(GetProcessHeap(), 0, szUrl);
3378 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3381 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3382 lenHeaders, dwFlags, dwContext);
3384 HeapFree(GetProcessHeap(), 0, szUrl);
3385 HeapFree(GetProcessHeap(), 0, szHeaders);
3391 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3393 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3397 lpwite->dwError = 0;
3398 lpwite->response[0] = '\0';
3401 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3403 HeapFree(GetProcessHeap(), 0, lpwite);
3411 /***********************************************************************
3412 * INTERNET_SetLastError (internal)
3414 * Set last thread specific error
3419 void INTERNET_SetLastError(DWORD dwError)
3421 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3424 lpwite = INTERNET_AllocThreadError();
3426 SetLastError(dwError);
3428 lpwite->dwError = dwError;
3432 /***********************************************************************
3433 * INTERNET_GetLastError (internal)
3435 * Get last thread specific error
3440 DWORD INTERNET_GetLastError(void)
3442 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3443 if (!lpwite) return 0;
3444 /* TlsGetValue clears last error, so set it again here */
3445 SetLastError(lpwite->dwError);
3446 return lpwite->dwError;
3450 /***********************************************************************
3451 * INTERNET_WorkerThreadFunc (internal)
3453 * Worker thread execution function
3458 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3460 LPWORKREQUEST lpRequest = lpvParam;
3461 WORKREQUEST workRequest;
3465 workRequest = *lpRequest;
3466 HeapFree(GetProcessHeap(), 0, lpRequest);
3468 workRequest.asyncproc(&workRequest);
3469 WININET_Release( workRequest.hdr );
3471 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3473 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
3474 TlsSetValue(g_dwTlsErrIndex, NULL);
3480 /***********************************************************************
3481 * INTERNET_AsyncCall (internal)
3483 * Retrieves work request from queue
3488 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3491 LPWORKREQUEST lpNewRequest;
3495 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3497 return ERROR_OUTOFMEMORY;
3499 *lpNewRequest = *lpWorkRequest;
3501 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3504 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3505 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3508 return ERROR_SUCCESS;
3512 /***********************************************************************
3513 * INTERNET_GetResponseBuffer (internal)
3518 LPSTR INTERNET_GetResponseBuffer(void)
3520 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3522 lpwite = INTERNET_AllocThreadError();
3524 return lpwite->response;
3527 /***********************************************************************
3528 * INTERNET_GetNextLine (internal)
3530 * Parse next line in directory string listing
3533 * Pointer to beginning of next line
3538 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3541 BOOL bSuccess = FALSE;
3543 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3548 pfd.events = POLLIN;
3550 while (nRecv < MAX_REPLY_LEN)
3552 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3554 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3556 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3560 if (lpszBuffer[nRecv] == '\n')
3565 if (lpszBuffer[nRecv] != '\r')
3570 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3578 lpszBuffer[nRecv] = '\0';
3580 TRACE(":%d %s\n", nRecv, lpszBuffer);
3589 /**********************************************************
3590 * InternetQueryDataAvailable (WININET.@)
3592 * Determines how much data is available to be read.
3595 * TRUE on success, FALSE if an error occurred. If
3596 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3597 * no data is presently available, FALSE is returned with
3598 * the last error ERROR_IO_PENDING; a callback with status
3599 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3600 * data is available.
3602 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3603 LPDWORD lpdwNumberOfBytesAvailble,
3604 DWORD dwFlags, DWORD_PTR dwContext)
3606 object_header_t *hdr;
3609 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3611 hdr = WININET_GetObject( hFile );
3613 SetLastError(ERROR_INVALID_HANDLE);
3617 if(hdr->vtbl->QueryDataAvailable) {
3618 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3620 WARN("wrong handle\n");
3621 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3624 WININET_Release(hdr);
3626 if(res != ERROR_SUCCESS)
3628 return res == ERROR_SUCCESS;
3632 /***********************************************************************
3633 * InternetLockRequestFile (WININET.@)
3635 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3642 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3649 /***********************************************************************
3650 * InternetAutodial (WININET.@)
3652 * On windows this function is supposed to dial the default internet
3653 * connection. We don't want to have Wine dial out to the internet so
3654 * we return TRUE by default. It might be nice to check if we are connected.
3661 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3665 /* Tell that we are connected to the internet. */
3669 /***********************************************************************
3670 * InternetAutodialHangup (WININET.@)
3672 * Hangs up a connection made with InternetAutodial
3681 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3685 /* we didn't dial, we don't disconnect */
3689 /***********************************************************************
3690 * InternetCombineUrlA (WININET.@)
3692 * Combine a base URL with a relative URL
3700 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3701 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3706 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3708 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3709 dwFlags ^= ICU_NO_ENCODE;
3710 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3715 /***********************************************************************
3716 * InternetCombineUrlW (WININET.@)
3718 * Combine a base URL with a relative URL
3726 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3727 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3732 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3734 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3735 dwFlags ^= ICU_NO_ENCODE;
3736 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3741 /* max port num is 65535 => 5 digits */
3742 #define MAX_WORD_DIGITS 5
3744 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3745 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3746 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3747 (url)->dw##component##Length : strlen((url)->lpsz##component))
3749 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3751 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3752 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3754 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3755 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3757 if ((nScheme == INTERNET_SCHEME_FTP) &&
3758 (nPort == INTERNET_DEFAULT_FTP_PORT))
3760 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3761 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3764 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3770 /* opaque urls do not fit into the standard url hierarchy and don't have
3771 * two following slashes */
3772 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3774 return (nScheme != INTERNET_SCHEME_FTP) &&
3775 (nScheme != INTERNET_SCHEME_GOPHER) &&
3776 (nScheme != INTERNET_SCHEME_HTTP) &&
3777 (nScheme != INTERNET_SCHEME_HTTPS) &&
3778 (nScheme != INTERNET_SCHEME_FILE);
3781 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3784 if (scheme < INTERNET_SCHEME_FIRST)
3786 index = scheme - INTERNET_SCHEME_FIRST;
3787 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3789 return (LPCWSTR)url_schemes[index];
3792 /* we can calculate using ansi strings because we're just
3793 * calculating string length, not size
3795 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3796 LPDWORD lpdwUrlLength)
3798 INTERNET_SCHEME nScheme;
3802 if (lpUrlComponents->lpszScheme)
3804 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3805 *lpdwUrlLength += dwLen;
3806 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3812 nScheme = lpUrlComponents->nScheme;
3814 if (nScheme == INTERNET_SCHEME_DEFAULT)
3815 nScheme = INTERNET_SCHEME_HTTP;
3816 scheme = INTERNET_GetSchemeString(nScheme);
3817 *lpdwUrlLength += strlenW(scheme);
3820 (*lpdwUrlLength)++; /* ':' */
3821 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3822 *lpdwUrlLength += strlen("//");
3824 if (lpUrlComponents->lpszUserName)
3826 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3827 *lpdwUrlLength += strlen("@");
3831 if (lpUrlComponents->lpszPassword)
3833 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3838 if (lpUrlComponents->lpszPassword)
3840 *lpdwUrlLength += strlen(":");
3841 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3844 if (lpUrlComponents->lpszHostName)
3846 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3848 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3850 char szPort[MAX_WORD_DIGITS+1];
3852 sprintf(szPort, "%d", lpUrlComponents->nPort);
3853 *lpdwUrlLength += strlen(szPort);
3854 *lpdwUrlLength += strlen(":");
3857 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3858 (*lpdwUrlLength)++; /* '/' */
3861 if (lpUrlComponents->lpszUrlPath)
3862 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3864 if (lpUrlComponents->lpszExtraInfo)
3865 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3870 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3874 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3876 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3877 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3878 urlCompW->nScheme = lpUrlComponents->nScheme;
3879 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3880 urlCompW->nPort = lpUrlComponents->nPort;
3881 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3882 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3883 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3884 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3886 if (lpUrlComponents->lpszScheme)
3888 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3889 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3890 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3891 -1, urlCompW->lpszScheme, len);
3894 if (lpUrlComponents->lpszHostName)
3896 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3897 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3898 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3899 -1, urlCompW->lpszHostName, len);
3902 if (lpUrlComponents->lpszUserName)
3904 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3905 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3906 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3907 -1, urlCompW->lpszUserName, len);
3910 if (lpUrlComponents->lpszPassword)
3912 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3913 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3914 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3915 -1, urlCompW->lpszPassword, len);
3918 if (lpUrlComponents->lpszUrlPath)
3920 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3921 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3922 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3923 -1, urlCompW->lpszUrlPath, len);
3926 if (lpUrlComponents->lpszExtraInfo)
3928 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3929 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3930 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3931 -1, urlCompW->lpszExtraInfo, len);
3935 /***********************************************************************
3936 * InternetCreateUrlA (WININET.@)
3938 * See InternetCreateUrlW.
3940 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3941 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3945 URL_COMPONENTSW urlCompW;
3947 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3949 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3951 SetLastError(ERROR_INVALID_PARAMETER);
3955 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3958 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3960 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3962 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3963 *lpdwUrlLength /= sizeof(WCHAR);
3965 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3966 * minus one, so add one to leave room for NULL terminator
3969 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3971 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3972 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3973 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3974 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3975 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3976 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3977 HeapFree(GetProcessHeap(), 0, urlW);
3982 /***********************************************************************
3983 * InternetCreateUrlW (WININET.@)
3985 * Creates a URL from its component parts.
3988 * lpUrlComponents [I] URL Components.
3989 * dwFlags [I] Flags. See notes.
3990 * lpszUrl [I] Buffer in which to store the created URL.
3991 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3992 * lpszUrl in characters. On output, the number of bytes
3993 * required to store the URL including terminator.
3997 * The dwFlags parameter can be zero or more of the following:
3998 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4005 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4006 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4009 INTERNET_SCHEME nScheme;
4011 static const WCHAR slashSlashW[] = {'/','/'};
4012 static const WCHAR percentD[] = {'%','d',0};
4014 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4016 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4018 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4022 if (!calc_url_length(lpUrlComponents, &dwLen))
4025 if (!lpszUrl || *lpdwUrlLength < dwLen)
4027 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4028 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4032 *lpdwUrlLength = dwLen;
4037 if (lpUrlComponents->lpszScheme)
4039 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4040 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4043 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4048 nScheme = lpUrlComponents->nScheme;
4050 if (nScheme == INTERNET_SCHEME_DEFAULT)
4051 nScheme = INTERNET_SCHEME_HTTP;
4053 scheme = INTERNET_GetSchemeString(nScheme);
4054 dwLen = strlenW(scheme);
4055 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4059 /* all schemes are followed by at least a colon */
4063 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4065 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4066 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4069 if (lpUrlComponents->lpszUserName)
4071 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4072 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4075 if (lpUrlComponents->lpszPassword)
4080 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4081 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4089 if (lpUrlComponents->lpszHostName)
4091 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4092 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4095 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4097 WCHAR szPort[MAX_WORD_DIGITS+1];
4099 sprintfW(szPort, percentD, lpUrlComponents->nPort);
4102 dwLen = strlenW(szPort);
4103 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4107 /* add slash between hostname and path if necessary */
4108 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4115 if (lpUrlComponents->lpszUrlPath)
4117 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4118 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4122 if (lpUrlComponents->lpszExtraInfo)
4124 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4125 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4134 /***********************************************************************
4135 * InternetConfirmZoneCrossingA (WININET.@)
4138 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4140 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4141 return ERROR_SUCCESS;
4144 /***********************************************************************
4145 * InternetConfirmZoneCrossingW (WININET.@)
4148 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4150 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4151 return ERROR_SUCCESS;
4154 static DWORD zone_preference = 3;
4156 /***********************************************************************
4157 * PrivacySetZonePreferenceW (WININET.@)
4159 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4161 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4163 zone_preference = template;
4167 /***********************************************************************
4168 * PrivacyGetZonePreferenceW (WININET.@)
4170 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4171 LPWSTR preference, LPDWORD length )
4173 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4175 if (template) *template = zone_preference;
4179 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4180 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4182 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4183 lpdwConnection, dwReserved);
4184 return ERROR_SUCCESS;
4187 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4188 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4190 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4191 lpdwConnection, dwReserved);
4192 return ERROR_SUCCESS;
4195 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4197 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4201 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4203 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4207 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4209 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4210 return ERROR_SUCCESS;
4213 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4216 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4217 debugstr_w(pwszTarget), pbHexHash);
4221 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4223 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4227 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4229 FIXME("(%p, %08lx) stub\n", a, b);