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 */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
44 #ifdef HAVE_SYS_POLL_H
45 # include <sys/poll.h>
47 #ifdef HAVE_SYS_TIME_H
48 # include <sys/time.h>
64 #include "wine/debug.h"
66 #define NO_SHLWAPI_STREAM
69 #include "wine/exception.h"
74 #include "wine/unicode.h"
76 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
78 #define RESPONSE_TIMEOUT 30
83 CHAR response[MAX_REPLY_LEN];
84 } WITHREADERROR, *LPWITHREADERROR;
86 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
87 static HMODULE WININET_hModule;
89 #define HANDLE_CHUNK_SIZE 0x10
91 static CRITICAL_SECTION WININET_cs;
92 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
95 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
96 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
98 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
100 static LPWININETHANDLEHEADER *WININET_Handles;
101 static UINT WININET_dwNextHandle;
102 static UINT WININET_dwMaxHandles;
104 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
106 LPWININETHANDLEHEADER *p;
107 UINT handle = 0, num;
109 list_init( &info->children );
111 EnterCriticalSection( &WININET_cs );
112 if( !WININET_dwMaxHandles )
114 num = HANDLE_CHUNK_SIZE;
115 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
120 WININET_dwMaxHandles = num;
122 if( WININET_dwMaxHandles == WININET_dwNextHandle )
124 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
125 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
126 WININET_Handles, sizeof (UINT)* num);
130 WININET_dwMaxHandles = num;
133 handle = WININET_dwNextHandle;
134 if( WININET_Handles[handle] )
135 ERR("handle isn't free but should be\n");
136 WININET_Handles[handle] = WININET_AddRef( info );
138 while( WININET_Handles[WININET_dwNextHandle] &&
139 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
140 WININET_dwNextHandle++;
143 LeaveCriticalSection( &WININET_cs );
145 return info->hInternet = (HINTERNET) (handle+1);
148 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
150 ULONG refs = InterlockedIncrement(&info->refs);
151 TRACE("%p -> refcount = %d\n", info, refs );
155 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
157 LPWININETHANDLEHEADER info = NULL;
158 UINT handle = (UINT) hinternet;
160 EnterCriticalSection( &WININET_cs );
162 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
163 WININET_Handles[handle-1] )
164 info = WININET_AddRef( WININET_Handles[handle-1] );
166 LeaveCriticalSection( &WININET_cs );
168 TRACE("handle %d -> %p\n", handle, info);
173 BOOL WININET_Release( LPWININETHANDLEHEADER info )
175 ULONG refs = InterlockedDecrement(&info->refs);
176 TRACE( "object %p refcount = %d\n", info, refs );
179 if ( info->vtbl->CloseConnection )
181 TRACE( "closing connection %p\n", info);
182 info->vtbl->CloseConnection( info );
184 /* Don't send a callback if this is a session handle created with InternetOpenUrl */
185 if (info->htype != WH_HHTTPSESSION || !(info->dwInternalFlags & INET_OPENURL))
187 INTERNET_SendCallback(info, info->dwContext,
188 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
191 TRACE( "destroying object %p\n", info);
192 if ( info->htype != WH_HINIT )
193 list_remove( &info->entry );
194 info->vtbl->Destroy( info );
199 BOOL WININET_FreeHandle( HINTERNET hinternet )
202 UINT handle = (UINT) hinternet;
203 LPWININETHANDLEHEADER info = NULL, child, next;
205 EnterCriticalSection( &WININET_cs );
207 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
210 if( WININET_Handles[handle] )
212 info = WININET_Handles[handle];
213 TRACE( "destroying handle %d for object %p\n", handle+1, info);
214 WININET_Handles[handle] = NULL;
219 LeaveCriticalSection( &WININET_cs );
221 /* As on native when the equivalent of WININET_Release is called, the handle
222 * is already invalid, but if a new handle is created at this time it does
223 * not yet get assigned the freed handle number */
226 /* Free all children as native does */
227 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, WININETHANDLEHEADER, entry )
229 TRACE( "freeing child handle %d for parent handle %d\n",
230 (UINT)child->hInternet, handle+1);
231 WININET_FreeHandle( child->hInternet );
233 WININET_Release( info );
236 EnterCriticalSection( &WININET_cs );
238 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
239 WININET_dwNextHandle = handle;
241 LeaveCriticalSection( &WININET_cs );
246 /***********************************************************************
247 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
250 * hinstDLL [I] handle to the DLL's instance
252 * lpvReserved [I] reserved, must be NULL
259 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
261 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
264 case DLL_PROCESS_ATTACH:
266 g_dwTlsErrIndex = TlsAlloc();
268 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
271 URLCacheContainers_CreateDefaults();
273 WININET_hModule = hinstDLL;
275 case DLL_THREAD_ATTACH:
278 case DLL_THREAD_DETACH:
279 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
281 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
282 HeapFree(GetProcessHeap(), 0, lpwite);
286 case DLL_PROCESS_DETACH:
288 URLCacheContainers_DeleteAll();
290 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
292 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
293 TlsFree(g_dwTlsErrIndex);
302 /***********************************************************************
303 * InternetInitializeAutoProxyDll (WININET.@)
305 * Setup the internal proxy
314 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
317 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
321 /***********************************************************************
322 * DetectAutoProxyUrl (WININET.@)
324 * Auto detect the proxy url
330 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
331 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
334 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
339 /***********************************************************************
340 * INTERNET_ConfigureProxy
343 * The proxy may be specified in the form 'http=proxy.my.org'
344 * Presumably that means there can be ftp=ftpproxy.my.org too.
346 static BOOL INTERNET_ConfigureProxy( LPWININETAPPINFOW lpwai )
349 DWORD type, len, enabled = 0;
351 static const WCHAR szInternetSettings[] =
352 { 'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
353 'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
354 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0 };
355 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
356 static const WCHAR szProxyEnable[] = { 'P','r','o','x','y','E','n','a','b','l','e', 0 };
358 if (RegOpenKeyW( HKEY_CURRENT_USER, szInternetSettings, &key )) return FALSE;
360 len = sizeof enabled;
361 if (RegQueryValueExW( key, szProxyEnable, NULL, &type, (BYTE *)&enabled, &len ) || type != REG_DWORD)
362 RegSetValueExW( key, szProxyEnable, 0, REG_DWORD, (BYTE *)&enabled, sizeof(REG_DWORD) );
366 TRACE("Proxy is enabled.\n");
368 /* figure out how much memory the proxy setting takes */
369 if (!RegQueryValueExW( key, szProxyServer, NULL, &type, NULL, &len ) && len && (type == REG_SZ))
372 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
374 if (!(szProxy = HeapAlloc( GetProcessHeap(), 0, len )))
379 RegQueryValueExW( key, szProxyServer, NULL, &type, (BYTE*)szProxy, &len );
381 /* find the http proxy, and strip away everything else */
382 p = strstrW( szProxy, szHttp );
385 p += lstrlenW( szHttp );
386 lstrcpyW( szProxy, p );
388 p = strchrW( szProxy, ' ' );
391 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
392 lpwai->lpszProxy = szProxy;
394 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
397 ERR("Couldn't read proxy server settings from registry.\n");
399 else if ((envproxy = getenv( "http_proxy" )))
403 len = MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, NULL, 0 );
404 if (!(envproxyW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR)))) return FALSE;
405 MultiByteToWideChar( CP_UNIXCP, 0, envproxy, -1, envproxyW, len );
407 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
408 lpwai->lpszProxy = envproxyW;
410 TRACE("http proxy (from environment) = %s\n", debugstr_w(lpwai->lpszProxy));
413 if (!enabled) TRACE("Proxy is not enabled.\n");
416 return (enabled > 0);
419 /***********************************************************************
420 * dump_INTERNET_FLAGS
422 * Helper function to TRACE the internet flags.
428 static void dump_INTERNET_FLAGS(DWORD dwFlags)
430 #define FE(x) { x, #x }
431 static const wininet_flag_info flag[] = {
432 FE(INTERNET_FLAG_RELOAD),
433 FE(INTERNET_FLAG_RAW_DATA),
434 FE(INTERNET_FLAG_EXISTING_CONNECT),
435 FE(INTERNET_FLAG_ASYNC),
436 FE(INTERNET_FLAG_PASSIVE),
437 FE(INTERNET_FLAG_NO_CACHE_WRITE),
438 FE(INTERNET_FLAG_MAKE_PERSISTENT),
439 FE(INTERNET_FLAG_FROM_CACHE),
440 FE(INTERNET_FLAG_SECURE),
441 FE(INTERNET_FLAG_KEEP_CONNECTION),
442 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
443 FE(INTERNET_FLAG_READ_PREFETCH),
444 FE(INTERNET_FLAG_NO_COOKIES),
445 FE(INTERNET_FLAG_NO_AUTH),
446 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
447 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
448 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
449 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
450 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
451 FE(INTERNET_FLAG_RESYNCHRONIZE),
452 FE(INTERNET_FLAG_HYPERLINK),
453 FE(INTERNET_FLAG_NO_UI),
454 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
455 FE(INTERNET_FLAG_CACHE_ASYNC),
456 FE(INTERNET_FLAG_FORMS_SUBMIT),
457 FE(INTERNET_FLAG_NEED_FILE),
458 FE(INTERNET_FLAG_TRANSFER_ASCII),
459 FE(INTERNET_FLAG_TRANSFER_BINARY)
464 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
465 if (flag[i].val & dwFlags) {
466 TRACE(" %s", flag[i].name);
467 dwFlags &= ~flag[i].val;
471 TRACE(" Unknown flags (%08x)\n", dwFlags);
476 /***********************************************************************
477 * INTERNET_CloseHandle (internal)
479 * Close internet handle
482 static VOID APPINFO_Destroy(WININETHANDLEHEADER *hdr)
484 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
488 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
489 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
490 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
491 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
492 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
493 HeapFree(GetProcessHeap(), 0, lpwai);
496 static DWORD APPINFO_QueryOption(WININETHANDLEHEADER *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
499 case INTERNET_OPTION_HANDLE_TYPE:
500 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
502 if (*size < sizeof(ULONG))
503 return ERROR_INSUFFICIENT_BUFFER;
505 *size = sizeof(DWORD);
506 *(DWORD*)buffer = INTERNET_HANDLE_TYPE_INTERNET;
507 return ERROR_SUCCESS;
510 FIXME("Not implemented option %d\n", option);
511 return ERROR_INTERNET_INVALID_OPTION;
514 static const HANDLEHEADERVtbl APPINFOVtbl = {
527 /***********************************************************************
528 * InternetOpenW (WININET.@)
530 * Per-application initialization of wininet
533 * HINTERNET on success
537 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
538 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
540 LPWININETAPPINFOW lpwai = NULL;
541 HINTERNET handle = NULL;
543 if (TRACE_ON(wininet)) {
544 #define FE(x) { x, #x }
545 static const wininet_flag_info access_type[] = {
546 FE(INTERNET_OPEN_TYPE_PRECONFIG),
547 FE(INTERNET_OPEN_TYPE_DIRECT),
548 FE(INTERNET_OPEN_TYPE_PROXY),
549 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
553 const char *access_type_str = "Unknown";
555 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
556 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
557 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
558 if (access_type[i].val == dwAccessType) {
559 access_type_str = access_type[i].name;
563 TRACE(" access type : %s\n", access_type_str);
565 dump_INTERNET_FLAGS(dwFlags);
568 /* Clear any error information */
569 INTERNET_SetLastError(0);
571 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
574 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
578 lpwai->hdr.htype = WH_HINIT;
579 lpwai->hdr.vtbl = &APPINFOVtbl;
580 lpwai->hdr.dwFlags = dwFlags;
582 lpwai->dwAccessType = dwAccessType;
583 lpwai->lpszProxyUsername = NULL;
584 lpwai->lpszProxyPassword = NULL;
586 handle = WININET_AllocHandle( &lpwai->hdr );
589 HeapFree( GetProcessHeap(), 0, lpwai );
590 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
594 if (NULL != lpszAgent)
596 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
597 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
598 if (lpwai->lpszAgent)
599 lstrcpyW( lpwai->lpszAgent, lpszAgent );
601 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
602 INTERNET_ConfigureProxy( lpwai );
603 else if (NULL != lpszProxy)
605 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
606 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
607 if (lpwai->lpszProxy)
608 lstrcpyW( lpwai->lpszProxy, lpszProxy );
611 if (NULL != lpszProxyBypass)
613 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
614 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
615 if (lpwai->lpszProxyBypass)
616 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
621 WININET_Release( &lpwai->hdr );
623 TRACE("returning %p\n", lpwai);
629 /***********************************************************************
630 * InternetOpenA (WININET.@)
632 * Per-application initialization of wininet
635 * HINTERNET on success
639 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
640 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
644 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
646 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
647 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
651 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
652 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
653 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
658 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
659 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
660 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
663 if( lpszProxyBypass )
665 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
666 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
667 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
670 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
672 HeapFree(GetProcessHeap(), 0, szAgent);
673 HeapFree(GetProcessHeap(), 0, szProxy);
674 HeapFree(GetProcessHeap(), 0, szBypass);
679 /***********************************************************************
680 * InternetGetLastResponseInfoA (WININET.@)
682 * Return last wininet error description on the calling thread
685 * TRUE on success of writing to buffer
689 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
690 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
692 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
698 *lpdwError = lpwite->dwError;
701 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
702 *lpdwBufferLength = strlen(lpszBuffer);
705 *lpdwBufferLength = 0;
710 *lpdwBufferLength = 0;
716 /***********************************************************************
717 * InternetGetLastResponseInfoW (WININET.@)
719 * Return last wininet error description on the calling thread
722 * TRUE on success of writing to buffer
726 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
727 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
729 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
735 *lpdwError = lpwite->dwError;
738 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
739 *lpdwBufferLength = lstrlenW(lpszBuffer);
742 *lpdwBufferLength = 0;
747 *lpdwBufferLength = 0;
753 /***********************************************************************
754 * InternetGetConnectedState (WININET.@)
756 * Return connected state
760 * if lpdwStatus is not null, return the status (off line,
761 * modem, lan...) in it.
762 * FALSE if not connected
764 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
766 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
769 FIXME("always returning LAN connection.\n");
770 *lpdwStatus = INTERNET_CONNECTION_LAN;
776 /***********************************************************************
777 * InternetGetConnectedStateExW (WININET.@)
779 * Return connected state
783 * lpdwStatus [O] Flags specifying the status of the internet connection.
784 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
785 * dwNameLen [I] Size of the buffer, in characters.
786 * dwReserved [I] Reserved. Must be set to 0.
790 * if lpdwStatus is not null, return the status (off line,
791 * modem, lan...) in it.
792 * FALSE if not connected
795 * If the system has no available network connections, an empty string is
796 * stored in lpszConnectionName. If there is a LAN connection, a localized
797 * "LAN Connection" string is stored. Presumably, if only a dial-up
798 * connection is available then the name of the dial-up connection is
799 * returned. Why any application, other than the "Internet Settings" CPL,
800 * would want to use this function instead of the simpler InternetGetConnectedStateW
801 * function is beyond me.
803 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
804 DWORD dwNameLen, DWORD dwReserved)
806 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
813 FIXME("always returning LAN connection.\n");
814 *lpdwStatus = INTERNET_CONNECTION_LAN;
816 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
820 /***********************************************************************
821 * InternetGetConnectedStateExA (WININET.@)
823 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
824 DWORD dwNameLen, DWORD dwReserved)
826 LPWSTR lpwszConnectionName = NULL;
829 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
831 if (lpszConnectionName && dwNameLen > 0)
832 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
834 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
836 if (rc && lpwszConnectionName)
838 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
839 dwNameLen, NULL, NULL);
841 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
848 /***********************************************************************
849 * InternetConnectW (WININET.@)
851 * Open a ftp, gopher or http session
854 * HINTERNET a session handle on success
858 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
859 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
860 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
861 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
863 LPWININETAPPINFOW hIC;
866 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
867 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
868 dwService, dwFlags, dwContext);
872 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
876 /* Clear any error information */
877 INTERNET_SetLastError(0);
878 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
879 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
881 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
887 case INTERNET_SERVICE_FTP:
888 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
889 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
892 case INTERNET_SERVICE_HTTP:
893 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
894 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
897 case INTERNET_SERVICE_GOPHER:
903 WININET_Release( &hIC->hdr );
905 TRACE("returning %p\n", rc);
910 /***********************************************************************
911 * InternetConnectA (WININET.@)
913 * Open a ftp, gopher or http session
916 * HINTERNET a session handle on success
920 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
921 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
922 LPCSTR lpszUserName, LPCSTR lpszPassword,
923 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
927 LPWSTR szServerName = NULL;
928 LPWSTR szUserName = NULL;
929 LPWSTR szPassword = NULL;
933 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
934 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
935 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
939 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
940 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
941 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
945 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
946 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
947 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
951 rc = InternetConnectW(hInternet, szServerName, nServerPort,
952 szUserName, szPassword, dwService, dwFlags, dwContext);
954 HeapFree(GetProcessHeap(), 0, szServerName);
955 HeapFree(GetProcessHeap(), 0, szUserName);
956 HeapFree(GetProcessHeap(), 0, szPassword);
961 /***********************************************************************
962 * InternetFindNextFileA (WININET.@)
964 * Continues a file search from a previous call to FindFirstFile
971 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
976 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
978 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
982 /***********************************************************************
983 * InternetFindNextFileW (WININET.@)
985 * Continues a file search from a previous call to FindFirstFile
992 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
994 WININETHANDLEHEADER *hdr;
999 hdr = WININET_GetObject(hFind);
1001 WARN("Invalid handle\n");
1002 SetLastError(ERROR_INVALID_HANDLE);
1006 if(hdr->vtbl->FindNextFileW) {
1007 res = hdr->vtbl->FindNextFileW(hdr, lpvFindData);
1009 WARN("Handle doesn't support NextFile\n");
1010 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1013 WININET_Release(hdr);
1015 if(res != ERROR_SUCCESS)
1017 return res == ERROR_SUCCESS;
1020 /***********************************************************************
1021 * InternetCloseHandle (WININET.@)
1023 * Generic close handle function
1030 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1032 LPWININETHANDLEHEADER lpwh;
1034 TRACE("%p\n",hInternet);
1036 lpwh = WININET_GetObject( hInternet );
1039 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1043 WININET_Release( lpwh );
1044 WININET_FreeHandle( hInternet );
1050 /***********************************************************************
1051 * ConvertUrlComponentValue (Internal)
1053 * Helper function for InternetCrackUrlW
1056 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1057 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1058 LPCSTR lpszStart, LPCWSTR lpwszStart)
1060 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1061 if (*dwComponentLen != 0)
1063 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1064 if (*lppszComponent == NULL)
1066 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1068 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1070 *lppszComponent = NULL;
1071 *dwComponentLen = nASCIILength;
1075 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1076 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1077 (*lppszComponent)[ncpylen]=0;
1078 *dwComponentLen = ncpylen;
1084 /***********************************************************************
1085 * InternetCrackUrlA (WININET.@)
1087 * See InternetCrackUrlW.
1089 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1090 LPURL_COMPONENTSA lpUrlComponents)
1093 URL_COMPONENTSW UCW;
1096 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1098 if (!lpszUrl || !*lpszUrl || !lpUrlComponents ||
1099 lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSA))
1101 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1107 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1109 /* if dwUrlLength=-1 then nLength includes null but length to
1110 InternetCrackUrlW should not include it */
1111 if (dwUrlLength == -1) nLength--;
1113 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1114 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1116 memset(&UCW,0,sizeof(UCW));
1117 UCW.dwStructSize = sizeof(URL_COMPONENTSW);
1118 if(lpUrlComponents->dwHostNameLength!=0)
1119 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1120 if(lpUrlComponents->dwUserNameLength!=0)
1121 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1122 if(lpUrlComponents->dwPasswordLength!=0)
1123 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1124 if(lpUrlComponents->dwUrlPathLength!=0)
1125 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1126 if(lpUrlComponents->dwSchemeLength!=0)
1127 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1128 if(lpUrlComponents->dwExtraInfoLength!=0)
1129 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1130 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1132 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1136 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1137 UCW.lpszHostName, UCW.dwHostNameLength,
1139 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1140 UCW.lpszUserName, UCW.dwUserNameLength,
1142 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1143 UCW.lpszPassword, UCW.dwPasswordLength,
1145 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1146 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1148 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1149 UCW.lpszScheme, UCW.dwSchemeLength,
1151 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1152 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1154 lpUrlComponents->nScheme=UCW.nScheme;
1155 lpUrlComponents->nPort=UCW.nPort;
1156 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1158 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1159 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1160 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1161 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1162 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1167 static const WCHAR url_schemes[][7] =
1170 {'g','o','p','h','e','r',0},
1171 {'h','t','t','p',0},
1172 {'h','t','t','p','s',0},
1173 {'f','i','l','e',0},
1174 {'n','e','w','s',0},
1175 {'m','a','i','l','t','o',0},
1179 /***********************************************************************
1180 * GetInternetSchemeW (internal)
1186 * INTERNET_SCHEME_UNKNOWN on failure
1189 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1193 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1195 if(lpszScheme==NULL)
1196 return INTERNET_SCHEME_UNKNOWN;
1198 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1199 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1200 return INTERNET_SCHEME_FIRST + i;
1202 return INTERNET_SCHEME_UNKNOWN;
1205 /***********************************************************************
1206 * SetUrlComponentValueW (Internal)
1208 * Helper function for InternetCrackUrlW
1211 * lppszComponent [O] Holds the returned string
1212 * dwComponentLen [I] Holds the size of lppszComponent
1213 * [O] Holds the length of the string in lppszComponent without '\0'
1214 * lpszStart [I] Holds the string to copy from
1215 * len [I] Holds the length of lpszStart without '\0'
1222 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1224 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1226 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1229 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1231 if (*lppszComponent == NULL)
1233 *lppszComponent = (LPWSTR)lpszStart;
1234 *dwComponentLen = len;
1238 DWORD ncpylen = min((*dwComponentLen)-1, len);
1239 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1240 (*lppszComponent)[ncpylen] = '\0';
1241 *dwComponentLen = ncpylen;
1248 /***********************************************************************
1249 * InternetCrackUrlW (WININET.@)
1251 * Break up URL into its components
1257 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1258 LPURL_COMPONENTSW lpUC)
1262 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1265 LPCWSTR lpszParam = NULL;
1266 BOOL bIsAbsolute = FALSE;
1267 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1268 LPCWSTR lpszcp = NULL;
1269 LPWSTR lpszUrl_decode = NULL;
1270 DWORD dwUrlLength = dwUrlLength_orig;
1272 TRACE("(%s %u %x %p)\n",
1273 lpszUrl ? debugstr_wn(lpszUrl, dwUrlLength ? dwUrlLength : strlenW(lpszUrl)) : "(null)",
1274 dwUrlLength, dwFlags, lpUC);
1276 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1278 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1281 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1283 if (dwFlags & ICU_DECODE)
1286 DWORD len = dwUrlLength + 1;
1288 if (!(url_tmp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1290 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1293 memcpy(url_tmp, lpszUrl_orig, dwUrlLength * sizeof(WCHAR));
1294 url_tmp[dwUrlLength] = 0;
1295 if (!(lpszUrl_decode = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
1297 HeapFree(GetProcessHeap(), 0, url_tmp);
1298 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
1301 if (InternetCanonicalizeUrlW(url_tmp, lpszUrl_decode, &len, ICU_DECODE | ICU_NO_ENCODE))
1304 lpszUrl = lpszUrl_decode;
1306 HeapFree(GetProcessHeap(), 0, url_tmp);
1310 /* Determine if the URI is absolute. */
1311 while (lpszap - lpszUrl < dwUrlLength)
1313 if (isalnumW(*lpszap))
1318 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1325 lpszcp = lpszUrl; /* Relative url */
1331 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1332 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1334 /* Parse <params> */
1335 if (!(lpszParam = memchrW(lpszap, ';', dwUrlLength - (lpszap - lpszUrl))))
1336 lpszParam = memchrW(lpszap, '?', dwUrlLength - (lpszap - lpszUrl));
1338 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1339 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1341 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1345 /* Get scheme first. */
1346 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1347 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1348 lpszUrl, lpszcp - lpszUrl);
1350 /* Eat ':' in protocol. */
1353 /* double slash indicates the net_loc portion is present */
1354 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1358 lpszNetLoc = memchrW(lpszcp, '/', dwUrlLength - (lpszcp - lpszUrl));
1362 lpszNetLoc = min(lpszNetLoc, lpszParam);
1364 lpszNetLoc = lpszParam;
1366 else if (!lpszNetLoc)
1367 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1375 /* [<user>[<:password>]@]<host>[:<port>] */
1376 /* First find the user and password if they exist */
1378 lpszHost = memchrW(lpszcp, '@', dwUrlLength - (lpszcp - lpszUrl));
1379 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1381 /* username and password not specified. */
1382 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1383 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1385 else /* Parse out username and password */
1387 LPCWSTR lpszUser = lpszcp;
1388 LPCWSTR lpszPasswd = lpszHost;
1390 while (lpszcp < lpszHost)
1393 lpszPasswd = lpszcp;
1398 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1399 lpszUser, lpszPasswd - lpszUser);
1401 if (lpszPasswd != lpszHost)
1403 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1404 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1405 lpszHost - lpszPasswd);
1407 lpszcp++; /* Advance to beginning of host */
1410 /* Parse <host><:port> */
1413 lpszPort = lpszNetLoc;
1415 /* special case for res:// URLs: there is no port here, so the host is the
1416 entire string up to the first '/' */
1417 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1419 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1420 lpszHost, lpszPort - lpszHost);
1425 while (lpszcp < lpszNetLoc)
1433 /* If the scheme is "file" and the host is just one letter, it's not a host */
1434 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1437 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1442 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1443 lpszHost, lpszPort - lpszHost);
1444 if (lpszPort != lpszNetLoc)
1445 lpUC->nPort = atoiW(++lpszPort);
1446 else switch (lpUC->nScheme)
1448 case INTERNET_SCHEME_HTTP:
1449 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1451 case INTERNET_SCHEME_HTTPS:
1452 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1454 case INTERNET_SCHEME_FTP:
1455 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1457 case INTERNET_SCHEME_GOPHER:
1458 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1469 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1470 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1471 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1476 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1477 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1478 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1479 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1482 /* Here lpszcp points to:
1484 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1485 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1487 if (lpszcp != 0 && lpszcp - lpszUrl < dwUrlLength && (!lpszParam || lpszcp < lpszParam))
1491 /* Only truncate the parameter list if it's already been saved
1492 * in lpUC->lpszExtraInfo.
1494 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1495 len = lpszParam - lpszcp;
1498 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1499 * newlines if necessary.
1501 LPWSTR lpsznewline = memchrW(lpszcp, '\n', dwUrlLength - (lpszcp - lpszUrl));
1502 if (lpsznewline != NULL)
1503 len = lpsznewline - lpszcp;
1505 len = dwUrlLength-(lpszcp-lpszUrl);
1507 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1512 if (lpUC->lpszUrlPath && (lpUC->dwUrlPathLength > 0))
1513 lpUC->lpszUrlPath[0] = 0;
1514 lpUC->dwUrlPathLength = 0;
1517 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1518 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1519 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1520 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1521 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1523 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1527 /***********************************************************************
1528 * InternetAttemptConnect (WININET.@)
1530 * Attempt to make a connection to the internet
1533 * ERROR_SUCCESS on success
1534 * Error value on failure
1537 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1540 return ERROR_SUCCESS;
1544 /***********************************************************************
1545 * InternetCanonicalizeUrlA (WININET.@)
1547 * Escape unsafe characters and spaces
1554 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1555 LPDWORD lpdwBufferLength, DWORD dwFlags)
1558 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1560 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1561 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1563 if(dwFlags & ICU_DECODE)
1565 dwURLFlags |= URL_UNESCAPE;
1566 dwFlags &= ~ICU_DECODE;
1569 if(dwFlags & ICU_ESCAPE)
1571 dwURLFlags |= URL_UNESCAPE;
1572 dwFlags &= ~ICU_ESCAPE;
1575 if(dwFlags & ICU_BROWSER_MODE)
1577 dwURLFlags |= URL_BROWSER_MODE;
1578 dwFlags &= ~ICU_BROWSER_MODE;
1581 if(dwFlags & ICU_NO_ENCODE)
1583 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1584 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1585 dwFlags &= ~ICU_NO_ENCODE;
1588 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1590 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1591 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1592 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1594 return (hr == S_OK) ? TRUE : FALSE;
1597 /***********************************************************************
1598 * InternetCanonicalizeUrlW (WININET.@)
1600 * Escape unsafe characters and spaces
1607 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1608 LPDWORD lpdwBufferLength, DWORD dwFlags)
1611 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1613 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1614 lpdwBufferLength, dwFlags, lpdwBufferLength ? *lpdwBufferLength : -1);
1616 if(dwFlags & ICU_DECODE)
1618 dwURLFlags |= URL_UNESCAPE;
1619 dwFlags &= ~ICU_DECODE;
1622 if(dwFlags & ICU_ESCAPE)
1624 dwURLFlags |= URL_UNESCAPE;
1625 dwFlags &= ~ICU_ESCAPE;
1628 if(dwFlags & ICU_BROWSER_MODE)
1630 dwURLFlags |= URL_BROWSER_MODE;
1631 dwFlags &= ~ICU_BROWSER_MODE;
1634 if(dwFlags & ICU_NO_ENCODE)
1636 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1637 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1638 dwFlags &= ~ICU_NO_ENCODE;
1641 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1643 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1644 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1645 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1647 return (hr == S_OK) ? TRUE : FALSE;
1650 /* #################################################### */
1652 static INTERNET_STATUS_CALLBACK set_status_callback(
1653 LPWININETHANDLEHEADER lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1655 INTERNET_STATUS_CALLBACK ret;
1657 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1658 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1660 ret = lpwh->lpfnStatusCB;
1661 lpwh->lpfnStatusCB = callback;
1666 /***********************************************************************
1667 * InternetSetStatusCallbackA (WININET.@)
1669 * Sets up a callback function which is called as progress is made
1670 * during an operation.
1673 * Previous callback or NULL on success
1674 * INTERNET_INVALID_STATUS_CALLBACK on failure
1677 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1678 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1680 INTERNET_STATUS_CALLBACK retVal;
1681 LPWININETHANDLEHEADER lpwh;
1683 TRACE("0x%08x\n", (ULONG)hInternet);
1685 if (!(lpwh = WININET_GetObject(hInternet)))
1686 return INTERNET_INVALID_STATUS_CALLBACK;
1688 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1690 WININET_Release( lpwh );
1694 /***********************************************************************
1695 * InternetSetStatusCallbackW (WININET.@)
1697 * Sets up a callback function which is called as progress is made
1698 * during an operation.
1701 * Previous callback or NULL on success
1702 * INTERNET_INVALID_STATUS_CALLBACK on failure
1705 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1706 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1708 INTERNET_STATUS_CALLBACK retVal;
1709 LPWININETHANDLEHEADER lpwh;
1711 TRACE("0x%08x\n", (ULONG)hInternet);
1713 if (!(lpwh = WININET_GetObject(hInternet)))
1714 return INTERNET_INVALID_STATUS_CALLBACK;
1716 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1718 WININET_Release( lpwh );
1722 /***********************************************************************
1723 * InternetSetFilePointer (WININET.@)
1725 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1726 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1732 /***********************************************************************
1733 * InternetWriteFile (WININET.@)
1735 * Write data to an open internet file
1742 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer,
1743 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1745 LPWININETHANDLEHEADER lpwh;
1746 BOOL retval = FALSE;
1748 TRACE("(%p %p %d %p)\n", hFile, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1750 lpwh = WININET_GetObject( hFile );
1752 WARN("Invalid handle\n");
1753 SetLastError(ERROR_INVALID_HANDLE);
1757 if(lpwh->vtbl->WriteFile) {
1758 retval = lpwh->vtbl->WriteFile(lpwh, lpBuffer, dwNumOfBytesToWrite, lpdwNumOfBytesWritten);
1760 WARN("No Writefile method.\n");
1761 SetLastError(ERROR_INVALID_HANDLE);
1765 WININET_Release( lpwh );
1771 /***********************************************************************
1772 * InternetReadFile (WININET.@)
1774 * Read data from an open internet file
1781 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1782 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1784 LPWININETHANDLEHEADER hdr;
1785 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1787 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1789 hdr = WININET_GetObject(hFile);
1791 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1795 if(hdr->vtbl->ReadFile)
1796 res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1798 WININET_Release(hdr);
1800 TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
1801 pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1803 if(res != ERROR_SUCCESS)
1805 return res == ERROR_SUCCESS;
1808 /***********************************************************************
1809 * InternetReadFileExA (WININET.@)
1811 * Read data from an open internet file
1814 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1815 * lpBuffersOut [I/O] Buffer.
1816 * dwFlags [I] Flags. See notes.
1817 * dwContext [I] Context for callbacks.
1824 * The parameter dwFlags include zero or more of the following flags:
1825 *|IRF_ASYNC - Makes the call asynchronous.
1826 *|IRF_SYNC - Makes the call synchronous.
1827 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1828 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1830 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1833 * InternetOpenUrlA(), HttpOpenRequestA()
1835 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1836 DWORD dwFlags, DWORD_PTR dwContext)
1838 LPWININETHANDLEHEADER hdr;
1839 DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
1841 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1843 hdr = WININET_GetObject(hFile);
1845 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1849 if(hdr->vtbl->ReadFileExA)
1850 res = hdr->vtbl->ReadFileExA(hdr, lpBuffersOut, dwFlags, dwContext);
1852 WININET_Release(hdr);
1854 TRACE("-- %s (%u, bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE",
1855 res, lpBuffersOut->dwBufferLength);
1857 if(res != ERROR_SUCCESS)
1859 return res == ERROR_SUCCESS;
1862 /***********************************************************************
1863 * InternetReadFileExW (WININET.@)
1865 * Read data from an open internet file.
1868 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1869 * lpBuffersOut [I/O] Buffer.
1870 * dwFlags [I] Flags.
1871 * dwContext [I] Context for callbacks.
1874 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1877 * Not implemented in Wine or native either (as of IE6 SP2).
1880 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1881 DWORD dwFlags, DWORD_PTR dwContext)
1883 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1885 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1889 /***********************************************************************
1890 * INET_QueryOptionHelper (internal)
1892 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1893 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1895 LPWININETHANDLEHEADER lpwhh;
1896 BOOL bSuccess = FALSE;
1898 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1900 lpwhh = WININET_GetObject( hInternet );
1904 case INTERNET_OPTION_REQUEST_FLAGS:
1907 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1908 if (*lpdwBufferLength < sizeof(ULONG))
1909 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1912 memcpy(lpBuffer, &flags, sizeof(ULONG));
1915 *lpdwBufferLength = sizeof(ULONG);
1919 case INTERNET_OPTION_USER_AGENT:
1922 LPWININETAPPINFOW ai = (LPWININETAPPINFOW)lpwhh;
1924 TRACE("INTERNET_OPTION_USER_AGENT\n");
1926 if (!lpwhh || lpwhh->htype != INTERNET_HANDLE_TYPE_INTERNET)
1928 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1933 required = (strlenW(ai->lpszAgent) + 1) * sizeof(WCHAR);
1934 if (*lpdwBufferLength < required)
1935 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1938 strcpyW(lpBuffer, ai->lpszAgent);
1944 required = WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, NULL, 0, NULL, NULL);
1945 if (*lpdwBufferLength < required)
1946 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1949 WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, lpBuffer, required, NULL, NULL);
1953 *lpdwBufferLength = required;
1956 case INTERNET_OPTION_HTTP_VERSION:
1958 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
1959 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1963 * Presently hardcoded to 1.1
1965 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
1966 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
1969 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
1972 case INTERNET_OPTION_CONNECTED_STATE:
1974 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
1975 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
1977 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
1978 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1981 *pdwConnectedState = INTERNET_STATE_CONNECTED;
1984 *lpdwBufferLength = sizeof(*pdwConnectedState);
1987 case INTERNET_OPTION_PROXY:
1989 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
1990 WININETAPPINFOW wai;
1994 TRACE("Getting global proxy info\n");
1995 memset(&wai, 0, sizeof(WININETAPPINFOW));
1996 INTERNET_ConfigureProxy( &wai );
2002 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2003 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2005 if (lpwai->lpszProxy)
2006 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2008 if (lpwai->lpszProxyBypass)
2009 proxyBypassBytesRequired =
2010 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2011 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2012 proxyBytesRequired + proxyBypassBytesRequired)
2013 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2016 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2017 sizeof(INTERNET_PROXY_INFOW));
2018 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2019 sizeof(INTERNET_PROXY_INFOW) +
2020 proxyBytesRequired);
2022 pPI->dwAccessType = lpwai->dwAccessType;
2023 pPI->lpszProxy = NULL;
2024 pPI->lpszProxyBypass = NULL;
2025 if (lpwai->lpszProxy)
2027 lstrcpyW(proxy, lpwai->lpszProxy);
2028 pPI->lpszProxy = proxy;
2031 if (lpwai->lpszProxyBypass)
2033 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2034 pPI->lpszProxyBypass = proxy_bypass;
2038 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2039 proxyBytesRequired + proxyBypassBytesRequired;
2043 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2044 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2046 if (lpwai->lpszProxy)
2047 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2048 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2049 if (lpwai->lpszProxyBypass)
2050 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2051 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2052 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2053 proxyBytesRequired + proxyBypassBytesRequired)
2054 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2057 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2058 sizeof(INTERNET_PROXY_INFOA));
2059 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2060 sizeof(INTERNET_PROXY_INFOA) +
2061 proxyBytesRequired);
2063 pPI->dwAccessType = lpwai->dwAccessType;
2064 pPI->lpszProxy = NULL;
2065 pPI->lpszProxyBypass = NULL;
2066 if (lpwai->lpszProxy)
2068 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2069 proxy, proxyBytesRequired, NULL, NULL);
2070 pPI->lpszProxy = proxy;
2073 if (lpwai->lpszProxyBypass)
2075 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2076 -1, proxy_bypass, proxyBypassBytesRequired,
2078 pPI->lpszProxyBypass = proxy_bypass;
2082 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2083 proxyBytesRequired + proxyBypassBytesRequired;
2087 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2090 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2091 if (*lpdwBufferLength < sizeof(ULONG))
2092 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2095 memcpy(lpBuffer, &conn, sizeof(ULONG));
2098 *lpdwBufferLength = sizeof(ULONG);
2101 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2104 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2105 if (*lpdwBufferLength < sizeof(ULONG))
2106 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2109 memcpy(lpBuffer, &conn, sizeof(ULONG));
2112 *lpdwBufferLength = sizeof(ULONG);
2115 case INTERNET_OPTION_SECURITY_FLAGS:
2116 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2120 case INTERNET_OPTION_VERSION:
2122 TRACE("INTERNET_OPTION_VERSION\n");
2123 if (*lpdwBufferLength < sizeof(INTERNET_VERSION_INFO))
2124 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2127 static const INTERNET_VERSION_INFO info = { 1, 2 };
2128 memcpy(lpBuffer, &info, sizeof(info));
2129 *lpdwBufferLength = sizeof(info);
2134 case INTERNET_OPTION_PER_CONNECTION_OPTION:
2135 FIXME("INTERNET_OPTION_PER_CONNECTION_OPTION stub\n");
2136 if (*lpdwBufferLength < sizeof(INTERNET_PER_CONN_OPTION_LISTW))
2137 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2140 INTERNET_PER_CONN_OPTION_LISTW *con = lpBuffer;
2143 for (x = 0; x < con->dwOptionCount; ++x)
2145 INTERNET_PER_CONN_OPTIONW *option = con->pOptions + x;
2146 switch (option->dwOption)
2148 case INTERNET_PER_CONN_FLAGS:
2149 option->Value.dwValue = PROXY_TYPE_DIRECT;
2152 case INTERNET_PER_CONN_PROXY_SERVER:
2153 case INTERNET_PER_CONN_PROXY_BYPASS:
2154 case INTERNET_PER_CONN_AUTOCONFIG_URL:
2155 case INTERNET_PER_CONN_AUTODISCOVERY_FLAGS:
2156 case INTERNET_PER_CONN_AUTOCONFIG_SECONDARY_URL:
2157 case INTERNET_PER_CONN_AUTOCONFIG_RELOAD_DELAY_MINS:
2158 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_TIME:
2159 case INTERNET_PER_CONN_AUTOCONFIG_LAST_DETECT_URL:
2160 FIXME("Unhandled dwOption %d\n", option->dwOption);
2161 option->Value.dwValue = 0;
2166 FIXME("Unknown dwOption %d\n", option->dwOption);
2172 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2183 res = lpwhh->vtbl->QueryOption(lpwhh, dwOption, lpBuffer, lpdwBufferLength, bIsUnicode);
2184 if(res == ERROR_SUCCESS)
2189 FIXME("Stub! %d\n", dwOption);
2195 WININET_Release( lpwhh );
2200 /***********************************************************************
2201 * InternetQueryOptionW (WININET.@)
2203 * Queries an options on the specified handle
2210 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2211 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2213 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2216 /***********************************************************************
2217 * InternetQueryOptionA (WININET.@)
2219 * Queries an options on the specified handle
2226 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2227 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2229 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2233 /***********************************************************************
2234 * InternetSetOptionW (WININET.@)
2236 * Sets an options on the specified handle
2243 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2244 LPVOID lpBuffer, DWORD dwBufferLength)
2246 LPWININETHANDLEHEADER lpwhh;
2249 TRACE("(%p %d %p %d)\n", hInternet, dwOption, lpBuffer, dwBufferLength);
2251 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2252 if(lpwhh && lpwhh->vtbl->SetOption) {
2255 res = lpwhh->vtbl->SetOption(lpwhh, dwOption, lpBuffer, dwBufferLength);
2256 if(res != ERROR_INTERNET_INVALID_OPTION) {
2257 WININET_Release( lpwhh );
2259 if(res != ERROR_SUCCESS)
2262 return res == ERROR_SUCCESS;
2268 case INTERNET_OPTION_CALLBACK:
2270 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2271 ret = (set_status_callback(lpwhh, callback, TRUE) != INTERNET_INVALID_STATUS_CALLBACK);
2274 case INTERNET_OPTION_HTTP_VERSION:
2276 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2277 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2280 case INTERNET_OPTION_ERROR_MASK:
2282 ULONG flags = *(ULONG *)lpBuffer;
2283 FIXME("Option INTERNET_OPTION_ERROR_MASK(%d): STUB\n", flags);
2286 case INTERNET_OPTION_CODEPAGE:
2288 ULONG codepage = *(ULONG *)lpBuffer;
2289 FIXME("Option INTERNET_OPTION_CODEPAGE (%d): STUB\n", codepage);
2292 case INTERNET_OPTION_REQUEST_PRIORITY:
2294 ULONG priority = *(ULONG *)lpBuffer;
2295 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%d): STUB\n", priority);
2298 case INTERNET_OPTION_CONNECT_TIMEOUT:
2300 ULONG connecttimeout = *(ULONG *)lpBuffer;
2301 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%d): STUB\n", connecttimeout);
2304 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2306 ULONG receivetimeout = *(ULONG *)lpBuffer;
2307 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%d): STUB\n", receivetimeout);
2310 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2312 ULONG conns = *(ULONG *)lpBuffer;
2313 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%d): STUB\n", conns);
2316 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2318 ULONG conns = *(ULONG *)lpBuffer;
2319 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%d): STUB\n", conns);
2322 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2323 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2325 case INTERNET_OPTION_END_BROWSER_SESSION:
2326 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2328 case INTERNET_OPTION_CONNECTED_STATE:
2329 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2331 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2332 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2334 case INTERNET_OPTION_SEND_TIMEOUT:
2335 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2337 ULONG timeout = *(ULONG *)lpBuffer;
2338 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT %d\n", timeout);
2341 case INTERNET_OPTION_CONNECT_RETRIES:
2343 ULONG retries = *(ULONG *)lpBuffer;
2344 FIXME("INTERNET_OPTION_CONNECT_RETRIES %d\n", retries);
2347 case INTERNET_OPTION_CONTEXT_VALUE:
2348 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2350 case INTERNET_OPTION_SECURITY_FLAGS:
2351 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2353 case INTERNET_OPTION_DISABLE_AUTODIAL:
2354 FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n");
2360 FIXME("Option %d STUB\n",dwOption);
2361 INTERNET_SetLastError(ERROR_INTERNET_INVALID_OPTION);
2367 WININET_Release( lpwhh );
2373 /***********************************************************************
2374 * InternetSetOptionA (WININET.@)
2376 * Sets an options on the specified handle.
2383 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2384 LPVOID lpBuffer, DWORD dwBufferLength)
2392 case INTERNET_OPTION_CALLBACK:
2394 LPWININETHANDLEHEADER lpwh;
2395 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2397 if (!(lpwh = WININET_GetObject(hInternet))) return FALSE;
2398 r = (set_status_callback(lpwh, callback, FALSE) != INTERNET_INVALID_STATUS_CALLBACK);
2399 WININET_Release(lpwh);
2402 case INTERNET_OPTION_PROXY:
2404 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2405 LPINTERNET_PROXY_INFOW piw;
2406 DWORD proxlen, prbylen;
2409 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2410 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2411 wlen = sizeof(*piw) + proxlen + prbylen;
2412 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2413 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2414 piw->dwAccessType = pi->dwAccessType;
2415 prox = (LPWSTR) &piw[1];
2416 prby = &prox[proxlen+1];
2417 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2418 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2419 piw->lpszProxy = prox;
2420 piw->lpszProxyBypass = prby;
2423 case INTERNET_OPTION_USER_AGENT:
2424 case INTERNET_OPTION_USERNAME:
2425 case INTERNET_OPTION_PASSWORD:
2426 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2428 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2429 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2434 wlen = dwBufferLength;
2437 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2439 if( lpBuffer != wbuffer )
2440 HeapFree( GetProcessHeap(), 0, wbuffer );
2446 /***********************************************************************
2447 * InternetSetOptionExA (WININET.@)
2449 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2450 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2452 FIXME("Flags %08x ignored\n", dwFlags);
2453 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2456 /***********************************************************************
2457 * InternetSetOptionExW (WININET.@)
2459 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2460 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2462 FIXME("Flags %08x ignored\n", dwFlags);
2463 if( dwFlags & ~ISO_VALID_FLAGS )
2465 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2468 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2471 static const WCHAR WININET_wkday[7][4] =
2472 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2473 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2474 static const WCHAR WININET_month[12][4] =
2475 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2476 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2477 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2479 /***********************************************************************
2480 * InternetTimeFromSystemTimeA (WININET.@)
2482 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2485 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2487 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2489 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2490 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2495 /***********************************************************************
2496 * InternetTimeFromSystemTimeW (WININET.@)
2498 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2500 static const WCHAR date[] =
2501 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2502 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2504 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2506 if (!time || !string) return FALSE;
2508 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2511 sprintfW( string, date,
2512 WININET_wkday[time->wDayOfWeek],
2514 WININET_month[time->wMonth - 1],
2523 /***********************************************************************
2524 * InternetTimeToSystemTimeA (WININET.@)
2526 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2532 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2534 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2535 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2539 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2540 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2541 HeapFree( GetProcessHeap(), 0, stringW );
2546 /***********************************************************************
2547 * InternetTimeToSystemTimeW (WININET.@)
2549 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2552 const WCHAR *s = string;
2555 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2557 if (!string || !time) return FALSE;
2559 /* Windows does this too */
2560 GetSystemTime( time );
2562 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2563 * a SYSTEMTIME structure.
2566 while (*s && !isalphaW( *s )) s++;
2567 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2568 time->wDayOfWeek = 7;
2570 for (i = 0; i < 7; i++)
2572 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2573 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2574 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2576 time->wDayOfWeek = i;
2581 if (time->wDayOfWeek > 6) return TRUE;
2582 while (*s && !isdigitW( *s )) s++;
2583 time->wDay = strtolW( s, &end, 10 );
2586 while (*s && !isalphaW( *s )) s++;
2587 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2590 for (i = 0; i < 12; i++)
2592 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2593 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2594 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2596 time->wMonth = i + 1;
2600 if (time->wMonth == 0) return TRUE;
2602 while (*s && !isdigitW( *s )) s++;
2603 if (*s == '\0') return TRUE;
2604 time->wYear = strtolW( s, &end, 10 );
2607 while (*s && !isdigitW( *s )) s++;
2608 if (*s == '\0') return TRUE;
2609 time->wHour = strtolW( s, &end, 10 );
2612 while (*s && !isdigitW( *s )) s++;
2613 if (*s == '\0') return TRUE;
2614 time->wMinute = strtolW( s, &end, 10 );
2617 while (*s && !isdigitW( *s )) s++;
2618 if (*s == '\0') return TRUE;
2619 time->wSecond = strtolW( s, &end, 10 );
2622 time->wMilliseconds = 0;
2626 /***********************************************************************
2627 * InternetCheckConnectionW (WININET.@)
2629 * Pings a requested host to check internet connection
2632 * TRUE on success and FALSE on failure. If a failure then
2633 * ERROR_NOT_CONNECTED is placed into GetLastError
2636 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2639 * this is a kludge which runs the resident ping program and reads the output.
2641 * Anyone have a better idea?
2645 static const CHAR ping[] = "ping -c 1 ";
2646 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2647 CHAR *command = NULL;
2656 * Crack or set the Address
2658 if (lpszUrl == NULL)
2661 * According to the doc we are supposed to use the ip for the next
2662 * server in the WnInet internal server database. I have
2663 * no idea what that is or how to get it.
2665 * So someone needs to implement this.
2667 FIXME("Unimplemented with URL of NULL\n");
2672 URL_COMPONENTSW components;
2674 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2675 components.lpszHostName = (LPWSTR)&hostW;
2676 components.dwHostNameLength = 1024;
2678 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2681 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2682 port = components.nPort;
2683 TRACE("port: %d\n", port);
2686 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2688 struct sockaddr_in sin;
2691 if (!GetAddress(hostW, port, &sin))
2693 fd = socket(sin.sin_family, SOCK_STREAM, 0);
2696 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
2704 * Build our ping command
2706 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2707 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2708 strcpy(command,ping);
2709 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2710 strcat(command,redirect);
2712 TRACE("Ping command is : %s\n",command);
2714 status = system(command);
2716 TRACE("Ping returned a code of %i\n",status);
2718 /* Ping return code of 0 indicates success */
2725 HeapFree( GetProcessHeap(), 0, command );
2727 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2733 /***********************************************************************
2734 * InternetCheckConnectionA (WININET.@)
2736 * Pings a requested host to check internet connection
2739 * TRUE on success and FALSE on failure. If a failure then
2740 * ERROR_NOT_CONNECTED is placed into GetLastError
2743 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2749 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2750 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2752 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2753 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2754 HeapFree(GetProcessHeap(), 0, szUrl);
2760 /**********************************************************
2761 * INTERNET_InternetOpenUrlW (internal)
2766 * handle of connection or NULL on failure
2768 static HINTERNET INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2769 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2771 URL_COMPONENTSW urlComponents;
2772 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2773 WCHAR password[1024], path[2048], extra[1024];
2774 HINTERNET client = NULL, client1 = NULL;
2776 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2777 dwHeadersLength, dwFlags, dwContext);
2779 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2780 urlComponents.lpszScheme = protocol;
2781 urlComponents.dwSchemeLength = 32;
2782 urlComponents.lpszHostName = hostName;
2783 urlComponents.dwHostNameLength = MAXHOSTNAME;
2784 urlComponents.lpszUserName = userName;
2785 urlComponents.dwUserNameLength = 1024;
2786 urlComponents.lpszPassword = password;
2787 urlComponents.dwPasswordLength = 1024;
2788 urlComponents.lpszUrlPath = path;
2789 urlComponents.dwUrlPathLength = 2048;
2790 urlComponents.lpszExtraInfo = extra;
2791 urlComponents.dwExtraInfoLength = 1024;
2792 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2794 switch(urlComponents.nScheme) {
2795 case INTERNET_SCHEME_FTP:
2796 if(urlComponents.nPort == 0)
2797 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2798 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2799 userName, password, dwFlags, dwContext, INET_OPENURL);
2802 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2803 if(client1 == NULL) {
2804 InternetCloseHandle(client);
2809 case INTERNET_SCHEME_HTTP:
2810 case INTERNET_SCHEME_HTTPS: {
2811 static const WCHAR szStars[] = { '*','/','*', 0 };
2812 LPCWSTR accept[2] = { szStars, NULL };
2813 if(urlComponents.nPort == 0) {
2814 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2815 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2817 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2819 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2820 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2821 userName, password, dwFlags, dwContext, INET_OPENURL);
2825 if (urlComponents.dwExtraInfoLength) {
2827 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2829 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2831 InternetCloseHandle(client);
2834 strcpyW(path_extra, urlComponents.lpszUrlPath);
2835 strcatW(path_extra, urlComponents.lpszExtraInfo);
2836 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2837 HeapFree(GetProcessHeap(), 0, path_extra);
2840 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2842 if(client1 == NULL) {
2843 InternetCloseHandle(client);
2846 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2847 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2848 GetLastError() != ERROR_IO_PENDING) {
2849 InternetCloseHandle(client1);
2854 case INTERNET_SCHEME_GOPHER:
2855 /* gopher doesn't seem to be implemented in wine, but it's supposed
2856 * to be supported by InternetOpenUrlA. */
2858 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2862 TRACE(" %p <--\n", client1);
2867 /**********************************************************
2868 * InternetOpenUrlW (WININET.@)
2873 * handle of connection or NULL on failure
2875 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2877 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2878 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
2882 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2883 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2884 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2885 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2888 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2889 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2891 HINTERNET ret = NULL;
2892 LPWININETAPPINFOW hIC = NULL;
2894 if (TRACE_ON(wininet)) {
2895 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2896 dwHeadersLength, dwFlags, dwContext);
2898 dump_INTERNET_FLAGS(dwFlags);
2903 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2907 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2908 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2909 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2913 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2914 WORKREQUEST workRequest;
2915 struct WORKREQ_INTERNETOPENURLW *req;
2917 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2918 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2919 req = &workRequest.u.InternetOpenUrlW;
2920 req->lpszUrl = WININET_strdupW(lpszUrl);
2922 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2924 req->lpszHeaders = 0;
2925 req->dwHeadersLength = dwHeadersLength;
2926 req->dwFlags = dwFlags;
2927 req->dwContext = dwContext;
2929 INTERNET_AsyncCall(&workRequest);
2931 * This is from windows.
2933 INTERNET_SetLastError(ERROR_IO_PENDING);
2935 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2940 WININET_Release( &hIC->hdr );
2941 TRACE(" %p <--\n", ret);
2946 /**********************************************************
2947 * InternetOpenUrlA (WININET.@)
2952 * handle of connection or NULL on failure
2954 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2955 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2957 HINTERNET rc = NULL;
2961 LPWSTR szUrl = NULL;
2962 LPWSTR szHeaders = NULL;
2967 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2968 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2971 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2975 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
2976 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
2978 HeapFree(GetProcessHeap(), 0, szUrl);
2981 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
2984 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
2985 lenHeaders, dwFlags, dwContext);
2987 HeapFree(GetProcessHeap(), 0, szUrl);
2988 HeapFree(GetProcessHeap(), 0, szHeaders);
2994 static LPWITHREADERROR INTERNET_AllocThreadError(void)
2996 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3000 lpwite->dwError = 0;
3001 lpwite->response[0] = '\0';
3004 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3006 HeapFree(GetProcessHeap(), 0, lpwite);
3014 /***********************************************************************
3015 * INTERNET_SetLastError (internal)
3017 * Set last thread specific error
3022 void INTERNET_SetLastError(DWORD dwError)
3024 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3027 lpwite = INTERNET_AllocThreadError();
3029 SetLastError(dwError);
3031 lpwite->dwError = dwError;
3035 /***********************************************************************
3036 * INTERNET_GetLastError (internal)
3038 * Get last thread specific error
3043 DWORD INTERNET_GetLastError(void)
3045 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3046 if (!lpwite) return 0;
3047 /* TlsGetValue clears last error, so set it again here */
3048 SetLastError(lpwite->dwError);
3049 return lpwite->dwError;
3053 /***********************************************************************
3054 * INTERNET_WorkerThreadFunc (internal)
3056 * Worker thread execution function
3061 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3063 LPWORKREQUEST lpRequest = lpvParam;
3064 WORKREQUEST workRequest;
3068 workRequest = *lpRequest;
3069 HeapFree(GetProcessHeap(), 0, lpRequest);
3071 workRequest.asyncproc(&workRequest);
3073 WININET_Release( workRequest.hdr );
3078 /***********************************************************************
3079 * INTERNET_AsyncCall (internal)
3081 * Retrieves work request from queue
3086 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3089 LPWORKREQUEST lpNewRequest;
3093 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3097 *lpNewRequest = *lpWorkRequest;
3099 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3102 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3103 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3110 /***********************************************************************
3111 * INTERNET_GetResponseBuffer (internal)
3116 LPSTR INTERNET_GetResponseBuffer(void)
3118 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3120 lpwite = INTERNET_AllocThreadError();
3122 return lpwite->response;
3125 /***********************************************************************
3126 * INTERNET_GetNextLine (internal)
3128 * Parse next line in directory string listing
3131 * Pointer to beginning of next line
3136 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3139 BOOL bSuccess = FALSE;
3141 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3146 pfd.events = POLLIN;
3148 while (nRecv < MAX_REPLY_LEN)
3150 if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
3152 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3154 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3158 if (lpszBuffer[nRecv] == '\n')
3163 if (lpszBuffer[nRecv] != '\r')
3168 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3176 lpszBuffer[nRecv] = '\0';
3178 TRACE(":%d %s\n", nRecv, lpszBuffer);
3187 /**********************************************************
3188 * InternetQueryDataAvailable (WININET.@)
3190 * Determines how much data is available to be read.
3193 * TRUE on success, FALSE if an error occurred. If
3194 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3195 * no data is presently available, FALSE is returned with
3196 * the last error ERROR_IO_PENDING; a callback with status
3197 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3198 * data is available.
3200 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3201 LPDWORD lpdwNumberOfBytesAvailble,
3202 DWORD dwFlags, DWORD_PTR dwContext)
3204 WININETHANDLEHEADER *hdr;
3207 TRACE("(%p %p %x %lx)\n", hFile, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3209 hdr = WININET_GetObject( hFile );
3211 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
3215 if(hdr->vtbl->QueryDataAvailable) {
3216 res = hdr->vtbl->QueryDataAvailable(hdr, lpdwNumberOfBytesAvailble, dwFlags, dwContext);
3218 WARN("wrong handle\n");
3219 res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
3222 WININET_Release(hdr);
3224 if(res != ERROR_SUCCESS)
3226 return res == ERROR_SUCCESS;
3230 /***********************************************************************
3231 * InternetLockRequestFile (WININET.@)
3233 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3240 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3247 /***********************************************************************
3248 * InternetAutodial (WININET.@)
3250 * On windows this function is supposed to dial the default internet
3251 * connection. We don't want to have Wine dial out to the internet so
3252 * we return TRUE by default. It might be nice to check if we are connected.
3259 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3263 /* Tell that we are connected to the internet. */
3267 /***********************************************************************
3268 * InternetAutodialHangup (WININET.@)
3270 * Hangs up a connection made with InternetAutodial
3279 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3283 /* we didn't dial, we don't disconnect */
3287 /***********************************************************************
3288 * InternetCombineUrlA (WININET.@)
3290 * Combine a base URL with a relative URL
3298 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3299 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3304 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3306 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3307 dwFlags ^= ICU_NO_ENCODE;
3308 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3313 /***********************************************************************
3314 * InternetCombineUrlW (WININET.@)
3316 * Combine a base URL with a relative URL
3324 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3325 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3330 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3332 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3333 dwFlags ^= ICU_NO_ENCODE;
3334 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3339 /* max port num is 65535 => 5 digits */
3340 #define MAX_WORD_DIGITS 5
3342 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3343 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3344 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3345 (url)->dw##component##Length : strlen((url)->lpsz##component))
3347 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3349 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3350 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3352 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3353 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3355 if ((nScheme == INTERNET_SCHEME_FTP) &&
3356 (nPort == INTERNET_DEFAULT_FTP_PORT))
3358 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3359 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3362 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3368 /* opaque urls do not fit into the standard url hierarchy and don't have
3369 * two following slashes */
3370 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3372 return (nScheme != INTERNET_SCHEME_FTP) &&
3373 (nScheme != INTERNET_SCHEME_GOPHER) &&
3374 (nScheme != INTERNET_SCHEME_HTTP) &&
3375 (nScheme != INTERNET_SCHEME_HTTPS) &&
3376 (nScheme != INTERNET_SCHEME_FILE);
3379 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3382 if (scheme < INTERNET_SCHEME_FIRST)
3384 index = scheme - INTERNET_SCHEME_FIRST;
3385 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3387 return (LPCWSTR)&url_schemes[index];
3390 /* we can calculate using ansi strings because we're just
3391 * calculating string length, not size
3393 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3394 LPDWORD lpdwUrlLength)
3396 INTERNET_SCHEME nScheme;
3400 if (lpUrlComponents->lpszScheme)
3402 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3403 *lpdwUrlLength += dwLen;
3404 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3410 nScheme = lpUrlComponents->nScheme;
3412 if (nScheme == INTERNET_SCHEME_DEFAULT)
3413 nScheme = INTERNET_SCHEME_HTTP;
3414 scheme = INTERNET_GetSchemeString(nScheme);
3415 *lpdwUrlLength += strlenW(scheme);
3418 (*lpdwUrlLength)++; /* ':' */
3419 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3420 *lpdwUrlLength += strlen("//");
3422 if (lpUrlComponents->lpszUserName)
3424 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3425 *lpdwUrlLength += strlen("@");
3429 if (lpUrlComponents->lpszPassword)
3431 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3436 if (lpUrlComponents->lpszPassword)
3438 *lpdwUrlLength += strlen(":");
3439 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3442 if (lpUrlComponents->lpszHostName)
3444 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3446 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3448 char szPort[MAX_WORD_DIGITS+1];
3450 sprintf(szPort, "%d", lpUrlComponents->nPort);
3451 *lpdwUrlLength += strlen(szPort);
3452 *lpdwUrlLength += strlen(":");
3455 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3456 (*lpdwUrlLength)++; /* '/' */
3459 if (lpUrlComponents->lpszUrlPath)
3460 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3465 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3469 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3471 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3472 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3473 urlCompW->nScheme = lpUrlComponents->nScheme;
3474 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3475 urlCompW->nPort = lpUrlComponents->nPort;
3476 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3477 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3478 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3479 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3481 if (lpUrlComponents->lpszScheme)
3483 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3484 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3485 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3486 -1, urlCompW->lpszScheme, len);
3489 if (lpUrlComponents->lpszHostName)
3491 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3492 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3493 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3494 -1, urlCompW->lpszHostName, len);
3497 if (lpUrlComponents->lpszUserName)
3499 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3500 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3501 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3502 -1, urlCompW->lpszUserName, len);
3505 if (lpUrlComponents->lpszPassword)
3507 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3508 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3509 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3510 -1, urlCompW->lpszPassword, len);
3513 if (lpUrlComponents->lpszUrlPath)
3515 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3516 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3517 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3518 -1, urlCompW->lpszUrlPath, len);
3521 if (lpUrlComponents->lpszExtraInfo)
3523 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3524 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3525 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3526 -1, urlCompW->lpszExtraInfo, len);
3530 /***********************************************************************
3531 * InternetCreateUrlA (WININET.@)
3533 * See InternetCreateUrlW.
3535 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3536 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3540 URL_COMPONENTSW urlCompW;
3542 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3544 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3546 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3550 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3553 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3555 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3557 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3558 *lpdwUrlLength /= sizeof(WCHAR);
3560 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3561 * minus one, so add one to leave room for NULL terminator
3564 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3566 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3567 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3568 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3569 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3570 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3571 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3572 HeapFree(GetProcessHeap(), 0, urlW);
3577 /***********************************************************************
3578 * InternetCreateUrlW (WININET.@)
3580 * Creates a URL from its component parts.
3583 * lpUrlComponents [I] URL Components.
3584 * dwFlags [I] Flags. See notes.
3585 * lpszUrl [I] Buffer in which to store the created URL.
3586 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3587 * lpszUrl in characters. On output, the number of bytes
3588 * required to store the URL including terminator.
3592 * The dwFlags parameter can be zero or more of the following:
3593 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3600 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3601 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3604 INTERNET_SCHEME nScheme;
3606 static const WCHAR slashSlashW[] = {'/','/'};
3607 static const WCHAR percentD[] = {'%','d',0};
3609 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3611 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3613 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3617 if (!calc_url_length(lpUrlComponents, &dwLen))
3620 if (!lpszUrl || *lpdwUrlLength < dwLen)
3622 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3623 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3627 *lpdwUrlLength = dwLen;
3632 if (lpUrlComponents->lpszScheme)
3634 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3635 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3638 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3643 nScheme = lpUrlComponents->nScheme;
3645 if (nScheme == INTERNET_SCHEME_DEFAULT)
3646 nScheme = INTERNET_SCHEME_HTTP;
3648 scheme = INTERNET_GetSchemeString(nScheme);
3649 dwLen = strlenW(scheme);
3650 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3654 /* all schemes are followed by at least a colon */
3658 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3660 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3661 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3664 if (lpUrlComponents->lpszUserName)
3666 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3667 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3670 if (lpUrlComponents->lpszPassword)
3675 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3676 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3684 if (lpUrlComponents->lpszHostName)
3686 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3687 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3690 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3692 WCHAR szPort[MAX_WORD_DIGITS+1];
3694 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3697 dwLen = strlenW(szPort);
3698 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3702 /* add slash between hostname and path if necessary */
3703 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3711 if (lpUrlComponents->lpszUrlPath)
3713 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3714 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3723 /***********************************************************************
3724 * InternetConfirmZoneCrossingA (WININET.@)
3727 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3729 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3730 return ERROR_SUCCESS;
3733 /***********************************************************************
3734 * InternetConfirmZoneCrossingW (WININET.@)
3737 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3739 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3740 return ERROR_SUCCESS;
3743 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3744 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3746 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3747 lpdwConnection, dwReserved);
3748 return ERROR_SUCCESS;
3751 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3752 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3754 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3755 lpdwConnection, dwReserved);
3756 return ERROR_SUCCESS;
3759 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3761 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3765 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3767 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3771 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3773 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3774 return ERROR_SUCCESS;
3777 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3780 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3781 debugstr_w(pwszTarget), pbHexHash);
3785 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3787 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3791 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
3793 FIXME("(%p, %08lx) stub\n", a, b);