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:
287 LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR));
291 TlsSetValue(g_dwTlsErrIndex, (LPVOID)lpwite);
295 case DLL_THREAD_DETACH:
296 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
298 LPVOID lpwite = TlsGetValue(g_dwTlsErrIndex);
299 HeapFree(GetProcessHeap(), 0, lpwite);
303 case DLL_PROCESS_DETACH:
305 URLCacheContainers_DeleteAll();
307 if (g_dwTlsErrIndex != TLS_OUT_OF_INDEXES)
309 HeapFree(GetProcessHeap(), 0, TlsGetValue(g_dwTlsErrIndex));
310 TlsFree(g_dwTlsErrIndex);
313 SetEvent(hQuitEvent);
315 CloseHandle(hQuitEvent);
316 CloseHandle(hWorkEvent);
317 DeleteCriticalSection(&csQueue);
325 /***********************************************************************
326 * InternetInitializeAutoProxyDll (WININET.@)
328 * Setup the internal proxy
337 BOOL WINAPI InternetInitializeAutoProxyDll(DWORD dwReserved)
340 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
344 /***********************************************************************
345 * DetectAutoProxyUrl (WININET.@)
347 * Auto detect the proxy url
353 BOOL WINAPI DetectAutoProxyUrl(LPSTR lpszAutoProxyUrl,
354 DWORD dwAutoProxyUrlLength, DWORD dwDetectFlags)
357 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
362 /***********************************************************************
363 * INTERNET_ConfigureProxyFromReg
366 * The proxy may be specified in the form 'http=proxy.my.org'
367 * Presumably that means there can be ftp=ftpproxy.my.org too.
369 static BOOL INTERNET_ConfigureProxyFromReg( LPWININETAPPINFOW lpwai )
372 DWORD r, keytype, len, enabled;
373 LPCSTR lpszInternetSettings =
374 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
375 static const WCHAR szProxyServer[] = { 'P','r','o','x','y','S','e','r','v','e','r', 0 };
377 r = RegOpenKeyA(HKEY_CURRENT_USER, lpszInternetSettings, &key);
378 if ( r != ERROR_SUCCESS )
381 len = sizeof enabled;
382 r = RegQueryValueExA( key, "ProxyEnable", NULL, &keytype,
383 (BYTE*)&enabled, &len);
384 if( (r == ERROR_SUCCESS) && enabled )
386 TRACE("Proxy is enabled.\n");
388 /* figure out how much memory the proxy setting takes */
389 r = RegQueryValueExW( key, szProxyServer, NULL, &keytype,
391 if( (r == ERROR_SUCCESS) && len && (keytype == REG_SZ) )
394 static const WCHAR szHttp[] = {'h','t','t','p','=',0};
396 szProxy=HeapAlloc( GetProcessHeap(), 0, len );
397 RegQueryValueExW( key, szProxyServer, NULL, &keytype,
398 (BYTE*)szProxy, &len);
400 /* find the http proxy, and strip away everything else */
401 p = strstrW( szProxy, szHttp );
404 p += lstrlenW(szHttp);
405 lstrcpyW( szProxy, p );
407 p = strchrW( szProxy, ' ' );
411 lpwai->dwAccessType = INTERNET_OPEN_TYPE_PROXY;
412 lpwai->lpszProxy = szProxy;
414 TRACE("http proxy = %s\n", debugstr_w(lpwai->lpszProxy));
417 ERR("Couldn't read proxy server settings.\n");
420 TRACE("Proxy is not enabled.\n");
426 /***********************************************************************
427 * dump_INTERNET_FLAGS
429 * Helper function to TRACE the internet flags.
435 static void dump_INTERNET_FLAGS(DWORD dwFlags)
437 #define FE(x) { x, #x }
438 static const wininet_flag_info flag[] = {
439 FE(INTERNET_FLAG_RELOAD),
440 FE(INTERNET_FLAG_RAW_DATA),
441 FE(INTERNET_FLAG_EXISTING_CONNECT),
442 FE(INTERNET_FLAG_ASYNC),
443 FE(INTERNET_FLAG_PASSIVE),
444 FE(INTERNET_FLAG_NO_CACHE_WRITE),
445 FE(INTERNET_FLAG_MAKE_PERSISTENT),
446 FE(INTERNET_FLAG_FROM_CACHE),
447 FE(INTERNET_FLAG_SECURE),
448 FE(INTERNET_FLAG_KEEP_CONNECTION),
449 FE(INTERNET_FLAG_NO_AUTO_REDIRECT),
450 FE(INTERNET_FLAG_READ_PREFETCH),
451 FE(INTERNET_FLAG_NO_COOKIES),
452 FE(INTERNET_FLAG_NO_AUTH),
453 FE(INTERNET_FLAG_CACHE_IF_NET_FAIL),
454 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP),
455 FE(INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS),
456 FE(INTERNET_FLAG_IGNORE_CERT_DATE_INVALID),
457 FE(INTERNET_FLAG_IGNORE_CERT_CN_INVALID),
458 FE(INTERNET_FLAG_RESYNCHRONIZE),
459 FE(INTERNET_FLAG_HYPERLINK),
460 FE(INTERNET_FLAG_NO_UI),
461 FE(INTERNET_FLAG_PRAGMA_NOCACHE),
462 FE(INTERNET_FLAG_CACHE_ASYNC),
463 FE(INTERNET_FLAG_FORMS_SUBMIT),
464 FE(INTERNET_FLAG_NEED_FILE),
465 FE(INTERNET_FLAG_TRANSFER_ASCII),
466 FE(INTERNET_FLAG_TRANSFER_BINARY)
471 for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) {
472 if (flag[i].val & dwFlags) {
473 TRACE(" %s", flag[i].name);
474 dwFlags &= ~flag[i].val;
478 TRACE(" Unknown flags (%08lx)\n", dwFlags);
483 /***********************************************************************
484 * InternetOpenW (WININET.@)
486 * Per-application initialization of wininet
489 * HINTERNET on success
493 HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType,
494 LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
496 LPWININETAPPINFOW lpwai = NULL;
497 HINTERNET handle = NULL;
499 if (TRACE_ON(wininet)) {
500 #define FE(x) { x, #x }
501 static const wininet_flag_info access_type[] = {
502 FE(INTERNET_OPEN_TYPE_PRECONFIG),
503 FE(INTERNET_OPEN_TYPE_DIRECT),
504 FE(INTERNET_OPEN_TYPE_PROXY),
505 FE(INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY)
509 const char *access_type_str = "Unknown";
511 TRACE("(%s, %li, %s, %s, %li)\n", debugstr_w(lpszAgent), dwAccessType,
512 debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags);
513 for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) {
514 if (access_type[i].val == dwAccessType) {
515 access_type_str = access_type[i].name;
519 TRACE(" access type : %s\n", access_type_str);
521 dump_INTERNET_FLAGS(dwFlags);
524 /* Clear any error information */
525 INTERNET_SetLastError(0);
527 lpwai = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETAPPINFOW));
530 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
534 memset(lpwai, 0, sizeof(WININETAPPINFOW));
535 lpwai->hdr.htype = WH_HINIT;
536 lpwai->hdr.lpwhparent = NULL;
537 lpwai->hdr.dwFlags = dwFlags;
538 lpwai->hdr.dwRefCount = 1;
539 lpwai->hdr.destroy = INTERNET_CloseHandle;
540 lpwai->dwAccessType = dwAccessType;
541 lpwai->lpszProxyUsername = NULL;
542 lpwai->lpszProxyPassword = NULL;
544 handle = WININET_AllocHandle( &lpwai->hdr );
547 HeapFree( GetProcessHeap(), 0, lpwai );
548 INTERNET_SetLastError(ERROR_OUTOFMEMORY);
552 if (NULL != lpszAgent)
554 lpwai->lpszAgent = HeapAlloc( GetProcessHeap(),0,
555 (strlenW(lpszAgent)+1)*sizeof(WCHAR));
556 if (lpwai->lpszAgent)
557 lstrcpyW( lpwai->lpszAgent, lpszAgent );
559 if(dwAccessType == INTERNET_OPEN_TYPE_PRECONFIG)
560 INTERNET_ConfigureProxyFromReg( lpwai );
561 else if (NULL != lpszProxy)
563 lpwai->lpszProxy = HeapAlloc( GetProcessHeap(), 0,
564 (strlenW(lpszProxy)+1)*sizeof(WCHAR));
565 if (lpwai->lpszProxy)
566 lstrcpyW( lpwai->lpszProxy, lpszProxy );
569 if (NULL != lpszProxyBypass)
571 lpwai->lpszProxyBypass = HeapAlloc( GetProcessHeap(), 0,
572 (strlenW(lpszProxyBypass)+1)*sizeof(WCHAR));
573 if (lpwai->lpszProxyBypass)
574 lstrcpyW( lpwai->lpszProxyBypass, lpszProxyBypass );
579 WININET_Release( &lpwai->hdr );
581 TRACE("returning %p\n", lpwai);
587 /***********************************************************************
588 * InternetOpenA (WININET.@)
590 * Per-application initialization of wininet
593 * HINTERNET on success
597 HINTERNET WINAPI InternetOpenA(LPCSTR lpszAgent, DWORD dwAccessType,
598 LPCSTR lpszProxy, LPCSTR lpszProxyBypass, DWORD dwFlags)
600 HINTERNET rc = (HINTERNET)NULL;
602 WCHAR *szAgent = NULL, *szProxy = NULL, *szBypass = NULL;
604 TRACE("(%s, 0x%08lx, %s, %s, 0x%08lx)\n", debugstr_a(lpszAgent),
605 dwAccessType, debugstr_a(lpszProxy), debugstr_a(lpszProxyBypass), dwFlags);
609 len = MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, NULL, 0);
610 szAgent = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
611 MultiByteToWideChar(CP_ACP, 0, lpszAgent, -1, szAgent, len);
616 len = MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, NULL, 0);
617 szProxy = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
618 MultiByteToWideChar(CP_ACP, 0, lpszProxy, -1, szProxy, len);
621 if( lpszProxyBypass )
623 len = MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, NULL, 0);
624 szBypass = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
625 MultiByteToWideChar(CP_ACP, 0, lpszProxyBypass, -1, szBypass, len);
628 rc = InternetOpenW(szAgent, dwAccessType, szProxy, szBypass, dwFlags);
630 HeapFree(GetProcessHeap(), 0, szAgent);
631 HeapFree(GetProcessHeap(), 0, szProxy);
632 HeapFree(GetProcessHeap(), 0, szBypass);
637 /***********************************************************************
638 * InternetGetLastResponseInfoA (WININET.@)
640 * Return last wininet error description on the calling thread
643 * TRUE on success of writing to buffer
647 BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
648 LPSTR lpszBuffer, LPDWORD lpdwBufferLength)
650 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
654 *lpdwError = lpwite->dwError;
657 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
658 *lpdwBufferLength = strlen(lpszBuffer);
661 *lpdwBufferLength = 0;
666 /***********************************************************************
667 * InternetGetLastResponseInfoW (WININET.@)
669 * Return last wininet error description on the calling thread
672 * TRUE on success of writing to buffer
676 BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
677 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength)
679 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
683 *lpdwError = lpwite->dwError;
686 memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
687 *lpdwBufferLength = lstrlenW(lpszBuffer);
690 *lpdwBufferLength = 0;
695 /***********************************************************************
696 * InternetGetConnectedState (WININET.@)
698 * Return connected state
702 * if lpdwStatus is not null, return the status (off line,
703 * modem, lan...) in it.
704 * FALSE if not connected
706 BOOL WINAPI InternetGetConnectedState(LPDWORD lpdwStatus, DWORD dwReserved)
708 TRACE("(%p, 0x%08lx)\n", lpdwStatus, dwReserved);
711 FIXME("always returning LAN connection.\n");
712 *lpdwStatus = INTERNET_CONNECTION_LAN;
718 /***********************************************************************
719 * InternetGetConnectedStateExW (WININET.@)
721 * Return connected state
725 * lpdwStatus [O] Flags specifying the status of the internet connection.
726 * lpszConnectionName [O] Pointer to buffer to receive the friendly name of the internet connection.
727 * dwNameLen [I] Size of the buffer, in characters.
728 * dwReserved [I] Reserved. Must be set to 0.
732 * if lpdwStatus is not null, return the status (off line,
733 * modem, lan...) in it.
734 * FALSE if not connected
737 * If the system has no available network connections, an empty string is
738 * stored in lpszConnectionName. If there is a LAN connection, a localized
739 * "LAN Connection" string is stored. Presumably, if only a dial-up
740 * connection is available then the name of the dial-up connection is
741 * returned. Why any application, other than the "Internet Settings" CPL,
742 * would want to use this function instead of the simpler InternetGetConnectedStateW
743 * function is beyond me.
745 BOOL WINAPI InternetGetConnectedStateExW(LPDWORD lpdwStatus, LPWSTR lpszConnectionName,
746 DWORD dwNameLen, DWORD dwReserved)
748 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
755 FIXME("always returning LAN connection.\n");
756 *lpdwStatus = INTERNET_CONNECTION_LAN;
758 return LoadStringW(WININET_hModule, IDS_LANCONNECTION, lpszConnectionName, dwNameLen);
762 /***********************************************************************
763 * InternetGetConnectedStateExA (WININET.@)
765 BOOL WINAPI InternetGetConnectedStateExA(LPDWORD lpdwStatus, LPSTR lpszConnectionName,
766 DWORD dwNameLen, DWORD dwReserved)
768 LPWSTR lpwszConnectionName = NULL;
771 TRACE("(%p, %p, %ld, 0x%08lx)\n", lpdwStatus, lpszConnectionName, dwNameLen, dwReserved);
773 if (lpszConnectionName && dwNameLen > 0)
774 lpwszConnectionName= HeapAlloc(GetProcessHeap(), 0, dwNameLen * sizeof(WCHAR));
776 rc = InternetGetConnectedStateExW(lpdwStatus,lpwszConnectionName, dwNameLen,
778 if (rc && lpwszConnectionName)
780 WideCharToMultiByte(CP_ACP,0,lpwszConnectionName,-1,lpszConnectionName,
781 dwNameLen, NULL, NULL);
783 HeapFree(GetProcessHeap(),0,lpwszConnectionName);
790 /***********************************************************************
791 * InternetConnectW (WININET.@)
793 * Open a ftp, gopher or http session
796 * HINTERNET a session handle on success
800 HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
801 LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
802 LPCWSTR lpszUserName, LPCWSTR lpszPassword,
803 DWORD dwService, DWORD dwFlags, DWORD dwContext)
805 LPWININETAPPINFOW hIC;
806 HINTERNET rc = (HINTERNET) NULL;
808 TRACE("(%p, %s, %i, %s, %s, %li, %li, %li)\n", hInternet, debugstr_w(lpszServerName),
809 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
810 dwService, dwFlags, dwContext);
812 /* Clear any error information */
813 INTERNET_SetLastError(0);
814 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
815 if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
820 case INTERNET_SERVICE_FTP:
821 rc = FTP_Connect(hIC, lpszServerName, nServerPort,
822 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
825 case INTERNET_SERVICE_HTTP:
826 rc = HTTP_Connect(hIC, lpszServerName, nServerPort,
827 lpszUserName, lpszPassword, dwFlags, dwContext, 0);
830 case INTERNET_SERVICE_GOPHER:
836 WININET_Release( &hIC->hdr );
838 TRACE("returning %p\n", rc);
843 /***********************************************************************
844 * InternetConnectA (WININET.@)
846 * Open a ftp, gopher or http session
849 * HINTERNET a session handle on success
853 HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
854 LPCSTR lpszServerName, INTERNET_PORT nServerPort,
855 LPCSTR lpszUserName, LPCSTR lpszPassword,
856 DWORD dwService, DWORD dwFlags, DWORD dwContext)
858 HINTERNET rc = (HINTERNET)NULL;
860 LPWSTR szServerName = NULL;
861 LPWSTR szUserName = NULL;
862 LPWSTR szPassword = NULL;
866 len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
867 szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
868 MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
872 len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
873 szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
874 MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
878 len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
879 szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
880 MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
884 rc = InternetConnectW(hInternet, szServerName, nServerPort,
885 szUserName, szPassword, dwService, dwFlags, dwContext);
887 HeapFree(GetProcessHeap(), 0, szServerName);
888 HeapFree(GetProcessHeap(), 0, szUserName);
889 HeapFree(GetProcessHeap(), 0, szPassword);
894 /***********************************************************************
895 * InternetFindNextFileA (WININET.@)
897 * Continues a file search from a previous call to FindFirstFile
904 BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
909 ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
911 WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
915 /***********************************************************************
916 * InternetFindNextFileW (WININET.@)
918 * Continues a file search from a previous call to FindFirstFile
925 BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
927 LPWININETAPPINFOW hIC = NULL;
928 LPWININETFINDNEXTW lpwh;
929 BOOL bSuccess = FALSE;
933 lpwh = (LPWININETFINDNEXTW) WININET_GetObject( hFind );
934 if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
936 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
940 hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
941 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
943 WORKREQUEST workRequest;
944 struct WORKREQ_INTERNETFINDNEXTW *req;
946 workRequest.asyncall = INTERNETFINDNEXTW;
947 workRequest.hdr = WININET_AddRef( &lpwh->hdr );
948 req = &workRequest.u.InternetFindNextW;
949 req->lpFindFileData = lpvFindData;
951 bSuccess = INTERNET_AsyncCall(&workRequest);
955 bSuccess = INTERNET_FindNextFileW(lpwh, lpvFindData);
959 WININET_Release( &lpwh->hdr );
963 /***********************************************************************
964 * INTERNET_FindNextFileW (Internal)
966 * Continues a file search from a previous call to FindFirstFile
973 BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData)
975 BOOL bSuccess = TRUE;
976 LPWIN32_FIND_DATAW lpFindFileData;
980 assert (lpwh->hdr.htype == WH_HFINDNEXT);
982 /* Clear any error information */
983 INTERNET_SetLastError(0);
985 if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
987 FIXME("Only FTP find next supported\n");
988 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
992 TRACE("index(%ld) size(%ld)\n", lpwh->index, lpwh->size);
994 lpFindFileData = (LPWIN32_FIND_DATAW) lpvFindData;
995 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
997 if (lpwh->index >= lpwh->size)
999 INTERNET_SetLastError(ERROR_NO_MORE_FILES);
1004 FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
1007 TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData->cFileName), lpFindFileData->nFileSizeLow);
1011 if (lpwh->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1013 INTERNET_ASYNC_RESULT iar;
1015 iar.dwResult = (DWORD)bSuccess;
1016 iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
1017 INTERNET_GetLastError();
1019 INTERNET_SendCallback(&lpwh->hdr, lpwh->hdr.dwContext,
1020 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1021 sizeof(INTERNET_ASYNC_RESULT));
1028 /***********************************************************************
1029 * INTERNET_CloseHandle (internal)
1031 * Close internet handle
1037 static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr)
1039 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr;
1041 TRACE("%p\n",lpwai);
1043 HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent);
1044 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy);
1045 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass);
1046 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername);
1047 HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword);
1048 HeapFree(GetProcessHeap(), 0, lpwai);
1052 /***********************************************************************
1053 * InternetCloseHandle (WININET.@)
1055 * Generic close handle function
1062 BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
1064 LPWININETHANDLEHEADER lpwh;
1066 TRACE("%p\n",hInternet);
1068 lpwh = WININET_GetObject( hInternet );
1071 INTERNET_SetLastError(ERROR_INVALID_HANDLE);
1075 /* FIXME: native appears to send this from the equivalent of
1076 * WININET_Release */
1077 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1078 INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
1081 if( lpwh->lpwhparent )
1082 WININET_Release( lpwh->lpwhparent );
1083 WININET_FreeHandle( hInternet );
1084 WININET_Release( lpwh );
1090 /***********************************************************************
1091 * ConvertUrlComponentValue (Internal)
1093 * Helper function for InternetCrackUrlW
1096 static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
1097 LPWSTR lpwszComponent, DWORD dwwComponentLen,
1098 LPCSTR lpszStart, LPCWSTR lpwszStart)
1100 TRACE("%p %ld %p %ld %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
1101 if (*dwComponentLen != 0)
1103 DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
1104 if (*lppszComponent == NULL)
1106 int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
1108 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1110 *lppszComponent = NULL;
1111 *dwComponentLen = nASCIILength;
1115 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1116 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1117 (*lppszComponent)[ncpylen]=0;
1118 *dwComponentLen = ncpylen;
1124 /***********************************************************************
1125 * InternetCrackUrlA (WININET.@)
1127 * Break up URL into its components
1129 * TODO: Handle dwFlags
1136 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1137 LPURL_COMPONENTSA lpUrlComponents)
1140 URL_COMPONENTSW UCW;
1143 TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1146 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1148 /* if dwUrlLength=-1 then nLength includes null but length to
1149 InternetCrackUrlW should not include it */
1150 if (dwUrlLength == -1) nLength--;
1152 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1153 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1155 memset(&UCW,0,sizeof(UCW));
1156 if(lpUrlComponents->dwHostNameLength!=0)
1157 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1158 if(lpUrlComponents->dwUserNameLength!=0)
1159 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1160 if(lpUrlComponents->dwPasswordLength!=0)
1161 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1162 if(lpUrlComponents->dwUrlPathLength!=0)
1163 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1164 if(lpUrlComponents->dwSchemeLength!=0)
1165 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1166 if(lpUrlComponents->dwExtraInfoLength!=0)
1167 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1168 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1170 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1174 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1175 UCW.lpszHostName, UCW.dwHostNameLength,
1177 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1178 UCW.lpszUserName, UCW.dwUserNameLength,
1180 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1181 UCW.lpszPassword, UCW.dwPasswordLength,
1183 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1184 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1186 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1187 UCW.lpszScheme, UCW.dwSchemeLength,
1189 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1190 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1192 lpUrlComponents->nScheme=UCW.nScheme;
1193 lpUrlComponents->nPort=UCW.nPort;
1194 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1196 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1197 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1198 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1199 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1200 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1205 static const WCHAR url_schemes[][7] =
1208 {'g','o','p','h','e','r',0},
1209 {'h','t','t','p',0},
1210 {'h','t','t','p','s',0},
1211 {'f','i','l','e',0},
1212 {'n','e','w','s',0},
1213 {'m','a','i','l','t','o',0},
1217 /***********************************************************************
1218 * GetInternetSchemeW (internal)
1224 * INTERNET_SCHEME_UNKNOWN on failure
1227 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1231 TRACE("%s %ld\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1233 if(lpszScheme==NULL)
1234 return INTERNET_SCHEME_UNKNOWN;
1236 for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
1237 if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
1238 return INTERNET_SCHEME_FIRST + i;
1240 return INTERNET_SCHEME_UNKNOWN;
1243 /***********************************************************************
1244 * SetUrlComponentValueW (Internal)
1246 * Helper function for InternetCrackUrlW
1249 * lppszComponent [O] Holds the returned string
1250 * dwComponentLen [I] Holds the size of lppszComponent
1251 * [O] Holds the length of the string in lppszComponent without '\0'
1252 * lpszStart [I] Holds the string to copy from
1253 * len [I] Holds the length of lpszStart without '\0'
1260 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1262 TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
1264 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1267 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1269 if (*lppszComponent == NULL)
1271 *lppszComponent = (LPWSTR)lpszStart;
1272 *dwComponentLen = len;
1276 DWORD ncpylen = min((*dwComponentLen)-1, len);
1277 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1278 (*lppszComponent)[ncpylen] = '\0';
1279 *dwComponentLen = ncpylen;
1286 /***********************************************************************
1287 * InternetCrackUrlW (WININET.@)
1289 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1290 LPURL_COMPONENTSW lpUC)
1294 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1297 LPCWSTR lpszParam = NULL;
1298 BOOL bIsAbsolute = FALSE;
1299 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1300 LPCWSTR lpszcp = NULL;
1301 LPWSTR lpszUrl_decode = NULL;
1302 DWORD dwUrlLength = dwUrlLength_orig;
1303 const WCHAR lpszSeparators[3]={';','?',0};
1304 const WCHAR lpszSlash[2]={'/',0};
1306 dwUrlLength=strlenW(lpszUrl);
1308 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1309 if (dwFlags & ICU_DECODE)
1311 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1312 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1314 lpszUrl = lpszUrl_decode;
1319 /* Determine if the URI is absolute. */
1320 while (*lpszap != '\0')
1322 if (isalnumW(*lpszap))
1327 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1334 lpszcp = lpszUrl; /* Relative url */
1340 lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
1341 lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
1343 /* Parse <params> */
1344 lpszParam = strpbrkW(lpszap, lpszSeparators);
1345 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1346 lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
1348 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1352 /* Get scheme first. */
1353 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1354 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1355 lpszUrl, lpszcp - lpszUrl);
1357 /* Eat ':' in protocol. */
1360 /* double slash indicates the net_loc portion is present */
1361 if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
1365 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1369 lpszNetLoc = min(lpszNetLoc, lpszParam);
1371 lpszNetLoc = lpszParam;
1373 else if (!lpszNetLoc)
1374 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1382 /* [<user>[<:password>]@]<host>[:<port>] */
1383 /* First find the user and password if they exist */
1385 lpszHost = strchrW(lpszcp, '@');
1386 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1388 /* username and password not specified. */
1389 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1390 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1392 else /* Parse out username and password */
1394 LPCWSTR lpszUser = lpszcp;
1395 LPCWSTR lpszPasswd = lpszHost;
1397 while (lpszcp < lpszHost)
1400 lpszPasswd = lpszcp;
1405 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1406 lpszUser, lpszPasswd - lpszUser);
1408 if (lpszPasswd != lpszHost)
1410 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1411 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1412 lpszHost - lpszPasswd);
1414 lpszcp++; /* Advance to beginning of host */
1417 /* Parse <host><:port> */
1420 lpszPort = lpszNetLoc;
1422 /* special case for res:// URLs: there is no port here, so the host is the
1423 entire string up to the first '/' */
1424 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1426 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1427 lpszHost, lpszPort - lpszHost);
1432 while (lpszcp < lpszNetLoc)
1440 /* If the scheme is "file" and the host is just one letter, it's not a host */
1441 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1444 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1449 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1450 lpszHost, lpszPort - lpszHost);
1451 if (lpszPort != lpszNetLoc)
1452 lpUC->nPort = atoiW(++lpszPort);
1453 else switch (lpUC->nScheme)
1455 case INTERNET_SCHEME_HTTP:
1456 lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
1458 case INTERNET_SCHEME_HTTPS:
1459 lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
1461 case INTERNET_SCHEME_FTP:
1462 lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
1464 case INTERNET_SCHEME_GOPHER:
1465 lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
1476 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1477 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1478 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1483 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
1484 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1485 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1486 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1489 /* Here lpszcp points to:
1491 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1492 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1494 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
1498 /* Only truncate the parameter list if it's already been saved
1499 * in lpUC->lpszExtraInfo.
1501 if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
1502 len = lpszParam - lpszcp;
1505 /* Leave the parameter list in lpszUrlPath. Strip off any trailing
1506 * newlines if necessary.
1508 LPWSTR lpsznewline = strchrW(lpszcp, '\n');
1509 if (lpsznewline != NULL)
1510 len = lpsznewline - lpszcp;
1512 len = dwUrlLength-(lpszcp-lpszUrl);
1514 SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
1519 lpUC->dwUrlPathLength = 0;
1522 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
1523 debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
1524 debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
1525 debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
1526 debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
1529 HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
1533 /***********************************************************************
1534 * InternetAttemptConnect (WININET.@)
1536 * Attempt to make a connection to the internet
1539 * ERROR_SUCCESS on success
1540 * Error value on failure
1543 DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
1546 return ERROR_SUCCESS;
1550 /***********************************************************************
1551 * InternetCanonicalizeUrlA (WININET.@)
1553 * Escape unsafe characters and spaces
1560 BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
1561 LPDWORD lpdwBufferLength, DWORD dwFlags)
1564 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1565 if(dwFlags & ICU_DECODE)
1567 dwURLFlags |= URL_UNESCAPE;
1568 dwFlags &= ~ICU_DECODE;
1571 if(dwFlags & ICU_ESCAPE)
1573 dwURLFlags |= URL_UNESCAPE;
1574 dwFlags &= ~ICU_ESCAPE;
1576 if(dwFlags & ICU_BROWSER_MODE)
1578 dwURLFlags |= URL_BROWSER_MODE;
1579 dwFlags &= ~ICU_BROWSER_MODE;
1582 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1583 TRACE("%s %p %p %08lx\n", debugstr_a(lpszUrl), lpszBuffer,
1584 lpdwBufferLength, dwURLFlags);
1586 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1587 dwFlags ^= ICU_NO_ENCODE;
1589 hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1591 return (hr == S_OK) ? TRUE : FALSE;
1594 /***********************************************************************
1595 * InternetCanonicalizeUrlW (WININET.@)
1597 * Escape unsafe characters and spaces
1604 BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
1605 LPDWORD lpdwBufferLength, DWORD dwFlags)
1608 DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
1609 if(dwFlags & ICU_DECODE)
1611 dwURLFlags |= URL_UNESCAPE;
1612 dwFlags &= ~ICU_DECODE;
1615 if(dwFlags & ICU_ESCAPE)
1617 dwURLFlags |= URL_UNESCAPE;
1618 dwFlags &= ~ICU_ESCAPE;
1620 if(dwFlags & ICU_BROWSER_MODE)
1622 dwURLFlags |= URL_BROWSER_MODE;
1623 dwFlags &= ~ICU_BROWSER_MODE;
1626 FIXME("Unhandled flags 0x%08lx\n", dwFlags);
1627 TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
1628 lpdwBufferLength, dwURLFlags);
1630 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
1631 dwFlags ^= ICU_NO_ENCODE;
1633 hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
1635 return (hr == S_OK) ? TRUE : FALSE;
1639 /***********************************************************************
1640 * InternetSetStatusCallbackA (WININET.@)
1642 * Sets up a callback function which is called as progress is made
1643 * during an operation.
1646 * Previous callback or NULL on success
1647 * INTERNET_INVALID_STATUS_CALLBACK on failure
1650 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
1651 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1653 INTERNET_STATUS_CALLBACK retVal;
1654 LPWININETHANDLEHEADER lpwh;
1656 TRACE("0x%08lx\n", (ULONG)hInternet);
1658 lpwh = WININET_GetObject(hInternet);
1660 return INTERNET_INVALID_STATUS_CALLBACK;
1662 lpwh->dwInternalFlags &= ~INET_CALLBACKW;
1663 retVal = lpwh->lpfnStatusCB;
1664 lpwh->lpfnStatusCB = lpfnIntCB;
1666 WININET_Release( lpwh );
1671 /***********************************************************************
1672 * InternetSetStatusCallbackW (WININET.@)
1674 * Sets up a callback function which is called as progress is made
1675 * during an operation.
1678 * Previous callback or NULL on success
1679 * INTERNET_INVALID_STATUS_CALLBACK on failure
1682 INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(
1683 HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
1685 INTERNET_STATUS_CALLBACK retVal;
1686 LPWININETHANDLEHEADER lpwh;
1688 TRACE("0x%08lx\n", (ULONG)hInternet);
1690 lpwh = WININET_GetObject(hInternet);
1692 return INTERNET_INVALID_STATUS_CALLBACK;
1694 lpwh->dwInternalFlags |= INET_CALLBACKW;
1695 retVal = lpwh->lpfnStatusCB;
1696 lpwh->lpfnStatusCB = lpfnIntCB;
1698 WININET_Release( lpwh );
1703 /***********************************************************************
1704 * InternetSetFilePointer (WININET.@)
1706 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove,
1707 PVOID pReserved, DWORD dwMoveContext, DWORD dwContext)
1713 /***********************************************************************
1714 * InternetWriteFile (WININET.@)
1716 * Write data to an open internet file
1723 BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer ,
1724 DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
1726 BOOL retval = FALSE;
1728 LPWININETHANDLEHEADER lpwh;
1731 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1735 switch (lpwh->htype)
1739 LPWININETHTTPREQW lpwhr;
1740 lpwhr = (LPWININETHTTPREQW)lpwh;
1742 TRACE("HTTPREQ %li\n",dwNumOfBytesToWrite);
1743 retval = NETCON_send(&lpwhr->netConnection, lpBuffer,
1744 dwNumOfBytesToWrite, 0, (LPINT)lpdwNumOfBytesWritten);
1746 WININET_Release( lpwh );
1752 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1761 int res = send(nSocket, lpBuffer, dwNumOfBytesToWrite, 0);
1762 retval = (res >= 0);
1763 *lpdwNumOfBytesWritten = retval ? res : 0;
1765 WININET_Release( lpwh );
1771 static BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
1772 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead,
1773 BOOL bWait, BOOL bSendCompletionStatus)
1775 BOOL retval = FALSE;
1778 /* FIXME: this should use NETCON functions! */
1779 switch (lpwh->htype)
1782 if (!NETCON_recv(&((LPWININETHTTPREQW)lpwh)->netConnection, lpBuffer,
1783 dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0, (int *)pdwNumOfBytesRead))
1785 *pdwNumOfBytesRead = 0;
1786 retval = TRUE; /* Under windows, it seems to return 0 even if nothing was read... */
1793 /* FIXME: FTP should use NETCON_ stuff */
1794 nSocket = ((LPWININETFILE)lpwh)->nDataSocket;
1797 int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
1798 retval = (res >= 0);
1799 *pdwNumOfBytesRead = retval ? res : 0;
1807 if (bSendCompletionStatus)
1809 INTERNET_ASYNC_RESULT iar;
1811 iar.dwResult = retval;
1812 iar.dwError = iar.dwError = retval ? ERROR_SUCCESS :
1813 INTERNET_GetLastError();
1815 INTERNET_SendCallback(lpwh, lpwh->dwContext,
1816 INTERNET_STATUS_REQUEST_COMPLETE, &iar,
1817 sizeof(INTERNET_ASYNC_RESULT));
1822 /***********************************************************************
1823 * InternetReadFile (WININET.@)
1825 * Read data from an open internet file
1832 BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
1833 DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
1835 LPWININETHANDLEHEADER lpwh;
1838 TRACE("%p %p %ld %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
1840 lpwh = WININET_GetObject( hFile );
1843 SetLastError(ERROR_INVALID_HANDLE);
1847 retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE, FALSE);
1848 WININET_Release( lpwh );
1850 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
1854 /***********************************************************************
1855 * InternetReadFileExA (WININET.@)
1857 * Read data from an open internet file
1860 * hFile [I] Handle returned by InternetOpenUrl or HttpOpenRequest.
1861 * lpBuffersOut [I/O] Buffer.
1862 * dwFlags [I] Flags. See notes.
1863 * dwContext [I] Context for callbacks.
1870 * The parameter dwFlags include zero or more of the following flags:
1871 *|IRF_ASYNC - Makes the call asynchronous.
1872 *|IRF_SYNC - Makes the call synchronous.
1873 *|IRF_USE_CONTEXT - Forces dwContext to be used.
1874 *|IRF_NO_WAIT - Don't block if the data is not available, just return what is available.
1876 * However, in testing IRF_USE_CONTEXT seems to have no effect - dwContext isn't used.
1879 * InternetOpenUrlA(), HttpOpenRequestA()
1881 BOOL WINAPI InternetReadFileExA(HINTERNET hFile, LPINTERNET_BUFFERSA lpBuffersOut,
1882 DWORD dwFlags, DWORD dwContext)
1884 BOOL retval = FALSE;
1885 LPWININETHANDLEHEADER lpwh;
1887 TRACE("(%p %p 0x%lx 0x%lx)\n", hFile, lpBuffersOut, dwFlags, dwContext);
1889 if (dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT))
1890 FIXME("these dwFlags aren't implemented: 0x%lx\n", dwFlags & ~(IRF_ASYNC|IRF_NO_WAIT));
1892 if (lpBuffersOut->dwStructSize != sizeof(*lpBuffersOut))
1894 SetLastError(ERROR_INVALID_PARAMETER);
1898 lpwh = (LPWININETHANDLEHEADER) WININET_GetObject( hFile );
1901 SetLastError(ERROR_INVALID_HANDLE);
1905 /* FIXME: native only does it asynchronously if the amount of data
1906 * requested isn't available. See NtReadFile. */
1907 /* FIXME: IRF_ASYNC may not be the right thing to test here;
1908 * hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC is probably better, but
1909 * we should implement the above first */
1910 if (dwFlags & IRF_ASYNC)
1912 WORKREQUEST workRequest;
1913 struct WORKREQ_INTERNETREADFILEEXA *req;
1915 workRequest.asyncall = INTERNETREADFILEEXA;
1916 workRequest.hdr = WININET_AddRef( lpwh );
1917 req = &workRequest.u.InternetReadFileExA;
1918 req->lpBuffersOut = lpBuffersOut;
1920 retval = INTERNET_AsyncCall(&workRequest);
1921 if (!retval) return FALSE;
1923 SetLastError(ERROR_IO_PENDING);
1927 retval = INTERNET_ReadFile(lpwh, lpBuffersOut->lpvBuffer,
1928 lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength,
1929 !(dwFlags & IRF_NO_WAIT), FALSE);
1931 WININET_Release( lpwh );
1933 TRACE("-- %s (bytes read: %ld)\n", retval ? "TRUE": "FALSE", lpBuffersOut->dwBufferLength);
1937 /***********************************************************************
1938 * InternetReadFileExW (WININET.@)
1940 * Read data from an open internet file.
1943 * hFile [I] Handle returned by InternetOpenUrl() or HttpOpenRequest().
1944 * lpBuffersOut [I/O] Buffer.
1945 * dwFlags [I] Flags.
1946 * dwContext [I] Context for callbacks.
1949 * FALSE, last error is set to ERROR_CALL_NOT_IMPLEMENTED
1952 * Not implemented in Wine or native either (as of IE6 SP2).
1955 BOOL WINAPI InternetReadFileExW(HINTERNET hFile, LPINTERNET_BUFFERSW lpBuffer,
1956 DWORD dwFlags, DWORD dwContext)
1958 ERR("(%p, %p, 0x%lx, 0x%lx): not implemented in native\n", hFile, lpBuffer, dwFlags, dwContext);
1960 INTERNET_SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1964 /***********************************************************************
1965 * INET_QueryOptionHelper (internal)
1967 static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD dwOption,
1968 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
1970 LPWININETHANDLEHEADER lpwhh;
1971 BOOL bSuccess = FALSE;
1973 TRACE("(%p, 0x%08lx, %p, %p)\n", hInternet, dwOption, lpBuffer, lpdwBufferLength);
1975 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
1979 case INTERNET_OPTION_HANDLE_TYPE:
1985 WARN("Invalid hInternet handle\n");
1986 SetLastError(ERROR_INVALID_HANDLE);
1990 type = lpwhh->htype;
1992 TRACE("INTERNET_OPTION_HANDLE_TYPE: %ld\n", type);
1994 if (*lpdwBufferLength < sizeof(ULONG))
1995 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
1998 memcpy(lpBuffer, &type, sizeof(ULONG));
2001 *lpdwBufferLength = sizeof(ULONG);
2005 case INTERNET_OPTION_REQUEST_FLAGS:
2008 TRACE("INTERNET_OPTION_REQUEST_FLAGS: %ld\n", flags);
2009 if (*lpdwBufferLength < sizeof(ULONG))
2010 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2013 memcpy(lpBuffer, &flags, sizeof(ULONG));
2016 *lpdwBufferLength = sizeof(ULONG);
2020 case INTERNET_OPTION_URL:
2021 case INTERNET_OPTION_DATAFILE_NAME:
2025 WARN("Invalid hInternet handle\n");
2026 SetLastError(ERROR_INVALID_HANDLE);
2029 if (lpwhh->htype == WH_HHTTPREQ)
2031 LPWININETHTTPREQW lpreq = (LPWININETHTTPREQW) lpwhh;
2033 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
2034 static const WCHAR szHost[] = {'H','o','s','t',0};
2038 Host = HTTP_GetHeader(lpreq,szHost);
2039 sprintfW(url,szFmt,Host->lpszValue,lpreq->lpszPath);
2040 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
2043 sizeRequired = WideCharToMultiByte(CP_ACP,0,url,-1,
2044 lpBuffer,*lpdwBufferLength,NULL,NULL);
2045 if (sizeRequired > *lpdwBufferLength)
2046 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2049 *lpdwBufferLength = sizeRequired;
2053 sizeRequired = (lstrlenW(url)+1) * sizeof(WCHAR);
2054 if (*lpdwBufferLength < sizeRequired)
2055 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2058 strcpyW(lpBuffer, url);
2061 *lpdwBufferLength = sizeRequired;
2066 case INTERNET_OPTION_HTTP_VERSION:
2068 if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO))
2069 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2073 * Presently hardcoded to 1.1
2075 ((HTTP_VERSION_INFO*)lpBuffer)->dwMajorVersion = 1;
2076 ((HTTP_VERSION_INFO*)lpBuffer)->dwMinorVersion = 1;
2079 *lpdwBufferLength = sizeof(HTTP_VERSION_INFO);
2082 case INTERNET_OPTION_CONNECTED_STATE:
2084 DWORD *pdwConnectedState = (DWORD *)lpBuffer;
2085 FIXME("INTERNET_OPTION_CONNECTED_STATE: semi-stub\n");
2087 if (*lpdwBufferLength < sizeof(*pdwConnectedState))
2088 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2091 *pdwConnectedState = INTERNET_STATE_CONNECTED;
2094 *lpdwBufferLength = sizeof(*pdwConnectedState);
2097 case INTERNET_OPTION_PROXY:
2099 LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW)lpwhh;
2100 WININETAPPINFOW wai;
2104 TRACE("Getting global proxy info\n");
2105 memset(&wai, 0, sizeof(WININETAPPINFOW));
2106 INTERNET_ConfigureProxyFromReg( &wai );
2112 INTERNET_PROXY_INFOW *pPI = (INTERNET_PROXY_INFOW *)lpBuffer;
2113 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2115 if (lpwai->lpszProxy)
2116 proxyBytesRequired = (lstrlenW(lpwai->lpszProxy) + 1) *
2118 if (lpwai->lpszProxyBypass)
2119 proxyBypassBytesRequired =
2120 (lstrlenW(lpwai->lpszProxyBypass) + 1) * sizeof(WCHAR);
2121 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOW) +
2122 proxyBytesRequired + proxyBypassBytesRequired)
2123 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2126 pPI->dwAccessType = lpwai->dwAccessType;
2127 if (lpwai->lpszProxy)
2129 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2130 sizeof(INTERNET_PROXY_INFOW));
2131 lstrcpyW((LPWSTR)pPI->lpszProxy, lpwai->lpszProxy);
2135 pPI->lpszProxy = (LPWSTR)((LPBYTE)lpBuffer +
2136 sizeof(INTERNET_PROXY_INFOW));
2137 *((LPWSTR)(pPI->lpszProxy)) = 0;
2140 if (lpwai->lpszProxyBypass)
2142 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2143 sizeof(INTERNET_PROXY_INFOW) +
2144 proxyBytesRequired);
2145 lstrcpyW((LPWSTR)pPI->lpszProxyBypass,
2146 lpwai->lpszProxyBypass);
2150 pPI->lpszProxyBypass = (LPWSTR)((LPBYTE)lpBuffer +
2151 sizeof(INTERNET_PROXY_INFOW) +
2152 proxyBytesRequired);
2153 *((LPWSTR)(pPI->lpszProxyBypass)) = 0;
2157 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOW) +
2158 proxyBytesRequired + proxyBypassBytesRequired;
2162 INTERNET_PROXY_INFOA *pPI = (INTERNET_PROXY_INFOA *)lpBuffer;
2163 DWORD proxyBytesRequired = 0, proxyBypassBytesRequired = 0;
2165 if (lpwai->lpszProxy)
2166 proxyBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2167 lpwai->lpszProxy, -1, NULL, 0, NULL, NULL);
2168 if (lpwai->lpszProxyBypass)
2169 proxyBypassBytesRequired = WideCharToMultiByte(CP_ACP, 0,
2170 lpwai->lpszProxyBypass, -1, NULL, 0, NULL, NULL);
2171 if (*lpdwBufferLength < sizeof(INTERNET_PROXY_INFOA) +
2172 proxyBytesRequired + proxyBypassBytesRequired)
2173 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2176 pPI->dwAccessType = lpwai->dwAccessType;
2177 if (lpwai->lpszProxy)
2179 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2180 sizeof(INTERNET_PROXY_INFOA));
2181 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxy, -1,
2182 (LPSTR)pPI->lpszProxy, proxyBytesRequired, NULL, NULL);
2186 pPI->lpszProxy = (LPSTR)((LPBYTE)lpBuffer +
2187 sizeof(INTERNET_PROXY_INFOA));
2188 *((LPSTR)(pPI->lpszProxy)) = '\0';
2191 if (lpwai->lpszProxyBypass)
2193 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2194 sizeof(INTERNET_PROXY_INFOA) + proxyBytesRequired);
2195 WideCharToMultiByte(CP_ACP, 0, lpwai->lpszProxyBypass,
2196 -1, (LPSTR)pPI->lpszProxyBypass,
2197 proxyBypassBytesRequired,
2202 pPI->lpszProxyBypass = (LPSTR)((LPBYTE)lpBuffer +
2203 sizeof(INTERNET_PROXY_INFOA) +
2204 proxyBytesRequired);
2205 *((LPSTR)(pPI->lpszProxyBypass)) = '\0';
2209 *lpdwBufferLength = sizeof(INTERNET_PROXY_INFOA) +
2210 proxyBytesRequired + proxyBypassBytesRequired;
2214 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2217 TRACE("INTERNET_OPTION_MAX_CONNS_PER_SERVER: %ld\n", conn);
2218 if (*lpdwBufferLength < sizeof(ULONG))
2219 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2222 memcpy(lpBuffer, &conn, sizeof(ULONG));
2225 *lpdwBufferLength = sizeof(ULONG);
2228 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2231 TRACE("INTERNET_OPTION_MAX_CONNS_1_0_SERVER: %ld\n", conn);
2232 if (*lpdwBufferLength < sizeof(ULONG))
2233 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2236 memcpy(lpBuffer, &conn, sizeof(ULONG));
2239 *lpdwBufferLength = sizeof(ULONG);
2242 case INTERNET_OPTION_SECURITY_FLAGS:
2243 FIXME("INTERNET_OPTION_SECURITY_FLAGS: Stub\n");
2246 case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT:
2247 if (*lpdwBufferLength < sizeof(INTERNET_CERTIFICATE_INFOW))
2249 *lpdwBufferLength = sizeof(INTERNET_CERTIFICATE_INFOW);
2250 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
2252 else if (lpwhh->htype == WH_HHTTPREQ)
2254 LPWININETHTTPREQW lpwhr;
2255 PCCERT_CONTEXT context;
2257 lpwhr = (LPWININETHTTPREQW)lpwhh;
2258 context = (PCCERT_CONTEXT)NETCON_GetCert(&(lpwhr->netConnection));
2261 LPINTERNET_CERTIFICATE_INFOW info = (LPINTERNET_CERTIFICATE_INFOW)lpBuffer;
2264 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2265 info->ftExpiry = context->pCertInfo->NotAfter;
2266 info->ftStart = context->pCertInfo->NotBefore;
2269 strLen = CertNameToStrW(context->dwCertEncodingType,
2270 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2272 info->lpszSubjectInfo = LocalAlloc(0,
2273 strLen * sizeof(WCHAR));
2274 if (info->lpszSubjectInfo)
2275 CertNameToStrW(context->dwCertEncodingType,
2276 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2277 info->lpszSubjectInfo, strLen);
2278 strLen = CertNameToStrW(context->dwCertEncodingType,
2279 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2281 info->lpszIssuerInfo = LocalAlloc(0,
2282 strLen * sizeof(WCHAR));
2283 if (info->lpszIssuerInfo)
2284 CertNameToStrW(context->dwCertEncodingType,
2285 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2286 info->lpszIssuerInfo, strLen);
2290 LPINTERNET_CERTIFICATE_INFOA infoA =
2291 (LPINTERNET_CERTIFICATE_INFOA)info;
2293 strLen = CertNameToStrA(context->dwCertEncodingType,
2294 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2296 infoA->lpszSubjectInfo = LocalAlloc(0, strLen);
2297 if (infoA->lpszSubjectInfo)
2298 CertNameToStrA(context->dwCertEncodingType,
2299 &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR,
2300 infoA->lpszSubjectInfo, strLen);
2301 strLen = CertNameToStrA(context->dwCertEncodingType,
2302 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2304 infoA->lpszIssuerInfo = LocalAlloc(0, strLen);
2305 if (infoA->lpszIssuerInfo)
2306 CertNameToStrA(context->dwCertEncodingType,
2307 &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR,
2308 infoA->lpszIssuerInfo, strLen);
2311 * Contrary to MSDN, these do not appear to be set.
2313 * lpszSignatureAlgName
2314 * lpszEncryptionAlgName
2317 CertFreeCertificateContext(context);
2323 FIXME("Stub! %ld\n", dwOption);
2327 WININET_Release( lpwhh );
2332 /***********************************************************************
2333 * InternetQueryOptionW (WININET.@)
2335 * Queries an options on the specified handle
2342 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2343 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2345 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2348 /***********************************************************************
2349 * InternetQueryOptionA (WININET.@)
2351 * Queries an options on the specified handle
2358 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2359 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2361 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2365 /***********************************************************************
2366 * InternetSetOptionW (WININET.@)
2368 * Sets an options on the specified handle
2375 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2376 LPVOID lpBuffer, DWORD dwBufferLength)
2378 LPWININETHANDLEHEADER lpwhh;
2381 TRACE("0x%08lx\n", dwOption);
2383 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2389 case INTERNET_OPTION_HTTP_VERSION:
2391 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2392 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2395 case INTERNET_OPTION_ERROR_MASK:
2397 unsigned long flags=*(unsigned long*)lpBuffer;
2398 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2401 case INTERNET_OPTION_CODEPAGE:
2403 unsigned long codepage=*(unsigned long*)lpBuffer;
2404 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2407 case INTERNET_OPTION_REQUEST_PRIORITY:
2409 unsigned long priority=*(unsigned long*)lpBuffer;
2410 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2413 case INTERNET_OPTION_CONNECT_TIMEOUT:
2415 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2416 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2419 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2421 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2422 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2425 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2427 unsigned long conns=*(unsigned long*)lpBuffer;
2428 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2431 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2433 unsigned long conns=*(unsigned long*)lpBuffer;
2434 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2437 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2438 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2440 case INTERNET_OPTION_END_BROWSER_SESSION:
2441 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2443 case INTERNET_OPTION_CONNECTED_STATE:
2444 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2446 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2447 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2449 case INTERNET_OPTION_SEND_TIMEOUT:
2450 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2451 TRACE("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT\n");
2452 if (dwBufferLength == sizeof(DWORD))
2454 if (lpwhh->htype == WH_HHTTPREQ)
2455 ret = NETCON_set_timeout(
2456 &((LPWININETHTTPREQW)lpwhh)->netConnection,
2457 dwOption == INTERNET_OPTION_SEND_TIMEOUT,
2458 *(DWORD *)lpBuffer);
2461 FIXME("INTERNET_OPTION_SEND/RECEIVE_TIMEOUT not supported on protocol %d\n",
2463 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2469 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2473 case INTERNET_OPTION_CONNECT_RETRIES:
2474 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2476 case INTERNET_OPTION_CONTEXT_VALUE:
2477 FIXME("Option INTERNET_OPTION_CONTEXT_VALUE; STUB\n");
2480 FIXME("Option %ld STUB\n",dwOption);
2481 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2485 WININET_Release( lpwhh );
2491 /***********************************************************************
2492 * InternetSetOptionA (WININET.@)
2494 * Sets an options on the specified handle.
2501 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2502 LPVOID lpBuffer, DWORD dwBufferLength)
2510 case INTERNET_OPTION_PROXY:
2512 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2513 LPINTERNET_PROXY_INFOW piw;
2514 DWORD proxlen, prbylen;
2517 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2518 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2519 wlen = sizeof(*piw) + proxlen + prbylen;
2520 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2521 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2522 piw->dwAccessType = pi->dwAccessType;
2523 prox = (LPWSTR) &piw[1];
2524 prby = &prox[proxlen+1];
2525 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2526 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2527 piw->lpszProxy = prox;
2528 piw->lpszProxyBypass = prby;
2531 case INTERNET_OPTION_USER_AGENT:
2532 case INTERNET_OPTION_USERNAME:
2533 case INTERNET_OPTION_PASSWORD:
2534 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2536 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2537 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2542 wlen = dwBufferLength;
2545 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2547 if( lpBuffer != wbuffer )
2548 HeapFree( GetProcessHeap(), 0, wbuffer );
2554 /***********************************************************************
2555 * InternetSetOptionExA (WININET.@)
2557 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2558 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2560 FIXME("Flags %08lx ignored\n", dwFlags);
2561 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2564 /***********************************************************************
2565 * InternetSetOptionExW (WININET.@)
2567 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2568 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2570 FIXME("Flags %08lx ignored\n", dwFlags);
2571 if( dwFlags & ~ISO_VALID_FLAGS )
2573 SetLastError( ERROR_INVALID_PARAMETER );
2576 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2579 static const WCHAR WININET_wkday[7][4] =
2580 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2581 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2582 static const WCHAR WININET_month[12][4] =
2583 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2584 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2585 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2587 /***********************************************************************
2588 * InternetTimeFromSystemTimeA (WININET.@)
2590 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2593 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2595 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2597 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2598 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2603 /***********************************************************************
2604 * InternetTimeFromSystemTimeW (WININET.@)
2606 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2608 static const WCHAR date[] =
2609 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2610 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2612 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2614 if (!time || !string) return FALSE;
2616 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2619 sprintfW( string, date,
2620 WININET_wkday[time->wDayOfWeek],
2622 WININET_month[time->wMonth - 1],
2631 /***********************************************************************
2632 * InternetTimeToSystemTimeA (WININET.@)
2634 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2640 TRACE( "%s %p 0x%08lx\n", debugstr_a(string), time, reserved );
2642 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2643 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2647 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2648 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2649 HeapFree( GetProcessHeap(), 0, stringW );
2654 /***********************************************************************
2655 * InternetTimeToSystemTimeW (WININET.@)
2657 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2660 WCHAR *s = (LPWSTR)string;
2662 TRACE( "%s %p 0x%08lx\n", debugstr_w(string), time, reserved );
2664 if (!string || !time) return FALSE;
2666 /* Windows does this too */
2667 GetSystemTime( time );
2669 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2670 * a SYSTEMTIME structure.
2673 while (*s && !isalphaW( *s )) s++;
2674 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2675 time->wDayOfWeek = 7;
2677 for (i = 0; i < 7; i++)
2679 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2680 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2681 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2683 time->wDayOfWeek = i;
2688 if (time->wDayOfWeek > 6) return TRUE;
2689 while (*s && !isdigitW( *s )) s++;
2690 time->wDay = strtolW( s, &s, 10 );
2692 while (*s && !isalphaW( *s )) s++;
2693 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2696 for (i = 0; i < 12; i++)
2698 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2699 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2700 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2702 time->wMonth = i + 1;
2706 if (time->wMonth == 0) return TRUE;
2708 while (*s && !isdigitW( *s )) s++;
2709 if (*s == '\0') return TRUE;
2710 time->wYear = strtolW( s, &s, 10 );
2712 while (*s && !isdigitW( *s )) s++;
2713 if (*s == '\0') return TRUE;
2714 time->wHour = strtolW( s, &s, 10 );
2716 while (*s && !isdigitW( *s )) s++;
2717 if (*s == '\0') return TRUE;
2718 time->wMinute = strtolW( s, &s, 10 );
2720 while (*s && !isdigitW( *s )) s++;
2721 if (*s == '\0') return TRUE;
2722 time->wSecond = strtolW( s, &s, 10 );
2724 time->wMilliseconds = 0;
2728 /***********************************************************************
2729 * InternetCheckConnectionW (WININET.@)
2731 * Pings a requested host to check internet connection
2734 * TRUE on success and FALSE on failure. If a failure then
2735 * ERROR_NOT_CONNECTED is placed into GetLastError
2738 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2741 * this is a kludge which runs the resident ping program and reads the output.
2743 * Anyone have a better idea?
2747 static const CHAR ping[] = "ping -w 1 ";
2748 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2749 CHAR *command = NULL;
2757 * Crack or set the Address
2759 if (lpszUrl == NULL)
2762 * According to the doc we are supost to use the ip for the next
2763 * server in the WnInet internal server database. I have
2764 * no idea what that is or how to get it.
2766 * So someone needs to implement this.
2768 FIXME("Unimplemented with URL of NULL\n");
2773 URL_COMPONENTSW components;
2775 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2776 components.lpszHostName = (LPWSTR)&hostW;
2777 components.dwHostNameLength = 1024;
2779 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2782 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2786 * Build our ping command
2788 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2789 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2790 strcpy(command,ping);
2791 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2792 strcat(command,redirect);
2794 TRACE("Ping command is : %s\n",command);
2796 status = system(command);
2798 TRACE("Ping returned a code of %i\n",status);
2800 /* Ping return code of 0 indicates success */
2806 HeapFree( GetProcessHeap(), 0, command );
2808 SetLastError(ERROR_NOT_CONNECTED);
2814 /***********************************************************************
2815 * InternetCheckConnectionA (WININET.@)
2817 * Pings a requested host to check internet connection
2820 * TRUE on success and FALSE on failure. If a failure then
2821 * ERROR_NOT_CONNECTED is placed into GetLastError
2824 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2830 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2831 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2833 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2834 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2835 HeapFree(GetProcessHeap(), 0, szUrl);
2841 /**********************************************************
2842 * INTERNET_InternetOpenUrlW (internal)
2847 * handle of connection or NULL on failure
2849 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2850 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2852 URL_COMPONENTSW urlComponents;
2853 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2854 WCHAR password[1024], path[2048], extra[1024];
2855 HINTERNET client = NULL, client1 = NULL;
2857 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2858 dwHeadersLength, dwFlags, dwContext);
2860 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2861 urlComponents.lpszScheme = protocol;
2862 urlComponents.dwSchemeLength = 32;
2863 urlComponents.lpszHostName = hostName;
2864 urlComponents.dwHostNameLength = MAXHOSTNAME;
2865 urlComponents.lpszUserName = userName;
2866 urlComponents.dwUserNameLength = 1024;
2867 urlComponents.lpszPassword = password;
2868 urlComponents.dwPasswordLength = 1024;
2869 urlComponents.lpszUrlPath = path;
2870 urlComponents.dwUrlPathLength = 2048;
2871 urlComponents.lpszExtraInfo = extra;
2872 urlComponents.dwExtraInfoLength = 1024;
2873 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2875 switch(urlComponents.nScheme) {
2876 case INTERNET_SCHEME_FTP:
2877 if(urlComponents.nPort == 0)
2878 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2879 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2880 userName, password, dwFlags, dwContext, INET_OPENURL);
2883 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2884 if(client1 == NULL) {
2885 InternetCloseHandle(client);
2890 case INTERNET_SCHEME_HTTP:
2891 case INTERNET_SCHEME_HTTPS: {
2892 static const WCHAR szStars[] = { '*','/','*', 0 };
2893 LPCWSTR accept[2] = { szStars, NULL };
2894 if(urlComponents.nPort == 0) {
2895 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2896 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2898 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2900 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2901 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2902 userName, password, dwFlags, dwContext, INET_OPENURL);
2905 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2906 if(client1 == NULL) {
2907 InternetCloseHandle(client);
2910 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2911 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2912 InternetCloseHandle(client1);
2917 case INTERNET_SCHEME_GOPHER:
2918 /* gopher doesn't seem to be implemented in wine, but it's supposed
2919 * to be supported by InternetOpenUrlA. */
2924 TRACE(" %p <--\n", client1);
2929 /**********************************************************
2930 * InternetOpenUrlW (WININET.@)
2935 * handle of connection or NULL on failure
2937 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2938 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2940 HINTERNET ret = NULL;
2941 LPWININETAPPINFOW hIC = NULL;
2943 if (TRACE_ON(wininet)) {
2944 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2945 dwHeadersLength, dwFlags, dwContext);
2947 dump_INTERNET_FLAGS(dwFlags);
2950 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2951 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2952 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2956 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2957 WORKREQUEST workRequest;
2958 struct WORKREQ_INTERNETOPENURLW *req;
2960 workRequest.asyncall = INTERNETOPENURLW;
2961 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2962 req = &workRequest.u.InternetOpenUrlW;
2964 req->lpszUrl = WININET_strdupW(lpszUrl);
2968 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2970 req->lpszHeaders = 0;
2971 req->dwHeadersLength = dwHeadersLength;
2972 req->dwFlags = dwFlags;
2973 req->dwContext = dwContext;
2975 INTERNET_AsyncCall(&workRequest);
2977 * This is from windows.
2979 SetLastError(ERROR_IO_PENDING);
2981 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2986 WININET_Release( &hIC->hdr );
2987 TRACE(" %p <--\n", ret);
2992 /**********************************************************
2993 * InternetOpenUrlA (WININET.@)
2998 * handle of connection or NULL on failure
3000 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
3001 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
3003 HINTERNET rc = (HINTERNET)NULL;
3007 LPWSTR szUrl = NULL;
3008 LPWSTR szHeaders = NULL;
3013 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
3014 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
3016 return (HINTERNET)NULL;
3017 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
3021 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
3022 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
3024 HeapFree(GetProcessHeap(), 0, szUrl);
3025 return (HINTERNET)NULL;
3027 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
3030 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
3031 lenHeaders, dwFlags, dwContext);
3033 HeapFree(GetProcessHeap(), 0, szUrl);
3034 HeapFree(GetProcessHeap(), 0, szHeaders);
3040 /***********************************************************************
3041 * INTERNET_SetLastError (internal)
3043 * Set last thread specific error
3048 void INTERNET_SetLastError(DWORD dwError)
3050 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3052 SetLastError(dwError);
3054 lpwite->dwError = dwError;
3058 /***********************************************************************
3059 * INTERNET_GetLastError (internal)
3061 * Get last thread specific error
3066 DWORD INTERNET_GetLastError(void)
3068 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3069 /* TlsGetValue clears last error, so set it again here */
3070 SetLastError(lpwite->dwError);
3071 return lpwite->dwError;
3075 /***********************************************************************
3076 * INTERNET_WorkerThreadFunc (internal)
3078 * Worker thread execution function
3083 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3090 INTERNET_ExecuteWork();
3093 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
3095 if (dwWaitRes == WAIT_OBJECT_0 + 1)
3096 INTERNET_ExecuteWork();
3100 InterlockedIncrement(&dwNumIdleThreads);
3103 InterlockedDecrement(&dwNumIdleThreads);
3104 InterlockedDecrement(&dwNumThreads);
3105 TRACE("Worker thread exiting\n");
3110 /***********************************************************************
3111 * INTERNET_InsertWorkRequest (internal)
3113 * Insert work request into queue
3118 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
3120 BOOL bSuccess = FALSE;
3121 LPWORKREQUEST lpNewRequest;
3125 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3128 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3129 lpNewRequest->prev = NULL;
3131 EnterCriticalSection(&csQueue);
3133 lpNewRequest->next = lpWorkQueueTail;
3134 if (lpWorkQueueTail)
3135 lpWorkQueueTail->prev = lpNewRequest;
3136 lpWorkQueueTail = lpNewRequest;
3137 if (!lpHeadWorkQueue)
3138 lpHeadWorkQueue = lpWorkQueueTail;
3140 LeaveCriticalSection(&csQueue);
3143 InterlockedIncrement(&dwNumJobs);
3150 /***********************************************************************
3151 * INTERNET_GetWorkRequest (internal)
3153 * Retrieves work request from queue
3158 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
3160 BOOL bSuccess = FALSE;
3161 LPWORKREQUEST lpRequest = NULL;
3165 EnterCriticalSection(&csQueue);
3167 if (lpHeadWorkQueue)
3169 lpRequest = lpHeadWorkQueue;
3170 lpHeadWorkQueue = lpHeadWorkQueue->prev;
3171 if (lpRequest == lpWorkQueueTail)
3172 lpWorkQueueTail = lpHeadWorkQueue;
3175 LeaveCriticalSection(&csQueue);
3179 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
3180 HeapFree(GetProcessHeap(), 0, lpRequest);
3182 InterlockedDecrement(&dwNumJobs);
3189 /***********************************************************************
3190 * INTERNET_AsyncCall (internal)
3192 * Retrieves work request from queue
3197 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3201 BOOL bSuccess = FALSE;
3205 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
3207 InterlockedIncrement(&dwNumIdleThreads);
3209 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
3210 !(hThread = CreateThread(NULL, 0,
3211 INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
3213 InterlockedDecrement(&dwNumThreads);
3214 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3218 TRACE("Created new thread\n");
3222 INTERNET_InsertWorkRequest(lpWorkRequest);
3223 SetEvent(hWorkEvent);
3231 /***********************************************************************
3232 * INTERNET_ExecuteWork (internal)
3237 static VOID INTERNET_ExecuteWork(void)
3239 WORKREQUEST workRequest;
3243 if (!INTERNET_GetWorkRequest(&workRequest))
3246 switch (workRequest.asyncall)
3250 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
3251 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3253 TRACE("FTPPUTFILEW %p\n", lpwfs);
3255 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
3256 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
3258 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
3259 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
3263 case FTPSETCURRENTDIRECTORYW:
3265 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
3266 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3268 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
3270 req = &workRequest.u.FtpSetCurrentDirectoryW;
3271 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
3272 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3276 case FTPCREATEDIRECTORYW:
3278 struct WORKREQ_FTPCREATEDIRECTORYW *req;
3279 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3281 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
3283 req = &workRequest.u.FtpCreateDirectoryW;
3284 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
3285 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3289 case FTPFINDFIRSTFILEW:
3291 struct WORKREQ_FTPFINDFIRSTFILEW *req;
3292 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3294 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
3296 req = &workRequest.u.FtpFindFirstFileW;
3297 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
3298 req->lpFindFileData, req->dwFlags, req->dwContext);
3299 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
3303 case FTPGETCURRENTDIRECTORYW:
3305 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
3306 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3308 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
3310 req = &workRequest.u.FtpGetCurrentDirectoryW;
3311 FTP_FtpGetCurrentDirectoryW(lpwfs,
3312 req->lpszDirectory, req->lpdwDirectory);
3318 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
3319 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3321 TRACE("FTPOPENFILEW %p\n", lpwfs);
3323 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
3324 req->dwAccess, req->dwFlags, req->dwContext);
3325 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3331 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
3332 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3334 TRACE("FTPGETFILEW %p\n", lpwfs);
3336 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
3337 req->lpszNewFile, req->fFailIfExists,
3338 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
3339 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
3340 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
3344 case FTPDELETEFILEW:
3346 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
3347 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3349 TRACE("FTPDELETEFILEW %p\n", lpwfs);
3351 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
3352 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3356 case FTPREMOVEDIRECTORYW:
3358 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
3359 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3361 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
3363 req = &workRequest.u.FtpRemoveDirectoryW;
3364 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
3365 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3369 case FTPRENAMEFILEW:
3371 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
3372 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3374 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
3376 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
3377 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
3378 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
3382 case INTERNETFINDNEXTW:
3384 struct WORKREQ_INTERNETFINDNEXTW *req;
3385 LPWININETFINDNEXTW lpwh = (LPWININETFINDNEXTW) workRequest.hdr;
3387 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
3389 req = &workRequest.u.InternetFindNextW;
3390 INTERNET_FindNextFileW(lpwh, req->lpFindFileData);
3394 case HTTPSENDREQUESTW:
3396 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
3397 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
3399 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
3401 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
3402 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength,
3403 req->dwContentLength, req->bEndRequest);
3405 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
3409 case HTTPOPENREQUESTW:
3411 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
3412 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
3414 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
3416 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
3417 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
3418 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
3420 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
3421 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
3422 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
3423 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
3429 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
3431 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
3433 INTERNET_SendCallback(workRequest.hdr,
3434 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
3435 req->dwStatusInfoLength);
3437 /* And frees the copy of the status info */
3438 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
3442 case INTERNETOPENURLW:
3444 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
3445 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
3447 TRACE("INTERNETOPENURLW %p\n", hIC);
3449 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3450 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3451 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3452 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3455 case INTERNETREADFILEEXA:
3457 struct WORKREQ_INTERNETREADFILEEXA *req = &workRequest.u.InternetReadFileExA;
3459 TRACE("INTERNETREADFILEEXA %p\n", workRequest.hdr);
3461 INTERNET_ReadFile(workRequest.hdr, req->lpBuffersOut->lpvBuffer,
3462 req->lpBuffersOut->dwBufferLength,
3463 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
3467 WININET_Release( workRequest.hdr );
3471 /***********************************************************************
3472 * INTERNET_GetResponseBuffer (internal)
3477 LPSTR INTERNET_GetResponseBuffer(void)
3479 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3481 return lpwite->response;
3484 /***********************************************************************
3485 * INTERNET_GetNextLine (internal)
3487 * Parse next line in directory string listing
3490 * Pointer to beginning of next line
3495 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3499 BOOL bSuccess = FALSE;
3501 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3506 FD_SET(nSocket, &infd);
3507 tv.tv_sec=RESPONSE_TIMEOUT;
3510 while (nRecv < MAX_REPLY_LEN)
3512 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3514 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3516 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3520 if (lpszBuffer[nRecv] == '\n')
3525 if (lpszBuffer[nRecv] != '\r')
3530 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3538 lpszBuffer[nRecv] = '\0';
3540 TRACE(":%d %s\n", nRecv, lpszBuffer);
3549 /**********************************************************
3550 * InternetQueryDataAvailable (WININET.@)
3552 * Determines how much data is available to be read.
3555 * If there is data available then TRUE, otherwise if there
3556 * is not or an error occurred then FALSE. Use GetLastError() to
3557 * check for ERROR_NO_MORE_FILES to see if it was the former.
3559 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3560 LPDWORD lpdwNumberOfBytesAvailble,
3561 DWORD dwFlags, DWORD dwConext)
3563 LPWININETHTTPREQW lpwhr;
3564 BOOL retval = FALSE;
3567 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3570 SetLastError(ERROR_NO_MORE_FILES);
3574 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3576 switch (lpwhr->hdr.htype)
3579 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3580 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3582 SetLastError(ERROR_NO_MORE_FILES);
3590 FIXME("unsupported file type\n");
3593 WININET_Release( &lpwhr->hdr );
3595 TRACE("<-- %i\n",retval);
3600 /***********************************************************************
3601 * InternetLockRequestFile (WININET.@)
3603 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3610 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3617 /***********************************************************************
3618 * InternetAutodial (WININET.@)
3620 * On windows this function is supposed to dial the default internet
3621 * connection. We don't want to have Wine dial out to the internet so
3622 * we return TRUE by default. It might be nice to check if we are connected.
3629 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3633 /* Tell that we are connected to the internet. */
3637 /***********************************************************************
3638 * InternetAutodialHangup (WININET.@)
3640 * Hangs up a connection made with InternetAutodial
3649 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3653 /* we didn't dial, we don't disconnect */
3657 /***********************************************************************
3658 * InternetCombineUrlA (WININET.@)
3660 * Combine a base URL with a relative URL
3668 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3669 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3674 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3676 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3677 dwFlags ^= ICU_NO_ENCODE;
3678 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3683 /***********************************************************************
3684 * InternetCombineUrlW (WININET.@)
3686 * Combine a base URL with a relative URL
3694 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3695 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3700 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3702 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3703 dwFlags ^= ICU_NO_ENCODE;
3704 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3709 /* max port num is 65535 => 5 digits */
3710 #define MAX_WORD_DIGITS 5
3712 #define URL_GET_COMP_LENGTH(url, component) ((url)->dw##component##Length ? \
3713 (url)->dw##component##Length : strlenW((url)->lpsz##component))
3714 #define URL_GET_COMP_LENGTHA(url, component) ((url)->dw##component##Length ? \
3715 (url)->dw##component##Length : strlen((url)->lpsz##component))
3717 static BOOL url_uses_default_port(INTERNET_SCHEME nScheme, INTERNET_PORT nPort)
3719 if ((nScheme == INTERNET_SCHEME_HTTP) &&
3720 (nPort == INTERNET_DEFAULT_HTTP_PORT))
3722 if ((nScheme == INTERNET_SCHEME_HTTPS) &&
3723 (nPort == INTERNET_DEFAULT_HTTPS_PORT))
3725 if ((nScheme == INTERNET_SCHEME_FTP) &&
3726 (nPort == INTERNET_DEFAULT_FTP_PORT))
3728 if ((nScheme == INTERNET_SCHEME_GOPHER) &&
3729 (nPort == INTERNET_DEFAULT_GOPHER_PORT))
3732 if (nPort == INTERNET_INVALID_PORT_NUMBER)
3738 /* opaque urls do not fit into the standard url hierarchy and don't have
3739 * two following slashes */
3740 static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
3742 return (nScheme != INTERNET_SCHEME_FTP) &&
3743 (nScheme != INTERNET_SCHEME_GOPHER) &&
3744 (nScheme != INTERNET_SCHEME_HTTP) &&
3745 (nScheme != INTERNET_SCHEME_HTTPS) &&
3746 (nScheme != INTERNET_SCHEME_FILE);
3749 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
3752 if (scheme < INTERNET_SCHEME_FIRST)
3754 index = scheme - INTERNET_SCHEME_FIRST;
3755 if (index >= sizeof(url_schemes)/sizeof(url_schemes[0]))
3757 return (LPCWSTR)&url_schemes[index];
3760 /* we can calculate using ansi strings because we're just
3761 * calculating string length, not size
3763 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3764 LPDWORD lpdwUrlLength)
3766 INTERNET_SCHEME nScheme;
3770 if (lpUrlComponents->lpszScheme)
3772 DWORD dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3773 *lpdwUrlLength += dwLen;
3774 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
3780 nScheme = lpUrlComponents->nScheme;
3782 if (nScheme == INTERNET_SCHEME_DEFAULT)
3783 nScheme = INTERNET_SCHEME_HTTP;
3784 scheme = INTERNET_GetSchemeString(nScheme);
3785 *lpdwUrlLength += strlenW(scheme);
3788 (*lpdwUrlLength)++; /* ':' */
3789 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
3790 *lpdwUrlLength += strlen("//");
3792 if (lpUrlComponents->lpszUserName)
3794 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
3795 *lpdwUrlLength += strlen("@");
3799 if (lpUrlComponents->lpszPassword)
3801 SetLastError(ERROR_INVALID_PARAMETER);
3806 if (lpUrlComponents->lpszPassword)
3808 *lpdwUrlLength += strlen(":");
3809 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, Password);
3812 if (lpUrlComponents->lpszHostName)
3814 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
3816 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
3818 char szPort[MAX_WORD_DIGITS+1];
3820 sprintf(szPort, "%d", lpUrlComponents->nPort);
3821 *lpdwUrlLength += strlen(szPort);
3822 *lpdwUrlLength += strlen(":");
3825 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
3826 (*lpdwUrlLength)++; /* '/' */
3829 if (lpUrlComponents->lpszUrlPath)
3830 *lpdwUrlLength += URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
3835 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3839 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3841 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3842 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3843 urlCompW->nScheme = lpUrlComponents->nScheme;
3844 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3845 urlCompW->nPort = lpUrlComponents->nPort;
3846 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3847 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3848 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3849 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3851 if (lpUrlComponents->lpszScheme)
3853 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Scheme) + 1;
3854 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3855 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3856 -1, urlCompW->lpszScheme, len);
3859 if (lpUrlComponents->lpszHostName)
3861 len = URL_GET_COMP_LENGTHA(lpUrlComponents, HostName) + 1;
3862 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3863 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3864 -1, urlCompW->lpszHostName, len);
3867 if (lpUrlComponents->lpszUserName)
3869 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UserName) + 1;
3870 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3871 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3872 -1, urlCompW->lpszUserName, len);
3875 if (lpUrlComponents->lpszPassword)
3877 len = URL_GET_COMP_LENGTHA(lpUrlComponents, Password) + 1;
3878 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3879 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3880 -1, urlCompW->lpszPassword, len);
3883 if (lpUrlComponents->lpszUrlPath)
3885 len = URL_GET_COMP_LENGTHA(lpUrlComponents, UrlPath) + 1;
3886 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3887 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3888 -1, urlCompW->lpszUrlPath, len);
3891 if (lpUrlComponents->lpszExtraInfo)
3893 len = URL_GET_COMP_LENGTHA(lpUrlComponents, ExtraInfo) + 1;
3894 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3895 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3896 -1, urlCompW->lpszExtraInfo, len);
3900 /***********************************************************************
3901 * InternetCreateUrlA (WININET.@)
3908 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3909 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3913 URL_COMPONENTSW urlCompW;
3915 TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3917 if (!lpUrlComponents)
3920 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3922 SetLastError(ERROR_INVALID_PARAMETER);
3926 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3929 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3931 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3933 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3934 * minus one, so add one to leave room for NULL terminator
3937 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3939 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3940 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3941 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3942 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3943 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3944 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3945 HeapFree(GetProcessHeap(), 0, urlW);
3950 /***********************************************************************
3951 * InternetCreateUrlW (WININET.@)
3958 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3959 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3962 INTERNET_SCHEME nScheme;
3964 static const WCHAR slashSlashW[] = {'/','/'};
3965 static const WCHAR percentD[] = {'%','d',0};
3967 TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
3969 if (!lpUrlComponents)
3972 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3974 SetLastError(ERROR_INVALID_PARAMETER);
3978 if (!calc_url_length(lpUrlComponents, &dwLen))
3981 if (!lpszUrl || *lpdwUrlLength < dwLen)
3983 *lpdwUrlLength = dwLen + 1; /* terminating null */
3984 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3988 *lpdwUrlLength = dwLen;
3993 if (lpUrlComponents->lpszScheme)
3995 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Scheme);
3996 memcpy(lpszUrl, lpUrlComponents->lpszScheme, dwLen * sizeof(WCHAR));
3999 nScheme = GetInternetSchemeW(lpUrlComponents->lpszScheme, dwLen);
4004 nScheme = lpUrlComponents->nScheme;
4006 if (nScheme == INTERNET_SCHEME_DEFAULT)
4007 nScheme = INTERNET_SCHEME_HTTP;
4009 scheme = INTERNET_GetSchemeString(nScheme);
4010 dwLen = strlenW(scheme);
4011 memcpy(lpszUrl, scheme, dwLen * sizeof(WCHAR));
4015 /* all schemes are followed by at least a colon */
4019 if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
4021 memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
4022 lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
4025 if (lpUrlComponents->lpszUserName)
4027 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UserName);
4028 memcpy(lpszUrl, lpUrlComponents->lpszUserName, dwLen * sizeof(WCHAR));
4031 if (lpUrlComponents->lpszPassword)
4036 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, Password);
4037 memcpy(lpszUrl, lpUrlComponents->lpszPassword, dwLen * sizeof(WCHAR));
4045 if (lpUrlComponents->lpszHostName)
4047 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, HostName);
4048 memcpy(lpszUrl, lpUrlComponents->lpszHostName, dwLen * sizeof(WCHAR));
4051 if (!url_uses_default_port(nScheme, lpUrlComponents->nPort))
4053 WCHAR szPort[MAX_WORD_DIGITS+1];
4055 sprintfW(szPort, percentD, lpUrlComponents->nPort);
4058 dwLen = strlenW(szPort);
4059 memcpy(lpszUrl, szPort, dwLen * sizeof(WCHAR));
4063 /* add slash between hostname and path if necessary */
4064 if (lpUrlComponents->lpszUrlPath && *lpUrlComponents->lpszUrlPath != '/')
4072 if (lpUrlComponents->lpszUrlPath)
4074 dwLen = URL_GET_COMP_LENGTH(lpUrlComponents, UrlPath);
4075 memcpy(lpszUrl, lpUrlComponents->lpszUrlPath, dwLen * sizeof(WCHAR));
4084 /***********************************************************************
4085 * InternetConfirmZoneCrossingA (WININET.@)
4088 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
4090 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
4091 return ERROR_SUCCESS;
4094 /***********************************************************************
4095 * InternetConfirmZoneCrossingW (WININET.@)
4098 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
4100 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
4101 return ERROR_SUCCESS;
4104 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
4105 LPDWORD lpdwConnection, DWORD dwReserved )
4107 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
4108 lpdwConnection, dwReserved);
4109 return ERROR_SUCCESS;
4112 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
4113 LPDWORD lpdwConnection, DWORD dwReserved )
4115 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
4116 lpdwConnection, dwReserved);
4117 return ERROR_SUCCESS;
4120 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4122 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
4126 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
4128 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
4132 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
4134 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection, dwReserved);
4135 return ERROR_SUCCESS;
4138 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
4141 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
4142 debugstr_w(pwszTarget), pbHexHash);
4146 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4148 FIXME("(%p, 0x%08lx) stub\n", hInternet, dwError);