4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
57 #include "wine/debug.h"
59 #define NO_SHLWAPI_STREAM
62 #include "wine/exception.h"
68 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define 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 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 TRACE( "destroying object %p\n", info);
177 info->destroy( info );
182 BOOL WININET_FreeHandle( HINTERNET hinternet )
185 UINT handle = (UINT) hinternet;
186 LPWININETHANDLEHEADER info = NULL;
188 EnterCriticalSection( &WININET_cs );
190 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
193 if( WININET_Handles[handle] )
195 info = WININET_Handles[handle];
196 TRACE( "destroying handle %d for object %p\n", handle+1, info);
197 WININET_Handles[handle] = NULL;
199 if( WININET_dwNextHandle > handle )
200 WININET_dwNextHandle = handle;
204 LeaveCriticalSection( &WININET_cs );
207 WININET_Release( info );
212 /***********************************************************************
213 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
216 * hinstDLL [I] handle to the DLL's instance
218 * lpvReserved [I] reserved, must be NULL
225 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
227 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
230 case DLL_PROCESS_ATTACH:
232 g_dwTlsErrIndex = TlsAlloc();
234 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
237 URLCacheContainers_CreateDefaults();
239 WININET_hModule = (HMODULE)hinstDLL;
241 case DLL_THREAD_ATTACH:
244 case DLL_THREAD_DETACH:
245 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
247 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
248 HeapFree(GetProcessHeap(), 0, lpwite);
252 case DLL_PROCESS_DETACH:
254 URLCacheContainers_DeleteAll();
256 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
258 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
259 TlsFree(g_dwTlsErrIndex);
268 /***********************************************************************
269 * InternetInitializeAutoProxyDll (WININET.@)
271 * Setup the internal proxy
280 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
283 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
287 /***********************************************************************
288 * DetectAutoProxyUrl (WININET.@)
290 * Auto detect the proxy url
296 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
297 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
300 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
305 /***********************************************************************
306 * INTERNET_ConfigureProxyFromReg
309 * The proxy may be specified in the form 'http=proxy.my.org'
310 * Presumably that means there can be ftp=ftpproxy.my.org too.
312 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
315 DWORD r, keytype, len, enabled;
316 LPCSTR lpszInternetSettings =
317 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
318 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
320 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
321 if ( r != ERROR_SUCCESS )
324 len = sizeof enabled;
325 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
326 (BYTE*)&enabled, &len);
327 if( (r == ERROR_SUCCESS) && enabled )
329 TRACE("Proxy is enabled.\n");
331 /* figure out how much memory the proxy setting takes */
332 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
334 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
337 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
339 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
340 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
341 (BYTE*)szProxy, &len);
343 /* find the http proxy, and strip away everything else */
344 p = strstrW( szProxy, szHttp );
347 p += lstrlenW(szHttp);
348 lstrcpyW( szProxy, p );
350 p = strchrW( szProxy, ' ' );
354 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
355 lpwai->lpszProxy = szProxy;
357 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
360 ERR("Couldn't read proxy server settings.\n");
363 TRACE("Proxy is not enabled.\n");
369 /***********************************************************************
370 * dump_INTERNET_FLAGS
372 * Helper function to TRACE the internet flags.
378 static void dump_INTERNET_FLAGS(DWORD dwFlags)
380 #define FE(x) { x, #x }
381 static const wininet_flag_info flag[] = {
382 FE(INTERNET_FLAG_RELOAD),
383 FE(INTERNET_FLAG_RAW_DATA),
384 FE(INTERNET_FLAG_EXISTING_CONNECT),
385 FE(INTERNET_FLAG_ASYNC),
386 FE(INTERNET_FLAG_PASSIVE),
387 FE(INTERNET_FLAG_NO_CACHE_WRITE),
388 FE(INTERNET_FLAG_MAKE_PERSISTENT),
389 FE(INTERNET_FLAG_FROM_CACHE),
390 FE(INTERNET_FLAG_SECURE),
391 FE(INTERNET_FLAG_KEEP_CONNECTION),
392 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
393 FE(INTERNET_FLAG_READ_PREFETCH),
394 FE(INTERNET_FLAG_NO_COOKIES),
395 FE(INTERNET_FLAG_NO_AUTH),
396 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
397 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
398 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
399 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
400 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
401 FE(INTERNET_FLAG_RESYNCHRONIZE),
402 FE(INTERNET_FLAG_HYPERLINK),
403 FE(INTERNET_FLAG_NO_UI),
404 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
405 FE(INTERNET_FLAG_CACHE_ASYNC),
406 FE(INTERNET_FLAG_FORMS_SUBMIT),
407 FE(INTERNET_FLAG_NEED_FILE),
408 FE(INTERNET_FLAG_TRANSFER_ASCII),
409 FE(INTERNET_FLAG_TRANSFER_BINARY)
414 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
415 if (flag[i].val & dwFlags) {
416 TRACE(" %s", flag[i].name);
417 dwFlags &= ~flag[i].val;
421 TRACE(" Unknown flags (%08x)\n", dwFlags);
426 /***********************************************************************
427 * InternetOpenW (WININET.@)
429 * Per-application initialization of wininet
432 * HINTERNET on success
436 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
437 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
439 LPWININETAPPINFOW lpwai = NULL;
440 HINTERNET handle = NULL;
442 if (TRACE_ON(wininet)) {
443 #define FE(x) { x, #x }
444 static const wininet_flag_info access_type[] = {
445 FE(INTERNET_OPEN_TYPE_PRECONFIG),
446 FE(INTERNET_OPEN_TYPE_DIRECT),
447 FE(INTERNET_OPEN_TYPE_PROXY),
448 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
452 const char *access_type_str = "Unknown";
454 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
455 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
456 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
457 if (access_type[i].val == dwAccessType) {
458 access_type_str = access_type[i].name;
462 TRACE(" access type : %s\n", access_type_str);
464 dump_INTERNET_FLAGS(dwFlags);
467 /* Clear any error information */
468 INTERNET_SetLastError(0);
470 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
473 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
477 lpwai->hdr.htype = WH_HINIT;
478 lpwai->hdr.dwFlags = dwFlags;
479 lpwai->hdr.dwRefCount = 1;
480 lpwai->hdr.destroy = INTERNET_CloseHandle;
481 lpwai->dwAccessType = dwAccessType;
482 lpwai->lpszProxyUsername = NULL;
483 lpwai->lpszProxyPassword = NULL;
485 handle = WININET_AllocHandle( &lpwai->hdr );
488 HeapFree( GetProcessHeap(), 0, lpwai );
489 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
493 if (NULL != lpszAgent)
495 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
496 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
497 if (lpwai->lpszAgent)
498 lstrcpyW( lpwai->lpszAgent, lpszAgent );
500 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
501 INTERNET_ConfigureProxyFromReg( lpwai );
502 else if (NULL != lpszProxy)
504 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
505 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
506 if (lpwai->lpszProxy)
507 lstrcpyW( lpwai->lpszProxy, lpszProxy );
510 if (NULL != lpszProxyBypass)
512 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
513 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
514 if (lpwai->lpszProxyBypass)
515 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
520 WININET_Release( &lpwai->hdr );
522 TRACE("returning %p\n", lpwai);
528 /***********************************************************************
529 * InternetOpenA (WININET.@)
531 * Per-application initialization of wininet
534 * HINTERNET on success
538 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
539 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
541 HINTERNET rc = (HINTERNET)NULL;
543 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
545 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
546 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
550 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
551 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
552 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
557 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
558 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
559 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
562 if( lpszProxyBypass )
564 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
565 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
566 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
569 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
571 HeapFree(GetProcessHeap(), 0, szAgent);
572 HeapFree(GetProcessHeap(), 0, szProxy);
573 HeapFree(GetProcessHeap(), 0, szBypass);
578 /***********************************************************************
579 * InternetGetLastResponseInfoA (WININET.@)
581 * Return last wininet error description on the calling thread
584 * TRUE on success of writing to buffer
588 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
589 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
591 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
597 *lpdwError = lpwite->dwError;
600 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
601 *lpdwBufferLength = strlen(lpszBuffer);
604 *lpdwBufferLength = 0;
609 *lpdwBufferLength = 0;
615 /***********************************************************************
616 * InternetGetLastResponseInfoW (WININET.@)
618 * Return last wininet error description on the calling thread
621 * TRUE on success of writing to buffer
625 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
626 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
628 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
634 *lpdwError = lpwite->dwError;
637 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
638 *lpdwBufferLength = lstrlenW(lpszBuffer);
641 *lpdwBufferLength = 0;
646 *lpdwBufferLength = 0;
652 /***********************************************************************
653 * InternetGetConnectedState (WININET.@)
655 * Return connected state
659 * if lpdwStatus is not null, return the status (off line,
660 * modem, lan...) in it.
661 * FALSE if not connected
663 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
665 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
668 FIXME("always returning LAN connection.\n");
669 *lpdwStatus = INTERNET_CONNECTION_LAN;
675 /***********************************************************************
676 * InternetGetConnectedStateExW (WININET.@)
678 * Return connected state
682 * lpdwStatus [O] Flags specifying the status of the internet connection.
683 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
684 * dwNameLen [I] Size of the buffer, in characters.
685 * dwReserved [I] Reserved. Must be set to 0.
689 * if lpdwStatus is not null, return the status (off line,
690 * modem, lan...) in it.
691 * FALSE if not connected
694 * If the system has no available network connections, an empty string is
695 * stored in lpszConnectionName. If there is a LAN connection, a localized
696 * "LAN Connection" string is stored. Presumably, if only a dial-up
697 * connection is available then the name of the dial-up connection is
698 * returned. Why any application, other than the "Internet Settings" CPL,
699 * would want to use this function instead of the simpler InternetGetConnectedStateW
700 * function is beyond me.
702 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
703 DWORD dwNameLen, DWORD dwReserved)
705 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
712 FIXME("always returning LAN connection.\n");
713 *lpdwStatus = INTERNET_CONNECTION_LAN;
715 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
719 /***********************************************************************
720 * InternetGetConnectedStateExA (WININET.@)
722 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
723 DWORD dwNameLen, DWORD dwReserved)
725 LPWSTR lpwszConnectionName = NULL;
728 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
730 if (lpszConnectionName && dwNameLen > 0)
731 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
733 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
735 if (rc && lpwszConnectionName)
737 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
738 dwNameLen, NULL, NULL);
740 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
747 /***********************************************************************
748 * InternetConnectW (WININET.@)
750 * Open a ftp, gopher or http session
753 * HINTERNET a session handle on success
757 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
758 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
759 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
760 DWORD dwService, DWORD dwFlags, DWORD dwContext)
762 LPWININETAPPINFOW hIC;
765 TRACE("(%p, %s, %i, %s, %s, %i, %i, %i)\n", hInternet, debugstr_w(lpszServerName),
766 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
767 dwService, dwFlags, dwContext);
771 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
775 /* Clear any error information */
776 INTERNET_SetLastError(0);
777 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
778 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
780 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
786 case INTERNET_SERVICE_FTP:
787 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
788 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
791 case INTERNET_SERVICE_HTTP:
792 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
793 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
796 case INTERNET_SERVICE_GOPHER:
802 WININET_Release( &hIC->hdr );
804 TRACE("returning %p\n", rc);
809 /***********************************************************************
810 * InternetConnectA (WININET.@)
812 * Open a ftp, gopher or http session
815 * HINTERNET a session handle on success
819 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
820 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
821 LPCSTR lpszUserName, LPCSTR lpszPassword,
822 DWORD dwService, DWORD dwFlags, DWORD dwContext)
824 HINTERNET rc = (HINTERNET)NULL;
826 LPWSTR szServerName = NULL;
827 LPWSTR szUserName = NULL;
828 LPWSTR szPassword = NULL;
832 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
833 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
834 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
838 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
839 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
840 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
844 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
845 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
846 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
850 rc = InternetConnectW(hInternet, szServerName, nServerPort,
851 szUserName, szPassword, dwService, dwFlags, dwContext);
853 HeapFree(GetProcessHeap(), 0, szServerName);
854 HeapFree(GetProcessHeap(), 0, szUserName);
855 HeapFree(GetProcessHeap(), 0, szPassword);
860 /***********************************************************************
861 * InternetFindNextFileA (WININET.@)
863 * Continues a file search from a previous call to FindFirstFile
870 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
875 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
877 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
881 /***********************************************************************
882 * InternetFindNextFileW (WININET.@)
884 * Continues a file search from a previous call to FindFirstFile
891 static void AsyncFtpFindNextFileProc(WORKREQUEST *workRequest)
893 struct WORKREQ_FTPFINDNEXTW *req = &workRequest->u.FtpFindNextW;
894 LPWININETFTPFINDNEXTW lpwh = (LPWININETFTPFINDNEXTW) workRequest->hdr;
898 FTP_FindNextFileW(lpwh, req->lpFindFileData);
901 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
903 LPWININETAPPINFOW hIC = NULL;
904 LPWININETFTPFINDNEXTW lpwh;
905 BOOL bSuccess = FALSE;
909 lpwh = (LPWININETFTPFINDNEXTW) WININET_GetObject( hFind );
910 if (NULL == lpwh || lpwh->hdr.htype != WH_HFTPFINDNEXT)
912 FIXME("Only FTP supported\n");
913 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
917 hIC = lpwh->lpFtpSession->lpAppInfo;
918 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
920 WORKREQUEST workRequest;
921 struct WORKREQ_FTPFINDNEXTW *req;
923 workRequest.asyncproc = AsyncFtpFindNextFileProc;
924 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
925 req = &workRequest.u.FtpFindNextW;
926 req->lpFindFileData = lpvFindData;
928 bSuccess = INTERNET_AsyncCall(&workRequest);
932 bSuccess = FTP_FindNextFileW(lpwh, lpvFindData);
936 WININET_Release( &lpwh->hdr );
940 /***********************************************************************
941 * INTERNET_CloseHandle (internal)
943 * Close internet handle
949 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
951 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
955 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
956 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
957 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
958 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
959 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
960 HeapFree(GetProcessHeap(), 0, lpwai);
964 /***********************************************************************
965 * InternetCloseHandle (WININET.@)
967 * Generic close handle function
974 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
976 LPWININETHANDLEHEADER lpwh;
978 TRACE("%p\n",hInternet);
980 lpwh = WININET_GetObject( hInternet );
983 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
987 /* FIXME: native appears to send this from the equivalent of
989 INTERNET_SendCallback(lpwh, lpwh->dwContext,
990 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
993 WININET_FreeHandle( hInternet );
994 WININET_Release( lpwh );
1000 /***********************************************************************
1001 * ConvertUrlComponentValue (Internal)
1003 * Helper function for InternetCrackUrlW
1006 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1007 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1008 LPCSTR lpszStart, LPCWSTR lpwszStart)
1010 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1011 if (*dwComponentLen != 0)
1013 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1014 if (*lppszComponent == NULL)
1016 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1018 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1020 *lppszComponent = NULL;
1021 *dwComponentLen = nASCIILength;
1025 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1026 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1027 (*lppszComponent)[ncpylen]=0;
1028 *dwComponentLen = ncpylen;
1034 /***********************************************************************
1035 * InternetCrackUrlA (WININET.@)
1037 * See InternetCrackUrlW.
1039 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1040 LPURL_COMPONENTSA lpUrlComponents)
1043 URL_COMPONENTSW UCW;
1046 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1049 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1051 /* if dwUrlLength=-1 then nLength includes null but length to
1052 InternetCrackUrlW should not include it */
1053 if (dwUrlLength == -1) nLength--;
1055 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1056 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1058 memset(&UCW,0,sizeof(UCW));
1059 if(lpUrlComponents->dwHostNameLength!=0)
1060 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1061 if(lpUrlComponents->dwUserNameLength!=0)
1062 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1063 if(lpUrlComponents->dwPasswordLength!=0)
1064 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1065 if(lpUrlComponents->dwUrlPathLength!=0)
1066 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1067 if(lpUrlComponents->dwSchemeLength!=0)
1068 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1069 if(lpUrlComponents->dwExtraInfoLength!=0)
1070 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1071 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1073 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1077 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1078 UCW.lpszHostName, UCW.dwHostNameLength,
1080 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1081 UCW.lpszUserName, UCW.dwUserNameLength,
1083 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1084 UCW.lpszPassword, UCW.dwPasswordLength,
1086 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1087 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1089 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1090 UCW.lpszScheme, UCW.dwSchemeLength,
1092 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1093 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1095 lpUrlComponents->nScheme=UCW.nScheme;
1096 lpUrlComponents->nPort=UCW.nPort;
1097 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1099 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1100 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1101 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1102 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1103 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1108 static const WCHAR url_schemes[][7] =
1111 {'g','o','p','h','e','r',0},
1112 {'h','t','t','p',0},
1113 {'h','t','t','p','s',0},
1114 {'f','i','l','e',0},
1115 {'n','e','w','s',0},
1116 {'m','a','i','l','t','o',0},
1120 /***********************************************************************
1121 * GetInternetSchemeW (internal)
1127 * INTERNET_SCHEME_UNKNOWN on failure
1130 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1134 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1136 if(lpszScheme==NULL)
1137 return INTERNET_SCHEME_UNKNOWN;
1139 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1140 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1141 return INTERNET_SCHEME_FIRST + i;
1143 return INTERNET_SCHEME_UNKNOWN;
1146 /***********************************************************************
1147 * SetUrlComponentValueW (Internal)
1149 * Helper function for InternetCrackUrlW
1152 * lppszComponent [O] Holds the returned string
1153 * dwComponentLen [I] Holds the size of lppszComponent
1154 * [O] Holds the length of the string in lppszComponent without '\0'
1155 * lpszStart [I] Holds the string to copy from
1156 * len [I] Holds the length of lpszStart without '\0'
1163 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1165 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1167 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1170 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1172 if (*lppszComponent == NULL)
1174 *lppszComponent = (LPWSTR)lpszStart;
1175 *dwComponentLen = len;
1179 DWORD ncpylen = min((*dwComponentLen)-1, len);
1180 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1181 (*lppszComponent)[ncpylen] = '\0';
1182 *dwComponentLen = ncpylen;
1189 /***********************************************************************
1190 * InternetCrackUrlW (WININET.@)
1192 * Break up URL into its components
1198 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1199 LPURL_COMPONENTSW lpUC)
1203 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1206 LPCWSTR lpszParam = NULL;
1207 BOOL bIsAbsolute = FALSE;
1208 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1209 LPCWSTR lpszcp = NULL;
1210 LPWSTR lpszUrl_decode = NULL;
1211 DWORD dwUrlLength = dwUrlLength_orig;
1212 const WCHAR lpszSeparators[3]={';','?',0};
1213 const WCHAR lpszSlash[2]={'/',0};
1215 dwUrlLength=strlenW(lpszUrl);
1217 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1219 if (!lpszUrl_orig || !*lpszUrl_orig)
1221 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1225 if (dwFlags & ICU_DECODE)
1227 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1228 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1230 lpszUrl = lpszUrl_decode;
1235 /* Determine if the URI is absolute. */
1236 while (*lpszap != '\0')
1238 if (isalnumW(*lpszap))
1243 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1250 lpszcp = lpszUrl; /* Relative url */
1256 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1257 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1259 /* Parse <params> */
1260 lpszParam = strpbrkW(lpszap, lpszSeparators);
1261 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1262 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1264 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1268 /* Get scheme first. */
1269 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1270 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1271 lpszUrl, lpszcp - lpszUrl);
1273 /* Eat ':' in protocol. */
1276 /* double slash indicates the net_loc portion is present */
1277 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1281 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1285 lpszNetLoc = min(lpszNetLoc, lpszParam);
1287 lpszNetLoc = lpszParam;
1289 else if (!lpszNetLoc)
1290 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1298 /* [<user>[<:password>]@]<host>[:<port>] */
1299 /* First find the user and password if they exist */
1301 lpszHost = strchrW(lpszcp, '@');
1302 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1304 /* username and password not specified. */
1305 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1306 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1308 else /* Parse out username and password */
1310 LPCWSTR lpszUser = lpszcp;
1311 LPCWSTR lpszPasswd = lpszHost;
1313 while (lpszcp < lpszHost)
1316 lpszPasswd = lpszcp;
1321 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1322 lpszUser, lpszPasswd - lpszUser);
1324 if (lpszPasswd != lpszHost)
1326 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1327 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1328 lpszHost - lpszPasswd);
1330 lpszcp++; /* Advance to beginning of host */
1333 /* Parse <host><:port> */
1336 lpszPort = lpszNetLoc;
1338 /* special case for res:// URLs: there is no port here, so the host is the
1339 entire string up to the first '/' */
1340 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1342 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1343 lpszHost, lpszPort - lpszHost);
1348 while (lpszcp < lpszNetLoc)
1356 /* If the scheme is "file" and the host is just one letter, it's not a host */
1357 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1360 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1365 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1366 lpszHost, lpszPort - lpszHost);
1367 if (lpszPort != lpszNetLoc)
1368 lpUC->nPort = atoiW(++lpszPort);
1369 else switch (lpUC->nScheme)
1371 case INTERNET_SCHEME_HTTP:
1372 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1374 case INTERNET_SCHEME_HTTPS:
1375 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1377 case INTERNET_SCHEME_FTP:
1378 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1380 case INTERNET_SCHEME_GOPHER:
1381 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1392 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1393 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1394 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1399 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1400 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1401 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1402 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1405 /* Here lpszcp points to:
1407 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1408 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1410 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1414 /* Only truncate the parameter list if it's already been saved
1415 * in lpUC->lpszExtraInfo.
1417 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1418 len = lpszParam - lpszcp;
1421 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1422 * newlines if necessary.
1424 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1425 if (lpsznewline != NULL)
1426 len = lpsznewline - lpszcp;
1428 len = dwUrlLength-(lpszcp-lpszUrl);
1430 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1435 lpUC->dwUrlPathLength = 0;
1438 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1439 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1440 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1441 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1442 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1444 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1448 /***********************************************************************
1449 * InternetAttemptConnect (WININET.@)
1451 * Attempt to make a connection to the internet
1454 * ERROR_SUCCESS on success
1455 * Error value on failure
1458 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1461 return ERROR_SUCCESS;
1465 /***********************************************************************
1466 * InternetCanonicalizeUrlA (WININET.@)
1468 * Escape unsafe characters and spaces
1475 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1476 LPDWORD lpdwBufferLength, DWORD dwFlags)
1479 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1480 if(dwFlags & ICU_DECODE)
1482 dwURLFlags |= URL_UNESCAPE;
1483 dwFlags &= ~ICU_DECODE;
1486 if(dwFlags & ICU_ESCAPE)
1488 dwURLFlags |= URL_UNESCAPE;
1489 dwFlags &= ~ICU_ESCAPE;
1491 if(dwFlags & ICU_BROWSER_MODE)
1493 dwURLFlags |= URL_BROWSER_MODE;
1494 dwFlags &= ~ICU_BROWSER_MODE;
1497 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1498 TRACE("%s %p %p %08x\n", debugstr_a(lpszUrl), lpszBuffer,
1499 lpdwBufferLength, dwURLFlags);
1501 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1502 dwFlags ^= ICU_NO_ENCODE;
1504 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1506 return (hr == S_OK) ? TRUE : FALSE;
1509 /***********************************************************************
1510 * InternetCanonicalizeUrlW (WININET.@)
1512 * Escape unsafe characters and spaces
1519 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1520 LPDWORD lpdwBufferLength, DWORD dwFlags)
1523 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1524 if(dwFlags & ICU_DECODE)
1526 dwURLFlags |= URL_UNESCAPE;
1527 dwFlags &= ~ICU_DECODE;
1530 if(dwFlags & ICU_ESCAPE)
1532 dwURLFlags |= URL_UNESCAPE;
1533 dwFlags &= ~ICU_ESCAPE;
1535 if(dwFlags & ICU_BROWSER_MODE)
1537 dwURLFlags |= URL_BROWSER_MODE;
1538 dwFlags &= ~ICU_BROWSER_MODE;
1541 FIXME("Unhandled flags 0x%08x\n", dwFlags);
1542 TRACE("%s %p %p %08x\n", debugstr_w(lpszUrl), lpszBuffer,
1543 lpdwBufferLength, dwURLFlags);
1545 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1546 dwFlags ^= ICU_NO_ENCODE;
1548 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1550 return (hr == S_OK) ? TRUE : FALSE;
1554 /***********************************************************************
1555 * InternetSetStatusCallbackA (WININET.@)
1557 * Sets up a callback function which is called as progress is made
1558 * during an operation.
1561 * Previous callback or NULL on success
1562 * INTERNET_INVALID_STATUS_CALLBACK on failure
1565 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1566 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1568 INTERNET_STATUS_CALLBACK retVal;
1569 LPWININETHANDLEHEADER lpwh;
1571 TRACE("0x%08x\n", (ULONG)hInternet);
1573 lpwh = WININET_GetObject(hInternet);
1575 return INTERNET_INVALID_STATUS_CALLBACK;
1577 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1578 retVal = lpwh->lpfnStatusCB;
1579 lpwh->lpfnStatusCB = lpfnIntCB;
1581 WININET_Release( lpwh );
1586 /***********************************************************************
1587 * InternetSetStatusCallbackW (WININET.@)
1589 * Sets up a callback function which is called as progress is made
1590 * during an operation.
1593 * Previous callback or NULL on success
1594 * INTERNET_INVALID_STATUS_CALLBACK on failure
1597 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1598 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1600 INTERNET_STATUS_CALLBACK retVal;
1601 LPWININETHANDLEHEADER lpwh;
1603 TRACE("0x%08x\n", (ULONG)hInternet);
1605 lpwh = WININET_GetObject(hInternet);
1607 return INTERNET_INVALID_STATUS_CALLBACK;
1609 lpwh->dwInternalFlags |= INET_CALLBACKW;
1610 retVal = lpwh->lpfnStatusCB;
1611 lpwh->lpfnStatusCB = lpfnIntCB;
1613 WININET_Release( lpwh );
1618 /***********************************************************************
1619 * InternetSetFilePointer (WININET.@)
1621 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1622 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1628 /***********************************************************************
1629 * InternetWriteFile (WININET.@)
1631 * Write data to an open internet file
1638 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1639 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1641 BOOL retval = FALSE;
1643 LPWININETHANDLEHEADER lpwh;
1646 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1650 switch (lpwh->htype)
1654 LPWININETHTTPREQW lpwhr;
1655 lpwhr = (LPWININETHTTPREQW)lpwh;
1657 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite);
1658 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1659 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1661 WININET_Release( lpwh );
1667 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1676 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1677 retval = (res >= 0);
1678 *lpdwNumOfBytesWritten = retval ? res : 0;
1680 WININET_Release( lpwh );
1686 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1687 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1688 BOOL bWait, BOOL bSendCompletionStatus)
1690 BOOL retval = FALSE;
1693 LPWININETHTTPREQW lpwhr;
1695 /* FIXME: this should use NETCON functions! */
1696 switch (lpwh->htype)
1699 lpwhr = (LPWININETHTTPREQW)lpwh;
1701 if (!NETCON_recv(&lpwhr->netConnection, lpBuffer,
1702 min(dwNumOfBytesToRead, lpwhr->dwContentLength - lpwhr->dwContentRead),
1703 bWait ? MSG_WAITALL : 0, &bytes_read))
1706 if (((lpwhr->dwContentLength != -1) &&
1707 (lpwhr->dwContentRead != lpwhr->dwContentLength)))
1708 ERR("not all data received %d/%d\n", lpwhr->dwContentRead,
1709 lpwhr->dwContentLength);
1711 /* always returns TRUE, even if the network layer returns an
1713 *pdwNumOfBytesRead = 0;
1714 HTTP_FinishedReading(lpwhr);
1719 lpwhr->dwContentRead += bytes_read;
1720 *pdwNumOfBytesRead = bytes_read;
1722 retval = HTTP_FinishedReading(lpwhr);
1729 /* FIXME: FTP should use NETCON_ stuff */
1730 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1733 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1734 retval = (res >= 0);
1735 *pdwNumOfBytesRead = retval ? res : 0;
1743 if (bSendCompletionStatus)
1745 INTERNET_ASYNC_RESULT iar;
1747 iar.dwResult = retval;
1748 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1749 INTERNET_GetLastError();
1751 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1752 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1753 sizeof(INTERNET_ASYNC_RESULT));
1758 /***********************************************************************
1759 * InternetReadFile (WININET.@)
1761 * Read data from an open internet file
1768 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1769 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1771 LPWININETHANDLEHEADER lpwh;
1774 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1776 lpwh = WININET_GetObject( hFile );
1779 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1783 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1784 WININET_Release( lpwh );
1786 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1790 /***********************************************************************
1791 * InternetReadFileExA (WININET.@)
1793 * Read data from an open internet file
1796 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1797 * lpBuffersOut [I/O] Buffer.
1798 * dwFlags [I] Flags. See notes.
1799 * dwContext [I] Context for callbacks.
1806 * The parameter dwFlags include zero or more of the following flags:
1807 *|IRF_ASYNC - Makes the call asynchronous.
1808 *|IRF_SYNC - Makes the call synchronous.
1809 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1810 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1812 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1815 * InternetOpenUrlA(), HttpOpenRequestA()
1817 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1819 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1821 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1823 INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1824 req->lpBuffersOut->dwBufferLength,
1825 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
1828 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1829 DWORD dwFlags, DWORD dwContext)
1831 BOOL retval = FALSE;
1832 LPWININETHANDLEHEADER lpwh;
1834 TRACE("(%p %p 0x%x 0x%x)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1836 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1837 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1839 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1841 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1845 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1848 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1852 /* FIXME: native only does it asynchronously if the amount of data
1853 * requested isn't available. See NtReadFile. */
1854 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1855 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1856 * we should implement the above first */
1857 if (dwFlags & IRF_ASYNC)
1859 WORKREQUEST workRequest;
1860 struct WORKREQ_INTERNETREADFILEEXA *req;
1862 workRequest.asyncproc = AsyncInternetReadFileExProc;
1863 workRequest.hdr = WININET_AddRef( lpwh );
1864 req = &workRequest.u.InternetReadFileExA;
1865 req->lpBuffersOut = lpBuffersOut;
1867 retval = INTERNET_AsyncCall(&workRequest);
1868 if (!retval) return FALSE;
1870 INTERNET_SetLastError(ERROR_IO_PENDING);
1874 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1875 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1876 !(dwFlags & IRF_NO_WAIT), FALSE);
1878 WININET_Release( lpwh );
1880 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1884 /***********************************************************************
1885 * InternetReadFileExW (WININET.@)
1887 * Read data from an open internet file.
1890 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1891 * lpBuffersOut [I/O] Buffer.
1892 * dwFlags [I] Flags.
1893 * dwContext [I] Context for callbacks.
1896 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1899 * Not implemented in Wine or native either (as of IE6 SP2).
1902 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1903 DWORD dwFlags, DWORD dwContext)
1905 ERR("(%p, %p, 0x%x, 0x%x): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1907 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1911 /***********************************************************************
1912 * INET_QueryOptionHelper (internal)
1914 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1915 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1917 LPWININETHANDLEHEADER lpwhh;
1918 BOOL bSuccess = FALSE;
1920 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1922 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1925 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1931 case INTERNET_OPTION_HANDLE_TYPE:
1937 WARN("Invalid hInternet handle\n");
1938 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1942 type = lpwhh->htype;
1944 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
1946 if (*lpdwBufferLength < sizeof(ULONG))
1947 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1950 memcpy(lpBuffer, &type, sizeof(ULONG));
1953 *lpdwBufferLength = sizeof(ULONG);
1957 case INTERNET_OPTION_REQUEST_FLAGS:
1960 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
1961 if (*lpdwBufferLength < sizeof(ULONG))
1962 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1965 memcpy(lpBuffer, &flags, sizeof(ULONG));
1968 *lpdwBufferLength = sizeof(ULONG);
1972 case INTERNET_OPTION_URL:
1973 case INTERNET_OPTION_DATAFILE_NAME:
1977 WARN("Invalid hInternet handle\n");
1978 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1981 if (lpwhh->htype == WH_HHTTPREQ)
1983 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
1985 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
1986 static const WCHAR szHost[] = {'H','o','s','t',0};
1990 Host = HTTP_GetHeader(lpreq,szHost);
1991 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
1992 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
1995 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
1996 lpBuffer,*lpdwBufferLength,NULL,NULL);
1997 if (sizeRequired > *lpdwBufferLength)
1998 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2001 *lpdwBufferLength = sizeRequired;
2005 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2006 if (*lpdwBufferLength < sizeRequired)
2007 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2010 strcpyW(lpBuffer, url);
2013 *lpdwBufferLength = sizeRequired;
2018 case INTERNET_OPTION_HTTP_VERSION:
2020 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2021 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2025 * Presently hardcoded to 1.1
2027 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2028 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2031 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2034 case INTERNET_OPTION_CONNECTED_STATE:
2036 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2037 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2039 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2040 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2043 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2046 *lpdwBufferLength = sizeof(*pdwConnectedState);
2049 case INTERNET_OPTION_PROXY:
2051 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2052 WININETAPPINFOW wai;
2056 TRACE("Getting global proxy info\n");
2057 memset(&wai, 0, sizeof(WININETAPPINFOW));
2058 INTERNET_ConfigureProxyFromReg( &wai );
2064 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2065 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2067 if (lpwai->lpszProxy)
2068 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2070 if (lpwai->lpszProxyBypass)
2071 proxyBypassBytesRequired =
2072 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2073 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2074 proxyBytesRequired + proxyBypassBytesRequired)
2075 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2078 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2079 sizeof(INTERNET_PROXY_INFOW));
2080 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2081 sizeof(INTERNET_PROXY_INFOW) +
2082 proxyBytesRequired);
2084 pPI->dwAccessType = lpwai->dwAccessType;
2085 if (lpwai->lpszProxy)
2087 lstrcpyW(proxy, lpwai->lpszProxy);
2093 pPI->lpszProxy = proxy;
2095 if (lpwai->lpszProxyBypass)
2097 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2103 pPI->lpszProxyBypass = proxy_bypass;
2106 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2107 proxyBytesRequired + proxyBypassBytesRequired;
2111 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2112 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2114 if (lpwai->lpszProxy)
2115 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2116 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2117 if (lpwai->lpszProxyBypass)
2118 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2119 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2120 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2121 proxyBytesRequired + proxyBypassBytesRequired)
2122 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2125 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2126 sizeof(INTERNET_PROXY_INFOA));
2127 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2128 sizeof(INTERNET_PROXY_INFOA) +
2129 proxyBytesRequired);
2131 pPI->dwAccessType = lpwai->dwAccessType;
2132 if (lpwai->lpszProxy)
2134 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2135 proxy, proxyBytesRequired, NULL, NULL);
2141 pPI->lpszProxy = proxy;
2143 if (lpwai->lpszProxyBypass)
2145 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2146 -1, proxy_bypass, proxyBypassBytesRequired,
2151 *proxy_bypass = '\0';
2153 pPI->lpszProxyBypass = proxy_bypass;
2156 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2157 proxyBytesRequired + proxyBypassBytesRequired;
2161 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2164 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2165 if (*lpdwBufferLength < sizeof(ULONG))
2166 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2169 memcpy(lpBuffer, &conn, sizeof(ULONG));
2172 *lpdwBufferLength = sizeof(ULONG);
2175 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2178 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2179 if (*lpdwBufferLength < sizeof(ULONG))
2180 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2183 memcpy(lpBuffer, &conn, sizeof(ULONG));
2186 *lpdwBufferLength = sizeof(ULONG);
2189 case INTERNET_OPTION_SECURITY_FLAGS:
2190 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2193 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2194 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2196 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2197 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2199 else if (lpwhh->htype == WH_HHTTPREQ)
2201 LPWININETHTTPREQW lpwhr;
2202 PCCERT_CONTEXT context;
2204 lpwhr = (LPWININETHTTPREQW)lpwhh;
2205 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2208 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2211 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2212 info->ftExpiry = context->pCertInfo->NotAfter;
2213 info->ftStart = context->pCertInfo->NotBefore;
2216 strLen = CertNameToStrW(context->dwCertEncodingType,
2217 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2219 info->lpszSubjectInfo = LocalAlloc(0,
2220 strLen * sizeof(WCHAR));
2221 if (info->lpszSubjectInfo)
2222 CertNameToStrW(context->dwCertEncodingType,
2223 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2224 info->lpszSubjectInfo, strLen);
2225 strLen = CertNameToStrW(context->dwCertEncodingType,
2226 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2228 info->lpszIssuerInfo = LocalAlloc(0,
2229 strLen * sizeof(WCHAR));
2230 if (info->lpszIssuerInfo)
2231 CertNameToStrW(context->dwCertEncodingType,
2232 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2233 info->lpszIssuerInfo, strLen);
2237 LPINTERNET_CERTIFICATE_INFOA infoA =
2238 (LPINTERNET_CERTIFICATE_INFOA)info;
2240 strLen = CertNameToStrA(context->dwCertEncodingType,
2241 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2243 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2244 if (infoA->lpszSubjectInfo)
2245 CertNameToStrA(context->dwCertEncodingType,
2246 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2247 infoA->lpszSubjectInfo, strLen);
2248 strLen = CertNameToStrA(context->dwCertEncodingType,
2249 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2251 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2252 if (infoA->lpszIssuerInfo)
2253 CertNameToStrA(context->dwCertEncodingType,
2254 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2255 infoA->lpszIssuerInfo, strLen);
2258 * Contrary to MSDN, these do not appear to be set.
2260 * lpszSignatureAlgName
2261 * lpszEncryptionAlgName
2264 CertFreeCertificateContext(context);
2270 FIXME("Stub! %d\n", dwOption);
2274 WININET_Release( lpwhh );
2279 /***********************************************************************
2280 * InternetQueryOptionW (WININET.@)
2282 * Queries an options on the specified handle
2289 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2290 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2292 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2295 /***********************************************************************
2296 * InternetQueryOptionA (WININET.@)
2298 * Queries an options on the specified handle
2305 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2306 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2308 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2312 /***********************************************************************
2313 * InternetSetOptionW (WININET.@)
2315 * Sets an options on the specified handle
2322 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2323 LPVOID lpBuffer, DWORD dwBufferLength)
2325 LPWININETHANDLEHEADER lpwhh;
2328 TRACE("0x%08x\n", dwOption);
2330 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2336 case INTERNET_OPTION_HTTP_VERSION:
2338 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2339 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2342 case INTERNET_OPTION_ERROR_MASK:
2344 unsigned long flags=*(unsigned long*)lpBuffer;
2345 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2348 case INTERNET_OPTION_CODEPAGE:
2350 unsigned long codepage=*(unsigned long*)lpBuffer;
2351 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2354 case INTERNET_OPTION_REQUEST_PRIORITY:
2356 unsigned long priority=*(unsigned long*)lpBuffer;
2357 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2360 case INTERNET_OPTION_CONNECT_TIMEOUT:
2362 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2363 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2366 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2368 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2369 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2372 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2374 unsigned long conns=*(unsigned long*)lpBuffer;
2375 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2378 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2380 unsigned long conns=*(unsigned long*)lpBuffer;
2381 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2384 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2385 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2387 case INTERNET_OPTION_END_BROWSER_SESSION:
2388 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2390 case INTERNET_OPTION_CONNECTED_STATE:
2391 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2393 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2394 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2396 case INTERNET_OPTION_SEND_TIMEOUT:
2397 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2398 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2399 if (dwBufferLength == sizeof(DWORD))
2401 if (lpwhh->htype == WH_HHTTPREQ)
2402 ret = NETCON_set_timeout(
2403 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2404 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2405 *(DWORD *)lpBuffer);
2408 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2414 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2418 case INTERNET_OPTION_CONNECT_RETRIES:
2419 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2421 case INTERNET_OPTION_CONTEXT_VALUE:
2422 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2424 case INTERNET_OPTION_SECURITY_FLAGS:
2425 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2428 FIXME("Option %d STUB\n",dwOption);
2429 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2433 WININET_Release( lpwhh );
2439 /***********************************************************************
2440 * InternetSetOptionA (WININET.@)
2442 * Sets an options on the specified handle.
2449 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2450 LPVOID lpBuffer, DWORD dwBufferLength)
2458 case INTERNET_OPTION_PROXY:
2460 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2461 LPINTERNET_PROXY_INFOW piw;
2462 DWORD proxlen, prbylen;
2465 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2466 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2467 wlen = sizeof(*piw) + proxlen + prbylen;
2468 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2469 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2470 piw->dwAccessType = pi->dwAccessType;
2471 prox = (LPWSTR) &piw[1];
2472 prby = &prox[proxlen+1];
2473 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2474 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2475 piw->lpszProxy = prox;
2476 piw->lpszProxyBypass = prby;
2479 case INTERNET_OPTION_USER_AGENT:
2480 case INTERNET_OPTION_USERNAME:
2481 case INTERNET_OPTION_PASSWORD:
2482 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2484 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2485 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2490 wlen = dwBufferLength;
2493 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2495 if( lpBuffer != wbuffer )
2496 HeapFree( GetProcessHeap(), 0, wbuffer );
2502 /***********************************************************************
2503 * InternetSetOptionExA (WININET.@)
2505 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2506 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2508 FIXME("Flags %08x ignored\n", dwFlags);
2509 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2512 /***********************************************************************
2513 * InternetSetOptionExW (WININET.@)
2515 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2516 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2518 FIXME("Flags %08x ignored\n", dwFlags);
2519 if( dwFlags & ~ISO_VALID_FLAGS )
2521 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2524 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2527 static const WCHAR WININET_wkday[7][4] =
2528 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2529 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2530 static const WCHAR WININET_month[12][4] =
2531 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2532 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2533 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2535 /***********************************************************************
2536 * InternetTimeFromSystemTimeA (WININET.@)
2538 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2541 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2543 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2545 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2546 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2551 /***********************************************************************
2552 * InternetTimeFromSystemTimeW (WININET.@)
2554 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2556 static const WCHAR date[] =
2557 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2558 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2560 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2562 if (!time || !string) return FALSE;
2564 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2567 sprintfW( string, date,
2568 WININET_wkday[time->wDayOfWeek],
2570 WININET_month[time->wMonth - 1],
2579 /***********************************************************************
2580 * InternetTimeToSystemTimeA (WININET.@)
2582 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2588 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2590 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2591 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2595 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2596 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2597 HeapFree( GetProcessHeap(), 0, stringW );
2602 /***********************************************************************
2603 * InternetTimeToSystemTimeW (WININET.@)
2605 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2608 const WCHAR *s = string;
2611 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2613 if (!string || !time) return FALSE;
2615 /* Windows does this too */
2616 GetSystemTime( time );
2618 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2619 * a SYSTEMTIME structure.
2622 while (*s && !isalphaW( *s )) s++;
2623 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2624 time->wDayOfWeek = 7;
2626 for (i = 0; i < 7; i++)
2628 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2629 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2630 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2632 time->wDayOfWeek = i;
2637 if (time->wDayOfWeek > 6) return TRUE;
2638 while (*s && !isdigitW( *s )) s++;
2639 time->wDay = strtolW( s, &end, 10 );
2642 while (*s && !isalphaW( *s )) s++;
2643 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2646 for (i = 0; i < 12; i++)
2648 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2649 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2650 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2652 time->wMonth = i + 1;
2656 if (time->wMonth == 0) return TRUE;
2658 while (*s && !isdigitW( *s )) s++;
2659 if (*s == '\0') return TRUE;
2660 time->wYear = strtolW( s, &end, 10 );
2663 while (*s && !isdigitW( *s )) s++;
2664 if (*s == '\0') return TRUE;
2665 time->wHour = strtolW( s, &end, 10 );
2668 while (*s && !isdigitW( *s )) s++;
2669 if (*s == '\0') return TRUE;
2670 time->wMinute = strtolW( s, &end, 10 );
2673 while (*s && !isdigitW( *s )) s++;
2674 if (*s == '\0') return TRUE;
2675 time->wSecond = strtolW( s, &end, 10 );
2678 time->wMilliseconds = 0;
2682 /***********************************************************************
2683 * InternetCheckConnectionW (WININET.@)
2685 * Pings a requested host to check internet connection
2688 * TRUE on success and FALSE on failure. If a failure then
2689 * ERROR_NOT_CONNECTED is placed into GetLastError
2692 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2695 * this is a kludge which runs the resident ping program and reads the output.
2697 * Anyone have a better idea?
2701 static const CHAR ping[] = "ping -c 1 ";
2702 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2703 CHAR *command = NULL;
2711 * Crack or set the Address
2713 if (lpszUrl == NULL)
2716 * According to the doc we are supost to use the ip for the next
2717 * server in the WnInet internal server database. I have
2718 * no idea what that is or how to get it.
2720 * So someone needs to implement this.
2722 FIXME("Unimplemented with URL of NULL\n");
2727 URL_COMPONENTSW components;
2729 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2730 components.lpszHostName = (LPWSTR)&hostW;
2731 components.dwHostNameLength = 1024;
2733 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2736 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2740 * Build our ping command
2742 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2743 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2744 strcpy(command,ping);
2745 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2746 strcat(command,redirect);
2748 TRACE("Ping command is : %s\n",command);
2750 status = system(command);
2752 TRACE("Ping returned a code of %i\n",status);
2754 /* Ping return code of 0 indicates success */
2760 HeapFree( GetProcessHeap(), 0, command );
2762 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2768 /***********************************************************************
2769 * InternetCheckConnectionA (WININET.@)
2771 * Pings a requested host to check internet connection
2774 * TRUE on success and FALSE on failure. If a failure then
2775 * ERROR_NOT_CONNECTED is placed into GetLastError
2778 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2784 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2785 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2787 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2788 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2789 HeapFree(GetProcessHeap(), 0, szUrl);
2795 /**********************************************************
2796 * INTERNET_InternetOpenUrlW (internal)
2801 * handle of connection or NULL on failure
2803 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2804 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2806 URL_COMPONENTSW urlComponents;
2807 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2808 WCHAR password[1024], path[2048], extra[1024];
2809 HINTERNET client = NULL, client1 = NULL;
2811 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2812 dwHeadersLength, dwFlags, dwContext);
2814 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2815 urlComponents.lpszScheme = protocol;
2816 urlComponents.dwSchemeLength = 32;
2817 urlComponents.lpszHostName = hostName;
2818 urlComponents.dwHostNameLength = MAXHOSTNAME;
2819 urlComponents.lpszUserName = userName;
2820 urlComponents.dwUserNameLength = 1024;
2821 urlComponents.lpszPassword = password;
2822 urlComponents.dwPasswordLength = 1024;
2823 urlComponents.lpszUrlPath = path;
2824 urlComponents.dwUrlPathLength = 2048;
2825 urlComponents.lpszExtraInfo = extra;
2826 urlComponents.dwExtraInfoLength = 1024;
2827 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2829 switch(urlComponents.nScheme) {
2830 case INTERNET_SCHEME_FTP:
2831 if(urlComponents.nPort == 0)
2832 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2833 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2834 userName, password, dwFlags, dwContext, INET_OPENURL);
2837 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2838 if(client1 == NULL) {
2839 InternetCloseHandle(client);
2844 case INTERNET_SCHEME_HTTP:
2845 case INTERNET_SCHEME_HTTPS: {
2846 static const WCHAR szStars[] = { '*','/','*', 0 };
2847 LPCWSTR accept[2] = { szStars, NULL };
2848 if(urlComponents.nPort == 0) {
2849 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2850 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2852 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2854 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2855 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2856 userName, password, dwFlags, dwContext, INET_OPENURL);
2860 if (urlComponents.dwExtraInfoLength) {
2862 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2864 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2866 InternetCloseHandle(client);
2869 strcpyW(path_extra, urlComponents.lpszUrlPath);
2870 strcatW(path_extra, urlComponents.lpszExtraInfo);
2871 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2872 HeapFree(GetProcessHeap(), 0, path_extra);
2875 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2877 if(client1 == NULL) {
2878 InternetCloseHandle(client);
2881 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2882 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2883 GetLastError() != ERROR_IO_PENDING) {
2884 InternetCloseHandle(client1);
2889 case INTERNET_SCHEME_GOPHER:
2890 /* gopher doesn't seem to be implemented in wine, but it's supposed
2891 * to be supported by InternetOpenUrlA. */
2893 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2897 TRACE(" %p <--\n", client1);
2902 /**********************************************************
2903 * InternetOpenUrlW (WININET.@)
2908 * handle of connection or NULL on failure
2910 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
2912 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
2913 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
2917 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
2918 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
2919 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
2920 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
2923 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2924 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2926 HINTERNET ret = NULL;
2927 LPWININETAPPINFOW hIC = NULL;
2929 if (TRACE_ON(wininet)) {
2930 TRACE("(%p, %s, %s, %08x, %08x, %08x)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2931 dwHeadersLength, dwFlags, dwContext);
2933 dump_INTERNET_FLAGS(dwFlags);
2938 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2942 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2943 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2944 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2948 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2949 WORKREQUEST workRequest;
2950 struct WORKREQ_INTERNETOPENURLW *req;
2952 workRequest.asyncproc = AsyncInternetOpenUrlProc;
2953 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2954 req = &workRequest.u.InternetOpenUrlW;
2955 req->lpszUrl = WININET_strdupW(lpszUrl);
2957 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2959 req->lpszHeaders = 0;
2960 req->dwHeadersLength = dwHeadersLength;
2961 req->dwFlags = dwFlags;
2962 req->dwContext = dwContext;
2964 INTERNET_AsyncCall(&workRequest);
2966 * This is from windows.
2968 INTERNET_SetLastError(ERROR_IO_PENDING);
2970 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2975 WININET_Release( &hIC->hdr );
2976 TRACE(" %p <--\n", ret);
2981 /**********************************************************
2982 * InternetOpenUrlA (WININET.@)
2987 * handle of connection or NULL on failure
2989 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2990 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2992 HINTERNET rc = (HINTERNET)NULL;
2996 LPWSTR szUrl = NULL;
2997 LPWSTR szHeaders = NULL;
3002 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3003 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3005 return (HINTERNET)NULL;
3006 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3010 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3011 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3013 HeapFree(GetProcessHeap(), 0, szUrl);
3014 return (HINTERNET)NULL;
3016 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3019 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3020 lenHeaders, dwFlags, dwContext);
3022 HeapFree(GetProcessHeap(), 0, szUrl);
3023 HeapFree(GetProcessHeap(), 0, szHeaders);
3029 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3031 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3035 lpwite->dwError = 0;
3036 lpwite->response[0] = '\0';
3039 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3041 HeapFree(GetProcessHeap(), 0, lpwite);
3049 /***********************************************************************
3050 * INTERNET_SetLastError (internal)
3052 * Set last thread specific error
3057 void INTERNET_SetLastError(DWORD dwError)
3059 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3062 lpwite = INTERNET_AllocThreadError();
3064 SetLastError(dwError);
3066 lpwite->dwError = dwError;
3070 /***********************************************************************
3071 * INTERNET_GetLastError (internal)
3073 * Get last thread specific error
3078 DWORD INTERNET_GetLastError(void)
3080 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3081 if (!lpwite) return 0;
3082 /* TlsGetValue clears last error, so set it again here */
3083 SetLastError(lpwite->dwError);
3084 return lpwite->dwError;
3088 /***********************************************************************
3089 * INTERNET_WorkerThreadFunc (internal)
3091 * Worker thread execution function
3096 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3098 LPWORKREQUEST lpRequest = lpvParam;
3099 WORKREQUEST workRequest;
3103 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3104 HeapFree(GetProcessHeap(), 0, lpRequest);
3106 workRequest.asyncproc(&workRequest);
3108 WININET_Release( workRequest.hdr );
3113 /***********************************************************************
3114 * INTERNET_AsyncCall (internal)
3116 * Retrieves work request from queue
3121 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3124 LPWORKREQUEST lpNewRequest;
3128 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3132 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3134 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3137 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3138 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3145 /***********************************************************************
3146 * INTERNET_GetResponseBuffer (internal)
3151 LPSTR INTERNET_GetResponseBuffer(void)
3153 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3155 lpwite = INTERNET_AllocThreadError();
3157 return lpwite->response;
3160 /***********************************************************************
3161 * INTERNET_GetNextLine (internal)
3163 * Parse next line in directory string listing
3166 * Pointer to beginning of next line
3171 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3175 BOOL bSuccess = FALSE;
3177 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3182 FD_SET(nSocket, &infd);
3183 tv.tv_sec=RESPONSE_TIMEOUT;
3186 while (nRecv < MAX_REPLY_LEN)
3188 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3190 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3192 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3196 if (lpszBuffer[nRecv] == '\n')
3201 if (lpszBuffer[nRecv] != '\r')
3206 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3214 lpszBuffer[nRecv] = '\0';
3216 TRACE(":%d %s\n", nRecv, lpszBuffer);
3225 /**********************************************************
3226 * InternetQueryDataAvailable (WININET.@)
3228 * Determines how much data is available to be read.
3231 * If there is data available then TRUE, otherwise if there
3232 * is not or an error occurred then FALSE. Use GetLastError() to
3233 * check for ERROR_NO_MORE_FILES to see if it was the former.
3235 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3236 LPDWORD lpdwNumberOfBytesAvailble,
3237 DWORD dwFlags, DWORD dwConext)
3239 LPWININETHTTPREQW lpwhr;
3240 BOOL retval = FALSE;
3243 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3246 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3250 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3252 switch (lpwhr->hdr.htype)
3255 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3256 min(sizeof(buffer), lpwhr->dwContentLength - lpwhr->dwContentRead),
3257 MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3259 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3267 FIXME("unsupported file type\n");
3270 WININET_Release( &lpwhr->hdr );
3272 TRACE("<-- %i\n",retval);
3277 /***********************************************************************
3278 * InternetLockRequestFile (WININET.@)
3280 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3287 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3294 /***********************************************************************
3295 * InternetAutodial (WININET.@)
3297 * On windows this function is supposed to dial the default internet
3298 * connection. We don't want to have Wine dial out to the internet so
3299 * we return TRUE by default. It might be nice to check if we are connected.
3306 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3310 /* Tell that we are connected to the internet. */
3314 /***********************************************************************
3315 * InternetAutodialHangup (WININET.@)
3317 * Hangs up a connection made with InternetAutodial
3326 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3330 /* we didn't dial, we don't disconnect */
3334 /***********************************************************************
3335 * InternetCombineUrlA (WININET.@)
3337 * Combine a base URL with a relative URL
3345 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3346 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3351 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3353 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3354 dwFlags ^= ICU_NO_ENCODE;
3355 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3360 /***********************************************************************
3361 * InternetCombineUrlW (WININET.@)
3363 * Combine a base URL with a relative URL
3371 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3372 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3377 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3379 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3380 dwFlags ^= ICU_NO_ENCODE;
3381 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3386 /* max port num is 65535 => 5 digits */
3387 #define MAX_WORD_DIGITS 5
3389 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3390 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3391 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3392 (url)->dw##component##Length : strlen((url)->lpsz##component))
3394 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3396 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3397 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3399 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3400 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3402 if ((nScheme == INTERNET_SCHEME_FTP) &&
3403 (nPort == INTERNET_DEFAULT_FTP_PORT))
3405 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3406 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3409 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3415 /* opaque urls do not fit into the standard url hierarchy and don't have
3416 * two following slashes */
3417 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3419 return (nScheme != INTERNET_SCHEME_FTP) &&
3420 (nScheme != INTERNET_SCHEME_GOPHER) &&
3421 (nScheme != INTERNET_SCHEME_HTTP) &&
3422 (nScheme != INTERNET_SCHEME_HTTPS) &&
3423 (nScheme != INTERNET_SCHEME_FILE);
3426 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3429 if (scheme < INTERNET_SCHEME_FIRST)
3431 index = scheme - INTERNET_SCHEME_FIRST;
3432 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3434 return (LPCWSTR)&url_schemes[index];
3437 /* we can calculate using ansi strings because we're just
3438 * calculating string length, not size
3440 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3441 LPDWORD lpdwUrlLength)
3443 INTERNET_SCHEME nScheme;
3447 if (lpUrlComponents->lpszScheme)
3449 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3450 *lpdwUrlLength += dwLen;
3451 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3457 nScheme = lpUrlComponents->nScheme;
3459 if (nScheme == INTERNET_SCHEME_DEFAULT)
3460 nScheme = INTERNET_SCHEME_HTTP;
3461 scheme = INTERNET_GetSchemeString(nScheme);
3462 *lpdwUrlLength += strlenW(scheme);
3465 (*lpdwUrlLength)++; /* ':' */
3466 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3467 *lpdwUrlLength += strlen("//");
3469 if (lpUrlComponents->lpszUserName)
3471 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3472 *lpdwUrlLength += strlen("@");
3476 if (lpUrlComponents->lpszPassword)
3478 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3483 if (lpUrlComponents->lpszPassword)
3485 *lpdwUrlLength += strlen(":");
3486 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3489 if (lpUrlComponents->lpszHostName)
3491 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3493 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3495 char szPort[MAX_WORD_DIGITS+1];
3497 sprintf(szPort, "%d", lpUrlComponents->nPort);
3498 *lpdwUrlLength += strlen(szPort);
3499 *lpdwUrlLength += strlen(":");
3502 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3503 (*lpdwUrlLength)++; /* '/' */
3506 if (lpUrlComponents->lpszUrlPath)
3507 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3512 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3516 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3518 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3519 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3520 urlCompW->nScheme = lpUrlComponents->nScheme;
3521 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3522 urlCompW->nPort = lpUrlComponents->nPort;
3523 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3524 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3525 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3526 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3528 if (lpUrlComponents->lpszScheme)
3530 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3531 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3532 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3533 -1, urlCompW->lpszScheme, len);
3536 if (lpUrlComponents->lpszHostName)
3538 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3539 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3540 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3541 -1, urlCompW->lpszHostName, len);
3544 if (lpUrlComponents->lpszUserName)
3546 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3547 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3548 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3549 -1, urlCompW->lpszUserName, len);
3552 if (lpUrlComponents->lpszPassword)
3554 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3555 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3556 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3557 -1, urlCompW->lpszPassword, len);
3560 if (lpUrlComponents->lpszUrlPath)
3562 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3563 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3564 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3565 -1, urlCompW->lpszUrlPath, len);
3568 if (lpUrlComponents->lpszExtraInfo)
3570 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3571 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3572 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3573 -1, urlCompW->lpszExtraInfo, len);
3577 /***********************************************************************
3578 * InternetCreateUrlA (WININET.@)
3580 * See InternetCreateUrlW.
3582 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3583 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3587 URL_COMPONENTSW urlCompW;
3589 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3591 if (!lpUrlComponents)
3594 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3596 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3600 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3603 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3605 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3607 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3608 *lpdwUrlLength /= sizeof(WCHAR);
3610 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3611 * minus one, so add one to leave room for NULL terminator
3614 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3616 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3617 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3618 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3619 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3620 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3621 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3622 HeapFree(GetProcessHeap(), 0, urlW);
3627 /***********************************************************************
3628 * InternetCreateUrlW (WININET.@)
3630 * Creates a URL from its component parts.
3633 * lpUrlComponents [I] URL Components.
3634 * dwFlags [I] Flags. See notes.
3635 * lpszUrl [I] Buffer in which to store the created URL.
3636 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3637 * lpszUrl in characters. On output, the number of bytes
3638 * required to store the URL including terminator.
3642 * The dwFlags parameter can be zero or more of the following:
3643 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3650 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3651 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3654 INTERNET_SCHEME nScheme;
3656 static const WCHAR slashSlashW[] = {'/','/'};
3657 static const WCHAR percentD[] = {'%','d',0};
3659 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3661 if (!lpUrlComponents)
3664 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3666 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3670 if (!calc_url_length(lpUrlComponents, &dwLen))
3673 if (!lpszUrl || *lpdwUrlLength < dwLen)
3675 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3676 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3680 *lpdwUrlLength = dwLen;
3685 if (lpUrlComponents->lpszScheme)
3687 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3688 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3691 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3696 nScheme = lpUrlComponents->nScheme;
3698 if (nScheme == INTERNET_SCHEME_DEFAULT)
3699 nScheme = INTERNET_SCHEME_HTTP;
3701 scheme = INTERNET_GetSchemeString(nScheme);
3702 dwLen = strlenW(scheme);
3703 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3707 /* all schemes are followed by at least a colon */
3711 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3713 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3714 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3717 if (lpUrlComponents->lpszUserName)
3719 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3720 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3723 if (lpUrlComponents->lpszPassword)
3728 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3729 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3737 if (lpUrlComponents->lpszHostName)
3739 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3740 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3743 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3745 WCHAR szPort[MAX_WORD_DIGITS+1];
3747 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3750 dwLen = strlenW(szPort);
3751 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3755 /* add slash between hostname and path if necessary */
3756 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3764 if (lpUrlComponents->lpszUrlPath)
3766 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3767 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3776 /***********************************************************************
3777 * InternetConfirmZoneCrossingA (WININET.@)
3780 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3782 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3783 return ERROR_SUCCESS;
3786 /***********************************************************************
3787 * InternetConfirmZoneCrossingW (WININET.@)
3790 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3792 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3793 return ERROR_SUCCESS;
3796 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3797 LPDWORD lpdwConnection, DWORD dwReserved )
3799 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3800 lpdwConnection, dwReserved);
3801 return ERROR_SUCCESS;
3804 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3805 LPDWORD lpdwConnection, DWORD dwReserved )
3807 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3808 lpdwConnection, dwReserved);
3809 return ERROR_SUCCESS;
3812 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3814 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3818 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3820 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3824 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
3826 FIXME("(0x%08x, 0x%08x) stub\n", dwConnection, dwReserved);
3827 return ERROR_SUCCESS;
3830 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3833 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3834 debugstr_w(pwszTarget), pbHexHash);
3838 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3840 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);