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 info->hInternet = (HINTERNET) (handle+1);
157 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
160 TRACE("%p -> refcount = %d\n", info, info->dwRefCount );
164 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
166 LPWININETHANDLEHEADER info = NULL;
167 UINT handle = (UINT) hinternet;
169 EnterCriticalSection( &WININET_cs );
171 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
172 WININET_Handles[handle-1] )
173 info = WININET_AddRef( WININET_Handles[handle-1] );
175 LeaveCriticalSection( &WININET_cs );
177 TRACE("handle %d -> %p\n", handle, info);
182 BOOL WININET_Release( LPWININETHANDLEHEADER info )
185 TRACE( "object %p refcount = %d\n", info, info->dwRefCount );
186 if( !info->dwRefCount )
188 TRACE( "destroying object %p\n", info);
189 info->destroy( info );
194 BOOL WININET_FreeHandle( HINTERNET hinternet )
197 UINT handle = (UINT) hinternet;
198 LPWININETHANDLEHEADER info = NULL;
200 EnterCriticalSection( &WININET_cs );
202 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
205 if( WININET_Handles[handle] )
207 info = WININET_Handles[handle];
208 TRACE( "destroying handle %d for object %p\n", handle+1, info);
209 WININET_Handles[handle] = NULL;
211 if( WININET_dwNextHandle > handle )
212 WININET_dwNextHandle = handle;
216 LeaveCriticalSection( &WININET_cs );
219 WININET_Release( info );
224 /***********************************************************************
225 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
228 * hinstDLL [I] handle to the DLL's instance
230 * lpvReserved [I] reserved, must be NULL
237 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
239 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
242 case DLL_PROCESS_ATTACH:
244 g_dwTlsErrIndex = TlsAlloc();
246 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
249 hQuitEvent = CreateEventW(0, TRUE, FALSE, NULL);
250 hWorkEvent = CreateEventW(0, FALSE, FALSE, NULL);
251 InitializeCriticalSection(&csQueue);
253 URLCacheContainers_CreateDefaults();
256 dwNumIdleThreads = 0;
259 WININET_hModule = (HMODULE)hinstDLL;
261 case DLL_THREAD_ATTACH:
264 case DLL_THREAD_DETACH:
265 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
267 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
268 HeapFree(GetProcessHeap(), 0, lpwite);
272 case DLL_PROCESS_DETACH:
274 URLCacheContainers_DeleteAll();
276 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
278 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
279 TlsFree(g_dwTlsErrIndex);
282 SetEvent(hQuitEvent);
284 CloseHandle(hQuitEvent);
285 CloseHandle(hWorkEvent);
286 DeleteCriticalSection(&csQueue);
294 /***********************************************************************
295 * InternetInitializeAutoProxyDll (WININET.@)
297 * Setup the internal proxy
306 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
309 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
313 /***********************************************************************
314 * DetectAutoProxyUrl (WININET.@)
316 * Auto detect the proxy url
322 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
323 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
326 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
331 /***********************************************************************
332 * INTERNET_ConfigureProxyFromReg
335 * The proxy may be specified in the form 'http=proxy.my.org'
336 * Presumably that means there can be ftp=ftpproxy.my.org too.
338 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
341 DWORD r, keytype, len, enabled;
342 LPCSTR lpszInternetSettings =
343 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
344 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
346 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
347 if ( r != ERROR_SUCCESS )
350 len = sizeof enabled;
351 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
352 (BYTE*)&enabled, &len);
353 if( (r == ERROR_SUCCESS) && enabled )
355 TRACE("Proxy is enabled.\n");
357 /* figure out how much memory the proxy setting takes */
358 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
360 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
363 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
365 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
366 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
367 (BYTE*)szProxy, &len);
369 /* find the http proxy, and strip away everything else */
370 p = strstrW( szProxy, szHttp );
373 p += lstrlenW(szHttp);
374 lstrcpyW( szProxy, p );
376 p = strchrW( szProxy, ' ' );
380 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
381 lpwai->lpszProxy = szProxy;
383 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
386 ERR("Couldn't read proxy server settings.\n");
389 TRACE("Proxy is not enabled.\n");
395 /***********************************************************************
396 * dump_INTERNET_FLAGS
398 * Helper function to TRACE the internet flags.
404 static void dump_INTERNET_FLAGS(DWORD dwFlags)
406 #define FE(x) { x, #x }
407 static const wininet_flag_info flag[] = {
408 FE(INTERNET_FLAG_RELOAD),
409 FE(INTERNET_FLAG_RAW_DATA),
410 FE(INTERNET_FLAG_EXISTING_CONNECT),
411 FE(INTERNET_FLAG_ASYNC),
412 FE(INTERNET_FLAG_PASSIVE),
413 FE(INTERNET_FLAG_NO_CACHE_WRITE),
414 FE(INTERNET_FLAG_MAKE_PERSISTENT),
415 FE(INTERNET_FLAG_FROM_CACHE),
416 FE(INTERNET_FLAG_SECURE),
417 FE(INTERNET_FLAG_KEEP_CONNECTION),
418 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
419 FE(INTERNET_FLAG_READ_PREFETCH),
420 FE(INTERNET_FLAG_NO_COOKIES),
421 FE(INTERNET_FLAG_NO_AUTH),
422 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
423 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
424 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
425 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
426 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
427 FE(INTERNET_FLAG_RESYNCHRONIZE),
428 FE(INTERNET_FLAG_HYPERLINK),
429 FE(INTERNET_FLAG_NO_UI),
430 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
431 FE(INTERNET_FLAG_CACHE_ASYNC),
432 FE(INTERNET_FLAG_FORMS_SUBMIT),
433 FE(INTERNET_FLAG_NEED_FILE),
434 FE(INTERNET_FLAG_TRANSFER_ASCII),
435 FE(INTERNET_FLAG_TRANSFER_BINARY)
440 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
441 if (flag[i].val & dwFlags) {
442 TRACE(" %s", flag[i].name);
443 dwFlags &= ~flag[i].val;
447 TRACE(" Unknown flags (%08x)\n", dwFlags);
452 /***********************************************************************
453 * InternetOpenW (WININET.@)
455 * Per-application initialization of wininet
458 * HINTERNET on success
462 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
463 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
465 LPWININETAPPINFOW lpwai = NULL;
466 HINTERNET handle = NULL;
468 if (TRACE_ON(wininet)) {
469 #define FE(x) { x, #x }
470 static const wininet_flag_info access_type[] = {
471 FE(INTERNET_OPEN_TYPE_PRECONFIG),
472 FE(INTERNET_OPEN_TYPE_DIRECT),
473 FE(INTERNET_OPEN_TYPE_PROXY),
474 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
478 const char *access_type_str = "Unknown";
480 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
481 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
482 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
483 if (access_type[i].val == dwAccessType) {
484 access_type_str = access_type[i].name;
488 TRACE(" access type : %s\n", access_type_str);
490 dump_INTERNET_FLAGS(dwFlags);
493 /* Clear any error information */
494 INTERNET_SetLastError(0);
496 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW));
499 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
503 memset(lpwai, 0, sizeof(WININETAPPINFOW));
504 lpwai->hdr.htype = WH_HINIT;
505 lpwai->hdr.dwFlags = dwFlags;
506 lpwai->hdr.dwRefCount = 1;
507 lpwai->hdr.destroy = INTERNET_CloseHandle;
508 lpwai->dwAccessType = dwAccessType;
509 lpwai->lpszProxyUsername = NULL;
510 lpwai->lpszProxyPassword = NULL;
512 handle = WININET_AllocHandle( &lpwai->hdr );
515 HeapFree( GetProcessHeap(), 0, lpwai );
516 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
520 if (NULL != lpszAgent)
522 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
523 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
524 if (lpwai->lpszAgent)
525 lstrcpyW( lpwai->lpszAgent, lpszAgent );
527 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
528 INTERNET_ConfigureProxyFromReg( lpwai );
529 else if (NULL != lpszProxy)
531 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
532 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
533 if (lpwai->lpszProxy)
534 lstrcpyW( lpwai->lpszProxy, lpszProxy );
537 if (NULL != lpszProxyBypass)
539 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
540 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
541 if (lpwai->lpszProxyBypass)
542 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
547 WININET_Release( &lpwai->hdr );
549 TRACE("returning %p\n", lpwai);
555 /***********************************************************************
556 * InternetOpenA (WININET.@)
558 * Per-application initialization of wininet
561 * HINTERNET on success
565 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
566 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
568 HINTERNET rc = (HINTERNET)NULL;
570 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
572 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
573 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
577 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
578 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
579 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
584 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
585 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
586 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
589 if( lpszProxyBypass )
591 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
592 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
593 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
596 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
598 HeapFree(GetProcessHeap(), 0, szAgent);
599 HeapFree(GetProcessHeap(), 0, szProxy);
600 HeapFree(GetProcessHeap(), 0, szBypass);
605 /***********************************************************************
606 * InternetGetLastResponseInfoA (WININET.@)
608 * Return last wininet error description on the calling thread
611 * TRUE on success of writing to buffer
615 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
616 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
618 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
624 *lpdwError = lpwite->dwError;
627 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
628 *lpdwBufferLength = strlen(lpszBuffer);
631 *lpdwBufferLength = 0;
636 *lpdwBufferLength = 0;
642 /***********************************************************************
643 * InternetGetLastResponseInfoW (WININET.@)
645 * Return last wininet error description on the calling thread
648 * TRUE on success of writing to buffer
652 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
653 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
655 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
661 *lpdwError = lpwite->dwError;
664 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
665 *lpdwBufferLength = lstrlenW(lpszBuffer);
668 *lpdwBufferLength = 0;
673 *lpdwBufferLength = 0;
679 /***********************************************************************
680 * InternetGetConnectedState (WININET.@)
682 * Return connected state
686 * if lpdwStatus is not null, return the status (off line,
687 * modem, lan...) in it.
688 * FALSE if not connected
690 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
692 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
695 FIXME("always returning LAN connection.\n");
696 *lpdwStatus = INTERNET_CONNECTION_LAN;
702 /***********************************************************************
703 * InternetGetConnectedStateExW (WININET.@)
705 * Return connected state
709 * lpdwStatus [O] Flags specifying the status of the internet connection.
710 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
711 * dwNameLen [I] Size of the buffer, in characters.
712 * dwReserved [I] Reserved. Must be set to 0.
716 * if lpdwStatus is not null, return the status (off line,
717 * modem, lan...) in it.
718 * FALSE if not connected
721 * If the system has no available network connections, an empty string is
722 * stored in lpszConnectionName. If there is a LAN connection, a localized
723 * "LAN Connection" string is stored. Presumably, if only a dial-up
724 * connection is available then the name of the dial-up connection is
725 * returned. Why any application, other than the "Internet Settings" CPL,
726 * would want to use this function instead of the simpler InternetGetConnectedStateW
727 * function is beyond me.
729 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
730 DWORD dwNameLen, DWORD dwReserved)
732 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
739 FIXME("always returning LAN connection.\n");
740 *lpdwStatus = INTERNET_CONNECTION_LAN;
742 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
746 /***********************************************************************
747 * InternetGetConnectedStateExA (WININET.@)
749 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
750 DWORD dwNameLen, DWORD dwReserved)
752 LPWSTR lpwszConnectionName = NULL;
755 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
757 if (lpszConnectionName && dwNameLen > 0)
758 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
760 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
762 if (rc && lpwszConnectionName)
764 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
765 dwNameLen, NULL, NULL);
767 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
774 /***********************************************************************
775 * InternetConnectW (WININET.@)
777 * Open a ftp, gopher or http session
780 * HINTERNET a session handle on success
784 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
785 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
786 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
787 DWORD dwService, DWORD dwFlags, DWORD dwContext)
789 LPWININETAPPINFOW hIC;
792 TRACE("(%p, %s, %i, %s, %s, %i, %i, %i)\n", hInternet, debugstr_w(lpszServerName),
793 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
794 dwService, dwFlags, dwContext);
798 SetLastError(ERROR_INVALID_PARAMETER);
802 /* Clear any error information */
803 INTERNET_SetLastError(0);
804 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
805 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
807 SetLastError(ERROR_INVALID_HANDLE);
813 case INTERNET_SERVICE_FTP:
814 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
815 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
818 case INTERNET_SERVICE_HTTP:
819 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
820 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
823 case INTERNET_SERVICE_GOPHER:
829 WININET_Release( &hIC->hdr );
831 TRACE("returning %p\n", rc);
836 /***********************************************************************
837 * InternetConnectA (WININET.@)
839 * Open a ftp, gopher or http session
842 * HINTERNET a session handle on success
846 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
847 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
848 LPCSTR lpszUserName, LPCSTR lpszPassword,
849 DWORD dwService, DWORD dwFlags, DWORD dwContext)
851 HINTERNET rc = (HINTERNET)NULL;
853 LPWSTR szServerName = NULL;
854 LPWSTR szUserName = NULL;
855 LPWSTR szPassword = NULL;
859 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
860 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
861 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
865 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
866 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
867 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
871 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
872 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
873 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
877 rc = InternetConnectW(hInternet, szServerName, nServerPort,
878 szUserName, szPassword, dwService, dwFlags, dwContext);
880 HeapFree(GetProcessHeap(), 0, szServerName);
881 HeapFree(GetProcessHeap(), 0, szUserName);
882 HeapFree(GetProcessHeap(), 0, szPassword);
887 /***********************************************************************
888 * InternetFindNextFileA (WININET.@)
890 * Continues a file search from a previous call to FindFirstFile
897 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
902 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
904 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
908 /***********************************************************************
909 * InternetFindNextFileW (WININET.@)
911 * Continues a file search from a previous call to FindFirstFile
918 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
920 LPWININETAPPINFOW hIC = NULL;
921 LPWININETFTPFINDNEXTW lpwh;
922 BOOL bSuccess = FALSE;
926 lpwh = (LPWININETFTPFINDNEXTW) WININET_GetObject( hFind );
927 if (NULL == lpwh || lpwh->hdr.htype != WH_HFTPFINDNEXT)
929 FIXME("Only FTP supported\n");
930 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
934 hIC = lpwh->lpFtpSession->lpAppInfo;
935 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
937 WORKREQUEST workRequest;
938 struct WORKREQ_FTPFINDNEXTW *req;
940 workRequest.asyncall = FTPFINDNEXTW;
941 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
942 req = &workRequest.u.FtpFindNextW;
943 req->lpFindFileData = lpvFindData;
945 bSuccess = INTERNET_AsyncCall(&workRequest);
949 bSuccess = FTP_FindNextFileW(lpwh, lpvFindData);
953 WININET_Release( &lpwh->hdr );
957 /***********************************************************************
958 * INTERNET_CloseHandle (internal)
960 * Close internet handle
966 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
968 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
972 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
973 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
974 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
975 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
976 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
977 HeapFree(GetProcessHeap(), 0, lpwai);
981 /***********************************************************************
982 * InternetCloseHandle (WININET.@)
984 * Generic close handle function
991 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
993 LPWININETHANDLEHEADER lpwh;
995 TRACE("%p\n",hInternet);
997 lpwh = WININET_GetObject( hInternet );
1000 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1004 /* FIXME: native appears to send this from the equivalent of
1005 * WININET_Release */
1006 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1007 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
1010 WININET_FreeHandle( hInternet );
1011 WININET_Release( lpwh );
1017 /***********************************************************************
1018 * ConvertUrlComponentValue (Internal)
1020 * Helper function for InternetCrackUrlW
1023 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1024 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1025 LPCSTR lpszStart, LPCWSTR lpwszStart)
1027 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1028 if (*dwComponentLen != 0)
1030 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1031 if (*lppszComponent == NULL)
1033 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1035 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1037 *lppszComponent = NULL;
1038 *dwComponentLen = nASCIILength;
1042 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1043 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1044 (*lppszComponent)[ncpylen]=0;
1045 *dwComponentLen = ncpylen;
1051 /***********************************************************************
1052 * InternetCrackUrlA (WININET.@)
1054 * See InternetCrackUrlW.
1056 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1057 LPURL_COMPONENTSA lpUrlComponents)
1060 URL_COMPONENTSW UCW;
1063 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1066 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1068 /* if dwUrlLength=-1 then nLength includes null but length to
1069 InternetCrackUrlW should not include it */
1070 if (dwUrlLength == -1) nLength--;
1072 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1073 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1075 memset(&UCW,0,sizeof(UCW));
1076 if(lpUrlComponents->dwHostNameLength!=0)
1077 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1078 if(lpUrlComponents->dwUserNameLength!=0)
1079 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1080 if(lpUrlComponents->dwPasswordLength!=0)
1081 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1082 if(lpUrlComponents->dwUrlPathLength!=0)
1083 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1084 if(lpUrlComponents->dwSchemeLength!=0)
1085 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1086 if(lpUrlComponents->dwExtraInfoLength!=0)
1087 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1088 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1090 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1094 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1095 UCW.lpszHostName, UCW.dwHostNameLength,
1097 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1098 UCW.lpszUserName, UCW.dwUserNameLength,
1100 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1101 UCW.lpszPassword, UCW.dwPasswordLength,
1103 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1104 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1106 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1107 UCW.lpszScheme, UCW.dwSchemeLength,
1109 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1110 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1112 lpUrlComponents->nScheme=UCW.nScheme;
1113 lpUrlComponents->nPort=UCW.nPort;
1114 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1116 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1117 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1118 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1119 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1120 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1125 static const WCHAR url_schemes[][7] =
1128 {'g','o','p','h','e','r',0},
1129 {'h','t','t','p',0},
1130 {'h','t','t','p','s',0},
1131 {'f','i','l','e',0},
1132 {'n','e','w','s',0},
1133 {'m','a','i','l','t','o',0},
1137 /***********************************************************************
1138 * GetInternetSchemeW (internal)
1144 * INTERNET_SCHEME_UNKNOWN on failure
1147 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1151 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1153 if(lpszScheme==NULL)
1154 return INTERNET_SCHEME_UNKNOWN;
1156 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1157 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1158 return INTERNET_SCHEME_FIRST + i;
1160 return INTERNET_SCHEME_UNKNOWN;
1163 /***********************************************************************
1164 * SetUrlComponentValueW (Internal)
1166 * Helper function for InternetCrackUrlW
1169 * lppszComponent [O] Holds the returned string
1170 * dwComponentLen [I] Holds the size of lppszComponent
1171 * [O] Holds the length of the string in lppszComponent without '\0'
1172 * lpszStart [I] Holds the string to copy from
1173 * len [I] Holds the length of lpszStart without '\0'
1180 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1182 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1184 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1187 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1189 if (*lppszComponent == NULL)
1191 *lppszComponent = (LPWSTR)lpszStart;
1192 *dwComponentLen = len;
1196 DWORD ncpylen = min((*dwComponentLen)-1, len);
1197 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1198 (*lppszComponent)[ncpylen] = '\0';
1199 *dwComponentLen = ncpylen;
1206 /***********************************************************************
1207 * InternetCrackUrlW (WININET.@)
1209 * Break up URL into its components
1215 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1216 LPURL_COMPONENTSW lpUC)
1220 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1223 LPCWSTR lpszParam = NULL;
1224 BOOL bIsAbsolute = FALSE;
1225 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1226 LPCWSTR lpszcp = NULL;
1227 LPWSTR lpszUrl_decode = NULL;
1228 DWORD dwUrlLength = dwUrlLength_orig;
1229 const WCHAR lpszSeparators[3]={';','?',0};
1230 const WCHAR lpszSlash[2]={'/',0};
1232 dwUrlLength=strlenW(lpszUrl);
1234 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1236 if (!lpszUrl_orig || !*lpszUrl_orig)
1238 SetLastError(ERROR_INVALID_PARAMETER);
1242 if (dwFlags & ICU_DECODE)
1244 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1245 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1247 lpszUrl = lpszUrl_decode;
1252 /* Determine if the URI is absolute. */
1253 while (*lpszap != '\0')
1255 if (isalnumW(*lpszap))
1260 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1267 lpszcp = lpszUrl; /* Relative url */
1273 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1274 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1276 /* Parse <params> */
1277 lpszParam = strpbrkW(lpszap, lpszSeparators);
1278 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1279 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1281 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1285 /* Get scheme first. */
1286 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1287 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1288 lpszUrl, lpszcp - lpszUrl);
1290 /* Eat ':' in protocol. */
1293 /* double slash indicates the net_loc portion is present */
1294 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1298 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1302 lpszNetLoc = min(lpszNetLoc, lpszParam);
1304 lpszNetLoc = lpszParam;
1306 else if (!lpszNetLoc)
1307 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1315 /* [<user>[<:password>]@]<host>[:<port>] */
1316 /* First find the user and password if they exist */
1318 lpszHost = strchrW(lpszcp, '@');
1319 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1321 /* username and password not specified. */
1322 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1323 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1325 else /* Parse out username and password */
1327 LPCWSTR lpszUser = lpszcp;
1328 LPCWSTR lpszPasswd = lpszHost;
1330 while (lpszcp < lpszHost)
1333 lpszPasswd = lpszcp;
1338 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1339 lpszUser, lpszPasswd - lpszUser);
1341 if (lpszPasswd != lpszHost)
1343 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1344 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1345 lpszHost - lpszPasswd);
1347 lpszcp++; /* Advance to beginning of host */
1350 /* Parse <host><:port> */
1353 lpszPort = lpszNetLoc;
1355 /* special case for res:// URLs: there is no port here, so the host is the
1356 entire string up to the first '/' */
1357 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1359 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1360 lpszHost, lpszPort - lpszHost);
1365 while (lpszcp < lpszNetLoc)
1373 /* If the scheme is "file" and the host is just one letter, it's not a host */
1374 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1377 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1382 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1383 lpszHost, lpszPort - lpszHost);
1384 if (lpszPort != lpszNetLoc)
1385 lpUC->nPort = atoiW(++lpszPort);
1386 else switch (lpUC->nScheme)
1388 case INTERNET_SCHEME_HTTP:
1389 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1391 case INTERNET_SCHEME_HTTPS:
1392 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1394 case INTERNET_SCHEME_FTP:
1395 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1397 case INTERNET_SCHEME_GOPHER:
1398 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1409 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1410 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1411 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1416 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1417 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1418 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1419 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1422 /* Here lpszcp points to:
1424 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1425 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1427 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1431 /* Only truncate the parameter list if it's already been saved
1432 * in lpUC->lpszExtraInfo.
1434 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1435 len = lpszParam - lpszcp;
1438 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1439 * newlines if necessary.
1441 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1442 if (lpsznewline != NULL)
1443 len = lpsznewline - lpszcp;
1445 len = dwUrlLength-(lpszcp-lpszUrl);
1447 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1452 lpUC->dwUrlPathLength = 0;
1455 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1456 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1457 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1458 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1459 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1461 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1465 /***********************************************************************
1466 * InternetAttemptConnect (WININET.@)
1468 * Attempt to make a connection to the internet
1471 * ERROR_SUCCESS on success
1472 * Error value on failure
1475 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1478 return ERROR_SUCCESS;
1482 /***********************************************************************
1483 * InternetCanonicalizeUrlA (WININET.@)
1485 * Escape unsafe characters and spaces
1492 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1493 LPDWORD lpdwBufferLength, DWORD dwFlags)
1496 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1497 if(dwFlags & ICU_DECODE)
1499 dwURLFlags |= URL_UNESCAPE;
1500 dwFlags &= ~ICU_DECODE;
1503 if(dwFlags & ICU_ESCAPE)
1505 dwURLFlags |= URL_UNESCAPE;
1506 dwFlags &= ~ICU_ESCAPE;
1508 if(dwFlags & ICU_BROWSER_MODE)
1510 dwURLFlags |= URL_BROWSER_MODE;
1511 dwFlags &= ~ICU_BROWSER_MODE;
1514 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1515 TRACE("%s %p %p %08x\n", debugstr_a(lpszUrl), lpszBuffer,
1516 lpdwBufferLength, dwURLFlags);
1518 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1519 dwFlags ^= ICU_NO_ENCODE;
1521 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1523 return (hr == S_OK) ? TRUE : FALSE;
1526 /***********************************************************************
1527 * InternetCanonicalizeUrlW (WININET.@)
1529 * Escape unsafe characters and spaces
1536 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1537 LPDWORD lpdwBufferLength, DWORD dwFlags)
1540 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1541 if(dwFlags & ICU_DECODE)
1543 dwURLFlags |= URL_UNESCAPE;
1544 dwFlags &= ~ICU_DECODE;
1547 if(dwFlags & ICU_ESCAPE)
1549 dwURLFlags |= URL_UNESCAPE;
1550 dwFlags &= ~ICU_ESCAPE;
1552 if(dwFlags & ICU_BROWSER_MODE)
1554 dwURLFlags |= URL_BROWSER_MODE;
1555 dwFlags &= ~ICU_BROWSER_MODE;
1558 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1559 TRACE("%s %p %p %08x\n", debugstr_w(lpszUrl), lpszBuffer,
1560 lpdwBufferLength, dwURLFlags);
1562 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1563 dwFlags ^= ICU_NO_ENCODE;
1565 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1567 return (hr == S_OK) ? TRUE : FALSE;
1571 /***********************************************************************
1572 * InternetSetStatusCallbackA (WININET.@)
1574 * Sets up a callback function which is called as progress is made
1575 * during an operation.
1578 * Previous callback or NULL on success
1579 * INTERNET_INVALID_STATUS_CALLBACK on failure
1582 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1583 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1585 INTERNET_STATUS_CALLBACK retVal;
1586 LPWININETHANDLEHEADER lpwh;
1588 TRACE("0x%08x\n", (ULONG)hInternet);
1590 lpwh = WININET_GetObject(hInternet);
1592 return INTERNET_INVALID_STATUS_CALLBACK;
1594 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1595 retVal = lpwh->lpfnStatusCB;
1596 lpwh->lpfnStatusCB = lpfnIntCB;
1598 WININET_Release( lpwh );
1603 /***********************************************************************
1604 * InternetSetStatusCallbackW (WININET.@)
1606 * Sets up a callback function which is called as progress is made
1607 * during an operation.
1610 * Previous callback or NULL on success
1611 * INTERNET_INVALID_STATUS_CALLBACK on failure
1614 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1615 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1617 INTERNET_STATUS_CALLBACK retVal;
1618 LPWININETHANDLEHEADER lpwh;
1620 TRACE("0x%08x\n", (ULONG)hInternet);
1622 lpwh = WININET_GetObject(hInternet);
1624 return INTERNET_INVALID_STATUS_CALLBACK;
1626 lpwh->dwInternalFlags |= INET_CALLBACKW;
1627 retVal = lpwh->lpfnStatusCB;
1628 lpwh->lpfnStatusCB = lpfnIntCB;
1630 WININET_Release( lpwh );
1635 /***********************************************************************
1636 * InternetSetFilePointer (WININET.@)
1638 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1639 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1645 /***********************************************************************
1646 * InternetWriteFile (WININET.@)
1648 * Write data to an open internet file
1655 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1656 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1658 BOOL retval = FALSE;
1660 LPWININETHANDLEHEADER lpwh;
1663 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1667 switch (lpwh->htype)
1671 LPWININETHTTPREQW lpwhr;
1672 lpwhr = (LPWININETHTTPREQW)lpwh;
1674 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite);
1675 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1676 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1678 WININET_Release( lpwh );
1684 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1693 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1694 retval = (res >= 0);
1695 *lpdwNumOfBytesWritten = retval ? res : 0;
1697 WININET_Release( lpwh );
1703 static BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1704 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1705 BOOL bWait, BOOL bSendCompletionStatus)
1707 BOOL retval = FALSE;
1710 /* FIXME: this should use NETCON functions! */
1711 switch (lpwh->htype)
1714 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1715 dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0, (int *)pdwNumOfBytesRead))
1717 *pdwNumOfBytesRead = 0;
1718 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1725 /* FIXME: FTP should use NETCON_ stuff */
1726 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1729 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1730 retval = (res >= 0);
1731 *pdwNumOfBytesRead = retval ? res : 0;
1739 if (bSendCompletionStatus)
1741 INTERNET_ASYNC_RESULT iar;
1743 iar.dwResult = retval;
1744 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1745 INTERNET_GetLastError();
1747 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1748 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1749 sizeof(INTERNET_ASYNC_RESULT));
1754 /***********************************************************************
1755 * InternetReadFile (WININET.@)
1757 * Read data from an open internet file
1764 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1765 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1767 LPWININETHANDLEHEADER lpwh;
1770 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1772 lpwh = WININET_GetObject( hFile );
1775 SetLastError(ERROR_INVALID_HANDLE);
1779 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1780 WININET_Release( lpwh );
1782 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1786 /***********************************************************************
1787 * InternetReadFileExA (WININET.@)
1789 * Read data from an open internet file
1792 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1793 * lpBuffersOut [I/O] Buffer.
1794 * dwFlags [I] Flags. See notes.
1795 * dwContext [I] Context for callbacks.
1802 * The parameter dwFlags include zero or more of the following flags:
1803 *|IRF_ASYNC - Makes the call asynchronous.
1804 *|IRF_SYNC - Makes the call synchronous.
1805 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1806 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1808 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1811 * InternetOpenUrlA(), HttpOpenRequestA()
1813 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1815 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1817 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1819 INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1820 req->lpBuffersOut->dwBufferLength,
1821 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
1824 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1825 DWORD dwFlags, DWORD dwContext)
1827 BOOL retval = FALSE;
1828 LPWININETHANDLEHEADER lpwh;
1830 TRACE("(%p %p 0x%x 0x%x)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1832 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1833 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1835 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1837 SetLastError(ERROR_INVALID_PARAMETER);
1841 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1844 SetLastError(ERROR_INVALID_HANDLE);
1848 /* FIXME: native only does it asynchronously if the amount of data
1849 * requested isn't available. See NtReadFile. */
1850 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1851 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1852 * we should implement the above first */
1853 if (dwFlags & IRF_ASYNC)
1855 WORKREQUEST workRequest;
1856 struct WORKREQ_INTERNETREADFILEEXA *req;
1858 workRequest.asyncall = CALLASYNCPROC;
1859 workRequest.asyncproc = AsyncInternetReadFileExProc;
1860 workRequest.hdr = WININET_AddRef( lpwh );
1861 req = &workRequest.u.InternetReadFileExA;
1862 req->lpBuffersOut = lpBuffersOut;
1864 retval = INTERNET_AsyncCall(&workRequest);
1865 if (!retval) return FALSE;
1867 SetLastError(ERROR_IO_PENDING);
1871 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1872 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1873 !(dwFlags & IRF_NO_WAIT), FALSE);
1875 WININET_Release( lpwh );
1877 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1881 /***********************************************************************
1882 * InternetReadFileExW (WININET.@)
1884 * Read data from an open internet file.
1887 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1888 * lpBuffersOut [I/O] Buffer.
1889 * dwFlags [I] Flags.
1890 * dwContext [I] Context for callbacks.
1893 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1896 * Not implemented in Wine or native either (as of IE6 SP2).
1899 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1900 DWORD dwFlags, DWORD dwContext)
1902 ERR("(%p, %p, 0x%x, 0x%x): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1904 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1908 /***********************************************************************
1909 * INET_QueryOptionHelper (internal)
1911 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1912 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1914 LPWININETHANDLEHEADER lpwhh;
1915 BOOL bSuccess = FALSE;
1917 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1919 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1922 SetLastError(ERROR_INVALID_PARAMETER);
1928 case INTERNET_OPTION_HANDLE_TYPE:
1934 WARN("Invalid hInternet handle\n");
1935 SetLastError(ERROR_INVALID_HANDLE);
1939 type = lpwhh->htype;
1941 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
1943 if (*lpdwBufferLength < sizeof(ULONG))
1944 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1947 memcpy(lpBuffer, &type, sizeof(ULONG));
1950 *lpdwBufferLength = sizeof(ULONG);
1954 case INTERNET_OPTION_REQUEST_FLAGS:
1957 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1958 if (*lpdwBufferLength < sizeof(ULONG))
1959 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1962 memcpy(lpBuffer, &flags, sizeof(ULONG));
1965 *lpdwBufferLength = sizeof(ULONG);
1969 case INTERNET_OPTION_URL:
1970 case INTERNET_OPTION_DATAFILE_NAME:
1974 WARN("Invalid hInternet handle\n");
1975 SetLastError(ERROR_INVALID_HANDLE);
1978 if (lpwhh->htype == WH_HHTTPREQ)
1980 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
1982 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
1983 static const WCHAR szHost[] = {'H','o','s','t',0};
1987 Host = HTTP_GetHeader(lpreq,szHost);
1988 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
1989 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
1992 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
1993 lpBuffer,*lpdwBufferLength,NULL,NULL);
1994 if (sizeRequired > *lpdwBufferLength)
1995 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1998 *lpdwBufferLength = sizeRequired;
2002 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2003 if (*lpdwBufferLength < sizeRequired)
2004 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2007 strcpyW(lpBuffer, url);
2010 *lpdwBufferLength = sizeRequired;
2015 case INTERNET_OPTION_HTTP_VERSION:
2017 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2018 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2022 * Presently hardcoded to 1.1
2024 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2025 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2028 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2031 case INTERNET_OPTION_CONNECTED_STATE:
2033 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2034 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2036 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2037 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2040 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2043 *lpdwBufferLength = sizeof(*pdwConnectedState);
2046 case INTERNET_OPTION_PROXY:
2048 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2049 WININETAPPINFOW wai;
2053 TRACE("Getting global proxy info\n");
2054 memset(&wai, 0, sizeof(WININETAPPINFOW));
2055 INTERNET_ConfigureProxyFromReg( &wai );
2061 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2062 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2064 if (lpwai->lpszProxy)
2065 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2067 if (lpwai->lpszProxyBypass)
2068 proxyBypassBytesRequired =
2069 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2070 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2071 proxyBytesRequired + proxyBypassBytesRequired)
2072 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2075 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2076 sizeof(INTERNET_PROXY_INFOW));
2077 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2078 sizeof(INTERNET_PROXY_INFOW) +
2079 proxyBytesRequired);
2081 pPI->dwAccessType = lpwai->dwAccessType;
2082 if (lpwai->lpszProxy)
2084 lstrcpyW(proxy, lpwai->lpszProxy);
2090 pPI->lpszProxy = proxy;
2092 if (lpwai->lpszProxyBypass)
2094 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2100 pPI->lpszProxyBypass = proxy_bypass;
2103 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2104 proxyBytesRequired + proxyBypassBytesRequired;
2108 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2109 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2111 if (lpwai->lpszProxy)
2112 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2113 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2114 if (lpwai->lpszProxyBypass)
2115 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2116 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2117 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2118 proxyBytesRequired + proxyBypassBytesRequired)
2119 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2122 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2123 sizeof(INTERNET_PROXY_INFOA));
2124 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2125 sizeof(INTERNET_PROXY_INFOA) +
2126 proxyBytesRequired);
2128 pPI->dwAccessType = lpwai->dwAccessType;
2129 if (lpwai->lpszProxy)
2131 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2132 proxy, proxyBytesRequired, NULL, NULL);
2138 pPI->lpszProxy = proxy;
2140 if (lpwai->lpszProxyBypass)
2142 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2143 -1, proxy_bypass, proxyBypassBytesRequired,
2148 *proxy_bypass = '\0';
2150 pPI->lpszProxyBypass = proxy_bypass;
2153 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2154 proxyBytesRequired + proxyBypassBytesRequired;
2158 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2161 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2162 if (*lpdwBufferLength < sizeof(ULONG))
2163 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2166 memcpy(lpBuffer, &conn, sizeof(ULONG));
2169 *lpdwBufferLength = sizeof(ULONG);
2172 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2175 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2176 if (*lpdwBufferLength < sizeof(ULONG))
2177 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2180 memcpy(lpBuffer, &conn, sizeof(ULONG));
2183 *lpdwBufferLength = sizeof(ULONG);
2186 case INTERNET_OPTION_SECURITY_FLAGS:
2187 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2190 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2191 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2193 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2194 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2196 else if (lpwhh->htype == WH_HHTTPREQ)
2198 LPWININETHTTPREQW lpwhr;
2199 PCCERT_CONTEXT context;
2201 lpwhr = (LPWININETHTTPREQW)lpwhh;
2202 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2205 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2208 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2209 info->ftExpiry = context->pCertInfo->NotAfter;
2210 info->ftStart = context->pCertInfo->NotBefore;
2213 strLen = CertNameToStrW(context->dwCertEncodingType,
2214 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2216 info->lpszSubjectInfo = LocalAlloc(0,
2217 strLen * sizeof(WCHAR));
2218 if (info->lpszSubjectInfo)
2219 CertNameToStrW(context->dwCertEncodingType,
2220 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2221 info->lpszSubjectInfo, strLen);
2222 strLen = CertNameToStrW(context->dwCertEncodingType,
2223 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2225 info->lpszIssuerInfo = LocalAlloc(0,
2226 strLen * sizeof(WCHAR));
2227 if (info->lpszIssuerInfo)
2228 CertNameToStrW(context->dwCertEncodingType,
2229 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2230 info->lpszIssuerInfo, strLen);
2234 LPINTERNET_CERTIFICATE_INFOA infoA =
2235 (LPINTERNET_CERTIFICATE_INFOA)info;
2237 strLen = CertNameToStrA(context->dwCertEncodingType,
2238 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2240 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2241 if (infoA->lpszSubjectInfo)
2242 CertNameToStrA(context->dwCertEncodingType,
2243 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2244 infoA->lpszSubjectInfo, strLen);
2245 strLen = CertNameToStrA(context->dwCertEncodingType,
2246 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2248 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2249 if (infoA->lpszIssuerInfo)
2250 CertNameToStrA(context->dwCertEncodingType,
2251 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2252 infoA->lpszIssuerInfo, strLen);
2255 * Contrary to MSDN, these do not appear to be set.
2257 * lpszSignatureAlgName
2258 * lpszEncryptionAlgName
2261 CertFreeCertificateContext(context);
2267 FIXME("Stub! %d\n", dwOption);
2271 WININET_Release( lpwhh );
2276 /***********************************************************************
2277 * InternetQueryOptionW (WININET.@)
2279 * Queries an options on the specified handle
2286 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2287 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2289 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2292 /***********************************************************************
2293 * InternetQueryOptionA (WININET.@)
2295 * Queries an options on the specified handle
2302 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2303 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2305 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2309 /***********************************************************************
2310 * InternetSetOptionW (WININET.@)
2312 * Sets an options on the specified handle
2319 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2320 LPVOID lpBuffer, DWORD dwBufferLength)
2322 LPWININETHANDLEHEADER lpwhh;
2325 TRACE("0x%08x\n", dwOption);
2327 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2333 case INTERNET_OPTION_HTTP_VERSION:
2335 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2336 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2339 case INTERNET_OPTION_ERROR_MASK:
2341 unsigned long flags=*(unsigned long*)lpBuffer;
2342 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2345 case INTERNET_OPTION_CODEPAGE:
2347 unsigned long codepage=*(unsigned long*)lpBuffer;
2348 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2351 case INTERNET_OPTION_REQUEST_PRIORITY:
2353 unsigned long priority=*(unsigned long*)lpBuffer;
2354 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2357 case INTERNET_OPTION_CONNECT_TIMEOUT:
2359 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2360 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2363 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2365 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2366 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2369 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2371 unsigned long conns=*(unsigned long*)lpBuffer;
2372 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2375 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2377 unsigned long conns=*(unsigned long*)lpBuffer;
2378 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2381 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2382 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2384 case INTERNET_OPTION_END_BROWSER_SESSION:
2385 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2387 case INTERNET_OPTION_CONNECTED_STATE:
2388 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2390 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2391 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2393 case INTERNET_OPTION_SEND_TIMEOUT:
2394 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2395 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2396 if (dwBufferLength == sizeof(DWORD))
2398 if (lpwhh->htype == WH_HHTTPREQ)
2399 ret = NETCON_set_timeout(
2400 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2401 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2402 *(DWORD *)lpBuffer);
2405 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2411 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2415 case INTERNET_OPTION_CONNECT_RETRIES:
2416 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2418 case INTERNET_OPTION_CONTEXT_VALUE:
2419 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2421 case INTERNET_OPTION_SECURITY_FLAGS:
2422 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2425 FIXME("Option %d STUB\n",dwOption);
2426 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2430 WININET_Release( lpwhh );
2436 /***********************************************************************
2437 * InternetSetOptionA (WININET.@)
2439 * Sets an options on the specified handle.
2446 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2447 LPVOID lpBuffer, DWORD dwBufferLength)
2455 case INTERNET_OPTION_PROXY:
2457 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2458 LPINTERNET_PROXY_INFOW piw;
2459 DWORD proxlen, prbylen;
2462 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2463 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2464 wlen = sizeof(*piw) + proxlen + prbylen;
2465 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2466 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2467 piw->dwAccessType = pi->dwAccessType;
2468 prox = (LPWSTR) &piw[1];
2469 prby = &prox[proxlen+1];
2470 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2471 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2472 piw->lpszProxy = prox;
2473 piw->lpszProxyBypass = prby;
2476 case INTERNET_OPTION_USER_AGENT:
2477 case INTERNET_OPTION_USERNAME:
2478 case INTERNET_OPTION_PASSWORD:
2479 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2481 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2482 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2487 wlen = dwBufferLength;
2490 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2492 if( lpBuffer != wbuffer )
2493 HeapFree( GetProcessHeap(), 0, wbuffer );
2499 /***********************************************************************
2500 * InternetSetOptionExA (WININET.@)
2502 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2503 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2505 FIXME("Flags %08x ignored\n", dwFlags);
2506 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2509 /***********************************************************************
2510 * InternetSetOptionExW (WININET.@)
2512 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2513 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2515 FIXME("Flags %08x ignored\n", dwFlags);
2516 if( dwFlags & ~ISO_VALID_FLAGS )
2518 SetLastError( ERROR_INVALID_PARAMETER );
2521 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2524 static const WCHAR WININET_wkday[7][4] =
2525 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2526 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2527 static const WCHAR WININET_month[12][4] =
2528 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2529 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2530 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2532 /***********************************************************************
2533 * InternetTimeFromSystemTimeA (WININET.@)
2535 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2538 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2540 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2542 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2543 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2548 /***********************************************************************
2549 * InternetTimeFromSystemTimeW (WININET.@)
2551 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2553 static const WCHAR date[] =
2554 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2555 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2557 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2559 if (!time || !string) return FALSE;
2561 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2564 sprintfW( string, date,
2565 WININET_wkday[time->wDayOfWeek],
2567 WININET_month[time->wMonth - 1],
2576 /***********************************************************************
2577 * InternetTimeToSystemTimeA (WININET.@)
2579 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2585 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2587 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2588 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2592 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2593 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2594 HeapFree( GetProcessHeap(), 0, stringW );
2599 /***********************************************************************
2600 * InternetTimeToSystemTimeW (WININET.@)
2602 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2605 const WCHAR *s = string;
2608 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2610 if (!string || !time) return FALSE;
2612 /* Windows does this too */
2613 GetSystemTime( time );
2615 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2616 * a SYSTEMTIME structure.
2619 while (*s && !isalphaW( *s )) s++;
2620 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2621 time->wDayOfWeek = 7;
2623 for (i = 0; i < 7; i++)
2625 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2626 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2627 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2629 time->wDayOfWeek = i;
2634 if (time->wDayOfWeek > 6) return TRUE;
2635 while (*s && !isdigitW( *s )) s++;
2636 time->wDay = strtolW( s, &end, 10 );
2639 while (*s && !isalphaW( *s )) s++;
2640 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2643 for (i = 0; i < 12; i++)
2645 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2646 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2647 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2649 time->wMonth = i + 1;
2653 if (time->wMonth == 0) return TRUE;
2655 while (*s && !isdigitW( *s )) s++;
2656 if (*s == '\0') return TRUE;
2657 time->wYear = strtolW( s, &end, 10 );
2660 while (*s && !isdigitW( *s )) s++;
2661 if (*s == '\0') return TRUE;
2662 time->wHour = strtolW( s, &end, 10 );
2665 while (*s && !isdigitW( *s )) s++;
2666 if (*s == '\0') return TRUE;
2667 time->wMinute = strtolW( s, &end, 10 );
2670 while (*s && !isdigitW( *s )) s++;
2671 if (*s == '\0') return TRUE;
2672 time->wSecond = strtolW( s, &end, 10 );
2675 time->wMilliseconds = 0;
2679 /***********************************************************************
2680 * InternetCheckConnectionW (WININET.@)
2682 * Pings a requested host to check internet connection
2685 * TRUE on success and FALSE on failure. If a failure then
2686 * ERROR_NOT_CONNECTED is placed into GetLastError
2689 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2692 * this is a kludge which runs the resident ping program and reads the output.
2694 * Anyone have a better idea?
2698 static const CHAR ping[] = "ping -w 1 ";
2699 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2700 CHAR *command = NULL;
2708 * Crack or set the Address
2710 if (lpszUrl == NULL)
2713 * According to the doc we are supost to use the ip for the next
2714 * server in the WnInet internal server database. I have
2715 * no idea what that is or how to get it.
2717 * So someone needs to implement this.
2719 FIXME("Unimplemented with URL of NULL\n");
2724 URL_COMPONENTSW components;
2726 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2727 components.lpszHostName = (LPWSTR)&hostW;
2728 components.dwHostNameLength = 1024;
2730 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2733 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2737 * Build our ping command
2739 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2740 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2741 strcpy(command,ping);
2742 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2743 strcat(command,redirect);
2745 TRACE("Ping command is : %s\n",command);
2747 status = system(command);
2749 TRACE("Ping returned a code of %i\n",status);
2751 /* Ping return code of 0 indicates success */
2757 HeapFree( GetProcessHeap(), 0, command );
2759 SetLastError(ERROR_NOT_CONNECTED);
2765 /***********************************************************************
2766 * InternetCheckConnectionA (WININET.@)
2768 * Pings a requested host to check internet connection
2771 * TRUE on success and FALSE on failure. If a failure then
2772 * ERROR_NOT_CONNECTED is placed into GetLastError
2775 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2781 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2782 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2784 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2785 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2786 HeapFree(GetProcessHeap(), 0, szUrl);
2792 /**********************************************************
2793 * INTERNET_InternetOpenUrlW (internal)
2798 * handle of connection or NULL on failure
2800 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2801 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2803 URL_COMPONENTSW urlComponents;
2804 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2805 WCHAR password[1024], path[2048], extra[1024];
2806 HINTERNET client = NULL, client1 = NULL;
2808 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2809 dwHeadersLength, dwFlags, dwContext);
2811 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2812 urlComponents.lpszScheme = protocol;
2813 urlComponents.dwSchemeLength = 32;
2814 urlComponents.lpszHostName = hostName;
2815 urlComponents.dwHostNameLength = MAXHOSTNAME;
2816 urlComponents.lpszUserName = userName;
2817 urlComponents.dwUserNameLength = 1024;
2818 urlComponents.lpszPassword = password;
2819 urlComponents.dwPasswordLength = 1024;
2820 urlComponents.lpszUrlPath = path;
2821 urlComponents.dwUrlPathLength = 2048;
2822 urlComponents.lpszExtraInfo = extra;
2823 urlComponents.dwExtraInfoLength = 1024;
2824 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2826 switch(urlComponents.nScheme) {
2827 case INTERNET_SCHEME_FTP:
2828 if(urlComponents.nPort == 0)
2829 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2830 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2831 userName, password, dwFlags, dwContext, INET_OPENURL);
2834 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2835 if(client1 == NULL) {
2836 InternetCloseHandle(client);
2841 case INTERNET_SCHEME_HTTP:
2842 case INTERNET_SCHEME_HTTPS: {
2843 static const WCHAR szStars[] = { '*','/','*', 0 };
2844 LPCWSTR accept[2] = { szStars, NULL };
2845 if(urlComponents.nPort == 0) {
2846 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2847 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2849 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2851 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2852 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2853 userName, password, dwFlags, dwContext, INET_OPENURL);
2856 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2857 if(client1 == NULL) {
2858 InternetCloseHandle(client);
2861 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2862 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2863 GetLastError() != ERROR_IO_PENDING) {
2864 InternetCloseHandle(client1);
2869 case INTERNET_SCHEME_GOPHER:
2870 /* gopher doesn't seem to be implemented in wine, but it's supposed
2871 * to be supported by InternetOpenUrlA. */
2873 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2877 TRACE(" %p <--\n", client1);
2882 /**********************************************************
2883 * InternetOpenUrlW (WININET.@)
2888 * handle of connection or NULL on failure
2890 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2892 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2893 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
2897 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2898 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2899 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2900 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2903 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2904 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2906 HINTERNET ret = NULL;
2907 LPWININETAPPINFOW hIC = NULL;
2909 if (TRACE_ON(wininet)) {
2910 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2911 dwHeadersLength, dwFlags, dwContext);
2913 dump_INTERNET_FLAGS(dwFlags);
2918 SetLastError(ERROR_INVALID_PARAMETER);
2922 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2923 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2924 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2928 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2929 WORKREQUEST workRequest;
2930 struct WORKREQ_INTERNETOPENURLW *req;
2932 workRequest.asyncall = CALLASYNCPROC;
2933 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2934 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2935 req = &workRequest.u.InternetOpenUrlW;
2936 req->lpszUrl = WININET_strdupW(lpszUrl);
2938 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2940 req->lpszHeaders = 0;
2941 req->dwHeadersLength = dwHeadersLength;
2942 req->dwFlags = dwFlags;
2943 req->dwContext = dwContext;
2945 INTERNET_AsyncCall(&workRequest);
2947 * This is from windows.
2949 SetLastError(ERROR_IO_PENDING);
2951 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2956 WININET_Release( &hIC->hdr );
2957 TRACE(" %p <--\n", ret);
2962 /**********************************************************
2963 * InternetOpenUrlA (WININET.@)
2968 * handle of connection or NULL on failure
2970 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2971 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2973 HINTERNET rc = (HINTERNET)NULL;
2977 LPWSTR szUrl = NULL;
2978 LPWSTR szHeaders = NULL;
2983 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2984 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2986 return (HINTERNET)NULL;
2987 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2991 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
2992 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
2994 HeapFree(GetProcessHeap(), 0, szUrl);
2995 return (HINTERNET)NULL;
2997 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3000 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3001 lenHeaders, dwFlags, dwContext);
3003 HeapFree(GetProcessHeap(), 0, szUrl);
3004 HeapFree(GetProcessHeap(), 0, szHeaders);
3010 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3012 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3016 lpwite->dwError = 0;
3017 lpwite->response[0] = '\0';
3020 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3022 HeapFree(GetProcessHeap(), 0, lpwite);
3030 /***********************************************************************
3031 * INTERNET_SetLastError (internal)
3033 * Set last thread specific error
3038 void INTERNET_SetLastError(DWORD dwError)
3040 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3043 lpwite = INTERNET_AllocThreadError();
3045 SetLastError(dwError);
3047 lpwite->dwError = dwError;
3051 /***********************************************************************
3052 * INTERNET_GetLastError (internal)
3054 * Get last thread specific error
3059 DWORD INTERNET_GetLastError(void)
3061 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3062 if (!lpwite) return 0;
3063 /* TlsGetValue clears last error, so set it again here */
3064 SetLastError(lpwite->dwError);
3065 return lpwite->dwError;
3069 /***********************************************************************
3070 * INTERNET_WorkerThreadFunc (internal)
3072 * Worker thread execution function
3077 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3084 INTERNET_ExecuteWork();
3087 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
3089 if (dwWaitRes == WAIT_OBJECT_0 + 1)
3090 INTERNET_ExecuteWork();
3094 InterlockedIncrement(&dwNumIdleThreads);
3097 InterlockedDecrement(&dwNumIdleThreads);
3098 InterlockedDecrement(&dwNumThreads);
3099 TRACE("Worker thread exiting\n");
3104 /***********************************************************************
3105 * INTERNET_InsertWorkRequest (internal)
3107 * Insert work request into queue
3112 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
3114 BOOL bSuccess = FALSE;
3115 LPWORKREQUEST lpNewRequest;
3119 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3122 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3123 lpNewRequest->prev = NULL;
3125 EnterCriticalSection(&csQueue);
3127 lpNewRequest->next = lpWorkQueueTail;
3128 if (lpWorkQueueTail)
3129 lpWorkQueueTail->prev = lpNewRequest;
3130 lpWorkQueueTail = lpNewRequest;
3131 if (!lpHeadWorkQueue)
3132 lpHeadWorkQueue = lpWorkQueueTail;
3134 LeaveCriticalSection(&csQueue);
3137 InterlockedIncrement(&dwNumJobs);
3144 /***********************************************************************
3145 * INTERNET_GetWorkRequest (internal)
3147 * Retrieves work request from queue
3152 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
3154 BOOL bSuccess = FALSE;
3155 LPWORKREQUEST lpRequest = NULL;
3159 EnterCriticalSection(&csQueue);
3161 if (lpHeadWorkQueue)
3163 lpRequest = lpHeadWorkQueue;
3164 lpHeadWorkQueue = lpHeadWorkQueue->prev;
3165 if (lpRequest == lpWorkQueueTail)
3166 lpWorkQueueTail = lpHeadWorkQueue;
3169 LeaveCriticalSection(&csQueue);
3173 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
3174 HeapFree(GetProcessHeap(), 0, lpRequest);
3176 InterlockedDecrement(&dwNumJobs);
3183 /***********************************************************************
3184 * INTERNET_AsyncCall (internal)
3186 * Retrieves work request from queue
3191 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3195 BOOL bSuccess = FALSE;
3199 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
3201 InterlockedIncrement(&dwNumIdleThreads);
3203 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
3204 !(hThread = CreateThread(NULL, 0,
3205 INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
3207 InterlockedDecrement(&dwNumThreads);
3208 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3212 TRACE("Created new thread\n");
3216 INTERNET_InsertWorkRequest(lpWorkRequest);
3217 SetEvent(hWorkEvent);
3225 /***********************************************************************
3226 * INTERNET_ExecuteWork (internal)
3231 static VOID INTERNET_ExecuteWork(void)
3233 WORKREQUEST workRequest;
3237 if (!INTERNET_GetWorkRequest(&workRequest))
3240 switch (workRequest.asyncall)
3243 workRequest.asyncproc(&workRequest);
3246 case FTPRENAMEFILEW:
3248 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
3249 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3251 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
3253 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
3254 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
3255 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
3261 struct WORKREQ_FTPFINDNEXTW *req;
3262 LPWININETFTPFINDNEXTW lpwh = (LPWININETFTPFINDNEXTW) workRequest.hdr;
3264 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
3266 req = &workRequest.u.FtpFindNextW;
3267 FTP_FindNextFileW(lpwh, req->lpFindFileData);
3271 WININET_Release( workRequest.hdr );
3275 /***********************************************************************
3276 * INTERNET_GetResponseBuffer (internal)
3281 LPSTR INTERNET_GetResponseBuffer(void)
3283 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3285 lpwite = INTERNET_AllocThreadError();
3287 return lpwite->response;
3290 /***********************************************************************
3291 * INTERNET_GetNextLine (internal)
3293 * Parse next line in directory string listing
3296 * Pointer to beginning of next line
3301 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3305 BOOL bSuccess = FALSE;
3307 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3312 FD_SET(nSocket, &infd);
3313 tv.tv_sec=RESPONSE_TIMEOUT;
3316 while (nRecv < MAX_REPLY_LEN)
3318 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3320 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3322 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3326 if (lpszBuffer[nRecv] == '\n')
3331 if (lpszBuffer[nRecv] != '\r')
3336 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3344 lpszBuffer[nRecv] = '\0';
3346 TRACE(":%d %s\n", nRecv, lpszBuffer);
3355 /**********************************************************
3356 * InternetQueryDataAvailable (WININET.@)
3358 * Determines how much data is available to be read.
3361 * If there is data available then TRUE, otherwise if there
3362 * is not or an error occurred then FALSE. Use GetLastError() to
3363 * check for ERROR_NO_MORE_FILES to see if it was the former.
3365 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3366 LPDWORD lpdwNumberOfBytesAvailble,
3367 DWORD dwFlags, DWORD dwConext)
3369 LPWININETHTTPREQW lpwhr;
3370 BOOL retval = FALSE;
3373 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3376 SetLastError(ERROR_NO_MORE_FILES);
3380 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3382 switch (lpwhr->hdr.htype)
3385 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3386 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3388 SetLastError(ERROR_NO_MORE_FILES);
3396 FIXME("unsupported file type\n");
3399 WININET_Release( &lpwhr->hdr );
3401 TRACE("<-- %i\n",retval);
3406 /***********************************************************************
3407 * InternetLockRequestFile (WININET.@)
3409 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3416 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3423 /***********************************************************************
3424 * InternetAutodial (WININET.@)
3426 * On windows this function is supposed to dial the default internet
3427 * connection. We don't want to have Wine dial out to the internet so
3428 * we return TRUE by default. It might be nice to check if we are connected.
3435 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3439 /* Tell that we are connected to the internet. */
3443 /***********************************************************************
3444 * InternetAutodialHangup (WININET.@)
3446 * Hangs up a connection made with InternetAutodial
3455 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3459 /* we didn't dial, we don't disconnect */
3463 /***********************************************************************
3464 * InternetCombineUrlA (WININET.@)
3466 * Combine a base URL with a relative URL
3474 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3475 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3480 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3482 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3483 dwFlags ^= ICU_NO_ENCODE;
3484 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3489 /***********************************************************************
3490 * InternetCombineUrlW (WININET.@)
3492 * Combine a base URL with a relative URL
3500 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3501 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3506 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3508 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3509 dwFlags ^= ICU_NO_ENCODE;
3510 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3515 /* max port num is 65535 => 5 digits */
3516 #define MAX_WORD_DIGITS 5
3518 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3519 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3520 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3521 (url)->dw##component##Length : strlen((url)->lpsz##component))
3523 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3525 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3526 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3528 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3529 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3531 if ((nScheme == INTERNET_SCHEME_FTP) &&
3532 (nPort == INTERNET_DEFAULT_FTP_PORT))
3534 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3535 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3538 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3544 /* opaque urls do not fit into the standard url hierarchy and don't have
3545 * two following slashes */
3546 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3548 return (nScheme != INTERNET_SCHEME_FTP) &&
3549 (nScheme != INTERNET_SCHEME_GOPHER) &&
3550 (nScheme != INTERNET_SCHEME_HTTP) &&
3551 (nScheme != INTERNET_SCHEME_HTTPS) &&
3552 (nScheme != INTERNET_SCHEME_FILE);
3555 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3558 if (scheme < INTERNET_SCHEME_FIRST)
3560 index = scheme - INTERNET_SCHEME_FIRST;
3561 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3563 return (LPCWSTR)&url_schemes[index];
3566 /* we can calculate using ansi strings because we're just
3567 * calculating string length, not size
3569 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3570 LPDWORD lpdwUrlLength)
3572 INTERNET_SCHEME nScheme;
3576 if (lpUrlComponents->lpszScheme)
3578 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3579 *lpdwUrlLength += dwLen;
3580 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3586 nScheme = lpUrlComponents->nScheme;
3588 if (nScheme == INTERNET_SCHEME_DEFAULT)
3589 nScheme = INTERNET_SCHEME_HTTP;
3590 scheme = INTERNET_GetSchemeString(nScheme);
3591 *lpdwUrlLength += strlenW(scheme);
3594 (*lpdwUrlLength)++; /* ':' */
3595 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3596 *lpdwUrlLength += strlen("//");
3598 if (lpUrlComponents->lpszUserName)
3600 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3601 *lpdwUrlLength += strlen("@");
3605 if (lpUrlComponents->lpszPassword)
3607 SetLastError(ERROR_INVALID_PARAMETER);
3612 if (lpUrlComponents->lpszPassword)
3614 *lpdwUrlLength += strlen(":");
3615 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3618 if (lpUrlComponents->lpszHostName)
3620 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3622 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3624 char szPort[MAX_WORD_DIGITS+1];
3626 sprintf(szPort, "%d", lpUrlComponents->nPort);
3627 *lpdwUrlLength += strlen(szPort);
3628 *lpdwUrlLength += strlen(":");
3631 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3632 (*lpdwUrlLength)++; /* '/' */
3635 if (lpUrlComponents->lpszUrlPath)
3636 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3641 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3645 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3647 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3648 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3649 urlCompW->nScheme = lpUrlComponents->nScheme;
3650 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3651 urlCompW->nPort = lpUrlComponents->nPort;
3652 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3653 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3654 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3655 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3657 if (lpUrlComponents->lpszScheme)
3659 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3660 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3661 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3662 -1, urlCompW->lpszScheme, len);
3665 if (lpUrlComponents->lpszHostName)
3667 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3668 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3669 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3670 -1, urlCompW->lpszHostName, len);
3673 if (lpUrlComponents->lpszUserName)
3675 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3676 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3677 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3678 -1, urlCompW->lpszUserName, len);
3681 if (lpUrlComponents->lpszPassword)
3683 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3684 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3685 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3686 -1, urlCompW->lpszPassword, len);
3689 if (lpUrlComponents->lpszUrlPath)
3691 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3692 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3693 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3694 -1, urlCompW->lpszUrlPath, len);
3697 if (lpUrlComponents->lpszExtraInfo)
3699 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3700 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3701 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3702 -1, urlCompW->lpszExtraInfo, len);
3706 /***********************************************************************
3707 * InternetCreateUrlA (WININET.@)
3709 * See InternetCreateUrlW.
3711 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3712 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3716 URL_COMPONENTSW urlCompW;
3718 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3720 if (!lpUrlComponents)
3723 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3725 SetLastError(ERROR_INVALID_PARAMETER);
3729 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3732 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3734 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3736 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3737 *lpdwUrlLength /= sizeof(WCHAR);
3739 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3740 * minus one, so add one to leave room for NULL terminator
3743 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3745 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3746 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3747 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3748 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3749 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3750 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3751 HeapFree(GetProcessHeap(), 0, urlW);
3756 /***********************************************************************
3757 * InternetCreateUrlW (WININET.@)
3759 * Creates a URL from its component parts.
3762 * lpUrlComponents [I] URL Components.
3763 * dwFlags [I] Flags. See notes.
3764 * lpszUrl [I] Buffer in which to store the created URL.
3765 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3766 * lpszUrl in characters. On output, the number of bytes
3767 * required to store the URL including terminator.
3771 * The dwFlags parameter can be zero or more of the following:
3772 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3779 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3780 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3783 INTERNET_SCHEME nScheme;
3785 static const WCHAR slashSlashW[] = {'/','/'};
3786 static const WCHAR percentD[] = {'%','d',0};
3788 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3790 if (!lpUrlComponents)
3793 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3795 SetLastError(ERROR_INVALID_PARAMETER);
3799 if (!calc_url_length(lpUrlComponents, &dwLen))
3802 if (!lpszUrl || *lpdwUrlLength < dwLen)
3804 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3805 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3809 *lpdwUrlLength = dwLen;
3814 if (lpUrlComponents->lpszScheme)
3816 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3817 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3820 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3825 nScheme = lpUrlComponents->nScheme;
3827 if (nScheme == INTERNET_SCHEME_DEFAULT)
3828 nScheme = INTERNET_SCHEME_HTTP;
3830 scheme = INTERNET_GetSchemeString(nScheme);
3831 dwLen = strlenW(scheme);
3832 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3836 /* all schemes are followed by at least a colon */
3840 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3842 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3843 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3846 if (lpUrlComponents->lpszUserName)
3848 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3849 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3852 if (lpUrlComponents->lpszPassword)
3857 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3858 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3866 if (lpUrlComponents->lpszHostName)
3868 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3869 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3872 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3874 WCHAR szPort[MAX_WORD_DIGITS+1];
3876 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3879 dwLen = strlenW(szPort);
3880 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3884 /* add slash between hostname and path if necessary */
3885 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3893 if (lpUrlComponents->lpszUrlPath)
3895 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3896 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3905 /***********************************************************************
3906 * InternetConfirmZoneCrossingA (WININET.@)
3909 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3911 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3912 return ERROR_SUCCESS;
3915 /***********************************************************************
3916 * InternetConfirmZoneCrossingW (WININET.@)
3919 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3921 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3922 return ERROR_SUCCESS;
3925 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3926 LPDWORD lpdwConnection, DWORD dwReserved )
3928 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3929 lpdwConnection, dwReserved);
3930 return ERROR_SUCCESS;
3933 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3934 LPDWORD lpdwConnection, DWORD dwReserved )
3936 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3937 lpdwConnection, dwReserved);
3938 return ERROR_SUCCESS;
3941 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3943 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3947 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3949 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3953 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
3955 FIXME("(0x%08x, 0x%08x) stub\n", dwConnection, dwReserved);
3956 return ERROR_SUCCESS;
3959 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3962 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3963 debugstr_w(pwszTarget), pbHexHash);
3967 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3969 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);