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 %p %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);
1107 *lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
1108 *dwComponentLen = nASCIILength;
1112 DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
1113 WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
1114 (*lppszComponent)[ncpylen]=0;
1115 *dwComponentLen = ncpylen;
1121 /***********************************************************************
1122 * InternetCrackUrlA (WININET.@)
1124 * Break up URL into its components
1126 * TODO: Handle dwFlags
1133 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
1134 LPURL_COMPONENTSA lpUrlComponents)
1137 URL_COMPONENTSW UCW;
1140 TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
1143 nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
1145 /* if dwUrlLength=-1 then nLength includes null but length to
1146 InternetCrackUrlW should not include it */
1147 if (dwUrlLength == -1) nLength--;
1149 lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
1150 MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
1152 memset(&UCW,0,sizeof(UCW));
1153 if(lpUrlComponents->dwHostNameLength!=0)
1154 UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
1155 if(lpUrlComponents->dwUserNameLength!=0)
1156 UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
1157 if(lpUrlComponents->dwPasswordLength!=0)
1158 UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
1159 if(lpUrlComponents->dwUrlPathLength!=0)
1160 UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
1161 if(lpUrlComponents->dwSchemeLength!=0)
1162 UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
1163 if(lpUrlComponents->dwExtraInfoLength!=0)
1164 UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
1165 if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
1167 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1171 ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
1172 UCW.lpszHostName, UCW.dwHostNameLength,
1174 ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
1175 UCW.lpszUserName, UCW.dwUserNameLength,
1177 ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
1178 UCW.lpszPassword, UCW.dwPasswordLength,
1180 ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
1181 UCW.lpszUrlPath, UCW.dwUrlPathLength,
1183 ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
1184 UCW.lpszScheme, UCW.dwSchemeLength,
1186 ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
1187 UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
1189 lpUrlComponents->nScheme=UCW.nScheme;
1190 lpUrlComponents->nPort=UCW.nPort;
1191 HeapFree(GetProcessHeap(), 0, lpwszUrl);
1193 TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
1194 debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
1195 debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
1196 debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
1197 debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
1202 /***********************************************************************
1203 * GetInternetSchemeW (internal)
1209 * INTERNET_SCHEME_UNKNOWN on failure
1212 static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
1214 INTERNET_SCHEME iScheme=INTERNET_SCHEME_UNKNOWN;
1215 static const WCHAR lpszFtp[]={'f','t','p',0};
1216 static const WCHAR lpszGopher[]={'g','o','p','h','e','r',0};
1217 static const WCHAR lpszHttp[]={'h','t','t','p',0};
1218 static const WCHAR lpszHttps[]={'h','t','t','p','s',0};
1219 static const WCHAR lpszFile[]={'f','i','l','e',0};
1220 static const WCHAR lpszNews[]={'n','e','w','s',0};
1221 static const WCHAR lpszMailto[]={'m','a','i','l','t','o',0};
1222 static const WCHAR lpszRes[]={'r','e','s',0};
1223 WCHAR* tempBuffer=NULL;
1224 TRACE("%s %ld\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
1225 if(lpszScheme==NULL)
1226 return INTERNET_SCHEME_UNKNOWN;
1228 tempBuffer=HeapAlloc(GetProcessHeap(),0,(nMaxCmp+1)*sizeof(WCHAR));
1229 lstrcpynW(tempBuffer,lpszScheme,nMaxCmp+1);
1230 strlwrW(tempBuffer);
1231 if (nMaxCmp==strlenW(lpszFtp) && !strncmpW(lpszFtp, tempBuffer, nMaxCmp))
1232 iScheme=INTERNET_SCHEME_FTP;
1233 else if (nMaxCmp==strlenW(lpszGopher) && !strncmpW(lpszGopher, tempBuffer, nMaxCmp))
1234 iScheme=INTERNET_SCHEME_GOPHER;
1235 else if (nMaxCmp==strlenW(lpszHttp) && !strncmpW(lpszHttp, tempBuffer, nMaxCmp))
1236 iScheme=INTERNET_SCHEME_HTTP;
1237 else if (nMaxCmp==strlenW(lpszHttps) && !strncmpW(lpszHttps, tempBuffer, nMaxCmp))
1238 iScheme=INTERNET_SCHEME_HTTPS;
1239 else if (nMaxCmp==strlenW(lpszFile) && !strncmpW(lpszFile, tempBuffer, nMaxCmp))
1240 iScheme=INTERNET_SCHEME_FILE;
1241 else if (nMaxCmp==strlenW(lpszNews) && !strncmpW(lpszNews, tempBuffer, nMaxCmp))
1242 iScheme=INTERNET_SCHEME_NEWS;
1243 else if (nMaxCmp==strlenW(lpszMailto) && !strncmpW(lpszMailto, tempBuffer, nMaxCmp))
1244 iScheme=INTERNET_SCHEME_MAILTO;
1245 else if (nMaxCmp==strlenW(lpszRes) && !strncmpW(lpszRes, tempBuffer, nMaxCmp))
1246 iScheme=INTERNET_SCHEME_RES;
1247 HeapFree(GetProcessHeap(),0,tempBuffer);
1251 /***********************************************************************
1252 * SetUrlComponentValueW (Internal)
1254 * Helper function for InternetCrackUrlW
1257 * lppszComponent [O] Holds the returned string
1258 * dwComponentLen [I] Holds the size of lppszComponent
1259 * [O] Holds the length of the string in lppszComponent without '\0'
1260 * lpszStart [I] Holds the string to copy from
1261 * len [I] Holds the length of lpszStart without '\0'
1268 static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
1270 TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
1272 if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
1275 if (*dwComponentLen != 0 || *lppszComponent == NULL)
1277 if (*lppszComponent == NULL)
1279 *lppszComponent = (LPWSTR)lpszStart;
1280 *dwComponentLen = len;
1284 DWORD ncpylen = min((*dwComponentLen)-1, len);
1285 memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
1286 (*lppszComponent)[ncpylen] = '\0';
1287 *dwComponentLen = ncpylen;
1294 /***********************************************************************
1295 * InternetCrackUrlW (WININET.@)
1297 BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
1298 LPURL_COMPONENTSW lpUC)
1302 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
1305 LPCWSTR lpszParam = NULL;
1306 BOOL bIsAbsolute = FALSE;
1307 LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
1308 LPCWSTR lpszcp = NULL;
1309 LPWSTR lpszUrl_decode = NULL;
1310 DWORD dwUrlLength = dwUrlLength_orig;
1311 const WCHAR lpszSeparators[3]={';','?',0};
1312 const WCHAR lpszSlash[2]={'/',0};
1314 dwUrlLength=strlenW(lpszUrl);
1316 TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
1317 if (dwFlags & ICU_DECODE)
1319 lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
1320 if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
1322 lpszUrl = lpszUrl_decode;
1327 /* Determine if the URI is absolute. */
1328 while (*lpszap != '\0')
1330 if (isalnumW(*lpszap))
1335 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
1342 lpszcp = lpszUrl; /* Relative url */
1348 /* Parse <params> */
1349 lpszParam = strpbrkW(lpszap, lpszSeparators);
1350 if (lpszParam != NULL)
1352 SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
1353 lpszParam, dwUrlLength-(lpszParam-lpszUrl));
1356 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
1359 static const WCHAR wszAbout[]={'a','b','o','u','t',':',0};
1361 /* Get scheme first. */
1362 lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
1363 SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
1364 lpszUrl, lpszcp - lpszUrl);
1366 /* Eat ':' in protocol. */
1369 /* if the scheme is "about", there is no host */
1370 if(strncmpW(wszAbout,lpszUrl, lpszcp - lpszUrl)==0)
1372 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1373 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1374 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
1379 /* Skip over slashes. */
1391 lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
1395 lpszNetLoc = min(lpszNetLoc, lpszParam);
1397 lpszNetLoc = lpszParam;
1399 else if (!lpszNetLoc)
1400 lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
1408 /* [<user>[<:password>]@]<host>[:<port>] */
1409 /* First find the user and password if they exist */
1411 lpszHost = strchrW(lpszcp, '@');
1412 if (lpszHost == NULL || lpszHost > lpszNetLoc)
1414 /* username and password not specified. */
1415 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
1416 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
1418 else /* Parse out username and password */
1420 LPCWSTR lpszUser = lpszcp;
1421 LPCWSTR lpszPasswd = lpszHost;
1423 while (lpszcp < lpszHost)
1426 lpszPasswd = lpszcp;
1431 SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
1432 lpszUser, lpszPasswd - lpszUser);
1434 if (lpszPasswd != lpszHost)
1436 SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
1437 lpszPasswd == lpszHost ? NULL : lpszPasswd,
1438 lpszHost - lpszPasswd);
1440 lpszcp++; /* Advance to beginning of host */
1443 /* Parse <host><:port> */
1446 lpszPort = lpszNetLoc;
1448 /* special case for res:// URLs: there is no port here, so the host is the
1449 entire string up to the first '/' */
1450 if(lpUC->nScheme==INTERNET_SCHEME_RES)
1452 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1453 lpszHost, lpszPort - lpszHost);
1459 while (lpszcp < lpszNetLoc)
1467 /* If the scheme is "file" and the host is just one letter, it's not a host */
1468 if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
1471 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1477 SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
1478 lpszHost, lpszPort - lpszHost);
1479 if (lpszPort != lpszNetLoc)
1480 lpUC->nPort = atoiW(++lpszPort);
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;
2262 memset(info,0,sizeof(INTERNET_CERTIFICATE_INFOW));
2263 info->ftExpiry = context->pCertInfo->NotAfter;
2264 info->ftStart = context->pCertInfo->NotBefore;
2266 * CertNameToStr implement requred for
2272 * lpszSignatureAlgName
2273 * lpszEncryptionAlgName
2276 CertFreeCertificateContext(context);
2282 FIXME("Stub! %ld\n", dwOption);
2286 WININET_Release( lpwhh );
2291 /***********************************************************************
2292 * InternetQueryOptionW (WININET.@)
2294 * Queries an options on the specified handle
2301 BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption,
2302 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2304 return INET_QueryOptionHelper(TRUE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2307 /***********************************************************************
2308 * InternetQueryOptionA (WININET.@)
2310 * Queries an options on the specified handle
2317 BOOL WINAPI InternetQueryOptionA(HINTERNET hInternet, DWORD dwOption,
2318 LPVOID lpBuffer, LPDWORD lpdwBufferLength)
2320 return INET_QueryOptionHelper(FALSE, hInternet, dwOption, lpBuffer, lpdwBufferLength);
2324 /***********************************************************************
2325 * InternetSetOptionW (WININET.@)
2327 * Sets an options on the specified handle
2334 BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption,
2335 LPVOID lpBuffer, DWORD dwBufferLength)
2337 LPWININETHANDLEHEADER lpwhh;
2340 TRACE("0x%08lx\n", dwOption);
2342 lpwhh = (LPWININETHANDLEHEADER) WININET_GetObject( hInternet );
2348 case INTERNET_OPTION_HTTP_VERSION:
2350 HTTP_VERSION_INFO* pVersion=(HTTP_VERSION_INFO*)lpBuffer;
2351 FIXME("Option INTERNET_OPTION_HTTP_VERSION(%ld,%ld): STUB\n",pVersion->dwMajorVersion,pVersion->dwMinorVersion);
2354 case INTERNET_OPTION_ERROR_MASK:
2356 unsigned long flags=*(unsigned long*)lpBuffer;
2357 FIXME("Option INTERNET_OPTION_ERROR_MASK(%ld): STUB\n",flags);
2360 case INTERNET_OPTION_CODEPAGE:
2362 unsigned long codepage=*(unsigned long*)lpBuffer;
2363 FIXME("Option INTERNET_OPTION_CODEPAGE (%ld): STUB\n",codepage);
2366 case INTERNET_OPTION_REQUEST_PRIORITY:
2368 unsigned long priority=*(unsigned long*)lpBuffer;
2369 FIXME("Option INTERNET_OPTION_REQUEST_PRIORITY (%ld): STUB\n",priority);
2372 case INTERNET_OPTION_CONNECT_TIMEOUT:
2374 unsigned long connecttimeout=*(unsigned long*)lpBuffer;
2375 FIXME("Option INTERNET_OPTION_CONNECT_TIMEOUT (%ld): STUB\n",connecttimeout);
2378 case INTERNET_OPTION_DATA_RECEIVE_TIMEOUT:
2380 unsigned long receivetimeout=*(unsigned long*)lpBuffer;
2381 FIXME("Option INTERNET_OPTION_DATA_RECEIVE_TIMEOUT (%ld): STUB\n",receivetimeout);
2384 case INTERNET_OPTION_MAX_CONNS_PER_SERVER:
2386 unsigned long conns=*(unsigned long*)lpBuffer;
2387 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_SERVER (%ld): STUB\n",conns);
2390 case INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER:
2392 unsigned long conns=*(unsigned long*)lpBuffer;
2393 FIXME("Option INTERNET_OPTION_MAX_CONNS_PER_1_0_SERVER (%ld): STUB\n",conns);
2396 case INTERNET_OPTION_RESET_URLCACHE_SESSION:
2397 FIXME("Option INTERNET_OPTION_RESET_URLCACHE_SESSION: STUB\n");
2399 case INTERNET_OPTION_END_BROWSER_SESSION:
2400 FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: STUB\n");
2402 case INTERNET_OPTION_CONNECTED_STATE:
2403 FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n");
2405 case INTERNET_OPTION_DISABLE_PASSPORT_AUTH:
2406 TRACE("Option INTERNET_OPTION_DISABLE_PASSPORT_AUTH: harmless stub, since not enabled\n");
2408 case INTERNET_OPTION_RECEIVE_TIMEOUT:
2409 FIXME("Option INTERNET_OPTION_RECEIVE_TIMEOUT: STUB\n");
2411 case INTERNET_OPTION_SEND_TIMEOUT:
2412 FIXME("Option INTERNET_OPTION_SEND_TIMEOUT: STUB\n");
2414 case INTERNET_OPTION_CONNECT_RETRIES:
2415 FIXME("Option INTERNET_OPTION_CONNECT_RETRIES: STUB\n");
2418 FIXME("Option %ld STUB\n",dwOption);
2419 INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
2423 WININET_Release( lpwhh );
2429 /***********************************************************************
2430 * InternetSetOptionA (WININET.@)
2432 * Sets an options on the specified handle.
2439 BOOL WINAPI InternetSetOptionA(HINTERNET hInternet, DWORD dwOption,
2440 LPVOID lpBuffer, DWORD dwBufferLength)
2448 case INTERNET_OPTION_PROXY:
2450 LPINTERNET_PROXY_INFOA pi = (LPINTERNET_PROXY_INFOA) lpBuffer;
2451 LPINTERNET_PROXY_INFOW piw;
2452 DWORD proxlen, prbylen;
2455 proxlen = MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, NULL, 0);
2456 prbylen= MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, NULL, 0);
2457 wlen = sizeof(*piw) + proxlen + prbylen;
2458 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2459 piw = (LPINTERNET_PROXY_INFOW) wbuffer;
2460 piw->dwAccessType = pi->dwAccessType;
2461 prox = (LPWSTR) &piw[1];
2462 prby = &prox[proxlen+1];
2463 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxy, -1, prox, proxlen);
2464 MultiByteToWideChar( CP_ACP, 0, pi->lpszProxyBypass, -1, prby, prbylen);
2465 piw->lpszProxy = prox;
2466 piw->lpszProxyBypass = prby;
2469 case INTERNET_OPTION_USER_AGENT:
2470 case INTERNET_OPTION_USERNAME:
2471 case INTERNET_OPTION_PASSWORD:
2472 wlen = MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2474 wbuffer = HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(WCHAR) );
2475 MultiByteToWideChar( CP_ACP, 0, lpBuffer, dwBufferLength,
2480 wlen = dwBufferLength;
2483 r = InternetSetOptionW(hInternet,dwOption, wbuffer, wlen);
2485 if( lpBuffer != wbuffer )
2486 HeapFree( GetProcessHeap(), 0, wbuffer );
2492 /***********************************************************************
2493 * InternetSetOptionExA (WININET.@)
2495 BOOL WINAPI InternetSetOptionExA(HINTERNET hInternet, DWORD dwOption,
2496 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2498 FIXME("Flags %08lx ignored\n", dwFlags);
2499 return InternetSetOptionA( hInternet, dwOption, lpBuffer, dwBufferLength );
2502 /***********************************************************************
2503 * InternetSetOptionExW (WININET.@)
2505 BOOL WINAPI InternetSetOptionExW(HINTERNET hInternet, DWORD dwOption,
2506 LPVOID lpBuffer, DWORD dwBufferLength, DWORD dwFlags)
2508 FIXME("Flags %08lx ignored\n", dwFlags);
2509 if( dwFlags & ~ISO_VALID_FLAGS )
2511 SetLastError( ERROR_INVALID_PARAMETER );
2514 return InternetSetOptionW( hInternet, dwOption, lpBuffer, dwBufferLength );
2517 static const WCHAR WININET_wkday[7][4] =
2518 { { 'S','u','n', 0 }, { 'M','o','n', 0 }, { 'T','u','e', 0 }, { 'W','e','d', 0 },
2519 { 'T','h','u', 0 }, { 'F','r','i', 0 }, { 'S','a','t', 0 } };
2520 static const WCHAR WININET_month[12][4] =
2521 { { 'J','a','n', 0 }, { 'F','e','b', 0 }, { 'M','a','r', 0 }, { 'A','p','r', 0 },
2522 { 'M','a','y', 0 }, { 'J','u','n', 0 }, { 'J','u','l', 0 }, { 'A','u','g', 0 },
2523 { 'S','e','p', 0 }, { 'O','c','t', 0 }, { 'N','o','v', 0 }, { 'D','e','c', 0 } };
2525 /***********************************************************************
2526 * InternetTimeFromSystemTimeA (WININET.@)
2528 BOOL WINAPI InternetTimeFromSystemTimeA( const SYSTEMTIME* time, DWORD format, LPSTR string, DWORD size )
2531 WCHAR stringW[INTERNET_RFC1123_BUFSIZE];
2533 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2535 ret = InternetTimeFromSystemTimeW( time, format, stringW, sizeof(stringW) );
2536 if (ret) WideCharToMultiByte( CP_ACP, 0, stringW, -1, string, size, NULL, NULL );
2541 /***********************************************************************
2542 * InternetTimeFromSystemTimeW (WININET.@)
2544 BOOL WINAPI InternetTimeFromSystemTimeW( const SYSTEMTIME* time, DWORD format, LPWSTR string, DWORD size )
2546 static const WCHAR date[] =
2547 { '%','s',',',' ','%','0','2','d',' ','%','s',' ','%','4','d',' ','%','0',
2548 '2','d',':','%','0','2','d',':','%','0','2','d',' ','G','M','T', 0 };
2550 TRACE( "%p 0x%08lx %p 0x%08lx\n", time, format, string, size );
2552 if (!time || !string) return FALSE;
2554 if (format != INTERNET_RFC1123_FORMAT || size < INTERNET_RFC1123_BUFSIZE * sizeof(WCHAR))
2557 sprintfW( string, date,
2558 WININET_wkday[time->wDayOfWeek],
2560 WININET_month[time->wMonth - 1],
2569 /***********************************************************************
2570 * InternetTimeToSystemTimeA (WININET.@)
2572 BOOL WINAPI InternetTimeToSystemTimeA( LPCSTR string, SYSTEMTIME* time, DWORD reserved )
2578 TRACE( "%s %p 0x%08lx\n", debugstr_a(string), time, reserved );
2580 len = MultiByteToWideChar( CP_ACP, 0, string, -1, NULL, 0 );
2581 stringW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2585 MultiByteToWideChar( CP_ACP, 0, string, -1, stringW, len );
2586 ret = InternetTimeToSystemTimeW( stringW, time, reserved );
2587 HeapFree( GetProcessHeap(), 0, stringW );
2592 /***********************************************************************
2593 * InternetTimeToSystemTimeW (WININET.@)
2595 BOOL WINAPI InternetTimeToSystemTimeW( LPCWSTR string, SYSTEMTIME* time, DWORD reserved )
2598 WCHAR *s = (LPWSTR)string;
2600 TRACE( "%s %p 0x%08lx\n", debugstr_w(string), time, reserved );
2602 if (!string || !time) return FALSE;
2604 /* Windows does this too */
2605 GetSystemTime( time );
2607 /* Convert an RFC1123 time such as 'Fri, 07 Jan 2005 12:06:35 GMT' into
2608 * a SYSTEMTIME structure.
2611 while (*s && !isalphaW( *s )) s++;
2612 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2613 time->wDayOfWeek = 7;
2615 for (i = 0; i < 7; i++)
2617 if (toupperW( WININET_wkday[i][0] ) == toupperW( s[0] ) &&
2618 toupperW( WININET_wkday[i][1] ) == toupperW( s[1] ) &&
2619 toupperW( WININET_wkday[i][2] ) == toupperW( s[2] ) )
2621 time->wDayOfWeek = i;
2626 if (time->wDayOfWeek > 6) return TRUE;
2627 while (*s && !isdigitW( *s )) s++;
2628 time->wDay = strtolW( s, &s, 10 );
2630 while (*s && !isalphaW( *s )) s++;
2631 if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
2634 for (i = 0; i < 12; i++)
2636 if (toupperW( WININET_month[i][0]) == toupperW( s[0] ) &&
2637 toupperW( WININET_month[i][1]) == toupperW( s[1] ) &&
2638 toupperW( WININET_month[i][2]) == toupperW( s[2] ) )
2640 time->wMonth = i + 1;
2644 if (time->wMonth == 0) return TRUE;
2646 while (*s && !isdigitW( *s )) s++;
2647 if (*s == '\0') return TRUE;
2648 time->wYear = strtolW( s, &s, 10 );
2650 while (*s && !isdigitW( *s )) s++;
2651 if (*s == '\0') return TRUE;
2652 time->wHour = strtolW( s, &s, 10 );
2654 while (*s && !isdigitW( *s )) s++;
2655 if (*s == '\0') return TRUE;
2656 time->wMinute = strtolW( s, &s, 10 );
2658 while (*s && !isdigitW( *s )) s++;
2659 if (*s == '\0') return TRUE;
2660 time->wSecond = strtolW( s, &s, 10 );
2662 time->wMilliseconds = 0;
2666 /***********************************************************************
2667 * InternetCheckConnectionW (WININET.@)
2669 * Pings a requested host to check internet connection
2672 * TRUE on success and FALSE on failure. If a failure then
2673 * ERROR_NOT_CONNECTED is placed into GetLastError
2676 BOOL WINAPI InternetCheckConnectionW( LPCWSTR lpszUrl, DWORD dwFlags, DWORD dwReserved )
2679 * this is a kludge which runs the resident ping program and reads the output.
2681 * Anyone have a better idea?
2685 static const CHAR ping[] = "ping -w 1 ";
2686 static const CHAR redirect[] = " >/dev/null 2>/dev/null";
2687 CHAR *command = NULL;
2695 * Crack or set the Address
2697 if (lpszUrl == NULL)
2700 * According to the doc we are supost to use the ip for the next
2701 * server in the WnInet internal server database. I have
2702 * no idea what that is or how to get it.
2704 * So someone needs to implement this.
2706 FIXME("Unimplemented with URL of NULL\n");
2711 URL_COMPONENTSW components;
2713 ZeroMemory(&components,sizeof(URL_COMPONENTSW));
2714 components.lpszHostName = (LPWSTR)&hostW;
2715 components.dwHostNameLength = 1024;
2717 if (!InternetCrackUrlW(lpszUrl,0,0,&components))
2720 TRACE("host name : %s\n",debugstr_w(components.lpszHostName));
2724 * Build our ping command
2726 len = WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, NULL, 0, NULL, NULL);
2727 command = HeapAlloc( GetProcessHeap(), 0, strlen(ping)+len+strlen(redirect) );
2728 strcpy(command,ping);
2729 WideCharToMultiByte(CP_UNIXCP, 0, hostW, -1, command+strlen(ping), len, NULL, NULL);
2730 strcat(command,redirect);
2732 TRACE("Ping command is : %s\n",command);
2734 status = system(command);
2736 TRACE("Ping returned a code of %i\n",status);
2738 /* Ping return code of 0 indicates success */
2744 HeapFree( GetProcessHeap(), 0, command );
2746 SetLastError(ERROR_NOT_CONNECTED);
2752 /***********************************************************************
2753 * InternetCheckConnectionA (WININET.@)
2755 * Pings a requested host to check internet connection
2758 * TRUE on success and FALSE on failure. If a failure then
2759 * ERROR_NOT_CONNECTED is placed into GetLastError
2762 BOOL WINAPI InternetCheckConnectionA(LPCSTR lpszUrl, DWORD dwFlags, DWORD dwReserved)
2768 len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
2769 if (!(szUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR))))
2771 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, len);
2772 rc = InternetCheckConnectionW(szUrl, dwFlags, dwReserved);
2773 HeapFree(GetProcessHeap(), 0, szUrl);
2779 /**********************************************************
2780 * INTERNET_InternetOpenUrlW (internal)
2785 * handle of connection or NULL on failure
2787 HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl,
2788 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2790 URL_COMPONENTSW urlComponents;
2791 WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
2792 WCHAR password[1024], path[2048], extra[1024];
2793 HINTERNET client = NULL, client1 = NULL;
2795 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2796 dwHeadersLength, dwFlags, dwContext);
2798 urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
2799 urlComponents.lpszScheme = protocol;
2800 urlComponents.dwSchemeLength = 32;
2801 urlComponents.lpszHostName = hostName;
2802 urlComponents.dwHostNameLength = MAXHOSTNAME;
2803 urlComponents.lpszUserName = userName;
2804 urlComponents.dwUserNameLength = 1024;
2805 urlComponents.lpszPassword = password;
2806 urlComponents.dwPasswordLength = 1024;
2807 urlComponents.lpszUrlPath = path;
2808 urlComponents.dwUrlPathLength = 2048;
2809 urlComponents.lpszExtraInfo = extra;
2810 urlComponents.dwExtraInfoLength = 1024;
2811 if(!InternetCrackUrlW(lpszUrl, strlenW(lpszUrl), 0, &urlComponents))
2813 switch(urlComponents.nScheme) {
2814 case INTERNET_SCHEME_FTP:
2815 if(urlComponents.nPort == 0)
2816 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
2817 client = FTP_Connect(hIC, hostName, urlComponents.nPort,
2818 userName, password, dwFlags, dwContext, INET_OPENURL);
2821 client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
2822 if(client1 == NULL) {
2823 InternetCloseHandle(client);
2828 case INTERNET_SCHEME_HTTP:
2829 case INTERNET_SCHEME_HTTPS: {
2830 static const WCHAR szStars[] = { '*','/','*', 0 };
2831 LPCWSTR accept[2] = { szStars, NULL };
2832 if(urlComponents.nPort == 0) {
2833 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP)
2834 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
2836 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
2838 /* FIXME: should use pointers, not handles, as handles are not thread-safe */
2839 client = HTTP_Connect(hIC, hostName, urlComponents.nPort,
2840 userName, password, dwFlags, dwContext, INET_OPENURL);
2843 client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
2844 if(client1 == NULL) {
2845 InternetCloseHandle(client);
2848 HttpAddRequestHeadersW(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);
2849 if (!HttpSendRequestW(client1, NULL, 0, NULL, 0)) {
2850 InternetCloseHandle(client1);
2855 case INTERNET_SCHEME_GOPHER:
2856 /* gopher doesn't seem to be implemented in wine, but it's supposed
2857 * to be supported by InternetOpenUrlA. */
2862 TRACE(" %p <--\n", client1);
2867 /**********************************************************
2868 * InternetOpenUrlW (WININET.@)
2873 * handle of connection or NULL on failure
2875 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
2876 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2878 HINTERNET ret = NULL;
2879 LPWININETAPPINFOW hIC = NULL;
2881 if (TRACE_ON(wininet)) {
2882 TRACE("(%p, %s, %s, %08lx, %08lx, %08lx)\n", hInternet, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
2883 dwHeadersLength, dwFlags, dwContext);
2885 dump_INTERNET_FLAGS(dwFlags);
2888 hIC = (LPWININETAPPINFOW) WININET_GetObject( hInternet );
2889 if (NULL == hIC || hIC->hdr.htype != WH_HINIT) {
2890 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
2894 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) {
2895 WORKREQUEST workRequest;
2896 struct WORKREQ_INTERNETOPENURLW *req;
2898 workRequest.asyncall = INTERNETOPENURLW;
2899 workRequest.hdr = WININET_AddRef( &hIC->hdr );
2900 req = &workRequest.u.InternetOpenUrlW;
2902 req->lpszUrl = WININET_strdupW(lpszUrl);
2906 req->lpszHeaders = WININET_strdupW(lpszHeaders);
2908 req->lpszHeaders = 0;
2909 req->dwHeadersLength = dwHeadersLength;
2910 req->dwFlags = dwFlags;
2911 req->dwContext = dwContext;
2913 INTERNET_AsyncCall(&workRequest);
2915 * This is from windows.
2917 SetLastError(ERROR_IO_PENDING);
2919 ret = INTERNET_InternetOpenUrlW(hIC, lpszUrl, lpszHeaders, dwHeadersLength, dwFlags, dwContext);
2924 WININET_Release( &hIC->hdr );
2925 TRACE(" %p <--\n", ret);
2930 /**********************************************************
2931 * InternetOpenUrlA (WININET.@)
2936 * handle of connection or NULL on failure
2938 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl,
2939 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)
2941 HINTERNET rc = (HINTERNET)NULL;
2945 LPWSTR szUrl = NULL;
2946 LPWSTR szHeaders = NULL;
2951 lenUrl = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0 );
2952 szUrl = HeapAlloc(GetProcessHeap(), 0, lenUrl*sizeof(WCHAR));
2954 return (HINTERNET)NULL;
2955 MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, szUrl, lenUrl);
2959 lenHeaders = MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, NULL, 0 );
2960 szHeaders = HeapAlloc(GetProcessHeap(), 0, lenHeaders*sizeof(WCHAR));
2962 HeapFree(GetProcessHeap(), 0, szUrl);
2963 return (HINTERNET)NULL;
2965 MultiByteToWideChar(CP_ACP, 0, lpszHeaders, dwHeadersLength, szHeaders, lenHeaders);
2968 rc = InternetOpenUrlW(hInternet, szUrl, szHeaders,
2969 lenHeaders, dwFlags, dwContext);
2971 HeapFree(GetProcessHeap(), 0, szUrl);
2972 HeapFree(GetProcessHeap(), 0, szHeaders);
2978 /***********************************************************************
2979 * INTERNET_SetLastError (internal)
2981 * Set last thread specific error
2986 void INTERNET_SetLastError(DWORD dwError)
2988 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
2990 SetLastError(dwError);
2992 lpwite->dwError = dwError;
2996 /***********************************************************************
2997 * INTERNET_GetLastError (internal)
2999 * Get last thread specific error
3004 DWORD INTERNET_GetLastError(void)
3006 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3007 /* TlsGetValue clears last error, so set it again here */
3008 SetLastError(lpwite->dwError);
3009 return lpwite->dwError;
3013 /***********************************************************************
3014 * INTERNET_WorkerThreadFunc (internal)
3016 * Worker thread execution function
3021 static DWORD CALLBACK INTERNET_WorkerThreadFunc(LPVOID lpvParam)
3028 INTERNET_ExecuteWork();
3031 dwWaitRes = WaitForMultipleObjects(2, hEventArray, FALSE, MAX_IDLE_WORKER);
3033 if (dwWaitRes == WAIT_OBJECT_0 + 1)
3034 INTERNET_ExecuteWork();
3038 InterlockedIncrement(&dwNumIdleThreads);
3041 InterlockedDecrement(&dwNumIdleThreads);
3042 InterlockedDecrement(&dwNumThreads);
3043 TRACE("Worker thread exiting\n");
3048 /***********************************************************************
3049 * INTERNET_InsertWorkRequest (internal)
3051 * Insert work request into queue
3056 static BOOL INTERNET_InsertWorkRequest(LPWORKREQUEST lpWorkRequest)
3058 BOOL bSuccess = FALSE;
3059 LPWORKREQUEST lpNewRequest;
3063 lpNewRequest = HeapAlloc(GetProcessHeap(), 0, sizeof(WORKREQUEST));
3066 memcpy(lpNewRequest, lpWorkRequest, sizeof(WORKREQUEST));
3067 lpNewRequest->prev = NULL;
3069 EnterCriticalSection(&csQueue);
3071 lpNewRequest->next = lpWorkQueueTail;
3072 if (lpWorkQueueTail)
3073 lpWorkQueueTail->prev = lpNewRequest;
3074 lpWorkQueueTail = lpNewRequest;
3075 if (!lpHeadWorkQueue)
3076 lpHeadWorkQueue = lpWorkQueueTail;
3078 LeaveCriticalSection(&csQueue);
3081 InterlockedIncrement(&dwNumJobs);
3088 /***********************************************************************
3089 * INTERNET_GetWorkRequest (internal)
3091 * Retrieves work request from queue
3096 static BOOL INTERNET_GetWorkRequest(LPWORKREQUEST lpWorkRequest)
3098 BOOL bSuccess = FALSE;
3099 LPWORKREQUEST lpRequest = NULL;
3103 EnterCriticalSection(&csQueue);
3105 if (lpHeadWorkQueue)
3107 lpRequest = lpHeadWorkQueue;
3108 lpHeadWorkQueue = lpHeadWorkQueue->prev;
3109 if (lpRequest == lpWorkQueueTail)
3110 lpWorkQueueTail = lpHeadWorkQueue;
3113 LeaveCriticalSection(&csQueue);
3117 memcpy(lpWorkRequest, lpRequest, sizeof(WORKREQUEST));
3118 HeapFree(GetProcessHeap(), 0, lpRequest);
3120 InterlockedDecrement(&dwNumJobs);
3127 /***********************************************************************
3128 * INTERNET_AsyncCall (internal)
3130 * Retrieves work request from queue
3135 BOOL INTERNET_AsyncCall(LPWORKREQUEST lpWorkRequest)
3139 BOOL bSuccess = FALSE;
3143 if (InterlockedDecrement(&dwNumIdleThreads) < 0)
3145 InterlockedIncrement(&dwNumIdleThreads);
3147 if (InterlockedIncrement(&dwNumThreads) > MAX_WORKER_THREADS ||
3148 !(hThread = CreateThread(NULL, 0,
3149 INTERNET_WorkerThreadFunc, NULL, 0, &dwTID)))
3151 InterlockedDecrement(&dwNumThreads);
3152 INTERNET_SetLastError(ERROR_INTERNET_ASYNC_THREAD_FAILED);
3156 TRACE("Created new thread\n");
3160 INTERNET_InsertWorkRequest(lpWorkRequest);
3161 SetEvent(hWorkEvent);
3169 /***********************************************************************
3170 * INTERNET_ExecuteWork (internal)
3175 static VOID INTERNET_ExecuteWork(void)
3177 WORKREQUEST workRequest;
3181 if (!INTERNET_GetWorkRequest(&workRequest))
3184 switch (workRequest.asyncall)
3188 struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
3189 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3191 TRACE("FTPPUTFILEW %p\n", lpwfs);
3193 FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
3194 req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
3196 HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
3197 HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
3201 case FTPSETCURRENTDIRECTORYW:
3203 struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
3204 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3206 TRACE("FTPSETCURRENTDIRECTORYW %p\n", lpwfs);
3208 req = &workRequest.u.FtpSetCurrentDirectoryW;
3209 FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
3210 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3214 case FTPCREATEDIRECTORYW:
3216 struct WORKREQ_FTPCREATEDIRECTORYW *req;
3217 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3219 TRACE("FTPCREATEDIRECTORYW %p\n", lpwfs);
3221 req = &workRequest.u.FtpCreateDirectoryW;
3222 FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
3223 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3227 case FTPFINDFIRSTFILEW:
3229 struct WORKREQ_FTPFINDFIRSTFILEW *req;
3230 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3232 TRACE("FTPFINDFIRSTFILEW %p\n", lpwfs);
3234 req = &workRequest.u.FtpFindFirstFileW;
3235 FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
3236 req->lpFindFileData, req->dwFlags, req->dwContext);
3237 HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
3241 case FTPGETCURRENTDIRECTORYW:
3243 struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
3244 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3246 TRACE("FTPGETCURRENTDIRECTORYW %p\n", lpwfs);
3248 req = &workRequest.u.FtpGetCurrentDirectoryW;
3249 FTP_FtpGetCurrentDirectoryW(lpwfs,
3250 req->lpszDirectory, req->lpdwDirectory);
3256 struct WORKREQ_FTPOPENFILEW *req = &workRequest.u.FtpOpenFileW;
3257 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3259 TRACE("FTPOPENFILEW %p\n", lpwfs);
3261 FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
3262 req->dwAccess, req->dwFlags, req->dwContext);
3263 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3269 struct WORKREQ_FTPGETFILEW *req = &workRequest.u.FtpGetFileW;
3270 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3272 TRACE("FTPGETFILEW %p\n", lpwfs);
3274 FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
3275 req->lpszNewFile, req->fFailIfExists,
3276 req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
3277 HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
3278 HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
3282 case FTPDELETEFILEW:
3284 struct WORKREQ_FTPDELETEFILEW *req = &workRequest.u.FtpDeleteFileW;
3285 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3287 TRACE("FTPDELETEFILEW %p\n", lpwfs);
3289 FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
3290 HeapFree(GetProcessHeap(), 0, req->lpszFilename);
3294 case FTPREMOVEDIRECTORYW:
3296 struct WORKREQ_FTPREMOVEDIRECTORYW *req;
3297 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3299 TRACE("FTPREMOVEDIRECTORYW %p\n", lpwfs);
3301 req = &workRequest.u.FtpRemoveDirectoryW;
3302 FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
3303 HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
3307 case FTPRENAMEFILEW:
3309 struct WORKREQ_FTPRENAMEFILEW *req = &workRequest.u.FtpRenameFileW;
3310 LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) workRequest.hdr;
3312 TRACE("FTPRENAMEFILEW %p\n", lpwfs);
3314 FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
3315 HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
3316 HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
3320 case INTERNETFINDNEXTW:
3322 struct WORKREQ_INTERNETFINDNEXTW *req;
3323 LPWININETFINDNEXTW lpwh = (LPWININETFINDNEXTW) workRequest.hdr;
3325 TRACE("INTERNETFINDNEXTW %p\n", lpwh);
3327 req = &workRequest.u.InternetFindNextW;
3328 INTERNET_FindNextFileW(lpwh, req->lpFindFileData);
3332 case HTTPSENDREQUESTW:
3334 struct WORKREQ_HTTPSENDREQUESTW *req = &workRequest.u.HttpSendRequestW;
3335 LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) workRequest.hdr;
3337 TRACE("HTTPSENDREQUESTW %p\n", lpwhr);
3339 HTTP_HttpSendRequestW(lpwhr, req->lpszHeader,
3340 req->dwHeaderLength, req->lpOptional, req->dwOptionalLength,
3341 req->dwContentLength, req->bEndRequest);
3343 HeapFree(GetProcessHeap(), 0, req->lpszHeader);
3347 case HTTPOPENREQUESTW:
3349 struct WORKREQ_HTTPOPENREQUESTW *req = &workRequest.u.HttpOpenRequestW;
3350 LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) workRequest.hdr;
3352 TRACE("HTTPOPENREQUESTW %p\n", lpwhs);
3354 HTTP_HttpOpenRequestW(lpwhs, req->lpszVerb,
3355 req->lpszObjectName, req->lpszVersion, req->lpszReferrer,
3356 req->lpszAcceptTypes, req->dwFlags, req->dwContext);
3358 HeapFree(GetProcessHeap(), 0, req->lpszVerb);
3359 HeapFree(GetProcessHeap(), 0, req->lpszObjectName);
3360 HeapFree(GetProcessHeap(), 0, req->lpszVersion);
3361 HeapFree(GetProcessHeap(), 0, req->lpszReferrer);
3367 struct WORKREQ_SENDCALLBACK *req = &workRequest.u.SendCallback;
3369 TRACE("SENDCALLBACK %p\n", workRequest.hdr);
3371 INTERNET_SendCallback(workRequest.hdr,
3372 req->dwContext, req->dwInternetStatus, req->lpvStatusInfo,
3373 req->dwStatusInfoLength);
3375 /* And frees the copy of the status info */
3376 HeapFree(GetProcessHeap(), 0, req->lpvStatusInfo);
3380 case INTERNETOPENURLW:
3382 struct WORKREQ_INTERNETOPENURLW *req = &workRequest.u.InternetOpenUrlW;
3383 LPWININETAPPINFOW hIC = (LPWININETAPPINFOW) workRequest.hdr;
3385 TRACE("INTERNETOPENURLW %p\n", hIC);
3387 INTERNET_InternetOpenUrlW(hIC, req->lpszUrl,
3388 req->lpszHeaders, req->dwHeadersLength, req->dwFlags, req->dwContext);
3389 HeapFree(GetProcessHeap(), 0, req->lpszUrl);
3390 HeapFree(GetProcessHeap(), 0, req->lpszHeaders);
3393 case INTERNETREADFILEEXA:
3395 struct WORKREQ_INTERNETREADFILEEXA *req = &workRequest.u.InternetReadFileExA;
3397 TRACE("INTERNETREADFILEEXA %p\n", workRequest.hdr);
3399 INTERNET_ReadFile(workRequest.hdr, req->lpBuffersOut->lpvBuffer,
3400 req->lpBuffersOut->dwBufferLength,
3401 &req->lpBuffersOut->dwBufferLength, TRUE, TRUE);
3405 WININET_Release( workRequest.hdr );
3409 /***********************************************************************
3410 * INTERNET_GetResponseBuffer (internal)
3415 LPSTR INTERNET_GetResponseBuffer(void)
3417 LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
3419 return lpwite->response;
3422 /***********************************************************************
3423 * INTERNET_GetNextLine (internal)
3425 * Parse next line in directory string listing
3428 * Pointer to beginning of next line
3433 LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
3437 BOOL bSuccess = FALSE;
3439 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
3444 FD_SET(nSocket, &infd);
3445 tv.tv_sec=RESPONSE_TIMEOUT;
3448 while (nRecv < MAX_REPLY_LEN)
3450 if (select(nSocket+1,&infd,NULL,NULL,&tv) > 0)
3452 if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
3454 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
3458 if (lpszBuffer[nRecv] == '\n')
3463 if (lpszBuffer[nRecv] != '\r')
3468 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT);
3476 lpszBuffer[nRecv] = '\0';
3478 TRACE(":%d %s\n", nRecv, lpszBuffer);
3487 /**********************************************************
3488 * InternetQueryDataAvailable (WININET.@)
3490 * Determines how much data is available to be read.
3493 * If there is data available then TRUE, otherwise if there
3494 * is not or an error occurred then FALSE. Use GetLastError() to
3495 * check for ERROR_NO_MORE_FILES to see if it was the former.
3497 BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
3498 LPDWORD lpdwNumberOfBytesAvailble,
3499 DWORD dwFlags, DWORD dwConext)
3501 LPWININETHTTPREQW lpwhr;
3502 BOOL retval = FALSE;
3505 lpwhr = (LPWININETHTTPREQW) WININET_GetObject( hFile );
3508 SetLastError(ERROR_NO_MORE_FILES);
3512 TRACE("--> %p %i\n",lpwhr,lpwhr->hdr.htype);
3514 switch (lpwhr->hdr.htype)
3517 if (!NETCON_recv(&lpwhr->netConnection, buffer,
3518 4048, MSG_PEEK, (int *)lpdwNumberOfBytesAvailble))
3520 SetLastError(ERROR_NO_MORE_FILES);
3528 FIXME("unsupported file type\n");
3531 WININET_Release( &lpwhr->hdr );
3533 TRACE("<-- %i\n",retval);
3538 /***********************************************************************
3539 * InternetLockRequestFile (WININET.@)
3541 BOOL WINAPI InternetLockRequestFile( HINTERNET hInternet, HANDLE
3548 BOOL WINAPI InternetUnlockRequestFile( HANDLE hLockHandle)
3555 /***********************************************************************
3556 * InternetAutodial (WININET.@)
3558 * On windows this function is supposed to dial the default internet
3559 * connection. We don't want to have Wine dial out to the internet so
3560 * we return TRUE by default. It might be nice to check if we are connected.
3567 BOOL WINAPI InternetAutodial(DWORD dwFlags, HWND hwndParent)
3571 /* Tell that we are connected to the internet. */
3575 /***********************************************************************
3576 * InternetAutodialHangup (WININET.@)
3578 * Hangs up a connection made with InternetAutodial
3587 BOOL WINAPI InternetAutodialHangup(DWORD dwReserved)
3591 /* we didn't dial, we don't disconnect */
3595 /***********************************************************************
3596 * InternetCombineUrlA (WININET.@)
3598 * Combine a base URL with a relative URL
3606 BOOL WINAPI InternetCombineUrlA(LPCSTR lpszBaseUrl, LPCSTR lpszRelativeUrl,
3607 LPSTR lpszBuffer, LPDWORD lpdwBufferLength,
3612 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_a(lpszBaseUrl), debugstr_a(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3614 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3615 dwFlags ^= ICU_NO_ENCODE;
3616 hr=UrlCombineA(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3621 /***********************************************************************
3622 * InternetCombineUrlW (WININET.@)
3624 * Combine a base URL with a relative URL
3632 BOOL WINAPI InternetCombineUrlW(LPCWSTR lpszBaseUrl, LPCWSTR lpszRelativeUrl,
3633 LPWSTR lpszBuffer, LPDWORD lpdwBufferLength,
3638 TRACE("(%s, %s, %p, %p, 0x%08lx)\n", debugstr_w(lpszBaseUrl), debugstr_w(lpszRelativeUrl), lpszBuffer, lpdwBufferLength, dwFlags);
3640 /* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
3641 dwFlags ^= ICU_NO_ENCODE;
3642 hr=UrlCombineW(lpszBaseUrl,lpszRelativeUrl,lpszBuffer,lpdwBufferLength,dwFlags);
3647 /* max port num is 65535 => 5 digits */
3648 #define MAX_WORD_DIGITS 5
3650 /* we can calculate using ansi strings because we're just
3651 * calculating string length, not size
3653 static BOOL calc_url_length(LPURL_COMPONENTSW lpUrlComponents,
3654 LPDWORD lpdwUrlLength, LPDWORD lpdwSchemeLength)
3656 static const WCHAR httpW[] = {'h','t','t','p',0};
3660 switch (lpUrlComponents->nScheme)
3662 case INTERNET_SCHEME_FTP:
3663 case INTERNET_SCHEME_RES:
3664 *lpdwSchemeLength = 3;
3666 case INTERNET_SCHEME_HTTP:
3667 case INTERNET_SCHEME_FILE:
3668 case INTERNET_SCHEME_NEWS:
3669 *lpdwSchemeLength = 4;
3673 *lpdwSchemeLength = 4;
3677 *lpdwUrlLength += *lpdwSchemeLength;
3678 *lpdwUrlLength += strlen("://");
3680 if (lpUrlComponents->lpszUserName)
3682 *lpdwUrlLength += lpUrlComponents->dwUserNameLength;
3683 *lpdwUrlLength += strlen("@");
3687 if (lpUrlComponents->lpszPassword)
3689 SetLastError(ERROR_INVALID_PARAMETER);
3694 if (lpUrlComponents->lpszPassword)
3696 *lpdwUrlLength += strlen(":");
3697 *lpdwUrlLength += lpUrlComponents->dwPasswordLength;
3700 *lpdwUrlLength += lpUrlComponents->dwHostNameLength;
3702 if (lpUrlComponents->nPort != 80 ||
3703 (lpUrlComponents->lpszScheme && strncmpW(lpUrlComponents->lpszScheme, httpW, lpUrlComponents->dwSchemeLength)))
3705 char szPort[MAX_WORD_DIGITS];
3707 sprintf(szPort, "%d", lpUrlComponents->nPort);
3708 *lpdwUrlLength += strlen(szPort);
3709 *lpdwUrlLength += strlen(":");
3712 *lpdwUrlLength += lpUrlComponents->dwUrlPathLength;
3716 static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPONENTSW urlCompW)
3720 ZeroMemory(urlCompW, sizeof(URL_COMPONENTSW));
3722 urlCompW->dwStructSize = sizeof(URL_COMPONENTSW);
3723 urlCompW->dwSchemeLength = lpUrlComponents->dwSchemeLength;
3724 urlCompW->nScheme = lpUrlComponents->nScheme;
3725 urlCompW->dwHostNameLength = lpUrlComponents->dwHostNameLength;
3726 urlCompW->nPort = lpUrlComponents->nPort;
3727 urlCompW->dwUserNameLength = lpUrlComponents->dwUserNameLength;
3728 urlCompW->dwPasswordLength = lpUrlComponents->dwPasswordLength;
3729 urlCompW->dwUrlPathLength = lpUrlComponents->dwUrlPathLength;
3730 urlCompW->dwExtraInfoLength = lpUrlComponents->dwExtraInfoLength;
3732 if (lpUrlComponents->lpszScheme)
3734 len = lpUrlComponents->dwSchemeLength + 1;
3735 urlCompW->lpszScheme = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3736 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszScheme,
3737 -1, urlCompW->lpszScheme, len);
3740 if (lpUrlComponents->lpszHostName)
3742 len = lpUrlComponents->dwHostNameLength + 1;
3743 urlCompW->lpszHostName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3744 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszHostName,
3745 -1, urlCompW->lpszHostName, len);
3748 if (lpUrlComponents->lpszUserName)
3750 len = lpUrlComponents->dwUserNameLength + 1;
3751 urlCompW->lpszUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3752 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUserName,
3753 -1, urlCompW->lpszUserName, len);
3756 if (lpUrlComponents->lpszPassword)
3758 len = lpUrlComponents->dwPasswordLength + 1;
3759 urlCompW->lpszPassword = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3760 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszPassword,
3761 -1, urlCompW->lpszPassword, len);
3764 if (lpUrlComponents->lpszUrlPath)
3766 len = lpUrlComponents->dwUrlPathLength + 1;
3767 urlCompW->lpszUrlPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3768 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszUrlPath,
3769 -1, urlCompW->lpszUrlPath, len);
3772 if (lpUrlComponents->lpszExtraInfo)
3774 len = lpUrlComponents->dwExtraInfoLength + 1;
3775 urlCompW->lpszExtraInfo = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3776 MultiByteToWideChar(CP_ACP, 0, lpUrlComponents->lpszExtraInfo,
3777 -1, urlCompW->lpszExtraInfo, len);
3781 /***********************************************************************
3782 * InternetCreateUrlA (WININET.@)
3789 BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
3790 LPSTR lpszUrl, LPDWORD lpdwUrlLength)
3794 URL_COMPONENTSW urlCompW;
3796 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents, dwFlags, debugstr_a(lpszUrl), lpdwUrlLength);
3798 if (!lpUrlComponents)
3801 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3803 SetLastError(ERROR_INVALID_PARAMETER);
3807 convert_urlcomp_atow(lpUrlComponents, &urlCompW);
3810 urlW = HeapAlloc(GetProcessHeap(), 0, *lpdwUrlLength * sizeof(WCHAR));
3812 ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength);
3814 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
3815 * minus one, so add one to leave room for NULL terminator
3818 WideCharToMultiByte(CP_ACP, 0, urlW, -1, lpszUrl, *lpdwUrlLength + 1, NULL, NULL);
3820 HeapFree(GetProcessHeap(), 0, urlCompW.lpszScheme);
3821 HeapFree(GetProcessHeap(), 0, urlCompW.lpszHostName);
3822 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUserName);
3823 HeapFree(GetProcessHeap(), 0, urlCompW.lpszPassword);
3824 HeapFree(GetProcessHeap(), 0, urlCompW.lpszUrlPath);
3825 HeapFree(GetProcessHeap(), 0, urlCompW.lpszExtraInfo);
3826 HeapFree(GetProcessHeap(), 0, urlW);
3831 /***********************************************************************
3832 * InternetCreateUrlW (WININET.@)
3839 BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
3840 LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
3842 DWORD dwLen, dwSchemeLen;
3844 static const WCHAR colonSlashW[] = {':','/','/',0};
3845 static const WCHAR httpW[] = {'h','t','t','p',0};
3846 static const WCHAR colonW[] = {':',0};
3847 static const WCHAR atW[] = {'@',0};
3848 static const WCHAR percentD[] = {'%','d',0};
3850 TRACE("(%p,%ld,%s,%p)\n", lpUrlComponents, dwFlags, debugstr_w(lpszUrl), lpdwUrlLength);
3852 if (!lpUrlComponents)
3855 if (lpUrlComponents->dwStructSize != sizeof(URL_COMPONENTSW) || !lpdwUrlLength)
3857 SetLastError(ERROR_INVALID_PARAMETER);
3861 if (!calc_url_length(lpUrlComponents, &dwLen, &dwSchemeLen))
3864 if (!lpszUrl || *lpdwUrlLength < dwLen)
3866 *lpdwUrlLength = dwLen + 1; /* terminating null */
3867 SetLastError(ERROR_INSUFFICIENT_BUFFER);
3871 *lpdwUrlLength = dwLen;
3874 if (lpUrlComponents->lpszScheme)
3875 lstrcpynW(lpszUrl, lpUrlComponents->lpszScheme,
3876 min(lpUrlComponents->dwSchemeLength, dwSchemeLen) + 1);
3878 lstrcatW(lpszUrl, colonSlashW);
3880 if (lpUrlComponents->lpszUserName)
3882 if (!*lpUrlComponents->lpszUserName)
3885 lstrcatW(lpszUrl, lpUrlComponents->lpszUserName);
3887 if (lpUrlComponents->lpszPassword)
3889 lstrcatW(lpszUrl, colonW);
3891 if (!*lpUrlComponents->lpszPassword)
3894 lstrcatW(lpszUrl, lpUrlComponents->lpszPassword);
3897 lstrcatW(lpszUrl, atW);
3900 lstrcatW(lpszUrl, lpUrlComponents->lpszHostName);
3902 if (lpUrlComponents->nPort != 80 || (lpUrlComponents->lpszScheme &&
3903 strncmpW(lpUrlComponents->lpszScheme, httpW, lpUrlComponents->dwSchemeLength)))
3905 WCHAR szPort[MAX_WORD_DIGITS];
3907 sprintfW(szPort, percentD, lpUrlComponents->nPort);
3908 lstrcatW(lpszUrl, colonW);
3909 lstrcatW(lpszUrl, szPort);
3912 lstrcatW(lpszUrl, lpUrlComponents->lpszUrlPath);
3917 /***********************************************************************
3918 * InternetConfirmZoneCrossingA (WININET.@)
3921 DWORD WINAPI InternetConfirmZoneCrossingA( HWND hWnd, LPSTR szUrlPrev, LPSTR szUrlNew, BOOL bPost )
3923 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_a(szUrlPrev), debugstr_a(szUrlNew), bPost);
3924 return ERROR_SUCCESS;
3927 /***********************************************************************
3928 * InternetConfirmZoneCrossingW (WININET.@)
3931 DWORD WINAPI InternetConfirmZoneCrossingW( HWND hWnd, LPWSTR szUrlPrev, LPWSTR szUrlNew, BOOL bPost )
3933 FIXME("(%p, %s, %s, %x) stub\n", hWnd, debugstr_w(szUrlPrev), debugstr_w(szUrlNew), bPost);
3934 return ERROR_SUCCESS;
3937 DWORD WINAPI InternetDialA( HWND hwndParent, LPSTR lpszConnectoid, DWORD dwFlags,
3938 LPDWORD lpdwConnection, DWORD dwReserved )
3940 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
3941 lpdwConnection, dwReserved);
3942 return ERROR_SUCCESS;
3945 DWORD WINAPI InternetDialW( HWND hwndParent, LPWSTR lpszConnectoid, DWORD dwFlags,
3946 LPDWORD lpdwConnection, DWORD dwReserved )
3948 FIXME("(%p, %p, 0x%08lx, %p, 0x%08lx) stub\n", hwndParent, lpszConnectoid, dwFlags,
3949 lpdwConnection, dwReserved);
3950 return ERROR_SUCCESS;
3953 BOOL WINAPI InternetGoOnlineA( LPSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3955 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_a(lpszURL), hwndParent, dwReserved);
3959 BOOL WINAPI InternetGoOnlineW( LPWSTR lpszURL, HWND hwndParent, DWORD dwReserved )
3961 FIXME("(%s, %p, 0x%08lx) stub\n", debugstr_w(lpszURL), hwndParent, dwReserved);
3965 DWORD WINAPI InternetHangUp( DWORD dwConnection, DWORD dwReserved )
3967 FIXME("(0x%08lx, 0x%08lx) stub\n", dwConnection, dwReserved);
3968 return ERROR_SUCCESS;
3971 BOOL WINAPI CreateMD5SSOHash( PWSTR pszChallengeInfo, PWSTR pwszRealm, PWSTR pwszTarget,
3974 FIXME("(%s, %s, %s, %p) stub\n", debugstr_w(pszChallengeInfo), debugstr_w(pwszRealm),
3975 debugstr_w(pwszTarget), pbHexHash);
3979 BOOL WINAPI InternetClearAllPerSiteCookieDecisions( VOID )
3985 BOOL WINAPI InternetEnumPerSiteCookieDecisionA( LPSTR pszSiteName, unsigned long *pcSiteNameSize,
3986 unsigned long *pdwDecision, unsigned long dwIndex )
3988 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3989 debugstr_a(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
3993 BOOL WINAPI InternetEnumPerSiteCookieDecisionW( LPWSTR pszSiteName, unsigned long *pcSiteNameSize,
3994 unsigned long *pdwDecision, unsigned long dwIndex )
3996 FIXME("(%s, %p, %p, 0x%08lx) stub\n",
3997 debugstr_w(pszSiteName), pcSiteNameSize, pdwDecision, dwIndex);
4001 BOOL WINAPI InternetGetCookieExA( LPCSTR pchURL, LPCSTR pchCookieName, LPSTR pchCookieData,
4002 LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
4004 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
4005 debugstr_a(pchURL), debugstr_a(pchCookieName), debugstr_a(pchCookieData),
4006 pcchCookieData, dwFlags, lpReserved);
4010 BOOL WINAPI InternetGetCookieExW( LPCWSTR pchURL, LPCWSTR pchCookieName, LPWSTR pchCookieData,
4011 LPDWORD pcchCookieData, DWORD dwFlags, LPVOID lpReserved)
4013 FIXME("(%s, %s, %s, %p, 0x%08lx, %p) stub\n",
4014 debugstr_w(pchURL), debugstr_w(pchCookieName), debugstr_w(pchCookieData),
4015 pcchCookieData, dwFlags, lpReserved);
4019 BOOL WINAPI InternetGetPerSiteCookieDecisionA( LPCSTR pwchHostName, unsigned long *pResult )
4021 FIXME("(%s, %p) stub\n", debugstr_a(pwchHostName), pResult);
4025 BOOL WINAPI InternetGetPerSiteCookieDecisionW( LPCWSTR pwchHostName, unsigned long *pResult )
4027 FIXME("(%s, %p) stub\n", debugstr_w(pwchHostName), pResult);
4031 BOOL WINAPI InternetSetPerSiteCookieDecisionA( LPCSTR pchHostName, DWORD dwDecision )
4033 FIXME("(%s, 0x%08lx) stub\n", debugstr_a(pchHostName), dwDecision);
4037 BOOL WINAPI InternetSetPerSiteCookieDecisionW( LPCWSTR pchHostName, DWORD dwDecision )
4039 FIXME("(%s, 0x%08lx) stub\n", debugstr_w(pchHostName), dwDecision);
4043 DWORD WINAPI InternetSetCookieExA( LPCSTR lpszURL, LPCSTR lpszCookieName, LPCSTR lpszCookieData,
4044 DWORD dwFlags, DWORD_PTR dwReserved)
4046 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
4047 debugstr_a(lpszURL), debugstr_a(lpszCookieName), debugstr_a(lpszCookieData),
4048 dwFlags, dwReserved);
4052 DWORD WINAPI InternetSetCookieExW( LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPCWSTR lpszCookieData,
4053 DWORD dwFlags, DWORD_PTR dwReserved)
4055 FIXME("(%s, %s, %s, 0x%08lx, 0x%08lx) stub\n",
4056 debugstr_w(lpszURL), debugstr_w(lpszCookieName), debugstr_w(lpszCookieData),
4057 dwFlags, dwReserved);
4061 BOOL WINAPI ResumeSuspendedDownload( HINTERNET hInternet, DWORD dwError )
4063 FIXME("(%p, 0x%08lx) stub\n", hInternet, dwError);