4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
34 #if defined(__MINGW32__) || defined (_MSC_VER)
41 #include <sys/types.h>
42 #ifdef HAVE_SYS_SOCKET_H
43 # include <sys/socket.h>
48 #ifdef HAVE_SYS_POLL_H
49 # include <sys/poll.h>
51 #ifdef HAVE_SYS_TIME_H
52 # include <sys/time.h>
68 #include "wine/debug.h"
70 #define NO_SHLWAPI_STREAM
73 #include "wine/exception.h"
78 #include "wine/unicode.h"
80 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
82 #define RESPONSE_TIMEOUT 30
87 CHAR response[MAX_REPLY_LEN];
88 } WITHREADERROR, *LPWITHREADERROR;
90 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
91 static HMODULE WININET_hModule;
93 #define HANDLE_CHUNK_SIZE 0x10
95 static CRITICAL_SECTION WININET_cs;
96 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
99 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
100 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
102 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
104 static object_header_t **WININET_Handles;
105 static UINT WININET_dwNextHandle;
106 static UINT WININET_dwMaxHandles;
108 HINTERNET WININET_AllocHandle( object_header_t *info )
111 UINT handle = 0, num;
113 list_init( &info->children );
115 EnterCriticalSection( &WININET_cs );
116 if( !WININET_dwMaxHandles )
118 num = HANDLE_CHUNK_SIZE;
119 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
120 sizeof (*WININET_Handles)* num);
124 WININET_dwMaxHandles = num;
126 if( WININET_dwMaxHandles == WININET_dwNextHandle )
128 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
129 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
130 WININET_Handles, sizeof (*WININET_Handles)* num);
134 WININET_dwMaxHandles = num;
137 handle = WININET_dwNextHandle;
138 if( WININET_Handles[handle] )
139 ERR("handle isn't free but should be\n");
140 WININET_Handles[handle] = WININET_AddRef( info );
142 while( WININET_Handles[WININET_dwNextHandle] &&
143 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
144 WININET_dwNextHandle++;
147 LeaveCriticalSection( &WININET_cs );
149 return info->hInternet = (HINTERNET) (handle+1);
152 object_header_t *WININET_AddRef( object_header_t *info )
154 ULONG refs = InterlockedIncrement(&info->refs);
155 TRACE("%p -> refcount = %d\n", info, refs );
159 object_header_t *WININET_GetObject( HINTERNET hinternet )
161 object_header_t *info = NULL;
162 UINT handle = (UINT) hinternet;
164 EnterCriticalSection( &WININET_cs );
166 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
167 WININET_Handles[handle-1] )
168 info = WININET_AddRef( WININET_Handles[handle-1] );
170 LeaveCriticalSection( &WININET_cs );
172 TRACE("handle %d -> %p\n", handle, info);
177 BOOL WININET_Release( object_header_t *info )
179 ULONG refs = InterlockedDecrement(&info->refs);
180 TRACE( "object %p refcount = %d\n", info, refs );
183 if ( info->vtbl->CloseConnection )
185 TRACE( "closing connection %p\n", info);
186 info->vtbl->CloseConnection( info );
188 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
189 if ((info->htype != WH_HHTTPSESSION && info->htype != WH_HFTPSESSION)
190 || !(info->dwInternalFlags & INET_OPENURL))
192 INTERNET_SendCallback(info, info->dwContext,
193 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
196 TRACE( "destroying object %p\n", info);
197 if ( info->htype != WH_HINIT )
198 list_remove( &info->entry );
199 info->vtbl->Destroy( info );
204 BOOL WININET_FreeHandle( HINTERNET hinternet )
207 UINT handle = (UINT) hinternet;
208 object_header_t *info = NULL, *child, *next;
210 EnterCriticalSection( &WININET_cs );
212 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
215 if( WININET_Handles[handle] )
217 info = WININET_Handles[handle];
218 TRACE( "destroying handle %d for object %p\n", handle+1, info);
219 WININET_Handles[handle] = NULL;
224 LeaveCriticalSection( &WININET_cs );
226 /* As on native when the equivalent of WININET_Release is called, the handle
227 * is already invalid, but if a new handle is created at this time it does
228 * not yet get assigned the freed handle number */
231 /* Free all children as native does */
232 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, object_header_t, entry )
234 TRACE( "freeing child handle %d for parent handle %d\n",
235 (UINT)child->hInternet, handle+1);
236 WININET_FreeHandle( child->hInternet );
238 WININET_Release( info );
241 EnterCriticalSection( &WININET_cs );
243 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
244 WININET_dwNextHandle = handle;
246 LeaveCriticalSection( &WININET_cs );
251 /***********************************************************************
252 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
255 * hinstDLL [I] handle to the DLL's instance
257 * lpvReserved [I] reserved, must be NULL
264 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
266 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
269 case DLL_PROCESS_ATTACH:
271 g_dwTlsErrIndex = TlsAlloc();
273 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
276 URLCacheContainers_CreateDefaults();
278 WININET_hModule = hinstDLL;
280 case DLL_THREAD_ATTACH:
283 case DLL_THREAD_DETACH:
284 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
286 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
287 HeapFree(GetProcessHeap(), 0, lpwite);
291 case DLL_PROCESS_DETACH:
295 URLCacheContainers_DeleteAll();
297 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
299 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
300 TlsFree(g_dwTlsErrIndex);
309 /***********************************************************************
310 * InternetInitializeAutoProxyDll (WININET.@)
312 * Setup the internal proxy
321 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
324 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
328 /***********************************************************************
329 * DetectAutoProxyUrl (WININET.@)
331 * Auto detect the proxy url
337 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
338 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
341 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
346 /***********************************************************************
347 * INTERNET_ConfigureProxy
350 * The proxy may be specified in the form 'http=proxy.my.org'
351 * Presumably that means there can be ftp=ftpproxy.my.org too.
353 static BOOL INTERNET_ConfigureProxy( appinfo_t *lpwai )
356 DWORD type, len, enabled = 0;
358 static const WCHAR szInternetSettings[] =
359 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
360 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
361 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
362 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
363 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
365 if (RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )) return FALSE;
367 len = sizeof enabled;
368 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&enabled, &len ) || type != REG_DWORD)
369 RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&enabled, sizeof(REG_DWORD) );
373 TRACE("Proxy is enabled.\n");
375 /* figure out how much memory the proxy setting takes */
376 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
379 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
381 if (!(szProxy = HeapAlloc( GetProcessHeap(), 0, len )))
386 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
388 /* find the http proxy, and strip away everything else */
389 p = strstrW( szProxy, szHttp );
392 p += lstrlenW( szHttp );
393 lstrcpyW( szProxy, p );
395 p = strchrW( szProxy, ' ' );
398 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
399 lpwai->lpszProxy = szProxy;
401 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
404 ERR("Couldn't read proxy server settings from registry.\n");
406 else if ((envproxy = getenv( "http_proxy" )))
410 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
411 if (!(envproxyW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR)))) return FALSE;
412 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
414 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
415 lpwai->lpszProxy = envproxyW;
417 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwai->lpszProxy));
422 TRACE("Proxy is not enabled.\n");
423 lpwai->dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
426 return (enabled > 0);
429 /***********************************************************************
430 * dump_INTERNET_FLAGS
432 * Helper function to TRACE the internet flags.
438 static void dump_INTERNET_FLAGS(DWORD dwFlags)
440 #define FE(x) { x, #x }
441 static const wininet_flag_info flag[] = {
442 FE(INTERNET_FLAG_RELOAD),
443 FE(INTERNET_FLAG_RAW_DATA),
444 FE(INTERNET_FLAG_EXISTING_CONNECT),
445 FE(INTERNET_FLAG_ASYNC),
446 FE(INTERNET_FLAG_PASSIVE),
447 FE(INTERNET_FLAG_NO_CACHE_WRITE),
448 FE(INTERNET_FLAG_MAKE_PERSISTENT),
449 FE(INTERNET_FLAG_FROM_CACHE),
450 FE(INTERNET_FLAG_SECURE),
451 FE(INTERNET_FLAG_KEEP_CONNECTION),
452 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
453 FE(INTERNET_FLAG_READ_PREFETCH),
454 FE(INTERNET_FLAG_NO_COOKIES),
455 FE(INTERNET_FLAG_NO_AUTH),
456 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
457 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
458 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
459 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
460 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
461 FE(INTERNET_FLAG_RESYNCHRONIZE),
462 FE(INTERNET_FLAG_HYPERLINK),
463 FE(INTERNET_FLAG_NO_UI),
464 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
465 FE(INTERNET_FLAG_CACHE_ASYNC),
466 FE(INTERNET_FLAG_FORMS_SUBMIT),
467 FE(INTERNET_FLAG_NEED_FILE),
468 FE(INTERNET_FLAG_TRANSFER_ASCII),
469 FE(INTERNET_FLAG_TRANSFER_BINARY)
474 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
475 if (flag[i].val & dwFlags) {
476 TRACE(" %s", flag[i].name);
477 dwFlags &= ~flag[i].val;
481 TRACE(" Unknown flags (%08x)\n", dwFlags);
486 /***********************************************************************
487 * INTERNET_CloseHandle (internal)
489 * Close internet handle
492 static VOID APPINFO_Destroy(object_header_t *hdr)
494 appinfo_t *lpwai = (appinfo_t*)hdr;
498 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
499 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
500 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
501 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
502 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
503 HeapFree(GetProcessHeap(), 0, lpwai);
506 static DWORD APPINFO_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
508 appinfo_t *ai = (appinfo_t*)hdr;
511 case INTERNET_OPTION_HANDLE_TYPE:
512 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
514 if (*size < sizeof(ULONG))
515 return ERROR_INSUFFICIENT_BUFFER;
517 *size = sizeof(DWORD);
518 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
519 return ERROR_SUCCESS;
521 case INTERNET_OPTION_USER_AGENT: {
524 TRACE("INTERNET_OPTION_USER_AGENT\n");
529 DWORD len = ai->lpszAgent ? strlenW(ai->lpszAgent) : 0;
531 *size = (len + 1) * sizeof(WCHAR);
532 if(!buffer || bufsize < *size)
533 return ERROR_INSUFFICIENT_BUFFER;
536 strcpyW(buffer, ai->lpszAgent);
538 *(WCHAR *)buffer = 0;
539 /* If the buffer is copied, the returned length doesn't include
540 * the NULL terminator.
542 *size = len * sizeof(WCHAR);
545 *size = WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, NULL, 0, NULL, NULL);
548 if(!buffer || bufsize < *size)
549 return ERROR_INSUFFICIENT_BUFFER;
552 WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, buffer, *size, NULL, NULL);
555 /* If the buffer is copied, the returned length doesn't include
556 * the NULL terminator.
561 return ERROR_SUCCESS;
564 case INTERNET_OPTION_PROXY:
566 INTERNET_PROXY_INFOW *pi = (INTERNET_PROXY_INFOW *)buffer;
567 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
568 LPWSTR proxy, proxy_bypass;
571 proxyBytesRequired = (lstrlenW(ai->lpszProxy) + 1) * sizeof(WCHAR);
572 if (ai->lpszProxyBypass)
573 proxyBypassBytesRequired = (lstrlenW(ai->lpszProxyBypass) + 1) * sizeof(WCHAR);
574 if (*size < sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired)
576 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
577 return ERROR_INSUFFICIENT_BUFFER;
579 proxy = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW));
580 proxy_bypass = (LPWSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired);
582 pi->dwAccessType = ai->dwAccessType;
583 pi->lpszProxy = NULL;
584 pi->lpszProxyBypass = NULL;
586 lstrcpyW(proxy, ai->lpszProxy);
587 pi->lpszProxy = proxy;
590 if (ai->lpszProxyBypass) {
591 lstrcpyW(proxy_bypass, ai->lpszProxyBypass);
592 pi->lpszProxyBypass = proxy_bypass;
595 *size = sizeof(INTERNET_PROXY_INFOW) + proxyBytesRequired + proxyBypassBytesRequired;
596 return ERROR_SUCCESS;
598 INTERNET_PROXY_INFOA *pi = (INTERNET_PROXY_INFOA *)buffer;
599 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
600 LPSTR proxy, proxy_bypass;
603 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->lpszProxy, -1, NULL, 0, NULL, NULL);
604 if (ai->lpszProxyBypass)
605 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0, ai->lpszProxyBypass, -1,
606 NULL, 0, NULL, NULL);
607 if (*size < sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired)
609 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
610 return ERROR_INSUFFICIENT_BUFFER;
612 proxy = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA));
613 proxy_bypass = (LPSTR)((LPBYTE)buffer + sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
615 pi->dwAccessType = ai->dwAccessType;
616 pi->lpszProxy = NULL;
617 pi->lpszProxyBypass = NULL;
619 WideCharToMultiByte(CP_ACP, 0, ai->lpszProxy, -1, proxy, proxyBytesRequired, NULL, NULL);
620 pi->lpszProxy = proxy;
623 if (ai->lpszProxyBypass) {
624 WideCharToMultiByte(CP_ACP, 0, ai->lpszProxyBypass, -1, proxy_bypass,
625 proxyBypassBytesRequired, NULL, NULL);
626 pi->lpszProxyBypass = proxy_bypass;
629 *size = sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired + proxyBypassBytesRequired;
630 return ERROR_SUCCESS;
634 return INET_QueryOption(option, buffer, size, unicode);
637 static const object_vtbl_t APPINFOVtbl = {
650 /***********************************************************************
651 * InternetOpenW (WININET.@)
653 * Per-application initialization of wininet
656 * HINTERNET on success
660 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
661 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
663 appinfo_t *lpwai = NULL;
664 HINTERNET handle = NULL;
666 if (TRACE_ON(wininet)) {
667 #define FE(x) { x, #x }
668 static const wininet_flag_info access_type[] = {
669 FE(INTERNET_OPEN_TYPE_PRECONFIG),
670 FE(INTERNET_OPEN_TYPE_DIRECT),
671 FE(INTERNET_OPEN_TYPE_PROXY),
672 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
676 const char *access_type_str = "Unknown";
678 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
679 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
680 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
681 if (access_type[i].val == dwAccessType) {
682 access_type_str = access_type[i].name;
686 TRACE(" access type : %s\n", access_type_str);
688 dump_INTERNET_FLAGS(dwFlags);
691 /* Clear any error information */
692 INTERNET_SetLastError(0);
694 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(appinfo_t));
697 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
701 lpwai->hdr.htype = WH_HINIT;
702 lpwai->hdr.vtbl = &APPINFOVtbl;
703 lpwai->hdr.dwFlags = dwFlags;
705 lpwai->dwAccessType = dwAccessType;
706 lpwai->lpszProxyUsername = NULL;
707 lpwai->lpszProxyPassword = NULL;
709 handle = WININET_AllocHandle( &lpwai->hdr );
712 HeapFree( GetProcessHeap(), 0, lpwai );
713 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
717 lpwai->lpszAgent = heap_strdupW(lpszAgent);
718 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
719 INTERNET_ConfigureProxy( lpwai );
721 lpwai->lpszProxy = heap_strdupW(lpszProxy);
722 lpwai->lpszProxyBypass = heap_strdupW(lpszProxyBypass);
726 WININET_Release( &lpwai->hdr );
728 TRACE("returning %p\n", lpwai);
734 /***********************************************************************
735 * InternetOpenA (WININET.@)
737 * Per-application initialization of wininet
740 * HINTERNET on success
744 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
745 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
747 WCHAR *szAgent, *szProxy, *szBypass;
750 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
751 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
753 szAgent = heap_strdupAtoW(lpszAgent);
754 szProxy = heap_strdupAtoW(lpszProxy);
755 szBypass = heap_strdupAtoW(lpszProxyBypass);
757 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
759 HeapFree(GetProcessHeap(), 0, szAgent);
760 HeapFree(GetProcessHeap(), 0, szProxy);
761 HeapFree(GetProcessHeap(), 0, szBypass);
766 /***********************************************************************
767 * InternetGetLastResponseInfoA (WININET.@)
769 * Return last wininet error description on the calling thread
772 * TRUE on success of writing to buffer
776 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
777 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
779 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
785 *lpdwError = lpwite->dwError;
788 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
789 *lpdwBufferLength = strlen(lpszBuffer);
792 *lpdwBufferLength = 0;
797 *lpdwBufferLength = 0;
803 /***********************************************************************
804 * InternetGetLastResponseInfoW (WININET.@)
806 * Return last wininet error description on the calling thread
809 * TRUE on success of writing to buffer
813 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
814 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
816 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
822 *lpdwError = lpwite->dwError;
825 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
826 *lpdwBufferLength = lstrlenW(lpszBuffer);
829 *lpdwBufferLength = 0;
834 *lpdwBufferLength = 0;
840 /***********************************************************************
841 * InternetGetConnectedState (WININET.@)
843 * Return connected state
847 * if lpdwStatus is not null, return the status (off line,
848 * modem, lan...) in it.
849 * FALSE if not connected
851 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
853 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
856 WARN("always returning LAN connection.\n");
857 *lpdwStatus = INTERNET_CONNECTION_LAN;
863 /***********************************************************************
864 * InternetGetConnectedStateExW (WININET.@)
866 * Return connected state
870 * lpdwStatus [O] Flags specifying the status of the internet connection.
871 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
872 * dwNameLen [I] Size of the buffer, in characters.
873 * dwReserved [I] Reserved. Must be set to 0.
877 * if lpdwStatus is not null, return the status (off line,
878 * modem, lan...) in it.
879 * FALSE if not connected
882 * If the system has no available network connections, an empty string is
883 * stored in lpszConnectionName. If there is a LAN connection, a localized
884 * "LAN Connection" string is stored. Presumably, if only a dial-up
885 * connection is available then the name of the dial-up connection is
886 * returned. Why any application, other than the "Internet Settings" CPL,
887 * would want to use this function instead of the simpler InternetGetConnectedStateW
888 * function is beyond me.
890 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
891 DWORD dwNameLen, DWORD dwReserved)
893 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
900 WARN("always returning LAN connection.\n");
901 *lpdwStatus = INTERNET_CONNECTION_LAN;
903 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
907 /***********************************************************************
908 * InternetGetConnectedStateExA (WININET.@)
910 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
911 DWORD dwNameLen, DWORD dwReserved)
913 LPWSTR lpwszConnectionName = NULL;
916 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
918 if (lpszConnectionName && dwNameLen > 0)
919 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
921 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
923 if (rc && lpwszConnectionName)
925 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
926 dwNameLen, NULL, NULL);
928 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
935 /***********************************************************************
936 * InternetConnectW (WININET.@)
938 * Open a ftp, gopher or http session
941 * HINTERNET a session handle on success
945 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
946 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
947 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
948 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
953 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
954 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
955 dwService, dwFlags, dwContext);
959 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
963 /* Clear any error information */
964 INTERNET_SetLastError(0);
965 hIC = (appinfo_t*)WININET_GetObject( hInternet );
966 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
968 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
974 case INTERNET_SERVICE_FTP:
975 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
976 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
979 case INTERNET_SERVICE_HTTP:
980 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
981 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
984 case INTERNET_SERVICE_GOPHER:
990 WININET_Release( &hIC->hdr );
992 TRACE("returning %p\n", rc);
997 /***********************************************************************
998 * InternetConnectA (WININET.@)
1000 * Open a ftp, gopher or http session
1003 * HINTERNET a session handle on success
1007 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1008 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1009 LPCSTR lpszUserName, LPCSTR lpszPassword,
1010 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1012 HINTERNET rc = NULL;
1013 LPWSTR szServerName;
1017 szServerName = heap_strdupAtoW(lpszServerName);
1018 szUserName = heap_strdupAtoW(lpszUserName);
1019 szPassword = heap_strdupAtoW(lpszPassword);
1021 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1022 szUserName, szPassword, dwService, dwFlags, dwContext);
1024 HeapFree(GetProcessHeap(), 0, szServerName);
1025 HeapFree(GetProcessHeap(), 0, szUserName);
1026 HeapFree(GetProcessHeap(), 0, szPassword);
1031 /***********************************************************************
1032 * InternetFindNextFileA (WININET.@)
1034 * Continues a file search from a previous call to FindFirstFile
1041 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1044 WIN32_FIND_DATAW fd;
1046 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1048 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1052 /***********************************************************************
1053 * InternetFindNextFileW (WININET.@)
1055 * Continues a file search from a previous call to FindFirstFile
1062 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1064 object_header_t *hdr;
1069 hdr = WININET_GetObject(hFind);
1071 WARN("Invalid handle\n");
1072 SetLastError(ERROR_INVALID_HANDLE);
1076 if(hdr->vtbl->FindNextFileW) {
1077 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1079 WARN("Handle doesn't support NextFile\n");
1080 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1083 WININET_Release(hdr);
1085 if(res != ERROR_SUCCESS)
1087 return res == ERROR_SUCCESS;
1090 /***********************************************************************
1091 * InternetCloseHandle (WININET.@)
1093 * Generic close handle function
1100 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1102 object_header_t *lpwh;
1104 TRACE("%p\n",hInternet);
1106 lpwh = WININET_GetObject( hInternet );
1109 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1113 WININET_Release( lpwh );
1114 WININET_FreeHandle( hInternet );
1120 /***********************************************************************
1121 * ConvertUrlComponentValue (Internal)
1123 * Helper function for InternetCrackUrlA
1126 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1127 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1128 LPCSTR lpszStart, LPCWSTR lpwszStart)
1130 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1131 if (*dwComponentLen != 0)
1133 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1134 if (*lppszComponent == NULL)
1138 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1139 *lppszComponent = (LPSTR)lpszStart + offset;
1142 *lppszComponent = NULL;
1144 *dwComponentLen = nASCIILength;
1148 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1149 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1150 (*lppszComponent)[ncpylen]=0;
1151 *dwComponentLen = ncpylen;
1157 /***********************************************************************
1158 * InternetCrackUrlA (WININET.@)
1160 * See InternetCrackUrlW.
1162 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1163 LPURL_COMPONENTSA lpUrlComponents)
1166 URL_COMPONENTSW UCW;
1168 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1169 *scheme = NULL, *extra = NULL;
1171 TRACE("(%s %u %x %p)\n",
1172 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1173 dwUrlLength, dwFlags, lpUrlComponents);
1175 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1176 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1178 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1184 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1186 /* if dwUrlLength=-1 then nLength includes null but length to
1187 InternetCrackUrlW should not include it */
1188 if (dwUrlLength == -1) nLength--;
1190 lpwszUrl = HeapAlloc(GetProcessHeap(), 0, nLength * sizeof(WCHAR));
1191 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1193 memset(&UCW,0,sizeof(UCW));
1194 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1195 if (lpUrlComponents->dwHostNameLength)
1197 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1198 if (lpUrlComponents->lpszHostName)
1200 hostname = HeapAlloc(GetProcessHeap(), 0, UCW.dwHostNameLength * sizeof(WCHAR));
1201 UCW.lpszHostName = hostname;
1204 if (lpUrlComponents->dwUserNameLength)
1206 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1207 if (lpUrlComponents->lpszUserName)
1209 username = HeapAlloc(GetProcessHeap(), 0, UCW.dwUserNameLength * sizeof(WCHAR));
1210 UCW.lpszUserName = username;
1213 if (lpUrlComponents->dwPasswordLength)
1215 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1216 if (lpUrlComponents->lpszPassword)
1218 password = HeapAlloc(GetProcessHeap(), 0, UCW.dwPasswordLength * sizeof(WCHAR));
1219 UCW.lpszPassword = password;
1222 if (lpUrlComponents->dwUrlPathLength)
1224 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1225 if (lpUrlComponents->lpszUrlPath)
1227 path = HeapAlloc(GetProcessHeap(), 0, UCW.dwUrlPathLength * sizeof(WCHAR));
1228 UCW.lpszUrlPath = path;
1231 if (lpUrlComponents->dwSchemeLength)
1233 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1234 if (lpUrlComponents->lpszScheme)
1236 scheme = HeapAlloc(GetProcessHeap(), 0, UCW.dwSchemeLength * sizeof(WCHAR));
1237 UCW.lpszScheme = scheme;
1240 if (lpUrlComponents->dwExtraInfoLength)
1242 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1243 if (lpUrlComponents->lpszExtraInfo)
1245 extra = HeapAlloc(GetProcessHeap(), 0, UCW.dwExtraInfoLength * sizeof(WCHAR));
1246 UCW.lpszExtraInfo = extra;
1249 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1251 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1252 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1253 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1254 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1255 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1256 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1257 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1258 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1259 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1260 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1261 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1262 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1264 lpUrlComponents->nScheme = UCW.nScheme;
1265 lpUrlComponents->nPort = UCW.nPort;
1267 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1268 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1269 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1270 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1271 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1273 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1274 HeapFree(GetProcessHeap(), 0, hostname);
1275 HeapFree(GetProcessHeap(), 0, username);
1276 HeapFree(GetProcessHeap(), 0, password);
1277 HeapFree(GetProcessHeap(), 0, path);
1278 HeapFree(GetProcessHeap(), 0, scheme);
1279 HeapFree(GetProcessHeap(), 0, extra);
1283 static const WCHAR url_schemes[][7] =
1286 {'g','o','p','h','e','r',0},
1287 {'h','t','t','p',0},
1288 {'h','t','t','p','s',0},
1289 {'f','i','l','e',0},
1290 {'n','e','w','s',0},
1291 {'m','a','i','l','t','o',0},
1295 /***********************************************************************
1296 * GetInternetSchemeW (internal)
1302 * INTERNET_SCHEME_UNKNOWN on failure
1305 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1309 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1311 if(lpszScheme==NULL)
1312 return INTERNET_SCHEME_UNKNOWN;
1314 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1315 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1316 return INTERNET_SCHEME_FIRST + i;
1318 return INTERNET_SCHEME_UNKNOWN;
1321 /***********************************************************************
1322 * SetUrlComponentValueW (Internal)
1324 * Helper function for InternetCrackUrlW
1327 * lppszComponent [O] Holds the returned string
1328 * dwComponentLen [I] Holds the size of lppszComponent
1329 * [O] Holds the length of the string in lppszComponent without '\0'
1330 * lpszStart [I] Holds the string to copy from
1331 * len [I] Holds the length of lpszStart without '\0'
1338 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1340 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1342 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1345 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1347 if (*lppszComponent == NULL)
1349 *lppszComponent = (LPWSTR)lpszStart;
1350 *dwComponentLen = len;
1354 DWORD ncpylen = min((*dwComponentLen)-1, len);
1355 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1356 (*lppszComponent)[ncpylen] = '\0';
1357 *dwComponentLen = ncpylen;
1364 /***********************************************************************
1365 * InternetCrackUrlW (WININET.@)
1367 * Break up URL into its components
1373 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1374 LPURL_COMPONENTSW lpUC)
1378 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1381 LPCWSTR lpszParam = NULL;
1382 BOOL bIsAbsolute = FALSE;
1383 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1384 LPCWSTR lpszcp = NULL;
1385 LPWSTR lpszUrl_decode = NULL;
1386 DWORD dwUrlLength = dwUrlLength_orig;
1388 TRACE("(%s %u %x %p)\n",
1389 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1390 dwUrlLength, dwFlags, lpUC);
1392 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1394 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1397 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1399 if (dwFlags & ICU_DECODE)
1402 DWORD len = dwUrlLength + 1;
1404 if (!(url_tmp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1406 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1409 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1410 url_tmp[dwUrlLength] = 0;
1411 if (!(lpszUrl_decode = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1413 HeapFree(GetProcessHeap(), 0, url_tmp);
1414 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1417 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1420 lpszUrl = lpszUrl_decode;
1422 HeapFree(GetProcessHeap(), 0, url_tmp);
1426 /* Determine if the URI is absolute. */
1427 while (lpszap - lpszUrl < dwUrlLength)
1429 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1434 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1441 lpszcp = lpszUrl; /* Relative url */
1447 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1448 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1450 /* Parse <params> */
1451 lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl));
1453 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1455 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1457 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1458 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1460 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1464 /* Get scheme first. */
1465 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1466 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1467 lpszUrl, lpszcp - lpszUrl);
1469 /* Eat ':' in protocol. */
1472 /* double slash indicates the net_loc portion is present */
1473 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1477 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1481 lpszNetLoc = min(lpszNetLoc, lpszParam);
1483 lpszNetLoc = lpszParam;
1485 else if (!lpszNetLoc)
1486 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1494 /* [<user>[<:password>]@]<host>[:<port>] */
1495 /* First find the user and password if they exist */
1497 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1498 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1500 /* username and password not specified. */
1501 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1502 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1504 else /* Parse out username and password */
1506 LPCWSTR lpszUser = lpszcp;
1507 LPCWSTR lpszPasswd = lpszHost;
1509 while (lpszcp < lpszHost)
1512 lpszPasswd = lpszcp;
1517 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1518 lpszUser, lpszPasswd - lpszUser);
1520 if (lpszPasswd != lpszHost)
1522 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1523 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1524 lpszHost - lpszPasswd);
1526 lpszcp++; /* Advance to beginning of host */
1529 /* Parse <host><:port> */
1532 lpszPort = lpszNetLoc;
1534 /* special case for res:// URLs: there is no port here, so the host is the
1535 entire string up to the first '/' */
1536 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1538 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1539 lpszHost, lpszPort - lpszHost);
1544 while (lpszcp < lpszNetLoc)
1552 /* If the scheme is "file" and the host is just one letter, it's not a host */
1553 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1556 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1561 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1562 lpszHost, lpszPort - lpszHost);
1563 if (lpszPort != lpszNetLoc)
1564 lpUC->nPort = atoiW(++lpszPort);
1565 else switch (lpUC->nScheme)
1567 case INTERNET_SCHEME_HTTP:
1568 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1570 case INTERNET_SCHEME_HTTPS:
1571 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1573 case INTERNET_SCHEME_FTP:
1574 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1576 case INTERNET_SCHEME_GOPHER:
1577 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1588 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1589 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1590 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1595 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1596 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1597 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1598 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1601 /* Here lpszcp points to:
1603 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1604 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1606 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp < lpszParam))
1610 /* Only truncate the parameter list if it's already been saved
1611 * in lpUC->lpszExtraInfo.
1613 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1614 len = lpszParam - lpszcp;
1617 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1618 * newlines if necessary.
1620 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1621 if (lpsznewline != NULL)
1622 len = lpsznewline - lpszcp;
1624 len = dwUrlLength-(lpszcp-lpszUrl);
1626 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1631 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1632 lpUC->lpszUrlPath[0] = 0;
1633 lpUC->dwUrlPathLength = 0;
1636 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1637 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1638 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1639 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1640 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1642 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1646 /***********************************************************************
1647 * InternetAttemptConnect (WININET.@)
1649 * Attempt to make a connection to the internet
1652 * ERROR_SUCCESS on success
1653 * Error value on failure
1656 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1659 return ERROR_SUCCESS;
1663 /***********************************************************************
1664 * InternetCanonicalizeUrlA (WININET.@)
1666 * Escape unsafe characters and spaces
1673 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1674 LPDWORD lpdwBufferLength, DWORD dwFlags)
1677 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1679 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1680 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1682 if(dwFlags & ICU_DECODE)
1684 dwURLFlags |= URL_UNESCAPE;
1685 dwFlags &= ~ICU_DECODE;
1688 if(dwFlags & ICU_ESCAPE)
1690 dwURLFlags |= URL_UNESCAPE;
1691 dwFlags &= ~ICU_ESCAPE;
1694 if(dwFlags & ICU_BROWSER_MODE)
1696 dwURLFlags |= URL_BROWSER_MODE;
1697 dwFlags &= ~ICU_BROWSER_MODE;
1700 if(dwFlags & ICU_NO_ENCODE)
1702 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1703 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1704 dwFlags &= ~ICU_NO_ENCODE;
1707 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1709 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1710 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1711 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1713 return (hr == S_OK) ? TRUE : FALSE;
1716 /***********************************************************************
1717 * InternetCanonicalizeUrlW (WININET.@)
1719 * Escape unsafe characters and spaces
1726 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1727 LPDWORD lpdwBufferLength, DWORD dwFlags)
1730 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1732 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1733 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1735 if(dwFlags & ICU_DECODE)
1737 dwURLFlags |= URL_UNESCAPE;
1738 dwFlags &= ~ICU_DECODE;
1741 if(dwFlags & ICU_ESCAPE)
1743 dwURLFlags |= URL_UNESCAPE;
1744 dwFlags &= ~ICU_ESCAPE;
1747 if(dwFlags & ICU_BROWSER_MODE)
1749 dwURLFlags |= URL_BROWSER_MODE;
1750 dwFlags &= ~ICU_BROWSER_MODE;
1753 if(dwFlags & ICU_NO_ENCODE)
1755 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1756 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1757 dwFlags &= ~ICU_NO_ENCODE;
1760 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1762 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1763 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1764 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1766 return (hr == S_OK) ? TRUE : FALSE;
1769 /* #################################################### */
1771 static INTERNET_STATUS_CALLBACK set_status_callback(
1772 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1774 INTERNET_STATUS_CALLBACK ret;
1776 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1777 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1779 ret = lpwh->lpfnStatusCB;
1780 lpwh->lpfnStatusCB = callback;
1785 /***********************************************************************
1786 * InternetSetStatusCallbackA (WININET.@)
1788 * Sets up a callback function which is called as progress is made
1789 * during an operation.
1792 * Previous callback or NULL on success
1793 * INTERNET_INVALID_STATUS_CALLBACK on failure
1796 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1797 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1799 INTERNET_STATUS_CALLBACK retVal;
1800 object_header_t *lpwh;
1802 TRACE("%p\n", hInternet);
1804 if (!(lpwh = WININET_GetObject(hInternet)))
1805 return INTERNET_INVALID_STATUS_CALLBACK;
1807 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1809 WININET_Release( lpwh );
1813 /***********************************************************************
1814 * InternetSetStatusCallbackW (WININET.@)
1816 * Sets up a callback function which is called as progress is made
1817 * during an operation.
1820 * Previous callback or NULL on success
1821 * INTERNET_INVALID_STATUS_CALLBACK on failure
1824 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1825 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1827 INTERNET_STATUS_CALLBACK retVal;
1828 object_header_t *lpwh;
1830 TRACE("%p\n", hInternet);
1832 if (!(lpwh = WININET_GetObject(hInternet)))
1833 return INTERNET_INVALID_STATUS_CALLBACK;
1835 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1837 WININET_Release( lpwh );
1841 /***********************************************************************
1842 * InternetSetFilePointer (WININET.@)
1844 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1845 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1851 /***********************************************************************
1852 * InternetWriteFile (WININET.@)
1854 * Write data to an open internet file
1861 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
1862 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1864 object_header_t *lpwh;
1867 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1869 lpwh = WININET_GetObject( hFile );
1871 WARN("Invalid handle\n");
1872 SetLastError(ERROR_INVALID_HANDLE);
1876 if(lpwh->vtbl->WriteFile) {
1877 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1879 WARN("No Writefile method.\n");
1880 res = ERROR_INVALID_HANDLE;
1883 WININET_Release( lpwh );
1885 if(res != ERROR_SUCCESS)
1887 return res == ERROR_SUCCESS;
1891 /***********************************************************************
1892 * InternetReadFile (WININET.@)
1894 * Read data from an open internet file
1901 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1902 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1904 object_header_t *hdr;
1905 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1907 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1909 hdr = WININET_GetObject(hFile);
1911 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1915 if(hdr->vtbl->ReadFile)
1916 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1918 WININET_Release(hdr);
1920 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
1921 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1923 if(res != ERROR_SUCCESS)
1925 return res == ERROR_SUCCESS;
1928 /***********************************************************************
1929 * InternetReadFileExA (WININET.@)
1931 * Read data from an open internet file
1934 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1935 * lpBuffersOut [I/O] Buffer.
1936 * dwFlags [I] Flags. See notes.
1937 * dwContext [I] Context for callbacks.
1944 * The parameter dwFlags include zero or more of the following flags:
1945 *|IRF_ASYNC - Makes the call asynchronous.
1946 *|IRF_SYNC - Makes the call synchronous.
1947 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1948 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1950 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1953 * InternetOpenUrlA(), HttpOpenRequestA()
1955 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1956 DWORD dwFlags, DWORD_PTR dwContext)
1958 object_header_t *hdr;
1959 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1961 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1963 hdr = WININET_GetObject(hFile);
1965 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1969 if(hdr->vtbl->ReadFileExA)
1970 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
1972 WININET_Release(hdr);
1974 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
1975 res, lpBuffersOut->dwBufferLength);
1977 if(res != ERROR_SUCCESS)
1979 return res == ERROR_SUCCESS;
1982 /***********************************************************************
1983 * InternetReadFileExW (WININET.@)
1985 * InternetReadFileExA()
1987 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1988 DWORD dwFlags, DWORD_PTR dwContext)
1990 object_header_t *hdr;
1991 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1993 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
1995 hdr = WININET_GetObject(hFile);
1997 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2001 if(hdr->vtbl->ReadFileExW)
2002 res = hdr->vtbl->ReadFileExW(hdr, lpBuffer, dwFlags, dwContext);
2004 WININET_Release(hdr);
2006 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2007 res, lpBuffer->dwBufferLength);
2009 if(res != ERROR_SUCCESS)
2011 return res == ERROR_SUCCESS;
2014 DWORD INET_QueryOption(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2016 static BOOL warn = TRUE;
2019 case INTERNET_OPTION_REQUEST_FLAGS:
2020 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2022 if (*size < sizeof(ULONG))
2023 return ERROR_INSUFFICIENT_BUFFER;
2025 *(ULONG*)buffer = 4;
2026 *size = sizeof(ULONG);
2028 return ERROR_SUCCESS;
2030 case INTERNET_OPTION_HTTP_VERSION:
2031 if (*size < sizeof(HTTP_VERSION_INFO))
2032 return ERROR_INSUFFICIENT_BUFFER;
2035 * Presently hardcoded to 1.1
2037 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2038 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2039 *size = sizeof(HTTP_VERSION_INFO);
2041 return ERROR_SUCCESS;
2043 case INTERNET_OPTION_CONNECTED_STATE:
2045 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2048 if (*size < sizeof(ULONG))
2049 return ERROR_INSUFFICIENT_BUFFER;
2051 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2052 *size = sizeof(ULONG);
2054 return ERROR_SUCCESS;
2056 case INTERNET_OPTION_PROXY: {
2060 TRACE("Getting global proxy info\n");
2061 memset(&ai, 0, sizeof(appinfo_t));
2062 INTERNET_ConfigureProxy(&ai);
2064 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2065 APPINFO_Destroy(&ai.hdr);
2069 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2070 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2072 if (*size < sizeof(ULONG))
2073 return ERROR_INSUFFICIENT_BUFFER;
2075 *(ULONG*)buffer = 2;
2076 *size = sizeof(ULONG);
2078 return ERROR_SUCCESS;
2080 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2081 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2083 if (*size < sizeof(ULONG))
2084 return ERROR_INSUFFICIENT_BUFFER;
2087 *size = sizeof(ULONG);
2089 return ERROR_SUCCESS;
2091 case INTERNET_OPTION_SECURITY_FLAGS:
2092 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2093 return ERROR_SUCCESS;
2095 case INTERNET_OPTION_VERSION: {
2096 static const INTERNET_VERSION_INFO info = { 1, 2 };
2098 TRACE("INTERNET_OPTION_VERSION\n");
2100 if (*size < sizeof(INTERNET_VERSION_INFO))
2101 return ERROR_INSUFFICIENT_BUFFER;
2103 memcpy(buffer, &info, sizeof(info));
2104 *size = sizeof(info);
2106 return ERROR_SUCCESS;
2109 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2110 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2111 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2112 DWORD res = ERROR_SUCCESS, i;
2115 TRACE("Getting global proxy info\n");
2116 memset(&ai, 0, sizeof(appinfo_t));
2117 INTERNET_ConfigureProxy(&ai);
2119 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2121 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2122 APPINFO_Destroy(&ai.hdr);
2123 return ERROR_INSUFFICIENT_BUFFER;
2126 for (i = 0; i < con->dwOptionCount; i++) {
2127 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2128 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2130 switch (option->dwOption) {
2131 case INTERNET_PER_CONN_FLAGS:
2132 option->Value.dwValue = ai.dwAccessType;
2135 case INTERNET_PER_CONN_PROXY_SERVER:
2137 option->Value.pszValue = heap_strdupW(ai.lpszProxy);
2139 optionA->Value.pszValue = heap_strdupWtoA(ai.lpszProxy);
2142 case INTERNET_PER_CONN_PROXY_BYPASS:
2144 option->Value.pszValue = heap_strdupW(ai.lpszProxyBypass);
2146 optionA->Value.pszValue = heap_strdupWtoA(ai.lpszProxyBypass);
2149 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2150 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2151 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2152 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2153 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2154 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2155 FIXME("Unhandled dwOption %d\n", option->dwOption);
2156 memset(&option->Value, 0, sizeof(option->Value));
2160 FIXME("Unknown dwOption %d\n", option->dwOption);
2161 res = ERROR_INVALID_PARAMETER;
2165 APPINFO_Destroy(&ai.hdr);
2169 case INTERNET_OPTION_USER_AGENT:
2170 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2173 FIXME("Stub for %d\n", option);
2174 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2177 /***********************************************************************
2178 * InternetQueryOptionW (WININET.@)
2180 * Queries an options on the specified handle
2187 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2188 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2190 object_header_t *hdr;
2191 DWORD res = ERROR_INVALID_HANDLE;
2193 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2196 hdr = WININET_GetObject(hInternet);
2198 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2199 WININET_Release(hdr);
2202 res = INET_QueryOption(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2205 if(res != ERROR_SUCCESS)
2207 return res == ERROR_SUCCESS;
2210 /***********************************************************************
2211 * InternetQueryOptionA (WININET.@)
2213 * Queries an options on the specified handle
2220 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2221 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2223 object_header_t *hdr;
2224 DWORD res = ERROR_INVALID_HANDLE;
2226 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2229 hdr = WININET_GetObject(hInternet);
2231 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2232 WININET_Release(hdr);
2235 res = INET_QueryOption(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2238 if(res != ERROR_SUCCESS)
2240 return res == ERROR_SUCCESS;
2244 /***********************************************************************
2245 * InternetSetOptionW (WININET.@)
2247 * Sets an options on the specified handle
2254 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2255 LPVOID lpBuffer, DWORD dwBufferLength)
2257 object_header_t *lpwhh;
2260 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2262 lpwhh = (object_header_t*) WININET_GetObject( hInternet );
2263 if(lpwhh && lpwhh->vtbl->SetOption) {
2266 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2267 if(res != ERROR_INTERNET_INVALID_OPTION) {
2268 WININET_Release( lpwhh );
2270 if(res != ERROR_SUCCESS)
2273 return res == ERROR_SUCCESS;
2279 case INTERNET_OPTION_CALLBACK:
2283 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2286 WININET_Release(lpwhh);
2287 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2290 case INTERNET_OPTION_HTTP_VERSION:
2292 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2293 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2296 case INTERNET_OPTION_ERROR_MASK:
2298 ULONG flags = *(ULONG *)lpBuffer;
2299 FIXME("Option INTERNET_OPTION_ERROR_MASK(%d): STUB\n", flags);
2302 case INTERNET_OPTION_CODEPAGE:
2304 ULONG codepage = *(ULONG *)lpBuffer;
2305 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2308 case INTERNET_OPTION_REQUEST_PRIORITY:
2310 ULONG priority = *(ULONG *)lpBuffer;
2311 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2314 case INTERNET_OPTION_CONNECT_TIMEOUT:
2316 ULONG connecttimeout = *(ULONG *)lpBuffer;
2317 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2320 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2322 ULONG receivetimeout = *(ULONG *)lpBuffer;
2323 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2326 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2328 ULONG conns = *(ULONG *)lpBuffer;
2329 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2332 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2334 ULONG conns = *(ULONG *)lpBuffer;
2335 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2338 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2339 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2341 case INTERNET_OPTION_END_BROWSER_SESSION:
2342 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2344 case INTERNET_OPTION_CONNECTED_STATE:
2345 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2347 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2348 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2350 case INTERNET_OPTION_SEND_TIMEOUT:
2351 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2353 ULONG timeout = *(ULONG *)lpBuffer;
2354 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout);
2357 case INTERNET_OPTION_CONNECT_RETRIES:
2359 ULONG retries = *(ULONG *)lpBuffer;
2360 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2363 case INTERNET_OPTION_CONTEXT_VALUE:
2364 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2366 case INTERNET_OPTION_SECURITY_FLAGS:
2367 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2369 case INTERNET_OPTION_DISABLE_AUTODIAL:
2370 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2372 case INTERNET_OPTION_HTTP_DECODING:
2373 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2374 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2377 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2378 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2379 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2382 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2383 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2384 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2387 case INTERNET_OPTION_CODEPAGE_PATH:
2388 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2389 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2392 case INTERNET_OPTION_CODEPAGE_EXTRA:
2393 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2394 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2397 case INTERNET_OPTION_IDN:
2398 FIXME("INTERNET_OPTION_IDN; STUB\n");
2399 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2403 FIXME("Option %d STUB\n",dwOption);
2404 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2410 WININET_Release( lpwhh );
2416 /***********************************************************************
2417 * InternetSetOptionA (WININET.@)
2419 * Sets an options on the specified handle.
2426 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2427 LPVOID lpBuffer, DWORD dwBufferLength)
2435 case INTERNET_OPTION_CALLBACK:
2437 object_header_t *lpwh;
2439 if (!(lpwh = WININET_GetObject(hInternet)))
2441 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2444 WININET_Release(lpwh);
2445 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2448 case INTERNET_OPTION_PROXY:
2450 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2451 LPINTERNET_PROXY_INFOW piw;
2452 DWORD proxlen, prbylen;
2455 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2456 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2457 wlen = sizeof(*piw) + proxlen + prbylen;
2458 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2459 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2460 piw->dwAccessType = pi->dwAccessType;
2461 prox = (LPWSTR) &piw[1];
2462 prby = &prox[proxlen+1];
2463 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2464 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2465 piw->lpszProxy = prox;
2466 piw->lpszProxyBypass = prby;
2469 case INTERNET_OPTION_USER_AGENT:
2470 case INTERNET_OPTION_USERNAME:
2471 case INTERNET_OPTION_PASSWORD:
2472 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2474 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2475 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2480 wlen = dwBufferLength;
2483 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2485 if( lpBuffer != wbuffer )
2486 HeapFree( GetProcessHeap(), 0, wbuffer );
2492 /***********************************************************************
2493 * InternetSetOptionExA (WININET.@)
2495 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2496 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2498 FIXME("Flags %08x ignored\n", dwFlags);
2499 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2502 /***********************************************************************
2503 * InternetSetOptionExW (WININET.@)
2505 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2506 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2508 FIXME("Flags %08x ignored\n", dwFlags);
2509 if( dwFlags & ~ISO_VALID_FLAGS )
2511 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2514 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2517 static const WCHAR WININET_wkday[7][4] =
2518 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2519 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2520 static const WCHAR WININET_month[12][4] =
2521 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2522 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2523 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2525 /***********************************************************************
2526 * InternetTimeFromSystemTimeA (WININET.@)
2528 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2531 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2533 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2535 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2537 SetLastError(ERROR_INVALID_PARAMETER);
2541 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2543 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2547 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2548 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2553 /***********************************************************************
2554 * InternetTimeFromSystemTimeW (WININET.@)
2556 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2558 static const WCHAR date[] =
2559 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2560 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2562 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2564 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2566 SetLastError(ERROR_INVALID_PARAMETER);
2570 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2572 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2576 sprintfW( string, date,
2577 WININET_wkday[time->wDayOfWeek],
2579 WININET_month[time->wMonth - 1],
2588 /***********************************************************************
2589 * InternetTimeToSystemTimeA (WININET.@)
2591 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2596 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2598 stringW = heap_strdupAtoW(string);
2601 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2602 HeapFree( GetProcessHeap(), 0, stringW );
2607 /***********************************************************************
2608 * InternetTimeToSystemTimeW (WININET.@)
2610 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2613 const WCHAR *s = string;
2616 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2618 if (!string || !time) return FALSE;
2620 /* Windows does this too */
2621 GetSystemTime( time );
2623 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2624 * a SYSTEMTIME structure.
2627 while (*s && !isalphaW( *s )) s++;
2628 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2629 time->wDayOfWeek = 7;
2631 for (i = 0; i < 7; i++)
2633 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2634 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2635 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2637 time->wDayOfWeek = i;
2642 if (time->wDayOfWeek > 6) return TRUE;
2643 while (*s && !isdigitW( *s )) s++;
2644 time->wDay = strtolW( s, &end, 10 );
2647 while (*s && !isalphaW( *s )) s++;
2648 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2651 for (i = 0; i < 12; i++)
2653 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2654 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2655 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2657 time->wMonth = i + 1;
2661 if (time->wMonth == 0) return TRUE;
2663 while (*s && !isdigitW( *s )) s++;
2664 if (*s == '\0') return TRUE;
2665 time->wYear = strtolW( s, &end, 10 );
2668 while (*s && !isdigitW( *s )) s++;
2669 if (*s == '\0') return TRUE;
2670 time->wHour = strtolW( s, &end, 10 );
2673 while (*s && !isdigitW( *s )) s++;
2674 if (*s == '\0') return TRUE;
2675 time->wMinute = strtolW( s, &end, 10 );
2678 while (*s && !isdigitW( *s )) s++;
2679 if (*s == '\0') return TRUE;
2680 time->wSecond = strtolW( s, &end, 10 );
2683 time->wMilliseconds = 0;
2687 /***********************************************************************
2688 * InternetCheckConnectionW (WININET.@)
2690 * Pings a requested host to check internet connection
2693 * TRUE on success and FALSE on failure. If a failure then
2694 * ERROR_NOT_CONNECTED is placed into GetLastError
2697 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2700 * this is a kludge which runs the resident ping program and reads the output.
2702 * Anyone have a better idea?
2706 static const CHAR ping[] = "ping -c 1 ";
2707 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2708 CHAR *command = NULL;
2717 * Crack or set the Address
2719 if (lpszUrl == NULL)
2722 * According to the doc we are supposed to use the ip for the next
2723 * server in the WnInet internal server database. I have
2724 * no idea what that is or how to get it.
2726 * So someone needs to implement this.
2728 FIXME("Unimplemented with URL of NULL\n");
2733 URL_COMPONENTSW components;
2735 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2736 components.lpszHostName = (LPWSTR)hostW;
2737 components.dwHostNameLength = 1024;
2739 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2742 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2743 port = components.nPort;
2744 TRACE("port: %d\n", port);
2747 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2749 struct sockaddr_storage saddr;
2750 socklen_t sa_len = sizeof(saddr);
2753 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
2755 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
2758 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
2766 * Build our ping command
2768 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2769 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2770 strcpy(command,ping);
2771 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2772 strcat(command,redirect);
2774 TRACE("Ping command is : %s\n",command);
2776 status = system(command);
2778 TRACE("Ping returned a code of %i\n",status);
2780 /* Ping return code of 0 indicates success */
2787 HeapFree( GetProcessHeap(), 0, command );
2789 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2795 /***********************************************************************
2796 * InternetCheckConnectionA (WININET.@)
2798 * Pings a requested host to check internet connection
2801 * TRUE on success and FALSE on failure. If a failure then
2802 * ERROR_NOT_CONNECTED is placed into GetLastError
2805 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2811 url = heap_strdupAtoW(lpszUrl);
2816 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
2818 HeapFree(GetProcessHeap(), 0, url);
2823 /**********************************************************
2824 * INTERNET_InternetOpenUrlW (internal)
2829 * handle of connection or NULL on failure
2831 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
2832 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2834 URL_COMPONENTSW urlComponents;
2835 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2836 WCHAR password[1024], path[2048], extra[1024];
2837 HINTERNET client = NULL, client1 = NULL;
2839 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2840 dwHeadersLength, dwFlags, dwContext);
2842 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2843 urlComponents.lpszScheme = protocol;
2844 urlComponents.dwSchemeLength = 32;
2845 urlComponents.lpszHostName = hostName;
2846 urlComponents.dwHostNameLength = MAXHOSTNAME;
2847 urlComponents.lpszUserName = userName;
2848 urlComponents.dwUserNameLength = 1024;
2849 urlComponents.lpszPassword = password;
2850 urlComponents.dwPasswordLength = 1024;
2851 urlComponents.lpszUrlPath = path;
2852 urlComponents.dwUrlPathLength = 2048;
2853 urlComponents.lpszExtraInfo = extra;
2854 urlComponents.dwExtraInfoLength = 1024;
2855 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2857 switch(urlComponents.nScheme) {
2858 case INTERNET_SCHEME_FTP:
2859 if(urlComponents.nPort == 0)
2860 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2861 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2862 userName, password, dwFlags, dwContext, INET_OPENURL);
2865 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2866 if(client1 == NULL) {
2867 InternetCloseHandle(client);
2872 case INTERNET_SCHEME_HTTP:
2873 case INTERNET_SCHEME_HTTPS: {
2874 static const WCHAR szStars[] = { '*','/','*', 0 };
2875 LPCWSTR accept[2] = { szStars, NULL };
2876 if(urlComponents.nPort == 0) {
2877 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2878 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2880 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2882 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
2884 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2885 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2886 userName, password, dwFlags, dwContext, INET_OPENURL);
2890 if (urlComponents.dwExtraInfoLength) {
2892 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2894 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2896 InternetCloseHandle(client);
2899 strcpyW(path_extra, urlComponents.lpszUrlPath);
2900 strcatW(path_extra, urlComponents.lpszExtraInfo);
2901 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2902 HeapFree(GetProcessHeap(), 0, path_extra);
2905 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2907 if(client1 == NULL) {
2908 InternetCloseHandle(client);
2911 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2912 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2913 GetLastError() != ERROR_IO_PENDING) {
2914 InternetCloseHandle(client1);
2919 case INTERNET_SCHEME_GOPHER:
2920 /* gopher doesn't seem to be implemented in wine, but it's supposed
2921 * to be supported by InternetOpenUrlA. */
2923 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2927 TRACE(" %p <--\n", client1);
2932 /**********************************************************
2933 * InternetOpenUrlW (WININET.@)
2938 * handle of connection or NULL on failure
2940 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2942 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2943 appinfo_t *hIC = (appinfo_t*) workRequest->hdr;
2947 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2948 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2949 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2950 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2953 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2954 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2956 HINTERNET ret = NULL;
2957 appinfo_t *hIC = NULL;
2959 if (TRACE_ON(wininet)) {
2960 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2961 dwHeadersLength, dwFlags, dwContext);
2963 dump_INTERNET_FLAGS(dwFlags);
2968 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2972 hIC = (appinfo_t*)WININET_GetObject( hInternet );
2973 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2974 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2978 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2979 WORKREQUEST workRequest;
2980 struct WORKREQ_INTERNETOPENURLW *req;
2982 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2983 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2984 req = &workRequest.u.InternetOpenUrlW;
2985 req->lpszUrl = heap_strdupW(lpszUrl);
2986 req->lpszHeaders = heap_strdupW(lpszHeaders);
2987 req->dwHeadersLength = dwHeadersLength;
2988 req->dwFlags = dwFlags;
2989 req->dwContext = dwContext;
2991 INTERNET_AsyncCall(&workRequest);
2993 * This is from windows.
2995 INTERNET_SetLastError(ERROR_IO_PENDING);
2997 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3002 WININET_Release( &hIC->hdr );
3003 TRACE(" %p <--\n", ret);
3008 /**********************************************************
3009 * InternetOpenUrlA (WININET.@)
3014 * handle of connection or NULL on failure
3016 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3017 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3019 HINTERNET rc = NULL;
3020 DWORD lenHeaders = 0;
3021 LPWSTR szUrl = NULL;
3022 LPWSTR szHeaders = NULL;
3027 szUrl = heap_strdupAtoW(lpszUrl);
3033 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3034 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3036 HeapFree(GetProcessHeap(), 0, szUrl);
3039 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3042 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3043 lenHeaders, dwFlags, dwContext);
3045 HeapFree(GetProcessHeap(), 0, szUrl);
3046 HeapFree(GetProcessHeap(), 0, szHeaders);
3052 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3054 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3058 lpwite->dwError = 0;
3059 lpwite->response[0] = '\0';
3062 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3064 HeapFree(GetProcessHeap(), 0, lpwite);
3072 /***********************************************************************
3073 * INTERNET_SetLastError (internal)
3075 * Set last thread specific error
3080 void INTERNET_SetLastError(DWORD dwError)
3082 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3085 lpwite = INTERNET_AllocThreadError();
3087 SetLastError(dwError);
3089 lpwite->dwError = dwError;
3093 /***********************************************************************
3094 * INTERNET_GetLastError (internal)
3096 * Get last thread specific error
3101 DWORD INTERNET_GetLastError(void)
3103 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3104 if (!lpwite) return 0;
3105 /* TlsGetValue clears last error, so set it again here */
3106 SetLastError(lpwite->dwError);
3107 return lpwite->dwError;
3111 /***********************************************************************
3112 * INTERNET_WorkerThreadFunc (internal)
3114 * Worker thread execution function
3119 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3121 LPWORKREQUEST lpRequest = lpvParam;
3122 WORKREQUEST workRequest;
3126 workRequest = *lpRequest;
3127 HeapFree(GetProcessHeap(), 0, lpRequest);
3129 workRequest.asyncproc(&workRequest);
3131 WININET_Release( workRequest.hdr );
3136 /***********************************************************************
3137 * INTERNET_AsyncCall (internal)
3139 * Retrieves work request from queue
3144 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3147 LPWORKREQUEST lpNewRequest;
3151 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3155 *lpNewRequest = *lpWorkRequest;
3157 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3160 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3161 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3168 /***********************************************************************
3169 * INTERNET_GetResponseBuffer (internal)
3174 LPSTR INTERNET_GetResponseBuffer(void)
3176 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3178 lpwite = INTERNET_AllocThreadError();
3180 return lpwite->response;
3183 /***********************************************************************
3184 * INTERNET_GetNextLine (internal)
3186 * Parse next line in directory string listing
3189 * Pointer to beginning of next line
3194 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3197 BOOL bSuccess = FALSE;
3199 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3204 pfd.events = POLLIN;
3206 while (nRecv < MAX_REPLY_LEN)
3208 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3210 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3212 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3216 if (lpszBuffer[nRecv] == '\n')
3221 if (lpszBuffer[nRecv] != '\r')
3226 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3234 lpszBuffer[nRecv] = '\0';
3236 TRACE(":%d %s\n", nRecv, lpszBuffer);
3245 /**********************************************************
3246 * InternetQueryDataAvailable (WININET.@)
3248 * Determines how much data is available to be read.
3251 * TRUE on success, FALSE if an error occurred. If
3252 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3253 * no data is presently available, FALSE is returned with
3254 * the last error ERROR_IO_PENDING; a callback with status
3255 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3256 * data is available.
3258 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3259 LPDWORD lpdwNumberOfBytesAvailble,
3260 DWORD dwFlags, DWORD_PTR dwContext)
3262 object_header_t *hdr;
3265 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3267 hdr = WININET_GetObject( hFile );
3269 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
3273 if(hdr->vtbl->QueryDataAvailable) {
3274 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3276 WARN("wrong handle\n");
3277 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3280 WININET_Release(hdr);
3282 if(res != ERROR_SUCCESS)
3284 return res == ERROR_SUCCESS;
3288 /***********************************************************************
3289 * InternetLockRequestFile (WININET.@)
3291 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3298 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3305 /***********************************************************************
3306 * InternetAutodial (WININET.@)
3308 * On windows this function is supposed to dial the default internet
3309 * connection. We don't want to have Wine dial out to the internet so
3310 * we return TRUE by default. It might be nice to check if we are connected.
3317 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3321 /* Tell that we are connected to the internet. */
3325 /***********************************************************************
3326 * InternetAutodialHangup (WININET.@)
3328 * Hangs up a connection made with InternetAutodial
3337 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3341 /* we didn't dial, we don't disconnect */
3345 /***********************************************************************
3346 * InternetCombineUrlA (WININET.@)
3348 * Combine a base URL with a relative URL
3356 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3357 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3362 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3364 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3365 dwFlags ^= ICU_NO_ENCODE;
3366 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3371 /***********************************************************************
3372 * InternetCombineUrlW (WININET.@)
3374 * Combine a base URL with a relative URL
3382 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3383 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3388 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3390 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3391 dwFlags ^= ICU_NO_ENCODE;
3392 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3397 /* max port num is 65535 => 5 digits */
3398 #define MAX_WORD_DIGITS 5
3400 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3401 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3402 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3403 (url)->dw##component##Length : strlen((url)->lpsz##component))
3405 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3407 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3408 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3410 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3411 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3413 if ((nScheme == INTERNET_SCHEME_FTP) &&
3414 (nPort == INTERNET_DEFAULT_FTP_PORT))
3416 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3417 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3420 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3426 /* opaque urls do not fit into the standard url hierarchy and don't have
3427 * two following slashes */
3428 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3430 return (nScheme != INTERNET_SCHEME_FTP) &&
3431 (nScheme != INTERNET_SCHEME_GOPHER) &&
3432 (nScheme != INTERNET_SCHEME_HTTP) &&
3433 (nScheme != INTERNET_SCHEME_HTTPS) &&
3434 (nScheme != INTERNET_SCHEME_FILE);
3437 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3440 if (scheme < INTERNET_SCHEME_FIRST)
3442 index = scheme - INTERNET_SCHEME_FIRST;
3443 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3445 return (LPCWSTR)url_schemes[index];
3448 /* we can calculate using ansi strings because we're just
3449 * calculating string length, not size
3451 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3452 LPDWORD lpdwUrlLength)
3454 INTERNET_SCHEME nScheme;
3458 if (lpUrlComponents->lpszScheme)
3460 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3461 *lpdwUrlLength += dwLen;
3462 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3468 nScheme = lpUrlComponents->nScheme;
3470 if (nScheme == INTERNET_SCHEME_DEFAULT)
3471 nScheme = INTERNET_SCHEME_HTTP;
3472 scheme = INTERNET_GetSchemeString(nScheme);
3473 *lpdwUrlLength += strlenW(scheme);
3476 (*lpdwUrlLength)++; /* ':' */
3477 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3478 *lpdwUrlLength += strlen("//");
3480 if (lpUrlComponents->lpszUserName)
3482 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3483 *lpdwUrlLength += strlen("@");
3487 if (lpUrlComponents->lpszPassword)
3489 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3494 if (lpUrlComponents->lpszPassword)
3496 *lpdwUrlLength += strlen(":");
3497 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3500 if (lpUrlComponents->lpszHostName)
3502 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3504 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3506 char szPort[MAX_WORD_DIGITS+1];
3508 sprintf(szPort, "%d", lpUrlComponents->nPort);
3509 *lpdwUrlLength += strlen(szPort);
3510 *lpdwUrlLength += strlen(":");
3513 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3514 (*lpdwUrlLength)++; /* '/' */
3517 if (lpUrlComponents->lpszUrlPath)
3518 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3520 if (lpUrlComponents->lpszExtraInfo)
3521 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3526 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3530 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3532 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3533 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3534 urlCompW->nScheme = lpUrlComponents->nScheme;
3535 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3536 urlCompW->nPort = lpUrlComponents->nPort;
3537 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3538 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3539 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3540 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3542 if (lpUrlComponents->lpszScheme)
3544 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3545 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3546 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3547 -1, urlCompW->lpszScheme, len);
3550 if (lpUrlComponents->lpszHostName)
3552 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3553 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3554 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3555 -1, urlCompW->lpszHostName, len);
3558 if (lpUrlComponents->lpszUserName)
3560 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3561 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3562 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3563 -1, urlCompW->lpszUserName, len);
3566 if (lpUrlComponents->lpszPassword)
3568 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3569 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3570 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3571 -1, urlCompW->lpszPassword, len);
3574 if (lpUrlComponents->lpszUrlPath)
3576 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3577 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3578 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3579 -1, urlCompW->lpszUrlPath, len);
3582 if (lpUrlComponents->lpszExtraInfo)
3584 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3585 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3586 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3587 -1, urlCompW->lpszExtraInfo, len);
3591 /***********************************************************************
3592 * InternetCreateUrlA (WININET.@)
3594 * See InternetCreateUrlW.
3596 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3597 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3601 URL_COMPONENTSW urlCompW;
3603 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3605 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3607 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3611 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3614 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3616 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3618 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3619 *lpdwUrlLength /= sizeof(WCHAR);
3621 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3622 * minus one, so add one to leave room for NULL terminator
3625 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3627 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3628 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3629 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3630 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3631 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3632 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3633 HeapFree(GetProcessHeap(), 0, urlW);
3638 /***********************************************************************
3639 * InternetCreateUrlW (WININET.@)
3641 * Creates a URL from its component parts.
3644 * lpUrlComponents [I] URL Components.
3645 * dwFlags [I] Flags. See notes.
3646 * lpszUrl [I] Buffer in which to store the created URL.
3647 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3648 * lpszUrl in characters. On output, the number of bytes
3649 * required to store the URL including terminator.
3653 * The dwFlags parameter can be zero or more of the following:
3654 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3661 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3662 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3665 INTERNET_SCHEME nScheme;
3667 static const WCHAR slashSlashW[] = {'/','/'};
3668 static const WCHAR percentD[] = {'%','d',0};
3670 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3672 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3674 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3678 if (!calc_url_length(lpUrlComponents, &dwLen))
3681 if (!lpszUrl || *lpdwUrlLength < dwLen)
3683 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3684 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3688 *lpdwUrlLength = dwLen;
3693 if (lpUrlComponents->lpszScheme)
3695 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3696 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3699 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3704 nScheme = lpUrlComponents->nScheme;
3706 if (nScheme == INTERNET_SCHEME_DEFAULT)
3707 nScheme = INTERNET_SCHEME_HTTP;
3709 scheme = INTERNET_GetSchemeString(nScheme);
3710 dwLen = strlenW(scheme);
3711 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3715 /* all schemes are followed by at least a colon */
3719 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3721 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3722 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3725 if (lpUrlComponents->lpszUserName)
3727 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3728 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3731 if (lpUrlComponents->lpszPassword)
3736 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3737 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3745 if (lpUrlComponents->lpszHostName)
3747 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3748 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3751 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3753 WCHAR szPort[MAX_WORD_DIGITS+1];
3755 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3758 dwLen = strlenW(szPort);
3759 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3763 /* add slash between hostname and path if necessary */
3764 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3771 if (lpUrlComponents->lpszUrlPath)
3773 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3774 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3778 if (lpUrlComponents->lpszExtraInfo)
3780 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3781 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
3790 /***********************************************************************
3791 * InternetConfirmZoneCrossingA (WININET.@)
3794 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3796 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3797 return ERROR_SUCCESS;
3800 /***********************************************************************
3801 * InternetConfirmZoneCrossingW (WININET.@)
3804 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3806 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3807 return ERROR_SUCCESS;
3810 static DWORD zone_preference = 3;
3812 /***********************************************************************
3813 * PrivacySetZonePreferenceW (WININET.@)
3815 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
3817 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
3819 zone_preference = template;
3823 /***********************************************************************
3824 * PrivacyGetZonePreferenceW (WININET.@)
3826 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
3827 LPWSTR preference, LPDWORD length )
3829 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
3831 if (template) *template = zone_preference;
3835 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3836 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3838 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3839 lpdwConnection, dwReserved);
3840 return ERROR_SUCCESS;
3843 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3844 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3846 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3847 lpdwConnection, dwReserved);
3848 return ERROR_SUCCESS;
3851 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3853 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3857 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3859 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3863 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3865 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3866 return ERROR_SUCCESS;
3869 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3872 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3873 debugstr_w(pwszTarget), pbHexHash);
3877 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3879 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3883 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
3885 FIXME("(%p, %08lx) stub\n", a, b);