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>
58 #include "wine/debug.h"
60 #define NO_SHLWAPI_STREAM
64 #include "wine/exception.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define RESPONSE_TIMEOUT 30
78 CHAR response[MAX_REPLY_LEN];
79 } WITHREADERROR, *LPWITHREADERROR;
81 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr);
82 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
83 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext);
85 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
86 static HMODULE WININET_hModule;
88 #define HANDLE_CHUNK_SIZE 0x10
90 static CRITICAL_SECTION WININET_cs;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
94 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
95 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
99 static LPWININETHANDLEHEADER *WININET_Handles;
100 static UINT WININET_dwNextHandle;
101 static UINT WININET_dwMaxHandles;
103 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
105 LPWININETHANDLEHEADER *p;
106 UINT handle = 0, num;
108 EnterCriticalSection( &WININET_cs );
109 if( !WININET_dwMaxHandles )
111 num = HANDLE_CHUNK_SIZE;
112 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
117 WININET_dwMaxHandles = num;
119 if( WININET_dwMaxHandles == WININET_dwNextHandle )
121 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
122 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
123 WININET_Handles, sizeof (UINT)* num);
127 WININET_dwMaxHandles = num;
130 handle = WININET_dwNextHandle;
131 if( WININET_Handles[handle] )
132 ERR("handle isn't free but should be\n");
133 WININET_Handles[handle] = WININET_AddRef( info );
135 while( WININET_Handles[WININET_dwNextHandle] &&
136 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
137 WININET_dwNextHandle++;
140 LeaveCriticalSection( &WININET_cs );
142 return info->hInternet = (HINTERNET) (handle+1);
145 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
148 TRACE("%p -> refcount = %d\n", info, info->dwRefCount );
152 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
154 LPWININETHANDLEHEADER info = NULL;
155 UINT handle = (UINT) hinternet;
157 EnterCriticalSection( &WININET_cs );
159 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
160 WININET_Handles[handle-1] )
161 info = WININET_AddRef( WININET_Handles[handle-1] );
163 LeaveCriticalSection( &WININET_cs );
165 TRACE("handle %d -> %p\n", handle, info);
170 BOOL WININET_Release( LPWININETHANDLEHEADER info )
173 TRACE( "object %p refcount = %d\n", info, info->dwRefCount );
174 if( !info->dwRefCount )
176 if ( info->close_connection )
178 TRACE( "closing connection %p\n", info);
179 info->close_connection( info );
181 INTERNET_SendCallback(info, info->dwContext,
182 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
184 TRACE( "destroying object %p\n", info);
185 info->destroy( info );
190 BOOL WININET_FreeHandle( HINTERNET hinternet )
193 UINT handle = (UINT) hinternet;
194 LPWININETHANDLEHEADER info = NULL;
196 EnterCriticalSection( &WININET_cs );
198 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
201 if( WININET_Handles[handle] )
203 info = WININET_Handles[handle];
204 TRACE( "destroying handle %d for object %p\n", handle+1, info);
205 WININET_Handles[handle] = NULL;
207 if( WININET_dwNextHandle > handle )
208 WININET_dwNextHandle = handle;
212 LeaveCriticalSection( &WININET_cs );
215 WININET_Release( info );
220 /***********************************************************************
221 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
224 * hinstDLL [I] handle to the DLL's instance
226 * lpvReserved [I] reserved, must be NULL
233 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
235 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
238 case DLL_PROCESS_ATTACH:
240 g_dwTlsErrIndex = TlsAlloc();
242 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
245 URLCacheContainers_CreateDefaults();
247 WININET_hModule = (HMODULE)hinstDLL;
249 case DLL_THREAD_ATTACH:
252 case DLL_THREAD_DETACH:
253 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
255 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
256 HeapFree(GetProcessHeap(), 0, lpwite);
260 case DLL_PROCESS_DETACH:
262 URLCacheContainers_DeleteAll();
264 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
266 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
267 TlsFree(g_dwTlsErrIndex);
276 /***********************************************************************
277 * InternetInitializeAutoProxyDll (WININET.@)
279 * Setup the internal proxy
288 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
291 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
295 /***********************************************************************
296 * DetectAutoProxyUrl (WININET.@)
298 * Auto detect the proxy url
304 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
305 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
308 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
313 /***********************************************************************
314 * INTERNET_ConfigureProxyFromReg
317 * The proxy may be specified in the form 'http=proxy.my.org'
318 * Presumably that means there can be ftp=ftpproxy.my.org too.
320 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
323 DWORD r, keytype, len, enabled;
324 LPCSTR lpszInternetSettings =
325 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
326 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
328 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
329 if ( r != ERROR_SUCCESS )
332 len = sizeof enabled;
333 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
334 (BYTE*)&enabled, &len);
335 if( (r == ERROR_SUCCESS) && enabled )
337 TRACE("Proxy is enabled.\n");
339 /* figure out how much memory the proxy setting takes */
340 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
342 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
345 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
347 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
348 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
349 (BYTE*)szProxy, &len);
351 /* find the http proxy, and strip away everything else */
352 p = strstrW( szProxy, szHttp );
355 p += lstrlenW(szHttp);
356 lstrcpyW( szProxy, p );
358 p = strchrW( szProxy, ' ' );
362 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
363 lpwai->lpszProxy = szProxy;
365 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
368 ERR("Couldn't read proxy server settings.\n");
371 TRACE("Proxy is not enabled.\n");
377 /***********************************************************************
378 * dump_INTERNET_FLAGS
380 * Helper function to TRACE the internet flags.
386 static void dump_INTERNET_FLAGS(DWORD dwFlags)
388 #define FE(x) { x, #x }
389 static const wininet_flag_info flag[] = {
390 FE(INTERNET_FLAG_RELOAD),
391 FE(INTERNET_FLAG_RAW_DATA),
392 FE(INTERNET_FLAG_EXISTING_CONNECT),
393 FE(INTERNET_FLAG_ASYNC),
394 FE(INTERNET_FLAG_PASSIVE),
395 FE(INTERNET_FLAG_NO_CACHE_WRITE),
396 FE(INTERNET_FLAG_MAKE_PERSISTENT),
397 FE(INTERNET_FLAG_FROM_CACHE),
398 FE(INTERNET_FLAG_SECURE),
399 FE(INTERNET_FLAG_KEEP_CONNECTION),
400 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
401 FE(INTERNET_FLAG_READ_PREFETCH),
402 FE(INTERNET_FLAG_NO_COOKIES),
403 FE(INTERNET_FLAG_NO_AUTH),
404 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
405 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
406 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
407 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
408 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
409 FE(INTERNET_FLAG_RESYNCHRONIZE),
410 FE(INTERNET_FLAG_HYPERLINK),
411 FE(INTERNET_FLAG_NO_UI),
412 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
413 FE(INTERNET_FLAG_CACHE_ASYNC),
414 FE(INTERNET_FLAG_FORMS_SUBMIT),
415 FE(INTERNET_FLAG_NEED_FILE),
416 FE(INTERNET_FLAG_TRANSFER_ASCII),
417 FE(INTERNET_FLAG_TRANSFER_BINARY)
422 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
423 if (flag[i].val & dwFlags) {
424 TRACE(" %s", flag[i].name);
425 dwFlags &= ~flag[i].val;
429 TRACE(" Unknown flags (%08x)\n", dwFlags);
434 /***********************************************************************
435 * InternetOpenW (WININET.@)
437 * Per-application initialization of wininet
440 * HINTERNET on success
444 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
445 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
447 LPWININETAPPINFOW lpwai = NULL;
448 HINTERNET handle = NULL;
450 if (TRACE_ON(wininet)) {
451 #define FE(x) { x, #x }
452 static const wininet_flag_info access_type[] = {
453 FE(INTERNET_OPEN_TYPE_PRECONFIG),
454 FE(INTERNET_OPEN_TYPE_DIRECT),
455 FE(INTERNET_OPEN_TYPE_PROXY),
456 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
460 const char *access_type_str = "Unknown";
462 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
463 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
464 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
465 if (access_type[i].val == dwAccessType) {
466 access_type_str = access_type[i].name;
470 TRACE(" access type : %s\n", access_type_str);
472 dump_INTERNET_FLAGS(dwFlags);
475 /* Clear any error information */
476 INTERNET_SetLastError(0);
478 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
481 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
485 lpwai->hdr.htype = WH_HINIT;
486 lpwai->hdr.dwFlags = dwFlags;
487 lpwai->hdr.dwRefCount = 1;
488 lpwai->hdr.close_connection = NULL;
489 lpwai->hdr.destroy = INTERNET_CloseHandle;
490 lpwai->dwAccessType = dwAccessType;
491 lpwai->lpszProxyUsername = NULL;
492 lpwai->lpszProxyPassword = NULL;
494 handle = WININET_AllocHandle( &lpwai->hdr );
497 HeapFree( GetProcessHeap(), 0, lpwai );
498 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
502 if (NULL != lpszAgent)
504 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
505 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
506 if (lpwai->lpszAgent)
507 lstrcpyW( lpwai->lpszAgent, lpszAgent );
509 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
510 INTERNET_ConfigureProxyFromReg( lpwai );
511 else if (NULL != lpszProxy)
513 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
514 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
515 if (lpwai->lpszProxy)
516 lstrcpyW( lpwai->lpszProxy, lpszProxy );
519 if (NULL != lpszProxyBypass)
521 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
522 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
523 if (lpwai->lpszProxyBypass)
524 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
529 WININET_Release( &lpwai->hdr );
531 TRACE("returning %p\n", lpwai);
537 /***********************************************************************
538 * InternetOpenA (WININET.@)
540 * Per-application initialization of wininet
543 * HINTERNET on success
547 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
548 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
550 HINTERNET rc = (HINTERNET)NULL;
552 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
554 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
555 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
559 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
560 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
561 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
566 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
567 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
568 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
571 if( lpszProxyBypass )
573 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
574 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
575 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
578 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
580 HeapFree(GetProcessHeap(), 0, szAgent);
581 HeapFree(GetProcessHeap(), 0, szProxy);
582 HeapFree(GetProcessHeap(), 0, szBypass);
587 /***********************************************************************
588 * InternetGetLastResponseInfoA (WININET.@)
590 * Return last wininet error description on the calling thread
593 * TRUE on success of writing to buffer
597 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
598 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
600 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
606 *lpdwError = lpwite->dwError;
609 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
610 *lpdwBufferLength = strlen(lpszBuffer);
613 *lpdwBufferLength = 0;
618 *lpdwBufferLength = 0;
624 /***********************************************************************
625 * InternetGetLastResponseInfoW (WININET.@)
627 * Return last wininet error description on the calling thread
630 * TRUE on success of writing to buffer
634 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
635 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
637 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
643 *lpdwError = lpwite->dwError;
646 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
647 *lpdwBufferLength = lstrlenW(lpszBuffer);
650 *lpdwBufferLength = 0;
655 *lpdwBufferLength = 0;
661 /***********************************************************************
662 * InternetGetConnectedState (WININET.@)
664 * Return connected state
668 * if lpdwStatus is not null, return the status (off line,
669 * modem, lan...) in it.
670 * FALSE if not connected
672 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
674 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
677 FIXME("always returning LAN connection.\n");
678 *lpdwStatus = INTERNET_CONNECTION_LAN;
684 /***********************************************************************
685 * InternetGetConnectedStateExW (WININET.@)
687 * Return connected state
691 * lpdwStatus [O] Flags specifying the status of the internet connection.
692 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
693 * dwNameLen [I] Size of the buffer, in characters.
694 * dwReserved [I] Reserved. Must be set to 0.
698 * if lpdwStatus is not null, return the status (off line,
699 * modem, lan...) in it.
700 * FALSE if not connected
703 * If the system has no available network connections, an empty string is
704 * stored in lpszConnectionName. If there is a LAN connection, a localized
705 * "LAN Connection" string is stored. Presumably, if only a dial-up
706 * connection is available then the name of the dial-up connection is
707 * returned. Why any application, other than the "Internet Settings" CPL,
708 * would want to use this function instead of the simpler InternetGetConnectedStateW
709 * function is beyond me.
711 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
712 DWORD dwNameLen, DWORD dwReserved)
714 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
721 FIXME("always returning LAN connection.\n");
722 *lpdwStatus = INTERNET_CONNECTION_LAN;
724 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
728 /***********************************************************************
729 * InternetGetConnectedStateExA (WININET.@)
731 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
732 DWORD dwNameLen, DWORD dwReserved)
734 LPWSTR lpwszConnectionName = NULL;
737 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
739 if (lpszConnectionName && dwNameLen > 0)
740 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
742 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
744 if (rc && lpwszConnectionName)
746 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
747 dwNameLen, NULL, NULL);
749 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
756 /***********************************************************************
757 * InternetConnectW (WININET.@)
759 * Open a ftp, gopher or http session
762 * HINTERNET a session handle on success
766 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
767 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
768 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
769 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
771 LPWININETAPPINFOW hIC;
774 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
775 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
776 dwService, dwFlags, dwContext);
780 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
784 /* Clear any error information */
785 INTERNET_SetLastError(0);
786 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
787 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
789 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
795 case INTERNET_SERVICE_FTP:
796 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
797 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
800 case INTERNET_SERVICE_HTTP:
801 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
802 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
805 case INTERNET_SERVICE_GOPHER:
811 WININET_Release( &hIC->hdr );
813 TRACE("returning %p\n", rc);
818 /***********************************************************************
819 * InternetConnectA (WININET.@)
821 * Open a ftp, gopher or http session
824 * HINTERNET a session handle on success
828 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
829 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
830 LPCSTR lpszUserName, LPCSTR lpszPassword,
831 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
833 HINTERNET rc = (HINTERNET)NULL;
835 LPWSTR szServerName = NULL;
836 LPWSTR szUserName = NULL;
837 LPWSTR szPassword = NULL;
841 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
842 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
843 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
847 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
848 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
849 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
853 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
854 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
855 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
859 rc = InternetConnectW(hInternet, szServerName, nServerPort,
860 szUserName, szPassword, dwService, dwFlags, dwContext);
862 HeapFree(GetProcessHeap(), 0, szServerName);
863 HeapFree(GetProcessHeap(), 0, szUserName);
864 HeapFree(GetProcessHeap(), 0, szPassword);
869 /***********************************************************************
870 * InternetFindNextFileA (WININET.@)
872 * Continues a file search from a previous call to FindFirstFile
879 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
884 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
886 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
890 /***********************************************************************
891 * InternetFindNextFileW (WININET.@)
893 * Continues a file search from a previous call to FindFirstFile
900 static void AsyncFtpFindNextFileProc(WORKREQUEST *workRequest)
902 struct WORKREQ_FTPFINDNEXTW *req = &workRequest->u.FtpFindNextW;
903 LPWININETFTPFINDNEXTW lpwh = (LPWININETFTPFINDNEXTW) workRequest->hdr;
907 FTP_FindNextFileW(lpwh, req->lpFindFileData);
910 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
912 LPWININETAPPINFOW hIC = NULL;
913 LPWININETFTPFINDNEXTW lpwh;
914 BOOL bSuccess = FALSE;
918 lpwh = (LPWININETFTPFINDNEXTW) WININET_GetObject( hFind );
919 if (NULL == lpwh || lpwh->hdr.htype != WH_HFTPFINDNEXT)
921 FIXME("Only FTP supported\n");
922 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
926 hIC = lpwh->lpFtpSession->lpAppInfo;
927 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
929 WORKREQUEST workRequest;
930 struct WORKREQ_FTPFINDNEXTW *req;
932 workRequest.asyncproc = AsyncFtpFindNextFileProc;
933 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
934 req = &workRequest.u.FtpFindNextW;
935 req->lpFindFileData = lpvFindData;
937 bSuccess = INTERNET_AsyncCall(&workRequest);
941 bSuccess = FTP_FindNextFileW(lpwh, lpvFindData);
945 WININET_Release( &lpwh->hdr );
949 /***********************************************************************
950 * INTERNET_CloseHandle (internal)
952 * Close internet handle
958 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
960 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
964 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
965 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
966 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
967 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
968 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
969 HeapFree(GetProcessHeap(), 0, lpwai);
973 /***********************************************************************
974 * InternetCloseHandle (WININET.@)
976 * Generic close handle function
983 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
985 LPWININETHANDLEHEADER lpwh;
987 TRACE("%p\n",hInternet);
989 lpwh = WININET_GetObject( hInternet );
992 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
996 WININET_FreeHandle( hInternet );
997 WININET_Release( lpwh );
1003 /***********************************************************************
1004 * ConvertUrlComponentValue (Internal)
1006 * Helper function for InternetCrackUrlW
1009 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1010 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1011 LPCSTR lpszStart, LPCWSTR lpwszStart)
1013 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1014 if (*dwComponentLen != 0)
1016 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1017 if (*lppszComponent == NULL)
1019 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1021 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1023 *lppszComponent = NULL;
1024 *dwComponentLen = nASCIILength;
1028 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1029 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1030 (*lppszComponent)[ncpylen]=0;
1031 *dwComponentLen = ncpylen;
1037 /***********************************************************************
1038 * InternetCrackUrlA (WININET.@)
1040 * See InternetCrackUrlW.
1042 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1043 LPURL_COMPONENTSA lpUrlComponents)
1046 URL_COMPONENTSW UCW;
1049 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1051 if (!lpszUrl || !*lpszUrl)
1053 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1059 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1061 /* if dwUrlLength=-1 then nLength includes null but length to
1062 InternetCrackUrlW should not include it */
1063 if (dwUrlLength == -1) nLength--;
1065 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1066 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1068 memset(&UCW,0,sizeof(UCW));
1069 if(lpUrlComponents->dwHostNameLength!=0)
1070 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1071 if(lpUrlComponents->dwUserNameLength!=0)
1072 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1073 if(lpUrlComponents->dwPasswordLength!=0)
1074 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1075 if(lpUrlComponents->dwUrlPathLength!=0)
1076 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1077 if(lpUrlComponents->dwSchemeLength!=0)
1078 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1079 if(lpUrlComponents->dwExtraInfoLength!=0)
1080 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1081 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1083 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1087 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1088 UCW.lpszHostName, UCW.dwHostNameLength,
1090 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1091 UCW.lpszUserName, UCW.dwUserNameLength,
1093 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1094 UCW.lpszPassword, UCW.dwPasswordLength,
1096 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1097 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1099 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1100 UCW.lpszScheme, UCW.dwSchemeLength,
1102 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1103 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1105 lpUrlComponents->nScheme=UCW.nScheme;
1106 lpUrlComponents->nPort=UCW.nPort;
1107 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1109 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1110 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1111 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1112 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1113 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1118 static const WCHAR url_schemes[][7] =
1121 {'g','o','p','h','e','r',0},
1122 {'h','t','t','p',0},
1123 {'h','t','t','p','s',0},
1124 {'f','i','l','e',0},
1125 {'n','e','w','s',0},
1126 {'m','a','i','l','t','o',0},
1130 /***********************************************************************
1131 * GetInternetSchemeW (internal)
1137 * INTERNET_SCHEME_UNKNOWN on failure
1140 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1144 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1146 if(lpszScheme==NULL)
1147 return INTERNET_SCHEME_UNKNOWN;
1149 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1150 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1151 return INTERNET_SCHEME_FIRST + i;
1153 return INTERNET_SCHEME_UNKNOWN;
1156 /***********************************************************************
1157 * SetUrlComponentValueW (Internal)
1159 * Helper function for InternetCrackUrlW
1162 * lppszComponent [O] Holds the returned string
1163 * dwComponentLen [I] Holds the size of lppszComponent
1164 * [O] Holds the length of the string in lppszComponent without '\0'
1165 * lpszStart [I] Holds the string to copy from
1166 * len [I] Holds the length of lpszStart without '\0'
1173 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1175 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1177 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1180 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1182 if (*lppszComponent == NULL)
1184 *lppszComponent = (LPWSTR)lpszStart;
1185 *dwComponentLen = len;
1189 DWORD ncpylen = min((*dwComponentLen)-1, len);
1190 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1191 (*lppszComponent)[ncpylen] = '\0';
1192 *dwComponentLen = ncpylen;
1199 /***********************************************************************
1200 * InternetCrackUrlW (WININET.@)
1202 * Break up URL into its components
1208 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1209 LPURL_COMPONENTSW lpUC)
1213 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1216 LPCWSTR lpszParam = NULL;
1217 BOOL bIsAbsolute = FALSE;
1218 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1219 LPCWSTR lpszcp = NULL;
1220 LPWSTR lpszUrl_decode = NULL;
1221 DWORD dwUrlLength = dwUrlLength_orig;
1222 const WCHAR lpszSeparators[3]={';','?',0};
1223 const WCHAR lpszSlash[2]={'/',0};
1225 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1227 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1229 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1232 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1234 if (dwFlags & ICU_DECODE)
1236 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1237 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1239 lpszUrl = lpszUrl_decode;
1244 /* Determine if the URI is absolute. */
1245 while (*lpszap != '\0')
1247 if (isalnumW(*lpszap))
1252 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1259 lpszcp = lpszUrl; /* Relative url */
1265 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1266 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1268 /* Parse <params> */
1269 lpszParam = strpbrkW(lpszap, lpszSeparators);
1270 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1271 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1273 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1277 /* Get scheme first. */
1278 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1279 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1280 lpszUrl, lpszcp - lpszUrl);
1282 /* Eat ':' in protocol. */
1285 /* double slash indicates the net_loc portion is present */
1286 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1290 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1294 lpszNetLoc = min(lpszNetLoc, lpszParam);
1296 lpszNetLoc = lpszParam;
1298 else if (!lpszNetLoc)
1299 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1307 /* [<user>[<:password>]@]<host>[:<port>] */
1308 /* First find the user and password if they exist */
1310 lpszHost = strchrW(lpszcp, '@');
1311 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1313 /* username and password not specified. */
1314 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1315 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1317 else /* Parse out username and password */
1319 LPCWSTR lpszUser = lpszcp;
1320 LPCWSTR lpszPasswd = lpszHost;
1322 while (lpszcp < lpszHost)
1325 lpszPasswd = lpszcp;
1330 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1331 lpszUser, lpszPasswd - lpszUser);
1333 if (lpszPasswd != lpszHost)
1335 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1336 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1337 lpszHost - lpszPasswd);
1339 lpszcp++; /* Advance to beginning of host */
1342 /* Parse <host><:port> */
1345 lpszPort = lpszNetLoc;
1347 /* special case for res:// URLs: there is no port here, so the host is the
1348 entire string up to the first '/' */
1349 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1351 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1352 lpszHost, lpszPort - lpszHost);
1357 while (lpszcp < lpszNetLoc)
1365 /* If the scheme is "file" and the host is just one letter, it's not a host */
1366 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1369 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1374 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1375 lpszHost, lpszPort - lpszHost);
1376 if (lpszPort != lpszNetLoc)
1377 lpUC->nPort = atoiW(++lpszPort);
1378 else switch (lpUC->nScheme)
1380 case INTERNET_SCHEME_HTTP:
1381 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1383 case INTERNET_SCHEME_HTTPS:
1384 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1386 case INTERNET_SCHEME_FTP:
1387 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1389 case INTERNET_SCHEME_GOPHER:
1390 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1401 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1402 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1403 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1408 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1409 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1410 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1411 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1414 /* Here lpszcp points to:
1416 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1417 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1419 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1423 /* Only truncate the parameter list if it's already been saved
1424 * in lpUC->lpszExtraInfo.
1426 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1427 len = lpszParam - lpszcp;
1430 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1431 * newlines if necessary.
1433 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1434 if (lpsznewline != NULL)
1435 len = lpsznewline - lpszcp;
1437 len = dwUrlLength-(lpszcp-lpszUrl);
1439 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1444 lpUC->dwUrlPathLength = 0;
1447 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1448 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1449 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1450 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1451 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1453 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1457 /***********************************************************************
1458 * InternetAttemptConnect (WININET.@)
1460 * Attempt to make a connection to the internet
1463 * ERROR_SUCCESS on success
1464 * Error value on failure
1467 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1470 return ERROR_SUCCESS;
1474 /***********************************************************************
1475 * InternetCanonicalizeUrlA (WININET.@)
1477 * Escape unsafe characters and spaces
1484 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1485 LPDWORD lpdwBufferLength, DWORD dwFlags)
1488 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1489 if(dwFlags & ICU_DECODE)
1491 dwURLFlags |= URL_UNESCAPE;
1492 dwFlags &= ~ICU_DECODE;
1495 if(dwFlags & ICU_ESCAPE)
1497 dwURLFlags |= URL_UNESCAPE;
1498 dwFlags &= ~ICU_ESCAPE;
1500 if(dwFlags & ICU_BROWSER_MODE)
1502 dwURLFlags |= URL_BROWSER_MODE;
1503 dwFlags &= ~ICU_BROWSER_MODE;
1506 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1507 TRACE("%s %p %p %08x\n", debugstr_a(lpszUrl), lpszBuffer,
1508 lpdwBufferLength, dwURLFlags);
1510 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1511 dwFlags ^= ICU_NO_ENCODE;
1513 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1515 return (hr == S_OK) ? TRUE : FALSE;
1518 /***********************************************************************
1519 * InternetCanonicalizeUrlW (WININET.@)
1521 * Escape unsafe characters and spaces
1528 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1529 LPDWORD lpdwBufferLength, DWORD dwFlags)
1532 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1533 if(dwFlags & ICU_DECODE)
1535 dwURLFlags |= URL_UNESCAPE;
1536 dwFlags &= ~ICU_DECODE;
1539 if(dwFlags & ICU_ESCAPE)
1541 dwURLFlags |= URL_UNESCAPE;
1542 dwFlags &= ~ICU_ESCAPE;
1544 if(dwFlags & ICU_BROWSER_MODE)
1546 dwURLFlags |= URL_BROWSER_MODE;
1547 dwFlags &= ~ICU_BROWSER_MODE;
1550 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1551 TRACE("%s %p %p %08x\n", debugstr_w(lpszUrl), lpszBuffer,
1552 lpdwBufferLength, dwURLFlags);
1554 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1555 dwFlags ^= ICU_NO_ENCODE;
1557 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1559 return (hr == S_OK) ? TRUE : FALSE;
1562 static INTERNET_STATUS_CALLBACK set_status_callback(
1563 LPWININETHANDLEHEADER lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1565 INTERNET_STATUS_CALLBACK ret;
1567 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1568 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1570 ret = lpwh->lpfnStatusCB;
1571 lpwh->lpfnStatusCB = callback;
1576 /***********************************************************************
1577 * InternetSetStatusCallbackA (WININET.@)
1579 * Sets up a callback function which is called as progress is made
1580 * during an operation.
1583 * Previous callback or NULL on success
1584 * INTERNET_INVALID_STATUS_CALLBACK on failure
1587 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1588 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1590 INTERNET_STATUS_CALLBACK retVal;
1591 LPWININETHANDLEHEADER lpwh;
1593 TRACE("0x%08x\n", (ULONG)hInternet);
1595 if (!(lpwh = WININET_GetObject(hInternet)))
1596 return INTERNET_INVALID_STATUS_CALLBACK;
1598 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1600 WININET_Release( lpwh );
1604 /***********************************************************************
1605 * InternetSetStatusCallbackW (WININET.@)
1607 * Sets up a callback function which is called as progress is made
1608 * during an operation.
1611 * Previous callback or NULL on success
1612 * INTERNET_INVALID_STATUS_CALLBACK on failure
1615 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1616 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1618 INTERNET_STATUS_CALLBACK retVal;
1619 LPWININETHANDLEHEADER lpwh;
1621 TRACE("0x%08x\n", (ULONG)hInternet);
1623 if (!(lpwh = WININET_GetObject(hInternet)))
1624 return INTERNET_INVALID_STATUS_CALLBACK;
1626 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1628 WININET_Release( lpwh );
1632 /***********************************************************************
1633 * InternetSetFilePointer (WININET.@)
1635 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1636 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1642 /***********************************************************************
1643 * InternetWriteFile (WININET.@)
1645 * Write data to an open internet file
1652 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1653 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1655 BOOL retval = FALSE;
1657 LPWININETHANDLEHEADER lpwh;
1660 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1664 switch (lpwh->htype)
1668 LPWININETHTTPREQW lpwhr;
1669 lpwhr = (LPWININETHTTPREQW)lpwh;
1671 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite);
1672 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1673 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1675 WININET_Release( lpwh );
1681 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1690 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1691 retval = (res >= 0);
1692 *lpdwNumOfBytesWritten = retval ? res : 0;
1694 WININET_Release( lpwh );
1700 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1701 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1702 BOOL bWait, BOOL bSendCompletionStatus)
1704 BOOL retval = FALSE;
1707 LPWININETHTTPREQW lpwhr;
1709 /* FIXME: this should use NETCON functions! */
1710 switch (lpwh->htype)
1713 lpwhr = (LPWININETHTTPREQW)lpwh;
1715 if (!NETCON_recv(&lpwhr->netConnection, lpBuffer,
1716 min(dwNumOfBytesToRead, lpwhr->dwContentLength - lpwhr->dwContentRead),
1717 bWait ? MSG_WAITALL : 0, &bytes_read))
1720 if (((lpwhr->dwContentLength != -1) &&
1721 (lpwhr->dwContentRead != lpwhr->dwContentLength)))
1722 ERR("not all data received %d/%d\n", lpwhr->dwContentRead,
1723 lpwhr->dwContentLength);
1725 /* always returns TRUE, even if the network layer returns an
1727 *pdwNumOfBytesRead = 0;
1728 HTTP_FinishedReading(lpwhr);
1733 lpwhr->dwContentRead += bytes_read;
1734 *pdwNumOfBytesRead = bytes_read;
1735 if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
1736 retval = HTTP_FinishedReading(lpwhr);
1743 /* FIXME: FTP should use NETCON_ stuff */
1744 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1747 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1748 retval = (res >= 0);
1749 *pdwNumOfBytesRead = retval ? res : 0;
1757 if (bSendCompletionStatus)
1759 INTERNET_ASYNC_RESULT iar;
1761 iar.dwResult = retval;
1762 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1763 INTERNET_GetLastError();
1765 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1766 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1767 sizeof(INTERNET_ASYNC_RESULT));
1772 /***********************************************************************
1773 * InternetReadFile (WININET.@)
1775 * Read data from an open internet file
1782 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1783 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1785 LPWININETHANDLEHEADER lpwh;
1788 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1790 lpwh = WININET_GetObject( hFile );
1793 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1797 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1798 WININET_Release( lpwh );
1800 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1804 /***********************************************************************
1805 * InternetReadFileExA (WININET.@)
1807 * Read data from an open internet file
1810 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1811 * lpBuffersOut [I/O] Buffer.
1812 * dwFlags [I] Flags. See notes.
1813 * dwContext [I] Context for callbacks.
1820 * The parameter dwFlags include zero or more of the following flags:
1821 *|IRF_ASYNC - Makes the call asynchronous.
1822 *|IRF_SYNC - Makes the call synchronous.
1823 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1824 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1826 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1829 * InternetOpenUrlA(), HttpOpenRequestA()
1831 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1833 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1835 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1837 INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1838 req->lpBuffersOut->dwBufferLength,
1839 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
1842 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1843 DWORD dwFlags, DWORD_PTR dwContext)
1845 BOOL retval = FALSE;
1846 LPWININETHANDLEHEADER lpwh;
1848 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1850 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1851 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1853 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1855 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1859 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1862 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1866 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1867 INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
1869 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1870 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1871 if (dwFlags & IRF_ASYNC)
1873 DWORD dwDataAvailable = 0;
1875 if (lpwh->htype == WH_HHTTPREQ)
1876 NETCON_query_data_available(&((LPWININETHTTPREQW)lpwh)->netConnection,
1879 if (!dwDataAvailable)
1881 WORKREQUEST workRequest;
1882 struct WORKREQ_INTERNETREADFILEEXA *req;
1884 workRequest.asyncproc = AsyncInternetReadFileExProc;
1885 workRequest.hdr = WININET_AddRef( lpwh );
1886 req = &workRequest.u.InternetReadFileExA;
1887 req->lpBuffersOut = lpBuffersOut;
1889 if (!INTERNET_AsyncCall(&workRequest))
1890 WININET_Release( lpwh );
1892 INTERNET_SetLastError(ERROR_IO_PENDING);
1897 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1898 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1899 !(dwFlags & IRF_NO_WAIT), FALSE);
1903 DWORD dwBytesReceived = lpBuffersOut->dwBufferLength;
1904 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1905 INTERNET_STATUS_RESPONSE_RECEIVED, &dwBytesReceived,
1906 sizeof(dwBytesReceived));
1910 WININET_Release( lpwh );
1912 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1916 /***********************************************************************
1917 * InternetReadFileExW (WININET.@)
1919 * Read data from an open internet file.
1922 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1923 * lpBuffersOut [I/O] Buffer.
1924 * dwFlags [I] Flags.
1925 * dwContext [I] Context for callbacks.
1928 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1931 * Not implemented in Wine or native either (as of IE6 SP2).
1934 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1935 DWORD dwFlags, DWORD_PTR dwContext)
1937 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1939 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1943 /***********************************************************************
1944 * INET_QueryOptionHelper (internal)
1946 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1947 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1949 LPWININETHANDLEHEADER lpwhh;
1950 BOOL bSuccess = FALSE;
1952 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1954 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1958 case INTERNET_OPTION_HANDLE_TYPE:
1964 WARN("Invalid hInternet handle\n");
1965 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1969 type = lpwhh->htype;
1971 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
1973 if (*lpdwBufferLength < sizeof(ULONG))
1974 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1977 memcpy(lpBuffer, &type, sizeof(ULONG));
1980 *lpdwBufferLength = sizeof(ULONG);
1984 case INTERNET_OPTION_REQUEST_FLAGS:
1987 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1988 if (*lpdwBufferLength < sizeof(ULONG))
1989 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1992 memcpy(lpBuffer, &flags, sizeof(ULONG));
1995 *lpdwBufferLength = sizeof(ULONG);
1999 case INTERNET_OPTION_URL:
2000 case INTERNET_OPTION_DATAFILE_NAME:
2004 WARN("Invalid hInternet handle\n");
2005 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2008 if (lpwhh->htype == WH_HHTTPREQ)
2010 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2012 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2013 static const WCHAR szHost[] = {'H','o','s','t',0};
2017 Host = HTTP_GetHeader(lpreq,szHost);
2018 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2019 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2022 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2023 lpBuffer,*lpdwBufferLength,NULL,NULL);
2024 if (sizeRequired > *lpdwBufferLength)
2025 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2028 *lpdwBufferLength = sizeRequired;
2032 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2033 if (*lpdwBufferLength < sizeRequired)
2034 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2037 strcpyW(lpBuffer, url);
2040 *lpdwBufferLength = sizeRequired;
2045 case INTERNET_OPTION_HTTP_VERSION:
2047 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2048 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2052 * Presently hardcoded to 1.1
2054 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2055 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2058 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2061 case INTERNET_OPTION_CONNECTED_STATE:
2063 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2064 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2066 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2067 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2070 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2073 *lpdwBufferLength = sizeof(*pdwConnectedState);
2076 case INTERNET_OPTION_PROXY:
2078 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2079 WININETAPPINFOW wai;
2083 TRACE("Getting global proxy info\n");
2084 memset(&wai, 0, sizeof(WININETAPPINFOW));
2085 INTERNET_ConfigureProxyFromReg( &wai );
2091 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2092 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2094 if (lpwai->lpszProxy)
2095 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2097 if (lpwai->lpszProxyBypass)
2098 proxyBypassBytesRequired =
2099 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2100 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2101 proxyBytesRequired + proxyBypassBytesRequired)
2102 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2105 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2106 sizeof(INTERNET_PROXY_INFOW));
2107 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2108 sizeof(INTERNET_PROXY_INFOW) +
2109 proxyBytesRequired);
2111 pPI->dwAccessType = lpwai->dwAccessType;
2112 pPI->lpszProxy = NULL;
2113 pPI->lpszProxyBypass = NULL;
2114 if (lpwai->lpszProxy)
2116 lstrcpyW(proxy, lpwai->lpszProxy);
2117 pPI->lpszProxy = proxy;
2120 if (lpwai->lpszProxyBypass)
2122 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2123 pPI->lpszProxyBypass = proxy_bypass;
2127 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2128 proxyBytesRequired + proxyBypassBytesRequired;
2132 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2133 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2135 if (lpwai->lpszProxy)
2136 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2137 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2138 if (lpwai->lpszProxyBypass)
2139 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2140 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2141 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2142 proxyBytesRequired + proxyBypassBytesRequired)
2143 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2146 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2147 sizeof(INTERNET_PROXY_INFOA));
2148 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2149 sizeof(INTERNET_PROXY_INFOA) +
2150 proxyBytesRequired);
2152 pPI->dwAccessType = lpwai->dwAccessType;
2153 pPI->lpszProxy = NULL;
2154 pPI->lpszProxyBypass = NULL;
2155 if (lpwai->lpszProxy)
2157 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2158 proxy, proxyBytesRequired, NULL, NULL);
2159 pPI->lpszProxy = proxy;
2162 if (lpwai->lpszProxyBypass)
2164 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2165 -1, proxy_bypass, proxyBypassBytesRequired,
2167 pPI->lpszProxyBypass = proxy_bypass;
2171 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2172 proxyBytesRequired + proxyBypassBytesRequired;
2176 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2179 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2180 if (*lpdwBufferLength < sizeof(ULONG))
2181 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2184 memcpy(lpBuffer, &conn, sizeof(ULONG));
2187 *lpdwBufferLength = sizeof(ULONG);
2190 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2193 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2194 if (*lpdwBufferLength < sizeof(ULONG))
2195 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2198 memcpy(lpBuffer, &conn, sizeof(ULONG));
2201 *lpdwBufferLength = sizeof(ULONG);
2204 case INTERNET_OPTION_SECURITY_FLAGS:
2205 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2208 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2211 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2214 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2216 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2217 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2219 else if (lpwhh->htype == WH_HHTTPREQ)
2221 LPWININETHTTPREQW lpwhr;
2222 PCCERT_CONTEXT context;
2224 lpwhr = (LPWININETHTTPREQW)lpwhh;
2225 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2228 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2231 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2232 info->ftExpiry = context->pCertInfo->NotAfter;
2233 info->ftStart = context->pCertInfo->NotBefore;
2236 strLen = CertNameToStrW(context->dwCertEncodingType,
2237 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2239 info->lpszSubjectInfo = LocalAlloc(0,
2240 strLen * sizeof(WCHAR));
2241 if (info->lpszSubjectInfo)
2242 CertNameToStrW(context->dwCertEncodingType,
2243 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2244 info->lpszSubjectInfo, strLen);
2245 strLen = CertNameToStrW(context->dwCertEncodingType,
2246 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2248 info->lpszIssuerInfo = LocalAlloc(0,
2249 strLen * sizeof(WCHAR));
2250 if (info->lpszIssuerInfo)
2251 CertNameToStrW(context->dwCertEncodingType,
2252 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2253 info->lpszIssuerInfo, strLen);
2257 LPINTERNET_CERTIFICATE_INFOA infoA =
2258 (LPINTERNET_CERTIFICATE_INFOA)info;
2260 strLen = CertNameToStrA(context->dwCertEncodingType,
2261 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2263 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2264 if (infoA->lpszSubjectInfo)
2265 CertNameToStrA(context->dwCertEncodingType,
2266 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2267 infoA->lpszSubjectInfo, strLen);
2268 strLen = CertNameToStrA(context->dwCertEncodingType,
2269 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2271 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2272 if (infoA->lpszIssuerInfo)
2273 CertNameToStrA(context->dwCertEncodingType,
2274 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2275 infoA->lpszIssuerInfo, strLen);
2278 * Contrary to MSDN, these do not appear to be set.
2280 * lpszSignatureAlgName
2281 * lpszEncryptionAlgName
2284 CertFreeCertificateContext(context);
2290 FIXME("Stub! %d\n", dwOption);
2294 WININET_Release( lpwhh );
2299 /***********************************************************************
2300 * InternetQueryOptionW (WININET.@)
2302 * Queries an options on the specified handle
2309 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2310 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2312 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2315 /***********************************************************************
2316 * InternetQueryOptionA (WININET.@)
2318 * Queries an options on the specified handle
2325 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2326 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2328 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2332 /***********************************************************************
2333 * InternetSetOptionW (WININET.@)
2335 * Sets an options on the specified handle
2342 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2343 LPVOID lpBuffer, DWORD dwBufferLength)
2345 LPWININETHANDLEHEADER lpwhh;
2348 TRACE("0x%08x\n", dwOption);
2350 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2356 case INTERNET_OPTION_CALLBACK:
2358 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2359 ret = (set_status_callback(lpwhh, callback, TRUE) != INTERNET_INVALID_STATUS_CALLBACK);
2362 case INTERNET_OPTION_HTTP_VERSION:
2364 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2365 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2368 case INTERNET_OPTION_ERROR_MASK:
2370 unsigned long flags=*(unsigned long*)lpBuffer;
2371 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2374 case INTERNET_OPTION_CODEPAGE:
2376 unsigned long codepage=*(unsigned long*)lpBuffer;
2377 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2380 case INTERNET_OPTION_REQUEST_PRIORITY:
2382 unsigned long priority=*(unsigned long*)lpBuffer;
2383 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2386 case INTERNET_OPTION_CONNECT_TIMEOUT:
2388 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2389 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2392 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2394 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2395 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2398 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2400 unsigned long conns=*(unsigned long*)lpBuffer;
2401 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2404 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2406 unsigned long conns=*(unsigned long*)lpBuffer;
2407 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2410 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2411 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2413 case INTERNET_OPTION_END_BROWSER_SESSION:
2414 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2416 case INTERNET_OPTION_CONNECTED_STATE:
2417 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2419 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2420 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2422 case INTERNET_OPTION_SEND_TIMEOUT:
2423 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2424 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2425 if (dwBufferLength == sizeof(DWORD))
2427 if (lpwhh->htype == WH_HHTTPREQ)
2428 ret = NETCON_set_timeout(
2429 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2430 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2431 *(DWORD *)lpBuffer);
2434 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2440 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2444 case INTERNET_OPTION_CONNECT_RETRIES:
2445 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2447 case INTERNET_OPTION_CONTEXT_VALUE:
2448 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2450 case INTERNET_OPTION_SECURITY_FLAGS:
2451 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2454 FIXME("Option %d STUB\n",dwOption);
2455 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2459 WININET_Release( lpwhh );
2465 /***********************************************************************
2466 * InternetSetOptionA (WININET.@)
2468 * Sets an options on the specified handle.
2475 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2476 LPVOID lpBuffer, DWORD dwBufferLength)
2484 case INTERNET_OPTION_CALLBACK:
2486 LPWININETHANDLEHEADER lpwh;
2487 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2489 if (!(lpwh = (LPWININETHANDLEHEADER)WININET_GetObject(hInternet))) return FALSE;
2490 r = (set_status_callback(lpwh, callback, FALSE) != INTERNET_INVALID_STATUS_CALLBACK);
2491 WININET_Release(lpwh);
2494 case INTERNET_OPTION_PROXY:
2496 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2497 LPINTERNET_PROXY_INFOW piw;
2498 DWORD proxlen, prbylen;
2501 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2502 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2503 wlen = sizeof(*piw) + proxlen + prbylen;
2504 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2505 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2506 piw->dwAccessType = pi->dwAccessType;
2507 prox = (LPWSTR) &piw[1];
2508 prby = &prox[proxlen+1];
2509 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2510 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2511 piw->lpszProxy = prox;
2512 piw->lpszProxyBypass = prby;
2515 case INTERNET_OPTION_USER_AGENT:
2516 case INTERNET_OPTION_USERNAME:
2517 case INTERNET_OPTION_PASSWORD:
2518 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2520 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2521 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2526 wlen = dwBufferLength;
2529 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2531 if( lpBuffer != wbuffer )
2532 HeapFree( GetProcessHeap(), 0, wbuffer );
2538 /***********************************************************************
2539 * InternetSetOptionExA (WININET.@)
2541 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2542 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2544 FIXME("Flags %08x ignored\n", dwFlags);
2545 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2548 /***********************************************************************
2549 * InternetSetOptionExW (WININET.@)
2551 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2552 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2554 FIXME("Flags %08x ignored\n", dwFlags);
2555 if( dwFlags & ~ISO_VALID_FLAGS )
2557 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2560 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2563 static const WCHAR WININET_wkday[7][4] =
2564 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2565 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2566 static const WCHAR WININET_month[12][4] =
2567 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2568 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2569 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2571 /***********************************************************************
2572 * InternetTimeFromSystemTimeA (WININET.@)
2574 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2577 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2579 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2581 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2582 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2587 /***********************************************************************
2588 * InternetTimeFromSystemTimeW (WININET.@)
2590 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2592 static const WCHAR date[] =
2593 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2594 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2596 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2598 if (!time || !string) return FALSE;
2600 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2603 sprintfW( string, date,
2604 WININET_wkday[time->wDayOfWeek],
2606 WININET_month[time->wMonth - 1],
2615 /***********************************************************************
2616 * InternetTimeToSystemTimeA (WININET.@)
2618 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2624 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2626 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2627 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2631 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2632 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2633 HeapFree( GetProcessHeap(), 0, stringW );
2638 /***********************************************************************
2639 * InternetTimeToSystemTimeW (WININET.@)
2641 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2644 const WCHAR *s = string;
2647 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2649 if (!string || !time) return FALSE;
2651 /* Windows does this too */
2652 GetSystemTime( time );
2654 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2655 * a SYSTEMTIME structure.
2658 while (*s && !isalphaW( *s )) s++;
2659 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2660 time->wDayOfWeek = 7;
2662 for (i = 0; i < 7; i++)
2664 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2665 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2666 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2668 time->wDayOfWeek = i;
2673 if (time->wDayOfWeek > 6) return TRUE;
2674 while (*s && !isdigitW( *s )) s++;
2675 time->wDay = strtolW( s, &end, 10 );
2678 while (*s && !isalphaW( *s )) s++;
2679 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2682 for (i = 0; i < 12; i++)
2684 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2685 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2686 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2688 time->wMonth = i + 1;
2692 if (time->wMonth == 0) return TRUE;
2694 while (*s && !isdigitW( *s )) s++;
2695 if (*s == '\0') return TRUE;
2696 time->wYear = strtolW( s, &end, 10 );
2699 while (*s && !isdigitW( *s )) s++;
2700 if (*s == '\0') return TRUE;
2701 time->wHour = strtolW( s, &end, 10 );
2704 while (*s && !isdigitW( *s )) s++;
2705 if (*s == '\0') return TRUE;
2706 time->wMinute = strtolW( s, &end, 10 );
2709 while (*s && !isdigitW( *s )) s++;
2710 if (*s == '\0') return TRUE;
2711 time->wSecond = strtolW( s, &end, 10 );
2714 time->wMilliseconds = 0;
2718 /***********************************************************************
2719 * InternetCheckConnectionW (WININET.@)
2721 * Pings a requested host to check internet connection
2724 * TRUE on success and FALSE on failure. If a failure then
2725 * ERROR_NOT_CONNECTED is placed into GetLastError
2728 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2731 * this is a kludge which runs the resident ping program and reads the output.
2733 * Anyone have a better idea?
2737 static const CHAR ping[] = "ping -c 1 ";
2738 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2739 CHAR *command = NULL;
2747 * Crack or set the Address
2749 if (lpszUrl == NULL)
2752 * According to the doc we are supost to use the ip for the next
2753 * server in the WnInet internal server database. I have
2754 * no idea what that is or how to get it.
2756 * So someone needs to implement this.
2758 FIXME("Unimplemented with URL of NULL\n");
2763 URL_COMPONENTSW components;
2765 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2766 components.lpszHostName = (LPWSTR)&hostW;
2767 components.dwHostNameLength = 1024;
2769 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2772 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2776 * Build our ping command
2778 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2779 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2780 strcpy(command,ping);
2781 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2782 strcat(command,redirect);
2784 TRACE("Ping command is : %s\n",command);
2786 status = system(command);
2788 TRACE("Ping returned a code of %i\n",status);
2790 /* Ping return code of 0 indicates success */
2796 HeapFree( GetProcessHeap(), 0, command );
2798 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2804 /***********************************************************************
2805 * InternetCheckConnectionA (WININET.@)
2807 * Pings a requested host to check internet connection
2810 * TRUE on success and FALSE on failure. If a failure then
2811 * ERROR_NOT_CONNECTED is placed into GetLastError
2814 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2820 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2821 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2823 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2824 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2825 HeapFree(GetProcessHeap(), 0, szUrl);
2831 /**********************************************************
2832 * INTERNET_InternetOpenUrlW (internal)
2837 * handle of connection or NULL on failure
2839 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2840 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2842 URL_COMPONENTSW urlComponents;
2843 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2844 WCHAR password[1024], path[2048], extra[1024];
2845 HINTERNET client = NULL, client1 = NULL;
2847 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2848 dwHeadersLength, dwFlags, dwContext);
2850 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2851 urlComponents.lpszScheme = protocol;
2852 urlComponents.dwSchemeLength = 32;
2853 urlComponents.lpszHostName = hostName;
2854 urlComponents.dwHostNameLength = MAXHOSTNAME;
2855 urlComponents.lpszUserName = userName;
2856 urlComponents.dwUserNameLength = 1024;
2857 urlComponents.lpszPassword = password;
2858 urlComponents.dwPasswordLength = 1024;
2859 urlComponents.lpszUrlPath = path;
2860 urlComponents.dwUrlPathLength = 2048;
2861 urlComponents.lpszExtraInfo = extra;
2862 urlComponents.dwExtraInfoLength = 1024;
2863 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2865 switch(urlComponents.nScheme) {
2866 case INTERNET_SCHEME_FTP:
2867 if(urlComponents.nPort == 0)
2868 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2869 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2870 userName, password, dwFlags, dwContext, INET_OPENURL);
2873 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2874 if(client1 == NULL) {
2875 InternetCloseHandle(client);
2880 case INTERNET_SCHEME_HTTP:
2881 case INTERNET_SCHEME_HTTPS: {
2882 static const WCHAR szStars[] = { '*','/','*', 0 };
2883 LPCWSTR accept[2] = { szStars, NULL };
2884 if(urlComponents.nPort == 0) {
2885 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2886 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2888 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2890 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2891 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2892 userName, password, dwFlags, dwContext, INET_OPENURL);
2896 if (urlComponents.dwExtraInfoLength) {
2898 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2900 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2902 InternetCloseHandle(client);
2905 strcpyW(path_extra, urlComponents.lpszUrlPath);
2906 strcatW(path_extra, urlComponents.lpszExtraInfo);
2907 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2908 HeapFree(GetProcessHeap(), 0, path_extra);
2911 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2913 if(client1 == NULL) {
2914 InternetCloseHandle(client);
2917 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2918 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2919 GetLastError() != ERROR_IO_PENDING) {
2920 InternetCloseHandle(client1);
2925 case INTERNET_SCHEME_GOPHER:
2926 /* gopher doesn't seem to be implemented in wine, but it's supposed
2927 * to be supported by InternetOpenUrlA. */
2929 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2933 TRACE(" %p <--\n", client1);
2938 /**********************************************************
2939 * InternetOpenUrlW (WININET.@)
2944 * handle of connection or NULL on failure
2946 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2948 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2949 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
2953 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2954 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2955 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2956 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2959 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2960 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2962 HINTERNET ret = NULL;
2963 LPWININETAPPINFOW hIC = NULL;
2965 if (TRACE_ON(wininet)) {
2966 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2967 dwHeadersLength, dwFlags, dwContext);
2969 dump_INTERNET_FLAGS(dwFlags);
2974 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2978 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2979 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2980 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2984 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2985 WORKREQUEST workRequest;
2986 struct WORKREQ_INTERNETOPENURLW *req;
2988 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2989 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2990 req = &workRequest.u.InternetOpenUrlW;
2991 req->lpszUrl = WININET_strdupW(lpszUrl);
2993 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2995 req->lpszHeaders = 0;
2996 req->dwHeadersLength = dwHeadersLength;
2997 req->dwFlags = dwFlags;
2998 req->dwContext = dwContext;
3000 INTERNET_AsyncCall(&workRequest);
3002 * This is from windows.
3004 INTERNET_SetLastError(ERROR_IO_PENDING);
3006 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3011 WININET_Release( &hIC->hdr );
3012 TRACE(" %p <--\n", ret);
3017 /**********************************************************
3018 * InternetOpenUrlA (WININET.@)
3023 * handle of connection or NULL on failure
3025 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3026 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3028 HINTERNET rc = (HINTERNET)NULL;
3032 LPWSTR szUrl = NULL;
3033 LPWSTR szHeaders = NULL;
3038 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3039 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3041 return (HINTERNET)NULL;
3042 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3046 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3047 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3049 HeapFree(GetProcessHeap(), 0, szUrl);
3050 return (HINTERNET)NULL;
3052 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3055 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3056 lenHeaders, dwFlags, dwContext);
3058 HeapFree(GetProcessHeap(), 0, szUrl);
3059 HeapFree(GetProcessHeap(), 0, szHeaders);
3065 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3067 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3071 lpwite->dwError = 0;
3072 lpwite->response[0] = '\0';
3075 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3077 HeapFree(GetProcessHeap(), 0, lpwite);
3085 /***********************************************************************
3086 * INTERNET_SetLastError (internal)
3088 * Set last thread specific error
3093 void INTERNET_SetLastError(DWORD dwError)
3095 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3098 lpwite = INTERNET_AllocThreadError();
3100 SetLastError(dwError);
3102 lpwite->dwError = dwError;
3106 /***********************************************************************
3107 * INTERNET_GetLastError (internal)
3109 * Get last thread specific error
3114 DWORD INTERNET_GetLastError(void)
3116 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3117 if (!lpwite) return 0;
3118 /* TlsGetValue clears last error, so set it again here */
3119 SetLastError(lpwite->dwError);
3120 return lpwite->dwError;
3124 /***********************************************************************
3125 * INTERNET_WorkerThreadFunc (internal)
3127 * Worker thread execution function
3132 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3134 LPWORKREQUEST lpRequest = lpvParam;
3135 WORKREQUEST workRequest;
3139 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3140 HeapFree(GetProcessHeap(), 0, lpRequest);
3142 workRequest.asyncproc(&workRequest);
3144 WININET_Release( workRequest.hdr );
3149 /***********************************************************************
3150 * INTERNET_AsyncCall (internal)
3152 * Retrieves work request from queue
3157 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3160 LPWORKREQUEST lpNewRequest;
3164 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3168 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3170 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3173 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3174 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3181 /***********************************************************************
3182 * INTERNET_GetResponseBuffer (internal)
3187 LPSTR INTERNET_GetResponseBuffer(void)
3189 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3191 lpwite = INTERNET_AllocThreadError();
3193 return lpwite->response;
3196 /***********************************************************************
3197 * INTERNET_GetNextLine (internal)
3199 * Parse next line in directory string listing
3202 * Pointer to beginning of next line
3207 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3211 BOOL bSuccess = FALSE;
3213 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3218 FD_SET(nSocket, &infd);
3219 tv.tv_sec=RESPONSE_TIMEOUT;
3222 while (nRecv < MAX_REPLY_LEN)
3224 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3226 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3228 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3232 if (lpszBuffer[nRecv] == '\n')
3237 if (lpszBuffer[nRecv] != '\r')
3242 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3250 lpszBuffer[nRecv] = '\0';
3252 TRACE(":%d %s\n", nRecv, lpszBuffer);
3261 /**********************************************************
3262 * InternetQueryDataAvailable (WININET.@)
3264 * Determines how much data is available to be read.
3267 * TRUE on success, FALSE if an error occurred. If
3268 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3269 * no data is presently available, FALSE is returned with
3270 * the last error ERROR_IO_PENDING; a callback with status
3271 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3272 * data is available.
3274 void AsyncInternetQueryDataAvailableProc(WORKREQUEST *workRequest)
3276 LPWININETHTTPREQW lpwhr;
3277 INTERNET_ASYNC_RESULT iar;
3280 TRACE("INTERNETQUERYDATAAVAILABLE %p\n", workRequest->hdr);
3282 switch (workRequest->hdr->htype)
3285 lpwhr = (LPWININETHTTPREQW)workRequest->hdr;
3286 iar.dwResult = NETCON_recv(&lpwhr->netConnection, buffer,
3288 lpwhr->dwContentLength - lpwhr->dwContentRead),
3289 MSG_PEEK, (int *)&iar.dwError);
3290 INTERNET_SendCallback(workRequest->hdr, workRequest->hdr->dwContext,
3291 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
3292 sizeof(INTERNET_ASYNC_RESULT));
3296 FIXME("unsupported file type\n");
3301 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3302 LPDWORD lpdwNumberOfBytesAvailble,
3303 DWORD dwFlags, DWORD_PTR dwContext)
3305 LPWININETHTTPREQW lpwhr;
3306 BOOL retval = FALSE;
3309 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3312 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3316 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3318 switch (lpwhr->hdr.htype)
3322 if (NETCON_query_data_available(&lpwhr->netConnection,
3323 lpdwNumberOfBytesAvailble) &&
3324 !*lpdwNumberOfBytesAvailble)
3326 /* Even if we are in async mode, we need to determine whether
3327 * there is actually more data available. We do this by trying
3328 * to peek only a single byte in async mode. */
3329 BOOL async = (lpwhr->lpHttpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC);
3330 if (NETCON_recv(&lpwhr->netConnection, buffer,
3331 min(async ? 1 : sizeof(buffer),
3332 lpwhr->dwContentLength - lpwhr->dwContentRead),
3333 MSG_PEEK, (int *)lpdwNumberOfBytesAvailble) &&
3334 async && *lpdwNumberOfBytesAvailble)
3336 WORKREQUEST workRequest;
3338 *lpdwNumberOfBytesAvailble = 0;
3339 workRequest.asyncproc = AsyncInternetQueryDataAvailableProc;
3340 workRequest.hdr = WININET_AddRef( &lpwhr->hdr );
3342 retval = INTERNET_AsyncCall(&workRequest);
3345 WININET_Release( &lpwhr->hdr );
3349 INTERNET_SetLastError(ERROR_IO_PENDING);
3357 FIXME("unsupported file type\n");
3360 WININET_Release( &lpwhr->hdr );
3362 TRACE("<-- %i\n",retval);
3367 /***********************************************************************
3368 * InternetLockRequestFile (WININET.@)
3370 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3377 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3384 /***********************************************************************
3385 * InternetAutodial (WININET.@)
3387 * On windows this function is supposed to dial the default internet
3388 * connection. We don't want to have Wine dial out to the internet so
3389 * we return TRUE by default. It might be nice to check if we are connected.
3396 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3400 /* Tell that we are connected to the internet. */
3404 /***********************************************************************
3405 * InternetAutodialHangup (WININET.@)
3407 * Hangs up a connection made with InternetAutodial
3416 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3420 /* we didn't dial, we don't disconnect */
3424 /***********************************************************************
3425 * InternetCombineUrlA (WININET.@)
3427 * Combine a base URL with a relative URL
3435 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3436 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3441 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3443 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3444 dwFlags ^= ICU_NO_ENCODE;
3445 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3450 /***********************************************************************
3451 * InternetCombineUrlW (WININET.@)
3453 * Combine a base URL with a relative URL
3461 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3462 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3467 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3469 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3470 dwFlags ^= ICU_NO_ENCODE;
3471 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3476 /* max port num is 65535 => 5 digits */
3477 #define MAX_WORD_DIGITS 5
3479 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3480 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3481 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3482 (url)->dw##component##Length : strlen((url)->lpsz##component))
3484 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3486 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3487 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3489 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3490 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3492 if ((nScheme == INTERNET_SCHEME_FTP) &&
3493 (nPort == INTERNET_DEFAULT_FTP_PORT))
3495 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3496 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3499 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3505 /* opaque urls do not fit into the standard url hierarchy and don't have
3506 * two following slashes */
3507 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3509 return (nScheme != INTERNET_SCHEME_FTP) &&
3510 (nScheme != INTERNET_SCHEME_GOPHER) &&
3511 (nScheme != INTERNET_SCHEME_HTTP) &&
3512 (nScheme != INTERNET_SCHEME_HTTPS) &&
3513 (nScheme != INTERNET_SCHEME_FILE);
3516 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3519 if (scheme < INTERNET_SCHEME_FIRST)
3521 index = scheme - INTERNET_SCHEME_FIRST;
3522 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3524 return (LPCWSTR)&url_schemes[index];
3527 /* we can calculate using ansi strings because we're just
3528 * calculating string length, not size
3530 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3531 LPDWORD lpdwUrlLength)
3533 INTERNET_SCHEME nScheme;
3537 if (lpUrlComponents->lpszScheme)
3539 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3540 *lpdwUrlLength += dwLen;
3541 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3547 nScheme = lpUrlComponents->nScheme;
3549 if (nScheme == INTERNET_SCHEME_DEFAULT)
3550 nScheme = INTERNET_SCHEME_HTTP;
3551 scheme = INTERNET_GetSchemeString(nScheme);
3552 *lpdwUrlLength += strlenW(scheme);
3555 (*lpdwUrlLength)++; /* ':' */
3556 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3557 *lpdwUrlLength += strlen("//");
3559 if (lpUrlComponents->lpszUserName)
3561 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3562 *lpdwUrlLength += strlen("@");
3566 if (lpUrlComponents->lpszPassword)
3568 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3573 if (lpUrlComponents->lpszPassword)
3575 *lpdwUrlLength += strlen(":");
3576 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3579 if (lpUrlComponents->lpszHostName)
3581 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3583 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3585 char szPort[MAX_WORD_DIGITS+1];
3587 sprintf(szPort, "%d", lpUrlComponents->nPort);
3588 *lpdwUrlLength += strlen(szPort);
3589 *lpdwUrlLength += strlen(":");
3592 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3593 (*lpdwUrlLength)++; /* '/' */
3596 if (lpUrlComponents->lpszUrlPath)
3597 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3602 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3606 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3608 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3609 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3610 urlCompW->nScheme = lpUrlComponents->nScheme;
3611 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3612 urlCompW->nPort = lpUrlComponents->nPort;
3613 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3614 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3615 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3616 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3618 if (lpUrlComponents->lpszScheme)
3620 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3621 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3622 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3623 -1, urlCompW->lpszScheme, len);
3626 if (lpUrlComponents->lpszHostName)
3628 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3629 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3630 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3631 -1, urlCompW->lpszHostName, len);
3634 if (lpUrlComponents->lpszUserName)
3636 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3637 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3638 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3639 -1, urlCompW->lpszUserName, len);
3642 if (lpUrlComponents->lpszPassword)
3644 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3645 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3646 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3647 -1, urlCompW->lpszPassword, len);
3650 if (lpUrlComponents->lpszUrlPath)
3652 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3653 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3654 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3655 -1, urlCompW->lpszUrlPath, len);
3658 if (lpUrlComponents->lpszExtraInfo)
3660 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3661 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3662 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3663 -1, urlCompW->lpszExtraInfo, len);
3667 /***********************************************************************
3668 * InternetCreateUrlA (WININET.@)
3670 * See InternetCreateUrlW.
3672 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3673 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3677 URL_COMPONENTSW urlCompW;
3679 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3681 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3683 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3687 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3690 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3692 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3694 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3695 *lpdwUrlLength /= sizeof(WCHAR);
3697 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3698 * minus one, so add one to leave room for NULL terminator
3701 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3703 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3704 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3705 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3706 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3707 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3708 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3709 HeapFree(GetProcessHeap(), 0, urlW);
3714 /***********************************************************************
3715 * InternetCreateUrlW (WININET.@)
3717 * Creates a URL from its component parts.
3720 * lpUrlComponents [I] URL Components.
3721 * dwFlags [I] Flags. See notes.
3722 * lpszUrl [I] Buffer in which to store the created URL.
3723 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3724 * lpszUrl in characters. On output, the number of bytes
3725 * required to store the URL including terminator.
3729 * The dwFlags parameter can be zero or more of the following:
3730 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3737 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3738 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3741 INTERNET_SCHEME nScheme;
3743 static const WCHAR slashSlashW[] = {'/','/'};
3744 static const WCHAR percentD[] = {'%','d',0};
3746 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3748 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3750 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3754 if (!calc_url_length(lpUrlComponents, &dwLen))
3757 if (!lpszUrl || *lpdwUrlLength < dwLen)
3759 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3760 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3764 *lpdwUrlLength = dwLen;
3769 if (lpUrlComponents->lpszScheme)
3771 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3772 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3775 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3780 nScheme = lpUrlComponents->nScheme;
3782 if (nScheme == INTERNET_SCHEME_DEFAULT)
3783 nScheme = INTERNET_SCHEME_HTTP;
3785 scheme = INTERNET_GetSchemeString(nScheme);
3786 dwLen = strlenW(scheme);
3787 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3791 /* all schemes are followed by at least a colon */
3795 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3797 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3798 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3801 if (lpUrlComponents->lpszUserName)
3803 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3804 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3807 if (lpUrlComponents->lpszPassword)
3812 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3813 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3821 if (lpUrlComponents->lpszHostName)
3823 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3824 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3827 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3829 WCHAR szPort[MAX_WORD_DIGITS+1];
3831 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3834 dwLen = strlenW(szPort);
3835 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3839 /* add slash between hostname and path if necessary */
3840 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3848 if (lpUrlComponents->lpszUrlPath)
3850 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3851 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3860 /***********************************************************************
3861 * InternetConfirmZoneCrossingA (WININET.@)
3864 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3866 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3867 return ERROR_SUCCESS;
3870 /***********************************************************************
3871 * InternetConfirmZoneCrossingW (WININET.@)
3874 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3876 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3877 return ERROR_SUCCESS;
3880 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3881 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3883 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3884 lpdwConnection, dwReserved);
3885 return ERROR_SUCCESS;
3888 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3889 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3891 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3892 lpdwConnection, dwReserved);
3893 return ERROR_SUCCESS;
3896 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3898 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3902 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3904 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3908 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3910 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3911 return ERROR_SUCCESS;
3914 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3917 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3918 debugstr_w(pwszTarget), pbHexHash);
3922 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3924 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3928 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
3930 FIXME("(%p, %08lx) stub\n", a, b);