4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
6 * Copyright 2002 Jaco Greeff
7 * Copyright 2002 TransGaming Technologies Inc.
8 * Copyright 2004 Mike McCormack for CodeWeavers
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
58 #include "wine/debug.h"
60 #define NO_SHLWAPI_STREAM
64 #include "wine/exception.h"
69 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define RESPONSE_TIMEOUT 30
78 CHAR response[MAX_REPLY_LEN];
79 } WITHREADERROR, *LPWITHREADERROR;
81 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr);
82 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
83 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext);
85 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
86 static HMODULE WININET_hModule;
88 #define HANDLE_CHUNK_SIZE 0x10
90 static CRITICAL_SECTION WININET_cs;
91 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
94 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
95 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
97 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
99 static LPWININETHANDLEHEADER *WININET_Handles;
100 static UINT WININET_dwNextHandle;
101 static UINT WININET_dwMaxHandles;
103 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
105 LPWININETHANDLEHEADER *p;
106 UINT handle = 0, num;
108 list_init( &info->children );
110 EnterCriticalSection( &WININET_cs );
111 if( !WININET_dwMaxHandles )
113 num = HANDLE_CHUNK_SIZE;
114 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
119 WININET_dwMaxHandles = num;
121 if( WININET_dwMaxHandles == WININET_dwNextHandle )
123 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
124 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
125 WININET_Handles, sizeof (UINT)* num);
129 WININET_dwMaxHandles = num;
132 handle = WININET_dwNextHandle;
133 if( WININET_Handles[handle] )
134 ERR("handle isn't free but should be\n");
135 WININET_Handles[handle] = WININET_AddRef( info );
137 while( WININET_Handles[WININET_dwNextHandle] &&
138 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
139 WININET_dwNextHandle++;
142 LeaveCriticalSection( &WININET_cs );
144 return info->hInternet = (HINTERNET) (handle+1);
147 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
150 TRACE("%p -> refcount = %d\n", info, info->dwRefCount );
154 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
156 LPWININETHANDLEHEADER info = NULL;
157 UINT handle = (UINT) hinternet;
159 EnterCriticalSection( &WININET_cs );
161 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
162 WININET_Handles[handle-1] )
163 info = WININET_AddRef( WININET_Handles[handle-1] );
165 LeaveCriticalSection( &WININET_cs );
167 TRACE("handle %d -> %p\n", handle, info);
172 BOOL WININET_Release( LPWININETHANDLEHEADER info )
175 TRACE( "object %p refcount = %d\n", info, info->dwRefCount );
176 if( !info->dwRefCount )
178 if ( info->close_connection )
180 TRACE( "closing connection %p\n", info);
181 info->close_connection( info );
183 INTERNET_SendCallback(info, info->dwContext,
184 INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet,
186 TRACE( "destroying object %p\n", info);
187 if ( info->htype != WH_HINIT )
188 list_remove( &info->entry );
189 info->destroy( info );
194 BOOL WININET_FreeHandle( HINTERNET hinternet )
197 UINT handle = (UINT) hinternet;
198 LPWININETHANDLEHEADER info = NULL, child, next;
200 EnterCriticalSection( &WININET_cs );
202 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
205 if( WININET_Handles[handle] )
207 info = WININET_Handles[handle];
208 TRACE( "destroying handle %d for object %p\n", handle+1, info);
209 WININET_Handles[handle] = NULL;
214 LeaveCriticalSection( &WININET_cs );
216 /* As on native when the equivalent of WININET_Release is called, the handle
217 * is already invalid, but if a new handle is created at this time it does
218 * not yet get assigned the freed handle number */
221 /* Free all children as native does */
222 LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, WININETHANDLEHEADER, entry )
224 TRACE( "freeing child handle %d for parent handle %d\n",
225 (UINT)child->hInternet, handle+1);
226 WININET_FreeHandle( child->hInternet );
228 WININET_Release( info );
231 EnterCriticalSection( &WININET_cs );
233 if( WININET_dwNextHandle > handle && !WININET_Handles[handle] )
234 WININET_dwNextHandle = handle;
236 LeaveCriticalSection( &WININET_cs );
241 /***********************************************************************
242 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
245 * hinstDLL [I] handle to the DLL's instance
247 * lpvReserved [I] reserved, must be NULL
254 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
256 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
259 case DLL_PROCESS_ATTACH:
261 g_dwTlsErrIndex = TlsAlloc();
263 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
266 URLCacheContainers_CreateDefaults();
268 WININET_hModule = (HMODULE)hinstDLL;
270 case DLL_THREAD_ATTACH:
273 case DLL_THREAD_DETACH:
274 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
276 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
277 HeapFree(GetProcessHeap(), 0, lpwite);
281 case DLL_PROCESS_DETACH:
283 URLCacheContainers_DeleteAll();
285 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
287 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
288 TlsFree(g_dwTlsErrIndex);
297 /***********************************************************************
298 * InternetInitializeAutoProxyDll (WININET.@)
300 * Setup the internal proxy
309 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
312 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
316 /***********************************************************************
317 * DetectAutoProxyUrl (WININET.@)
319 * Auto detect the proxy url
325 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
326 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
329 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
334 /***********************************************************************
335 * INTERNET_ConfigureProxyFromReg
338 * The proxy may be specified in the form 'http=proxy.my.org'
339 * Presumably that means there can be ftp=ftpproxy.my.org too.
341 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
344 DWORD r, keytype, len, enabled;
345 LPCSTR lpszInternetSettings =
346 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
347 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
349 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
350 if ( r != ERROR_SUCCESS )
353 len = sizeof enabled;
354 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
355 (BYTE*)&enabled, &len);
356 if( (r == ERROR_SUCCESS) && enabled )
358 TRACE("Proxy is enabled.\n");
360 /* figure out how much memory the proxy setting takes */
361 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
363 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
366 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
368 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
369 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
370 (BYTE*)szProxy, &len);
372 /* find the http proxy, and strip away everything else */
373 p = strstrW( szProxy, szHttp );
376 p += lstrlenW(szHttp);
377 lstrcpyW( szProxy, p );
379 p = strchrW( szProxy, ' ' );
383 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
384 lpwai->lpszProxy = szProxy;
386 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
389 ERR("Couldn't read proxy server settings.\n");
392 TRACE("Proxy is not enabled.\n");
398 /***********************************************************************
399 * dump_INTERNET_FLAGS
401 * Helper function to TRACE the internet flags.
407 static void dump_INTERNET_FLAGS(DWORD dwFlags)
409 #define FE(x) { x, #x }
410 static const wininet_flag_info flag[] = {
411 FE(INTERNET_FLAG_RELOAD),
412 FE(INTERNET_FLAG_RAW_DATA),
413 FE(INTERNET_FLAG_EXISTING_CONNECT),
414 FE(INTERNET_FLAG_ASYNC),
415 FE(INTERNET_FLAG_PASSIVE),
416 FE(INTERNET_FLAG_NO_CACHE_WRITE),
417 FE(INTERNET_FLAG_MAKE_PERSISTENT),
418 FE(INTERNET_FLAG_FROM_CACHE),
419 FE(INTERNET_FLAG_SECURE),
420 FE(INTERNET_FLAG_KEEP_CONNECTION),
421 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
422 FE(INTERNET_FLAG_READ_PREFETCH),
423 FE(INTERNET_FLAG_NO_COOKIES),
424 FE(INTERNET_FLAG_NO_AUTH),
425 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
426 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
427 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
428 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
429 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
430 FE(INTERNET_FLAG_RESYNCHRONIZE),
431 FE(INTERNET_FLAG_HYPERLINK),
432 FE(INTERNET_FLAG_NO_UI),
433 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
434 FE(INTERNET_FLAG_CACHE_ASYNC),
435 FE(INTERNET_FLAG_FORMS_SUBMIT),
436 FE(INTERNET_FLAG_NEED_FILE),
437 FE(INTERNET_FLAG_TRANSFER_ASCII),
438 FE(INTERNET_FLAG_TRANSFER_BINARY)
443 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
444 if (flag[i].val & dwFlags) {
445 TRACE(" %s", flag[i].name);
446 dwFlags &= ~flag[i].val;
450 TRACE(" Unknown flags (%08x)\n", dwFlags);
455 /***********************************************************************
456 * InternetOpenW (WININET.@)
458 * Per-application initialization of wininet
461 * HINTERNET on success
465 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
466 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
468 LPWININETAPPINFOW lpwai = NULL;
469 HINTERNET handle = NULL;
471 if (TRACE_ON(wininet)) {
472 #define FE(x) { x, #x }
473 static const wininet_flag_info access_type[] = {
474 FE(INTERNET_OPEN_TYPE_PRECONFIG),
475 FE(INTERNET_OPEN_TYPE_DIRECT),
476 FE(INTERNET_OPEN_TYPE_PROXY),
477 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
481 const char *access_type_str = "Unknown";
483 TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType,
484 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
485 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
486 if (access_type[i].val == dwAccessType) {
487 access_type_str = access_type[i].name;
491 TRACE(" access type : %s\n", access_type_str);
493 dump_INTERNET_FLAGS(dwFlags);
496 /* Clear any error information */
497 INTERNET_SetLastError(0);
499 lpwai = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WININETAPPINFOW));
502 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
506 lpwai->hdr.htype = WH_HINIT;
507 lpwai->hdr.dwFlags = dwFlags;
508 lpwai->hdr.dwRefCount = 1;
509 lpwai->hdr.close_connection = NULL;
510 lpwai->hdr.destroy = INTERNET_CloseHandle;
511 lpwai->dwAccessType = dwAccessType;
512 lpwai->lpszProxyUsername = NULL;
513 lpwai->lpszProxyPassword = NULL;
515 handle = WININET_AllocHandle( &lpwai->hdr );
518 HeapFree( GetProcessHeap(), 0, lpwai );
519 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
523 if (NULL != lpszAgent)
525 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
526 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
527 if (lpwai->lpszAgent)
528 lstrcpyW( lpwai->lpszAgent, lpszAgent );
530 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
531 INTERNET_ConfigureProxyFromReg( lpwai );
532 else if (NULL != lpszProxy)
534 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
535 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
536 if (lpwai->lpszProxy)
537 lstrcpyW( lpwai->lpszProxy, lpszProxy );
540 if (NULL != lpszProxyBypass)
542 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
543 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
544 if (lpwai->lpszProxyBypass)
545 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
550 WININET_Release( &lpwai->hdr );
552 TRACE("returning %p\n", lpwai);
558 /***********************************************************************
559 * InternetOpenA (WININET.@)
561 * Per-application initialization of wininet
564 * HINTERNET on success
568 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
569 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
571 HINTERNET rc = (HINTERNET)NULL;
573 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
575 TRACE("(%s, 0x%08x, %s, %s, 0x%08x)\n", debugstr_a(lpszAgent),
576 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
580 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
581 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
582 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
587 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
588 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
589 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
592 if( lpszProxyBypass )
594 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
595 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
596 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
599 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
601 HeapFree(GetProcessHeap(), 0, szAgent);
602 HeapFree(GetProcessHeap(), 0, szProxy);
603 HeapFree(GetProcessHeap(), 0, szBypass);
608 /***********************************************************************
609 * InternetGetLastResponseInfoA (WININET.@)
611 * Return last wininet error description on the calling thread
614 * TRUE on success of writing to buffer
618 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
619 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
621 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
627 *lpdwError = lpwite->dwError;
630 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
631 *lpdwBufferLength = strlen(lpszBuffer);
634 *lpdwBufferLength = 0;
639 *lpdwBufferLength = 0;
645 /***********************************************************************
646 * InternetGetLastResponseInfoW (WININET.@)
648 * Return last wininet error description on the calling thread
651 * TRUE on success of writing to buffer
655 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
656 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
658 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
664 *lpdwError = lpwite->dwError;
667 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
668 *lpdwBufferLength = lstrlenW(lpszBuffer);
671 *lpdwBufferLength = 0;
676 *lpdwBufferLength = 0;
682 /***********************************************************************
683 * InternetGetConnectedState (WININET.@)
685 * Return connected state
689 * if lpdwStatus is not null, return the status (off line,
690 * modem, lan...) in it.
691 * FALSE if not connected
693 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
695 TRACE("(%p, 0x%08x)\n", lpdwStatus, dwReserved);
698 FIXME("always returning LAN connection.\n");
699 *lpdwStatus = INTERNET_CONNECTION_LAN;
705 /***********************************************************************
706 * InternetGetConnectedStateExW (WININET.@)
708 * Return connected state
712 * lpdwStatus [O] Flags specifying the status of the internet connection.
713 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
714 * dwNameLen [I] Size of the buffer, in characters.
715 * dwReserved [I] Reserved. Must be set to 0.
719 * if lpdwStatus is not null, return the status (off line,
720 * modem, lan...) in it.
721 * FALSE if not connected
724 * If the system has no available network connections, an empty string is
725 * stored in lpszConnectionName. If there is a LAN connection, a localized
726 * "LAN Connection" string is stored. Presumably, if only a dial-up
727 * connection is available then the name of the dial-up connection is
728 * returned. Why any application, other than the "Internet Settings" CPL,
729 * would want to use this function instead of the simpler InternetGetConnectedStateW
730 * function is beyond me.
732 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
733 DWORD dwNameLen, DWORD dwReserved)
735 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
742 FIXME("always returning LAN connection.\n");
743 *lpdwStatus = INTERNET_CONNECTION_LAN;
745 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
749 /***********************************************************************
750 * InternetGetConnectedStateExA (WININET.@)
752 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
753 DWORD dwNameLen, DWORD dwReserved)
755 LPWSTR lpwszConnectionName = NULL;
758 TRACE("(%p, %p, %d, 0x%08x)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
760 if (lpszConnectionName && dwNameLen > 0)
761 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
763 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
765 if (rc && lpwszConnectionName)
767 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
768 dwNameLen, NULL, NULL);
770 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
777 /***********************************************************************
778 * InternetConnectW (WININET.@)
780 * Open a ftp, gopher or http session
783 * HINTERNET a session handle on success
787 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
788 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
789 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
790 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
792 LPWININETAPPINFOW hIC;
795 TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
796 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
797 dwService, dwFlags, dwContext);
801 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
805 /* Clear any error information */
806 INTERNET_SetLastError(0);
807 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
808 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
810 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
816 case INTERNET_SERVICE_FTP:
817 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
818 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
821 case INTERNET_SERVICE_HTTP:
822 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
823 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
826 case INTERNET_SERVICE_GOPHER:
832 WININET_Release( &hIC->hdr );
834 TRACE("returning %p\n", rc);
839 /***********************************************************************
840 * InternetConnectA (WININET.@)
842 * Open a ftp, gopher or http session
845 * HINTERNET a session handle on success
849 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
850 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
851 LPCSTR lpszUserName, LPCSTR lpszPassword,
852 DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
854 HINTERNET rc = (HINTERNET)NULL;
856 LPWSTR szServerName = NULL;
857 LPWSTR szUserName = NULL;
858 LPWSTR szPassword = NULL;
862 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
863 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
864 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
868 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
869 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
870 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
874 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
875 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
876 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
880 rc = InternetConnectW(hInternet, szServerName, nServerPort,
881 szUserName, szPassword, dwService, dwFlags, dwContext);
883 HeapFree(GetProcessHeap(), 0, szServerName);
884 HeapFree(GetProcessHeap(), 0, szUserName);
885 HeapFree(GetProcessHeap(), 0, szPassword);
890 /***********************************************************************
891 * InternetFindNextFileA (WININET.@)
893 * Continues a file search from a previous call to FindFirstFile
900 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
905 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
907 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
911 /***********************************************************************
912 * InternetFindNextFileW (WININET.@)
914 * Continues a file search from a previous call to FindFirstFile
921 static void AsyncFtpFindNextFileProc(WORKREQUEST *workRequest)
923 struct WORKREQ_FTPFINDNEXTW *req = &workRequest->u.FtpFindNextW;
924 LPWININETFTPFINDNEXTW lpwh = (LPWININETFTPFINDNEXTW) workRequest->hdr;
928 FTP_FindNextFileW(lpwh, req->lpFindFileData);
931 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
933 LPWININETAPPINFOW hIC = NULL;
934 LPWININETFTPFINDNEXTW lpwh;
935 BOOL bSuccess = FALSE;
939 lpwh = (LPWININETFTPFINDNEXTW) WININET_GetObject( hFind );
940 if (NULL == lpwh || lpwh->hdr.htype != WH_HFTPFINDNEXT)
942 FIXME("Only FTP supported\n");
943 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
947 hIC = lpwh->lpFtpSession->lpAppInfo;
948 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
950 WORKREQUEST workRequest;
951 struct WORKREQ_FTPFINDNEXTW *req;
953 workRequest.asyncproc = AsyncFtpFindNextFileProc;
954 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
955 req = &workRequest.u.FtpFindNextW;
956 req->lpFindFileData = lpvFindData;
958 bSuccess = INTERNET_AsyncCall(&workRequest);
962 bSuccess = FTP_FindNextFileW(lpwh, lpvFindData);
966 WININET_Release( &lpwh->hdr );
970 /***********************************************************************
971 * INTERNET_CloseHandle (internal)
973 * Close internet handle
979 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
981 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
985 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
986 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
987 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
988 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
989 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
990 HeapFree(GetProcessHeap(), 0, lpwai);
994 /***********************************************************************
995 * InternetCloseHandle (WININET.@)
997 * Generic close handle function
1004 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1006 LPWININETHANDLEHEADER lpwh;
1008 TRACE("%p\n",hInternet);
1010 lpwh = WININET_GetObject( hInternet );
1013 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1017 WININET_Release( lpwh );
1018 WININET_FreeHandle( hInternet );
1024 /***********************************************************************
1025 * ConvertUrlComponentValue (Internal)
1027 * Helper function for InternetCrackUrlW
1030 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1031 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1032 LPCSTR lpszStart, LPCWSTR lpwszStart)
1034 TRACE("%p %d %p %d %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1035 if (*dwComponentLen != 0)
1037 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1038 if (*lppszComponent == NULL)
1040 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1042 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1044 *lppszComponent = NULL;
1045 *dwComponentLen = nASCIILength;
1049 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1050 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1051 (*lppszComponent)[ncpylen]=0;
1052 *dwComponentLen = ncpylen;
1058 /***********************************************************************
1059 * InternetCrackUrlA (WININET.@)
1061 * See InternetCrackUrlW.
1063 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1064 LPURL_COMPONENTSA lpUrlComponents)
1067 URL_COMPONENTSW UCW;
1070 TRACE("(%s %u %x %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1072 if (!lpszUrl || !*lpszUrl)
1074 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1080 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1082 /* if dwUrlLength=-1 then nLength includes null but length to
1083 InternetCrackUrlW should not include it */
1084 if (dwUrlLength == -1) nLength--;
1086 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1087 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1089 memset(&UCW,0,sizeof(UCW));
1090 if(lpUrlComponents->dwHostNameLength!=0)
1091 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1092 if(lpUrlComponents->dwUserNameLength!=0)
1093 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1094 if(lpUrlComponents->dwPasswordLength!=0)
1095 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1096 if(lpUrlComponents->dwUrlPathLength!=0)
1097 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1098 if(lpUrlComponents->dwSchemeLength!=0)
1099 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1100 if(lpUrlComponents->dwExtraInfoLength!=0)
1101 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1102 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1104 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1108 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1109 UCW.lpszHostName, UCW.dwHostNameLength,
1111 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1112 UCW.lpszUserName, UCW.dwUserNameLength,
1114 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1115 UCW.lpszPassword, UCW.dwPasswordLength,
1117 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1118 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1120 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1121 UCW.lpszScheme, UCW.dwSchemeLength,
1123 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1124 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1126 lpUrlComponents->nScheme=UCW.nScheme;
1127 lpUrlComponents->nPort=UCW.nPort;
1128 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1130 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1131 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1132 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1133 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1134 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1139 static const WCHAR url_schemes[][7] =
1142 {'g','o','p','h','e','r',0},
1143 {'h','t','t','p',0},
1144 {'h','t','t','p','s',0},
1145 {'f','i','l','e',0},
1146 {'n','e','w','s',0},
1147 {'m','a','i','l','t','o',0},
1151 /***********************************************************************
1152 * GetInternetSchemeW (internal)
1158 * INTERNET_SCHEME_UNKNOWN on failure
1161 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1165 TRACE("%s %d\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1167 if(lpszScheme==NULL)
1168 return INTERNET_SCHEME_UNKNOWN;
1170 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1171 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1172 return INTERNET_SCHEME_FIRST + i;
1174 return INTERNET_SCHEME_UNKNOWN;
1177 /***********************************************************************
1178 * SetUrlComponentValueW (Internal)
1180 * Helper function for InternetCrackUrlW
1183 * lppszComponent [O] Holds the returned string
1184 * dwComponentLen [I] Holds the size of lppszComponent
1185 * [O] Holds the length of the string in lppszComponent without '\0'
1186 * lpszStart [I] Holds the string to copy from
1187 * len [I] Holds the length of lpszStart without '\0'
1194 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1196 TRACE("%s (%d)\n", debugstr_wn(lpszStart,len), len);
1198 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1201 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1203 if (*lppszComponent == NULL)
1205 *lppszComponent = (LPWSTR)lpszStart;
1206 *dwComponentLen = len;
1210 DWORD ncpylen = min((*dwComponentLen)-1, len);
1211 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1212 (*lppszComponent)[ncpylen] = '\0';
1213 *dwComponentLen = ncpylen;
1220 /***********************************************************************
1221 * InternetCrackUrlW (WININET.@)
1223 * Break up URL into its components
1229 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1230 LPURL_COMPONENTSW lpUC)
1234 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1237 LPCWSTR lpszParam = NULL;
1238 BOOL bIsAbsolute = FALSE;
1239 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1240 LPCWSTR lpszcp = NULL;
1241 LPWSTR lpszUrl_decode = NULL;
1242 DWORD dwUrlLength = dwUrlLength_orig;
1243 const WCHAR lpszSeparators[3]={';','?',0};
1244 const WCHAR lpszSlash[2]={'/',0};
1246 TRACE("(%s %u %x %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1248 if (!lpszUrl_orig || !*lpszUrl_orig || !lpUC)
1250 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1253 if (!dwUrlLength) dwUrlLength = strlenW(lpszUrl);
1255 if (dwFlags & ICU_DECODE)
1257 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1258 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1260 lpszUrl = lpszUrl_decode;
1265 /* Determine if the URI is absolute. */
1266 while (*lpszap != '\0')
1268 if (isalnumW(*lpszap))
1273 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1280 lpszcp = lpszUrl; /* Relative url */
1286 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1287 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1289 /* Parse <params> */
1290 lpszParam = strpbrkW(lpszap, lpszSeparators);
1291 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1292 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1294 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1298 /* Get scheme first. */
1299 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1300 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1301 lpszUrl, lpszcp - lpszUrl);
1303 /* Eat ':' in protocol. */
1306 /* double slash indicates the net_loc portion is present */
1307 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1311 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1315 lpszNetLoc = min(lpszNetLoc, lpszParam);
1317 lpszNetLoc = lpszParam;
1319 else if (!lpszNetLoc)
1320 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1328 /* [<user>[<:password>]@]<host>[:<port>] */
1329 /* First find the user and password if they exist */
1331 lpszHost = strchrW(lpszcp, '@');
1332 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1334 /* username and password not specified. */
1335 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1336 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1338 else /* Parse out username and password */
1340 LPCWSTR lpszUser = lpszcp;
1341 LPCWSTR lpszPasswd = lpszHost;
1343 while (lpszcp < lpszHost)
1346 lpszPasswd = lpszcp;
1351 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1352 lpszUser, lpszPasswd - lpszUser);
1354 if (lpszPasswd != lpszHost)
1356 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1357 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1358 lpszHost - lpszPasswd);
1360 lpszcp++; /* Advance to beginning of host */
1363 /* Parse <host><:port> */
1366 lpszPort = lpszNetLoc;
1368 /* special case for res:// URLs: there is no port here, so the host is the
1369 entire string up to the first '/' */
1370 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1372 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1373 lpszHost, lpszPort - lpszHost);
1378 while (lpszcp < lpszNetLoc)
1386 /* If the scheme is "file" and the host is just one letter, it's not a host */
1387 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1390 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1395 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1396 lpszHost, lpszPort - lpszHost);
1397 if (lpszPort != lpszNetLoc)
1398 lpUC->nPort = atoiW(++lpszPort);
1399 else switch (lpUC->nScheme)
1401 case INTERNET_SCHEME_HTTP:
1402 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1404 case INTERNET_SCHEME_HTTPS:
1405 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1407 case INTERNET_SCHEME_FTP:
1408 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1410 case INTERNET_SCHEME_GOPHER:
1411 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1422 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1423 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1424 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1429 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1430 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1431 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1432 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1435 /* Here lpszcp points to:
1437 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1438 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1440 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1444 /* Only truncate the parameter list if it's already been saved
1445 * in lpUC->lpszExtraInfo.
1447 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1448 len = lpszParam - lpszcp;
1451 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1452 * newlines if necessary.
1454 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1455 if (lpsznewline != NULL)
1456 len = lpsznewline - lpszcp;
1458 len = dwUrlLength-(lpszcp-lpszUrl);
1460 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1465 lpUC->dwUrlPathLength = 0;
1468 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1469 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1470 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1471 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1472 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1474 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1478 /***********************************************************************
1479 * InternetAttemptConnect (WININET.@)
1481 * Attempt to make a connection to the internet
1484 * ERROR_SUCCESS on success
1485 * Error value on failure
1488 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1491 return ERROR_SUCCESS;
1495 /***********************************************************************
1496 * InternetCanonicalizeUrlA (WININET.@)
1498 * Escape unsafe characters and spaces
1505 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1506 LPDWORD lpdwBufferLength, DWORD dwFlags)
1509 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1511 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_a(lpszUrl), lpszBuffer,
1512 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1514 if(dwFlags & ICU_DECODE)
1516 dwURLFlags |= URL_UNESCAPE;
1517 dwFlags &= ~ICU_DECODE;
1520 if(dwFlags & ICU_ESCAPE)
1522 dwURLFlags |= URL_UNESCAPE;
1523 dwFlags &= ~ICU_ESCAPE;
1526 if(dwFlags & ICU_BROWSER_MODE)
1528 dwURLFlags |= URL_BROWSER_MODE;
1529 dwFlags &= ~ICU_BROWSER_MODE;
1532 if(dwFlags & ICU_NO_ENCODE)
1534 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1535 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1536 dwFlags &= ~ICU_NO_ENCODE;
1539 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1541 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1542 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1543 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1545 return (hr == S_OK) ? TRUE : FALSE;
1548 /***********************************************************************
1549 * InternetCanonicalizeUrlW (WININET.@)
1551 * Escape unsafe characters and spaces
1558 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1559 LPDWORD lpdwBufferLength, DWORD dwFlags)
1562 DWORD dwURLFlags = URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE;
1564 TRACE("(%s, %p, %p, 0x%08x) bufferlength: %d\n", debugstr_w(lpszUrl), lpszBuffer,
1565 lpdwBufferLength, lpdwBufferLength ? *lpdwBufferLength : -1, dwFlags);
1567 if(dwFlags & ICU_DECODE)
1569 dwURLFlags |= URL_UNESCAPE;
1570 dwFlags &= ~ICU_DECODE;
1573 if(dwFlags & ICU_ESCAPE)
1575 dwURLFlags |= URL_UNESCAPE;
1576 dwFlags &= ~ICU_ESCAPE;
1579 if(dwFlags & ICU_BROWSER_MODE)
1581 dwURLFlags |= URL_BROWSER_MODE;
1582 dwFlags &= ~ICU_BROWSER_MODE;
1585 if(dwFlags & ICU_NO_ENCODE)
1587 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1588 dwURLFlags ^= URL_ESCAPE_UNSAFE;
1589 dwFlags &= ~ICU_NO_ENCODE;
1592 if (dwFlags) FIXME("Unhandled flags 0x%08x\n", dwFlags);
1594 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1595 if (hr == E_POINTER) SetLastError(ERROR_INSUFFICIENT_BUFFER);
1596 if (hr == E_INVALIDARG) SetLastError(ERROR_INVALID_PARAMETER);
1598 return (hr == S_OK) ? TRUE : FALSE;
1601 /* #################################################### */
1603 static INTERNET_STATUS_CALLBACK set_status_callback(
1604 LPWININETHANDLEHEADER lpwh, INTERNET_STATUS_CALLBACK callback, BOOL unicode)
1606 INTERNET_STATUS_CALLBACK ret;
1608 if (unicode) lpwh->dwInternalFlags |= INET_CALLBACKW;
1609 else lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1611 ret = lpwh->lpfnStatusCB;
1612 lpwh->lpfnStatusCB = callback;
1617 /***********************************************************************
1618 * InternetSetStatusCallbackA (WININET.@)
1620 * Sets up a callback function which is called as progress is made
1621 * during an operation.
1624 * Previous callback or NULL on success
1625 * INTERNET_INVALID_STATUS_CALLBACK on failure
1628 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1629 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1631 INTERNET_STATUS_CALLBACK retVal;
1632 LPWININETHANDLEHEADER lpwh;
1634 TRACE("0x%08x\n", (ULONG)hInternet);
1636 if (!(lpwh = WININET_GetObject(hInternet)))
1637 return INTERNET_INVALID_STATUS_CALLBACK;
1639 retVal = set_status_callback(lpwh, lpfnIntCB, FALSE);
1641 WININET_Release( lpwh );
1645 /***********************************************************************
1646 * InternetSetStatusCallbackW (WININET.@)
1648 * Sets up a callback function which is called as progress is made
1649 * during an operation.
1652 * Previous callback or NULL on success
1653 * INTERNET_INVALID_STATUS_CALLBACK on failure
1656 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1657 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1659 INTERNET_STATUS_CALLBACK retVal;
1660 LPWININETHANDLEHEADER lpwh;
1662 TRACE("0x%08x\n", (ULONG)hInternet);
1664 if (!(lpwh = WININET_GetObject(hInternet)))
1665 return INTERNET_INVALID_STATUS_CALLBACK;
1667 retVal = set_status_callback(lpwh, lpfnIntCB, TRUE);
1669 WININET_Release( lpwh );
1673 /***********************************************************************
1674 * InternetSetFilePointer (WININET.@)
1676 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1677 PVOID pReserved, DWORD dwMoveContext, DWORD_PTR dwContext)
1683 /***********************************************************************
1684 * InternetWriteFile (WININET.@)
1686 * Write data to an open internet file
1693 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1694 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1696 BOOL retval = FALSE;
1698 LPWININETHANDLEHEADER lpwh;
1701 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1705 switch (lpwh->htype)
1709 LPWININETHTTPREQW lpwhr;
1710 lpwhr = (LPWININETHTTPREQW)lpwh;
1712 TRACE("HTTPREQ %i\n",dwNumOfBytesToWrite);
1713 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1714 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1716 WININET_Release( lpwh );
1722 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1731 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1732 retval = (res >= 0);
1733 *lpdwNumOfBytesWritten = retval ? res : 0;
1735 WININET_Release( lpwh );
1741 BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1742 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1743 BOOL bWait, BOOL bSendCompletionStatus)
1745 BOOL retval = FALSE;
1748 LPWININETHTTPREQW lpwhr;
1750 /* FIXME: this should use NETCON functions! */
1751 switch (lpwh->htype)
1754 lpwhr = (LPWININETHTTPREQW)lpwh;
1756 if (!NETCON_recv(&lpwhr->netConnection, lpBuffer,
1757 min(dwNumOfBytesToRead, lpwhr->dwContentLength - lpwhr->dwContentRead),
1758 bWait ? MSG_WAITALL : 0, &bytes_read))
1761 if (((lpwhr->dwContentLength != -1) &&
1762 (lpwhr->dwContentRead != lpwhr->dwContentLength)))
1763 ERR("not all data received %d/%d\n", lpwhr->dwContentRead,
1764 lpwhr->dwContentLength);
1766 /* always returns TRUE, even if the network layer returns an
1768 *pdwNumOfBytesRead = 0;
1769 HTTP_FinishedReading(lpwhr);
1774 lpwhr->dwContentRead += bytes_read;
1775 *pdwNumOfBytesRead = bytes_read;
1776 if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
1777 retval = HTTP_FinishedReading(lpwhr);
1784 /* FIXME: FTP should use NETCON_ stuff */
1785 nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
1788 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1789 retval = (res >= 0);
1790 *pdwNumOfBytesRead = retval ? res : 0;
1798 if (bSendCompletionStatus)
1800 INTERNET_ASYNC_RESULT iar;
1802 iar.dwResult = retval;
1803 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1804 INTERNET_GetLastError();
1806 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1807 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1808 sizeof(INTERNET_ASYNC_RESULT));
1813 /***********************************************************************
1814 * InternetReadFile (WININET.@)
1816 * Read data from an open internet file
1823 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1824 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1826 LPWININETHANDLEHEADER lpwh;
1829 TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1831 lpwh = WININET_GetObject( hFile );
1834 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1838 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1839 WININET_Release( lpwh );
1841 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1845 /***********************************************************************
1846 * InternetReadFileExA (WININET.@)
1848 * Read data from an open internet file
1851 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1852 * lpBuffersOut [I/O] Buffer.
1853 * dwFlags [I] Flags. See notes.
1854 * dwContext [I] Context for callbacks.
1861 * The parameter dwFlags include zero or more of the following flags:
1862 *|IRF_ASYNC - Makes the call asynchronous.
1863 *|IRF_SYNC - Makes the call synchronous.
1864 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1865 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1867 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1870 * InternetOpenUrlA(), HttpOpenRequestA()
1872 void AsyncInternetReadFileExProc(WORKREQUEST *workRequest)
1874 struct WORKREQ_INTERNETREADFILEEXA const *req = &workRequest->u.InternetReadFileExA;
1876 TRACE("INTERNETREADFILEEXA %p\n", workRequest->hdr);
1878 INTERNET_ReadFile(workRequest->hdr, req->lpBuffersOut->lpvBuffer,
1879 req->lpBuffersOut->dwBufferLength,
1880 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
1883 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1884 DWORD dwFlags, DWORD_PTR dwContext)
1886 BOOL retval = FALSE;
1887 LPWININETHANDLEHEADER lpwh;
1889 TRACE("(%p %p 0x%x 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1891 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1892 FIXME("these dwFlags aren't implemented: 0x%x\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1894 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1896 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
1900 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1903 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1907 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1908 INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
1910 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1911 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better */
1912 if (dwFlags & IRF_ASYNC)
1914 DWORD dwDataAvailable = 0;
1916 if (lpwh->htype == WH_HHTTPREQ)
1917 NETCON_query_data_available(&((LPWININETHTTPREQW)lpwh)->netConnection,
1920 if (!dwDataAvailable)
1922 WORKREQUEST workRequest;
1923 struct WORKREQ_INTERNETREADFILEEXA *req;
1925 workRequest.asyncproc = AsyncInternetReadFileExProc;
1926 workRequest.hdr = WININET_AddRef( lpwh );
1927 req = &workRequest.u.InternetReadFileExA;
1928 req->lpBuffersOut = lpBuffersOut;
1930 if (!INTERNET_AsyncCall(&workRequest))
1931 WININET_Release( lpwh );
1933 INTERNET_SetLastError(ERROR_IO_PENDING);
1938 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1939 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1940 !(dwFlags & IRF_NO_WAIT), FALSE);
1944 DWORD dwBytesReceived = lpBuffersOut->dwBufferLength;
1945 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1946 INTERNET_STATUS_RESPONSE_RECEIVED, &dwBytesReceived,
1947 sizeof(dwBytesReceived));
1951 WININET_Release( lpwh );
1953 TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1957 /***********************************************************************
1958 * InternetReadFileExW (WININET.@)
1960 * Read data from an open internet file.
1963 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1964 * lpBuffersOut [I/O] Buffer.
1965 * dwFlags [I] Flags.
1966 * dwContext [I] Context for callbacks.
1969 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1972 * Not implemented in Wine or native either (as of IE6 SP2).
1975 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1976 DWORD dwFlags, DWORD_PTR dwContext)
1978 ERR("(%p, %p, 0x%x, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1980 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1984 /***********************************************************************
1985 * INET_QueryOptionHelper (internal)
1987 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1988 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1990 LPWININETHANDLEHEADER lpwhh;
1991 BOOL bSuccess = FALSE;
1993 TRACE("(%p, 0x%08x, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1995 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1999 case INTERNET_OPTION_HANDLE_TYPE:
2005 WARN("Invalid hInternet handle\n");
2006 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2010 type = lpwhh->htype;
2012 TRACE("INTERNET_OPTION_HANDLE_TYPE: %d\n", type);
2014 if (*lpdwBufferLength < sizeof(ULONG))
2015 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2018 memcpy(lpBuffer, &type, sizeof(ULONG));
2021 *lpdwBufferLength = sizeof(ULONG);
2025 case INTERNET_OPTION_REQUEST_FLAGS:
2028 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %d\n", flags);
2029 if (*lpdwBufferLength < sizeof(ULONG))
2030 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2033 memcpy(lpBuffer, &flags, sizeof(ULONG));
2036 *lpdwBufferLength = sizeof(ULONG);
2040 case INTERNET_OPTION_URL:
2041 case INTERNET_OPTION_DATAFILE_NAME:
2045 WARN("Invalid hInternet handle\n");
2046 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
2049 if (lpwhh->htype == WH_HHTTPREQ)
2051 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2053 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2054 static const WCHAR szHost[] = {'H','o','s','t',0};
2058 Host = HTTP_GetHeader(lpreq,szHost);
2059 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2060 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2063 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2064 lpBuffer,*lpdwBufferLength,NULL,NULL);
2065 if (sizeRequired > *lpdwBufferLength)
2066 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2069 *lpdwBufferLength = sizeRequired;
2073 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2074 if (*lpdwBufferLength < sizeRequired)
2075 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2078 strcpyW(lpBuffer, url);
2081 *lpdwBufferLength = sizeRequired;
2086 case INTERNET_OPTION_HTTP_VERSION:
2088 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2089 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2093 * Presently hardcoded to 1.1
2095 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2096 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2099 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2102 case INTERNET_OPTION_CONNECTED_STATE:
2104 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2105 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2107 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2108 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2111 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2114 *lpdwBufferLength = sizeof(*pdwConnectedState);
2117 case INTERNET_OPTION_PROXY:
2119 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2120 WININETAPPINFOW wai;
2124 TRACE("Getting global proxy info\n");
2125 memset(&wai, 0, sizeof(WININETAPPINFOW));
2126 INTERNET_ConfigureProxyFromReg( &wai );
2132 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2133 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2135 if (lpwai->lpszProxy)
2136 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2138 if (lpwai->lpszProxyBypass)
2139 proxyBypassBytesRequired =
2140 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2141 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2142 proxyBytesRequired + proxyBypassBytesRequired)
2143 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2146 LPWSTR proxy = (LPWSTR)((LPBYTE)lpBuffer +
2147 sizeof(INTERNET_PROXY_INFOW));
2148 LPWSTR proxy_bypass = (LPWSTR)((LPBYTE)lpBuffer +
2149 sizeof(INTERNET_PROXY_INFOW) +
2150 proxyBytesRequired);
2152 pPI->dwAccessType = lpwai->dwAccessType;
2153 pPI->lpszProxy = NULL;
2154 pPI->lpszProxyBypass = NULL;
2155 if (lpwai->lpszProxy)
2157 lstrcpyW(proxy, lpwai->lpszProxy);
2158 pPI->lpszProxy = proxy;
2161 if (lpwai->lpszProxyBypass)
2163 lstrcpyW(proxy_bypass, lpwai->lpszProxyBypass);
2164 pPI->lpszProxyBypass = proxy_bypass;
2168 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2169 proxyBytesRequired + proxyBypassBytesRequired;
2173 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2174 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2176 if (lpwai->lpszProxy)
2177 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2178 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2179 if (lpwai->lpszProxyBypass)
2180 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2181 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2182 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2183 proxyBytesRequired + proxyBypassBytesRequired)
2184 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2187 LPSTR proxy = (LPSTR)((LPBYTE)lpBuffer +
2188 sizeof(INTERNET_PROXY_INFOA));
2189 LPSTR proxy_bypass = (LPSTR)((LPBYTE)lpBuffer +
2190 sizeof(INTERNET_PROXY_INFOA) +
2191 proxyBytesRequired);
2193 pPI->dwAccessType = lpwai->dwAccessType;
2194 pPI->lpszProxy = NULL;
2195 pPI->lpszProxyBypass = NULL;
2196 if (lpwai->lpszProxy)
2198 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2199 proxy, proxyBytesRequired, NULL, NULL);
2200 pPI->lpszProxy = proxy;
2203 if (lpwai->lpszProxyBypass)
2205 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2206 -1, proxy_bypass, proxyBypassBytesRequired,
2208 pPI->lpszProxyBypass = proxy_bypass;
2212 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2213 proxyBytesRequired + proxyBypassBytesRequired;
2217 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2220 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %d\n", conn);
2221 if (*lpdwBufferLength < sizeof(ULONG))
2222 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2225 memcpy(lpBuffer, &conn, sizeof(ULONG));
2228 *lpdwBufferLength = sizeof(ULONG);
2231 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2234 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %d\n", conn);
2235 if (*lpdwBufferLength < sizeof(ULONG))
2236 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2239 memcpy(lpBuffer, &conn, sizeof(ULONG));
2242 *lpdwBufferLength = sizeof(ULONG);
2245 case INTERNET_OPTION_SECURITY_FLAGS:
2246 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2249 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2252 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2255 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2257 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2258 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2260 else if (lpwhh->htype == WH_HHTTPREQ)
2262 LPWININETHTTPREQW lpwhr;
2263 PCCERT_CONTEXT context;
2265 lpwhr = (LPWININETHTTPREQW)lpwhh;
2266 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2269 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2272 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2273 info->ftExpiry = context->pCertInfo->NotAfter;
2274 info->ftStart = context->pCertInfo->NotBefore;
2277 strLen = CertNameToStrW(context->dwCertEncodingType,
2278 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2280 info->lpszSubjectInfo = LocalAlloc(0,
2281 strLen * sizeof(WCHAR));
2282 if (info->lpszSubjectInfo)
2283 CertNameToStrW(context->dwCertEncodingType,
2284 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2285 info->lpszSubjectInfo, strLen);
2286 strLen = CertNameToStrW(context->dwCertEncodingType,
2287 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2289 info->lpszIssuerInfo = LocalAlloc(0,
2290 strLen * sizeof(WCHAR));
2291 if (info->lpszIssuerInfo)
2292 CertNameToStrW(context->dwCertEncodingType,
2293 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2294 info->lpszIssuerInfo, strLen);
2298 LPINTERNET_CERTIFICATE_INFOA infoA =
2299 (LPINTERNET_CERTIFICATE_INFOA)info;
2301 strLen = CertNameToStrA(context->dwCertEncodingType,
2302 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2304 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2305 if (infoA->lpszSubjectInfo)
2306 CertNameToStrA(context->dwCertEncodingType,
2307 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2308 infoA->lpszSubjectInfo, strLen);
2309 strLen = CertNameToStrA(context->dwCertEncodingType,
2310 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2312 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2313 if (infoA->lpszIssuerInfo)
2314 CertNameToStrA(context->dwCertEncodingType,
2315 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2316 infoA->lpszIssuerInfo, strLen);
2319 * Contrary to MSDN, these do not appear to be set.
2321 * lpszSignatureAlgName
2322 * lpszEncryptionAlgName
2325 CertFreeCertificateContext(context);
2331 FIXME("Stub! %d\n", dwOption);
2335 WININET_Release( lpwhh );
2340 /***********************************************************************
2341 * InternetQueryOptionW (WININET.@)
2343 * Queries an options on the specified handle
2350 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2351 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2353 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2356 /***********************************************************************
2357 * InternetQueryOptionA (WININET.@)
2359 * Queries an options on the specified handle
2366 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2367 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2369 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2373 /***********************************************************************
2374 * InternetSetOptionW (WININET.@)
2376 * Sets an options on the specified handle
2383 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2384 LPVOID lpBuffer, DWORD dwBufferLength)
2386 LPWININETHANDLEHEADER lpwhh;
2389 TRACE("0x%08x\n", dwOption);
2391 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2397 case INTERNET_OPTION_CALLBACK:
2399 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2400 ret = (set_status_callback(lpwhh, callback, TRUE) != INTERNET_INVALID_STATUS_CALLBACK);
2403 case INTERNET_OPTION_HTTP_VERSION:
2405 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2406 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%d,%d): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2409 case INTERNET_OPTION_ERROR_MASK:
2411 unsigned long flags=*(unsigned long*)lpBuffer;
2412 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2415 case INTERNET_OPTION_CODEPAGE:
2417 unsigned long codepage=*(unsigned long*)lpBuffer;
2418 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2421 case INTERNET_OPTION_REQUEST_PRIORITY:
2423 unsigned long priority=*(unsigned long*)lpBuffer;
2424 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2427 case INTERNET_OPTION_CONNECT_TIMEOUT:
2429 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2430 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2433 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2435 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2436 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2439 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2441 unsigned long conns=*(unsigned long*)lpBuffer;
2442 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2445 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2447 unsigned long conns=*(unsigned long*)lpBuffer;
2448 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2451 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2452 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2454 case INTERNET_OPTION_END_BROWSER_SESSION:
2455 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2457 case INTERNET_OPTION_CONNECTED_STATE:
2458 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2460 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2461 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2463 case INTERNET_OPTION_SEND_TIMEOUT:
2464 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2465 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2466 if (dwBufferLength == sizeof(DWORD))
2468 if (lpwhh->htype == WH_HHTTPREQ)
2469 ret = NETCON_set_timeout(
2470 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2471 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2472 *(DWORD *)lpBuffer);
2475 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2481 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2485 case INTERNET_OPTION_CONNECT_RETRIES:
2486 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2488 case INTERNET_OPTION_CONTEXT_VALUE:
2489 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2491 case INTERNET_OPTION_SECURITY_FLAGS:
2492 FIXME("Option INTERNET_OPTION_SECURITY_FLAGS; STUB\n");
2495 FIXME("Option %d STUB\n",dwOption);
2496 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2500 WININET_Release( lpwhh );
2506 /***********************************************************************
2507 * InternetSetOptionA (WININET.@)
2509 * Sets an options on the specified handle.
2516 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2517 LPVOID lpBuffer, DWORD dwBufferLength)
2525 case INTERNET_OPTION_CALLBACK:
2527 LPWININETHANDLEHEADER lpwh;
2528 INTERNET_STATUS_CALLBACK callback = *(INTERNET_STATUS_CALLBACK *)lpBuffer;
2530 if (!(lpwh = (LPWININETHANDLEHEADER)WININET_GetObject(hInternet))) return FALSE;
2531 r = (set_status_callback(lpwh, callback, FALSE) != INTERNET_INVALID_STATUS_CALLBACK);
2532 WININET_Release(lpwh);
2535 case INTERNET_OPTION_PROXY:
2537 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2538 LPINTERNET_PROXY_INFOW piw;
2539 DWORD proxlen, prbylen;
2542 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2543 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2544 wlen = sizeof(*piw) + proxlen + prbylen;
2545 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2546 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2547 piw->dwAccessType = pi->dwAccessType;
2548 prox = (LPWSTR) &piw[1];
2549 prby = &prox[proxlen+1];
2550 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2551 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2552 piw->lpszProxy = prox;
2553 piw->lpszProxyBypass = prby;
2556 case INTERNET_OPTION_USER_AGENT:
2557 case INTERNET_OPTION_USERNAME:
2558 case INTERNET_OPTION_PASSWORD:
2559 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2561 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2562 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2567 wlen = dwBufferLength;
2570 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2572 if( lpBuffer != wbuffer )
2573 HeapFree( GetProcessHeap(), 0, wbuffer );
2579 /***********************************************************************
2580 * InternetSetOptionExA (WININET.@)
2582 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2583 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2585 FIXME("Flags %08x ignored\n", dwFlags);
2586 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2589 /***********************************************************************
2590 * InternetSetOptionExW (WININET.@)
2592 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2593 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2595 FIXME("Flags %08x ignored\n", dwFlags);
2596 if( dwFlags & ~ISO_VALID_FLAGS )
2598 INTERNET_SetLastError( ERROR_INVALID_PARAMETER );
2601 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2604 static const WCHAR WININET_wkday[7][4] =
2605 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2606 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2607 static const WCHAR WININET_month[12][4] =
2608 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2609 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2610 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2612 /***********************************************************************
2613 * InternetTimeFromSystemTimeA (WININET.@)
2615 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2618 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2620 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2622 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2623 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2628 /***********************************************************************
2629 * InternetTimeFromSystemTimeW (WININET.@)
2631 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2633 static const WCHAR date[] =
2634 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2635 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2637 TRACE( "%p 0x%08x %p 0x%08x\n", time, format, string, size );
2639 if (!time || !string) return FALSE;
2641 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2644 sprintfW( string, date,
2645 WININET_wkday[time->wDayOfWeek],
2647 WININET_month[time->wMonth - 1],
2656 /***********************************************************************
2657 * InternetTimeToSystemTimeA (WININET.@)
2659 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2665 TRACE( "%s %p 0x%08x\n", debugstr_a(string), time, reserved );
2667 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2668 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2672 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2673 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2674 HeapFree( GetProcessHeap(), 0, stringW );
2679 /***********************************************************************
2680 * InternetTimeToSystemTimeW (WININET.@)
2682 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2685 const WCHAR *s = string;
2688 TRACE( "%s %p 0x%08x\n", debugstr_w(string), time, reserved );
2690 if (!string || !time) return FALSE;
2692 /* Windows does this too */
2693 GetSystemTime( time );
2695 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2696 * a SYSTEMTIME structure.
2699 while (*s && !isalphaW( *s )) s++;
2700 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2701 time->wDayOfWeek = 7;
2703 for (i = 0; i < 7; i++)
2705 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2706 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2707 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2709 time->wDayOfWeek = i;
2714 if (time->wDayOfWeek > 6) return TRUE;
2715 while (*s && !isdigitW( *s )) s++;
2716 time->wDay = strtolW( s, &end, 10 );
2719 while (*s && !isalphaW( *s )) s++;
2720 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2723 for (i = 0; i < 12; i++)
2725 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2726 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2727 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2729 time->wMonth = i + 1;
2733 if (time->wMonth == 0) return TRUE;
2735 while (*s && !isdigitW( *s )) s++;
2736 if (*s == '\0') return TRUE;
2737 time->wYear = strtolW( s, &end, 10 );
2740 while (*s && !isdigitW( *s )) s++;
2741 if (*s == '\0') return TRUE;
2742 time->wHour = strtolW( s, &end, 10 );
2745 while (*s && !isdigitW( *s )) s++;
2746 if (*s == '\0') return TRUE;
2747 time->wMinute = strtolW( s, &end, 10 );
2750 while (*s && !isdigitW( *s )) s++;
2751 if (*s == '\0') return TRUE;
2752 time->wSecond = strtolW( s, &end, 10 );
2755 time->wMilliseconds = 0;
2759 /***********************************************************************
2760 * InternetCheckConnectionW (WININET.@)
2762 * Pings a requested host to check internet connection
2765 * TRUE on success and FALSE on failure. If a failure then
2766 * ERROR_NOT_CONNECTED is placed into GetLastError
2769 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2772 * this is a kludge which runs the resident ping program and reads the output.
2774 * Anyone have a better idea?
2778 static const CHAR ping[] = "ping -c 1 ";
2779 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2780 CHAR *command = NULL;
2789 * Crack or set the Address
2791 if (lpszUrl == NULL)
2794 * According to the doc we are supost to use the ip for the next
2795 * server in the WnInet internal server database. I have
2796 * no idea what that is or how to get it.
2798 * So someone needs to implement this.
2800 FIXME("Unimplemented with URL of NULL\n");
2805 URL_COMPONENTSW components;
2807 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2808 components.lpszHostName = (LPWSTR)&hostW;
2809 components.dwHostNameLength = 1024;
2811 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2814 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2815 port = components.nPort;
2816 TRACE("port: %d\n", port);
2819 if (dwFlags & FLAG_ICC_FORCE_CONNECTION)
2821 struct sockaddr_in sin;
2824 if (!GetAddress(hostW, port, &sin))
2826 fd = socket(sin.sin_family, SOCK_STREAM, 0);
2829 if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == 0)
2837 * Build our ping command
2839 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2840 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2841 strcpy(command,ping);
2842 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2843 strcat(command,redirect);
2845 TRACE("Ping command is : %s\n",command);
2847 status = system(command);
2849 TRACE("Ping returned a code of %i\n",status);
2851 /* Ping return code of 0 indicates success */
2858 HeapFree( GetProcessHeap(), 0, command );
2860 INTERNET_SetLastError(ERROR_NOT_CONNECTED);
2866 /***********************************************************************
2867 * InternetCheckConnectionA (WININET.@)
2869 * Pings a requested host to check internet connection
2872 * TRUE on success and FALSE on failure. If a failure then
2873 * ERROR_NOT_CONNECTED is placed into GetLastError
2876 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2882 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2883 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2885 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2886 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2887 HeapFree(GetProcessHeap(), 0, szUrl);
2893 /**********************************************************
2894 * INTERNET_InternetOpenUrlW (internal)
2899 * handle of connection or NULL on failure
2901 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2902 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
2904 URL_COMPONENTSW urlComponents;
2905 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2906 WCHAR password[1024], path[2048], extra[1024];
2907 HINTERNET client = NULL, client1 = NULL;
2909 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2910 dwHeadersLength, dwFlags, dwContext);
2912 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2913 urlComponents.lpszScheme = protocol;
2914 urlComponents.dwSchemeLength = 32;
2915 urlComponents.lpszHostName = hostName;
2916 urlComponents.dwHostNameLength = MAXHOSTNAME;
2917 urlComponents.lpszUserName = userName;
2918 urlComponents.dwUserNameLength = 1024;
2919 urlComponents.lpszPassword = password;
2920 urlComponents.dwPasswordLength = 1024;
2921 urlComponents.lpszUrlPath = path;
2922 urlComponents.dwUrlPathLength = 2048;
2923 urlComponents.lpszExtraInfo = extra;
2924 urlComponents.dwExtraInfoLength = 1024;
2925 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2927 switch(urlComponents.nScheme) {
2928 case INTERNET_SCHEME_FTP:
2929 if(urlComponents.nPort == 0)
2930 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2931 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2932 userName, password, dwFlags, dwContext, INET_OPENURL);
2935 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2936 if(client1 == NULL) {
2937 InternetCloseHandle(client);
2942 case INTERNET_SCHEME_HTTP:
2943 case INTERNET_SCHEME_HTTPS: {
2944 static const WCHAR szStars[] = { '*','/','*', 0 };
2945 LPCWSTR accept[2] = { szStars, NULL };
2946 if(urlComponents.nPort == 0) {
2947 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2948 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2950 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2952 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2953 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2954 userName, password, dwFlags, dwContext, INET_OPENURL);
2958 if (urlComponents.dwExtraInfoLength) {
2960 DWORD len = urlComponents.dwUrlPathLength + urlComponents.dwExtraInfoLength + 1;
2962 if (!(path_extra = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
2964 InternetCloseHandle(client);
2967 strcpyW(path_extra, urlComponents.lpszUrlPath);
2968 strcatW(path_extra, urlComponents.lpszExtraInfo);
2969 client1 = HttpOpenRequestW(client, NULL, path_extra, NULL, NULL, accept, dwFlags, dwContext);
2970 HeapFree(GetProcessHeap(), 0, path_extra);
2973 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2975 if(client1 == NULL) {
2976 InternetCloseHandle(client);
2979 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2980 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0) &&
2981 GetLastError() != ERROR_IO_PENDING) {
2982 InternetCloseHandle(client1);
2987 case INTERNET_SCHEME_GOPHER:
2988 /* gopher doesn't seem to be implemented in wine, but it's supposed
2989 * to be supported by InternetOpenUrlA. */
2991 INTERNET_SetLastError(ERROR_INTERNET_UNRECOGNIZED_SCHEME);
2995 TRACE(" %p <--\n", client1);
3000 /**********************************************************
3001 * InternetOpenUrlW (WININET.@)
3006 * handle of connection or NULL on failure
3008 static void AsyncInternetOpenUrlProc(WORKREQUEST *workRequest)
3010 struct WORKREQ_INTERNETOPENURLW const *req = &workRequest->u.InternetOpenUrlW;
3011 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest->hdr;
3015 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3016 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3017 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3018 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3021 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
3022 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3024 HINTERNET ret = NULL;
3025 LPWININETAPPINFOW hIC = NULL;
3027 if (TRACE_ON(wininet)) {
3028 TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
3029 dwHeadersLength, dwFlags, dwContext);
3031 dump_INTERNET_FLAGS(dwFlags);
3036 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3040 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
3041 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
3042 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
3046 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
3047 WORKREQUEST workRequest;
3048 struct WORKREQ_INTERNETOPENURLW *req;
3050 workRequest.asyncproc = AsyncInternetOpenUrlProc;
3051 workRequest.hdr = WININET_AddRef( &hIC->hdr );
3052 req = &workRequest.u.InternetOpenUrlW;
3053 req->lpszUrl = WININET_strdupW(lpszUrl);
3055 req->lpszHeaders = WININET_strdupW(lpszHeaders);
3057 req->lpszHeaders = 0;
3058 req->dwHeadersLength = dwHeadersLength;
3059 req->dwFlags = dwFlags;
3060 req->dwContext = dwContext;
3062 INTERNET_AsyncCall(&workRequest);
3064 * This is from windows.
3066 INTERNET_SetLastError(ERROR_IO_PENDING);
3068 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
3073 WININET_Release( &hIC->hdr );
3074 TRACE(" %p <--\n", ret);
3079 /**********************************************************
3080 * InternetOpenUrlA (WININET.@)
3085 * handle of connection or NULL on failure
3087 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3088 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext)
3090 HINTERNET rc = (HINTERNET)NULL;
3094 LPWSTR szUrl = NULL;
3095 LPWSTR szHeaders = NULL;
3100 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3101 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3103 return (HINTERNET)NULL;
3104 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3108 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3109 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3111 HeapFree(GetProcessHeap(), 0, szUrl);
3112 return (HINTERNET)NULL;
3114 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3117 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3118 lenHeaders, dwFlags, dwContext);
3120 HeapFree(GetProcessHeap(), 0, szUrl);
3121 HeapFree(GetProcessHeap(), 0, szHeaders);
3127 static LPWITHREADERROR INTERNET_AllocThreadError(void)
3129 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3133 lpwite->dwError = 0;
3134 lpwite->response[0] = '\0';
3137 if (!TlsSetValue(g_dwTlsErrIndex, lpwite))
3139 HeapFree(GetProcessHeap(), 0, lpwite);
3147 /***********************************************************************
3148 * INTERNET_SetLastError (internal)
3150 * Set last thread specific error
3155 void INTERNET_SetLastError(DWORD dwError)
3157 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3160 lpwite = INTERNET_AllocThreadError();
3162 SetLastError(dwError);
3164 lpwite->dwError = dwError;
3168 /***********************************************************************
3169 * INTERNET_GetLastError (internal)
3171 * Get last thread specific error
3176 DWORD INTERNET_GetLastError(void)
3178 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3179 if (!lpwite) return 0;
3180 /* TlsGetValue clears last error, so set it again here */
3181 SetLastError(lpwite->dwError);
3182 return lpwite->dwError;
3186 /***********************************************************************
3187 * INTERNET_WorkerThreadFunc (internal)
3189 * Worker thread execution function
3194 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3196 LPWORKREQUEST lpRequest = lpvParam;
3197 WORKREQUEST workRequest;
3201 memcpy(&workRequest, lpRequest, sizeof(WORKREQUEST));
3202 HeapFree(GetProcessHeap(), 0, lpRequest);
3204 workRequest.asyncproc(&workRequest);
3206 WININET_Release( workRequest.hdr );
3211 /***********************************************************************
3212 * INTERNET_AsyncCall (internal)
3214 * Retrieves work request from queue
3219 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3222 LPWORKREQUEST lpNewRequest;
3226 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3230 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3232 bSuccess = QueueUserWorkItem(INTERNET_WorkerThreadFunc, lpNewRequest, WT_EXECUTELONGFUNCTION);
3235 HeapFree(GetProcessHeap(), 0, lpNewRequest);
3236 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3243 /***********************************************************************
3244 * INTERNET_GetResponseBuffer (internal)
3249 LPSTR INTERNET_GetResponseBuffer(void)
3251 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3253 lpwite = INTERNET_AllocThreadError();
3255 return lpwite->response;
3258 /***********************************************************************
3259 * INTERNET_GetNextLine (internal)
3261 * Parse next line in directory string listing
3264 * Pointer to beginning of next line
3269 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3273 BOOL bSuccess = FALSE;
3275 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3280 FD_SET(nSocket, &infd);
3281 tv.tv_sec=RESPONSE_TIMEOUT;
3284 while (nRecv < MAX_REPLY_LEN)
3286 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3288 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3290 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3294 if (lpszBuffer[nRecv] == '\n')
3299 if (lpszBuffer[nRecv] != '\r')
3304 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3312 lpszBuffer[nRecv] = '\0';
3314 TRACE(":%d %s\n", nRecv, lpszBuffer);
3323 /**********************************************************
3324 * InternetQueryDataAvailable (WININET.@)
3326 * Determines how much data is available to be read.
3329 * TRUE on success, FALSE if an error occurred. If
3330 * INTERNET_FLAG_ASYNC was specified in InternetOpen, and
3331 * no data is presently available, FALSE is returned with
3332 * the last error ERROR_IO_PENDING; a callback with status
3333 * INTERNET_STATUS_REQUEST_COMPLETE will be sent when more
3334 * data is available.
3336 void AsyncInternetQueryDataAvailableProc(WORKREQUEST *workRequest)
3338 LPWININETHTTPREQW lpwhr;
3339 INTERNET_ASYNC_RESULT iar;
3342 TRACE("INTERNETQUERYDATAAVAILABLE %p\n", workRequest->hdr);
3344 switch (workRequest->hdr->htype)
3347 lpwhr = (LPWININETHTTPREQW)workRequest->hdr;
3348 iar.dwResult = NETCON_recv(&lpwhr->netConnection, buffer,
3350 lpwhr->dwContentLength - lpwhr->dwContentRead),
3351 MSG_PEEK, (int *)&iar.dwError);
3352 INTERNET_SendCallback(workRequest->hdr, workRequest->hdr->dwContext,
3353 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
3354 sizeof(INTERNET_ASYNC_RESULT));
3358 FIXME("unsupported file type\n");
3363 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3364 LPDWORD lpdwNumberOfBytesAvailble,
3365 DWORD dwFlags, DWORD_PTR dwContext)
3367 LPWININETHTTPREQW lpwhr;
3368 BOOL retval = FALSE;
3371 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3374 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
3378 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3380 switch (lpwhr->hdr.htype)
3384 if (NETCON_query_data_available(&lpwhr->netConnection,
3385 lpdwNumberOfBytesAvailble) &&
3386 !*lpdwNumberOfBytesAvailble)
3388 /* Even if we are in async mode, we need to determine whether
3389 * there is actually more data available. We do this by trying
3390 * to peek only a single byte in async mode. */
3391 BOOL async = (lpwhr->lpHttpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC);
3392 if (NETCON_recv(&lpwhr->netConnection, buffer,
3393 min(async ? 1 : sizeof(buffer),
3394 lpwhr->dwContentLength - lpwhr->dwContentRead),
3395 MSG_PEEK, (int *)lpdwNumberOfBytesAvailble) &&
3396 async && *lpdwNumberOfBytesAvailble)
3398 WORKREQUEST workRequest;
3400 *lpdwNumberOfBytesAvailble = 0;
3401 workRequest.asyncproc = AsyncInternetQueryDataAvailableProc;
3402 workRequest.hdr = WININET_AddRef( &lpwhr->hdr );
3404 retval = INTERNET_AsyncCall(&workRequest);
3407 WININET_Release( &lpwhr->hdr );
3411 INTERNET_SetLastError(ERROR_IO_PENDING);
3419 FIXME("unsupported file type\n");
3422 WININET_Release( &lpwhr->hdr );
3424 TRACE("<-- %i\n",retval);
3429 /***********************************************************************
3430 * InternetLockRequestFile (WININET.@)
3432 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3439 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3446 /***********************************************************************
3447 * InternetAutodial (WININET.@)
3449 * On windows this function is supposed to dial the default internet
3450 * connection. We don't want to have Wine dial out to the internet so
3451 * we return TRUE by default. It might be nice to check if we are connected.
3458 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3462 /* Tell that we are connected to the internet. */
3466 /***********************************************************************
3467 * InternetAutodialHangup (WININET.@)
3469 * Hangs up a connection made with InternetAutodial
3478 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3482 /* we didn't dial, we don't disconnect */
3486 /***********************************************************************
3487 * InternetCombineUrlA (WININET.@)
3489 * Combine a base URL with a relative URL
3497 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3498 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3503 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3505 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3506 dwFlags ^= ICU_NO_ENCODE;
3507 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3512 /***********************************************************************
3513 * InternetCombineUrlW (WININET.@)
3515 * Combine a base URL with a relative URL
3523 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3524 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3529 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3531 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3532 dwFlags ^= ICU_NO_ENCODE;
3533 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3538 /* max port num is 65535 => 5 digits */
3539 #define MAX_WORD_DIGITS 5
3541 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3542 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3543 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3544 (url)->dw##component##Length : strlen((url)->lpsz##component))
3546 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3548 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3549 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3551 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3552 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3554 if ((nScheme == INTERNET_SCHEME_FTP) &&
3555 (nPort == INTERNET_DEFAULT_FTP_PORT))
3557 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3558 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3561 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3567 /* opaque urls do not fit into the standard url hierarchy and don't have
3568 * two following slashes */
3569 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3571 return (nScheme != INTERNET_SCHEME_FTP) &&
3572 (nScheme != INTERNET_SCHEME_GOPHER) &&
3573 (nScheme != INTERNET_SCHEME_HTTP) &&
3574 (nScheme != INTERNET_SCHEME_HTTPS) &&
3575 (nScheme != INTERNET_SCHEME_FILE);
3578 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3581 if (scheme < INTERNET_SCHEME_FIRST)
3583 index = scheme - INTERNET_SCHEME_FIRST;
3584 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3586 return (LPCWSTR)&url_schemes[index];
3589 /* we can calculate using ansi strings because we're just
3590 * calculating string length, not size
3592 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3593 LPDWORD lpdwUrlLength)
3595 INTERNET_SCHEME nScheme;
3599 if (lpUrlComponents->lpszScheme)
3601 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3602 *lpdwUrlLength += dwLen;
3603 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3609 nScheme = lpUrlComponents->nScheme;
3611 if (nScheme == INTERNET_SCHEME_DEFAULT)
3612 nScheme = INTERNET_SCHEME_HTTP;
3613 scheme = INTERNET_GetSchemeString(nScheme);
3614 *lpdwUrlLength += strlenW(scheme);
3617 (*lpdwUrlLength)++; /* ':' */
3618 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3619 *lpdwUrlLength += strlen("//");
3621 if (lpUrlComponents->lpszUserName)
3623 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3624 *lpdwUrlLength += strlen("@");
3628 if (lpUrlComponents->lpszPassword)
3630 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3635 if (lpUrlComponents->lpszPassword)
3637 *lpdwUrlLength += strlen(":");
3638 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3641 if (lpUrlComponents->lpszHostName)
3643 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3645 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3647 char szPort[MAX_WORD_DIGITS+1];
3649 sprintf(szPort, "%d", lpUrlComponents->nPort);
3650 *lpdwUrlLength += strlen(szPort);
3651 *lpdwUrlLength += strlen(":");
3654 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3655 (*lpdwUrlLength)++; /* '/' */
3658 if (lpUrlComponents->lpszUrlPath)
3659 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3664 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3668 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3670 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3671 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3672 urlCompW->nScheme = lpUrlComponents->nScheme;
3673 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3674 urlCompW->nPort = lpUrlComponents->nPort;
3675 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3676 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3677 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3678 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3680 if (lpUrlComponents->lpszScheme)
3682 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3683 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3684 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3685 -1, urlCompW->lpszScheme, len);
3688 if (lpUrlComponents->lpszHostName)
3690 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3691 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3692 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3693 -1, urlCompW->lpszHostName, len);
3696 if (lpUrlComponents->lpszUserName)
3698 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3699 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3700 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3701 -1, urlCompW->lpszUserName, len);
3704 if (lpUrlComponents->lpszPassword)
3706 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3707 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3708 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3709 -1, urlCompW->lpszPassword, len);
3712 if (lpUrlComponents->lpszUrlPath)
3714 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3715 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3716 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3717 -1, urlCompW->lpszUrlPath, len);
3720 if (lpUrlComponents->lpszExtraInfo)
3722 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3723 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3724 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3725 -1, urlCompW->lpszExtraInfo, len);
3729 /***********************************************************************
3730 * InternetCreateUrlA (WININET.@)
3732 * See InternetCreateUrlW.
3734 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3735 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3739 URL_COMPONENTSW urlCompW;
3741 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3743 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3745 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3749 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3752 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3754 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3756 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3757 *lpdwUrlLength /= sizeof(WCHAR);
3759 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3760 * minus one, so add one to leave room for NULL terminator
3763 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3765 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3766 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3767 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3768 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3769 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3770 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3771 HeapFree(GetProcessHeap(), 0, urlW);
3776 /***********************************************************************
3777 * InternetCreateUrlW (WININET.@)
3779 * Creates a URL from its component parts.
3782 * lpUrlComponents [I] URL Components.
3783 * dwFlags [I] Flags. See notes.
3784 * lpszUrl [I] Buffer in which to store the created URL.
3785 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3786 * lpszUrl in characters. On output, the number of bytes
3787 * required to store the URL including terminator.
3791 * The dwFlags parameter can be zero or more of the following:
3792 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3799 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3800 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3803 INTERNET_SCHEME nScheme;
3805 static const WCHAR slashSlashW[] = {'/','/'};
3806 static const WCHAR percentD[] = {'%','d',0};
3808 TRACE("(%p,%d,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3810 if (!lpUrlComponents || lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3812 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
3816 if (!calc_url_length(lpUrlComponents, &dwLen))
3819 if (!lpszUrl || *lpdwUrlLength < dwLen)
3821 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
3822 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
3826 *lpdwUrlLength = dwLen;
3831 if (lpUrlComponents->lpszScheme)
3833 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3834 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3837 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3842 nScheme = lpUrlComponents->nScheme;
3844 if (nScheme == INTERNET_SCHEME_DEFAULT)
3845 nScheme = INTERNET_SCHEME_HTTP;
3847 scheme = INTERNET_GetSchemeString(nScheme);
3848 dwLen = strlenW(scheme);
3849 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
3853 /* all schemes are followed by at least a colon */
3857 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3859 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
3860 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
3863 if (lpUrlComponents->lpszUserName)
3865 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3866 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
3869 if (lpUrlComponents->lpszPassword)
3874 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3875 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
3883 if (lpUrlComponents->lpszHostName)
3885 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3886 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
3889 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3891 WCHAR szPort[MAX_WORD_DIGITS+1];
3893 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3896 dwLen = strlenW(szPort);
3897 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
3901 /* add slash between hostname and path if necessary */
3902 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3910 if (lpUrlComponents->lpszUrlPath)
3912 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3913 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
3922 /***********************************************************************
3923 * InternetConfirmZoneCrossingA (WININET.@)
3926 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3928 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3929 return ERROR_SUCCESS;
3932 /***********************************************************************
3933 * InternetConfirmZoneCrossingW (WININET.@)
3936 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3938 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3939 return ERROR_SUCCESS;
3942 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3943 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3945 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3946 lpdwConnection, dwReserved);
3947 return ERROR_SUCCESS;
3950 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3951 DWORD_PTR* lpdwConnection, DWORD dwReserved )
3953 FIXME("(%p, %p, 0x%08x, %p, 0x%08x) stub\n", hwndParent, lpszConnectoid, dwFlags,
3954 lpdwConnection, dwReserved);
3955 return ERROR_SUCCESS;
3958 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3960 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3964 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3966 FIXME("(%s, %p, 0x%08x) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3970 DWORD WINAPI InternetHangUp( DWORD_PTR dwConnection, DWORD dwReserved )
3972 FIXME("(0x%08lx, 0x%08x) stub\n", dwConnection, dwReserved);
3973 return ERROR_SUCCESS;
3976 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3979 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3980 debugstr_w(pwszTarget), pbHexHash);
3984 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
3986 FIXME("(%p, 0x%08x) stub\n", hInternet, dwError);
3990 BOOL WINAPI InternetQueryFortezzaStatus(DWORD *a, DWORD_PTR b)
3992 FIXME("(%p, %08lx) stub\n", a, b);