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 = heap_alloc(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 = heap_alloc(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 = heap_alloc(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 = heap_alloc((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 = heap_alloc(UCW.dwHostNameLength * sizeof(WCHAR));
1372 UCW.lpszHostName = hostname;
1375 if (lpUrlComponents->dwUserNameLength)
1377 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1378 if (lpUrlComponents->lpszUserName)
1380 username = heap_alloc(UCW.dwUserNameLength * sizeof(WCHAR));
1381 UCW.lpszUserName = username;
1384 if (lpUrlComponents->dwPasswordLength)
1386 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1387 if (lpUrlComponents->lpszPassword)
1389 password = heap_alloc(UCW.dwPasswordLength * sizeof(WCHAR));
1390 UCW.lpszPassword = password;
1393 if (lpUrlComponents->dwUrlPathLength)
1395 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1396 if (lpUrlComponents->lpszUrlPath)
1398 path = heap_alloc(UCW.dwUrlPathLength * sizeof(WCHAR));
1399 UCW.lpszUrlPath = path;
1402 if (lpUrlComponents->dwSchemeLength)
1404 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1405 if (lpUrlComponents->lpszScheme)
1407 scheme = heap_alloc(UCW.dwSchemeLength * sizeof(WCHAR));
1408 UCW.lpszScheme = scheme;
1411 if (lpUrlComponents->dwExtraInfoLength)
1413 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1414 if (lpUrlComponents->lpszExtraInfo)
1416 extra = heap_alloc(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 = heap_alloc(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 = heap_alloc(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:
2597 case INTERNET_OPTION_DATA_SEND_TIMEOUT:
2599 ULONG timeout = *(ULONG *)lpBuffer;
2600 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT/DATA_SEND_TIMEOUT %d\n", timeout);
2603 case INTERNET_OPTION_CONNECT_RETRIES:
2605 ULONG retries = *(ULONG *)lpBuffer;
2606 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2609 case INTERNET_OPTION_CONTEXT_VALUE:
2613 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2616 if (!lpBuffer || dwBufferLength != sizeof(DWORD_PTR))
2618 SetLastError(ERROR_INVALID_PARAMETER);
2622 lpwhh->dwContext = *(DWORD_PTR *)lpBuffer;
2625 case INTERNET_OPTION_SECURITY_FLAGS:
2626 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2628 case INTERNET_OPTION_DISABLE_AUTODIAL:
2629 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2631 case INTERNET_OPTION_HTTP_DECODING:
2632 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2633 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2636 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2637 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2638 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2641 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2642 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2643 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2646 case INTERNET_OPTION_CODEPAGE_PATH:
2647 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2648 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2651 case INTERNET_OPTION_CODEPAGE_EXTRA:
2652 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2653 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2656 case INTERNET_OPTION_IDN:
2657 FIXME("INTERNET_OPTION_IDN; STUB\n");
2658 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2661 case INTERNET_OPTION_POLICY:
2662 SetLastError(ERROR_INVALID_PARAMETER);
2665 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2666 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2671 INTERNET_LoadProxySettings(&pi);
2673 for (i = 0; i < con->dwOptionCount; i++) {
2674 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2676 switch (option->dwOption) {
2677 case INTERNET_PER_CONN_PROXY_SERVER:
2678 HeapFree(GetProcessHeap(), 0, pi.lpszProxyServer);
2679 pi.lpszProxyServer = heap_strdupW(option->Value.pszValue);
2682 case INTERNET_PER_CONN_FLAGS:
2683 if(option->Value.dwValue & PROXY_TYPE_PROXY)
2684 pi.dwProxyEnabled = 1;
2687 if(option->Value.dwValue != PROXY_TYPE_DIRECT)
2688 FIXME("Unhandled flags: 0x%x\n", option->Value.dwValue);
2689 pi.dwProxyEnabled = 0;
2693 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2694 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2695 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2696 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2697 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2698 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2699 case INTERNET_PER_CONN_PROXY_BYPASS:
2700 FIXME("Unhandled dwOption %d\n", option->dwOption);
2704 FIXME("Unknown dwOption %d\n", option->dwOption);
2705 SetLastError(ERROR_INVALID_PARAMETER);
2710 if ((res = INTERNET_SaveProxySettings(&pi)))
2715 ret = (res == ERROR_SUCCESS);
2719 FIXME("Option %d STUB\n",dwOption);
2720 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2726 WININET_Release( lpwhh );
2732 /***********************************************************************
2733 * InternetSetOptionA (WININET.@)
2735 * Sets an options on the specified handle.
2742 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2743 LPVOID lpBuffer, DWORD dwBufferLength)
2751 case INTERNET_OPTION_CALLBACK:
2753 object_header_t *lpwh;
2755 if (!(lpwh = get_handle_object(hInternet)))
2757 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2760 WININET_Release(lpwh);
2761 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2764 case INTERNET_OPTION_PROXY:
2766 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2767 LPINTERNET_PROXY_INFOW piw;
2768 DWORD proxlen, prbylen;
2771 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2772 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2773 wlen = sizeof(*piw) + proxlen + prbylen;
2774 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2775 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2776 piw->dwAccessType = pi->dwAccessType;
2777 prox = (LPWSTR) &piw[1];
2778 prby = &prox[proxlen+1];
2779 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2780 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2781 piw->lpszProxy = prox;
2782 piw->lpszProxyBypass = prby;
2785 case INTERNET_OPTION_USER_AGENT:
2786 case INTERNET_OPTION_USERNAME:
2787 case INTERNET_OPTION_PASSWORD:
2788 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2790 wbuffer = heap_alloc(wlen*sizeof(WCHAR) );
2791 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2794 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2796 INTERNET_PER_CONN_OPTION_LISTW *listW;
2797 INTERNET_PER_CONN_OPTION_LISTA *listA = lpBuffer;
2798 wlen = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2799 wbuffer = heap_alloc(wlen);
2802 listW->dwSize = sizeof(INTERNET_PER_CONN_OPTION_LISTW);
2803 if (listA->pszConnection)
2805 wlen = MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, NULL, 0 );
2806 listW->pszConnection = heap_alloc(wlen*sizeof(WCHAR));
2807 MultiByteToWideChar( CP_ACP, 0, listA->pszConnection, -1, listW->pszConnection, wlen );
2810 listW->pszConnection = NULL;
2811 listW->dwOptionCount = listA->dwOptionCount;
2812 listW->dwOptionError = listA->dwOptionError;
2813 listW->pOptions = heap_alloc(sizeof(INTERNET_PER_CONN_OPTIONW) * listA->dwOptionCount);
2815 for (i = 0; i < listA->dwOptionCount; ++i) {
2816 INTERNET_PER_CONN_OPTIONA *optA = listA->pOptions + i;
2817 INTERNET_PER_CONN_OPTIONW *optW = listW->pOptions + i;
2819 optW->dwOption = optA->dwOption;
2821 switch (optA->dwOption) {
2822 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2823 case INTERNET_PER_CONN_PROXY_BYPASS:
2824 case INTERNET_PER_CONN_PROXY_SERVER:
2825 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2826 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2827 if (optA->Value.pszValue)
2829 wlen = MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, NULL, 0 );
2830 optW->Value.pszValue = heap_alloc(wlen*sizeof(WCHAR));
2831 MultiByteToWideChar( CP_ACP, 0, optA->Value.pszValue, -1, optW->Value.pszValue, wlen );
2834 optW->Value.pszValue = NULL;
2836 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2837 case INTERNET_PER_CONN_FLAGS:
2838 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2839 optW->Value.dwValue = optA->Value.dwValue;
2841 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2842 optW->Value.ftValue = optA->Value.ftValue;
2845 WARN("Unknown PER_CONN dwOption: %d, guessing at conversion to Wide\n", optA->dwOption);
2846 optW->Value.dwValue = optA->Value.dwValue;
2854 wlen = dwBufferLength;
2857 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2859 if( lpBuffer != wbuffer )
2861 if (dwOption == INTERNET_OPTION_PER_CONNECTION_OPTION)
2863 INTERNET_PER_CONN_OPTION_LISTW *list = wbuffer;
2865 for (i = 0; i < list->dwOptionCount; ++i) {
2866 INTERNET_PER_CONN_OPTIONW *opt = list->pOptions + i;
2867 switch (opt->dwOption) {
2868 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2869 case INTERNET_PER_CONN_PROXY_BYPASS:
2870 case INTERNET_PER_CONN_PROXY_SERVER:
2871 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2872 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2873 HeapFree( GetProcessHeap(), 0, opt->Value.pszValue );
2879 HeapFree( GetProcessHeap(), 0, list->pOptions );
2881 HeapFree( GetProcessHeap(), 0, wbuffer );
2888 /***********************************************************************
2889 * InternetSetOptionExA (WININET.@)
2891 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2892 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2894 FIXME("Flags %08x ignored\n", dwFlags);
2895 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2898 /***********************************************************************
2899 * InternetSetOptionExW (WININET.@)
2901 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2902 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2904 FIXME("Flags %08x ignored\n", dwFlags);
2905 if( dwFlags & ~ISO_VALID_FLAGS )
2907 SetLastError( ERROR_INVALID_PARAMETER );
2910 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2913 static const WCHAR WININET_wkday[7][4] =
2914 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2915 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2916 static const WCHAR WININET_month[12][4] =
2917 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2918 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2919 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2921 /***********************************************************************
2922 * InternetTimeFromSystemTimeA (WININET.@)
2924 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2927 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2929 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2931 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2933 SetLastError(ERROR_INVALID_PARAMETER);
2937 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2939 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2943 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2944 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2949 /***********************************************************************
2950 * InternetTimeFromSystemTimeW (WININET.@)
2952 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2954 static const WCHAR date[] =
2955 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2956 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2958 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2960 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2962 SetLastError(ERROR_INVALID_PARAMETER);
2966 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2968 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2972 sprintfW( string, date,
2973 WININET_wkday[time->wDayOfWeek],
2975 WININET_month[time->wMonth - 1],
2984 /***********************************************************************
2985 * InternetTimeToSystemTimeA (WININET.@)
2987 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2992 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2994 stringW = heap_strdupAtoW(string);
2997 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2998 HeapFree( GetProcessHeap(), 0, stringW );
3003 /***********************************************************************
3004 * InternetTimeToSystemTimeW (WININET.@)
3006 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
3009 const WCHAR *s = string;
3012 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
3014 if (!string || !time) return FALSE;
3016 /* Windows does this too */
3017 GetSystemTime( time );
3019 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
3020 * a SYSTEMTIME structure.
3023 while (*s && !isalphaW( *s )) s++;
3024 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3025 time->wDayOfWeek = 7;
3027 for (i = 0; i < 7; i++)
3029 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
3030 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
3031 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
3033 time->wDayOfWeek = i;
3038 if (time->wDayOfWeek > 6) return TRUE;
3039 while (*s && !isdigitW( *s )) s++;
3040 time->wDay = strtolW( s, &end, 10 );
3043 while (*s && !isalphaW( *s )) s++;
3044 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
3047 for (i = 0; i < 12; i++)
3049 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
3050 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
3051 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
3053 time->wMonth = i + 1;
3057 if (time->wMonth == 0) return TRUE;
3059 while (*s && !isdigitW( *s )) s++;
3060 if (*s == '\0') return TRUE;
3061 time->wYear = strtolW( s, &end, 10 );
3064 while (*s && !isdigitW( *s )) s++;
3065 if (*s == '\0') return TRUE;
3066 time->wHour = strtolW( s, &end, 10 );
3069 while (*s && !isdigitW( *s )) s++;
3070 if (*s == '\0') return TRUE;
3071 time->wMinute = strtolW( s, &end, 10 );
3074 while (*s && !isdigitW( *s )) s++;
3075 if (*s == '\0') return TRUE;
3076 time->wSecond = strtolW( s, &end, 10 );
3079 time->wMilliseconds = 0;
3083 /***********************************************************************
3084 * InternetCheckConnectionW (WININET.@)
3086 * Pings a requested host to check internet connection
3089 * TRUE on success and FALSE on failure. If a failure then
3090 * ERROR_NOT_CONNECTED is placed into GetLastError
3093 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
3096 * this is a kludge which runs the resident ping program and reads the output.
3098 * Anyone have a better idea?
3102 static const CHAR ping[] = "ping -c 1 ";
3103 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
3104 CHAR *command = NULL;
3113 * Crack or set the Address
3115 if (lpszUrl == NULL)
3118 * According to the doc we are supposed to use the ip for the next
3119 * server in the WnInet internal server database. I have
3120 * no idea what that is or how to get it.
3122 * So someone needs to implement this.
3124 FIXME("Unimplemented with URL of NULL\n");
3129 URL_COMPONENTSW components;
3131 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
3132 components.lpszHostName = (LPWSTR)hostW;
3133 components.dwHostNameLength = 1024;
3135 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
3138 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
3139 port = components.nPort;
3140 TRACE("port: %d\n", port);
3143 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
3145 struct sockaddr_storage saddr;
3146 socklen_t sa_len = sizeof(saddr);
3149 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
3151 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
3154 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
3162 * Build our ping command
3164 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
3165 command = heap_alloc(strlen(ping)+len+strlen(redirect));
3166 strcpy(command,ping);
3167 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
3168 strcat(command,redirect);
3170 TRACE("Ping command is : %s\n",command);
3172 status = system(command);
3174 TRACE("Ping returned a code of %i\n",status);
3176 /* Ping return code of 0 indicates success */
3183 HeapFree( GetProcessHeap(), 0, command );
3185 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
3191 /***********************************************************************
3192 * InternetCheckConnectionA (WININET.@)
3194 * Pings a requested host to check internet connection
3197 * TRUE on success and FALSE on failure. If a failure then
3198 * ERROR_NOT_CONNECTED is placed into GetLastError
3201 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
3207 url = heap_strdupAtoW(lpszUrl);
3212 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
3214 HeapFree(GetProcessHeap(), 0, url);
3219 /**********************************************************
3220 * INTERNET_InternetOpenUrlW (internal)
3225 * handle of connection or NULL on failure
3227 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
3228 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3230 URL_COMPONENTSW urlComponents;
3231 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
3232 WCHAR password[1024], path[2048], extra[1024];
3233 HINTERNET client = NULL, client1 = NULL;
3236 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3237 dwHeadersLength, dwFlags, dwContext);
3239 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
3240 urlComponents.lpszScheme = protocol;
3241 urlComponents.dwSchemeLength = 32;
3242 urlComponents.lpszHostName = hostName;
3243 urlComponents.dwHostNameLength = MAXHOSTNAME;
3244 urlComponents.lpszUserName = userName;
3245 urlComponents.dwUserNameLength = 1024;
3246 urlComponents.lpszPassword = password;
3247 urlComponents.dwPasswordLength = 1024;
3248 urlComponents.lpszUrlPath = path;
3249 urlComponents.dwUrlPathLength = 2048;
3250 urlComponents.lpszExtraInfo = extra;
3251 urlComponents.dwExtraInfoLength = 1024;
3252 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
3254 switch(urlComponents.nScheme) {
3255 case INTERNET_SCHEME_FTP:
3256 if(urlComponents.nPort == 0)
3257 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
3258 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
3259 userName, password, dwFlags, dwContext, INET_OPENURL);
3262 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
3263 if(client1 == NULL) {
3264 InternetCloseHandle(client);
3269 case INTERNET_SCHEME_HTTP:
3270 case INTERNET_SCHEME_HTTPS: {
3271 static const WCHAR szStars[] = { '*','/','*', 0 };
3272 LPCWSTR accept[2] = { szStars, NULL };
3273 if(urlComponents.nPort == 0) {
3274 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
3275 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
3277 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
3279 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
3281 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
3282 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
3283 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
3284 if(res != ERROR_SUCCESS) {
3285 INTERNET_SetLastError(res);
3289 if (urlComponents.dwExtraInfoLength) {
3291 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
3293 if (!(path_extra = heap_alloc(len * sizeof(WCHAR))))
3295 InternetCloseHandle(client);
3298 strcpyW(path_extra, urlComponents.lpszUrlPath);
3299 strcatW(path_extra, urlComponents.lpszExtraInfo);
3300 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
3301 HeapFree(GetProcessHeap(), 0, path_extra);
3304 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
3306 if(client1 == NULL) {
3307 InternetCloseHandle(client);
3310 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
3311 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
3312 GetLastError() != ERROR_IO_PENDING) {
3313 InternetCloseHandle(client1);
3318 case INTERNET_SCHEME_GOPHER:
3319 /* gopher doesn't seem to be implemented in wine, but it's supposed
3320 * to be supported by InternetOpenUrlA. */
3322 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
3326 TRACE(" %p <--\n", client1);
3331 /**********************************************************
3332 * InternetOpenUrlW (WININET.@)
3337 * handle of connection or NULL on failure
3339 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3341 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3342 appinfo_t *hIC = (appinfo_t*) workRequest->hdr;
3346 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3347 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3348 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3349 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3352 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3353 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3355 HINTERNET ret = NULL;
3356 appinfo_t *hIC = NULL;
3358 if (TRACE_ON(wininet)) {
3359 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3360 dwHeadersLength, dwFlags, dwContext);
3362 dump_INTERNET_FLAGS(dwFlags);
3367 SetLastError(ERROR_INVALID_PARAMETER);
3371 hIC = (appinfo_t*)get_handle_object( hInternet );
3372 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3373 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3377 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3378 WORKREQUEST workRequest;
3379 struct WORKREQ_INTERNETOPENURLW *req;
3381 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3382 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3383 req = &workRequest.u.InternetOpenUrlW;
3384 req->lpszUrl = heap_strdupW(lpszUrl);
3385 req->lpszHeaders = heap_strdupW(lpszHeaders);
3386 req->dwHeadersLength = dwHeadersLength;
3387 req->dwFlags = dwFlags;
3388 req->dwContext = dwContext;
3390 INTERNET_AsyncCall(&workRequest);
3392 * This is from windows.
3394 SetLastError(ERROR_IO_PENDING);
3396 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3401 WININET_Release( &hIC->hdr );
3402 TRACE(" %p <--\n", ret);
3407 /**********************************************************
3408 * InternetOpenUrlA (WININET.@)
3413 * handle of connection or NULL on failure
3415 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3416 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3418 HINTERNET rc = NULL;
3419 DWORD lenHeaders = 0;
3420 LPWSTR szUrl = NULL;
3421 LPWSTR szHeaders = NULL;
3426 szUrl = heap_strdupAtoW(lpszUrl);
3432 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3433 szHeaders = heap_alloc(lenHeaders*sizeof(WCHAR));
3435 HeapFree(GetProcessHeap(), 0, szUrl);
3438 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3441 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3442 lenHeaders, dwFlags, dwContext);
3444 HeapFree(GetProcessHeap(), 0, szUrl);
3445 HeapFree(GetProcessHeap(), 0, szHeaders);
3451 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3453 LPWITHREADERROR lpwite = heap_alloc(sizeof(*lpwite));
3457 lpwite->dwError = 0;
3458 lpwite->response[0] = '\0';
3461 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3463 HeapFree(GetProcessHeap(), 0, lpwite);
3471 /***********************************************************************
3472 * INTERNET_SetLastError (internal)
3474 * Set last thread specific error
3479 void INTERNET_SetLastError(DWORD dwError)
3481 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3484 lpwite = INTERNET_AllocThreadError();
3486 SetLastError(dwError);
3488 lpwite->dwError = dwError;
3492 /***********************************************************************
3493 * INTERNET_GetLastError (internal)
3495 * Get last thread specific error
3500 DWORD INTERNET_GetLastError(void)
3502 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3503 if (!lpwite) return 0;
3504 /* TlsGetValue clears last error, so set it again here */
3505 SetLastError(lpwite->dwError);
3506 return lpwite->dwError;
3510 /***********************************************************************
3511 * INTERNET_WorkerThreadFunc (internal)
3513 * Worker thread execution function
3518 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3520 LPWORKREQUEST lpRequest = lpvParam;
3521 WORKREQUEST workRequest;
3525 workRequest = *lpRequest;
3526 HeapFree(GetProcessHeap(), 0, lpRequest);
3528 workRequest.asyncproc(&workRequest);
3529 WININET_Release( workRequest.hdr );
3531 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3533 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
3534 TlsSetValue(g_dwTlsErrIndex, NULL);
3540 /***********************************************************************
3541 * INTERNET_AsyncCall (internal)
3543 * Retrieves work request from queue
3548 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3551 LPWORKREQUEST lpNewRequest;
3555 lpNewRequest = heap_alloc(sizeof(WORKREQUEST));
3557 return ERROR_OUTOFMEMORY;
3559 *lpNewRequest = *lpWorkRequest;
3561 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3564 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3565 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3568 return ERROR_SUCCESS;
3572 /***********************************************************************
3573 * INTERNET_GetResponseBuffer (internal)
3578 LPSTR INTERNET_GetResponseBuffer(void)
3580 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3582 lpwite = INTERNET_AllocThreadError();
3584 return lpwite->response;
3587 /***********************************************************************
3588 * INTERNET_GetNextLine (internal)
3590 * Parse next line in directory string listing
3593 * Pointer to beginning of next line
3598 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3601 BOOL bSuccess = FALSE;
3603 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3608 pfd.events = POLLIN;
3610 while (nRecv < MAX_REPLY_LEN)
3612 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3614 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3616 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3620 if (lpszBuffer[nRecv] == '\n')
3625 if (lpszBuffer[nRecv] != '\r')
3630 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3638 lpszBuffer[nRecv] = '\0';
3640 TRACE(":%d %s\n", nRecv, lpszBuffer);
3649 /**********************************************************
3650 * InternetQueryDataAvailable (WININET.@)
3652 * Determines how much data is available to be read.
3655 * TRUE on success, FALSE if an error occurred. If
3656 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3657 * no data is presently available, FALSE is returned with
3658 * the last error ERROR_IO_PENDING; a callback with status
3659 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3660 * data is available.
3662 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3663 LPDWORD lpdwNumberOfBytesAvailble,
3664 DWORD dwFlags, DWORD_PTR dwContext)
3666 object_header_t *hdr;
3669 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3671 hdr = get_handle_object( hFile );
3673 SetLastError(ERROR_INVALID_HANDLE);
3677 if(hdr->vtbl->QueryDataAvailable) {
3678 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3680 WARN("wrong handle\n");
3681 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3684 WININET_Release(hdr);
3686 if(res != ERROR_SUCCESS)
3688 return res == ERROR_SUCCESS;
3692 /***********************************************************************
3693 * InternetLockRequestFile (WININET.@)
3695 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3702 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3709 /***********************************************************************
3710 * InternetAutodial (WININET.@)
3712 * On windows this function is supposed to dial the default internet
3713 * connection. We don't want to have Wine dial out to the internet so
3714 * we return TRUE by default. It might be nice to check if we are connected.
3721 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3725 /* Tell that we are connected to the internet. */
3729 /***********************************************************************
3730 * InternetAutodialHangup (WININET.@)
3732 * Hangs up a connection made with InternetAutodial
3741 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3745 /* we didn't dial, we don't disconnect */
3749 /***********************************************************************
3750 * InternetCombineUrlA (WININET.@)
3752 * Combine a base URL with a relative URL
3760 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3761 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3766 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3768 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3769 dwFlags ^= ICU_NO_ENCODE;
3770 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3775 /***********************************************************************
3776 * InternetCombineUrlW (WININET.@)
3778 * Combine a base URL with a relative URL
3786 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3787 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3792 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3794 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3795 dwFlags ^= ICU_NO_ENCODE;
3796 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3801 /* max port num is 65535 => 5 digits */
3802 #define MAX_WORD_DIGITS 5
3804 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3805 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3806 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3807 (url)->dw##component##Length : strlen((url)->lpsz##component))
3809 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3811 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3812 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3814 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3815 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3817 if ((nScheme == INTERNET_SCHEME_FTP) &&
3818 (nPort == INTERNET_DEFAULT_FTP_PORT))
3820 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3821 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3824 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3830 /* opaque urls do not fit into the standard url hierarchy and don't have
3831 * two following slashes */
3832 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3834 return (nScheme != INTERNET_SCHEME_FTP) &&
3835 (nScheme != INTERNET_SCHEME_GOPHER) &&
3836 (nScheme != INTERNET_SCHEME_HTTP) &&
3837 (nScheme != INTERNET_SCHEME_HTTPS) &&
3838 (nScheme != INTERNET_SCHEME_FILE);
3841 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3844 if (scheme < INTERNET_SCHEME_FIRST)
3846 index = scheme - INTERNET_SCHEME_FIRST;
3847 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3849 return (LPCWSTR)url_schemes[index];
3852 /* we can calculate using ansi strings because we're just
3853 * calculating string length, not size
3855 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3856 LPDWORD lpdwUrlLength)
3858 INTERNET_SCHEME nScheme;
3862 if (lpUrlComponents->lpszScheme)
3864 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3865 *lpdwUrlLength += dwLen;
3866 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3872 nScheme = lpUrlComponents->nScheme;
3874 if (nScheme == INTERNET_SCHEME_DEFAULT)
3875 nScheme = INTERNET_SCHEME_HTTP;
3876 scheme = INTERNET_GetSchemeString(nScheme);
3877 *lpdwUrlLength += strlenW(scheme);
3880 (*lpdwUrlLength)++; /* ':' */
3881 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3882 *lpdwUrlLength += strlen("//");
3884 if (lpUrlComponents->lpszUserName)
3886 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3887 *lpdwUrlLength += strlen("@");
3891 if (lpUrlComponents->lpszPassword)
3893 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3898 if (lpUrlComponents->lpszPassword)
3900 *lpdwUrlLength += strlen(":");
3901 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3904 if (lpUrlComponents->lpszHostName)
3906 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3908 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3910 char szPort[MAX_WORD_DIGITS+1];
3912 sprintf(szPort, "%d", lpUrlComponents->nPort);
3913 *lpdwUrlLength += strlen(szPort);
3914 *lpdwUrlLength += strlen(":");
3917 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3918 (*lpdwUrlLength)++; /* '/' */
3921 if (lpUrlComponents->lpszUrlPath)
3922 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3924 if (lpUrlComponents->lpszExtraInfo)
3925 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3930 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3934 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3936 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3937 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3938 urlCompW->nScheme = lpUrlComponents->nScheme;
3939 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3940 urlCompW->nPort = lpUrlComponents->nPort;
3941 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3942 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3943 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3944 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3946 if (lpUrlComponents->lpszScheme)
3948 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3949 urlCompW->lpszScheme = heap_alloc(len * sizeof(WCHAR));
3950 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3951 -1, urlCompW->lpszScheme, len);
3954 if (lpUrlComponents->lpszHostName)
3956 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3957 urlCompW->lpszHostName = heap_alloc(len * sizeof(WCHAR));
3958 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3959 -1, urlCompW->lpszHostName, len);
3962 if (lpUrlComponents->lpszUserName)
3964 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3965 urlCompW->lpszUserName = heap_alloc(len * sizeof(WCHAR));
3966 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3967 -1, urlCompW->lpszUserName, len);
3970 if (lpUrlComponents->lpszPassword)
3972 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3973 urlCompW->lpszPassword = heap_alloc(len * sizeof(WCHAR));
3974 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3975 -1, urlCompW->lpszPassword, len);
3978 if (lpUrlComponents->lpszUrlPath)
3980 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3981 urlCompW->lpszUrlPath = heap_alloc(len * sizeof(WCHAR));
3982 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3983 -1, urlCompW->lpszUrlPath, len);
3986 if (lpUrlComponents->lpszExtraInfo)
3988 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3989 urlCompW->lpszExtraInfo = heap_alloc(len * sizeof(WCHAR));
3990 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3991 -1, urlCompW->lpszExtraInfo, len);
3995 /***********************************************************************
3996 * InternetCreateUrlA (WININET.@)
3998 * See InternetCreateUrlW.
4000 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
4001 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
4005 URL_COMPONENTSW urlCompW;
4007 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4009 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4011 SetLastError(ERROR_INVALID_PARAMETER);
4015 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
4018 urlW = heap_alloc(*lpdwUrlLength * sizeof(WCHAR));
4020 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
4022 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
4023 *lpdwUrlLength /= sizeof(WCHAR);
4025 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
4026 * minus one, so add one to leave room for NULL terminator
4029 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
4031 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
4032 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
4033 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
4034 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
4035 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
4036 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
4037 HeapFree(GetProcessHeap(), 0, urlW);
4042 /***********************************************************************
4043 * InternetCreateUrlW (WININET.@)
4045 * Creates a URL from its component parts.
4048 * lpUrlComponents [I] URL Components.
4049 * dwFlags [I] Flags. See notes.
4050 * lpszUrl [I] Buffer in which to store the created URL.
4051 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
4052 * lpszUrl in characters. On output, the number of bytes
4053 * required to store the URL including terminator.
4057 * The dwFlags parameter can be zero or more of the following:
4058 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
4065 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
4066 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
4069 INTERNET_SCHEME nScheme;
4071 static const WCHAR slashSlashW[] = {'/','/'};
4072 static const WCHAR fmtW[] = {'%','u',0};
4074 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4076 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4078 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
4082 if (!calc_url_length(lpUrlComponents, &dwLen))
4085 if (!lpszUrl || *lpdwUrlLength < dwLen)
4087 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4088 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
4092 *lpdwUrlLength = dwLen;
4097 if (lpUrlComponents->lpszScheme)
4099 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4100 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4103 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4108 nScheme = lpUrlComponents->nScheme;
4110 if (nScheme == INTERNET_SCHEME_DEFAULT)
4111 nScheme = INTERNET_SCHEME_HTTP;
4113 scheme = INTERNET_GetSchemeString(nScheme);
4114 dwLen = strlenW(scheme);
4115 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4119 /* all schemes are followed by at least a colon */
4123 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4125 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4126 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4129 if (lpUrlComponents->lpszUserName)
4131 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4132 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4135 if (lpUrlComponents->lpszPassword)
4140 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4141 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4149 if (lpUrlComponents->lpszHostName)
4151 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4152 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4155 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4157 WCHAR szPort[MAX_WORD_DIGITS+1];
4159 sprintfW(szPort, fmtW, lpUrlComponents->nPort);
4162 dwLen = strlenW(szPort);
4163 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4167 /* add slash between hostname and path if necessary */
4168 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4175 if (lpUrlComponents->lpszUrlPath)
4177 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4178 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4182 if (lpUrlComponents->lpszExtraInfo)
4184 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
4185 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
4194 /***********************************************************************
4195 * InternetConfirmZoneCrossingA (WININET.@)
4198 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4200 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4201 return ERROR_SUCCESS;
4204 /***********************************************************************
4205 * InternetConfirmZoneCrossingW (WININET.@)
4208 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4210 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4211 return ERROR_SUCCESS;
4214 static DWORD zone_preference = 3;
4216 /***********************************************************************
4217 * PrivacySetZonePreferenceW (WININET.@)
4219 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
4221 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
4223 zone_preference = template;
4227 /***********************************************************************
4228 * PrivacyGetZonePreferenceW (WININET.@)
4230 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
4231 LPWSTR preference, LPDWORD length )
4233 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
4235 if (template) *template = zone_preference;
4239 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4240 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4242 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4243 lpdwConnection, dwReserved);
4244 return ERROR_SUCCESS;
4247 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4248 DWORD_PTR* lpdwConnection, DWORD dwReserved )
4250 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4251 lpdwConnection, dwReserved);
4252 return ERROR_SUCCESS;
4255 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4257 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4261 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4263 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4267 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
4269 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
4270 return ERROR_SUCCESS;
4273 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4276 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4277 debugstr_w(pwszTarget), pbHexHash);
4281 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4283 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
4287 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
4289 FIXME("(%p, %08lx) stub\n", a, b);