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>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
57 #include "wine/debug.h"
59 #define NO_SHLWAPI_STREAM
62 #include "wine/exception.h"
68 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define MAX_IDLE_WORKER 1000*60*1
74 #define MAX_WORKER_THREADS 10
75 #define RESPONSE_TIMEOUT 30
80 CHAR response[MAX_REPLY_LEN];
81 } WITHREADERROR, *LPWITHREADERROR;
83 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr);
84 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
85 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext);
86 static VOID INTERNET_ExecuteWork(void);
88 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
89 static LONG dwNumThreads;
90 static LONG dwNumIdleThreads;
91 static LONG dwNumJobs;
92 static HANDLE hEventArray[2];
93 #define hQuitEvent hEventArray[0]
94 #define hWorkEvent hEventArray[1]
95 static CRITICAL_SECTION csQueue;
96 static LPWORKREQUEST lpHeadWorkQueue;
97 static LPWORKREQUEST lpWorkQueueTail;
98 static HMODULE WININET_hModule;
100 #define HANDLE_CHUNK_SIZE 0x10
102 static CRITICAL_SECTION WININET_cs;
103 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
106 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
107 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
109 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
111 static LPWININETHANDLEHEADER *WININET_Handles;
112 static UINT WININET_dwNextHandle;
113 static UINT WININET_dwMaxHandles;
115 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
117 LPWININETHANDLEHEADER *p;
118 UINT handle = 0, num;
120 EnterCriticalSection( &WININET_cs );
121 if( !WININET_dwMaxHandles )
123 num = HANDLE_CHUNK_SIZE;
124 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
129 WININET_dwMaxHandles = num;
131 if( WININET_dwMaxHandles == WININET_dwNextHandle )
133 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
134 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
135 WININET_Handles, sizeof (UINT)* num);
139 WININET_dwMaxHandles = num;
142 handle = WININET_dwNextHandle;
143 if( WININET_Handles[handle] )
144 ERR("handle isn't free but should be\n");
145 WININET_Handles[handle] = WININET_AddRef( info );
147 while( WININET_Handles[WININET_dwNextHandle] &&
148 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
149 WININET_dwNextHandle++;
152 LeaveCriticalSection( &WININET_cs );
154 return (HINTERNET) (handle+1);
157 HINTERNET WININET_FindHandle( LPWININETHANDLEHEADER info )
161 EnterCriticalSection( &WININET_cs );
162 for( i=0; i<WININET_dwMaxHandles; i++ )
164 if( info == WININET_Handles[i] )
166 WININET_AddRef( info );
171 LeaveCriticalSection( &WININET_cs );
173 return (HINTERNET) handle;
176 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
179 TRACE("%p -> refcount = %d\n", info, info->dwRefCount );
183 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
185 LPWININETHANDLEHEADER info = NULL;
186 UINT handle = (UINT) hinternet;
188 EnterCriticalSection( &WININET_cs );
190 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
191 WININET_Handles[handle-1] )
192 info = WININET_AddRef( WININET_Handles[handle-1] );
194 LeaveCriticalSection( &WININET_cs );
196 TRACE("handle %d -> %p\n", handle, info);
201 BOOL WININET_Release( LPWININETHANDLEHEADER info )
204 TRACE( "object %p refcount = %d\n", info, info->dwRefCount );
205 if( !info->dwRefCount )
207 TRACE( "destroying object %p\n", info);
208 info->destroy( info );
213 BOOL WININET_FreeHandle( HINTERNET hinternet )
216 UINT handle = (UINT) hinternet;
217 LPWININETHANDLEHEADER info = NULL;
219 EnterCriticalSection( &WININET_cs );
221 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
224 if( WININET_Handles[handle] )
226 info = WININET_Handles[handle];
227 TRACE( "destroying handle %d for object %p\n", handle+1, info);
228 WININET_Handles[handle] = NULL;
230 if( WININET_dwNextHandle > handle )
231 WININET_dwNextHandle = handle;
235 LeaveCriticalSection( &WININET_cs );
238 WININET_Release( info );
243 /***********************************************************************
244 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
247 * hinstDLL [I] handle to the DLL's instance
249 * lpvReserved [I] reserved, must be NULL
256 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
258 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
261 case DLL_PROCESS_ATTACH:
263 g_dwTlsErrIndex = TlsAlloc();
265 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
268 hQuitEvent = CreateEventW(0, TRUE, FALSE, NULL);
269 hWorkEvent = CreateEventW(0, FALSE, FALSE, NULL);
270 InitializeCriticalSection(&csQueue);
272 URLCacheContainers_CreateDefaults();
275 dwNumIdleThreads = 0;
278 WININET_hModule = (HMODULE)hinstDLL;
280 case DLL_THREAD_ATTACH:
283 case DLL_THREAD_DETACH:
284 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
286 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
287 HeapFree(GetProcessHeap(), 0, lpwite);
291 case DLL_PROCESS_DETACH:
293 URLCacheContainers_DeleteAll();
295 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
297 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
298 TlsFree(g_dwTlsErrIndex);
301 SetEvent(hQuitEvent);
303 CloseHandle(hQuitEvent);
304 CloseHandle(hWorkEvent);
305 DeleteCriticalSection(&csQueue);
313 /***********************************************************************
314 * InternetInitializeAutoProxyDll (WININET.@)
316 * Setup the internal proxy
325 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
328 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
332 /***********************************************************************
333 * DetectAutoProxyUrl (WININET.@)
335 * Auto detect the proxy url
341 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
342 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
345 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
350 /***********************************************************************
351 * INTERNET_ConfigureProxyFromReg
354 * The proxy may be specified in the form 'http=proxy.my.org'
355 * Presumably that means there can be ftp=ftpproxy.my.org too.
357 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
360 DWORD r, keytype, len, enabled;
361 LPCSTR lpszInternetSettings =
362 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
363 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
365 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
366 if ( r != ERROR_SUCCESS )
369 len = sizeof enabled;
370 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
371 (BYTE*)&enabled, &len);
372 if( (r == ERROR_SUCCESS) && enabled )
374 TRACE("Proxy is enabled.\n");
376 /* figure out how much memory the proxy setting takes */
377 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
379 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
382 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
384 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
385 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
386 (BYTE*)szProxy, &len);
388 /* find the http proxy, and strip away everything else */
389 p = strstrW( szProxy, szHttp );
392 p += lstrlenW(szHttp);
393 lstrcpyW( szProxy, p );
395 p = strchrW( szProxy, ' ' );
399 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
400 lpwai->lpszProxy = szProxy;
402 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
405 ERR("Couldn't read proxy server settings.\n");
408 TRACE("Proxy is not enabled.\n");
414 /***********************************************************************
415 * dump_INTERNET_FLAGS
417 * Helper function to TRACE the internet flags.
423 static void dump_INTERNET_FLAGS(DWORD dwFlags)
425 #define FE(x) { x, #x }
426 static const wininet_flag_info flag[] = {
427 FE(INTERNET_FLAG_RELOAD),
428 FE(INTERNET_FLAG_RAW_DATA),
429 FE(INTERNET_FLAG_EXISTING_CONNECT),
430 FE(INTERNET_FLAG_ASYNC),
431 FE(INTERNET_FLAG_PASSIVE),
432 FE(INTERNET_FLAG_NO_CACHE_WRITE),
433 FE(INTERNET_FLAG_MAKE_PERSISTENT),
434 FE(INTERNET_FLAG_FROM_CACHE),
435 FE(INTERNET_FLAG_SECURE),
436 FE(INTERNET_FLAG_KEEP_CONNECTION),
437 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
438 FE(INTERNET_FLAG_READ_PREFETCH),
439 FE(INTERNET_FLAG_NO_COOKIES),
440 FE(INTERNET_FLAG_NO_AUTH),
441 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
442 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
443 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
444 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
445 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
446 FE(INTERNET_FLAG_RESYNCHRONIZE),
447 FE(INTERNET_FLAG_HYPERLINK),
448 FE(INTERNET_FLAG_NO_UI),
449 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
450 FE(INTERNET_FLAG_CACHE_ASYNC),
451 FE(INTERNET_FLAG_FORMS_SUBMIT),
452 FE(INTERNET_FLAG_NEED_FILE),
453 FE(INTERNET_FLAG_TRANSFER_ASCII),
454 FE(INTERNET_FLAG_TRANSFER_BINARY)
459 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
460 if (flag[i].val & dwFlags) {
461 TRACE(" %s", flag[i].name);
462 dwFlags &= ~flag[i].val;
466 TRACE(" Unknown flags (%08x)\n", dwFlags);
471 /***********************************************************************
472 * InternetOpenW (WININET.@)
474 * Per-application initialization of wininet
477 * HINTERNET on success
481 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
482 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
484 LPWININETAPPINFOW lpwai = NULL;
485 HINTERNET handle = NULL;
487 if (TRACE_ON(wininet)) {
488 #define FE(x) { x, #x }
489 static const wininet_flag_info access_type[] = {
490 FE(INTERNET_OPEN_TYPE_PRECONFIG),
491 FE(INTERNET_OPEN_TYPE_DIRECT),
492 FE(INTERNET_OPEN_TYPE_PROXY),
493 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
497 const char *access_type_str = "Unknown";
499 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
500 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
501 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
502 if (access_type[i].val == dwAccessType) {
503 access_type_str = access_type[i].name;
507 TRACE(" access type : %s\n", access_type_str);
509 dump_INTERNET_FLAGS(dwFlags);
512 /* Clear any error information */
513 INTERNET_SetLastError(0);
515 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW));
518 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
522 memset(lpwai, 0, sizeof(WININETAPPINFOW));
523 lpwai->hdr.htype = WH_HINIT;
524 lpwai->hdr.lpwhparent = NULL;
525 lpwai->hdr.dwFlags = dwFlags;
526 lpwai->hdr.dwRefCount = 1;
527 lpwai->hdr.destroy = INTERNET_CloseHandle;
528 lpwai->dwAccessType = dwAccessType;
529 lpwai->lpszProxyUsername = NULL;
530 lpwai->lpszProxyPassword = NULL;
532 handle = WININET_AllocHandle( &lpwai->hdr );
535 HeapFree( GetProcessHeap(), 0, lpwai );
536 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
540 if (NULL != lpszAgent)
542 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
543 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
544 if (lpwai->lpszAgent)
545 lstrcpyW( lpwai->lpszAgent, lpszAgent );
547 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
548 INTERNET_ConfigureProxyFromReg( lpwai );
549 else if (NULL != lpszProxy)
551 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
552 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
553 if (lpwai->lpszProxy)
554 lstrcpyW( lpwai->lpszProxy, lpszProxy );
557 if (NULL != lpszProxyBypass)
559 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
560 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
561 if (lpwai->lpszProxyBypass)
562 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
567 WININET_Release( &lpwai->hdr );
569 TRACE("returning %p\n", lpwai);
575 /***********************************************************************
576 * InternetOpenA (WININET.@)
578 * Per-application initialization of wininet
581 * HINTERNET on success
585 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
586 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
588 HINTERNET rc = (HINTERNET)NULL;
590 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
592 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
593 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
597 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
598 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
599 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
604 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
605 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
606 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
609 if( lpszProxyBypass )
611 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
612 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
613 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
616 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
618 HeapFree(GetProcessHeap(), 0, szAgent);
619 HeapFree(GetProcessHeap(), 0, szProxy);
620 HeapFree(GetProcessHeap(), 0, szBypass);
625 /***********************************************************************
626 * InternetGetLastResponseInfoA (WININET.@)
628 * Return last wininet error description on the calling thread
631 * TRUE on success of writing to buffer
635 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
636 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
638 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
644 *lpdwError = lpwite->dwError;
647 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
648 *lpdwBufferLength = strlen(lpszBuffer);
651 *lpdwBufferLength = 0;
656 *lpdwBufferLength = 0;
662 /***********************************************************************
663 * InternetGetLastResponseInfoW (WININET.@)
665 * Return last wininet error description on the calling thread
668 * TRUE on success of writing to buffer
672 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
673 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
675 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
681 *lpdwError = lpwite->dwError;
684 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
685 *lpdwBufferLength = lstrlenW(lpszBuffer);
688 *lpdwBufferLength = 0;
693 *lpdwBufferLength = 0;
699 /***********************************************************************
700 * InternetGetConnectedState (WININET.@)
702 * Return connected state
706 * if lpdwStatus is not null, return the status (off line,
707 * modem, lan...) in it.
708 * FALSE if not connected
710 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
712 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
715 FIXME("always returning LAN connection.\n");
716 *lpdwStatus = INTERNET_CONNECTION_LAN;
722 /***********************************************************************
723 * InternetGetConnectedStateExW (WININET.@)
725 * Return connected state
729 * lpdwStatus [O] Flags specifying the status of the internet connection.
730 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
731 * dwNameLen [I] Size of the buffer, in characters.
732 * dwReserved [I] Reserved. Must be set to 0.
736 * if lpdwStatus is not null, return the status (off line,
737 * modem, lan...) in it.
738 * FALSE if not connected
741 * If the system has no available network connections, an empty string is
742 * stored in lpszConnectionName. If there is a LAN connection, a localized
743 * "LAN Connection" string is stored. Presumably, if only a dial-up
744 * connection is available then the name of the dial-up connection is
745 * returned. Why any application, other than the "Internet Settings" CPL,
746 * would want to use this function instead of the simpler InternetGetConnectedStateW
747 * function is beyond me.
749 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
750 DWORD dwNameLen, DWORD dwReserved)
752 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
759 FIXME("always returning LAN connection.\n");
760 *lpdwStatus = INTERNET_CONNECTION_LAN;
762 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
766 /***********************************************************************
767 * InternetGetConnectedStateExA (WININET.@)
769 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
770 DWORD dwNameLen, DWORD dwReserved)
772 LPWSTR lpwszConnectionName = NULL;
775 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
777 if (lpszConnectionName && dwNameLen > 0)
778 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
780 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
782 if (rc && lpwszConnectionName)
784 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
785 dwNameLen, NULL, NULL);
787 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
794 /***********************************************************************
795 * InternetConnectW (WININET.@)
797 * Open a ftp, gopher or http session
800 * HINTERNET a session handle on success
804 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
805 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
806 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
807 DWORD dwService, DWORD dwFlags, DWORD dwContext)
809 LPWININETAPPINFOW hIC;
812 TRACE("(%p, %s, %i, %s, %s, %i, %i, %i)\n", hInternet, debugstr_w(lpszServerName),
813 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
814 dwService, dwFlags, dwContext);
818 SetLastError(ERROR_INVALID_PARAMETER);
822 /* Clear any error information */
823 INTERNET_SetLastError(0);
824 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
825 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
827 SetLastError(ERROR_INVALID_HANDLE);
833 case INTERNET_SERVICE_FTP:
834 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
835 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
838 case INTERNET_SERVICE_HTTP:
839 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
840 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
843 case INTERNET_SERVICE_GOPHER:
849 WININET_Release( &hIC->hdr );
851 TRACE("returning %p\n", rc);
856 /***********************************************************************
857 * InternetConnectA (WININET.@)
859 * Open a ftp, gopher or http session
862 * HINTERNET a session handle on success
866 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
867 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
868 LPCSTR lpszUserName, LPCSTR lpszPassword,
869 DWORD dwService, DWORD dwFlags, DWORD dwContext)
871 HINTERNET rc = (HINTERNET)NULL;
873 LPWSTR szServerName = NULL;
874 LPWSTR szUserName = NULL;
875 LPWSTR szPassword = NULL;
879 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
880 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
881 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
885 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
886 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
887 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
891 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
892 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
893 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
897 rc = InternetConnectW(hInternet, szServerName, nServerPort,
898 szUserName, szPassword, dwService, dwFlags, dwContext);
900 HeapFree(GetProcessHeap(), 0, szServerName);
901 HeapFree(GetProcessHeap(), 0, szUserName);
902 HeapFree(GetProcessHeap(), 0, szPassword);
907 /***********************************************************************
908 * InternetFindNextFileA (WININET.@)
910 * Continues a file search from a previous call to FindFirstFile
917 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
922 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
924 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
928 /***********************************************************************
929 * InternetFindNextFileW (WININET.@)
931 * Continues a file search from a previous call to FindFirstFile
938 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
940 LPWININETAPPINFOW hIC = NULL;
941 LPWININETFTPFINDNEXTW lpwh;
942 BOOL bSuccess = FALSE;
946 lpwh = (LPWININETFTPFINDNEXTW) WININET_GetObject( hFind );
947 if (NULL == lpwh || lpwh->hdr.htype != WH_HFTPFINDNEXT)
949 FIXME("Only FTP supported\n");
950 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
954 hIC = lpwh->lpFtpSession->lpAppInfo;
955 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
957 WORKREQUEST workRequest;
958 struct WORKREQ_FTPFINDNEXTW *req;
960 workRequest.asyncall = FTPFINDNEXTW;
961 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
962 req = &workRequest.u.FtpFindNextW;
963 req->lpFindFileData = lpvFindData;
965 bSuccess = INTERNET_AsyncCall(&workRequest);
969 bSuccess = FTP_FindNextFileW(lpwh, lpvFindData);
973 WININET_Release( &lpwh->hdr );
977 /***********************************************************************
978 * INTERNET_CloseHandle (internal)
980 * Close internet handle
986 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
988 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
992 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
993 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
994 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
995 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
996 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
997 HeapFree(GetProcessHeap(), 0, lpwai);
1001 /***********************************************************************
1002 * InternetCloseHandle (WININET.@)
1004 * Generic close handle function
1011 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1013 LPWININETHANDLEHEADER lpwh;
1015 TRACE("%p\n",hInternet);
1017 lpwh = WININET_GetObject( hInternet );
1020 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1024 /* FIXME: native appears to send this from the equivalent of
1025 * WININET_Release */
1026 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1027 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
1030 if( lpwh->lpwhparent )
1031 WININET_Release( lpwh->lpwhparent );
1032 WININET_FreeHandle( hInternet );
1033 WININET_Release( lpwh );
1039 /***********************************************************************
1040 * ConvertUrlComponentValue (Internal)
1042 * Helper function for InternetCrackUrlW
1045 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1046 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1047 LPCSTR lpszStart, LPCWSTR lpwszStart)
1049 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1050 if (*dwComponentLen != 0)
1052 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1053 if (*lppszComponent == NULL)
1055 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1057 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1059 *lppszComponent = NULL;
1060 *dwComponentLen = nASCIILength;
1064 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1065 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1066 (*lppszComponent)[ncpylen]=0;
1067 *dwComponentLen = ncpylen;
1073 /***********************************************************************
1074 * InternetCrackUrlA (WININET.@)
1076 * See InternetCrackUrlW.
1078 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1079 LPURL_COMPONENTSA lpUrlComponents)
1082 URL_COMPONENTSW UCW;
1085 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1088 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1090 /* if dwUrlLength=-1 then nLength includes null but length to
1091 InternetCrackUrlW should not include it */
1092 if (dwUrlLength == -1) nLength--;
1094 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1095 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1097 memset(&UCW,0,sizeof(UCW));
1098 if(lpUrlComponents->dwHostNameLength!=0)
1099 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1100 if(lpUrlComponents->dwUserNameLength!=0)
1101 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1102 if(lpUrlComponents->dwPasswordLength!=0)
1103 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1104 if(lpUrlComponents->dwUrlPathLength!=0)
1105 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1106 if(lpUrlComponents->dwSchemeLength!=0)
1107 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1108 if(lpUrlComponents->dwExtraInfoLength!=0)
1109 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1110 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1112 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1116 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1117 UCW.lpszHostName, UCW.dwHostNameLength,
1119 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1120 UCW.lpszUserName, UCW.dwUserNameLength,
1122 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1123 UCW.lpszPassword, UCW.dwPasswordLength,
1125 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1126 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1128 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1129 UCW.lpszScheme, UCW.dwSchemeLength,
1131 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1132 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1134 lpUrlComponents->nScheme=UCW.nScheme;
1135 lpUrlComponents->nPort=UCW.nPort;
1136 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1138 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1139 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1140 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1141 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1142 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1147 static const WCHAR url_schemes[][7] =
1150 {'g','o','p','h','e','r',0},
1151 {'h','t','t','p',0},
1152 {'h','t','t','p','s',0},
1153 {'f','i','l','e',0},
1154 {'n','e','w','s',0},
1155 {'m','a','i','l','t','o',0},
1159 /***********************************************************************
1160 * GetInternetSchemeW (internal)
1166 * INTERNET_SCHEME_UNKNOWN on failure
1169 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1173 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1175 if(lpszScheme==NULL)
1176 return INTERNET_SCHEME_UNKNOWN;
1178 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1179 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1180 return INTERNET_SCHEME_FIRST + i;
1182 return INTERNET_SCHEME_UNKNOWN;
1185 /***********************************************************************
1186 * SetUrlComponentValueW (Internal)
1188 * Helper function for InternetCrackUrlW
1191 * lppszComponent [O] Holds the returned string
1192 * dwComponentLen [I] Holds the size of lppszComponent
1193 * [O] Holds the length of the string in lppszComponent without '\0'
1194 * lpszStart [I] Holds the string to copy from
1195 * len [I] Holds the length of lpszStart without '\0'
1202 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1204 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1206 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1209 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1211 if (*lppszComponent == NULL)
1213 *lppszComponent = (LPWSTR)lpszStart;
1214 *dwComponentLen = len;
1218 DWORD ncpylen = min((*dwComponentLen)-1, len);
1219 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1220 (*lppszComponent)[ncpylen] = '\0';
1221 *dwComponentLen = ncpylen;
1228 /***********************************************************************
1229 * InternetCrackUrlW (WININET.@)
1231 * Break up URL into its components
1237 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1238 LPURL_COMPONENTSW lpUC)
1242 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1245 LPCWSTR lpszParam = NULL;
1246 BOOL bIsAbsolute = FALSE;
1247 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1248 LPCWSTR lpszcp = NULL;
1249 LPWSTR lpszUrl_decode = NULL;
1250 DWORD dwUrlLength = dwUrlLength_orig;
1251 const WCHAR lpszSeparators[3]={';','?',0};
1252 const WCHAR lpszSlash[2]={'/',0};
1254 dwUrlLength=strlenW(lpszUrl);
1256 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1258 if (!lpszUrl_orig || !*lpszUrl_orig)
1260 SetLastError(ERROR_INVALID_PARAMETER);
1264 if (dwFlags & ICU_DECODE)
1266 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1267 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1269 lpszUrl = lpszUrl_decode;
1274 /* Determine if the URI is absolute. */
1275 while (*lpszap != '\0')
1277 if (isalnumW(*lpszap))
1282 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1289 lpszcp = lpszUrl; /* Relative url */
1295 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1296 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1298 /* Parse <params> */
1299 lpszParam = strpbrkW(lpszap, lpszSeparators);
1300 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1301 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1303 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1307 /* Get scheme first. */
1308 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1309 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1310 lpszUrl, lpszcp - lpszUrl);
1312 /* Eat ':' in protocol. */
1315 /* double slash indicates the net_loc portion is present */
1316 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1320 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1324 lpszNetLoc = min(lpszNetLoc, lpszParam);
1326 lpszNetLoc = lpszParam;
1328 else if (!lpszNetLoc)
1329 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1337 /* [<user>[<:password>]@]<host>[:<port>] */
1338 /* First find the user and password if they exist */
1340 lpszHost = strchrW(lpszcp, '@');
1341 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1343 /* username and password not specified. */
1344 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1345 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1347 else /* Parse out username and password */
1349 LPCWSTR lpszUser = lpszcp;
1350 LPCWSTR lpszPasswd = lpszHost;
1352 while (lpszcp < lpszHost)
1355 lpszPasswd = lpszcp;
1360 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1361 lpszUser, lpszPasswd - lpszUser);
1363 if (lpszPasswd != lpszHost)
1365 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1366 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1367 lpszHost - lpszPasswd);
1369 lpszcp++; /* Advance to beginning of host */
1372 /* Parse <host><:port> */
1375 lpszPort = lpszNetLoc;
1377 /* special case for res:// URLs: there is no port here, so the host is the
1378 entire string up to the first '/' */
1379 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1381 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1382 lpszHost, lpszPort - lpszHost);
1387 while (lpszcp < lpszNetLoc)
1395 /* If the scheme is "file" and the host is just one letter, it's not a host */
1396 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1399 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1404 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1405 lpszHost, lpszPort - lpszHost);
1406 if (lpszPort != lpszNetLoc)
1407 lpUC->nPort = atoiW(++lpszPort);
1408 else switch (lpUC->nScheme)
1410 case INTERNET_SCHEME_HTTP:
1411 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1413 case INTERNET_SCHEME_HTTPS:
1414 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1416 case INTERNET_SCHEME_FTP:
1417 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1419 case INTERNET_SCHEME_GOPHER:
1420 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1431 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1432 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1433 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1438 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1439 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1440 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1441 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1444 /* Here lpszcp points to:
1446 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1447 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1449 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1453 /* Only truncate the parameter list if it's already been saved
1454 * in lpUC->lpszExtraInfo.
1456 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1457 len = lpszParam - lpszcp;
1460 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1461 * newlines if necessary.
1463 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1464 if (lpsznewline != NULL)
1465 len = lpsznewline - lpszcp;
1467 len = dwUrlLength-(lpszcp-lpszUrl);
1469 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1474 lpUC->dwUrlPathLength = 0;
1477 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1478 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1479 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1480 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1481 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1483 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1487 /***********************************************************************
1488 * InternetAttemptConnect (WININET.@)
1490 * Attempt to make a connection to the internet
1493 * ERROR_SUCCESS on success
1494 * Error value on failure
1497 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1500 return ERROR_SUCCESS;
1504 /***********************************************************************
1505 * InternetCanonicalizeUrlA (WININET.@)
1507 * Escape unsafe characters and spaces
1514 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1515 LPDWORD lpdwBufferLength, DWORD dwFlags)
1518 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1519 if(dwFlags & ICU_DECODE)
1521 dwURLFlags |= URL_UNESCAPE;
1522 dwFlags &= ~ICU_DECODE;
1525 if(dwFlags & ICU_ESCAPE)
1527 dwURLFlags |= URL_UNESCAPE;
1528 dwFlags &= ~ICU_ESCAPE;
1530 if(dwFlags & ICU_BROWSER_MODE)
1532 dwURLFlags |= URL_BROWSER_MODE;
1533 dwFlags &= ~ICU_BROWSER_MODE;
1536 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1537 TRACE("%s %p %p %08x\n", debugstr_a(lpszUrl), lpszBuffer,
1538 lpdwBufferLength, dwURLFlags);
1540 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1541 dwFlags ^= ICU_NO_ENCODE;
1543 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1545 return (hr == S_OK) ? TRUE : FALSE;
1548 /***********************************************************************
1549 * InternetCanonicalizeUrlW (WININET.@)
1551 * Escape unsafe characters and spaces
1558 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1559 LPDWORD lpdwBufferLength, DWORD dwFlags)
1562 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
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;
1574 if(dwFlags & ICU_BROWSER_MODE)
1576 dwURLFlags |= URL_BROWSER_MODE;
1577 dwFlags &= ~ICU_BROWSER_MODE;
1580 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1581 TRACE("%s %p %p %08x\n", debugstr_w(lpszUrl), lpszBuffer,
1582 lpdwBufferLength, dwURLFlags);
1584 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1585 dwFlags ^= ICU_NO_ENCODE;
1587 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1589 return (hr == S_OK) ? TRUE : FALSE;
1593 /***********************************************************************
1594 * InternetSetStatusCallbackA (WININET.@)
1596 * Sets up a callback function which is called as progress is made
1597 * during an operation.
1600 * Previous callback or NULL on success
1601 * INTERNET_INVALID_STATUS_CALLBACK on failure
1604 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1605 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1607 INTERNET_STATUS_CALLBACK retVal;
1608 LPWININETHANDLEHEADER lpwh;
1610 TRACE("0x%08x\n", (ULONG)hInternet);
1612 lpwh = WININET_GetObject(hInternet);
1614 return INTERNET_INVALID_STATUS_CALLBACK;
1616 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1617 retVal = lpwh->lpfnStatusCB;
1618 lpwh->lpfnStatusCB = lpfnIntCB;
1620 WININET_Release( lpwh );
1625 /***********************************************************************
1626 * InternetSetStatusCallbackW (WININET.@)
1628 * Sets up a callback function which is called as progress is made
1629 * during an operation.
1632 * Previous callback or NULL on success
1633 * INTERNET_INVALID_STATUS_CALLBACK on failure
1636 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1637 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1639 INTERNET_STATUS_CALLBACK retVal;
1640 LPWININETHANDLEHEADER lpwh;
1642 TRACE("0x%08x\n", (ULONG)hInternet);
1644 lpwh = WININET_GetObject(hInternet);
1646 return INTERNET_INVALID_STATUS_CALLBACK;
1648 lpwh->dwInternalFlags |= INET_CALLBACKW;
1649 retVal = lpwh->lpfnStatusCB;
1650 lpwh->lpfnStatusCB = lpfnIntCB;
1652 WININET_Release( lpwh );
1657 /***********************************************************************
1658 * InternetSetFilePointer (WININET.@)
1660 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1661 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1667 /***********************************************************************
1668 * InternetWriteFile (WININET.@)
1670 * Write data to an open internet file
1677 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1678 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1680 BOOL retval = FALSE;
1682 LPWININETHANDLEHEADER lpwh;
1685 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1689 switch (lpwh->htype)
1693 LPWININETHTTPREQW lpwhr;
1694 lpwhr = (LPWININETHTTPREQW)lpwh;
1696 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite);
1697 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1698 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1700 WININET_Release( lpwh );
1706 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1715 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1716 retval = (res >= 0);
1717 *lpdwNumOfBytesWritten = retval ? res : 0;
1719 WININET_Release( lpwh );
1725 static BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1726 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1727 BOOL bWait, BOOL bSendCompletionStatus)
1729 BOOL retval = FALSE;
1732 /* FIXME: this should use NETCON functions! */
1733 switch (lpwh->htype)
1736 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1737 dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0, (int *)pdwNumOfBytesRead))
1739 *pdwNumOfBytesRead = 0;
1740 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1747 /* FIXME: FTP should use NETCON_ stuff */
1748 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1751 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1752 retval = (res >= 0);
1753 *pdwNumOfBytesRead = retval ? res : 0;
1761 if (bSendCompletionStatus)
1763 INTERNET_ASYNC_RESULT iar;
1765 iar.dwResult = retval;
1766 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1767 INTERNET_GetLastError();
1769 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1770 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1771 sizeof(INTERNET_ASYNC_RESULT));
1776 /***********************************************************************
1777 * InternetReadFile (WININET.@)
1779 * Read data from an open internet file
1786 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1787 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1789 LPWININETHANDLEHEADER lpwh;
1792 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1794 lpwh = WININET_GetObject( hFile );
1797 SetLastError(ERROR_INVALID_HANDLE);
1801 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1802 WININET_Release( lpwh );
1804 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
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 dwContext)
1838 BOOL retval = FALSE;
1839 LPWININETHANDLEHEADER lpwh;
1841 TRACE("(%p %p 0x%x 0x%x)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1843 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1844 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1846 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1848 SetLastError(ERROR_INVALID_PARAMETER);
1852 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1855 SetLastError(ERROR_INVALID_HANDLE);
1859 /* FIXME: native only does it asynchronously if the amount of data
1860 * requested isn't available. See NtReadFile. */
1861 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1862 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1863 * we should implement the above first */
1864 if (dwFlags & IRF_ASYNC)
1866 WORKREQUEST workRequest;
1867 struct WORKREQ_INTERNETREADFILEEXA *req;
1869 workRequest.asyncall = INTERNETREADFILEEXA;
1870 workRequest.hdr = WININET_AddRef( lpwh );
1871 req = &workRequest.u.InternetReadFileExA;
1872 req->lpBuffersOut = lpBuffersOut;
1874 retval = INTERNET_AsyncCall(&workRequest);
1875 if (!retval) return FALSE;
1877 SetLastError(ERROR_IO_PENDING);
1881 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1882 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1883 !(dwFlags & IRF_NO_WAIT), FALSE);
1885 WININET_Release( lpwh );
1887 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1891 /***********************************************************************
1892 * InternetReadFileExW (WININET.@)
1894 * Read data from an open internet file.
1897 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1898 * lpBuffersOut [I/O] Buffer.
1899 * dwFlags [I] Flags.
1900 * dwContext [I] Context for callbacks.
1903 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1906 * Not implemented in Wine or native either (as of IE6 SP2).
1909 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1910 DWORD dwFlags, DWORD dwContext)
1912 ERR("(%p, %p, 0x%x, 0x%x): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1914 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1918 /***********************************************************************
1919 * INET_QueryOptionHelper (internal)
1921 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1922 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1924 LPWININETHANDLEHEADER lpwhh;
1925 BOOL bSuccess = FALSE;
1927 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1929 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1932 SetLastError(ERROR_INVALID_PARAMETER);
1938 case INTERNET_OPTION_HANDLE_TYPE:
1944 WARN("Invalid hInternet handle\n");
1945 SetLastError(ERROR_INVALID_HANDLE);
1949 type = lpwhh->htype;
1951 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
1953 if (*lpdwBufferLength < sizeof(ULONG))
1954 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1957 memcpy(lpBuffer, &type, sizeof(ULONG));
1960 *lpdwBufferLength = sizeof(ULONG);
1964 case INTERNET_OPTION_REQUEST_FLAGS:
1967 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1968 if (*lpdwBufferLength < sizeof(ULONG))
1969 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1972 memcpy(lpBuffer, &flags, sizeof(ULONG));
1975 *lpdwBufferLength = sizeof(ULONG);
1979 case INTERNET_OPTION_URL:
1980 case INTERNET_OPTION_DATAFILE_NAME:
1984 WARN("Invalid hInternet handle\n");
1985 SetLastError(ERROR_INVALID_HANDLE);
1988 if (lpwhh->htype == WH_HHTTPREQ)
1990 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
1992 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
1993 static const WCHAR szHost[] = {'H','o','s','t',0};
1997 Host = HTTP_GetHeader(lpreq,szHost);
1998 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
1999 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2002 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2003 lpBuffer,*lpdwBufferLength,NULL,NULL);
2004 if (sizeRequired > *lpdwBufferLength)
2005 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2008 *lpdwBufferLength = sizeRequired;
2012 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2013 if (*lpdwBufferLength < sizeRequired)
2014 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2017 strcpyW(lpBuffer, url);
2020 *lpdwBufferLength = sizeRequired;
2025 case INTERNET_OPTION_HTTP_VERSION:
2027 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2028 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2032 * Presently hardcoded to 1.1
2034 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2035 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2038 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2041 case INTERNET_OPTION_CONNECTED_STATE:
2043 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2044 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2046 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2047 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2050 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2053 *lpdwBufferLength = sizeof(*pdwConnectedState);
2056 case INTERNET_OPTION_PROXY:
2058 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2059 WININETAPPINFOW wai;
2063 TRACE("Getting global proxy info\n");
2064 memset(&wai, 0, sizeof(WININETAPPINFOW));
2065 INTERNET_ConfigureProxyFromReg( &wai );
2071 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2072 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2074 if (lpwai->lpszProxy)
2075 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2077 if (lpwai->lpszProxyBypass)
2078 proxyBypassBytesRequired =
2079 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2080 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2081 proxyBytesRequired + proxyBypassBytesRequired)
2082 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2085 pPI->dwAccessType = lpwai->dwAccessType;
2086 if (lpwai->lpszProxy)
2088 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2089 sizeof(INTERNET_PROXY_INFOW));
2090 lstrcpyW((LPWSTR)pPI->lpszProxy, lpwai->lpszProxy);
2094 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2095 sizeof(INTERNET_PROXY_INFOW));
2096 *((LPWSTR)(pPI->lpszProxy)) = 0;
2099 if (lpwai->lpszProxyBypass)
2101 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2102 sizeof(INTERNET_PROXY_INFOW) +
2103 proxyBytesRequired);
2104 lstrcpyW((LPWSTR)pPI->lpszProxyBypass,
2105 lpwai->lpszProxyBypass);
2109 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2110 sizeof(INTERNET_PROXY_INFOW) +
2111 proxyBytesRequired);
2112 *((LPWSTR)(pPI->lpszProxyBypass)) = 0;
2116 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2117 proxyBytesRequired + proxyBypassBytesRequired;
2121 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2122 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2124 if (lpwai->lpszProxy)
2125 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2126 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2127 if (lpwai->lpszProxyBypass)
2128 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2129 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2130 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2131 proxyBytesRequired + proxyBypassBytesRequired)
2132 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2135 pPI->dwAccessType = lpwai->dwAccessType;
2136 if (lpwai->lpszProxy)
2138 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2139 sizeof(INTERNET_PROXY_INFOA));
2140 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2141 (LPSTR)pPI->lpszProxy, proxyBytesRequired, NULL, NULL);
2145 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2146 sizeof(INTERNET_PROXY_INFOA));
2147 *((LPSTR)(pPI->lpszProxy)) = '\0';
2150 if (lpwai->lpszProxyBypass)
2152 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2153 sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
2154 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2155 -1, (LPSTR)pPI->lpszProxyBypass,
2156 proxyBypassBytesRequired,
2161 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2162 sizeof(INTERNET_PROXY_INFOA) +
2163 proxyBytesRequired);
2164 *((LPSTR)(pPI->lpszProxyBypass)) = '\0';
2168 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2169 proxyBytesRequired + proxyBypassBytesRequired;
2173 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2176 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2177 if (*lpdwBufferLength < sizeof(ULONG))
2178 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2181 memcpy(lpBuffer, &conn, sizeof(ULONG));
2184 *lpdwBufferLength = sizeof(ULONG);
2187 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2190 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2191 if (*lpdwBufferLength < sizeof(ULONG))
2192 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2195 memcpy(lpBuffer, &conn, sizeof(ULONG));
2198 *lpdwBufferLength = sizeof(ULONG);
2201 case INTERNET_OPTION_SECURITY_FLAGS:
2202 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2205 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2206 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2208 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2209 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2211 else if (lpwhh->htype == WH_HHTTPREQ)
2213 LPWININETHTTPREQW lpwhr;
2214 PCCERT_CONTEXT context;
2216 lpwhr = (LPWININETHTTPREQW)lpwhh;
2217 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2220 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2223 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2224 info->ftExpiry = context->pCertInfo->NotAfter;
2225 info->ftStart = context->pCertInfo->NotBefore;
2228 strLen = CertNameToStrW(context->dwCertEncodingType,
2229 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2231 info->lpszSubjectInfo = LocalAlloc(0,
2232 strLen * sizeof(WCHAR));
2233 if (info->lpszSubjectInfo)
2234 CertNameToStrW(context->dwCertEncodingType,
2235 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2236 info->lpszSubjectInfo, strLen);
2237 strLen = CertNameToStrW(context->dwCertEncodingType,
2238 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2240 info->lpszIssuerInfo = LocalAlloc(0,
2241 strLen * sizeof(WCHAR));
2242 if (info->lpszIssuerInfo)
2243 CertNameToStrW(context->dwCertEncodingType,
2244 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2245 info->lpszIssuerInfo, strLen);
2249 LPINTERNET_CERTIFICATE_INFOA infoA =
2250 (LPINTERNET_CERTIFICATE_INFOA)info;
2252 strLen = CertNameToStrA(context->dwCertEncodingType,
2253 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2255 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2256 if (infoA->lpszSubjectInfo)
2257 CertNameToStrA(context->dwCertEncodingType,
2258 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2259 infoA->lpszSubjectInfo, strLen);
2260 strLen = CertNameToStrA(context->dwCertEncodingType,
2261 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2263 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2264 if (infoA->lpszIssuerInfo)
2265 CertNameToStrA(context->dwCertEncodingType,
2266 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2267 infoA->lpszIssuerInfo, strLen);
2270 * Contrary to MSDN, these do not appear to be set.
2272 * lpszSignatureAlgName
2273 * lpszEncryptionAlgName
2276 CertFreeCertificateContext(context);
2282 FIXME("Stub! %d\n", dwOption);
2286 WININET_Release( lpwhh );
2291 /***********************************************************************
2292 * InternetQueryOptionW (WININET.@)
2294 * Queries an options on the specified handle
2301 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2302 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2304 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2307 /***********************************************************************
2308 * InternetQueryOptionA (WININET.@)
2310 * Queries an options on the specified handle
2317 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2318 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2320 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2324 /***********************************************************************
2325 * InternetSetOptionW (WININET.@)
2327 * Sets an options on the specified handle
2334 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2335 LPVOID lpBuffer, DWORD dwBufferLength)
2337 LPWININETHANDLEHEADER lpwhh;
2340 TRACE("0x%08x\n", dwOption);
2342 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2348 case INTERNET_OPTION_HTTP_VERSION:
2350 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2351 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2354 case INTERNET_OPTION_ERROR_MASK:
2356 unsigned long flags=*(unsigned long*)lpBuffer;
2357 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2360 case INTERNET_OPTION_CODEPAGE:
2362 unsigned long codepage=*(unsigned long*)lpBuffer;
2363 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2366 case INTERNET_OPTION_REQUEST_PRIORITY:
2368 unsigned long priority=*(unsigned long*)lpBuffer;
2369 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2372 case INTERNET_OPTION_CONNECT_TIMEOUT:
2374 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2375 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2378 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2380 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2381 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2384 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2386 unsigned long conns=*(unsigned long*)lpBuffer;
2387 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2390 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2392 unsigned long conns=*(unsigned long*)lpBuffer;
2393 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2396 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2397 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2399 case INTERNET_OPTION_END_BROWSER_SESSION:
2400 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2402 case INTERNET_OPTION_CONNECTED_STATE:
2403 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2405 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2406 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2408 case INTERNET_OPTION_SEND_TIMEOUT:
2409 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2410 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2411 if (dwBufferLength == sizeof(DWORD))
2413 if (lpwhh->htype == WH_HHTTPREQ)
2414 ret = NETCON_set_timeout(
2415 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2416 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2417 *(DWORD *)lpBuffer);
2420 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2422 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2428 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2432 case INTERNET_OPTION_CONNECT_RETRIES:
2433 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2435 case INTERNET_OPTION_CONTEXT_VALUE:
2436 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2438 case INTERNET_OPTION_SECURITY_FLAGS:
2439 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2442 FIXME("Option %d STUB\n",dwOption);
2443 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2447 WININET_Release( lpwhh );
2453 /***********************************************************************
2454 * InternetSetOptionA (WININET.@)
2456 * Sets an options on the specified handle.
2463 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2464 LPVOID lpBuffer, DWORD dwBufferLength)
2472 case INTERNET_OPTION_PROXY:
2474 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2475 LPINTERNET_PROXY_INFOW piw;
2476 DWORD proxlen, prbylen;
2479 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2480 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2481 wlen = sizeof(*piw) + proxlen + prbylen;
2482 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2483 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2484 piw->dwAccessType = pi->dwAccessType;
2485 prox = (LPWSTR) &piw[1];
2486 prby = &prox[proxlen+1];
2487 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2488 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2489 piw->lpszProxy = prox;
2490 piw->lpszProxyBypass = prby;
2493 case INTERNET_OPTION_USER_AGENT:
2494 case INTERNET_OPTION_USERNAME:
2495 case INTERNET_OPTION_PASSWORD:
2496 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2498 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2499 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2504 wlen = dwBufferLength;
2507 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2509 if( lpBuffer != wbuffer )
2510 HeapFree( GetProcessHeap(), 0, wbuffer );
2516 /***********************************************************************
2517 * InternetSetOptionExA (WININET.@)
2519 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2520 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2522 FIXME("Flags %08x ignored\n", dwFlags);
2523 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2526 /***********************************************************************
2527 * InternetSetOptionExW (WININET.@)
2529 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2530 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2532 FIXME("Flags %08x ignored\n", dwFlags);
2533 if( dwFlags & ~ISO_VALID_FLAGS )
2535 SetLastError( ERROR_INVALID_PARAMETER );
2538 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2541 static const WCHAR WININET_wkday[7][4] =
2542 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2543 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2544 static const WCHAR WININET_month[12][4] =
2545 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2546 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2547 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2549 /***********************************************************************
2550 * InternetTimeFromSystemTimeA (WININET.@)
2552 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2555 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2557 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2559 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2560 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2565 /***********************************************************************
2566 * InternetTimeFromSystemTimeW (WININET.@)
2568 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2570 static const WCHAR date[] =
2571 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2572 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2574 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2576 if (!time || !string) return FALSE;
2578 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2581 sprintfW( string, date,
2582 WININET_wkday[time->wDayOfWeek],
2584 WININET_month[time->wMonth - 1],
2593 /***********************************************************************
2594 * InternetTimeToSystemTimeA (WININET.@)
2596 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2602 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2604 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2605 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2609 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2610 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2611 HeapFree( GetProcessHeap(), 0, stringW );
2616 /***********************************************************************
2617 * InternetTimeToSystemTimeW (WININET.@)
2619 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2622 WCHAR *s = (LPWSTR)string;
2624 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2626 if (!string || !time) return FALSE;
2628 /* Windows does this too */
2629 GetSystemTime( time );
2631 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2632 * a SYSTEMTIME structure.
2635 while (*s && !isalphaW( *s )) s++;
2636 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2637 time->wDayOfWeek = 7;
2639 for (i = 0; i < 7; i++)
2641 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2642 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2643 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2645 time->wDayOfWeek = i;
2650 if (time->wDayOfWeek > 6) return TRUE;
2651 while (*s && !isdigitW( *s )) s++;
2652 time->wDay = strtolW( s, &s, 10 );
2654 while (*s && !isalphaW( *s )) s++;
2655 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2658 for (i = 0; i < 12; i++)
2660 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2661 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2662 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2664 time->wMonth = i + 1;
2668 if (time->wMonth == 0) return TRUE;
2670 while (*s && !isdigitW( *s )) s++;
2671 if (*s == '\0') return TRUE;
2672 time->wYear = strtolW( s, &s, 10 );
2674 while (*s && !isdigitW( *s )) s++;
2675 if (*s == '\0') return TRUE;
2676 time->wHour = strtolW( s, &s, 10 );
2678 while (*s && !isdigitW( *s )) s++;
2679 if (*s == '\0') return TRUE;
2680 time->wMinute = strtolW( s, &s, 10 );
2682 while (*s && !isdigitW( *s )) s++;
2683 if (*s == '\0') return TRUE;
2684 time->wSecond = strtolW( s, &s, 10 );
2686 time->wMilliseconds = 0;
2690 /***********************************************************************
2691 * InternetCheckConnectionW (WININET.@)
2693 * Pings a requested host to check internet connection
2696 * TRUE on success and FALSE on failure. If a failure then
2697 * ERROR_NOT_CONNECTED is placed into GetLastError
2700 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2703 * this is a kludge which runs the resident ping program and reads the output.
2705 * Anyone have a better idea?
2709 static const CHAR ping[] = "ping -w 1 ";
2710 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2711 CHAR *command = NULL;
2719 * Crack or set the Address
2721 if (lpszUrl == NULL)
2724 * According to the doc we are supost to use the ip for the next
2725 * server in the WnInet internal server database. I have
2726 * no idea what that is or how to get it.
2728 * So someone needs to implement this.
2730 FIXME("Unimplemented with URL of NULL\n");
2735 URL_COMPONENTSW components;
2737 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2738 components.lpszHostName = (LPWSTR)&hostW;
2739 components.dwHostNameLength = 1024;
2741 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2744 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2748 * Build our ping command
2750 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2751 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2752 strcpy(command,ping);
2753 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2754 strcat(command,redirect);
2756 TRACE("Ping command is : %s\n",command);
2758 status = system(command);
2760 TRACE("Ping returned a code of %i\n",status);
2762 /* Ping return code of 0 indicates success */
2768 HeapFree( GetProcessHeap(), 0, command );
2770 SetLastError(ERROR_NOT_CONNECTED);
2776 /***********************************************************************
2777 * InternetCheckConnectionA (WININET.@)
2779 * Pings a requested host to check internet connection
2782 * TRUE on success and FALSE on failure. If a failure then
2783 * ERROR_NOT_CONNECTED is placed into GetLastError
2786 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2792 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2793 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2795 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2796 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2797 HeapFree(GetProcessHeap(), 0, szUrl);
2803 /**********************************************************
2804 * INTERNET_InternetOpenUrlW (internal)
2809 * handle of connection or NULL on failure
2811 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2812 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2814 URL_COMPONENTSW urlComponents;
2815 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2816 WCHAR password[1024], path[2048], extra[1024];
2817 HINTERNET client = NULL, client1 = NULL;
2819 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2820 dwHeadersLength, dwFlags, dwContext);
2822 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2823 urlComponents.lpszScheme = protocol;
2824 urlComponents.dwSchemeLength = 32;
2825 urlComponents.lpszHostName = hostName;
2826 urlComponents.dwHostNameLength = MAXHOSTNAME;
2827 urlComponents.lpszUserName = userName;
2828 urlComponents.dwUserNameLength = 1024;
2829 urlComponents.lpszPassword = password;
2830 urlComponents.dwPasswordLength = 1024;
2831 urlComponents.lpszUrlPath = path;
2832 urlComponents.dwUrlPathLength = 2048;
2833 urlComponents.lpszExtraInfo = extra;
2834 urlComponents.dwExtraInfoLength = 1024;
2835 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2837 switch(urlComponents.nScheme) {
2838 case INTERNET_SCHEME_FTP:
2839 if(urlComponents.nPort == 0)
2840 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2841 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2842 userName, password, dwFlags, dwContext, INET_OPENURL);
2845 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2846 if(client1 == NULL) {
2847 InternetCloseHandle(client);
2852 case INTERNET_SCHEME_HTTP:
2853 case INTERNET_SCHEME_HTTPS: {
2854 static const WCHAR szStars[] = { '*','/','*', 0 };
2855 LPCWSTR accept[2] = { szStars, NULL };
2856 if(urlComponents.nPort == 0) {
2857 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2858 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2860 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2862 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2863 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2864 userName, password, dwFlags, dwContext, INET_OPENURL);
2867 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2868 if(client1 == NULL) {
2869 InternetCloseHandle(client);
2872 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2873 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2874 GetLastError() != ERROR_IO_PENDING) {
2875 InternetCloseHandle(client1);
2880 case INTERNET_SCHEME_GOPHER:
2881 /* gopher doesn't seem to be implemented in wine, but it's supposed
2882 * to be supported by InternetOpenUrlA. */
2884 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2888 TRACE(" %p <--\n", client1);
2893 /**********************************************************
2894 * InternetOpenUrlW (WININET.@)
2899 * handle of connection or NULL on failure
2901 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2902 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2904 HINTERNET ret = NULL;
2905 LPWININETAPPINFOW hIC = NULL;
2907 if (TRACE_ON(wininet)) {
2908 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2909 dwHeadersLength, dwFlags, dwContext);
2911 dump_INTERNET_FLAGS(dwFlags);
2916 SetLastError(ERROR_INVALID_PARAMETER);
2920 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2921 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2922 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2926 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2927 WORKREQUEST workRequest;
2928 struct WORKREQ_INTERNETOPENURLW *req;
2930 workRequest.asyncall = INTERNETOPENURLW;
2931 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2932 req = &workRequest.u.InternetOpenUrlW;
2933 req->lpszUrl = WININET_strdupW(lpszUrl);
2935 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2937 req->lpszHeaders = 0;
2938 req->dwHeadersLength = dwHeadersLength;
2939 req->dwFlags = dwFlags;
2940 req->dwContext = dwContext;
2942 INTERNET_AsyncCall(&workRequest);
2944 * This is from windows.
2946 SetLastError(ERROR_IO_PENDING);
2948 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2953 WININET_Release( &hIC->hdr );
2954 TRACE(" %p <--\n", ret);
2959 /**********************************************************
2960 * InternetOpenUrlA (WININET.@)
2965 * handle of connection or NULL on failure
2967 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2968 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2970 HINTERNET rc = (HINTERNET)NULL;
2974 LPWSTR szUrl = NULL;
2975 LPWSTR szHeaders = NULL;
2980 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2981 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2983 return (HINTERNET)NULL;
2984 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2988 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
2989 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
2991 HeapFree(GetProcessHeap(), 0, szUrl);
2992 return (HINTERNET)NULL;
2994 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
2997 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
2998 lenHeaders, dwFlags, dwContext);
3000 HeapFree(GetProcessHeap(), 0, szUrl);
3001 HeapFree(GetProcessHeap(), 0, szHeaders);
3007 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3009 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3013 lpwite->dwError = 0;
3014 lpwite->response[0] = '\0';
3017 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3019 HeapFree(GetProcessHeap(), 0, lpwite);
3027 /***********************************************************************
3028 * INTERNET_SetLastError (internal)
3030 * Set last thread specific error
3035 void INTERNET_SetLastError(DWORD dwError)
3037 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3040 lpwite = INTERNET_AllocThreadError();
3042 SetLastError(dwError);
3044 lpwite->dwError = dwError;
3048 /***********************************************************************
3049 * INTERNET_GetLastError (internal)
3051 * Get last thread specific error
3056 DWORD INTERNET_GetLastError(void)
3058 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3059 if (!lpwite) return 0;
3060 /* TlsGetValue clears last error, so set it again here */
3061 SetLastError(lpwite->dwError);
3062 return lpwite->dwError;
3066 /***********************************************************************
3067 * INTERNET_WorkerThreadFunc (internal)
3069 * Worker thread execution function
3074 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3081 INTERNET_ExecuteWork();
3084 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
3086 if (dwWaitRes == WAIT_OBJECT_0 + 1)
3087 INTERNET_ExecuteWork();
3091 InterlockedIncrement(&dwNumIdleThreads);
3094 InterlockedDecrement(&dwNumIdleThreads);
3095 InterlockedDecrement(&dwNumThreads);
3096 TRACE("Worker thread exiting\n");
3101 /***********************************************************************
3102 * INTERNET_InsertWorkRequest (internal)
3104 * Insert work request into queue
3109 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
3111 BOOL bSuccess = FALSE;
3112 LPWORKREQUEST lpNewRequest;
3116 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3119 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3120 lpNewRequest->prev = NULL;
3122 EnterCriticalSection(&csQueue);
3124 lpNewRequest->next = lpWorkQueueTail;
3125 if (lpWorkQueueTail)
3126 lpWorkQueueTail->prev = lpNewRequest;
3127 lpWorkQueueTail = lpNewRequest;
3128 if (!lpHeadWorkQueue)
3129 lpHeadWorkQueue = lpWorkQueueTail;
3131 LeaveCriticalSection(&csQueue);
3134 InterlockedIncrement(&dwNumJobs);
3141 /***********************************************************************
3142 * INTERNET_GetWorkRequest (internal)
3144 * Retrieves work request from queue
3149 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
3151 BOOL bSuccess = FALSE;
3152 LPWORKREQUEST lpRequest = NULL;
3156 EnterCriticalSection(&csQueue);
3158 if (lpHeadWorkQueue)
3160 lpRequest = lpHeadWorkQueue;
3161 lpHeadWorkQueue = lpHeadWorkQueue->prev;
3162 if (lpRequest == lpWorkQueueTail)
3163 lpWorkQueueTail = lpHeadWorkQueue;
3166 LeaveCriticalSection(&csQueue);
3170 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
3171 HeapFree(GetProcessHeap(), 0, lpRequest);
3173 InterlockedDecrement(&dwNumJobs);
3180 /***********************************************************************
3181 * INTERNET_AsyncCall (internal)
3183 * Retrieves work request from queue
3188 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3192 BOOL bSuccess = FALSE;
3196 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
3198 InterlockedIncrement(&dwNumIdleThreads);
3200 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
3201 !(hThread = CreateThread(NULL, 0,
3202 INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
3204 InterlockedDecrement(&dwNumThreads);
3205 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3209 TRACE("Created new thread\n");
3213 INTERNET_InsertWorkRequest(lpWorkRequest);
3214 SetEvent(hWorkEvent);
3222 /***********************************************************************
3223 * INTERNET_ExecuteWork (internal)
3228 static VOID INTERNET_ExecuteWork(void)
3230 WORKREQUEST workRequest;
3234 if (!INTERNET_GetWorkRequest(&workRequest))
3237 switch (workRequest.asyncall)
3241 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
3242 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3244 TRACE("FTPPUTFILEW %p\n", lpwfs);
3246 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
3247 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
3249 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
3250 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
3254 case FTPSETCURRENTDIRECTORYW:
3256 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
3257 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3259 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
3261 req = &workRequest.u.FtpSetCurrentDirectoryW;
3262 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
3263 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3267 case FTPCREATEDIRECTORYW:
3269 struct WORKREQ_FTPCREATEDIRECTORYW *req;
3270 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3272 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
3274 req = &workRequest.u.FtpCreateDirectoryW;
3275 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
3276 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3280 case FTPFINDFIRSTFILEW:
3282 struct WORKREQ_FTPFINDFIRSTFILEW *req;
3283 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3285 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
3287 req = &workRequest.u.FtpFindFirstFileW;
3288 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
3289 req->lpFindFileData, req->dwFlags, req->dwContext);
3290 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
3294 case FTPGETCURRENTDIRECTORYW:
3296 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
3297 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3299 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
3301 req = &workRequest.u.FtpGetCurrentDirectoryW;
3302 FTP_FtpGetCurrentDirectoryW(lpwfs,
3303 req->lpszDirectory, req->lpdwDirectory);
3309 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
3310 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3312 TRACE("FTPOPENFILEW %p\n", lpwfs);
3314 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
3315 req->dwAccess, req->dwFlags, req->dwContext);
3316 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3322 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
3323 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3325 TRACE("FTPGETFILEW %p\n", lpwfs);
3327 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
3328 req->lpszNewFile, req->fFailIfExists,
3329 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
3330 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
3331 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
3335 case FTPDELETEFILEW:
3337 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
3338 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3340 TRACE("FTPDELETEFILEW %p\n", lpwfs);
3342 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
3343 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3347 case FTPREMOVEDIRECTORYW:
3349 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
3350 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3352 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
3354 req = &workRequest.u.FtpRemoveDirectoryW;
3355 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
3356 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3360 case FTPRENAMEFILEW:
3362 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
3363 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3365 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
3367 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
3368 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
3369 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
3375 struct WORKREQ_FTPFINDNEXTW *req;
3376 LPWININETFTPFINDNEXTW lpwh = (LPWININETFTPFINDNEXTW) workRequest.hdr;
3378 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
3380 req = &workRequest.u.FtpFindNextW;
3381 FTP_FindNextFileW(lpwh, req->lpFindFileData);
3385 case HTTPSENDREQUESTW:
3387 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
3388 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
3390 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
3392 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
3393 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength,
3394 req->dwContentLength, req->bEndRequest);
3396 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
3400 case HTTPOPENREQUESTW:
3402 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
3403 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
3405 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
3407 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
3408 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
3409 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
3411 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
3412 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
3413 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
3414 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
3420 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
3422 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
3424 INTERNET_SendCallback(workRequest.hdr,
3425 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
3426 req->dwStatusInfoLength);
3428 /* And frees the copy of the status info */
3429 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
3433 case INTERNETOPENURLW:
3435 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
3436 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
3438 TRACE("INTERNETOPENURLW %p\n", hIC);
3440 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3441 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3442 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3443 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3446 case INTERNETREADFILEEXA:
3448 struct WORKREQ_INTERNETREADFILEEXA *req = &workRequest.u.InternetReadFileExA;
3450 TRACE("INTERNETREADFILEEXA %p\n", workRequest.hdr);
3452 INTERNET_ReadFile(workRequest.hdr, req->lpBuffersOut->lpvBuffer,
3453 req->lpBuffersOut->dwBufferLength,
3454 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
3458 WININET_Release( workRequest.hdr );
3462 /***********************************************************************
3463 * INTERNET_GetResponseBuffer (internal)
3468 LPSTR INTERNET_GetResponseBuffer(void)
3470 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3472 lpwite = INTERNET_AllocThreadError();
3474 return lpwite->response;
3477 /***********************************************************************
3478 * INTERNET_GetNextLine (internal)
3480 * Parse next line in directory string listing
3483 * Pointer to beginning of next line
3488 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3492 BOOL bSuccess = FALSE;
3494 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3499 FD_SET(nSocket, &infd);
3500 tv.tv_sec=RESPONSE_TIMEOUT;
3503 while (nRecv < MAX_REPLY_LEN)
3505 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3507 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3509 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3513 if (lpszBuffer[nRecv] == '\n')
3518 if (lpszBuffer[nRecv] != '\r')
3523 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3531 lpszBuffer[nRecv] = '\0';
3533 TRACE(":%d %s\n", nRecv, lpszBuffer);
3542 /**********************************************************
3543 * InternetQueryDataAvailable (WININET.@)
3545 * Determines how much data is available to be read.
3548 * If there is data available then TRUE, otherwise if there
3549 * is not or an error occurred then FALSE. Use GetLastError() to
3550 * check for ERROR_NO_MORE_FILES to see if it was the former.
3552 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3553 LPDWORD lpdwNumberOfBytesAvailble,
3554 DWORD dwFlags, DWORD dwConext)
3556 LPWININETHTTPREQW lpwhr;
3557 BOOL retval = FALSE;
3560 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3563 SetLastError(ERROR_NO_MORE_FILES);
3567 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3569 switch (lpwhr->hdr.htype)
3572 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3573 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3575 SetLastError(ERROR_NO_MORE_FILES);
3583 FIXME("unsupported file type\n");
3586 WININET_Release( &lpwhr->hdr );
3588 TRACE("<-- %i\n",retval);
3593 /***********************************************************************
3594 * InternetLockRequestFile (WININET.@)
3596 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3603 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3610 /***********************************************************************
3611 * InternetAutodial (WININET.@)
3613 * On windows this function is supposed to dial the default internet
3614 * connection. We don't want to have Wine dial out to the internet so
3615 * we return TRUE by default. It might be nice to check if we are connected.
3622 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3626 /* Tell that we are connected to the internet. */
3630 /***********************************************************************
3631 * InternetAutodialHangup (WININET.@)
3633 * Hangs up a connection made with InternetAutodial
3642 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3646 /* we didn't dial, we don't disconnect */
3650 /***********************************************************************
3651 * InternetCombineUrlA (WININET.@)
3653 * Combine a base URL with a relative URL
3661 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3662 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3667 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3669 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3670 dwFlags ^= ICU_NO_ENCODE;
3671 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3676 /***********************************************************************
3677 * InternetCombineUrlW (WININET.@)
3679 * Combine a base URL with a relative URL
3687 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3688 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3693 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3695 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3696 dwFlags ^= ICU_NO_ENCODE;
3697 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3702 /* max port num is 65535 => 5 digits */
3703 #define MAX_WORD_DIGITS 5
3705 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3706 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3707 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3708 (url)->dw##component##Length : strlen((url)->lpsz##component))
3710 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3712 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3713 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3715 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3716 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3718 if ((nScheme == INTERNET_SCHEME_FTP) &&
3719 (nPort == INTERNET_DEFAULT_FTP_PORT))
3721 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3722 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3725 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3731 /* opaque urls do not fit into the standard url hierarchy and don't have
3732 * two following slashes */
3733 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3735 return (nScheme != INTERNET_SCHEME_FTP) &&
3736 (nScheme != INTERNET_SCHEME_GOPHER) &&
3737 (nScheme != INTERNET_SCHEME_HTTP) &&
3738 (nScheme != INTERNET_SCHEME_HTTPS) &&
3739 (nScheme != INTERNET_SCHEME_FILE);
3742 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3745 if (scheme < INTERNET_SCHEME_FIRST)
3747 index = scheme - INTERNET_SCHEME_FIRST;
3748 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3750 return (LPCWSTR)&url_schemes[index];
3753 /* we can calculate using ansi strings because we're just
3754 * calculating string length, not size
3756 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3757 LPDWORD lpdwUrlLength)
3759 INTERNET_SCHEME nScheme;
3763 if (lpUrlComponents->lpszScheme)
3765 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3766 *lpdwUrlLength += dwLen;
3767 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3773 nScheme = lpUrlComponents->nScheme;
3775 if (nScheme == INTERNET_SCHEME_DEFAULT)
3776 nScheme = INTERNET_SCHEME_HTTP;
3777 scheme = INTERNET_GetSchemeString(nScheme);
3778 *lpdwUrlLength += strlenW(scheme);
3781 (*lpdwUrlLength)++; /* ':' */
3782 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3783 *lpdwUrlLength += strlen("//");
3785 if (lpUrlComponents->lpszUserName)
3787 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3788 *lpdwUrlLength += strlen("@");
3792 if (lpUrlComponents->lpszPassword)
3794 SetLastError(ERROR_INVALID_PARAMETER);
3799 if (lpUrlComponents->lpszPassword)
3801 *lpdwUrlLength += strlen(":");
3802 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3805 if (lpUrlComponents->lpszHostName)
3807 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3809 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3811 char szPort[MAX_WORD_DIGITS+1];
3813 sprintf(szPort, "%d", lpUrlComponents->nPort);
3814 *lpdwUrlLength += strlen(szPort);
3815 *lpdwUrlLength += strlen(":");
3818 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3819 (*lpdwUrlLength)++; /* '/' */
3822 if (lpUrlComponents->lpszUrlPath)
3823 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3828 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3832 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3834 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3835 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3836 urlCompW->nScheme = lpUrlComponents->nScheme;
3837 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3838 urlCompW->nPort = lpUrlComponents->nPort;
3839 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3840 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3841 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3842 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3844 if (lpUrlComponents->lpszScheme)
3846 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3847 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3848 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3849 -1, urlCompW->lpszScheme, len);
3852 if (lpUrlComponents->lpszHostName)
3854 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3855 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3856 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3857 -1, urlCompW->lpszHostName, len);
3860 if (lpUrlComponents->lpszUserName)
3862 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3863 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3864 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3865 -1, urlCompW->lpszUserName, len);
3868 if (lpUrlComponents->lpszPassword)
3870 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3871 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3872 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3873 -1, urlCompW->lpszPassword, len);
3876 if (lpUrlComponents->lpszUrlPath)
3878 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3879 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3880 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3881 -1, urlCompW->lpszUrlPath, len);
3884 if (lpUrlComponents->lpszExtraInfo)
3886 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3887 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3888 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3889 -1, urlCompW->lpszExtraInfo, len);
3893 /***********************************************************************
3894 * InternetCreateUrlA (WININET.@)
3896 * See InternetCreateUrlW.
3898 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3899 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3903 URL_COMPONENTSW urlCompW;
3905 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3907 if (!lpUrlComponents)
3910 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3912 SetLastError(ERROR_INVALID_PARAMETER);
3916 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3919 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3921 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3923 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3924 *lpdwUrlLength /= sizeof(WCHAR);
3926 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3927 * minus one, so add one to leave room for NULL terminator
3930 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3932 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3933 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3934 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3935 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3936 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3937 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3938 HeapFree(GetProcessHeap(), 0, urlW);
3943 /***********************************************************************
3944 * InternetCreateUrlW (WININET.@)
3946 * Creates a URL from its component parts.
3949 * lpUrlComponents [I] URL Components.
3950 * dwFlags [I] Flags. See notes.
3951 * lpszUrl [I] Buffer in which to store the created URL.
3952 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3953 * lpszUrl in characters. On output, the number of bytes
3954 * required to store the URL including terminator.
3958 * The dwFlags parameter can be zero or more of the following:
3959 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3966 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3967 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3970 INTERNET_SCHEME nScheme;
3972 static const WCHAR slashSlashW[] = {'/','/'};
3973 static const WCHAR percentD[] = {'%','d',0};
3975 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3977 if (!lpUrlComponents)
3980 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3982 SetLastError(ERROR_INVALID_PARAMETER);
3986 if (!calc_url_length(lpUrlComponents, &dwLen))
3989 if (!lpszUrl || *lpdwUrlLength < dwLen)
3991 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3992 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3996 *lpdwUrlLength = dwLen;
4001 if (lpUrlComponents->lpszScheme)
4003 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4004 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4007 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4012 nScheme = lpUrlComponents->nScheme;
4014 if (nScheme == INTERNET_SCHEME_DEFAULT)
4015 nScheme = INTERNET_SCHEME_HTTP;
4017 scheme = INTERNET_GetSchemeString(nScheme);
4018 dwLen = strlenW(scheme);
4019 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4023 /* all schemes are followed by at least a colon */
4027 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4029 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4030 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4033 if (lpUrlComponents->lpszUserName)
4035 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4036 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4039 if (lpUrlComponents->lpszPassword)
4044 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4045 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4053 if (lpUrlComponents->lpszHostName)
4055 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4056 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4059 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4061 WCHAR szPort[MAX_WORD_DIGITS+1];
4063 sprintfW(szPort, percentD, lpUrlComponents->nPort);
4066 dwLen = strlenW(szPort);
4067 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4071 /* add slash between hostname and path if necessary */
4072 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4080 if (lpUrlComponents->lpszUrlPath)
4082 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4083 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4092 /***********************************************************************
4093 * InternetConfirmZoneCrossingA (WININET.@)
4096 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4098 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4099 return ERROR_SUCCESS;
4102 /***********************************************************************
4103 * InternetConfirmZoneCrossingW (WININET.@)
4106 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4108 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4109 return ERROR_SUCCESS;
4112 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4113 LPDWORD lpdwConnection, DWORD dwReserved )
4115 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4116 lpdwConnection, dwReserved);
4117 return ERROR_SUCCESS;
4120 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4121 LPDWORD lpdwConnection, DWORD dwReserved )
4123 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
4124 lpdwConnection, dwReserved);
4125 return ERROR_SUCCESS;
4128 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4130 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4134 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4136 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4140 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
4142 FIXME("(0x%08x, 0x%08x) stub\n", dwConnection, dwReserved);
4143 return ERROR_SUCCESS;
4146 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4149 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4150 debugstr_w(pwszTarget), pbHexHash);
4154 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4156 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);