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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/port.h"
32 #define MAXHOSTNAME 100 /* from http.c */
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_SOCKET_H
39 # include <sys/socket.h>
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
57 #include "wine/debug.h"
59 #define NO_SHLWAPI_STREAM
62 #include "wine/exception.h"
68 #include "wine/unicode.h"
71 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
73 #define MAX_IDLE_WORKER 1000*60*1
74 #define MAX_WORKER_THREADS 10
75 #define RESPONSE_TIMEOUT 30
77 #define GET_HWININET_FROM_LPWININETFINDNEXT(lpwh) \
78 (LPWININETAPPINFOW)(((LPWININETFTPSESSIONW)(lpwh->hdr.lpwhparent))->hdr.lpwhparent)
84 CHAR response[MAX_REPLY_LEN];
85 } WITHREADERROR, *LPWITHREADERROR;
87 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr);
88 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData);
89 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
90 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext);
91 static VOID INTERNET_ExecuteWork(void);
93 static DWORD g_dwTlsErrIndex = TLS_OUT_OF_INDEXES;
94 static LONG dwNumThreads;
95 static LONG dwNumIdleThreads;
96 static LONG dwNumJobs;
97 static HANDLE hEventArray[2];
98 #define hQuitEvent hEventArray[0]
99 #define hWorkEvent hEventArray[1]
100 static CRITICAL_SECTION csQueue;
101 static LPWORKREQUEST lpHeadWorkQueue;
102 static LPWORKREQUEST lpWorkQueueTail;
103 static HMODULE WININET_hModule;
105 #define HANDLE_CHUNK_SIZE 0x10
107 static CRITICAL_SECTION WININET_cs;
108 static CRITICAL_SECTION_DEBUG WININET_cs_debug =
111 { &WININET_cs_debug.ProcessLocksList, &WININET_cs_debug.ProcessLocksList },
112 0, 0, { (DWORD_PTR)(__FILE__ ": WININET_cs") }
114 static CRITICAL_SECTION WININET_cs = { &WININET_cs_debug, -1, 0, 0, 0, 0 };
116 static LPWININETHANDLEHEADER *WININET_Handles;
117 static UINT WININET_dwNextHandle;
118 static UINT WININET_dwMaxHandles;
120 HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info )
122 LPWININETHANDLEHEADER *p;
123 UINT handle = 0, num;
125 EnterCriticalSection( &WININET_cs );
126 if( !WININET_dwMaxHandles )
128 num = HANDLE_CHUNK_SIZE;
129 p = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
134 WININET_dwMaxHandles = num;
136 if( WININET_dwMaxHandles == WININET_dwNextHandle )
138 num = WININET_dwMaxHandles + HANDLE_CHUNK_SIZE;
139 p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
140 WININET_Handles, sizeof (UINT)* num);
144 WININET_dwMaxHandles = num;
147 handle = WININET_dwNextHandle;
148 if( WININET_Handles[handle] )
149 ERR("handle isn't free but should be\n");
150 WININET_Handles[handle] = WININET_AddRef( info );
152 while( WININET_Handles[WININET_dwNextHandle] &&
153 (WININET_dwNextHandle < WININET_dwMaxHandles ) )
154 WININET_dwNextHandle++;
157 LeaveCriticalSection( &WININET_cs );
159 return (HINTERNET) (handle+1);
162 HINTERNET WININET_FindHandle( LPWININETHANDLEHEADER info )
166 EnterCriticalSection( &WININET_cs );
167 for( i=0; i<WININET_dwMaxHandles; i++ )
169 if( info == WININET_Handles[i] )
171 WININET_AddRef( info );
176 LeaveCriticalSection( &WININET_cs );
178 return (HINTERNET) handle;
181 LPWININETHANDLEHEADER WININET_AddRef( LPWININETHANDLEHEADER info )
184 TRACE("%p -> refcount = %ld\n", info, info->dwRefCount );
188 LPWININETHANDLEHEADER WININET_GetObject( HINTERNET hinternet )
190 LPWININETHANDLEHEADER info = NULL;
191 UINT handle = (UINT) hinternet;
193 EnterCriticalSection( &WININET_cs );
195 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) &&
196 WININET_Handles[handle-1] )
197 info = WININET_AddRef( WININET_Handles[handle-1] );
199 LeaveCriticalSection( &WININET_cs );
201 TRACE("handle %d -> %p\n", handle, info);
206 BOOL WININET_Release( LPWININETHANDLEHEADER info )
209 TRACE( "object %p refcount = %ld\n", info, info->dwRefCount );
210 if( !info->dwRefCount )
212 TRACE( "destroying object %p\n", info);
213 info->destroy( info );
218 BOOL WININET_FreeHandle( HINTERNET hinternet )
221 UINT handle = (UINT) hinternet;
222 LPWININETHANDLEHEADER info = NULL;
224 EnterCriticalSection( &WININET_cs );
226 if( (handle > 0) && ( handle <= WININET_dwMaxHandles ) )
229 if( WININET_Handles[handle] )
231 info = WININET_Handles[handle];
232 TRACE( "destroying handle %d for object %p\n", handle+1, info);
233 WININET_Handles[handle] = NULL;
235 if( WININET_dwNextHandle > handle )
236 WININET_dwNextHandle = handle;
240 LeaveCriticalSection( &WININET_cs );
243 WININET_Release( info );
248 /***********************************************************************
249 * DllMain [Internal] Initializes the internal 'WININET.DLL'.
252 * hinstDLL [I] handle to the DLL's instance
254 * lpvReserved [I] reserved, must be NULL
261 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
263 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
266 case DLL_PROCESS_ATTACH:
268 g_dwTlsErrIndex = TlsAlloc();
270 if (g_dwTlsErrIndex == TLS_OUT_OF_INDEXES)
273 hQuitEvent = CreateEventW(0, TRUE, FALSE, NULL);
274 hWorkEvent = CreateEventW(0, FALSE, FALSE, NULL);
275 InitializeCriticalSection(&csQueue);
277 URLCacheContainers_CreateDefaults();
280 dwNumIdleThreads = 0;
283 WININET_hModule = (HMODULE)hinstDLL;
285 case DLL_THREAD_ATTACH:
288 case DLL_THREAD_DETACH:
289 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
291 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
292 HeapFree(GetProcessHeap(), 0, lpwite);
296 case DLL_PROCESS_DETACH:
298 URLCacheContainers_DeleteAll();
300 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
302 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
303 TlsFree(g_dwTlsErrIndex);
306 SetEvent(hQuitEvent);
308 CloseHandle(hQuitEvent);
309 CloseHandle(hWorkEvent);
310 DeleteCriticalSection(&csQueue);
318 /***********************************************************************
319 * InternetInitializeAutoProxyDll (WININET.@)
321 * Setup the internal proxy
330 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
333 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
337 /***********************************************************************
338 * DetectAutoProxyUrl (WININET.@)
340 * Auto detect the proxy url
346 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
347 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
350 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
355 /***********************************************************************
356 * INTERNET_ConfigureProxyFromReg
359 * The proxy may be specified in the form 'http=proxy.my.org'
360 * Presumably that means there can be ftp=ftpproxy.my.org too.
362 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
365 DWORD r, keytype, len, enabled;
366 LPCSTR lpszInternetSettings =
367 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
368 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
370 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
371 if ( r != ERROR_SUCCESS )
374 len = sizeof enabled;
375 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
376 (BYTE*)&enabled, &len);
377 if( (r == ERROR_SUCCESS) && enabled )
379 TRACE("Proxy is enabled.\n");
381 /* figure out how much memory the proxy setting takes */
382 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
384 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
387 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
389 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
390 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
391 (BYTE*)szProxy, &len);
393 /* find the http proxy, and strip away everything else */
394 p = strstrW( szProxy, szHttp );
397 p += lstrlenW(szHttp);
398 lstrcpyW( szProxy, p );
400 p = strchrW( szProxy, ' ' );
404 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
405 lpwai->lpszProxy = szProxy;
407 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
410 ERR("Couldn't read proxy server settings.\n");
413 TRACE("Proxy is not enabled.\n");
419 /***********************************************************************
420 * dump_INTERNET_FLAGS
422 * Helper function to TRACE the internet flags.
428 static void dump_INTERNET_FLAGS(DWORD dwFlags)
430 #define FE(x) { x, #x }
431 static const wininet_flag_info flag[] = {
432 FE(INTERNET_FLAG_RELOAD),
433 FE(INTERNET_FLAG_RAW_DATA),
434 FE(INTERNET_FLAG_EXISTING_CONNECT),
435 FE(INTERNET_FLAG_ASYNC),
436 FE(INTERNET_FLAG_PASSIVE),
437 FE(INTERNET_FLAG_NO_CACHE_WRITE),
438 FE(INTERNET_FLAG_MAKE_PERSISTENT),
439 FE(INTERNET_FLAG_FROM_CACHE),
440 FE(INTERNET_FLAG_SECURE),
441 FE(INTERNET_FLAG_KEEP_CONNECTION),
442 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
443 FE(INTERNET_FLAG_READ_PREFETCH),
444 FE(INTERNET_FLAG_NO_COOKIES),
445 FE(INTERNET_FLAG_NO_AUTH),
446 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
447 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
448 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
449 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
450 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
451 FE(INTERNET_FLAG_RESYNCHRONIZE),
452 FE(INTERNET_FLAG_HYPERLINK),
453 FE(INTERNET_FLAG_NO_UI),
454 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
455 FE(INTERNET_FLAG_CACHE_ASYNC),
456 FE(INTERNET_FLAG_FORMS_SUBMIT),
457 FE(INTERNET_FLAG_NEED_FILE),
458 FE(INTERNET_FLAG_TRANSFER_ASCII),
459 FE(INTERNET_FLAG_TRANSFER_BINARY)
464 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
465 if (flag[i].val & dwFlags) {
466 TRACE(" %s", flag[i].name);
467 dwFlags &= ~flag[i].val;
471 TRACE(" Unknown flags (%08lx)\n", dwFlags);
476 /***********************************************************************
477 * InternetOpenW (WININET.@)
479 * Per-application initialization of wininet
482 * HINTERNET on success
486 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
487 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
489 LPWININETAPPINFOW lpwai = NULL;
490 HINTERNET handle = NULL;
492 if (TRACE_ON(wininet)) {
493 #define FE(x) { x, #x }
494 static const wininet_flag_info access_type[] = {
495 FE(INTERNET_OPEN_TYPE_PRECONFIG),
496 FE(INTERNET_OPEN_TYPE_DIRECT),
497 FE(INTERNET_OPEN_TYPE_PROXY),
498 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
502 const char *access_type_str = "Unknown";
504 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent), dwAccessType,
505 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
506 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
507 if (access_type[i].val == dwAccessType) {
508 access_type_str = access_type[i].name;
512 TRACE(" access type : %s\n", access_type_str);
514 dump_INTERNET_FLAGS(dwFlags);
517 /* Clear any error information */
518 INTERNET_SetLastError(0);
520 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW));
523 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
527 memset(lpwai, 0, sizeof(WININETAPPINFOW));
528 lpwai->hdr.htype = WH_HINIT;
529 lpwai->hdr.lpwhparent = NULL;
530 lpwai->hdr.dwFlags = dwFlags;
531 lpwai->hdr.dwRefCount = 1;
532 lpwai->hdr.destroy = INTERNET_CloseHandle;
533 lpwai->dwAccessType = dwAccessType;
534 lpwai->lpszProxyUsername = NULL;
535 lpwai->lpszProxyPassword = NULL;
537 handle = WININET_AllocHandle( &lpwai->hdr );
540 HeapFree( GetProcessHeap(), 0, lpwai );
541 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
545 if (NULL != lpszAgent)
547 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
548 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
549 if (lpwai->lpszAgent)
550 lstrcpyW( lpwai->lpszAgent, lpszAgent );
552 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
553 INTERNET_ConfigureProxyFromReg( lpwai );
554 else if (NULL != lpszProxy)
556 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
557 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
558 if (lpwai->lpszProxy)
559 lstrcpyW( lpwai->lpszProxy, lpszProxy );
562 if (NULL != lpszProxyBypass)
564 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
565 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
566 if (lpwai->lpszProxyBypass)
567 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
572 WININET_Release( &lpwai->hdr );
574 TRACE("returning %p\n", lpwai);
580 /***********************************************************************
581 * InternetOpenA (WININET.@)
583 * Per-application initialization of wininet
586 * HINTERNET on success
590 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
591 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
593 HINTERNET rc = (HINTERNET)NULL;
595 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
597 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent),
598 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
602 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
603 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
604 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
609 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
610 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
611 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
614 if( lpszProxyBypass )
616 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
617 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
618 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
621 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
623 HeapFree(GetProcessHeap(), 0, szAgent);
624 HeapFree(GetProcessHeap(), 0, szProxy);
625 HeapFree(GetProcessHeap(), 0, szBypass);
630 /***********************************************************************
631 * InternetGetLastResponseInfoA (WININET.@)
633 * Return last wininet error description on the calling thread
636 * TRUE on success of writing to buffer
640 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
641 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
643 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
649 *lpdwError = lpwite->dwError;
652 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
653 *lpdwBufferLength = strlen(lpszBuffer);
656 *lpdwBufferLength = 0;
661 *lpdwBufferLength = 0;
667 /***********************************************************************
668 * InternetGetLastResponseInfoW (WININET.@)
670 * Return last wininet error description on the calling thread
673 * TRUE on success of writing to buffer
677 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
678 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
680 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
686 *lpdwError = lpwite->dwError;
689 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
690 *lpdwBufferLength = lstrlenW(lpszBuffer);
693 *lpdwBufferLength = 0;
698 *lpdwBufferLength = 0;
704 /***********************************************************************
705 * InternetGetConnectedState (WININET.@)
707 * Return connected state
711 * if lpdwStatus is not null, return the status (off line,
712 * modem, lan...) in it.
713 * FALSE if not connected
715 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
717 TRACE("(%p, 0x%08lx)\n", lpdwStatus, dwReserved);
720 FIXME("always returning LAN connection.\n");
721 *lpdwStatus = INTERNET_CONNECTION_LAN;
727 /***********************************************************************
728 * InternetGetConnectedStateExW (WININET.@)
730 * Return connected state
734 * lpdwStatus [O] Flags specifying the status of the internet connection.
735 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
736 * dwNameLen [I] Size of the buffer, in characters.
737 * dwReserved [I] Reserved. Must be set to 0.
741 * if lpdwStatus is not null, return the status (off line,
742 * modem, lan...) in it.
743 * FALSE if not connected
746 * If the system has no available network connections, an empty string is
747 * stored in lpszConnectionName. If there is a LAN connection, a localized
748 * "LAN Connection" string is stored. Presumably, if only a dial-up
749 * connection is available then the name of the dial-up connection is
750 * returned. Why any application, other than the "Internet Settings" CPL,
751 * would want to use this function instead of the simpler InternetGetConnectedStateW
752 * function is beyond me.
754 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
755 DWORD dwNameLen, DWORD dwReserved)
757 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
764 FIXME("always returning LAN connection.\n");
765 *lpdwStatus = INTERNET_CONNECTION_LAN;
767 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
771 /***********************************************************************
772 * InternetGetConnectedStateExA (WININET.@)
774 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
775 DWORD dwNameLen, DWORD dwReserved)
777 LPWSTR lpwszConnectionName = NULL;
780 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
782 if (lpszConnectionName && dwNameLen > 0)
783 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
785 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
787 if (rc && lpwszConnectionName)
789 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
790 dwNameLen, NULL, NULL);
792 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
799 /***********************************************************************
800 * InternetConnectW (WININET.@)
802 * Open a ftp, gopher or http session
805 * HINTERNET a session handle on success
809 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
810 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
811 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
812 DWORD dwService, DWORD dwFlags, DWORD dwContext)
814 LPWININETAPPINFOW hIC;
815 HINTERNET rc = (HINTERNET) NULL;
817 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName),
818 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
819 dwService, dwFlags, dwContext);
821 /* Clear any error information */
822 INTERNET_SetLastError(0);
823 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
824 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
829 case INTERNET_SERVICE_FTP:
830 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
831 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
834 case INTERNET_SERVICE_HTTP:
835 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
836 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
839 case INTERNET_SERVICE_GOPHER:
845 WININET_Release( &hIC->hdr );
847 TRACE("returning %p\n", rc);
852 /***********************************************************************
853 * InternetConnectA (WININET.@)
855 * Open a ftp, gopher or http session
858 * HINTERNET a session handle on success
862 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
863 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
864 LPCSTR lpszUserName, LPCSTR lpszPassword,
865 DWORD dwService, DWORD dwFlags, DWORD dwContext)
867 HINTERNET rc = (HINTERNET)NULL;
869 LPWSTR szServerName = NULL;
870 LPWSTR szUserName = NULL;
871 LPWSTR szPassword = NULL;
875 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
876 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
877 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
881 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
882 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
883 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
887 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
888 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
889 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
893 rc = InternetConnectW(hInternet, szServerName, nServerPort,
894 szUserName, szPassword, dwService, dwFlags, dwContext);
896 HeapFree(GetProcessHeap(), 0, szServerName);
897 HeapFree(GetProcessHeap(), 0, szUserName);
898 HeapFree(GetProcessHeap(), 0, szPassword);
903 /***********************************************************************
904 * InternetFindNextFileA (WININET.@)
906 * Continues a file search from a previous call to FindFirstFile
913 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
918 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
920 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
924 /***********************************************************************
925 * InternetFindNextFileW (WININET.@)
927 * Continues a file search from a previous call to FindFirstFile
934 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
936 LPWININETAPPINFOW hIC = NULL;
937 LPWININETFINDNEXTW lpwh;
938 BOOL bSuccess = FALSE;
942 lpwh = (LPWININETFINDNEXTW) WININET_GetObject( hFind );
943 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
945 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
949 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
950 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
952 WORKREQUEST workRequest;
953 struct WORKREQ_INTERNETFINDNEXTW *req;
955 workRequest.asyncall = INTERNETFINDNEXTW;
956 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
957 req = &workRequest.u.InternetFindNextW;
958 req->lpFindFileData = lpvFindData;
960 bSuccess = INTERNET_AsyncCall(&workRequest);
964 bSuccess = INTERNET_FindNextFileW(lpwh, lpvFindData);
968 WININET_Release( &lpwh->hdr );
972 /***********************************************************************
973 * INTERNET_FindNextFileW (Internal)
975 * Continues a file search from a previous call to FindFirstFile
982 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData)
984 BOOL bSuccess = TRUE;
985 LPWIN32_FIND_DATAW lpFindFileData;
989 assert (lpwh->hdr.htype == WH_HFINDNEXT);
991 /* Clear any error information */
992 INTERNET_SetLastError(0);
994 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
996 FIXME("Only FTP find next supported\n");
997 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
1001 TRACE("index(%ld) size(%ld)\n", lpwh->index, lpwh->size);
1003 lpFindFileData = (LPWIN32_FIND_DATAW) lpvFindData;
1004 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
1006 if (lpwh->index >= lpwh->size)
1008 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
1013 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
1016 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData->cFileName), lpFindFileData->nFileSizeLow);
1020 if (lpwh->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1022 INTERNET_ASYNC_RESULT iar;
1024 iar.dwResult = (DWORD)bSuccess;
1025 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
1026 INTERNET_GetLastError();
1028 INTERNET_SendCallback(&lpwh->hdr, lpwh->hdr.dwContext,
1029 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1030 sizeof(INTERNET_ASYNC_RESULT));
1037 /***********************************************************************
1038 * INTERNET_CloseHandle (internal)
1040 * Close internet handle
1046 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
1048 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
1050 TRACE("%p\n",lpwai);
1052 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
1053 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
1054 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
1055 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
1056 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
1057 HeapFree(GetProcessHeap(), 0, lpwai);
1061 /***********************************************************************
1062 * InternetCloseHandle (WININET.@)
1064 * Generic close handle function
1071 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1073 LPWININETHANDLEHEADER lpwh;
1075 TRACE("%p\n",hInternet);
1077 lpwh = WININET_GetObject( hInternet );
1080 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1084 /* FIXME: native appears to send this from the equivalent of
1085 * WININET_Release */
1086 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1087 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
1090 if( lpwh->lpwhparent )
1091 WININET_Release( lpwh->lpwhparent );
1092 WININET_FreeHandle( hInternet );
1093 WININET_Release( lpwh );
1099 /***********************************************************************
1100 * ConvertUrlComponentValue (Internal)
1102 * Helper function for InternetCrackUrlW
1105 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1106 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1107 LPCSTR lpszStart, LPCWSTR lpwszStart)
1109 TRACE("%p %ld %p %ld %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1110 if (*dwComponentLen != 0)
1112 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1113 if (*lppszComponent == NULL)
1115 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1117 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1119 *lppszComponent = NULL;
1120 *dwComponentLen = nASCIILength;
1124 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1125 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1126 (*lppszComponent)[ncpylen]=0;
1127 *dwComponentLen = ncpylen;
1133 /***********************************************************************
1134 * InternetCrackUrlA (WININET.@)
1136 * See InternetCrackUrlW.
1138 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1139 LPURL_COMPONENTSA lpUrlComponents)
1142 URL_COMPONENTSW UCW;
1145 TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1148 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1150 /* if dwUrlLength=-1 then nLength includes null but length to
1151 InternetCrackUrlW should not include it */
1152 if (dwUrlLength == -1) nLength--;
1154 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1155 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1157 memset(&UCW,0,sizeof(UCW));
1158 if(lpUrlComponents->dwHostNameLength!=0)
1159 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1160 if(lpUrlComponents->dwUserNameLength!=0)
1161 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1162 if(lpUrlComponents->dwPasswordLength!=0)
1163 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1164 if(lpUrlComponents->dwUrlPathLength!=0)
1165 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1166 if(lpUrlComponents->dwSchemeLength!=0)
1167 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1168 if(lpUrlComponents->dwExtraInfoLength!=0)
1169 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1170 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1172 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1176 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1177 UCW.lpszHostName, UCW.dwHostNameLength,
1179 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1180 UCW.lpszUserName, UCW.dwUserNameLength,
1182 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1183 UCW.lpszPassword, UCW.dwPasswordLength,
1185 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1186 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1188 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1189 UCW.lpszScheme, UCW.dwSchemeLength,
1191 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1192 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1194 lpUrlComponents->nScheme=UCW.nScheme;
1195 lpUrlComponents->nPort=UCW.nPort;
1196 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1198 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1199 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1200 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1201 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1202 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1207 static const WCHAR url_schemes[][7] =
1210 {'g','o','p','h','e','r',0},
1211 {'h','t','t','p',0},
1212 {'h','t','t','p','s',0},
1213 {'f','i','l','e',0},
1214 {'n','e','w','s',0},
1215 {'m','a','i','l','t','o',0},
1219 /***********************************************************************
1220 * GetInternetSchemeW (internal)
1226 * INTERNET_SCHEME_UNKNOWN on failure
1229 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1233 TRACE("%s %ld\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1235 if(lpszScheme==NULL)
1236 return INTERNET_SCHEME_UNKNOWN;
1238 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1239 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1240 return INTERNET_SCHEME_FIRST + i;
1242 return INTERNET_SCHEME_UNKNOWN;
1245 /***********************************************************************
1246 * SetUrlComponentValueW (Internal)
1248 * Helper function for InternetCrackUrlW
1251 * lppszComponent [O] Holds the returned string
1252 * dwComponentLen [I] Holds the size of lppszComponent
1253 * [O] Holds the length of the string in lppszComponent without '\0'
1254 * lpszStart [I] Holds the string to copy from
1255 * len [I] Holds the length of lpszStart without '\0'
1262 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1264 TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
1266 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1269 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1271 if (*lppszComponent == NULL)
1273 *lppszComponent = (LPWSTR)lpszStart;
1274 *dwComponentLen = len;
1278 DWORD ncpylen = min((*dwComponentLen)-1, len);
1279 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1280 (*lppszComponent)[ncpylen] = '\0';
1281 *dwComponentLen = ncpylen;
1288 /***********************************************************************
1289 * InternetCrackUrlW (WININET.@)
1291 * Break up URL into its components
1297 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1298 LPURL_COMPONENTSW lpUC)
1302 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1305 LPCWSTR lpszParam = NULL;
1306 BOOL bIsAbsolute = FALSE;
1307 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1308 LPCWSTR lpszcp = NULL;
1309 LPWSTR lpszUrl_decode = NULL;
1310 DWORD dwUrlLength = dwUrlLength_orig;
1311 const WCHAR lpszSeparators[3]={';','?',0};
1312 const WCHAR lpszSlash[2]={'/',0};
1314 dwUrlLength=strlenW(lpszUrl);
1316 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1317 if (dwFlags & ICU_DECODE)
1319 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1320 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1322 lpszUrl = lpszUrl_decode;
1327 /* Determine if the URI is absolute. */
1328 while (*lpszap != '\0')
1330 if (isalnumW(*lpszap))
1335 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1342 lpszcp = lpszUrl; /* Relative url */
1348 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1349 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1351 /* Parse <params> */
1352 lpszParam = strpbrkW(lpszap, lpszSeparators);
1353 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1354 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1356 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1360 /* Get scheme first. */
1361 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1362 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1363 lpszUrl, lpszcp - lpszUrl);
1365 /* Eat ':' in protocol. */
1368 /* double slash indicates the net_loc portion is present */
1369 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1373 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1377 lpszNetLoc = min(lpszNetLoc, lpszParam);
1379 lpszNetLoc = lpszParam;
1381 else if (!lpszNetLoc)
1382 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1390 /* [<user>[<:password>]@]<host>[:<port>] */
1391 /* First find the user and password if they exist */
1393 lpszHost = strchrW(lpszcp, '@');
1394 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1396 /* username and password not specified. */
1397 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1398 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1400 else /* Parse out username and password */
1402 LPCWSTR lpszUser = lpszcp;
1403 LPCWSTR lpszPasswd = lpszHost;
1405 while (lpszcp < lpszHost)
1408 lpszPasswd = lpszcp;
1413 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1414 lpszUser, lpszPasswd - lpszUser);
1416 if (lpszPasswd != lpszHost)
1418 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1419 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1420 lpszHost - lpszPasswd);
1422 lpszcp++; /* Advance to beginning of host */
1425 /* Parse <host><:port> */
1428 lpszPort = lpszNetLoc;
1430 /* special case for res:// URLs: there is no port here, so the host is the
1431 entire string up to the first '/' */
1432 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1434 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1435 lpszHost, lpszPort - lpszHost);
1440 while (lpszcp < lpszNetLoc)
1448 /* If the scheme is "file" and the host is just one letter, it's not a host */
1449 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1452 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1457 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1458 lpszHost, lpszPort - lpszHost);
1459 if (lpszPort != lpszNetLoc)
1460 lpUC->nPort = atoiW(++lpszPort);
1461 else switch (lpUC->nScheme)
1463 case INTERNET_SCHEME_HTTP:
1464 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1466 case INTERNET_SCHEME_HTTPS:
1467 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1469 case INTERNET_SCHEME_FTP:
1470 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1472 case INTERNET_SCHEME_GOPHER:
1473 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1484 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1485 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1486 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1491 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1492 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1493 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1494 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1497 /* Here lpszcp points to:
1499 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1500 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1502 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1506 /* Only truncate the parameter list if it's already been saved
1507 * in lpUC->lpszExtraInfo.
1509 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1510 len = lpszParam - lpszcp;
1513 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1514 * newlines if necessary.
1516 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1517 if (lpsznewline != NULL)
1518 len = lpsznewline - lpszcp;
1520 len = dwUrlLength-(lpszcp-lpszUrl);
1522 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1527 lpUC->dwUrlPathLength = 0;
1530 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1531 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1532 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1533 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1534 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1537 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1541 /***********************************************************************
1542 * InternetAttemptConnect (WININET.@)
1544 * Attempt to make a connection to the internet
1547 * ERROR_SUCCESS on success
1548 * Error value on failure
1551 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1554 return ERROR_SUCCESS;
1558 /***********************************************************************
1559 * InternetCanonicalizeUrlA (WININET.@)
1561 * Escape unsafe characters and spaces
1568 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1569 LPDWORD lpdwBufferLength, DWORD dwFlags)
1572 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1573 if(dwFlags & ICU_DECODE)
1575 dwURLFlags |= URL_UNESCAPE;
1576 dwFlags &= ~ICU_DECODE;
1579 if(dwFlags & ICU_ESCAPE)
1581 dwURLFlags |= URL_UNESCAPE;
1582 dwFlags &= ~ICU_ESCAPE;
1584 if(dwFlags & ICU_BROWSER_MODE)
1586 dwURLFlags |= URL_BROWSER_MODE;
1587 dwFlags &= ~ICU_BROWSER_MODE;
1590 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1591 TRACE("%s %p %p %08lx\n", debugstr_a(lpszUrl), lpszBuffer,
1592 lpdwBufferLength, dwURLFlags);
1594 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1595 dwFlags ^= ICU_NO_ENCODE;
1597 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1599 return (hr == S_OK) ? TRUE : FALSE;
1602 /***********************************************************************
1603 * InternetCanonicalizeUrlW (WININET.@)
1605 * Escape unsafe characters and spaces
1612 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1613 LPDWORD lpdwBufferLength, DWORD dwFlags)
1616 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1617 if(dwFlags & ICU_DECODE)
1619 dwURLFlags |= URL_UNESCAPE;
1620 dwFlags &= ~ICU_DECODE;
1623 if(dwFlags & ICU_ESCAPE)
1625 dwURLFlags |= URL_UNESCAPE;
1626 dwFlags &= ~ICU_ESCAPE;
1628 if(dwFlags & ICU_BROWSER_MODE)
1630 dwURLFlags |= URL_BROWSER_MODE;
1631 dwFlags &= ~ICU_BROWSER_MODE;
1634 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1635 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
1636 lpdwBufferLength, dwURLFlags);
1638 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1639 dwFlags ^= ICU_NO_ENCODE;
1641 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1643 return (hr == S_OK) ? TRUE : FALSE;
1647 /***********************************************************************
1648 * InternetSetStatusCallbackA (WININET.@)
1650 * Sets up a callback function which is called as progress is made
1651 * during an operation.
1654 * Previous callback or NULL on success
1655 * INTERNET_INVALID_STATUS_CALLBACK on failure
1658 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1659 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1661 INTERNET_STATUS_CALLBACK retVal;
1662 LPWININETHANDLEHEADER lpwh;
1664 TRACE("0x%08lx\n", (ULONG)hInternet);
1666 lpwh = WININET_GetObject(hInternet);
1668 return INTERNET_INVALID_STATUS_CALLBACK;
1670 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1671 retVal = lpwh->lpfnStatusCB;
1672 lpwh->lpfnStatusCB = lpfnIntCB;
1674 WININET_Release( lpwh );
1679 /***********************************************************************
1680 * InternetSetStatusCallbackW (WININET.@)
1682 * Sets up a callback function which is called as progress is made
1683 * during an operation.
1686 * Previous callback or NULL on success
1687 * INTERNET_INVALID_STATUS_CALLBACK on failure
1690 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1691 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1693 INTERNET_STATUS_CALLBACK retVal;
1694 LPWININETHANDLEHEADER lpwh;
1696 TRACE("0x%08lx\n", (ULONG)hInternet);
1698 lpwh = WININET_GetObject(hInternet);
1700 return INTERNET_INVALID_STATUS_CALLBACK;
1702 lpwh->dwInternalFlags |= INET_CALLBACKW;
1703 retVal = lpwh->lpfnStatusCB;
1704 lpwh->lpfnStatusCB = lpfnIntCB;
1706 WININET_Release( lpwh );
1711 /***********************************************************************
1712 * InternetSetFilePointer (WININET.@)
1714 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1715 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1721 /***********************************************************************
1722 * InternetWriteFile (WININET.@)
1724 * Write data to an open internet file
1731 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1732 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1734 BOOL retval = FALSE;
1736 LPWININETHANDLEHEADER lpwh;
1739 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1743 switch (lpwh->htype)
1747 LPWININETHTTPREQW lpwhr;
1748 lpwhr = (LPWININETHTTPREQW)lpwh;
1750 TRACE("HTTPREQ %li\n",dwNumOfBytesToWrite);
1751 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1752 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1754 WININET_Release( lpwh );
1760 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1769 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1770 retval = (res >= 0);
1771 *lpdwNumOfBytesWritten = retval ? res : 0;
1773 WININET_Release( lpwh );
1779 static BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1780 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1781 BOOL bWait, BOOL bSendCompletionStatus)
1783 BOOL retval = FALSE;
1786 /* FIXME: this should use NETCON functions! */
1787 switch (lpwh->htype)
1790 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1791 dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0, (int *)pdwNumOfBytesRead))
1793 *pdwNumOfBytesRead = 0;
1794 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1801 /* FIXME: FTP should use NETCON_ stuff */
1802 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1805 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1806 retval = (res >= 0);
1807 *pdwNumOfBytesRead = retval ? res : 0;
1815 if (bSendCompletionStatus)
1817 INTERNET_ASYNC_RESULT iar;
1819 iar.dwResult = retval;
1820 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1821 INTERNET_GetLastError();
1823 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1824 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1825 sizeof(INTERNET_ASYNC_RESULT));
1830 /***********************************************************************
1831 * InternetReadFile (WININET.@)
1833 * Read data from an open internet file
1840 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1841 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1843 LPWININETHANDLEHEADER lpwh;
1846 TRACE("%p %p %ld %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1848 lpwh = WININET_GetObject( hFile );
1851 SetLastError(ERROR_INVALID_HANDLE);
1855 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1856 WININET_Release( lpwh );
1858 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1862 /***********************************************************************
1863 * InternetReadFileExA (WININET.@)
1865 * Read data from an open internet file
1868 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1869 * lpBuffersOut [I/O] Buffer.
1870 * dwFlags [I] Flags. See notes.
1871 * dwContext [I] Context for callbacks.
1878 * The parameter dwFlags include zero or more of the following flags:
1879 *|IRF_ASYNC - Makes the call asynchronous.
1880 *|IRF_SYNC - Makes the call synchronous.
1881 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1882 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1884 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1887 * InternetOpenUrlA(), HttpOpenRequestA()
1889 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1890 DWORD dwFlags, DWORD dwContext)
1892 BOOL retval = FALSE;
1893 LPWININETHANDLEHEADER lpwh;
1895 TRACE("(%p %p 0x%lx 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1897 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1898 FIXME("these dwFlags aren't implemented: 0x%lx\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1900 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1902 SetLastError(ERROR_INVALID_PARAMETER);
1906 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1909 SetLastError(ERROR_INVALID_HANDLE);
1913 /* FIXME: native only does it asynchronously if the amount of data
1914 * requested isn't available. See NtReadFile. */
1915 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1916 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1917 * we should implement the above first */
1918 if (dwFlags & IRF_ASYNC)
1920 WORKREQUEST workRequest;
1921 struct WORKREQ_INTERNETREADFILEEXA *req;
1923 workRequest.asyncall = INTERNETREADFILEEXA;
1924 workRequest.hdr = WININET_AddRef( lpwh );
1925 req = &workRequest.u.InternetReadFileExA;
1926 req->lpBuffersOut = lpBuffersOut;
1928 retval = INTERNET_AsyncCall(&workRequest);
1929 if (!retval) return FALSE;
1931 SetLastError(ERROR_IO_PENDING);
1935 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1936 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1937 !(dwFlags & IRF_NO_WAIT), FALSE);
1939 WININET_Release( lpwh );
1941 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1945 /***********************************************************************
1946 * InternetReadFileExW (WININET.@)
1948 * Read data from an open internet file.
1951 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1952 * lpBuffersOut [I/O] Buffer.
1953 * dwFlags [I] Flags.
1954 * dwContext [I] Context for callbacks.
1957 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1960 * Not implemented in Wine or native either (as of IE6 SP2).
1963 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1964 DWORD dwFlags, DWORD dwContext)
1966 ERR("(%p, %p, 0x%lx, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1968 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1972 /***********************************************************************
1973 * INET_QueryOptionHelper (internal)
1975 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1976 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1978 LPWININETHANDLEHEADER lpwhh;
1979 BOOL bSuccess = FALSE;
1981 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1983 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1987 case INTERNET_OPTION_HANDLE_TYPE:
1993 WARN("Invalid hInternet handle\n");
1994 SetLastError(ERROR_INVALID_HANDLE);
1998 type = lpwhh->htype;
2000 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
2002 if (*lpdwBufferLength < sizeof(ULONG))
2003 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2006 memcpy(lpBuffer, &type, sizeof(ULONG));
2009 *lpdwBufferLength = sizeof(ULONG);
2013 case INTERNET_OPTION_REQUEST_FLAGS:
2016 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
2017 if (*lpdwBufferLength < sizeof(ULONG))
2018 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2021 memcpy(lpBuffer, &flags, sizeof(ULONG));
2024 *lpdwBufferLength = sizeof(ULONG);
2028 case INTERNET_OPTION_URL:
2029 case INTERNET_OPTION_DATAFILE_NAME:
2033 WARN("Invalid hInternet handle\n");
2034 SetLastError(ERROR_INVALID_HANDLE);
2037 if (lpwhh->htype == WH_HHTTPREQ)
2039 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2041 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2042 static const WCHAR szHost[] = {'H','o','s','t',0};
2046 Host = HTTP_GetHeader(lpreq,szHost);
2047 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2048 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2051 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2052 lpBuffer,*lpdwBufferLength,NULL,NULL);
2053 if (sizeRequired > *lpdwBufferLength)
2054 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2057 *lpdwBufferLength = sizeRequired;
2061 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2062 if (*lpdwBufferLength < sizeRequired)
2063 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2066 strcpyW(lpBuffer, url);
2069 *lpdwBufferLength = sizeRequired;
2074 case INTERNET_OPTION_HTTP_VERSION:
2076 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2077 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2081 * Presently hardcoded to 1.1
2083 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2084 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2087 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2090 case INTERNET_OPTION_CONNECTED_STATE:
2092 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2093 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2095 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2096 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2099 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2102 *lpdwBufferLength = sizeof(*pdwConnectedState);
2105 case INTERNET_OPTION_PROXY:
2107 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2108 WININETAPPINFOW wai;
2112 TRACE("Getting global proxy info\n");
2113 memset(&wai, 0, sizeof(WININETAPPINFOW));
2114 INTERNET_ConfigureProxyFromReg( &wai );
2120 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2121 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2123 if (lpwai->lpszProxy)
2124 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2126 if (lpwai->lpszProxyBypass)
2127 proxyBypassBytesRequired =
2128 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2129 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2130 proxyBytesRequired + proxyBypassBytesRequired)
2131 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2134 pPI->dwAccessType = lpwai->dwAccessType;
2135 if (lpwai->lpszProxy)
2137 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2138 sizeof(INTERNET_PROXY_INFOW));
2139 lstrcpyW((LPWSTR)pPI->lpszProxy, lpwai->lpszProxy);
2143 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2144 sizeof(INTERNET_PROXY_INFOW));
2145 *((LPWSTR)(pPI->lpszProxy)) = 0;
2148 if (lpwai->lpszProxyBypass)
2150 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2151 sizeof(INTERNET_PROXY_INFOW) +
2152 proxyBytesRequired);
2153 lstrcpyW((LPWSTR)pPI->lpszProxyBypass,
2154 lpwai->lpszProxyBypass);
2158 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2159 sizeof(INTERNET_PROXY_INFOW) +
2160 proxyBytesRequired);
2161 *((LPWSTR)(pPI->lpszProxyBypass)) = 0;
2165 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2166 proxyBytesRequired + proxyBypassBytesRequired;
2170 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2171 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2173 if (lpwai->lpszProxy)
2174 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2175 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2176 if (lpwai->lpszProxyBypass)
2177 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2178 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2179 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2180 proxyBytesRequired + proxyBypassBytesRequired)
2181 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2184 pPI->dwAccessType = lpwai->dwAccessType;
2185 if (lpwai->lpszProxy)
2187 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2188 sizeof(INTERNET_PROXY_INFOA));
2189 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2190 (LPSTR)pPI->lpszProxy, proxyBytesRequired, NULL, NULL);
2194 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2195 sizeof(INTERNET_PROXY_INFOA));
2196 *((LPSTR)(pPI->lpszProxy)) = '\0';
2199 if (lpwai->lpszProxyBypass)
2201 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2202 sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
2203 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2204 -1, (LPSTR)pPI->lpszProxyBypass,
2205 proxyBypassBytesRequired,
2210 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2211 sizeof(INTERNET_PROXY_INFOA) +
2212 proxyBytesRequired);
2213 *((LPSTR)(pPI->lpszProxyBypass)) = '\0';
2217 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2218 proxyBytesRequired + proxyBypassBytesRequired;
2222 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2225 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %ld\n", conn);
2226 if (*lpdwBufferLength < sizeof(ULONG))
2227 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2230 memcpy(lpBuffer, &conn, sizeof(ULONG));
2233 *lpdwBufferLength = sizeof(ULONG);
2236 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2239 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %ld\n", conn);
2240 if (*lpdwBufferLength < sizeof(ULONG))
2241 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2244 memcpy(lpBuffer, &conn, sizeof(ULONG));
2247 *lpdwBufferLength = sizeof(ULONG);
2250 case INTERNET_OPTION_SECURITY_FLAGS:
2251 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2254 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
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! %ld\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%08lx\n", dwOption);
2391 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2397 case INTERNET_OPTION_HTTP_VERSION:
2399 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2400 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2403 case INTERNET_OPTION_ERROR_MASK:
2405 unsigned long flags=*(unsigned long*)lpBuffer;
2406 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2409 case INTERNET_OPTION_CODEPAGE:
2411 unsigned long codepage=*(unsigned long*)lpBuffer;
2412 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2415 case INTERNET_OPTION_REQUEST_PRIORITY:
2417 unsigned long priority=*(unsigned long*)lpBuffer;
2418 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2421 case INTERNET_OPTION_CONNECT_TIMEOUT:
2423 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2424 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2427 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2429 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2430 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2433 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2435 unsigned long conns=*(unsigned long*)lpBuffer;
2436 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2439 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2441 unsigned long conns=*(unsigned long*)lpBuffer;
2442 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2445 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2446 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2448 case INTERNET_OPTION_END_BROWSER_SESSION:
2449 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2451 case INTERNET_OPTION_CONNECTED_STATE:
2452 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2454 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2455 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2457 case INTERNET_OPTION_SEND_TIMEOUT:
2458 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2459 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2460 if (dwBufferLength == sizeof(DWORD))
2462 if (lpwhh->htype == WH_HHTTPREQ)
2463 ret = NETCON_set_timeout(
2464 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2465 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2466 *(DWORD *)lpBuffer);
2469 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2471 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2477 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2481 case INTERNET_OPTION_CONNECT_RETRIES:
2482 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2484 case INTERNET_OPTION_CONTEXT_VALUE:
2485 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2488 FIXME("Option %ld STUB\n",dwOption);
2489 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2493 WININET_Release( lpwhh );
2499 /***********************************************************************
2500 * InternetSetOptionA (WININET.@)
2502 * Sets an options on the specified handle.
2509 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2510 LPVOID lpBuffer, DWORD dwBufferLength)
2518 case INTERNET_OPTION_PROXY:
2520 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2521 LPINTERNET_PROXY_INFOW piw;
2522 DWORD proxlen, prbylen;
2525 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2526 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2527 wlen = sizeof(*piw) + proxlen + prbylen;
2528 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2529 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2530 piw->dwAccessType = pi->dwAccessType;
2531 prox = (LPWSTR) &piw[1];
2532 prby = &prox[proxlen+1];
2533 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2534 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2535 piw->lpszProxy = prox;
2536 piw->lpszProxyBypass = prby;
2539 case INTERNET_OPTION_USER_AGENT:
2540 case INTERNET_OPTION_USERNAME:
2541 case INTERNET_OPTION_PASSWORD:
2542 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2544 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2545 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2550 wlen = dwBufferLength;
2553 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2555 if( lpBuffer != wbuffer )
2556 HeapFree( GetProcessHeap(), 0, wbuffer );
2562 /***********************************************************************
2563 * InternetSetOptionExA (WININET.@)
2565 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2566 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2568 FIXME("Flags %08lx ignored\n", dwFlags);
2569 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2572 /***********************************************************************
2573 * InternetSetOptionExW (WININET.@)
2575 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2576 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2578 FIXME("Flags %08lx ignored\n", dwFlags);
2579 if( dwFlags & ~ISO_VALID_FLAGS )
2581 SetLastError( ERROR_INVALID_PARAMETER );
2584 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2587 static const WCHAR WININET_wkday[7][4] =
2588 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2589 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2590 static const WCHAR WININET_month[12][4] =
2591 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2592 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2593 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2595 /***********************************************************************
2596 * InternetTimeFromSystemTimeA (WININET.@)
2598 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2601 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2603 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2605 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2606 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2611 /***********************************************************************
2612 * InternetTimeFromSystemTimeW (WININET.@)
2614 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2616 static const WCHAR date[] =
2617 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2618 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2620 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2622 if (!time || !string) return FALSE;
2624 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2627 sprintfW( string, date,
2628 WININET_wkday[time->wDayOfWeek],
2630 WININET_month[time->wMonth - 1],
2639 /***********************************************************************
2640 * InternetTimeToSystemTimeA (WININET.@)
2642 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2648 TRACE( "%s %p 0x%08lx\n", debugstr_a(string), time, reserved );
2650 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2651 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2655 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2656 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2657 HeapFree( GetProcessHeap(), 0, stringW );
2662 /***********************************************************************
2663 * InternetTimeToSystemTimeW (WININET.@)
2665 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2668 WCHAR *s = (LPWSTR)string;
2670 TRACE( "%s %p 0x%08lx\n", debugstr_w(string), time, reserved );
2672 if (!string || !time) return FALSE;
2674 /* Windows does this too */
2675 GetSystemTime( time );
2677 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2678 * a SYSTEMTIME structure.
2681 while (*s && !isalphaW( *s )) s++;
2682 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2683 time->wDayOfWeek = 7;
2685 for (i = 0; i < 7; i++)
2687 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2688 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2689 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2691 time->wDayOfWeek = i;
2696 if (time->wDayOfWeek > 6) return TRUE;
2697 while (*s && !isdigitW( *s )) s++;
2698 time->wDay = strtolW( s, &s, 10 );
2700 while (*s && !isalphaW( *s )) s++;
2701 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2704 for (i = 0; i < 12; i++)
2706 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2707 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2708 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2710 time->wMonth = i + 1;
2714 if (time->wMonth == 0) return TRUE;
2716 while (*s && !isdigitW( *s )) s++;
2717 if (*s == '\0') return TRUE;
2718 time->wYear = strtolW( s, &s, 10 );
2720 while (*s && !isdigitW( *s )) s++;
2721 if (*s == '\0') return TRUE;
2722 time->wHour = strtolW( s, &s, 10 );
2724 while (*s && !isdigitW( *s )) s++;
2725 if (*s == '\0') return TRUE;
2726 time->wMinute = strtolW( s, &s, 10 );
2728 while (*s && !isdigitW( *s )) s++;
2729 if (*s == '\0') return TRUE;
2730 time->wSecond = strtolW( s, &s, 10 );
2732 time->wMilliseconds = 0;
2736 /***********************************************************************
2737 * InternetCheckConnectionW (WININET.@)
2739 * Pings a requested host to check internet connection
2742 * TRUE on success and FALSE on failure. If a failure then
2743 * ERROR_NOT_CONNECTED is placed into GetLastError
2746 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2749 * this is a kludge which runs the resident ping program and reads the output.
2751 * Anyone have a better idea?
2755 static const CHAR ping[] = "ping -w 1 ";
2756 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2757 CHAR *command = NULL;
2765 * Crack or set the Address
2767 if (lpszUrl == NULL)
2770 * According to the doc we are supost to use the ip for the next
2771 * server in the WnInet internal server database. I have
2772 * no idea what that is or how to get it.
2774 * So someone needs to implement this.
2776 FIXME("Unimplemented with URL of NULL\n");
2781 URL_COMPONENTSW components;
2783 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2784 components.lpszHostName = (LPWSTR)&hostW;
2785 components.dwHostNameLength = 1024;
2787 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2790 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2794 * Build our ping command
2796 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2797 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2798 strcpy(command,ping);
2799 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2800 strcat(command,redirect);
2802 TRACE("Ping command is : %s\n",command);
2804 status = system(command);
2806 TRACE("Ping returned a code of %i\n",status);
2808 /* Ping return code of 0 indicates success */
2814 HeapFree( GetProcessHeap(), 0, command );
2816 SetLastError(ERROR_NOT_CONNECTED);
2822 /***********************************************************************
2823 * InternetCheckConnectionA (WININET.@)
2825 * Pings a requested host to check internet connection
2828 * TRUE on success and FALSE on failure. If a failure then
2829 * ERROR_NOT_CONNECTED is placed into GetLastError
2832 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2838 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2839 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2841 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2842 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2843 HeapFree(GetProcessHeap(), 0, szUrl);
2849 /**********************************************************
2850 * INTERNET_InternetOpenUrlW (internal)
2855 * handle of connection or NULL on failure
2857 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2858 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2860 URL_COMPONENTSW urlComponents;
2861 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2862 WCHAR password[1024], path[2048], extra[1024];
2863 HINTERNET client = NULL, client1 = NULL;
2865 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2866 dwHeadersLength, dwFlags, dwContext);
2868 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2869 urlComponents.lpszScheme = protocol;
2870 urlComponents.dwSchemeLength = 32;
2871 urlComponents.lpszHostName = hostName;
2872 urlComponents.dwHostNameLength = MAXHOSTNAME;
2873 urlComponents.lpszUserName = userName;
2874 urlComponents.dwUserNameLength = 1024;
2875 urlComponents.lpszPassword = password;
2876 urlComponents.dwPasswordLength = 1024;
2877 urlComponents.lpszUrlPath = path;
2878 urlComponents.dwUrlPathLength = 2048;
2879 urlComponents.lpszExtraInfo = extra;
2880 urlComponents.dwExtraInfoLength = 1024;
2881 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2883 switch(urlComponents.nScheme) {
2884 case INTERNET_SCHEME_FTP:
2885 if(urlComponents.nPort == 0)
2886 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2887 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2888 userName, password, dwFlags, dwContext, INET_OPENURL);
2891 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2892 if(client1 == NULL) {
2893 InternetCloseHandle(client);
2898 case INTERNET_SCHEME_HTTP:
2899 case INTERNET_SCHEME_HTTPS: {
2900 static const WCHAR szStars[] = { '*','/','*', 0 };
2901 LPCWSTR accept[2] = { szStars, NULL };
2902 if(urlComponents.nPort == 0) {
2903 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2904 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2906 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2908 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2909 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2910 userName, password, dwFlags, dwContext, INET_OPENURL);
2913 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2914 if(client1 == NULL) {
2915 InternetCloseHandle(client);
2918 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2919 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2920 InternetCloseHandle(client1);
2925 case INTERNET_SCHEME_GOPHER:
2926 /* gopher doesn't seem to be implemented in wine, but it's supposed
2927 * to be supported by InternetOpenUrlA. */
2932 TRACE(" %p <--\n", client1);
2937 /**********************************************************
2938 * InternetOpenUrlW (WININET.@)
2943 * handle of connection or NULL on failure
2945 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2946 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2948 HINTERNET ret = NULL;
2949 LPWININETAPPINFOW hIC = NULL;
2951 if (TRACE_ON(wininet)) {
2952 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2953 dwHeadersLength, dwFlags, dwContext);
2955 dump_INTERNET_FLAGS(dwFlags);
2958 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2959 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2960 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2964 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2965 WORKREQUEST workRequest;
2966 struct WORKREQ_INTERNETOPENURLW *req;
2968 workRequest.asyncall = INTERNETOPENURLW;
2969 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2970 req = &workRequest.u.InternetOpenUrlW;
2972 req->lpszUrl = WININET_strdupW(lpszUrl);
2976 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2978 req->lpszHeaders = 0;
2979 req->dwHeadersLength = dwHeadersLength;
2980 req->dwFlags = dwFlags;
2981 req->dwContext = dwContext;
2983 INTERNET_AsyncCall(&workRequest);
2985 * This is from windows.
2987 SetLastError(ERROR_IO_PENDING);
2989 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2994 WININET_Release( &hIC->hdr );
2995 TRACE(" %p <--\n", ret);
3000 /**********************************************************
3001 * InternetOpenUrlA (WININET.@)
3006 * handle of connection or NULL on failure
3008 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3009 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
3011 HINTERNET rc = (HINTERNET)NULL;
3015 LPWSTR szUrl = NULL;
3016 LPWSTR szHeaders = NULL;
3021 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3022 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3024 return (HINTERNET)NULL;
3025 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3029 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3030 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3032 HeapFree(GetProcessHeap(), 0, szUrl);
3033 return (HINTERNET)NULL;
3035 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3038 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3039 lenHeaders, dwFlags, dwContext);
3041 HeapFree(GetProcessHeap(), 0, szUrl);
3042 HeapFree(GetProcessHeap(), 0, szHeaders);
3048 /***********************************************************************
3049 * INTERNET_SetLastError (internal)
3051 * Set last thread specific error
3056 void INTERNET_SetLastError(DWORD dwError)
3058 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3062 lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3063 TlsSetValue(g_dwTlsErrIndex, lpwite);
3066 SetLastError(dwError);
3068 lpwite->dwError = dwError;
3072 /***********************************************************************
3073 * INTERNET_GetLastError (internal)
3075 * Get last thread specific error
3080 DWORD INTERNET_GetLastError(void)
3082 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3083 if (!lpwite) return 0;
3084 /* TlsGetValue clears last error, so set it again here */
3085 SetLastError(lpwite->dwError);
3086 return lpwite->dwError;
3090 /***********************************************************************
3091 * INTERNET_WorkerThreadFunc (internal)
3093 * Worker thread execution function
3098 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3105 INTERNET_ExecuteWork();
3108 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
3110 if (dwWaitRes == WAIT_OBJECT_0 + 1)
3111 INTERNET_ExecuteWork();
3115 InterlockedIncrement(&dwNumIdleThreads);
3118 InterlockedDecrement(&dwNumIdleThreads);
3119 InterlockedDecrement(&dwNumThreads);
3120 TRACE("Worker thread exiting\n");
3125 /***********************************************************************
3126 * INTERNET_InsertWorkRequest (internal)
3128 * Insert work request into queue
3133 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
3135 BOOL bSuccess = FALSE;
3136 LPWORKREQUEST lpNewRequest;
3140 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3143 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3144 lpNewRequest->prev = NULL;
3146 EnterCriticalSection(&csQueue);
3148 lpNewRequest->next = lpWorkQueueTail;
3149 if (lpWorkQueueTail)
3150 lpWorkQueueTail->prev = lpNewRequest;
3151 lpWorkQueueTail = lpNewRequest;
3152 if (!lpHeadWorkQueue)
3153 lpHeadWorkQueue = lpWorkQueueTail;
3155 LeaveCriticalSection(&csQueue);
3158 InterlockedIncrement(&dwNumJobs);
3165 /***********************************************************************
3166 * INTERNET_GetWorkRequest (internal)
3168 * Retrieves work request from queue
3173 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
3175 BOOL bSuccess = FALSE;
3176 LPWORKREQUEST lpRequest = NULL;
3180 EnterCriticalSection(&csQueue);
3182 if (lpHeadWorkQueue)
3184 lpRequest = lpHeadWorkQueue;
3185 lpHeadWorkQueue = lpHeadWorkQueue->prev;
3186 if (lpRequest == lpWorkQueueTail)
3187 lpWorkQueueTail = lpHeadWorkQueue;
3190 LeaveCriticalSection(&csQueue);
3194 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
3195 HeapFree(GetProcessHeap(), 0, lpRequest);
3197 InterlockedDecrement(&dwNumJobs);
3204 /***********************************************************************
3205 * INTERNET_AsyncCall (internal)
3207 * Retrieves work request from queue
3212 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3216 BOOL bSuccess = FALSE;
3220 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
3222 InterlockedIncrement(&dwNumIdleThreads);
3224 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
3225 !(hThread = CreateThread(NULL, 0,
3226 INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
3228 InterlockedDecrement(&dwNumThreads);
3229 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3233 TRACE("Created new thread\n");
3237 INTERNET_InsertWorkRequest(lpWorkRequest);
3238 SetEvent(hWorkEvent);
3246 /***********************************************************************
3247 * INTERNET_ExecuteWork (internal)
3252 static VOID INTERNET_ExecuteWork(void)
3254 WORKREQUEST workRequest;
3258 if (!INTERNET_GetWorkRequest(&workRequest))
3261 switch (workRequest.asyncall)
3265 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
3266 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3268 TRACE("FTPPUTFILEW %p\n", lpwfs);
3270 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
3271 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
3273 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
3274 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
3278 case FTPSETCURRENTDIRECTORYW:
3280 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
3281 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3283 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
3285 req = &workRequest.u.FtpSetCurrentDirectoryW;
3286 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
3287 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3291 case FTPCREATEDIRECTORYW:
3293 struct WORKREQ_FTPCREATEDIRECTORYW *req;
3294 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3296 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
3298 req = &workRequest.u.FtpCreateDirectoryW;
3299 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
3300 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3304 case FTPFINDFIRSTFILEW:
3306 struct WORKREQ_FTPFINDFIRSTFILEW *req;
3307 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3309 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
3311 req = &workRequest.u.FtpFindFirstFileW;
3312 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
3313 req->lpFindFileData, req->dwFlags, req->dwContext);
3314 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
3318 case FTPGETCURRENTDIRECTORYW:
3320 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
3321 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3323 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
3325 req = &workRequest.u.FtpGetCurrentDirectoryW;
3326 FTP_FtpGetCurrentDirectoryW(lpwfs,
3327 req->lpszDirectory, req->lpdwDirectory);
3333 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
3334 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3336 TRACE("FTPOPENFILEW %p\n", lpwfs);
3338 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
3339 req->dwAccess, req->dwFlags, req->dwContext);
3340 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3346 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
3347 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3349 TRACE("FTPGETFILEW %p\n", lpwfs);
3351 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
3352 req->lpszNewFile, req->fFailIfExists,
3353 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
3354 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
3355 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
3359 case FTPDELETEFILEW:
3361 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
3362 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3364 TRACE("FTPDELETEFILEW %p\n", lpwfs);
3366 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
3367 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3371 case FTPREMOVEDIRECTORYW:
3373 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
3374 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3376 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
3378 req = &workRequest.u.FtpRemoveDirectoryW;
3379 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
3380 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3384 case FTPRENAMEFILEW:
3386 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
3387 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3389 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
3391 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
3392 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
3393 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
3397 case INTERNETFINDNEXTW:
3399 struct WORKREQ_INTERNETFINDNEXTW *req;
3400 LPWININETFINDNEXTW lpwh = (LPWININETFINDNEXTW) workRequest.hdr;
3402 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
3404 req = &workRequest.u.InternetFindNextW;
3405 INTERNET_FindNextFileW(lpwh, req->lpFindFileData);
3409 case HTTPSENDREQUESTW:
3411 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
3412 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
3414 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
3416 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
3417 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength,
3418 req->dwContentLength, req->bEndRequest);
3420 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
3424 case HTTPOPENREQUESTW:
3426 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
3427 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
3429 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
3431 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
3432 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
3433 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
3435 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
3436 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
3437 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
3438 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
3444 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
3446 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
3448 INTERNET_SendCallback(workRequest.hdr,
3449 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
3450 req->dwStatusInfoLength);
3452 /* And frees the copy of the status info */
3453 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
3457 case INTERNETOPENURLW:
3459 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
3460 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
3462 TRACE("INTERNETOPENURLW %p\n", hIC);
3464 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3465 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3466 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3467 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3470 case INTERNETREADFILEEXA:
3472 struct WORKREQ_INTERNETREADFILEEXA *req = &workRequest.u.InternetReadFileExA;
3474 TRACE("INTERNETREADFILEEXA %p\n", workRequest.hdr);
3476 INTERNET_ReadFile(workRequest.hdr, req->lpBuffersOut->lpvBuffer,
3477 req->lpBuffersOut->dwBufferLength,
3478 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
3482 WININET_Release( workRequest.hdr );
3486 /***********************************************************************
3487 * INTERNET_GetResponseBuffer (internal)
3492 LPSTR INTERNET_GetResponseBuffer(void)
3494 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3497 lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
3498 TlsSetValue(g_dwTlsErrIndex, lpwite);
3501 return lpwite->response;
3504 /***********************************************************************
3505 * INTERNET_GetNextLine (internal)
3507 * Parse next line in directory string listing
3510 * Pointer to beginning of next line
3515 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3519 BOOL bSuccess = FALSE;
3521 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3526 FD_SET(nSocket, &infd);
3527 tv.tv_sec=RESPONSE_TIMEOUT;
3530 while (nRecv < MAX_REPLY_LEN)
3532 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3534 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3536 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3540 if (lpszBuffer[nRecv] == '\n')
3545 if (lpszBuffer[nRecv] != '\r')
3550 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3558 lpszBuffer[nRecv] = '\0';
3560 TRACE(":%d %s\n", nRecv, lpszBuffer);
3569 /**********************************************************
3570 * InternetQueryDataAvailable (WININET.@)
3572 * Determines how much data is available to be read.
3575 * If there is data available then TRUE, otherwise if there
3576 * is not or an error occurred then FALSE. Use GetLastError() to
3577 * check for ERROR_NO_MORE_FILES to see if it was the former.
3579 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3580 LPDWORD lpdwNumberOfBytesAvailble,
3581 DWORD dwFlags, DWORD dwConext)
3583 LPWININETHTTPREQW lpwhr;
3584 BOOL retval = FALSE;
3587 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3590 SetLastError(ERROR_NO_MORE_FILES);
3594 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3596 switch (lpwhr->hdr.htype)
3599 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3600 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3602 SetLastError(ERROR_NO_MORE_FILES);
3610 FIXME("unsupported file type\n");
3613 WININET_Release( &lpwhr->hdr );
3615 TRACE("<-- %i\n",retval);
3620 /***********************************************************************
3621 * InternetLockRequestFile (WININET.@)
3623 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3630 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3637 /***********************************************************************
3638 * InternetAutodial (WININET.@)
3640 * On windows this function is supposed to dial the default internet
3641 * connection. We don't want to have Wine dial out to the internet so
3642 * we return TRUE by default. It might be nice to check if we are connected.
3649 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3653 /* Tell that we are connected to the internet. */
3657 /***********************************************************************
3658 * InternetAutodialHangup (WININET.@)
3660 * Hangs up a connection made with InternetAutodial
3669 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3673 /* we didn't dial, we don't disconnect */
3677 /***********************************************************************
3678 * InternetCombineUrlA (WININET.@)
3680 * Combine a base URL with a relative URL
3688 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3689 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3694 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3696 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3697 dwFlags ^= ICU_NO_ENCODE;
3698 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3703 /***********************************************************************
3704 * InternetCombineUrlW (WININET.@)
3706 * Combine a base URL with a relative URL
3714 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3715 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3720 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3722 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3723 dwFlags ^= ICU_NO_ENCODE;
3724 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3729 /* max port num is 65535 => 5 digits */
3730 #define MAX_WORD_DIGITS 5
3732 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3733 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3734 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3735 (url)->dw##component##Length : strlen((url)->lpsz##component))
3737 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3739 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3740 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3742 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3743 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3745 if ((nScheme == INTERNET_SCHEME_FTP) &&
3746 (nPort == INTERNET_DEFAULT_FTP_PORT))
3748 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3749 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3752 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3758 /* opaque urls do not fit into the standard url hierarchy and don't have
3759 * two following slashes */
3760 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3762 return (nScheme != INTERNET_SCHEME_FTP) &&
3763 (nScheme != INTERNET_SCHEME_GOPHER) &&
3764 (nScheme != INTERNET_SCHEME_HTTP) &&
3765 (nScheme != INTERNET_SCHEME_HTTPS) &&
3766 (nScheme != INTERNET_SCHEME_FILE);
3769 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3772 if (scheme < INTERNET_SCHEME_FIRST)
3774 index = scheme - INTERNET_SCHEME_FIRST;
3775 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3777 return (LPCWSTR)&url_schemes[index];
3780 /* we can calculate using ansi strings because we're just
3781 * calculating string length, not size
3783 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3784 LPDWORD lpdwUrlLength)
3786 INTERNET_SCHEME nScheme;
3790 if (lpUrlComponents->lpszScheme)
3792 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3793 *lpdwUrlLength += dwLen;
3794 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3800 nScheme = lpUrlComponents->nScheme;
3802 if (nScheme == INTERNET_SCHEME_DEFAULT)
3803 nScheme = INTERNET_SCHEME_HTTP;
3804 scheme = INTERNET_GetSchemeString(nScheme);
3805 *lpdwUrlLength += strlenW(scheme);
3808 (*lpdwUrlLength)++; /* ':' */
3809 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3810 *lpdwUrlLength += strlen("//");
3812 if (lpUrlComponents->lpszUserName)
3814 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3815 *lpdwUrlLength += strlen("@");
3819 if (lpUrlComponents->lpszPassword)
3821 SetLastError(ERROR_INVALID_PARAMETER);
3826 if (lpUrlComponents->lpszPassword)
3828 *lpdwUrlLength += strlen(":");
3829 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3832 if (lpUrlComponents->lpszHostName)
3834 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3836 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3838 char szPort[MAX_WORD_DIGITS+1];
3840 sprintf(szPort, "%d", lpUrlComponents->nPort);
3841 *lpdwUrlLength += strlen(szPort);
3842 *lpdwUrlLength += strlen(":");
3845 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3846 (*lpdwUrlLength)++; /* '/' */
3849 if (lpUrlComponents->lpszUrlPath)
3850 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3855 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3859 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3861 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3862 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3863 urlCompW->nScheme = lpUrlComponents->nScheme;
3864 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3865 urlCompW->nPort = lpUrlComponents->nPort;
3866 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3867 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3868 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3869 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3871 if (lpUrlComponents->lpszScheme)
3873 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3874 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3875 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3876 -1, urlCompW->lpszScheme, len);
3879 if (lpUrlComponents->lpszHostName)
3881 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3882 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3883 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3884 -1, urlCompW->lpszHostName, len);
3887 if (lpUrlComponents->lpszUserName)
3889 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3890 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3891 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3892 -1, urlCompW->lpszUserName, len);
3895 if (lpUrlComponents->lpszPassword)
3897 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3898 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3899 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3900 -1, urlCompW->lpszPassword, len);
3903 if (lpUrlComponents->lpszUrlPath)
3905 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3906 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3907 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3908 -1, urlCompW->lpszUrlPath, len);
3911 if (lpUrlComponents->lpszExtraInfo)
3913 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3914 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3915 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3916 -1, urlCompW->lpszExtraInfo, len);
3920 /***********************************************************************
3921 * InternetCreateUrlA (WININET.@)
3923 * See InternetCreateUrlW.
3925 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3926 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3930 URL_COMPONENTSW urlCompW;
3932 TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3934 if (!lpUrlComponents)
3937 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3939 SetLastError(ERROR_INVALID_PARAMETER);
3943 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3946 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3948 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3950 if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
3951 *lpdwUrlLength /= sizeof(WCHAR);
3953 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3954 * minus one, so add one to leave room for NULL terminator
3957 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3959 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3960 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3961 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3962 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3963 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3964 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3965 HeapFree(GetProcessHeap(), 0, urlW);
3970 /***********************************************************************
3971 * InternetCreateUrlW (WININET.@)
3973 * Creates a URL from its component parts.
3976 * lpUrlComponents [I] URL Components.
3977 * dwFlags [I] Flags. See notes.
3978 * lpszUrl [I] Buffer in which to store the created URL.
3979 * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by
3980 * lpszUrl in characters. On output, the number of bytes
3981 * required to store the URL including terminator.
3985 * The dwFlags parameter can be zero or more of the following:
3986 *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL.
3993 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3994 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3997 INTERNET_SCHEME nScheme;
3999 static const WCHAR slashSlashW[] = {'/','/'};
4000 static const WCHAR percentD[] = {'%','d',0};
4002 TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
4004 if (!lpUrlComponents)
4007 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
4009 SetLastError(ERROR_INVALID_PARAMETER);
4013 if (!calc_url_length(lpUrlComponents, &dwLen))
4016 if (!lpszUrl || *lpdwUrlLength < dwLen)
4018 *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
4019 SetLastError(ERROR_INSUFFICIENT_BUFFER);
4023 *lpdwUrlLength = dwLen;
4028 if (lpUrlComponents->lpszScheme)
4030 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
4031 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
4034 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4039 nScheme = lpUrlComponents->nScheme;
4041 if (nScheme == INTERNET_SCHEME_DEFAULT)
4042 nScheme = INTERNET_SCHEME_HTTP;
4044 scheme = INTERNET_GetSchemeString(nScheme);
4045 dwLen = strlenW(scheme);
4046 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4050 /* all schemes are followed by at least a colon */
4054 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4056 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4057 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4060 if (lpUrlComponents->lpszUserName)
4062 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4063 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4066 if (lpUrlComponents->lpszPassword)
4071 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4072 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4080 if (lpUrlComponents->lpszHostName)
4082 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4083 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4086 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4088 WCHAR szPort[MAX_WORD_DIGITS+1];
4090 sprintfW(szPort, percentD, lpUrlComponents->nPort);
4093 dwLen = strlenW(szPort);
4094 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4098 /* add slash between hostname and path if necessary */
4099 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4107 if (lpUrlComponents->lpszUrlPath)
4109 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4110 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4119 /***********************************************************************
4120 * InternetConfirmZoneCrossingA (WININET.@)
4123 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4125 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4126 return ERROR_SUCCESS;
4129 /***********************************************************************
4130 * InternetConfirmZoneCrossingW (WININET.@)
4133 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4135 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4136 return ERROR_SUCCESS;
4139 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4140 LPDWORD lpdwConnection, DWORD dwReserved )
4142 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
4143 lpdwConnection, dwReserved);
4144 return ERROR_SUCCESS;
4147 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4148 LPDWORD lpdwConnection, DWORD dwReserved )
4150 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
4151 lpdwConnection, dwReserved);
4152 return ERROR_SUCCESS;
4155 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4157 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4161 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4163 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4167 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
4169 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection, dwReserved);
4170 return ERROR_SUCCESS;
4173 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4176 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4177 debugstr_w(pwszTarget), pbHexHash);
4181 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4183 FIXME("(%p, 0x%08lx) stub\n", hInternet, dwError);