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 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 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)
952 DWORD res = ERROR_SUCCESS;
954 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
955 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
956 dwService, dwFlags, dwContext);
960 SetLastError(ERROR_INVALID_PARAMETER);
964 hIC = (appinfo_t*)WININET_GetObject( hInternet );
965 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
967 res = ERROR_INVALID_HANDLE;
973 case INTERNET_SERVICE_FTP:
974 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
975 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
977 res = INTERNET_GetLastError();
980 case INTERNET_SERVICE_HTTP:
981 res = HTTP_Connect(hIC, lpszServerName, nServerPort,
982 lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
985 case INTERNET_SERVICE_GOPHER:
991 WININET_Release( &hIC->hdr );
993 TRACE("returning %p\n", rc);
999 /***********************************************************************
1000 * InternetConnectA (WININET.@)
1002 * Open a ftp, gopher or http session
1005 * HINTERNET a session handle on success
1009 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
1010 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
1011 LPCSTR lpszUserName, LPCSTR lpszPassword,
1012 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
1014 HINTERNET rc = NULL;
1015 LPWSTR szServerName;
1019 szServerName = heap_strdupAtoW(lpszServerName);
1020 szUserName = heap_strdupAtoW(lpszUserName);
1021 szPassword = heap_strdupAtoW(lpszPassword);
1023 rc = InternetConnectW(hInternet, szServerName, nServerPort,
1024 szUserName, szPassword, dwService, dwFlags, dwContext);
1026 HeapFree(GetProcessHeap(), 0, szServerName);
1027 HeapFree(GetProcessHeap(), 0, szUserName);
1028 HeapFree(GetProcessHeap(), 0, szPassword);
1033 /***********************************************************************
1034 * InternetFindNextFileA (WININET.@)
1036 * Continues a file search from a previous call to FindFirstFile
1043 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
1046 WIN32_FIND_DATAW fd;
1048 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
1050 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
1054 /***********************************************************************
1055 * InternetFindNextFileW (WININET.@)
1057 * Continues a file search from a previous call to FindFirstFile
1064 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
1066 object_header_t *hdr;
1071 hdr = WININET_GetObject(hFind);
1073 WARN("Invalid handle\n");
1074 SetLastError(ERROR_INVALID_HANDLE);
1078 if(hdr->vtbl->FindNextFileW) {
1079 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1081 WARN("Handle doesn't support NextFile\n");
1082 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1085 WININET_Release(hdr);
1087 if(res != ERROR_SUCCESS)
1089 return res == ERROR_SUCCESS;
1092 /***********************************************************************
1093 * InternetCloseHandle (WININET.@)
1095 * Generic close handle function
1102 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1104 object_header_t *lpwh;
1106 TRACE("%p\n",hInternet);
1108 lpwh = WININET_GetObject( hInternet );
1111 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1115 WININET_Release( lpwh );
1116 WININET_FreeHandle( hInternet );
1122 /***********************************************************************
1123 * ConvertUrlComponentValue (Internal)
1125 * Helper function for InternetCrackUrlA
1128 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1129 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1130 LPCSTR lpszStart, LPCWSTR lpwszStart)
1132 TRACE("%p %d %p %d %p %p\n", *lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1133 if (*dwComponentLen != 0)
1135 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1136 if (*lppszComponent == NULL)
1140 int offset = WideCharToMultiByte(CP_ACP, 0, lpwszStart, lpwszComponent-lpwszStart, NULL, 0, NULL, NULL);
1141 *lppszComponent = (LPSTR)lpszStart + offset;
1144 *lppszComponent = NULL;
1146 *dwComponentLen = nASCIILength;
1150 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1151 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1152 (*lppszComponent)[ncpylen]=0;
1153 *dwComponentLen = ncpylen;
1159 /***********************************************************************
1160 * InternetCrackUrlA (WININET.@)
1162 * See InternetCrackUrlW.
1164 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1165 LPURL_COMPONENTSA lpUrlComponents)
1168 URL_COMPONENTSW UCW;
1170 WCHAR *lpwszUrl, *hostname = NULL, *username = NULL, *password = NULL, *path = NULL,
1171 *scheme = NULL, *extra = NULL;
1173 TRACE("(%s %u %x %p)\n",
1174 lpszUrl ? debugstr_an(lpszUrl, dwUrlLength ? dwUrlLength : strlen(lpszUrl)) : "(null)",
1175 dwUrlLength, dwFlags, lpUrlComponents);
1177 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1178 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1180 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1186 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1188 /* if dwUrlLength=-1 then nLength includes null but length to
1189 InternetCrackUrlW should not include it */
1190 if (dwUrlLength == -1) nLength--;
1192 lpwszUrl = HeapAlloc(GetProcessHeap(), 0, nLength * sizeof(WCHAR));
1193 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1195 memset(&UCW,0,sizeof(UCW));
1196 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1197 if (lpUrlComponents->dwHostNameLength)
1199 UCW.dwHostNameLength = lpUrlComponents->dwHostNameLength;
1200 if (lpUrlComponents->lpszHostName)
1202 hostname = HeapAlloc(GetProcessHeap(), 0, UCW.dwHostNameLength * sizeof(WCHAR));
1203 UCW.lpszHostName = hostname;
1206 if (lpUrlComponents->dwUserNameLength)
1208 UCW.dwUserNameLength = lpUrlComponents->dwUserNameLength;
1209 if (lpUrlComponents->lpszUserName)
1211 username = HeapAlloc(GetProcessHeap(), 0, UCW.dwUserNameLength * sizeof(WCHAR));
1212 UCW.lpszUserName = username;
1215 if (lpUrlComponents->dwPasswordLength)
1217 UCW.dwPasswordLength = lpUrlComponents->dwPasswordLength;
1218 if (lpUrlComponents->lpszPassword)
1220 password = HeapAlloc(GetProcessHeap(), 0, UCW.dwPasswordLength * sizeof(WCHAR));
1221 UCW.lpszPassword = password;
1224 if (lpUrlComponents->dwUrlPathLength)
1226 UCW.dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
1227 if (lpUrlComponents->lpszUrlPath)
1229 path = HeapAlloc(GetProcessHeap(), 0, UCW.dwUrlPathLength * sizeof(WCHAR));
1230 UCW.lpszUrlPath = path;
1233 if (lpUrlComponents->dwSchemeLength)
1235 UCW.dwSchemeLength = lpUrlComponents->dwSchemeLength;
1236 if (lpUrlComponents->lpszScheme)
1238 scheme = HeapAlloc(GetProcessHeap(), 0, UCW.dwSchemeLength * sizeof(WCHAR));
1239 UCW.lpszScheme = scheme;
1242 if (lpUrlComponents->dwExtraInfoLength)
1244 UCW.dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
1245 if (lpUrlComponents->lpszExtraInfo)
1247 extra = HeapAlloc(GetProcessHeap(), 0, UCW.dwExtraInfoLength * sizeof(WCHAR));
1248 UCW.lpszExtraInfo = extra;
1251 if ((ret = InternetCrackUrlW(lpwszUrl, nLength, dwFlags, &UCW)))
1253 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1254 UCW.lpszHostName, UCW.dwHostNameLength, lpszUrl, lpwszUrl);
1255 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1256 UCW.lpszUserName, UCW.dwUserNameLength, lpszUrl, lpwszUrl);
1257 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1258 UCW.lpszPassword, UCW.dwPasswordLength, lpszUrl, lpwszUrl);
1259 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1260 UCW.lpszUrlPath, UCW.dwUrlPathLength, lpszUrl, lpwszUrl);
1261 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1262 UCW.lpszScheme, UCW.dwSchemeLength, lpszUrl, lpwszUrl);
1263 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1264 UCW.lpszExtraInfo, UCW.dwExtraInfoLength, lpszUrl, lpwszUrl);
1266 lpUrlComponents->nScheme = UCW.nScheme;
1267 lpUrlComponents->nPort = UCW.nPort;
1269 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1270 debugstr_an(lpUrlComponents->lpszScheme, lpUrlComponents->dwSchemeLength),
1271 debugstr_an(lpUrlComponents->lpszHostName, lpUrlComponents->dwHostNameLength),
1272 debugstr_an(lpUrlComponents->lpszUrlPath, lpUrlComponents->dwUrlPathLength),
1273 debugstr_an(lpUrlComponents->lpszExtraInfo, lpUrlComponents->dwExtraInfoLength));
1275 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1276 HeapFree(GetProcessHeap(), 0, hostname);
1277 HeapFree(GetProcessHeap(), 0, username);
1278 HeapFree(GetProcessHeap(), 0, password);
1279 HeapFree(GetProcessHeap(), 0, path);
1280 HeapFree(GetProcessHeap(), 0, scheme);
1281 HeapFree(GetProcessHeap(), 0, extra);
1285 static const WCHAR url_schemes[][7] =
1288 {'g','o','p','h','e','r',0},
1289 {'h','t','t','p',0},
1290 {'h','t','t','p','s',0},
1291 {'f','i','l','e',0},
1292 {'n','e','w','s',0},
1293 {'m','a','i','l','t','o',0},
1297 /***********************************************************************
1298 * GetInternetSchemeW (internal)
1304 * INTERNET_SCHEME_UNKNOWN on failure
1307 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1311 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1313 if(lpszScheme==NULL)
1314 return INTERNET_SCHEME_UNKNOWN;
1316 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1317 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1318 return INTERNET_SCHEME_FIRST + i;
1320 return INTERNET_SCHEME_UNKNOWN;
1323 /***********************************************************************
1324 * SetUrlComponentValueW (Internal)
1326 * Helper function for InternetCrackUrlW
1329 * lppszComponent [O] Holds the returned string
1330 * dwComponentLen [I] Holds the size of lppszComponent
1331 * [O] Holds the length of the string in lppszComponent without '\0'
1332 * lpszStart [I] Holds the string to copy from
1333 * len [I] Holds the length of lpszStart without '\0'
1340 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1342 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1344 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1347 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1349 if (*lppszComponent == NULL)
1351 *lppszComponent = (LPWSTR)lpszStart;
1352 *dwComponentLen = len;
1356 DWORD ncpylen = min((*dwComponentLen)-1, len);
1357 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1358 (*lppszComponent)[ncpylen] = '\0';
1359 *dwComponentLen = ncpylen;
1366 /***********************************************************************
1367 * InternetCrackUrlW (WININET.@)
1369 * Break up URL into its components
1375 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1376 LPURL_COMPONENTSW lpUC)
1380 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1383 LPCWSTR lpszParam = NULL;
1384 BOOL bIsAbsolute = FALSE;
1385 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1386 LPCWSTR lpszcp = NULL;
1387 LPWSTR lpszUrl_decode = NULL;
1388 DWORD dwUrlLength = dwUrlLength_orig;
1390 TRACE("(%s %u %x %p)\n",
1391 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1392 dwUrlLength, dwFlags, lpUC);
1394 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1396 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1399 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1401 if (dwFlags & ICU_DECODE)
1404 DWORD len = dwUrlLength + 1;
1406 if (!(url_tmp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1408 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1411 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1412 url_tmp[dwUrlLength] = 0;
1413 if (!(lpszUrl_decode = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1415 HeapFree(GetProcessHeap(), 0, url_tmp);
1416 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1419 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1422 lpszUrl = lpszUrl_decode;
1424 HeapFree(GetProcessHeap(), 0, url_tmp);
1428 /* Determine if the URI is absolute. */
1429 while (lpszap - lpszUrl < dwUrlLength)
1431 if (isalnumW(*lpszap) || *lpszap == '+' || *lpszap == '.' || *lpszap == '-')
1436 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1443 lpszcp = lpszUrl; /* Relative url */
1449 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1450 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1452 /* Parse <params> */
1453 lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl));
1455 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1457 lpszParam = memchrW(lpszap, '#', dwUrlLength - (lpszap - lpszUrl));
1459 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1460 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1462 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1466 /* Get scheme first. */
1467 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1468 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1469 lpszUrl, lpszcp - lpszUrl);
1471 /* Eat ':' in protocol. */
1474 /* double slash indicates the net_loc portion is present */
1475 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1479 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1483 lpszNetLoc = min(lpszNetLoc, lpszParam);
1485 lpszNetLoc = lpszParam;
1487 else if (!lpszNetLoc)
1488 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1496 /* [<user>[<:password>]@]<host>[:<port>] */
1497 /* First find the user and password if they exist */
1499 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1500 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1502 /* username and password not specified. */
1503 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1504 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1506 else /* Parse out username and password */
1508 LPCWSTR lpszUser = lpszcp;
1509 LPCWSTR lpszPasswd = lpszHost;
1511 while (lpszcp < lpszHost)
1514 lpszPasswd = lpszcp;
1519 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1520 lpszUser, lpszPasswd - lpszUser);
1522 if (lpszPasswd != lpszHost)
1524 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1525 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1526 lpszHost - lpszPasswd);
1528 lpszcp++; /* Advance to beginning of host */
1531 /* Parse <host><:port> */
1534 lpszPort = lpszNetLoc;
1536 /* special case for res:// URLs: there is no port here, so the host is the
1537 entire string up to the first '/' */
1538 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1540 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1541 lpszHost, lpszPort - lpszHost);
1546 while (lpszcp < lpszNetLoc)
1554 /* If the scheme is "file" and the host is just one letter, it's not a host */
1555 if(lpUC->nScheme==INTERNET_SCHEME_FILE && lpszPort <= lpszHost+1)
1558 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1563 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1564 lpszHost, lpszPort - lpszHost);
1565 if (lpszPort != lpszNetLoc)
1566 lpUC->nPort = atoiW(++lpszPort);
1567 else switch (lpUC->nScheme)
1569 case INTERNET_SCHEME_HTTP:
1570 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1572 case INTERNET_SCHEME_HTTPS:
1573 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1575 case INTERNET_SCHEME_FTP:
1576 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1578 case INTERNET_SCHEME_GOPHER:
1579 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1590 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1591 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1592 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1597 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1598 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1599 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1600 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1603 /* Here lpszcp points to:
1605 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1606 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1608 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp <= lpszParam))
1612 /* Only truncate the parameter list if it's already been saved
1613 * in lpUC->lpszExtraInfo.
1615 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1616 len = lpszParam - lpszcp;
1619 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1620 * newlines if necessary.
1622 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1623 if (lpsznewline != NULL)
1624 len = lpsznewline - lpszcp;
1626 len = dwUrlLength-(lpszcp-lpszUrl);
1628 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1633 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1634 lpUC->lpszUrlPath[0] = 0;
1635 lpUC->dwUrlPathLength = 0;
1638 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1639 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1640 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1641 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1642 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1644 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1648 /***********************************************************************
1649 * InternetAttemptConnect (WININET.@)
1651 * Attempt to make a connection to the internet
1654 * ERROR_SUCCESS on success
1655 * Error value on failure
1658 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1661 return ERROR_SUCCESS;
1665 /***********************************************************************
1666 * InternetCanonicalizeUrlA (WININET.@)
1668 * Escape unsafe characters and spaces
1675 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1676 LPDWORD lpdwBufferLength, DWORD dwFlags)
1679 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1681 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1682 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1684 if(dwFlags & ICU_DECODE)
1686 dwURLFlags |= URL_UNESCAPE;
1687 dwFlags &= ~ICU_DECODE;
1690 if(dwFlags & ICU_ESCAPE)
1692 dwURLFlags |= URL_UNESCAPE;
1693 dwFlags &= ~ICU_ESCAPE;
1696 if(dwFlags & ICU_BROWSER_MODE)
1698 dwURLFlags |= URL_BROWSER_MODE;
1699 dwFlags &= ~ICU_BROWSER_MODE;
1702 if(dwFlags & ICU_NO_ENCODE)
1704 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1705 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1706 dwFlags &= ~ICU_NO_ENCODE;
1709 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1711 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1712 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1713 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1715 return (hr == S_OK) ? TRUE : FALSE;
1718 /***********************************************************************
1719 * InternetCanonicalizeUrlW (WININET.@)
1721 * Escape unsafe characters and spaces
1728 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1729 LPDWORD lpdwBufferLength, DWORD dwFlags)
1732 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1734 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1735 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1737 if(dwFlags & ICU_DECODE)
1739 dwURLFlags |= URL_UNESCAPE;
1740 dwFlags &= ~ICU_DECODE;
1743 if(dwFlags & ICU_ESCAPE)
1745 dwURLFlags |= URL_UNESCAPE;
1746 dwFlags &= ~ICU_ESCAPE;
1749 if(dwFlags & ICU_BROWSER_MODE)
1751 dwURLFlags |= URL_BROWSER_MODE;
1752 dwFlags &= ~ICU_BROWSER_MODE;
1755 if(dwFlags & ICU_NO_ENCODE)
1757 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1758 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1759 dwFlags &= ~ICU_NO_ENCODE;
1762 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1764 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1765 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1766 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1768 return (hr == S_OK) ? TRUE : FALSE;
1771 /* #################################################### */
1773 static INTERNET_STATUS_CALLBACK set_status_callback(
1774 object_header_t *lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1776 INTERNET_STATUS_CALLBACK ret;
1778 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1779 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1781 ret = lpwh->lpfnStatusCB;
1782 lpwh->lpfnStatusCB = callback;
1787 /***********************************************************************
1788 * InternetSetStatusCallbackA (WININET.@)
1790 * Sets up a callback function which is called as progress is made
1791 * during an operation.
1794 * Previous callback or NULL on success
1795 * INTERNET_INVALID_STATUS_CALLBACK on failure
1798 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1799 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1801 INTERNET_STATUS_CALLBACK retVal;
1802 object_header_t *lpwh;
1804 TRACE("%p\n", hInternet);
1806 if (!(lpwh = WININET_GetObject(hInternet)))
1807 return INTERNET_INVALID_STATUS_CALLBACK;
1809 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1811 WININET_Release( lpwh );
1815 /***********************************************************************
1816 * InternetSetStatusCallbackW (WININET.@)
1818 * Sets up a callback function which is called as progress is made
1819 * during an operation.
1822 * Previous callback or NULL on success
1823 * INTERNET_INVALID_STATUS_CALLBACK on failure
1826 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1827 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1829 INTERNET_STATUS_CALLBACK retVal;
1830 object_header_t *lpwh;
1832 TRACE("%p\n", hInternet);
1834 if (!(lpwh = WININET_GetObject(hInternet)))
1835 return INTERNET_INVALID_STATUS_CALLBACK;
1837 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1839 WININET_Release( lpwh );
1843 /***********************************************************************
1844 * InternetSetFilePointer (WININET.@)
1846 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1847 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1853 /***********************************************************************
1854 * InternetWriteFile (WININET.@)
1856 * Write data to an open internet file
1863 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
1864 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1866 object_header_t *lpwh;
1869 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1871 lpwh = WININET_GetObject( hFile );
1873 WARN("Invalid handle\n");
1874 SetLastError(ERROR_INVALID_HANDLE);
1878 if(lpwh->vtbl->WriteFile) {
1879 res = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1881 WARN("No Writefile method.\n");
1882 res = ERROR_INVALID_HANDLE;
1885 WININET_Release( lpwh );
1887 if(res != ERROR_SUCCESS)
1889 return res == ERROR_SUCCESS;
1893 /***********************************************************************
1894 * InternetReadFile (WININET.@)
1896 * Read data from an open internet file
1903 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1904 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1906 object_header_t *hdr;
1907 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1909 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1911 hdr = WININET_GetObject(hFile);
1913 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1917 if(hdr->vtbl->ReadFile)
1918 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1920 WININET_Release(hdr);
1922 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
1923 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1925 if(res != ERROR_SUCCESS)
1927 return res == ERROR_SUCCESS;
1930 /***********************************************************************
1931 * InternetReadFileExA (WININET.@)
1933 * Read data from an open internet file
1936 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1937 * lpBuffersOut [I/O] Buffer.
1938 * dwFlags [I] Flags. See notes.
1939 * dwContext [I] Context for callbacks.
1946 * The parameter dwFlags include zero or more of the following flags:
1947 *|IRF_ASYNC - Makes the call asynchronous.
1948 *|IRF_SYNC - Makes the call synchronous.
1949 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1950 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1952 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1955 * InternetOpenUrlA(), HttpOpenRequestA()
1957 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1958 DWORD dwFlags, DWORD_PTR dwContext)
1960 object_header_t *hdr;
1961 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1963 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1965 hdr = WININET_GetObject(hFile);
1967 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1971 if(hdr->vtbl->ReadFileExA)
1972 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
1974 WININET_Release(hdr);
1976 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
1977 res, lpBuffersOut->dwBufferLength);
1979 if(res != ERROR_SUCCESS)
1981 return res == ERROR_SUCCESS;
1984 /***********************************************************************
1985 * InternetReadFileExW (WININET.@)
1987 * InternetReadFileExA()
1989 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1990 DWORD dwFlags, DWORD_PTR dwContext)
1992 object_header_t *hdr;
1993 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1995 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffer, dwFlags, dwContext);
1997 hdr = WININET_GetObject(hFile);
1999 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2003 if(hdr->vtbl->ReadFileExW)
2004 res = hdr->vtbl->ReadFileExW(hdr, lpBuffer, dwFlags, dwContext);
2006 WININET_Release(hdr);
2008 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
2009 res, lpBuffer->dwBufferLength);
2011 if(res != ERROR_SUCCESS)
2013 return res == ERROR_SUCCESS;
2016 DWORD INET_QueryOption(DWORD option, void *buffer, DWORD *size, BOOL unicode)
2018 static BOOL warn = TRUE;
2021 case INTERNET_OPTION_REQUEST_FLAGS:
2022 TRACE("INTERNET_OPTION_REQUEST_FLAGS\n");
2024 if (*size < sizeof(ULONG))
2025 return ERROR_INSUFFICIENT_BUFFER;
2027 *(ULONG*)buffer = 4;
2028 *size = sizeof(ULONG);
2030 return ERROR_SUCCESS;
2032 case INTERNET_OPTION_HTTP_VERSION:
2033 if (*size < sizeof(HTTP_VERSION_INFO))
2034 return ERROR_INSUFFICIENT_BUFFER;
2037 * Presently hardcoded to 1.1
2039 ((HTTP_VERSION_INFO*)buffer)->dwMajorVersion = 1;
2040 ((HTTP_VERSION_INFO*)buffer)->dwMinorVersion = 1;
2041 *size = sizeof(HTTP_VERSION_INFO);
2043 return ERROR_SUCCESS;
2045 case INTERNET_OPTION_CONNECTED_STATE:
2047 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2050 if (*size < sizeof(ULONG))
2051 return ERROR_INSUFFICIENT_BUFFER;
2053 *(ULONG*)buffer = INTERNET_STATE_CONNECTED;
2054 *size = sizeof(ULONG);
2056 return ERROR_SUCCESS;
2058 case INTERNET_OPTION_PROXY: {
2062 TRACE("Getting global proxy info\n");
2063 memset(&ai, 0, sizeof(appinfo_t));
2064 INTERNET_ConfigureProxy(&ai);
2066 ret = APPINFO_QueryOption(&ai.hdr, INTERNET_OPTION_PROXY, buffer, size, unicode); /* FIXME */
2067 APPINFO_Destroy(&ai.hdr);
2071 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2072 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER\n");
2074 if (*size < sizeof(ULONG))
2075 return ERROR_INSUFFICIENT_BUFFER;
2077 *(ULONG*)buffer = 2;
2078 *size = sizeof(ULONG);
2080 return ERROR_SUCCESS;
2082 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2083 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER\n");
2085 if (*size < sizeof(ULONG))
2086 return ERROR_INSUFFICIENT_BUFFER;
2089 *size = sizeof(ULONG);
2091 return ERROR_SUCCESS;
2093 case INTERNET_OPTION_SECURITY_FLAGS:
2094 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2095 return ERROR_SUCCESS;
2097 case INTERNET_OPTION_VERSION: {
2098 static const INTERNET_VERSION_INFO info = { 1, 2 };
2100 TRACE("INTERNET_OPTION_VERSION\n");
2102 if (*size < sizeof(INTERNET_VERSION_INFO))
2103 return ERROR_INSUFFICIENT_BUFFER;
2105 memcpy(buffer, &info, sizeof(info));
2106 *size = sizeof(info);
2108 return ERROR_SUCCESS;
2111 case INTERNET_OPTION_PER_CONNECTION_OPTION: {
2112 INTERNET_PER_CONN_OPTION_LISTW *con = buffer;
2113 INTERNET_PER_CONN_OPTION_LISTA *conA = buffer;
2114 DWORD res = ERROR_SUCCESS, i;
2117 TRACE("Getting global proxy info\n");
2118 memset(&ai, 0, sizeof(appinfo_t));
2119 INTERNET_ConfigureProxy(&ai);
2121 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2123 if (*size < sizeof(INTERNET_PER_CONN_OPTION_LISTW)) {
2124 APPINFO_Destroy(&ai.hdr);
2125 return ERROR_INSUFFICIENT_BUFFER;
2128 for (i = 0; i < con->dwOptionCount; i++) {
2129 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + i;
2130 INTERNET_PER_CONN_OPTIONA *optionA = conA->pOptions + i;
2132 switch (option->dwOption) {
2133 case INTERNET_PER_CONN_FLAGS:
2134 option->Value.dwValue = ai.dwAccessType;
2137 case INTERNET_PER_CONN_PROXY_SERVER:
2139 option->Value.pszValue = heap_strdupW(ai.lpszProxy);
2141 optionA->Value.pszValue = heap_strdupWtoA(ai.lpszProxy);
2144 case INTERNET_PER_CONN_PROXY_BYPASS:
2146 option->Value.pszValue = heap_strdupW(ai.lpszProxyBypass);
2148 optionA->Value.pszValue = heap_strdupWtoA(ai.lpszProxyBypass);
2151 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2152 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2153 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2154 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2155 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2156 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2157 FIXME("Unhandled dwOption %d\n", option->dwOption);
2158 memset(&option->Value, 0, sizeof(option->Value));
2162 FIXME("Unknown dwOption %d\n", option->dwOption);
2163 res = ERROR_INVALID_PARAMETER;
2167 APPINFO_Destroy(&ai.hdr);
2171 case INTERNET_OPTION_USER_AGENT:
2172 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2175 FIXME("Stub for %d\n", option);
2176 return ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
2179 /***********************************************************************
2180 * InternetQueryOptionW (WININET.@)
2182 * Queries an options on the specified handle
2189 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2190 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2192 object_header_t *hdr;
2193 DWORD res = ERROR_INVALID_HANDLE;
2195 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2198 hdr = WININET_GetObject(hInternet);
2200 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, TRUE);
2201 WININET_Release(hdr);
2204 res = INET_QueryOption(dwOption, lpBuffer, lpdwBufferLength, TRUE);
2207 if(res != ERROR_SUCCESS)
2209 return res == ERROR_SUCCESS;
2212 /***********************************************************************
2213 * InternetQueryOptionA (WININET.@)
2215 * Queries an options on the specified handle
2222 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2223 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2225 object_header_t *hdr;
2226 DWORD res = ERROR_INVALID_HANDLE;
2228 TRACE("%p %d %p %p\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
2231 hdr = WININET_GetObject(hInternet);
2233 res = hdr->vtbl->QueryOption(hdr, dwOption, lpBuffer, lpdwBufferLength, FALSE);
2234 WININET_Release(hdr);
2237 res = INET_QueryOption(dwOption, lpBuffer, lpdwBufferLength, FALSE);
2240 if(res != ERROR_SUCCESS)
2242 return res == ERROR_SUCCESS;
2246 /***********************************************************************
2247 * InternetSetOptionW (WININET.@)
2249 * Sets an options on the specified handle
2256 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2257 LPVOID lpBuffer, DWORD dwBufferLength)
2259 object_header_t *lpwhh;
2262 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2264 lpwhh = (object_header_t*) WININET_GetObject( hInternet );
2265 if(lpwhh && lpwhh->vtbl->SetOption) {
2268 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2269 if(res != ERROR_INTERNET_INVALID_OPTION) {
2270 WININET_Release( lpwhh );
2272 if(res != ERROR_SUCCESS)
2275 return res == ERROR_SUCCESS;
2281 case INTERNET_OPTION_CALLBACK:
2285 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2288 WININET_Release(lpwhh);
2289 SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2292 case INTERNET_OPTION_HTTP_VERSION:
2294 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2295 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2298 case INTERNET_OPTION_ERROR_MASK:
2300 ULONG flags = *(ULONG *)lpBuffer;
2301 FIXME("Option INTERNET_OPTION_ERROR_MASK(%d): STUB\n", flags);
2304 case INTERNET_OPTION_CODEPAGE:
2306 ULONG codepage = *(ULONG *)lpBuffer;
2307 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2310 case INTERNET_OPTION_REQUEST_PRIORITY:
2312 ULONG priority = *(ULONG *)lpBuffer;
2313 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2316 case INTERNET_OPTION_CONNECT_TIMEOUT:
2318 ULONG connecttimeout = *(ULONG *)lpBuffer;
2319 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2322 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2324 ULONG receivetimeout = *(ULONG *)lpBuffer;
2325 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2328 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2330 ULONG conns = *(ULONG *)lpBuffer;
2331 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2334 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2336 ULONG conns = *(ULONG *)lpBuffer;
2337 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2340 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2341 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2343 case INTERNET_OPTION_END_BROWSER_SESSION:
2344 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2346 case INTERNET_OPTION_CONNECTED_STATE:
2347 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2349 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2350 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2352 case INTERNET_OPTION_SEND_TIMEOUT:
2353 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2355 ULONG timeout = *(ULONG *)lpBuffer;
2356 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout);
2359 case INTERNET_OPTION_CONNECT_RETRIES:
2361 ULONG retries = *(ULONG *)lpBuffer;
2362 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2365 case INTERNET_OPTION_CONTEXT_VALUE:
2366 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2368 case INTERNET_OPTION_SECURITY_FLAGS:
2369 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2371 case INTERNET_OPTION_DISABLE_AUTODIAL:
2372 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2374 case INTERNET_OPTION_HTTP_DECODING:
2375 FIXME("INTERNET_OPTION_HTTP_DECODING; STUB\n");
2376 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2379 case INTERNET_OPTION_COOKIES_3RD_PARTY:
2380 FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n");
2381 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2384 case INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY:
2385 FIXME("INTERNET_OPTION_SEND_UTF8_SERVERNAME_TO_PROXY; STUB\n");
2386 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2389 case INTERNET_OPTION_CODEPAGE_PATH:
2390 FIXME("INTERNET_OPTION_CODEPAGE_PATH; STUB\n");
2391 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2394 case INTERNET_OPTION_CODEPAGE_EXTRA:
2395 FIXME("INTERNET_OPTION_CODEPAGE_EXTRA; STUB\n");
2396 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2399 case INTERNET_OPTION_IDN:
2400 FIXME("INTERNET_OPTION_IDN; STUB\n");
2401 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2405 FIXME("Option %d STUB\n",dwOption);
2406 SetLastError(ERROR_INTERNET_INVALID_OPTION);
2412 WININET_Release( lpwhh );
2418 /***********************************************************************
2419 * InternetSetOptionA (WININET.@)
2421 * Sets an options on the specified handle.
2428 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2429 LPVOID lpBuffer, DWORD dwBufferLength)
2437 case INTERNET_OPTION_CALLBACK:
2439 object_header_t *lpwh;
2441 if (!(lpwh = WININET_GetObject(hInternet)))
2443 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2446 WININET_Release(lpwh);
2447 INTERNET_SetLastError(ERROR_INTERNET_OPTION_NOT_SETTABLE);
2450 case INTERNET_OPTION_PROXY:
2452 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2453 LPINTERNET_PROXY_INFOW piw;
2454 DWORD proxlen, prbylen;
2457 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2458 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2459 wlen = sizeof(*piw) + proxlen + prbylen;
2460 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2461 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2462 piw->dwAccessType = pi->dwAccessType;
2463 prox = (LPWSTR) &piw[1];
2464 prby = &prox[proxlen+1];
2465 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2466 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2467 piw->lpszProxy = prox;
2468 piw->lpszProxyBypass = prby;
2471 case INTERNET_OPTION_USER_AGENT:
2472 case INTERNET_OPTION_USERNAME:
2473 case INTERNET_OPTION_PASSWORD:
2474 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2476 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2477 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2482 wlen = dwBufferLength;
2485 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2487 if( lpBuffer != wbuffer )
2488 HeapFree( GetProcessHeap(), 0, wbuffer );
2494 /***********************************************************************
2495 * InternetSetOptionExA (WININET.@)
2497 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2498 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2500 FIXME("Flags %08x ignored\n", dwFlags);
2501 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2504 /***********************************************************************
2505 * InternetSetOptionExW (WININET.@)
2507 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2508 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2510 FIXME("Flags %08x ignored\n", dwFlags);
2511 if( dwFlags & ~ISO_VALID_FLAGS )
2513 SetLastError( ERROR_INVALID_PARAMETER );
2516 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2519 static const WCHAR WININET_wkday[7][4] =
2520 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2521 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2522 static const WCHAR WININET_month[12][4] =
2523 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2524 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2525 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2527 /***********************************************************************
2528 * InternetTimeFromSystemTimeA (WININET.@)
2530 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2533 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2535 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2537 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2539 SetLastError(ERROR_INVALID_PARAMETER);
2543 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2545 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2549 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2550 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2555 /***********************************************************************
2556 * InternetTimeFromSystemTimeW (WININET.@)
2558 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2560 static const WCHAR date[] =
2561 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2562 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2564 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2566 if (!time || !string || format != INTERNET_RFC1123_FORMAT)
2568 SetLastError(ERROR_INVALID_PARAMETER);
2572 if (size < INTERNET_RFC1123_BUFSIZE * sizeof(*string))
2574 SetLastError(ERROR_INSUFFICIENT_BUFFER);
2578 sprintfW( string, date,
2579 WININET_wkday[time->wDayOfWeek],
2581 WININET_month[time->wMonth - 1],
2590 /***********************************************************************
2591 * InternetTimeToSystemTimeA (WININET.@)
2593 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2598 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2600 stringW = heap_strdupAtoW(string);
2603 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2604 HeapFree( GetProcessHeap(), 0, stringW );
2609 /***********************************************************************
2610 * InternetTimeToSystemTimeW (WININET.@)
2612 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2615 const WCHAR *s = string;
2618 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2620 if (!string || !time) return FALSE;
2622 /* Windows does this too */
2623 GetSystemTime( time );
2625 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2626 * a SYSTEMTIME structure.
2629 while (*s && !isalphaW( *s )) s++;
2630 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2631 time->wDayOfWeek = 7;
2633 for (i = 0; i < 7; i++)
2635 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2636 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2637 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2639 time->wDayOfWeek = i;
2644 if (time->wDayOfWeek > 6) return TRUE;
2645 while (*s && !isdigitW( *s )) s++;
2646 time->wDay = strtolW( s, &end, 10 );
2649 while (*s && !isalphaW( *s )) s++;
2650 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2653 for (i = 0; i < 12; i++)
2655 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2656 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2657 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2659 time->wMonth = i + 1;
2663 if (time->wMonth == 0) return TRUE;
2665 while (*s && !isdigitW( *s )) s++;
2666 if (*s == '\0') return TRUE;
2667 time->wYear = strtolW( s, &end, 10 );
2670 while (*s && !isdigitW( *s )) s++;
2671 if (*s == '\0') return TRUE;
2672 time->wHour = strtolW( s, &end, 10 );
2675 while (*s && !isdigitW( *s )) s++;
2676 if (*s == '\0') return TRUE;
2677 time->wMinute = strtolW( s, &end, 10 );
2680 while (*s && !isdigitW( *s )) s++;
2681 if (*s == '\0') return TRUE;
2682 time->wSecond = strtolW( s, &end, 10 );
2685 time->wMilliseconds = 0;
2689 /***********************************************************************
2690 * InternetCheckConnectionW (WININET.@)
2692 * Pings a requested host to check internet connection
2695 * TRUE on success and FALSE on failure. If a failure then
2696 * ERROR_NOT_CONNECTED is placed into GetLastError
2699 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2702 * this is a kludge which runs the resident ping program and reads the output.
2704 * Anyone have a better idea?
2708 static const CHAR ping[] = "ping -c 1 ";
2709 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2710 CHAR *command = NULL;
2719 * Crack or set the Address
2721 if (lpszUrl == NULL)
2724 * According to the doc we are supposed to use the ip for the next
2725 * server in the WnInet internal server database. I have
2726 * no idea what that is or how to get it.
2728 * So someone needs to implement this.
2730 FIXME("Unimplemented with URL of NULL\n");
2735 URL_COMPONENTSW components;
2737 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2738 components.lpszHostName = (LPWSTR)hostW;
2739 components.dwHostNameLength = 1024;
2741 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2744 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2745 port = components.nPort;
2746 TRACE("port: %d\n", port);
2749 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2751 struct sockaddr_storage saddr;
2752 socklen_t sa_len = sizeof(saddr);
2755 if (!GetAddress(hostW, port, (struct sockaddr *)&saddr, &sa_len))
2757 fd = socket(saddr.ss_family, SOCK_STREAM, 0);
2760 if (connect(fd, (struct sockaddr *)&saddr, sa_len) == 0)
2768 * Build our ping command
2770 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2771 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2772 strcpy(command,ping);
2773 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2774 strcat(command,redirect);
2776 TRACE("Ping command is : %s\n",command);
2778 status = system(command);
2780 TRACE("Ping returned a code of %i\n",status);
2782 /* Ping return code of 0 indicates success */
2789 HeapFree( GetProcessHeap(), 0, command );
2791 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2797 /***********************************************************************
2798 * InternetCheckConnectionA (WININET.@)
2800 * Pings a requested host to check internet connection
2803 * TRUE on success and FALSE on failure. If a failure then
2804 * ERROR_NOT_CONNECTED is placed into GetLastError
2807 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2813 url = heap_strdupAtoW(lpszUrl);
2818 rc = InternetCheckConnectionW(url, dwFlags, dwReserved);
2820 HeapFree(GetProcessHeap(), 0, url);
2825 /**********************************************************
2826 * INTERNET_InternetOpenUrlW (internal)
2831 * handle of connection or NULL on failure
2833 static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
2834 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2836 URL_COMPONENTSW urlComponents;
2837 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2838 WCHAR password[1024], path[2048], extra[1024];
2839 HINTERNET client = NULL, client1 = NULL;
2842 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2843 dwHeadersLength, dwFlags, dwContext);
2845 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2846 urlComponents.lpszScheme = protocol;
2847 urlComponents.dwSchemeLength = 32;
2848 urlComponents.lpszHostName = hostName;
2849 urlComponents.dwHostNameLength = MAXHOSTNAME;
2850 urlComponents.lpszUserName = userName;
2851 urlComponents.dwUserNameLength = 1024;
2852 urlComponents.lpszPassword = password;
2853 urlComponents.dwPasswordLength = 1024;
2854 urlComponents.lpszUrlPath = path;
2855 urlComponents.dwUrlPathLength = 2048;
2856 urlComponents.lpszExtraInfo = extra;
2857 urlComponents.dwExtraInfoLength = 1024;
2858 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2860 switch(urlComponents.nScheme) {
2861 case INTERNET_SCHEME_FTP:
2862 if(urlComponents.nPort == 0)
2863 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2864 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2865 userName, password, dwFlags, dwContext, INET_OPENURL);
2868 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2869 if(client1 == NULL) {
2870 InternetCloseHandle(client);
2875 case INTERNET_SCHEME_HTTP:
2876 case INTERNET_SCHEME_HTTPS: {
2877 static const WCHAR szStars[] = { '*','/','*', 0 };
2878 LPCWSTR accept[2] = { szStars, NULL };
2879 if(urlComponents.nPort == 0) {
2880 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2881 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2883 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2885 if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
2887 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2888 res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2889 userName, password, dwFlags, dwContext, INET_OPENURL, &client);
2890 if(res != ERROR_SUCCESS) {
2891 INTERNET_SetLastError(res);
2895 if (urlComponents.dwExtraInfoLength) {
2897 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2899 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2901 InternetCloseHandle(client);
2904 strcpyW(path_extra, urlComponents.lpszUrlPath);
2905 strcatW(path_extra, urlComponents.lpszExtraInfo);
2906 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2907 HeapFree(GetProcessHeap(), 0, path_extra);
2910 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2912 if(client1 == NULL) {
2913 InternetCloseHandle(client);
2916 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2917 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2918 GetLastError() != ERROR_IO_PENDING) {
2919 InternetCloseHandle(client1);
2924 case INTERNET_SCHEME_GOPHER:
2925 /* gopher doesn't seem to be implemented in wine, but it's supposed
2926 * to be supported by InternetOpenUrlA. */
2928 SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2932 TRACE(" %p <--\n", client1);
2937 /**********************************************************
2938 * InternetOpenUrlW (WININET.@)
2943 * handle of connection or NULL on failure
2945 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2947 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2948 appinfo_t *hIC = (appinfo_t*) workRequest->hdr;
2952 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2953 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2954 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2955 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2958 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2959 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2961 HINTERNET ret = NULL;
2962 appinfo_t *hIC = NULL;
2964 if (TRACE_ON(wininet)) {
2965 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2966 dwHeadersLength, dwFlags, dwContext);
2968 dump_INTERNET_FLAGS(dwFlags);
2973 SetLastError(ERROR_INVALID_PARAMETER);
2977 hIC = (appinfo_t*)WININET_GetObject( hInternet );
2978 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2979 SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2983 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2984 WORKREQUEST workRequest;
2985 struct WORKREQ_INTERNETOPENURLW *req;
2987 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2988 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2989 req = &workRequest.u.InternetOpenUrlW;
2990 req->lpszUrl = heap_strdupW(lpszUrl);
2991 req->lpszHeaders = heap_strdupW(lpszHeaders);
2992 req->dwHeadersLength = dwHeadersLength;
2993 req->dwFlags = dwFlags;
2994 req->dwContext = dwContext;
2996 INTERNET_AsyncCall(&workRequest);
2998 * This is from windows.
3000 SetLastError(ERROR_IO_PENDING);
3002 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3007 WININET_Release( &hIC->hdr );
3008 TRACE(" %p <--\n", ret);
3013 /**********************************************************
3014 * InternetOpenUrlA (WININET.@)
3019 * handle of connection or NULL on failure
3021 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3022 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3024 HINTERNET rc = NULL;
3025 DWORD lenHeaders = 0;
3026 LPWSTR szUrl = NULL;
3027 LPWSTR szHeaders = NULL;
3032 szUrl = heap_strdupAtoW(lpszUrl);
3038 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3039 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3041 HeapFree(GetProcessHeap(), 0, szUrl);
3044 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3047 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3048 lenHeaders, dwFlags, dwContext);
3050 HeapFree(GetProcessHeap(), 0, szUrl);
3051 HeapFree(GetProcessHeap(), 0, szHeaders);
3057 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3059 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3063 lpwite->dwError = 0;
3064 lpwite->response[0] = '\0';
3067 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3069 HeapFree(GetProcessHeap(), 0, lpwite);
3077 /***********************************************************************
3078 * INTERNET_SetLastError (internal)
3080 * Set last thread specific error
3085 void INTERNET_SetLastError(DWORD dwError)
3087 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3090 lpwite = INTERNET_AllocThreadError();
3092 SetLastError(dwError);
3094 lpwite->dwError = dwError;
3098 /***********************************************************************
3099 * INTERNET_GetLastError (internal)
3101 * Get last thread specific error
3106 DWORD INTERNET_GetLastError(void)
3108 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3109 if (!lpwite) return 0;
3110 /* TlsGetValue clears last error, so set it again here */
3111 SetLastError(lpwite->dwError);
3112 return lpwite->dwError;
3116 /***********************************************************************
3117 * INTERNET_WorkerThreadFunc (internal)
3119 * Worker thread execution function
3124 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3126 LPWORKREQUEST lpRequest = lpvParam;
3127 WORKREQUEST workRequest;
3131 workRequest = *lpRequest;
3132 HeapFree(GetProcessHeap(), 0, lpRequest);
3134 workRequest.asyncproc(&workRequest);
3135 WININET_Release( workRequest.hdr );
3137 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
3139 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
3140 TlsSetValue(g_dwTlsErrIndex, NULL);
3146 /***********************************************************************
3147 * INTERNET_AsyncCall (internal)
3149 * Retrieves work request from queue
3154 DWORD INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3157 LPWORKREQUEST lpNewRequest;
3161 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3163 return ERROR_OUTOFMEMORY;
3165 *lpNewRequest = *lpWorkRequest;
3167 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3170 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3171 return ERROR_INTERNET_ASYNC_THREAD_FAILED;
3174 return ERROR_SUCCESS;
3178 /***********************************************************************
3179 * INTERNET_GetResponseBuffer (internal)
3184 LPSTR INTERNET_GetResponseBuffer(void)
3186 LPWITHREADERROR lpwite = TlsGetValue(g_dwTlsErrIndex);
3188 lpwite = INTERNET_AllocThreadError();
3190 return lpwite->response;
3193 /***********************************************************************
3194 * INTERNET_GetNextLine (internal)
3196 * Parse next line in directory string listing
3199 * Pointer to beginning of next line
3204 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3207 BOOL bSuccess = FALSE;
3209 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3214 pfd.events = POLLIN;
3216 while (nRecv < MAX_REPLY_LEN)
3218 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3220 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3222 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3226 if (lpszBuffer[nRecv] == '\n')
3231 if (lpszBuffer[nRecv] != '\r')
3236 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3244 lpszBuffer[nRecv] = '\0';
3246 TRACE(":%d %s\n", nRecv, lpszBuffer);
3255 /**********************************************************
3256 * InternetQueryDataAvailable (WININET.@)
3258 * Determines how much data is available to be read.
3261 * TRUE on success, FALSE if an error occurred. If
3262 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3263 * no data is presently available, FALSE is returned with
3264 * the last error ERROR_IO_PENDING; a callback with status
3265 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3266 * data is available.
3268 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3269 LPDWORD lpdwNumberOfBytesAvailble,
3270 DWORD dwFlags, DWORD_PTR dwContext)
3272 object_header_t *hdr;
3275 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3277 hdr = WININET_GetObject( hFile );
3279 SetLastError(ERROR_INVALID_HANDLE);
3283 if(hdr->vtbl->QueryDataAvailable) {
3284 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3286 WARN("wrong handle\n");
3287 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3290 WININET_Release(hdr);
3292 if(res != ERROR_SUCCESS)
3294 return res == ERROR_SUCCESS;
3298 /***********************************************************************
3299 * InternetLockRequestFile (WININET.@)
3301 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3308 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3315 /***********************************************************************
3316 * InternetAutodial (WININET.@)
3318 * On windows this function is supposed to dial the default internet
3319 * connection. We don't want to have Wine dial out to the internet so
3320 * we return TRUE by default. It might be nice to check if we are connected.
3327 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3331 /* Tell that we are connected to the internet. */
3335 /***********************************************************************
3336 * InternetAutodialHangup (WININET.@)
3338 * Hangs up a connection made with InternetAutodial
3347 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3351 /* we didn't dial, we don't disconnect */
3355 /***********************************************************************
3356 * InternetCombineUrlA (WININET.@)
3358 * Combine a base URL with a relative URL
3366 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3367 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3372 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3374 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3375 dwFlags ^= ICU_NO_ENCODE;
3376 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3381 /***********************************************************************
3382 * InternetCombineUrlW (WININET.@)
3384 * Combine a base URL with a relative URL
3392 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3393 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3398 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3400 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3401 dwFlags ^= ICU_NO_ENCODE;
3402 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3407 /* max port num is 65535 => 5 digits */
3408 #define MAX_WORD_DIGITS 5
3410 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3411 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3412 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3413 (url)->dw##component##Length : strlen((url)->lpsz##component))
3415 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3417 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3418 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3420 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3421 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3423 if ((nScheme == INTERNET_SCHEME_FTP) &&
3424 (nPort == INTERNET_DEFAULT_FTP_PORT))
3426 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3427 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3430 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3436 /* opaque urls do not fit into the standard url hierarchy and don't have
3437 * two following slashes */
3438 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3440 return (nScheme != INTERNET_SCHEME_FTP) &&
3441 (nScheme != INTERNET_SCHEME_GOPHER) &&
3442 (nScheme != INTERNET_SCHEME_HTTP) &&
3443 (nScheme != INTERNET_SCHEME_HTTPS) &&
3444 (nScheme != INTERNET_SCHEME_FILE);
3447 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3450 if (scheme < INTERNET_SCHEME_FIRST)
3452 index = scheme - INTERNET_SCHEME_FIRST;
3453 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3455 return (LPCWSTR)url_schemes[index];
3458 /* we can calculate using ansi strings because we're just
3459 * calculating string length, not size
3461 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3462 LPDWORD lpdwUrlLength)
3464 INTERNET_SCHEME nScheme;
3468 if (lpUrlComponents->lpszScheme)
3470 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3471 *lpdwUrlLength += dwLen;
3472 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3478 nScheme = lpUrlComponents->nScheme;
3480 if (nScheme == INTERNET_SCHEME_DEFAULT)
3481 nScheme = INTERNET_SCHEME_HTTP;
3482 scheme = INTERNET_GetSchemeString(nScheme);
3483 *lpdwUrlLength += strlenW(scheme);
3486 (*lpdwUrlLength)++; /* ':' */
3487 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3488 *lpdwUrlLength += strlen("//");
3490 if (lpUrlComponents->lpszUserName)
3492 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3493 *lpdwUrlLength += strlen("@");
3497 if (lpUrlComponents->lpszPassword)
3499 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3504 if (lpUrlComponents->lpszPassword)
3506 *lpdwUrlLength += strlen(":");
3507 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3510 if (lpUrlComponents->lpszHostName)
3512 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3514 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3516 char szPort[MAX_WORD_DIGITS+1];
3518 sprintf(szPort, "%d", lpUrlComponents->nPort);
3519 *lpdwUrlLength += strlen(szPort);
3520 *lpdwUrlLength += strlen(":");
3523 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3524 (*lpdwUrlLength)++; /* '/' */
3527 if (lpUrlComponents->lpszUrlPath)
3528 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3530 if (lpUrlComponents->lpszExtraInfo)
3531 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3536 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3540 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3542 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3543 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3544 urlCompW->nScheme = lpUrlComponents->nScheme;
3545 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3546 urlCompW->nPort = lpUrlComponents->nPort;
3547 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3548 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3549 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3550 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3552 if (lpUrlComponents->lpszScheme)
3554 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3555 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3556 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3557 -1, urlCompW->lpszScheme, len);
3560 if (lpUrlComponents->lpszHostName)
3562 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3563 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3564 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3565 -1, urlCompW->lpszHostName, len);
3568 if (lpUrlComponents->lpszUserName)
3570 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3571 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3572 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3573 -1, urlCompW->lpszUserName, len);
3576 if (lpUrlComponents->lpszPassword)
3578 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3579 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3580 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3581 -1, urlCompW->lpszPassword, len);
3584 if (lpUrlComponents->lpszUrlPath)
3586 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3587 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3588 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3589 -1, urlCompW->lpszUrlPath, len);
3592 if (lpUrlComponents->lpszExtraInfo)
3594 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3595 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3596 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3597 -1, urlCompW->lpszExtraInfo, len);
3601 /***********************************************************************
3602 * InternetCreateUrlA (WININET.@)
3604 * See InternetCreateUrlW.
3606 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3607 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3611 URL_COMPONENTSW urlCompW;
3613 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3615 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3617 SetLastError(ERROR_INVALID_PARAMETER);
3621 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3624 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3626 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3628 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3629 *lpdwUrlLength /= sizeof(WCHAR);
3631 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3632 * minus one, so add one to leave room for NULL terminator
3635 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3637 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3638 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3639 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3640 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3641 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3642 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3643 HeapFree(GetProcessHeap(), 0, urlW);
3648 /***********************************************************************
3649 * InternetCreateUrlW (WININET.@)
3651 * Creates a URL from its component parts.
3654 * lpUrlComponents [I] URL Components.
3655 * dwFlags [I] Flags. See notes.
3656 * lpszUrl [I] Buffer in which to store the created URL.
3657 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3658 * lpszUrl in characters. On output, the number of bytes
3659 * required to store the URL including terminator.
3663 * The dwFlags parameter can be zero or more of the following:
3664 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3671 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3672 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3675 INTERNET_SCHEME nScheme;
3677 static const WCHAR slashSlashW[] = {'/','/'};
3678 static const WCHAR percentD[] = {'%','d',0};
3680 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3682 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3684 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3688 if (!calc_url_length(lpUrlComponents, &dwLen))
3691 if (!lpszUrl || *lpdwUrlLength < dwLen)
3693 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3694 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3698 *lpdwUrlLength = dwLen;
3703 if (lpUrlComponents->lpszScheme)
3705 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3706 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3709 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3714 nScheme = lpUrlComponents->nScheme;
3716 if (nScheme == INTERNET_SCHEME_DEFAULT)
3717 nScheme = INTERNET_SCHEME_HTTP;
3719 scheme = INTERNET_GetSchemeString(nScheme);
3720 dwLen = strlenW(scheme);
3721 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3725 /* all schemes are followed by at least a colon */
3729 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3731 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3732 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3735 if (lpUrlComponents->lpszUserName)
3737 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3738 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3741 if (lpUrlComponents->lpszPassword)
3746 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3747 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3755 if (lpUrlComponents->lpszHostName)
3757 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3758 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3761 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3763 WCHAR szPort[MAX_WORD_DIGITS+1];
3765 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3768 dwLen = strlenW(szPort);
3769 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3773 /* add slash between hostname and path if necessary */
3774 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3781 if (lpUrlComponents->lpszUrlPath)
3783 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3784 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3788 if (lpUrlComponents->lpszExtraInfo)
3790 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, ExtraInfo);
3791 memcpy(lpszUrl, lpUrlComponents->lpszExtraInfo, dwLen * sizeof(WCHAR));
3800 /***********************************************************************
3801 * InternetConfirmZoneCrossingA (WININET.@)
3804 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3806 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3807 return ERROR_SUCCESS;
3810 /***********************************************************************
3811 * InternetConfirmZoneCrossingW (WININET.@)
3814 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3816 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3817 return ERROR_SUCCESS;
3820 static DWORD zone_preference = 3;
3822 /***********************************************************************
3823 * PrivacySetZonePreferenceW (WININET.@)
3825 DWORD WINAPI PrivacySetZonePreferenceW( DWORD zone, DWORD type, DWORD template, LPCWSTR preference )
3827 FIXME( "%x %x %x %s: stub\n", zone, type, template, debugstr_w(preference) );
3829 zone_preference = template;
3833 /***********************************************************************
3834 * PrivacyGetZonePreferenceW (WININET.@)
3836 DWORD WINAPI PrivacyGetZonePreferenceW( DWORD zone, DWORD type, LPDWORD template,
3837 LPWSTR preference, LPDWORD length )
3839 FIXME( "%x %x %p %p %p: stub\n", zone, type, template, preference, length );
3841 if (template) *template = zone_preference;
3845 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3846 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3848 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3849 lpdwConnection, dwReserved);
3850 return ERROR_SUCCESS;
3853 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3854 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3856 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3857 lpdwConnection, dwReserved);
3858 return ERROR_SUCCESS;
3861 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3863 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3867 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3869 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3873 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3875 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3876 return ERROR_SUCCESS;
3879 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3882 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3883 debugstr_w(pwszTarget), pbHexHash);
3887 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3889 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3893 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
3895 FIXME("(%p, %08lx) stub\n", a, b);