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 HMODULE WININET_hModule;
93 static CRITICAL_SECTION WININET_cs;
94 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
97 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
98 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
100 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
102 static object_header_t **handle_table;
103 static UINT_PTR next_handle;
104 static UINT_PTR handle_table_size;
108 DWORD dwProxyEnabled;
109 LPWSTR lpszProxyServer;
110 LPWSTR lpszProxyBypass;
113 static const WCHAR szInternetSettings[] =
114 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
115 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
116 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
117 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
118 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
120 void *alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
122 UINT_PTR handle = 0, num;
123 object_header_t *ret;
127 ret = heap_alloc_zero(size);
131 list_init(&ret->children);
133 EnterCriticalSection( &WININET_cs );
135 if(!handle_table_size) {
137 p = heap_alloc_zero(sizeof(handle_table[0]) * num);
140 handle_table_size = num;
145 }else if(next_handle == handle_table_size) {
146 num = handle_table_size * 2;
147 p = heap_realloc_zero(handle_table, sizeof(handle_table[0]) * num);
150 handle_table_size = num;
157 handle = next_handle;
158 if(handle_table[handle])
159 ERR("handle isn't free but should be\n");
160 handle_table[handle] = ret;
161 ret->valid_handle = TRUE;
163 while(handle_table[next_handle] && next_handle < handle_table_size)
167 LeaveCriticalSection( &WININET_cs );
176 ret->hInternet = (HINTERNET)handle;
179 ret->lpfnStatusCB = parent->lpfnStatusCB;
180 ret->dwInternalFlags = parent->dwInternalFlags & INET_CALLBACKW;
186 object_header_t *WININET_AddRef( object_header_t *info )
188 ULONG refs = InterlockedIncrement(&info->refs);
189 TRACE("%p -> refcount = %d\n", info, refs );
193 object_header_t *get_handle_object( HINTERNET hinternet )
195 object_header_t *info = NULL;
196 UINT_PTR handle = (UINT_PTR) hinternet;
198 EnterCriticalSection( &WININET_cs );
200 if(handle > 0 && handle < handle_table_size && handle_table[handle] && handle_table[handle]->valid_handle)
201 info = WININET_AddRef(handle_table[handle]);
203 LeaveCriticalSection( &WININET_cs );
205 TRACE("handle %ld -> %p\n", handle, info);
210 static void invalidate_handle(object_header_t *info)
212 object_header_t *child, *next;
214 if(!info->valid_handle)
216 info->valid_handle = FALSE;
218 /* Free all children as native does */
219 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
221 TRACE("invalidating child handle %p for parent %p\n", child->hInternet, info);
222 invalidate_handle( child );
225 WININET_Release(info);
228 BOOL WININET_Release( object_header_t *info )
230 ULONG refs = InterlockedDecrement(&info->refs);
231 TRACE( "object %p refcount = %d\n", info, refs );
234 invalidate_handle(info);
235 if ( info->vtbl->CloseConnection )
237 TRACE( "closing connection %p\n", info);
238 info->vtbl->CloseConnection( info );
240 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
241 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
242 || !(info->dwInternalFlags & INET_OPENURL))
244 INTERNET_SendCallback(info, info->dwContext,
245 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
248 TRACE( "destroying object %p\n", info);
249 if ( info->htype != WH_HINIT )
250 list_remove( &info->entry );
251 info->vtbl->Destroy( info );
253 if(info->hInternet) {
254 UINT_PTR handle = (UINT_PTR)info->hInternet;
256 EnterCriticalSection( &WININET_cs );
258 handle_table[handle] = NULL;
259 if(next_handle > handle)
260 next_handle = handle;
262 LeaveCriticalSection( &WININET_cs );
270 /***********************************************************************
271 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
274 * hinstDLL [I] handle to the DLL's instance
276 * lpvReserved [I] reserved, must be NULL
283 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
285 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
288 case DLL_PROCESS_ATTACH:
290 g_dwTlsErrIndex = TlsAlloc();
292 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
295 URLCacheContainers_CreateDefaults();
297 WININET_hModule = hinstDLL;
299 case DLL_THREAD_ATTACH:
302 case DLL_THREAD_DETACH:
303 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
305 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
306 HeapFree(GetProcessHeap(), 0, lpwite);
310 case DLL_PROCESS_DETACH:
314 URLCacheContainers_DeleteAll();
316 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
318 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
319 TlsFree(g_dwTlsErrIndex);
327 /***********************************************************************
328 * INTERNET_SaveProxySettings
330 * Stores the proxy settings given by lpwai into the registry
333 * ERROR_SUCCESS if no error, or error code on fail
335 static LONG INTERNET_SaveProxySettings( proxyinfo_t *lpwpi )
340 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
343 if ((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE*)&lpwpi->dwProxyEnabled, sizeof(DWORD))))
349 if (lpwpi->lpszProxyServer)
351 if ((ret = RegSetValueExW( key, szProxyServer, 0, REG_SZ, (BYTE*)lpwpi->lpszProxyServer, sizeof(WCHAR) * (lstrlenW(lpwpi->lpszProxyServer) + 1))))
359 if ((ret = RegDeleteValueW( key, szProxyServer )))
367 return ERROR_SUCCESS;
370 /***********************************************************************
371 * INTERNET_FindProxyForProtocol
373 * Searches the proxy string for a proxy of the given protocol.
374 * Returns the found proxy, or the default proxy if none of the given
378 * szProxy [In] proxy string to search
379 * proto [In] protocol to search for, e.g. "http"
380 * foundProxy [Out] found proxy
381 * foundProxyLen [In/Out] length of foundProxy buffer, in WCHARs
384 * TRUE if a proxy is found, FALSE if not. If foundProxy is too short,
385 * *foundProxyLen is set to the required size in WCHARs, including the
386 * NULL terminator, and the last error is set to ERROR_INSUFFICIENT_BUFFER.
388 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen)
393 TRACE("(%s, %s)\n", debugstr_w(szProxy), debugstr_w(proto));
395 /* First, look for the specified protocol (proto=scheme://host:port) */
396 for (ptr = szProxy; !ret && ptr && *ptr; )
400 if (!(end = strchrW(ptr, ' ')))
401 end = ptr + strlenW(ptr);
402 if ((equal = strchrW(ptr, '=')) && equal < end &&
403 equal - ptr == strlenW(proto) &&
404 !strncmpiW(proto, ptr, strlenW(proto)))
406 if (end - equal > *foundProxyLen)
408 WARN("buffer too short for %s\n",
409 debugstr_wn(equal + 1, end - equal - 1));
410 *foundProxyLen = end - equal;
411 SetLastError(ERROR_INSUFFICIENT_BUFFER);
415 memcpy(foundProxy, equal + 1, (end - equal) * sizeof(WCHAR));
416 foundProxy[end - equal] = 0;
427 /* It wasn't found: look for no protocol */
428 for (ptr = szProxy; !ret && ptr && *ptr; )
432 if (!(end = strchrW(ptr, ' ')))
433 end = ptr + strlenW(ptr);
434 if (!(equal = strchrW(ptr, '=')))
436 if (end - ptr + 1 > *foundProxyLen)
438 WARN("buffer too short for %s\n",
439 debugstr_wn(ptr, end - ptr));
440 *foundProxyLen = end - ptr + 1;
441 SetLastError(ERROR_INSUFFICIENT_BUFFER);
445 memcpy(foundProxy, ptr, (end - ptr) * sizeof(WCHAR));
446 foundProxy[end - ptr] = 0;
457 TRACE("found proxy for %s: %s\n", debugstr_w(proto),
458 debugstr_w(foundProxy));
462 /***********************************************************************
463 * InternetInitializeAutoProxyDll (WININET.@)
465 * Setup the internal proxy
474 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
477 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
481 /***********************************************************************
482 * DetectAutoProxyUrl (WININET.@)
484 * Auto detect the proxy url
490 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
491 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
494 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
498 static void FreeProxyInfo( proxyinfo_t *lpwpi )
500 HeapFree(GetProcessHeap(), 0, lpwpi->lpszProxyServer);
501 HeapFree(GetProcessHeap(), 0, lpwpi->lpszProxyBypass);
504 /***********************************************************************
505 * INTERNET_LoadProxySettings
507 * Loads proxy information from the registry or environment into lpwpi.
509 * The caller should call FreeProxyInfo when done with lpwpi.
512 * The proxy may be specified in the form 'http=proxy.my.org'
513 * Presumably that means there can be ftp=ftpproxy.my.org too.
515 static LONG INTERNET_LoadProxySettings( proxyinfo_t *lpwpi )
522 if ((ret = RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )))
526 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&lpwpi->dwProxyEnabled, &len ) || type != REG_DWORD)
528 lpwpi->dwProxyEnabled = 0;
529 if((ret = RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&lpwpi->dwProxyEnabled, sizeof(DWORD) )))
536 if (!(envproxy = getenv( "http_proxy" )) || lpwpi->dwProxyEnabled)
538 TRACE("Proxy is enabled.\n");
540 /* figure out how much memory the proxy setting takes */
541 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
544 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
546 if (!(szProxy = HeapAlloc( GetProcessHeap(), 0, len )))
549 return ERROR_OUTOFMEMORY;
551 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
553 /* find the http proxy, and strip away everything else */
554 p = strstrW( szProxy, szHttp );
557 p += lstrlenW( szHttp );
558 lstrcpyW( szProxy, p );
560 p = strchrW( szProxy, ' ' );
563 lpwpi->lpszProxyServer = szProxy;
565 TRACE("http proxy = %s\n", debugstr_w(lpwpi->lpszProxyServer));
569 TRACE("No proxy server settings in registry.\n");
570 lpwpi->lpszProxyServer = NULL;
577 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
578 if (!(envproxyW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR))))
579 return ERROR_OUTOFMEMORY;
580 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
582 lpwpi->dwProxyEnabled = 1;
583 lpwpi->lpszProxyServer = envproxyW;
585 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwpi->lpszProxyServer));
589 lpwpi->lpszProxyBypass = NULL;
591 return ERROR_SUCCESS;
594 /***********************************************************************
595 * INTERNET_ConfigureProxy
597 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
601 if (INTERNET_LoadProxySettings( &wpi ))
604 if (wpi.dwProxyEnabled)
606 lpwai->accessType = INTERNET_OPEN_TYPE_PROXY;
607 lpwai->proxy = wpi.lpszProxyServer;
611 lpwai->accessType = INTERNET_OPEN_TYPE_DIRECT;
615 /***********************************************************************
616 * dump_INTERNET_FLAGS
618 * Helper function to TRACE the internet flags.
624 static void dump_INTERNET_FLAGS(DWORD dwFlags)
626 #define FE(x) { x, #x }
627 static const wininet_flag_info flag[] = {
628 FE(INTERNET_FLAG_RELOAD),
629 FE(INTERNET_FLAG_RAW_DATA),
630 FE(INTERNET_FLAG_EXISTING_CONNECT),
631 FE(INTERNET_FLAG_ASYNC),
632 FE(INTERNET_FLAG_PASSIVE),
633 FE(INTERNET_FLAG_NO_CACHE_WRITE),
634 FE(INTERNET_FLAG_MAKE_PERSISTENT),
635 FE(INTERNET_FLAG_FROM_CACHE),
636 FE(INTERNET_FLAG_SECURE),
637 FE(INTERNET_FLAG_KEEP_CONNECTION),
638 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
639 FE(INTERNET_FLAG_READ_PREFETCH),
640 FE(INTERNET_FLAG_NO_COOKIES),
641 FE(INTERNET_FLAG_NO_AUTH),
642 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
643 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
644 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
645 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
646 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
647 FE(INTERNET_FLAG_RESYNCHRONIZE),
648 FE(INTERNET_FLAG_HYPERLINK),
649 FE(INTERNET_FLAG_NO_UI),
650 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
651 FE(INTERNET_FLAG_CACHE_ASYNC),
652 FE(INTERNET_FLAG_FORMS_SUBMIT),
653 FE(INTERNET_FLAG_NEED_FILE),
654 FE(INTERNET_FLAG_TRANSFER_ASCII),
655 FE(INTERNET_FLAG_TRANSFER_BINARY)
660 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
661 if (flag[i].val & dwFlags) {
662 TRACE(" %s", flag[i].name);
663 dwFlags &= ~flag[i].val;
667 TRACE(" Unknown flags (%08x)\n", dwFlags);
672 /***********************************************************************
673 * INTERNET_CloseHandle (internal)
675 * Close internet handle
678 static VOID APPINFO_Destroy(object_header_t *hdr)
680 appinfo_t *lpwai = (appinfo_t*)hdr;
684 HeapFree(GetProcessHeap(), 0, lpwai->agent);
685 HeapFree(GetProcessHeap(), 0, lpwai->proxy);
686 HeapFree(GetProcessHeap(), 0, lpwai->proxyBypass);
687 HeapFree(GetProcessHeap(), 0, lpwai->proxyUsername);
688 HeapFree(GetProcessHeap(), 0, lpwai->proxyPassword);
691 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
693 appinfo_t *ai = (appinfo_t*)hdr;
696 case INTERNET_OPTION_HANDLE_TYPE:
697 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
699 if (*size < sizeof(ULONG))
700 return ERROR_INSUFFICIENT_BUFFER;
702 *size = sizeof(DWORD);
703 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
704 return ERROR_SUCCESS;
706 case INTERNET_OPTION_USER_AGENT: {
709 TRACE("INTERNET_OPTION_USER_AGENT\n");
714 DWORD len = ai->agent ? strlenW(ai->agent) : 0;
716 *size = (len + 1) * sizeof(WCHAR);
717 if(!buffer || bufsize < *size)
718 return ERROR_INSUFFICIENT_BUFFER;
721 strcpyW(buffer, ai->agent);
723 *(WCHAR *)buffer = 0;
724 /* If the buffer is copied, the returned length doesn't include
725 * the NULL terminator.
727 *size = len * sizeof(WCHAR);
730 *size = WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, NULL, 0, NULL, NULL);
733 if(!buffer || bufsize < *size)
734 return ERROR_INSUFFICIENT_BUFFER;
737 WideCharToMultiByte(CP_ACP, 0, ai->agent, -1, buffer, *size, NULL, NULL);
740 /* If the buffer is copied, the returned length doesn't include
741 * the NULL terminator.
746 return ERROR_SUCCESS;
749 case INTERNET_OPTION_PROXY:
751 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
752 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
753 LPWSTR proxy, proxy_bypass;
756 proxyBytesRequired = (lstrlenW(ai->proxy) + 1) * sizeof(WCHAR);
758 proxyBypassBytesRequired = (lstrlenW(ai->proxyBypass) + 1) * sizeof(WCHAR);
759 if (*size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
761 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
762 return ERROR_INSUFFICIENT_BUFFER;
764 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
765 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
767 pi->dwAccessType = ai->accessType;
768 pi->lpszProxy = NULL;
769 pi->lpszProxyBypass = NULL;
771 lstrcpyW(proxy, ai->proxy);
772 pi->lpszProxy = proxy;
775 if (ai->proxyBypass) {
776 lstrcpyW(proxy_bypass, ai->proxyBypass);
777 pi->lpszProxyBypass = proxy_bypass;
780 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
781 return ERROR_SUCCESS;
783 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
784 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
785 LPSTR proxy, proxy_bypass;
788 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, NULL, 0, NULL, NULL);
790 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1,
791 NULL, 0, NULL, NULL);
792 if (*size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
794 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
795 return ERROR_INSUFFICIENT_BUFFER;
797 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
798 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
800 pi->dwAccessType = ai->accessType;
801 pi->lpszProxy = NULL;
802 pi->lpszProxyBypass = NULL;
804 WideCharToMultiByte(CP_ACP, 0, ai->proxy, -1, proxy, proxyBytesRequired, NULL, NULL);
805 pi->lpszProxy = proxy;
808 if (ai->proxyBypass) {
809 WideCharToMultiByte(CP_ACP, 0, ai->proxyBypass, -1, proxy_bypass,
810 proxyBypassBytesRequired, NULL, NULL);
811 pi->lpszProxyBypass = proxy_bypass;
814 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
815 return ERROR_SUCCESS;
819 return INET_QueryOption(hdr, option, buffer, size, unicode);
822 static const object_vtbl_t APPINFOVtbl = {
835 /***********************************************************************
836 * InternetOpenW (WININET.@)
838 * Per-application initialization of wininet
841 * HINTERNET on success
845 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
846 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
848 appinfo_t *lpwai = NULL;
850 if (TRACE_ON(wininet)) {
851 #define FE(x) { x, #x }
852 static const wininet_flag_info access_type[] = {
853 FE(INTERNET_OPEN_TYPE_PRECONFIG),
854 FE(INTERNET_OPEN_TYPE_DIRECT),
855 FE(INTERNET_OPEN_TYPE_PROXY),
856 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
860 const char *access_type_str = "Unknown";
862 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
863 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
864 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
865 if (access_type[i].val == dwAccessType) {
866 access_type_str = access_type[i].name;
870 TRACE(" access type : %s\n", access_type_str);
872 dump_INTERNET_FLAGS(dwFlags);
875 /* Clear any error information */
876 INTERNET_SetLastError(0);
878 lpwai = alloc_object(NULL, &APPINFOVtbl, sizeof(appinfo_t));
880 SetLastError(ERROR_OUTOFMEMORY);
884 lpwai->hdr.htype = WH_HINIT;
885 lpwai->hdr.dwFlags = dwFlags;
886 lpwai->accessType = dwAccessType;
887 lpwai->proxyUsername = NULL;
888 lpwai->proxyPassword = NULL;
890 lpwai->agent = heap_strdupW(lpszAgent);
891 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
892 INTERNET_ConfigureProxy( lpwai );
894 lpwai->proxy = heap_strdupW(lpszProxy);
895 lpwai->proxyBypass = heap_strdupW(lpszProxyBypass);
897 TRACE("returning %p\n", lpwai);
899 return lpwai->hdr.hInternet;
903 /***********************************************************************
904 * InternetOpenA (WININET.@)
906 * Per-application initialization of wininet
909 * HINTERNET on success
913 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
914 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
916 WCHAR *szAgent, *szProxy, *szBypass;
919 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
920 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
922 szAgent = heap_strdupAtoW(lpszAgent);
923 szProxy = heap_strdupAtoW(lpszProxy);
924 szBypass = heap_strdupAtoW(lpszProxyBypass);
926 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
928 HeapFree(GetProcessHeap(), 0, szAgent);
929 HeapFree(GetProcessHeap(), 0, szProxy);
930 HeapFree(GetProcessHeap(), 0, szBypass);
935 /***********************************************************************
936 * InternetGetLastResponseInfoA (WININET.@)
938 * Return last wininet error description on the calling thread
941 * TRUE on success of writing to buffer
945 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
946 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
948 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
954 *lpdwError = lpwite->dwError;
957 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
958 *lpdwBufferLength = strlen(lpszBuffer);
961 *lpdwBufferLength = 0;
966 *lpdwBufferLength = 0;
972 /***********************************************************************
973 * InternetGetLastResponseInfoW (WININET.@)
975 * Return last wininet error description on the calling thread
978 * TRUE on success of writing to buffer
982 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
983 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
985 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
991 *lpdwError = lpwite->dwError;
994 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
995 *lpdwBufferLength = lstrlenW(lpszBuffer);
998 *lpdwBufferLength = 0;
1003 *lpdwBufferLength = 0;
1009 /***********************************************************************
1010 * InternetGetConnectedState (WININET.@)
1012 * Return connected state
1016 * if lpdwStatus is not null, return the status (off line,
1017 * modem, lan...) in it.
1018 * FALSE if not connected
1020 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
1022 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
1025 WARN("always returning LAN connection.\n");
1026 *lpdwStatus = INTERNET_CONNECTION_LAN;
1032 /***********************************************************************
1033 * InternetGetConnectedStateExW (WININET.@)
1035 * Return connected state
1039 * lpdwStatus [O] Flags specifying the status of the internet connection.
1040 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
1041 * dwNameLen [I] Size of the buffer, in characters.
1042 * dwReserved [I] Reserved. Must be set to 0.
1046 * if lpdwStatus is not null, return the status (off line,
1047 * modem, lan...) in it.
1048 * FALSE if not connected
1051 * If the system has no available network connections, an empty string is
1052 * stored in lpszConnectionName. If there is a LAN connection, a localized
1053 * "LAN Connection" string is stored. Presumably, if only a dial-up
1054 * connection is available then the name of the dial-up connection is
1055 * returned. Why any application, other than the "Internet Settings" CPL,
1056 * would want to use this function instead of the simpler InternetGetConnectedStateW
1057 * function is beyond me.
1059 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
1060 DWORD dwNameLen, DWORD dwReserved)
1062 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1069 WARN("always returning LAN connection.\n");
1070 *lpdwStatus = INTERNET_CONNECTION_LAN;
1072 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
1076 /***********************************************************************
1077 * InternetGetConnectedStateExA (WININET.@)
1079 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
1080 DWORD dwNameLen, DWORD dwReserved)
1082 LPWSTR lpwszConnectionName = NULL;
1085 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
1087 if (lpszConnectionName && dwNameLen > 0)
1088 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
1090 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
1092 if (rc && lpwszConnectionName)
1094 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
1095 dwNameLen, NULL, NULL);
1097 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
1104 /***********************************************************************
1105 * InternetConnectW (WININET.@)
1107 * Open a ftp, gopher or http session
1110 * HINTERNET a session handle on success
1114 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
1115 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
1116 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
1117 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1120 HINTERNET rc = NULL;
1121 DWORD res = ERROR_SUCCESS;
1123 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
1124 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
1125 dwService, dwFlags, dwContext);
1127 if (!lpszServerName)
1129 SetLastError(ERROR_INVALID_PARAMETER);
1133 hIC = (appinfo_t*)get_handle_object( hInternet );
1134 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
1136 res = ERROR_INVALID_HANDLE;
1142 case INTERNET_SERVICE_FTP:
1143 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
1144 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
1146 res = INTERNET_GetLastError();
1149 case INTERNET_SERVICE_HTTP:
1150 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
1151 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
1154 case INTERNET_SERVICE_GOPHER:
1160 WININET_Release( &hIC->hdr );
1162 TRACE("returning %p\n", rc);
1168 /***********************************************************************
1169 * InternetConnectA (WININET.@)
1171 * Open a ftp, gopher or http session
1174 * HINTERNET a session handle on success
1178 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1179 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1180 LPCSTR lpszUserName, LPCSTR lpszPassword,
1181 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1183 HINTERNET rc = NULL;
1184 LPWSTR szServerName;
1188 szServerName = heap_strdupAtoW(lpszServerName);
1189 szUserName = heap_strdupAtoW(lpszUserName);
1190 szPassword = heap_strdupAtoW(lpszPassword);
1192 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1193 szUserName, szPassword, dwService, dwFlags, dwContext);
1195 HeapFree(GetProcessHeap(), 0, szServerName);
1196 HeapFree(GetProcessHeap(), 0, szUserName);
1197 HeapFree(GetProcessHeap(), 0, szPassword);
1202 /***********************************************************************
1203 * InternetFindNextFileA (WININET.@)
1205 * Continues a file search from a previous call to FindFirstFile
1212 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1215 WIN32_FIND_DATAW fd;
1217 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1219 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1223 /***********************************************************************
1224 * InternetFindNextFileW (WININET.@)
1226 * Continues a file search from a previous call to FindFirstFile
1233 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1235 object_header_t *hdr;
1240 hdr = get_handle_object(hFind);
1242 WARN("Invalid handle\n");
1243 SetLastError(ERROR_INVALID_HANDLE);
1247 if(hdr->vtbl->FindNextFileW) {
1248 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1250 WARN("Handle doesn't support NextFile\n");
1251 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1254 WININET_Release(hdr);
1256 if(res != ERROR_SUCCESS)
1258 return res == ERROR_SUCCESS;
1261 /***********************************************************************
1262 * InternetCloseHandle (WININET.@)
1264 * Generic close handle function
1271 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1273 object_header_t *obj;
1275 TRACE("%p\n", hInternet);
1277 obj = get_handle_object( hInternet );
1279 SetLastError(ERROR_INVALID_HANDLE);
1283 invalidate_handle(obj);
1284 WININET_Release(obj);
1290 /***********************************************************************
1291 * ConvertUrlComponentValue (Internal)
1293 * Helper function for InternetCrackUrlA
1296 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1297 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1298 LPCSTR lpszStart, LPCWSTR lpwszStart)
1300 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1301 if (*dwComponentLen != 0)
1303 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1304 if (*lppszComponent == NULL)
1308 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1309 *lppszComponent = (LPSTR)lpszStart + offset;
1312 *lppszComponent = NULL;
1314 *dwComponentLen = nASCIILength;
1318 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1319 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1320 (*lppszComponent)[ncpylen]=0;
1321 *dwComponentLen = ncpylen;
1327 /***********************************************************************
1328 * InternetCrackUrlA (WININET.@)
1330 * See InternetCrackUrlW.
1332 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1333 LPURL_COMPONENTSA lpUrlComponents)
1336 URL_COMPONENTSW UCW;
1338 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1339 *scheme = NULL, *extra = NULL;
1341 TRACE("(%s %u %x %p)\n",
1342 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1343 dwUrlLength, dwFlags, lpUrlComponents);
1345 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1346 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1348 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1354 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1356 /* if dwUrlLength=-1 then nLength includes null but length to
1357 InternetCrackUrlW should not include it */
1358 if (dwUrlLength == -1) nLength--;
1360 lpwszUrl = HeapAlloc(GetProcessHeap(), 0, (nLength + 1) * sizeof(WCHAR));
1361 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength + 1);
1362 lpwszUrl[nLength] = '\0';
1364 memset(&UCW,0,sizeof(UCW));
1365 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1366 if (lpUrlComponents->dwHostNameLength)
1368 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1369 if (lpUrlComponents->lpszHostName)
1371 hostname = HeapAlloc(GetProcessHeap(), 0, UCW.dwHostNameLength * sizeof(WCHAR));
1372 UCW.lpszHostName = hostname;
1375 if (lpUrlComponents->dwUserNameLength)
1377 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1378 if (lpUrlComponents->lpszUserName)
1380 username = HeapAlloc(GetProcessHeap(), 0, UCW.dwUserNameLength * sizeof(WCHAR));
1381 UCW.lpszUserName = username;
1384 if (lpUrlComponents->dwPasswordLength)
1386 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1387 if (lpUrlComponents->lpszPassword)
1389 password = HeapAlloc(GetProcessHeap(), 0, UCW.dwPasswordLength * sizeof(WCHAR));
1390 UCW.lpszPassword = password;
1393 if (lpUrlComponents->dwUrlPathLength)
1395 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1396 if (lpUrlComponents->lpszUrlPath)
1398 path = HeapAlloc(GetProcessHeap(), 0, UCW.dwUrlPathLength * sizeof(WCHAR));
1399 UCW.lpszUrlPath = path;
1402 if (lpUrlComponents->dwSchemeLength)
1404 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1405 if (lpUrlComponents->lpszScheme)
1407 scheme = HeapAlloc(GetProcessHeap(), 0, UCW.dwSchemeLength * sizeof(WCHAR));
1408 UCW.lpszScheme = scheme;
1411 if (lpUrlComponents->dwExtraInfoLength)
1413 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1414 if (lpUrlComponents->lpszExtraInfo)
1416 extra = HeapAlloc(GetProcessHeap(), 0, UCW.dwExtraInfoLength * sizeof(WCHAR));
1417 UCW.lpszExtraInfo = extra;
1420 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1422 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1423 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1424 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1425 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1426 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1427 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1428 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1429 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1430 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1431 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1432 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1433 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1435 lpUrlComponents->nScheme = UCW.nScheme;
1436 lpUrlComponents->nPort = UCW.nPort;
1438 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_a(lpszUrl),
1439 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1440 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1441 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1442 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1444 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1445 HeapFree(GetProcessHeap(), 0, hostname);
1446 HeapFree(GetProcessHeap(), 0, username);
1447 HeapFree(GetProcessHeap(), 0, password);
1448 HeapFree(GetProcessHeap(), 0, path);
1449 HeapFree(GetProcessHeap(), 0, scheme);
1450 HeapFree(GetProcessHeap(), 0, extra);
1454 static const WCHAR url_schemes[][7] =
1457 {'g','o','p','h','e','r',0},
1458 {'h','t','t','p',0},
1459 {'h','t','t','p','s',0},
1460 {'f','i','l','e',0},
1461 {'n','e','w','s',0},
1462 {'m','a','i','l','t','o',0},
1466 /***********************************************************************
1467 * GetInternetSchemeW (internal)
1473 * INTERNET_SCHEME_UNKNOWN on failure
1476 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1480 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1482 if(lpszScheme==NULL)
1483 return INTERNET_SCHEME_UNKNOWN;
1485 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1486 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1487 return INTERNET_SCHEME_FIRST + i;
1489 return INTERNET_SCHEME_UNKNOWN;
1492 /***********************************************************************
1493 * SetUrlComponentValueW (Internal)
1495 * Helper function for InternetCrackUrlW
1498 * lppszComponent [O] Holds the returned string
1499 * dwComponentLen [I] Holds the size of lppszComponent
1500 * [O] Holds the length of the string in lppszComponent without '\0'
1501 * lpszStart [I] Holds the string to copy from
1502 * len [I] Holds the length of lpszStart without '\0'
1509 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1511 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1513 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1516 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1518 if (*lppszComponent == NULL)
1520 *lppszComponent = (LPWSTR)lpszStart;
1521 *dwComponentLen = len;
1525 DWORD ncpylen = min((*dwComponentLen)-1, len);
1526 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1527 (*lppszComponent)[ncpylen] = '\0';
1528 *dwComponentLen = ncpylen;
1535 /***********************************************************************
1536 * InternetCrackUrlW (WININET.@)
1538 * Break up URL into its components
1544 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1545 LPURL_COMPONENTSW lpUC)
1549 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1552 LPCWSTR lpszParam = NULL;
1553 BOOL bIsAbsolute = FALSE;
1554 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1555 LPCWSTR lpszcp = NULL;
1556 LPWSTR lpszUrl_decode = NULL;
1557 DWORD dwUrlLength = dwUrlLength_orig;
1559 TRACE("(%s %u %x %p)\n",
1560 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1561 dwUrlLength, dwFlags, lpUC);
1563 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1565 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1568 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1570 if (dwFlags & ICU_DECODE)
1573 DWORD len = dwUrlLength + 1;
1575 if (!(url_tmp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1577 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1580 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1581 url_tmp[dwUrlLength] = 0;
1582 if (!(lpszUrl_decode = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1584 HeapFree(GetProcessHeap(), 0, url_tmp);
1585 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1588 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1591 lpszUrl = lpszUrl_decode;
1593 HeapFree(GetProcessHeap(), 0, url_tmp);
1597 /* Determine if the URI is absolute. */
1598 while (lpszap - lpszUrl < dwUrlLength)
1600 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1605 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1612 lpszcp = lpszUrl; /* Relative url */
1618 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1619 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1621 /* Parse <params> */
1622 lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl));
1624 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1626 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1628 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1629 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1631 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1635 /* Get scheme first. */
1636 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1637 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1638 lpszUrl, lpszcp - lpszUrl);
1640 /* Eat ':' in protocol. */
1643 /* double slash indicates the net_loc portion is present */
1644 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1648 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1652 lpszNetLoc = min(lpszNetLoc, lpszParam);
1654 lpszNetLoc = lpszParam;
1656 else if (!lpszNetLoc)
1657 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1665 /* [<user>[<:password>]@]<host>[:<port>] */
1666 /* First find the user and password if they exist */
1668 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1669 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1671 /* username and password not specified. */
1672 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1673 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1675 else /* Parse out username and password */
1677 LPCWSTR lpszUser = lpszcp;
1678 LPCWSTR lpszPasswd = lpszHost;
1680 while (lpszcp < lpszHost)
1683 lpszPasswd = lpszcp;
1688 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1689 lpszUser, lpszPasswd - lpszUser);
1691 if (lpszPasswd != lpszHost)
1693 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1694 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1695 lpszHost - lpszPasswd);
1697 lpszcp++; /* Advance to beginning of host */
1700 /* Parse <host><:port> */
1703 lpszPort = lpszNetLoc;
1705 /* special case for res:// URLs: there is no port here, so the host is the
1706 entire string up to the first '/' */
1707 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1709 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1710 lpszHost, lpszPort - lpszHost);
1715 while (lpszcp < lpszNetLoc)
1723 /* If the scheme is "file" and the host is just one letter, it's not a host */
1724 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1727 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1732 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1733 lpszHost, lpszPort - lpszHost);
1734 if (lpszPort != lpszNetLoc)
1735 lpUC->nPort = atoiW(++lpszPort);
1736 else switch (lpUC->nScheme)
1738 case INTERNET_SCHEME_HTTP:
1739 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1741 case INTERNET_SCHEME_HTTPS:
1742 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1744 case INTERNET_SCHEME_FTP:
1745 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1747 case INTERNET_SCHEME_GOPHER:
1748 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1759 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1760 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1761 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1766 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1767 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1768 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1769 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1772 /* Here lpszcp points to:
1774 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1775 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1777 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1781 /* Only truncate the parameter list if it's already been saved
1782 * in lpUC->lpszExtraInfo.
1784 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1785 len = lpszParam - lpszcp;
1788 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1789 * newlines if necessary.
1791 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1792 if (lpsznewline != NULL)
1793 len = lpsznewline - lpszcp;
1795 len = dwUrlLength-(lpszcp-lpszUrl);
1797 if (lpUC->dwUrlPathLength && lpUC->lpszUrlPath &&
1798 lpUC->nScheme == INTERNET_SCHEME_FILE)
1800 WCHAR tmppath[MAX_PATH];
1804 PathCreateFromUrlW(lpszUrl_orig, tmppath, &len, 0);
1809 memcpy(tmppath, lpszcp, len * sizeof(WCHAR));
1810 tmppath[len] = '\0';
1819 /* if ends in \. or \.. append a backslash */
1820 if (tmppath[len - 1] == '.' &&
1821 (tmppath[len - 2] == '\\' ||
1822 (tmppath[len - 2] == '.' && tmppath[len - 3] == '\\')))
1824 if (len < MAX_PATH - 1)
1826 tmppath[len] = '\\';
1827 tmppath[len+1] = '\0';
1831 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1835 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1840 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1841 lpUC->lpszUrlPath[0] = 0;
1842 lpUC->dwUrlPathLength = 0;
1845 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1846 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1847 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1848 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1849 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1851 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1855 /***********************************************************************
1856 * InternetAttemptConnect (WININET.@)
1858 * Attempt to make a connection to the internet
1861 * ERROR_SUCCESS on success
1862 * Error value on failure
1865 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1868 return ERROR_SUCCESS;
1872 /***********************************************************************
1873 * InternetCanonicalizeUrlA (WININET.@)
1875 * Escape unsafe characters and spaces
1882 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1883 LPDWORD lpdwBufferLength, DWORD dwFlags)
1886 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1888 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1889 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1891 if(dwFlags & ICU_DECODE)
1893 dwURLFlags |= URL_UNESCAPE;
1894 dwFlags &= ~ICU_DECODE;
1897 if(dwFlags & ICU_ESCAPE)
1899 dwURLFlags |= URL_UNESCAPE;
1900 dwFlags &= ~ICU_ESCAPE;
1903 if(dwFlags & ICU_BROWSER_MODE)
1905 dwURLFlags |= URL_BROWSER_MODE;
1906 dwFlags &= ~ICU_BROWSER_MODE;
1909 if(dwFlags & ICU_NO_ENCODE)
1911 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1912 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1913 dwFlags &= ~ICU_NO_ENCODE;
1916 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1918 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1919 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1920 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1922 return (hr == S_OK) ? TRUE : FALSE;
1925 /***********************************************************************
1926 * InternetCanonicalizeUrlW (WININET.@)
1928 * Escape unsafe characters and spaces
1935 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1936 LPDWORD lpdwBufferLength, DWORD dwFlags)
1939 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1941 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1942 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1944 if(dwFlags & ICU_DECODE)
1946 dwURLFlags |= URL_UNESCAPE;
1947 dwFlags &= ~ICU_DECODE;
1950 if(dwFlags & ICU_ESCAPE)
1952 dwURLFlags |= URL_UNESCAPE;
1953 dwFlags &= ~ICU_ESCAPE;
1956 if(dwFlags & ICU_BROWSER_MODE)
1958 dwURLFlags |= URL_BROWSER_MODE;
1959 dwFlags &= ~ICU_BROWSER_MODE;
1962 if(dwFlags & ICU_NO_ENCODE)
1964 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1965 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1966 dwFlags &= ~ICU_NO_ENCODE;
1969 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1971 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1972 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1973 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1975 return (hr == S_OK) ? TRUE : FALSE;
1978 /* #################################################### */
1980 static INTERNET_STATUS_CALLBACK set_status_callback(
1981 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1983 INTERNET_STATUS_CALLBACK ret;
1985 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1986 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1988 ret = lpwh->lpfnStatusCB;
1989 lpwh->lpfnStatusCB = callback;
1994 /***********************************************************************
1995 * InternetSetStatusCallbackA (WININET.@)
1997 * Sets up a callback function which is called as progress is made
1998 * during an operation.
2001 * Previous callback or NULL on success
2002 * INTERNET_INVALID_STATUS_CALLBACK on failure
2005 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
2006 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2008 INTERNET_STATUS_CALLBACK retVal;
2009 object_header_t *lpwh;
2011 TRACE("%p\n", hInternet);
2013 if (!(lpwh = get_handle_object(hInternet)))
2014 return INTERNET_INVALID_STATUS_CALLBACK;
2016 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
2018 WININET_Release( lpwh );
2022 /***********************************************************************
2023 * InternetSetStatusCallbackW (WININET.@)
2025 * Sets up a callback function which is called as progress is made
2026 * during an operation.
2029 * Previous callback or NULL on success
2030 * INTERNET_INVALID_STATUS_CALLBACK on failure
2033 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
2034 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
2036 INTERNET_STATUS_CALLBACK retVal;
2037 object_header_t *lpwh;
2039 TRACE("%p\n", hInternet);
2041 if (!(lpwh = get_handle_object(hInternet)))
2042 return INTERNET_INVALID_STATUS_CALLBACK;
2044 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
2046 WININET_Release( lpwh );
2050 /***********************************************************************
2051 * InternetSetFilePointer (WININET.@)
2053 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
2054 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
2060 /***********************************************************************
2061 * InternetWriteFile (WININET.@)
2063 * Write data to an open internet file
2070 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
2071 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
2073 object_header_t *lpwh;
2076 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2078 lpwh = get_handle_object( hFile );
2080 WARN("Invalid handle\n");
2081 SetLastError(ERROR_INVALID_HANDLE);
2085 if(lpwh->vtbl->WriteFile) {
2086 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
2088 WARN("No Writefile method.\n");
2089 res = ERROR_INVALID_HANDLE;
2092 WININET_Release( lpwh );
2094 if(res != ERROR_SUCCESS)
2096 return res == ERROR_SUCCESS;
2100 /***********************************************************************
2101 * InternetReadFile (WININET.@)
2103 * Read data from an open internet file
2110 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
2111 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
2113 object_header_t *hdr;
2114 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2116 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2118 hdr = get_handle_object(hFile);
2120 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2124 if(hdr->vtbl->ReadFile)
2125 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
2127 WININET_Release(hdr);
2129 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
2130 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
2132 if(res != ERROR_SUCCESS)
2134 return res == ERROR_SUCCESS;
2137 /***********************************************************************
2138 * InternetReadFileExA (WININET.@)
2140 * Read data from an open internet file
2143 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
2144 * lpBuffersOut [I/O] Buffer.
2145 * dwFlags [I] Flags. See notes.
2146 * dwContext [I] Context for callbacks.
2153 * The parameter dwFlags include zero or more of the following flags:
2154 *|IRF_ASYNC - Makes the call asynchronous.
2155 *|IRF_SYNC - Makes the call synchronous.
2156 *|IRF_USE_CONTEXT - Forces dwContext to be used.
2157 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
2159 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
2162 * InternetOpenUrlA(), HttpOpenRequestA()
2164 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
2165 DWORD dwFlags, DWORD_PTR dwContext)
2167 object_header_t *hdr;
2168 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2170 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
2172 hdr = get_handle_object(hFile);
2174 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2178 if(hdr->vtbl->ReadFileExA)
2179 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
2181 WININET_Release(hdr);
2183 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2184 res, lpBuffersOut->dwBufferLength);
2186 if(res != ERROR_SUCCESS)
2188 return res == ERROR_SUCCESS;
2191 /***********************************************************************
2192 * InternetReadFileExW (WININET.@)
2194 * InternetReadFileExA()
2196 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
2197 DWORD dwFlags, DWORD_PTR dwContext)
2199 object_header_t *hdr;
2200 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2202 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
2204 hdr = get_handle_object(hFile);
2206 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2210 if(hdr->vtbl->ReadFileExW)
2211 res = hdr->vtbl->ReadFileExW(hdr, lpBuffer, dwFlags, dwContext);
2213 WININET_Release(hdr);
2215 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2216 res, lpBuffer->dwBufferLength);
2218 if(res != ERROR_SUCCESS)
2220 return res == ERROR_SUCCESS;
2223 DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
2225 static BOOL warn = TRUE;
2228 case INTERNET_OPTION_REQUEST_FLAGS:
2229 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2231 if (*size < sizeof(ULONG))
2232 return ERROR_INSUFFICIENT_BUFFER;
2234 *(ULONG*)buffer = 4;
2235 *size = sizeof(ULONG);
2237 return ERROR_SUCCESS;
2239 case INTERNET_OPTION_HTTP_VERSION:
2240 if (*size < sizeof(HTTP_VERSION_INFO))
2241 return ERROR_INSUFFICIENT_BUFFER;
2244 * Presently hardcoded to 1.1
2246 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2247 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2248 *size = sizeof(HTTP_VERSION_INFO);
2250 return ERROR_SUCCESS;
2252 case INTERNET_OPTION_CONNECTED_STATE:
2254 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2257 if (*size < sizeof(ULONG))
2258 return ERROR_INSUFFICIENT_BUFFER;
2260 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2261 *size = sizeof(ULONG);
2263 return ERROR_SUCCESS;
2265 case INTERNET_OPTION_PROXY: {
2269 TRACE("Getting global proxy info\n");
2270 memset(&ai, 0, sizeof(appinfo_t));
2271 INTERNET_ConfigureProxy(&ai);
2273 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2274 APPINFO_Destroy(&ai.hdr);
2278 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2279 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2281 if (*size < sizeof(ULONG))
2282 return ERROR_INSUFFICIENT_BUFFER;
2284 *(ULONG*)buffer = 2;
2285 *size = sizeof(ULONG);
2287 return ERROR_SUCCESS;
2289 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2290 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2292 if (*size < sizeof(ULONG))
2293 return ERROR_INSUFFICIENT_BUFFER;
2295 *(ULONG*)buffer = 4;
2296 *size = sizeof(ULONG);
2298 return ERROR_SUCCESS;
2300 case INTERNET_OPTION_SECURITY_FLAGS:
2301 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2302 return ERROR_SUCCESS;
2304 case INTERNET_OPTION_VERSION: {
2305 static const INTERNET_VERSION_INFO info = { 1, 2 };
2307 TRACE("INTERNET_OPTION_VERSION\n");
2309 if (*size < sizeof(INTERNET_VERSION_INFO))
2310 return ERROR_INSUFFICIENT_BUFFER;
2312 memcpy(buffer, &info, sizeof(info));
2313 *size = sizeof(info);
2315 return ERROR_SUCCESS;
2318 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2319 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2320 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2321 DWORD res = ERROR_SUCCESS, i;
2325 TRACE("Getting global proxy info\n");
2326 if((ret = INTERNET_LoadProxySettings(&pi)))
2329 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2331 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2333 return ERROR_INSUFFICIENT_BUFFER;
2336 for (i = 0; i < con->dwOptionCount; i++) {
2337 INTERNET_PER_CONN_OPTIONW *optionW = con->pOptions + i;
2338 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2340 switch (optionW->dwOption) {
2341 case INTERNET_PER_CONN_FLAGS:
2342 if(pi.dwProxyEnabled)
2343 optionW->Value.dwValue = PROXY_TYPE_PROXY;
2345 optionW->Value.dwValue = PROXY_TYPE_DIRECT;
2348 case INTERNET_PER_CONN_PROXY_SERVER:
2350 optionW->Value.pszValue = heap_strdupW(pi.lpszProxyServer);
2352 optionA->Value.pszValue = heap_strdupWtoA(pi.lpszProxyServer);
2355 case INTERNET_PER_CONN_PROXY_BYPASS:
2357 optionW->Value.pszValue = heap_strdupW(pi.lpszProxyBypass);
2359 optionA->Value.pszValue = heap_strdupWtoA(pi.lpszProxyBypass);
2362 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2363 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2364 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2365 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2366 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2367 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2368 FIXME("Unhandled dwOption %d\n", optionW->dwOption);
2369 memset(&optionW->Value, 0, sizeof(optionW->Value));
2373 FIXME("Unknown dwOption %d\n", optionW->dwOption);
2374 res = ERROR_INVALID_PARAMETER;
2382 case INTERNET_OPTION_USER_AGENT:
2383 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2384 case INTERNET_OPTION_POLICY:
2385 return ERROR_INVALID_PARAMETER;
2386 case INTERNET_OPTION_CONTEXT_VALUE:
2389 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2391 return ERROR_INVALID_PARAMETER;
2393 if (*size < sizeof(DWORD_PTR))
2395 *size = sizeof(DWORD_PTR);
2396 return ERROR_INSUFFICIENT_BUFFER;
2399 return ERROR_INVALID_PARAMETER;
2401 *(DWORD_PTR *)buffer = hdr->dwContext;
2402 *size = sizeof(DWORD_PTR);
2403 return ERROR_SUCCESS;
2407 FIXME("Stub for %d\n", option);
2408 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2411 /***********************************************************************
2412 * InternetQueryOptionW (WININET.@)
2414 * Queries an options on the specified handle
2421 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2422 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2424 object_header_t *hdr;
2425 DWORD res = ERROR_INVALID_HANDLE;
2427 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2430 hdr = get_handle_object(hInternet);
2432 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2433 WININET_Release(hdr);
2436 res = INET_QueryOption(NULL, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2439 if(res != ERROR_SUCCESS)
2441 return res == ERROR_SUCCESS;
2444 /***********************************************************************
2445 * InternetQueryOptionA (WININET.@)
2447 * Queries an options on the specified handle
2454 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2455 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2457 object_header_t *hdr;
2458 DWORD res = ERROR_INVALID_HANDLE;
2460 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2463 hdr = get_handle_object(hInternet);
2465 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2466 WININET_Release(hdr);
2469 res = INET_QueryOption(NULL, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2472 if(res != ERROR_SUCCESS)
2474 return res == ERROR_SUCCESS;
2478 /***********************************************************************
2479 * InternetSetOptionW (WININET.@)
2481 * Sets an options on the specified handle
2488 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2489 LPVOID lpBuffer, DWORD dwBufferLength)
2491 object_header_t *lpwhh;
2494 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2496 lpwhh = (object_header_t*) get_handle_object( hInternet );
2497 if(lpwhh && lpwhh->vtbl->SetOption) {
2500 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2501 if(res != ERROR_INTERNET_INVALID_OPTION) {
2502 WININET_Release( lpwhh );
2504 if(res != ERROR_SUCCESS)
2507 return res == ERROR_SUCCESS;
2513 case INTERNET_OPTION_CALLBACK:
2517 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2520 WININET_Release(lpwhh);
2521 SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2524 case INTERNET_OPTION_HTTP_VERSION:
2526 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2527 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2530 case INTERNET_OPTION_ERROR_MASK:
2533 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2535 } else if(*(ULONG*)lpBuffer & (~(INTERNET_ERROR_MASK_INSERT_CDROM|
2536 INTERNET_ERROR_MASK_COMBINED_SEC_CERT|
2537 INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY))) {
2538 SetLastError(ERROR_INVALID_PARAMETER);
2540 } else if(dwBufferLength != sizeof(ULONG)) {
2541 SetLastError(ERROR_INTERNET_BAD_OPTION_LENGTH);
2544 lpwhh->ErrorMask = *(ULONG*)lpBuffer;
2547 case INTERNET_OPTION_CODEPAGE:
2549 ULONG codepage = *(ULONG *)lpBuffer;
2550 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2553 case INTERNET_OPTION_REQUEST_PRIORITY:
2555 ULONG priority = *(ULONG *)lpBuffer;
2556 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2559 case INTERNET_OPTION_CONNECT_TIMEOUT:
2561 ULONG connecttimeout = *(ULONG *)lpBuffer;
2562 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2565 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2567 ULONG receivetimeout = *(ULONG *)lpBuffer;
2568 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2571 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2573 ULONG conns = *(ULONG *)lpBuffer;
2574 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2577 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2579 ULONG conns = *(ULONG *)lpBuffer;
2580 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2583 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2584 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2586 case INTERNET_OPTION_END_BROWSER_SESSION:
2587 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2589 case INTERNET_OPTION_CONNECTED_STATE:
2590 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2592 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2593 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2595 case INTERNET_OPTION_SEND_TIMEOUT:
2596 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2598 ULONG timeout = *(ULONG *)lpBuffer;
2599 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout);
2602 case INTERNET_OPTION_CONNECT_RETRIES:
2604 ULONG retries = *(ULONG *)lpBuffer;
2605 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2608 case INTERNET_OPTION_CONTEXT_VALUE:
2612 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2615 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2617 SetLastError(ERROR_INVALID_PARAMETER);
2621 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2624 case INTERNET_OPTION_SECURITY_FLAGS:
2625 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2627 case INTERNET_OPTION_DISABLE_AUTODIAL:
2628 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2630 case INTERNET_OPTION_HTTP_DECODING:
2631 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2632 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2635 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2636 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2637 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2640 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2641 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2642 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2645 case INTERNET_OPTION_CODEPAGE_PATH:
2646 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2647 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2650 case INTERNET_OPTION_CODEPAGE_EXTRA:
2651 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2652 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2655 case INTERNET_OPTION_IDN:
2656 FIXME("INTERNET_OPTION_IDN; STUB\n");
2657 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2660 case INTERNET_OPTION_POLICY:
2661 SetLastError(ERROR_INVALID_PARAMETER);
2664 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2665 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2670 INTERNET_LoadProxySettings(&pi);
2672 for (i = 0; i < con->dwOptionCount; i++) {
2673 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2675 switch (option->dwOption) {
2676 case INTERNET_PER_CONN_PROXY_SERVER:
2677 HeapFree(GetProcessHeap(), 0, pi.lpszProxyServer);
2678 pi.lpszProxyServer = heap_strdupW(option->Value.pszValue);
2681 case INTERNET_PER_CONN_FLAGS:
2682 if(option->Value.dwValue & PROXY_TYPE_PROXY)
2683 pi.dwProxyEnabled = 1;
2686 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
2687 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
2688 pi.dwProxyEnabled = 0;
2692 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2693 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2694 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2695 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2696 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2697 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2698 case INTERNET_PER_CONN_PROXY_BYPASS:
2699 FIXME("Unhandled dwOption %d\n", option->dwOption);
2703 FIXME("Unknown dwOption %d\n", option->dwOption);
2704 SetLastError(ERROR_INVALID_PARAMETER);
2709 if ((res = INTERNET_SaveProxySettings(&pi)))
2714 ret = (res == ERROR_SUCCESS);
2718 FIXME("Option %d STUB\n",dwOption);
2719 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2725 WININET_Release( lpwhh );
2731 /***********************************************************************
2732 * InternetSetOptionA (WININET.@)
2734 * Sets an options on the specified handle.
2741 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2742 LPVOID lpBuffer, DWORD dwBufferLength)
2750 case INTERNET_OPTION_CALLBACK:
2752 object_header_t *lpwh;
2754 if (!(lpwh = get_handle_object(hInternet)))
2756 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2759 WININET_Release(lpwh);
2760 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2763 case INTERNET_OPTION_PROXY:
2765 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2766 LPINTERNET_PROXY_INFOW piw;
2767 DWORD proxlen, prbylen;
2770 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2771 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2772 wlen = sizeof(*piw) + proxlen + prbylen;
2773 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2774 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2775 piw->dwAccessType = pi->dwAccessType;
2776 prox = (LPWSTR) &piw[1];
2777 prby = &prox[proxlen+1];
2778 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2779 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2780 piw->lpszProxy = prox;
2781 piw->lpszProxyBypass = prby;
2784 case INTERNET_OPTION_USER_AGENT:
2785 case INTERNET_OPTION_USERNAME:
2786 case INTERNET_OPTION_PASSWORD:
2787 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2789 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2790 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2793 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2795 INTERNET_PER_CONN_OPTION_LISTW *listW;
2796 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
2797 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2798 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen );
2801 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2802 if (listA->pszConnection)
2804 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
2805 listW->pszConnection = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2806 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
2809 listW->pszConnection = NULL;
2810 listW->dwOptionCount = listA->dwOptionCount;
2811 listW->dwOptionError = listA->dwOptionError;
2812 listW->pOptions = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount );
2814 for (i = 0; i < listA->dwOptionCount; ++i) {
2815 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
2816 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
2818 optW->dwOption = optA->dwOption;
2820 switch (optA->dwOption) {
2821 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2822 case INTERNET_PER_CONN_PROXY_BYPASS:
2823 case INTERNET_PER_CONN_PROXY_SERVER:
2824 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2825 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2826 if (optA->Value.pszValue)
2828 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
2829 optW->Value.pszValue = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2830 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
2833 optW->Value.pszValue = NULL;
2835 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2836 case INTERNET_PER_CONN_FLAGS:
2837 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2838 optW->Value.dwValue = optA->Value.dwValue;
2840 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2841 optW->Value.ftValue = optA->Value.ftValue;
2844 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
2845 optW->Value.dwValue = optA->Value.dwValue;
2853 wlen = dwBufferLength;
2856 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2858 if( lpBuffer != wbuffer )
2860 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
2862 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
2864 for (i = 0; i < list->dwOptionCount; ++i) {
2865 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
2866 switch (opt->dwOption) {
2867 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2868 case INTERNET_PER_CONN_PROXY_BYPASS:
2869 case INTERNET_PER_CONN_PROXY_SERVER:
2870 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2871 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2872 HeapFree( GetProcessHeap(), 0, opt->Value.pszValue );
2878 HeapFree( GetProcessHeap(), 0, list->pOptions );
2880 HeapFree( GetProcessHeap(), 0, wbuffer );
2887 /***********************************************************************
2888 * InternetSetOptionExA (WININET.@)
2890 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2891 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2893 FIXME("Flags %08x ignored\n", dwFlags);
2894 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2897 /***********************************************************************
2898 * InternetSetOptionExW (WININET.@)
2900 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2901 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2903 FIXME("Flags %08x ignored\n", dwFlags);
2904 if( dwFlags & ~ISO_VALID_FLAGS )
2906 SetLastError( ERROR_INVALID_PARAMETER );
2909 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2912 static const WCHAR WININET_wkday[7][4] =
2913 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2914 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2915 static const WCHAR WININET_month[12][4] =
2916 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2917 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2918 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2920 /***********************************************************************
2921 * InternetTimeFromSystemTimeA (WININET.@)
2923 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2926 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2928 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2930 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2932 SetLastError(ERROR_INVALID_PARAMETER);
2936 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2938 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2942 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2943 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2948 /***********************************************************************
2949 * InternetTimeFromSystemTimeW (WININET.@)
2951 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2953 static const WCHAR date[] =
2954 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2955 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2957 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2959 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2961 SetLastError(ERROR_INVALID_PARAMETER);
2965 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2967 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2971 sprintfW( string, date,
2972 WININET_wkday[time->wDayOfWeek],
2974 WININET_month[time->wMonth - 1],
2983 /***********************************************************************
2984 * InternetTimeToSystemTimeA (WININET.@)
2986 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2991 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2993 stringW = heap_strdupAtoW(string);
2996 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2997 HeapFree( GetProcessHeap(), 0, stringW );
3002 /***********************************************************************
3003 * InternetTimeToSystemTimeW (WININET.@)
3005 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3008 const WCHAR *s = string;
3011 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3013 if (!string || !time) return FALSE;
3015 /* Windows does this too */
3016 GetSystemTime( time );
3018 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3019 * a SYSTEMTIME structure.
3022 while (*s && !isalphaW( *s )) s++;
3023 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3024 time->wDayOfWeek = 7;
3026 for (i = 0; i < 7; i++)
3028 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3029 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3030 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3032 time->wDayOfWeek = i;
3037 if (time->wDayOfWeek > 6) return TRUE;
3038 while (*s && !isdigitW( *s )) s++;
3039 time->wDay = strtolW( s, &end, 10 );
3042 while (*s && !isalphaW( *s )) s++;
3043 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3046 for (i = 0; i < 12; i++)
3048 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3049 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3050 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3052 time->wMonth = i + 1;
3056 if (time->wMonth == 0) return TRUE;
3058 while (*s && !isdigitW( *s )) s++;
3059 if (*s == '\0') return TRUE;
3060 time->wYear = strtolW( s, &end, 10 );
3063 while (*s && !isdigitW( *s )) s++;
3064 if (*s == '\0') return TRUE;
3065 time->wHour = strtolW( s, &end, 10 );
3068 while (*s && !isdigitW( *s )) s++;
3069 if (*s == '\0') return TRUE;
3070 time->wMinute = strtolW( s, &end, 10 );
3073 while (*s && !isdigitW( *s )) s++;
3074 if (*s == '\0') return TRUE;
3075 time->wSecond = strtolW( s, &end, 10 );
3078 time->wMilliseconds = 0;
3082 /***********************************************************************
3083 * InternetCheckConnectionW (WININET.@)
3085 * Pings a requested host to check internet connection
3088 * TRUE on success and FALSE on failure. If a failure then
3089 * ERROR_NOT_CONNECTED is placed into GetLastError
3092 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3095 * this is a kludge which runs the resident ping program and reads the output.
3097 * Anyone have a better idea?
3101 static const CHAR ping[] = "ping -c 1 ";
3102 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3103 CHAR *command = NULL;
3112 * Crack or set the Address
3114 if (lpszUrl == NULL)
3117 * According to the doc we are supposed to use the ip for the next
3118 * server in the WnInet internal server database. I have
3119 * no idea what that is or how to get it.
3121 * So someone needs to implement this.
3123 FIXME("Unimplemented with URL of NULL\n");
3128 URL_COMPONENTSW components;
3130 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3131 components.lpszHostName = (LPWSTR)hostW;
3132 components.dwHostNameLength = 1024;
3134 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3137 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3138 port = components.nPort;
3139 TRACE("port: %d\n", port);
3142 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3144 struct sockaddr_storage saddr;
3145 socklen_t sa_len = sizeof(saddr);
3148 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3150 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3153 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3161 * Build our ping command
3163 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3164 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
3165 strcpy(command,ping);
3166 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3167 strcat(command,redirect);
3169 TRACE("Ping command is : %s\n",command);
3171 status = system(command);
3173 TRACE("Ping returned a code of %i\n",status);
3175 /* Ping return code of 0 indicates success */
3182 HeapFree( GetProcessHeap(), 0, command );
3184 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3190 /***********************************************************************
3191 * InternetCheckConnectionA (WININET.@)
3193 * Pings a requested host to check internet connection
3196 * TRUE on success and FALSE on failure. If a failure then
3197 * ERROR_NOT_CONNECTED is placed into GetLastError
3200 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3206 url = heap_strdupAtoW(lpszUrl);
3211 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3213 HeapFree(GetProcessHeap(), 0, url);
3218 /**********************************************************
3219 * INTERNET_InternetOpenUrlW (internal)
3224 * handle of connection or NULL on failure
3226 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3227 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3229 URL_COMPONENTSW urlComponents;
3230 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
3231 WCHAR password[1024], path[2048], extra[1024];
3232 HINTERNET client = NULL, client1 = NULL;
3235 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3236 dwHeadersLength, dwFlags, dwContext);
3238 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3239 urlComponents.lpszScheme = protocol;
3240 urlComponents.dwSchemeLength = 32;
3241 urlComponents.lpszHostName = hostName;
3242 urlComponents.dwHostNameLength = MAXHOSTNAME;
3243 urlComponents.lpszUserName = userName;
3244 urlComponents.dwUserNameLength = 1024;
3245 urlComponents.lpszPassword = password;
3246 urlComponents.dwPasswordLength = 1024;
3247 urlComponents.lpszUrlPath = path;
3248 urlComponents.dwUrlPathLength = 2048;
3249 urlComponents.lpszExtraInfo = extra;
3250 urlComponents.dwExtraInfoLength = 1024;
3251 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3253 switch(urlComponents.nScheme) {
3254 case INTERNET_SCHEME_FTP:
3255 if(urlComponents.nPort == 0)
3256 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3257 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3258 userName, password, dwFlags, dwContext, INET_OPENURL);
3261 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3262 if(client1 == NULL) {
3263 InternetCloseHandle(client);
3268 case INTERNET_SCHEME_HTTP:
3269 case INTERNET_SCHEME_HTTPS: {
3270 static const WCHAR szStars[] = { '*','/','*', 0 };
3271 LPCWSTR accept[2] = { szStars, NULL };
3272 if(urlComponents.nPort == 0) {
3273 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3274 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3276 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3278 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3280 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3281 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3282 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3283 if(res != ERROR_SUCCESS) {
3284 INTERNET_SetLastError(res);
3288 if (urlComponents.dwExtraInfoLength) {
3290 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3292 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
3294 InternetCloseHandle(client);
3297 strcpyW(path_extra, urlComponents.lpszUrlPath);
3298 strcatW(path_extra, urlComponents.lpszExtraInfo);
3299 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3300 HeapFree(GetProcessHeap(), 0, path_extra);
3303 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3305 if(client1 == NULL) {
3306 InternetCloseHandle(client);
3309 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3310 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3311 GetLastError() != ERROR_IO_PENDING) {
3312 InternetCloseHandle(client1);
3317 case INTERNET_SCHEME_GOPHER:
3318 /* gopher doesn't seem to be implemented in wine, but it's supposed
3319 * to be supported by InternetOpenUrlA. */
3321 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3325 TRACE(" %p <--\n", client1);
3330 /**********************************************************
3331 * InternetOpenUrlW (WININET.@)
3336 * handle of connection or NULL on failure
3338 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3340 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3341 appinfo_t *hIC = (appinfo_t*) workRequest->hdr;
3345 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3346 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3347 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3348 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3351 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3352 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3354 HINTERNET ret = NULL;
3355 appinfo_t *hIC = NULL;
3357 if (TRACE_ON(wininet)) {
3358 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3359 dwHeadersLength, dwFlags, dwContext);
3361 dump_INTERNET_FLAGS(dwFlags);
3366 SetLastError(ERROR_INVALID_PARAMETER);
3370 hIC = (appinfo_t*)get_handle_object( hInternet );
3371 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3372 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3376 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3377 WORKREQUEST workRequest;
3378 struct WORKREQ_INTERNETOPENURLW *req;
3380 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3381 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3382 req = &workRequest.u.InternetOpenUrlW;
3383 req->lpszUrl = heap_strdupW(lpszUrl);
3384 req->lpszHeaders = heap_strdupW(lpszHeaders);
3385 req->dwHeadersLength = dwHeadersLength;
3386 req->dwFlags = dwFlags;
3387 req->dwContext = dwContext;
3389 INTERNET_AsyncCall(&workRequest);
3391 * This is from windows.
3393 SetLastError(ERROR_IO_PENDING);
3395 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3400 WININET_Release( &hIC->hdr );
3401 TRACE(" %p <--\n", ret);
3406 /**********************************************************
3407 * InternetOpenUrlA (WININET.@)
3412 * handle of connection or NULL on failure
3414 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3415 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3417 HINTERNET rc = NULL;
3418 DWORD lenHeaders = 0;
3419 LPWSTR szUrl = NULL;
3420 LPWSTR szHeaders = NULL;
3425 szUrl = heap_strdupAtoW(lpszUrl);
3431 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3432 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3434 HeapFree(GetProcessHeap(), 0, szUrl);
3437 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3440 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3441 lenHeaders, dwFlags, dwContext);
3443 HeapFree(GetProcessHeap(), 0, szUrl);
3444 HeapFree(GetProcessHeap(), 0, szHeaders);
3450 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3452 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3456 lpwite->dwError = 0;
3457 lpwite->response[0] = '\0';
3460 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3462 HeapFree(GetProcessHeap(), 0, lpwite);
3470 /***********************************************************************
3471 * INTERNET_SetLastError (internal)
3473 * Set last thread specific error
3478 void INTERNET_SetLastError(DWORD dwError)
3480 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3483 lpwite = INTERNET_AllocThreadError();
3485 SetLastError(dwError);
3487 lpwite->dwError = dwError;
3491 /***********************************************************************
3492 * INTERNET_GetLastError (internal)
3494 * Get last thread specific error
3499 DWORD INTERNET_GetLastError(void)
3501 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3502 if (!lpwite) return 0;
3503 /* TlsGetValue clears last error, so set it again here */
3504 SetLastError(lpwite->dwError);
3505 return lpwite->dwError;
3509 /***********************************************************************
3510 * INTERNET_WorkerThreadFunc (internal)
3512 * Worker thread execution function
3517 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3519 LPWORKREQUEST lpRequest = lpvParam;
3520 WORKREQUEST workRequest;
3524 workRequest = *lpRequest;
3525 HeapFree(GetProcessHeap(), 0, lpRequest);
3527 workRequest.asyncproc(&workRequest);
3528 WININET_Release( workRequest.hdr );
3530 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3532 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
3533 TlsSetValue(g_dwTlsErrIndex, NULL);
3539 /***********************************************************************
3540 * INTERNET_AsyncCall (internal)
3542 * Retrieves work request from queue
3547 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3550 LPWORKREQUEST lpNewRequest;
3554 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3556 return ERROR_OUTOFMEMORY;
3558 *lpNewRequest = *lpWorkRequest;
3560 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3563 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3564 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3567 return ERROR_SUCCESS;
3571 /***********************************************************************
3572 * INTERNET_GetResponseBuffer (internal)
3577 LPSTR INTERNET_GetResponseBuffer(void)
3579 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3581 lpwite = INTERNET_AllocThreadError();
3583 return lpwite->response;
3586 /***********************************************************************
3587 * INTERNET_GetNextLine (internal)
3589 * Parse next line in directory string listing
3592 * Pointer to beginning of next line
3597 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3600 BOOL bSuccess = FALSE;
3602 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3607 pfd.events = POLLIN;
3609 while (nRecv < MAX_REPLY_LEN)
3611 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3613 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3615 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3619 if (lpszBuffer[nRecv] == '\n')
3624 if (lpszBuffer[nRecv] != '\r')
3629 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3637 lpszBuffer[nRecv] = '\0';
3639 TRACE(":%d %s\n", nRecv, lpszBuffer);
3648 /**********************************************************
3649 * InternetQueryDataAvailable (WININET.@)
3651 * Determines how much data is available to be read.
3654 * TRUE on success, FALSE if an error occurred. If
3655 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3656 * no data is presently available, FALSE is returned with
3657 * the last error ERROR_IO_PENDING; a callback with status
3658 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3659 * data is available.
3661 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3662 LPDWORD lpdwNumberOfBytesAvailble,
3663 DWORD dwFlags, DWORD_PTR dwContext)
3665 object_header_t *hdr;
3668 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3670 hdr = get_handle_object( hFile );
3672 SetLastError(ERROR_INVALID_HANDLE);
3676 if(hdr->vtbl->QueryDataAvailable) {
3677 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3679 WARN("wrong handle\n");
3680 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3683 WININET_Release(hdr);
3685 if(res != ERROR_SUCCESS)
3687 return res == ERROR_SUCCESS;
3691 /***********************************************************************
3692 * InternetLockRequestFile (WININET.@)
3694 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3701 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3708 /***********************************************************************
3709 * InternetAutodial (WININET.@)
3711 * On windows this function is supposed to dial the default internet
3712 * connection. We don't want to have Wine dial out to the internet so
3713 * we return TRUE by default. It might be nice to check if we are connected.
3720 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3724 /* Tell that we are connected to the internet. */
3728 /***********************************************************************
3729 * InternetAutodialHangup (WININET.@)
3731 * Hangs up a connection made with InternetAutodial
3740 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3744 /* we didn't dial, we don't disconnect */
3748 /***********************************************************************
3749 * InternetCombineUrlA (WININET.@)
3751 * Combine a base URL with a relative URL
3759 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3760 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3765 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3767 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3768 dwFlags ^= ICU_NO_ENCODE;
3769 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3774 /***********************************************************************
3775 * InternetCombineUrlW (WININET.@)
3777 * Combine a base URL with a relative URL
3785 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3786 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3791 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3793 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3794 dwFlags ^= ICU_NO_ENCODE;
3795 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3800 /* max port num is 65535 => 5 digits */
3801 #define MAX_WORD_DIGITS 5
3803 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3804 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3805 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3806 (url)->dw##component##Length : strlen((url)->lpsz##component))
3808 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3810 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3811 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3813 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3814 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3816 if ((nScheme == INTERNET_SCHEME_FTP) &&
3817 (nPort == INTERNET_DEFAULT_FTP_PORT))
3819 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3820 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3823 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3829 /* opaque urls do not fit into the standard url hierarchy and don't have
3830 * two following slashes */
3831 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3833 return (nScheme != INTERNET_SCHEME_FTP) &&
3834 (nScheme != INTERNET_SCHEME_GOPHER) &&
3835 (nScheme != INTERNET_SCHEME_HTTP) &&
3836 (nScheme != INTERNET_SCHEME_HTTPS) &&
3837 (nScheme != INTERNET_SCHEME_FILE);
3840 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3843 if (scheme < INTERNET_SCHEME_FIRST)
3845 index = scheme - INTERNET_SCHEME_FIRST;
3846 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3848 return (LPCWSTR)url_schemes[index];
3851 /* we can calculate using ansi strings because we're just
3852 * calculating string length, not size
3854 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3855 LPDWORD lpdwUrlLength)
3857 INTERNET_SCHEME nScheme;
3861 if (lpUrlComponents->lpszScheme)
3863 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3864 *lpdwUrlLength += dwLen;
3865 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3871 nScheme = lpUrlComponents->nScheme;
3873 if (nScheme == INTERNET_SCHEME_DEFAULT)
3874 nScheme = INTERNET_SCHEME_HTTP;
3875 scheme = INTERNET_GetSchemeString(nScheme);
3876 *lpdwUrlLength += strlenW(scheme);
3879 (*lpdwUrlLength)++; /* ':' */
3880 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3881 *lpdwUrlLength += strlen("//");
3883 if (lpUrlComponents->lpszUserName)
3885 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3886 *lpdwUrlLength += strlen("@");
3890 if (lpUrlComponents->lpszPassword)
3892 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3897 if (lpUrlComponents->lpszPassword)
3899 *lpdwUrlLength += strlen(":");
3900 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3903 if (lpUrlComponents->lpszHostName)
3905 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3907 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3909 char szPort[MAX_WORD_DIGITS+1];
3911 sprintf(szPort, "%d", lpUrlComponents->nPort);
3912 *lpdwUrlLength += strlen(szPort);
3913 *lpdwUrlLength += strlen(":");
3916 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3917 (*lpdwUrlLength)++; /* '/' */
3920 if (lpUrlComponents->lpszUrlPath)
3921 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3923 if (lpUrlComponents->lpszExtraInfo)
3924 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3929 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3933 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3935 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3936 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3937 urlCompW->nScheme = lpUrlComponents->nScheme;
3938 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3939 urlCompW->nPort = lpUrlComponents->nPort;
3940 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3941 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3942 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3943 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3945 if (lpUrlComponents->lpszScheme)
3947 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3948 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3949 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3950 -1, urlCompW->lpszScheme, len);
3953 if (lpUrlComponents->lpszHostName)
3955 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3956 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3957 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3958 -1, urlCompW->lpszHostName, len);
3961 if (lpUrlComponents->lpszUserName)
3963 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3964 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3965 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3966 -1, urlCompW->lpszUserName, len);
3969 if (lpUrlComponents->lpszPassword)
3971 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3972 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3973 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3974 -1, urlCompW->lpszPassword, len);
3977 if (lpUrlComponents->lpszUrlPath)
3979 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3980 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3981 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3982 -1, urlCompW->lpszUrlPath, len);
3985 if (lpUrlComponents->lpszExtraInfo)
3987 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3988 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3989 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3990 -1, urlCompW->lpszExtraInfo, len);
3994 /***********************************************************************
3995 * InternetCreateUrlA (WININET.@)
3997 * See InternetCreateUrlW.
3999 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4000 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4004 URL_COMPONENTSW urlCompW;
4006 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4008 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4010 SetLastError(ERROR_INVALID_PARAMETER);
4014 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4017 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
4019 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4021 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4022 *lpdwUrlLength /= sizeof(WCHAR);
4024 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4025 * minus one, so add one to leave room for NULL terminator
4028 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4030 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
4031 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
4032 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
4033 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
4034 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
4035 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
4036 HeapFree(GetProcessHeap(), 0, urlW);
4041 /***********************************************************************
4042 * InternetCreateUrlW (WININET.@)
4044 * Creates a URL from its component parts.
4047 * lpUrlComponents [I] URL Components.
4048 * dwFlags [I] Flags. See notes.
4049 * lpszUrl [I] Buffer in which to store the created URL.
4050 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4051 * lpszUrl in characters. On output, the number of bytes
4052 * required to store the URL including terminator.
4056 * The dwFlags parameter can be zero or more of the following:
4057 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4064 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4065 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4068 INTERNET_SCHEME nScheme;
4070 static const WCHAR slashSlashW[] = {'/','/'};
4071 static const WCHAR fmtW[] = {'%','u',0};
4073 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4075 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4077 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4081 if (!calc_url_length(lpUrlComponents, &dwLen))
4084 if (!lpszUrl || *lpdwUrlLength < dwLen)
4086 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4087 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4091 *lpdwUrlLength = dwLen;
4096 if (lpUrlComponents->lpszScheme)
4098 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4099 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4102 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4107 nScheme = lpUrlComponents->nScheme;
4109 if (nScheme == INTERNET_SCHEME_DEFAULT)
4110 nScheme = INTERNET_SCHEME_HTTP;
4112 scheme = INTERNET_GetSchemeString(nScheme);
4113 dwLen = strlenW(scheme);
4114 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4118 /* all schemes are followed by at least a colon */
4122 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4124 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4125 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4128 if (lpUrlComponents->lpszUserName)
4130 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4131 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4134 if (lpUrlComponents->lpszPassword)
4139 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4140 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4148 if (lpUrlComponents->lpszHostName)
4150 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4151 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4154 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4156 WCHAR szPort[MAX_WORD_DIGITS+1];
4158 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4161 dwLen = strlenW(szPort);
4162 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4166 /* add slash between hostname and path if necessary */
4167 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4174 if (lpUrlComponents->lpszUrlPath)
4176 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4177 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4181 if (lpUrlComponents->lpszExtraInfo)
4183 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4184 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4193 /***********************************************************************
4194 * InternetConfirmZoneCrossingA (WININET.@)
4197 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4199 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4200 return ERROR_SUCCESS;
4203 /***********************************************************************
4204 * InternetConfirmZoneCrossingW (WININET.@)
4207 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4209 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4210 return ERROR_SUCCESS;
4213 static DWORD zone_preference = 3;
4215 /***********************************************************************
4216 * PrivacySetZonePreferenceW (WININET.@)
4218 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4220 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4222 zone_preference = template;
4226 /***********************************************************************
4227 * PrivacyGetZonePreferenceW (WININET.@)
4229 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4230 LPWSTR preference, LPDWORD length )
4232 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4234 if (template) *template = zone_preference;
4238 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4239 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4241 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4242 lpdwConnection, dwReserved);
4243 return ERROR_SUCCESS;
4246 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4247 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4249 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4250 lpdwConnection, dwReserved);
4251 return ERROR_SUCCESS;
4254 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4256 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4260 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4262 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4266 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4268 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4269 return ERROR_SUCCESS;
4272 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4275 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4276 debugstr_w(pwszTarget), pbHexHash);
4280 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4282 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4286 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4288 FIXME("(%p, %08lx) stub\n", a, b);